source: nappy/trunk/tests/test_1010_to_1020.py @ 5072

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/nappy/trunk/tests/test_1010_to_1020.py@7710
Revision 5072, 1.2 KB checked in by spascoe, 11 years ago (diff)

Moved tests back out of the package hierarchy. They are now not
included in the egg but can be run from a checkout or a
distribution directory created with "easy_install -eb . nappy"

To run the tests do "python setup.py test" or "nosetests" from the
checkout.

Line 
1import os
2
3import nappy.nc_interface.na_to_nc
4import nappy.nc_interface.nc_to_na
5import cdms2 as cdms
6
7print "Converting NAFile to NC file 1010.na"
8ncfile = os.path.join(os.path.dirname(__file__), "../test_outputs/1010.nc")
9nafile = os.path.join(os.path.dirname(__file__), "../data_files/1010.na")
10ncOutFile = os.path.join(os.path.dirname(__file__), "../test_outputs/1010_edited_for_1020.nc")
11
12n = nappy.nc_interface.na_to_nc.NAToNC(nafile)
13n.writeNCFile(ncfile)
14print "Writing a 1020 file from 1010 already converted to NetCDF..."
15f=cdms.open(ncfile)
16p_new = f('pressure', altitude=(10,85))
17o_new = f('ozone_concentration', altitude=slice(0,16,4))
18out_file = cdms.open(ncOutFile, "w")
19out_file.write(p_new)
20out_file.write(o_new)
21for att, value in f.attributes.items():
22    setattr(out_file, att, value)
23out_file.close()
24print "Outfile written:", ncfile
25
26out_dir = os.path.join(os.path.dirname(__file__), '../test_outputs')
27
28ffi_in, ffi_out = (1010, 1020)
29
30infile = os.path.join(out_dir, "%s_edited_for_%s.nc" % (ffi_in, ffi_out))
31outfile = os.path.join(out_dir, "%s_from_nc_%s.na" % (ffi_out, ffi_in))
32
33print "Reading:", infile
34x = nappy.nc_interface.nc_to_na.NCToNA(infile, requested_ffi=ffi_out)
35
36print "Writing:", outfile
37x.writeNAFiles(outfile)
Note: See TracBrowser for help on using the repository browser.