def runContourTest(self, cdl, sld_str, world_file_str):
        # create the netcdf file
        cdl_file = os.path.join(self.dir, "data.cdl")
        handle = open(cdl_file, "w")
        handle.write(cdl)
        handle.close()
        nc_file = os.path.join(self.dir, "data.nc")
        netcdf.ncgen(cdl_file, nc_file)

        # create the sld file
        sld_file = os.path.join(self.dir, "palette.sld")
        handle = open(sld_file, "w")
        handle.write(sld_str)
        handle.close()

        output_file = os.path.join(self.dir, "out.png")
        world_file = os.path.join(self.dir, "out.wld")

        argv = [
            nc_file, output_file, "--sld", sld_file, '--contour', "--world",
            world_file
        ]
        pmv.main(argv)

        self.assertTrue(os.path.exists(output_file), "Output file created")

        self.assertTrue(os.path.exists(world_file), "World file created")
        handle = open(world_file, 'r')
        test_world = handle.read()
        handle.close()

        self.assertEqual(world_file_str, test_world, "World file is correct")
    def runPlotTest(self,
                    cdl,
                    sld_str,
                    world_file_str,
                    variable_name=None,
                    bbox=None):
        # create the netcdf file
        cdl_file = os.path.join(self.dir, "data.cdl")
        handle = open(cdl_file, "w")
        handle.write(cdl)
        handle.close()
        nc_file = os.path.join(self.dir, "data.nc")
        netcdf.ncgen(cdl_file, nc_file)

        # create the sld file
        sld_file = os.path.join(self.dir, "palette.sld")
        handle = open(sld_file, "w")
        handle.write(sld_str)
        handle.close()

        output_file = os.path.join(self.dir, "out.png")
        world_file = os.path.join(self.dir, "out.wld")
        argv = [nc_file, output_file, "--sld", sld_file, "--world", world_file]

        if variable_name is not None:
            argv.append("--variable")
            argv.append(variable_name)

        if bbox is not None:
            [west, south, east, north] = bbox.split(",")
            argv.append("--west")
            argv.append(west)
            argv.append("--south")
            argv.append(south)
            argv.append("--east")
            argv.append(east)
            argv.append("--north")
            argv.append(north)

        pmv.main(argv)

        self.assertTrue(os.path.exists(output_file), "Output file created")

        self.assertTrue(os.path.exists(world_file), "World file created")
        handle = open(world_file, 'r')
        test_world = handle.read()
        handle.close()

        self.assertEqual(world_file_str, test_world, "World file is correct")
    def runTest(self, cdl, input_XML, output_csv):
        # write input.xml
        input_file = os.path.join(self.dir, "input.xml")
        handle = open(input_file, 'w')
        handle.write(input_XML)
        handle.close()

        # create the input netcdf file
        cdl_file = os.path.join(self.dir, "data.cdl")
        handle = open(cdl_file, 'w')
        handle.write(cdl)
        handle.close()

        nc_file = os.path.join(self.dir, "data.nc")
        nc.ncgen(cdl_file, nc_file)

        # call the serializer
        io = StringIO.StringIO()
        zm.main([input_file, nc_file, self.dir], io)

        # make sure the csv was created
        csv_file = io.getvalue()
        self.assertTrue(
            os.path.exists(csv_file), "csv file exists: %s" % csv_file)

        # compare the values
        handle = open(csv_file)
        test_csv = handle.read()
        handle.close()

        self.assertEqual(output_csv, test_csv, "CSV is correct")

        # run it again. This time the code to should pick up on the file that is
        # already there.
        io = StringIO.StringIO()
        zm.main([input_file, nc_file, self.dir], io)

        # make sure we got the csv file out
        csv_file = io.getvalue()
        self.assertTrue(
            os.path.exists(csv_file), "csv file exists: %s" % csv_file)

        # compare the values
        handle = open(csv_file)
        test_csv = handle.read()
        handle.close()

        self.assertEqual(output_csv, test_csv, "CSV is correct")
Exemple #4
0
    def setUp(self):
        self.dir = tempfile.mkdtemp()

        cdl = """netcdf g4.ints.TRMM_3B43_7_precipitation.20140101-20161231.MONTH_01.180W_50S_180E_50N {
dimensions:
	time = UNLIMITED ; // (3 currently)
	latv = 2 ;
	lonv = 2 ;
	nv = 2 ;
variables:
	int datayear(time) ;
		datayear:long_name = "Data year" ;
	float TRMM_3B43_7_precipitation(time) ;
		TRMM_3B43_7_precipitation:_FillValue = -9999.9f ;
		TRMM_3B43_7_precipitation:long_name = "Precipitation Rate" ;
		TRMM_3B43_7_precipitation:product_short_name = "TRMM_3B43" ;
		TRMM_3B43_7_precipitation:product_version = "7" ;
		TRMM_3B43_7_precipitation:quantity_type = "Precipitation" ;
		TRMM_3B43_7_precipitation:standard_name = "precipitation" ;
		TRMM_3B43_7_precipitation:units = "mm/hr" ;
		TRMM_3B43_7_precipitation:cell_methods = "lat, lon: mean" ;
		TRMM_3B43_7_precipitation:group_type = "MONTH" ;
		TRMM_3B43_7_precipitation:group_value = "January" ;
		TRMM_3B43_7_precipitation:coordinates = "time" ;
		TRMM_3B43_7_precipitation:plot_hint_legend_label = "January" ;
	double lat_bnds(latv) ;
		lat_bnds:units = "degrees_north" ;
		lat_bnds:cell_methods = "lat: mean" ;
	double lon_bnds(lonv) ;
		lon_bnds:units = "degrees_east" ;
		lon_bnds:cell_methods = "lon: mean" ;
	int time(time) ;
		time:long_name = "time" ;
		time:standard_name = "time" ;
		time:units = "seconds since 1970-01-01 00:00:00" ;
		time:bounds = "time_bnds" ;
	int time_bnds(time, nv) ;
		time_bnds:units = "seconds since 1970-01-01 00:00:00" ;

// global attributes:
		:nco_openmp_thread_number = 1 ;
		:Conventions = "CF-1.4" ;
		:temporal_resolution = "monthly" ;
		:start_time = "2014-01-01T00:00:00Z" ;
		:end_time = "2016-01-31T23:59:59Z" ;
		:userstartdate = "2014-01-01T00:00:00Z" ;
		:userenddate = "2016-12-31T23:59:59Z" ;
		:title = "Interannual time series Precipitation Rate monthly 0.25 deg. [TRMM TRMM_3B43 v7] mm/hr over 2014-Jan - 2016-Jan" ;
		:plot_hint_title = "Interannual time series Precipitation Rate monthly 0.25" ;
		:plot_hint_subtitle = "deg. [TRMM TRMM_3B43 v7] mm/hr over 2014-Jan - 2016-Jan" ;
		:plot_hint_time_axis_values = "1388534400,1420070400,1451606400,1483228800" ;
		:plot_hint_time_axis_labels = "2014,2015,2016,2017" ;
		:plot_hint_time_axis_minor = "1396310400,1404172800,1412121600,1427846400,1435708800,1443657600,1459468800,1467331200,1475280000" ;
		:history = "Mon Aug  7 20:08:11 2017: ncatted -a plot_hint_time_axis_values,global,c,c,1388534400,1420070400,1451606400,1483228800 -a plot_hint_time_axis_labels,global,c,c,2014,2015,2016,2017 -a plot_hint_time_axis_minor,global,c,c,1396310400,1404172800,1412121600,1427846400,1435708800,1443657600,1459468800,1467331200,1475280000 /var/giovanni/session/EEC22AFA-7BAB-11E7-BF44-045BF1999D63/10F083E2-7BAC-11E7-876F-CC5CF1999D63/10F326B0-7BAC-11E7-876F-CC5CF1999D63/g4.ints.TRMM_3B43_7_precipitation.20140101-20161231.MONTH_01.180W_50S_180E_50N.nc" ;
data:

 datayear = 2014, 2015, 2016 ;

 TRMM_3B43_7_precipitation = 0.1226119, 0.121721, 0.1265258 ;

 lat_bnds = -0.125, 0.125000000000007 ;

 lon_bnds = -0.125, 0.125 ;

 time = 1388534400, 1420070400, 1451606400 ;

 time_bnds =
  1388534400, 1391212799,
  1420070400, 1422748799,
  1451606400, 1454284799 ;
}"""

        cdl_file = os.path.join(self.dir, "ints.cdl")
        handle = open(cdl_file, 'w')
        handle.write(cdl)
        handle.close()

        # run ncgen
        nc_file = os.path.join(self.dir, "ints.MONTH_01.nc")
        netcdf.ncgen(cdl_file, nc_file)
        self.infile = nc_file

        xml_mfst = "<manifest><fileList><file>" + nc_file + "</file></fileList></manifest>"

        self.xml_mfst_file = os.path.join(self.dir,
                                          "mfst.combine+sInTs.MONTH_01.xml")
        handle = open(self.xml_mfst_file, 'w')
        handle.write(xml_mfst)
        handle.close()

        input_file = """<input>
<referer>https://dev.gesdisc.eosdis.nasa.gov/giovanni/</referer><query>session=EEC22AFA-7BAB-11E7-BF44-045BF1999D63&amp;service=InTs&amp;starttime=2014-01-01T00:00:00Z&amp;endtime=2016-12-31T23:59:59Z&amp;months=01&amp;data=TRMM_3B43_7_precipitation&amp;portal=GIOVANNI&amp;format=json</query><title>Time Series, Seasonal</title><description>Seasonal (inter annual) time series from 2014 to 2016 for Jan</description><result id="10F326B0-7BAC-11E7-876F-CC5CF1999D63"><dir>/var/giovanni/session/EEC22AFA-7BAB-11E7-BF44-045BF1999D63/10F083E2-7BAC-11E7-876F-CC5CF1999D63/10F326B0-7BAC-11E7-876F-CC5CF1999D63/</dir></result><data>TRMM_3B43_7_precipitation</data><endtime>2016-12-31T23:59:59Z</endtime><months>01</months><portal>GIOVANNI</portal><service>InTs</service><session>EEC22AFA-7BAB-11E7-BF44-045BF1999D63</session><starttime>2014-01-01T00:00:00Z</starttime>
</input>"""

        self.input_file = os.path.join(self.dir, "input.xml")
        handle = open(self.input_file, 'w')
        handle.write(input_file)
        handle.close()
Exemple #5
0
    def setUp(self):
        self.dir = tempfile.mkdtemp()

        cdl = """netcdf g4.ints.NLDAS_MOS0125_M_002_evcwsfc.20090101-20161231.SEASON_JJA.88W_34N_77W_41N {
dimensions:
	time = UNLIMITED ; // (8 currently)
	latv = 2 ;
	lonv = 2 ;
	nv = 2 ;
variables:
	int datayear(time) ;
		datayear:long_name = "Data year" ;
	int time(time) ;
		time:standard_name = "time" ;
		time:units = "seconds since 1970-01-01 00:00:00" ;
	float NLDAS_MOS0125_M_002_evcwsfc(time) ;
		NLDAS_MOS0125_M_002_evcwsfc:cell_methods = "time: mean lat, lon: mean" ;
		NLDAS_MOS0125_M_002_evcwsfc:GRIB_param_name = "Canopy_water_evaporation" ;
		NLDAS_MOS0125_M_002_evcwsfc:GRIB_param_short_name = "EVCW" ;
		NLDAS_MOS0125_M_002_evcwsfc:GRIB_center_id = 7 ;
		NLDAS_MOS0125_M_002_evcwsfc:GRIB_table_id = 130 ;
		NLDAS_MOS0125_M_002_evcwsfc:GRIB_param_number = 200 ;
		NLDAS_MOS0125_M_002_evcwsfc:GRIB_param_id = 1, 7, 130, 200 ;
		NLDAS_MOS0125_M_002_evcwsfc:GRIB_product_definition_type = "Average" ;
		NLDAS_MOS0125_M_002_evcwsfc:GRIB_level_type = 1 ;
		NLDAS_MOS0125_M_002_evcwsfc:GRIB_VectorComponentFlag = "easterlyNortherlyRelative" ;
		NLDAS_MOS0125_M_002_evcwsfc:standard_name = "canopy_water_evaporation" ;
		NLDAS_MOS0125_M_002_evcwsfc:_FillValue = -9999.f ;
		NLDAS_MOS0125_M_002_evcwsfc:quantity_type = "Evaporation" ;
		NLDAS_MOS0125_M_002_evcwsfc:product_short_name = "NLDAS_MOS0125_M" ;
		NLDAS_MOS0125_M_002_evcwsfc:product_version = "002" ;
		NLDAS_MOS0125_M_002_evcwsfc:long_name = "Canopy water evaporation" ;
		NLDAS_MOS0125_M_002_evcwsfc:units = "W/m^2" ;
		NLDAS_MOS0125_M_002_evcwsfc:group_type = "SEASON" ;
		NLDAS_MOS0125_M_002_evcwsfc:group_value = "JJA" ;
		NLDAS_MOS0125_M_002_evcwsfc:coordinates = "time" ;
		NLDAS_MOS0125_M_002_evcwsfc:plot_hint_legend_label = "JJA" ;
	double lat_bnds(time, latv) ;
		lat_bnds:units = "degrees_north" ;
		lat_bnds:cell_methods = "lat: mean" ;
	double lon_bnds(time, lonv) ;
		lon_bnds:units = "degrees_east" ;
		lon_bnds:cell_methods = "lon: mean" ;
	int time_bnds(time, nv) ;
		time_bnds:units = "seconds since 1970-01-01 00:00:00" ;
		time_bnds:cell_methods = "time: mean" ;

// global attributes:
		:Conventions = "CF-1.4" ;
		:temporal_resolution = "monthly" ;
		:nco_openmp_thread_number = 1 ;
		:start_time = "2009-06-01T00:00:00Z" ;
		:end_time = "2016-08-31T23:59:59Z" ;
		:userstartdate = "2009-01-01T00:00:00Z" ;
		:userenddate = "2016-12-31T23:59:59Z" ;
		:title = "Interannual time series Canopy water evaporation monthly 0.125 deg. [NLDAS Model NLDAS_MOS0125_M v002] W/m^2 over 2009-Jun - 2016-Aug, Region 88.5937W, 34.5703N, 77.3437W, 41.6016N" ;
		:plot_hint_title = "Interannual time series Canopy water evaporation monthly 0.125 deg. [NLDAS Model" ;
		:plot_hint_subtitle = "NLDAS_MOS0125_M v002] W/m^2 over 2009-Jun - 2016-Aug, Region 88.5937W, 34.5703N, 77.3437W, 41.6016N" ;
		:plot_hint_time_axis_values = "1262304000,1420070400,1577836800" ;
		:plot_hint_time_axis_labels = "2010,2015,2020" ;
		:plot_hint_time_axis_minor = "1230768000,1293840000,1325376000,1356998400,1388534400,1451606400" ;
		:history = "Tue Aug  8 16:42:48 2017: ncatted -a plot_hint_time_axis_values,global,c,c,1262304000,1420070400,1577836800 -a plot_hint_time_axis_labels,global,c,c,2010,2015,2020 -a plot_hint_time_axis_minor,global,c,c,1230768000,1293840000,1325376000,1356998400,1388534400,1451606400 /var/giovanni/session/452EB79C-7C55-11E7-ABCA-C521F1999D63/56FD3C76-7C57-11E7-9260-D168F1999D63/56FF054C-7C57-11E7-9260-D168F1999D63/g4.ints.NLDAS_MOS0125_M_002_evcwsfc.20090101-20161231.SEASON_JJA.88W_34N_77W_41N.nc" ;
		:plot_hint_caption = "- Seasons with missing months are discarded.\n",
			"- DJF seasons are plotted against the year of the January and February data granules." ;
data:

 datayear = 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 ;

 time = 1243814400, 1275350400, 1306886400, 1338508800, 1370044800, 
    1401580800, 1433116800, 1464739200 ;

 NLDAS_MOS0125_M_002_evcwsfc = -15.94302, -13.77004, -12.49541, -12.13854, 
    -15.9496, -14.06023, -14.56764, -13.81603 ;

 lat_bnds =
  38.0065727390533, 38.1315727390532,
  38.0065727390533, 38.1315727390532,
  38.0065727390533, 38.1315727390532,
  38.0065727390533, 38.1315727390532,
  38.0065727390533, 38.1315727390532,
  38.0065727390533, 38.1315727390532,
  38.0065727390533, 38.1315727390532,
  38.0065727390533, 38.1315727390532 ;

 lon_bnds =
  -83.0625, -82.9375,
  -83.0625, -82.9375,
  -83.0625, -82.9375,
  -83.0625, -82.9375,
  -83.0625, -82.9375,
  -83.0625, -82.9375,
  -83.0625, -82.9375,
  -83.0625, -82.9375 ;

 time_bnds =
  1246435200, 1249084799,
  1277971200, 1280620799,
  1309507200, 1312156799,
  1341129600, 1343779199,
  1372665600, 1375315199,
  1404201600, 1406851199,
  1435737600, 1438387199,
  1467360000, 1470009599 ;
}"""

        cdl_file = os.path.join(self.dir, "ints1.cdl")
        handle = open(cdl_file, 'w')
        handle.write(cdl)
        handle.close()

        # run ncgen
        nc_file = os.path.join(self.dir, "ints.SEASON_JJA.88W_34N_77W_41N.nc")
        netcdf.ncgen(cdl_file, nc_file)
        self.file2 = nc_file

        cdl = """netcdf g4.ints.NLDAS_MOS0125_M_002_evcwsfc.20090101-20161231.SEASON_MAM.88W_34N_77W_41N {
dimensions:
	time = UNLIMITED ; // (8 currently)
	latv = 2 ;
	lonv = 2 ;
	nv = 2 ;
variables:
	int datayear(time) ;
		datayear:long_name = "Data year" ;
	int time(time) ;
		time:standard_name = "time" ;
		time:units = "seconds since 1970-01-01 00:00:00" ;
	float NLDAS_MOS0125_M_002_evcwsfc(time) ;
		NLDAS_MOS0125_M_002_evcwsfc:cell_methods = "time: mean lat, lon: mean" ;
		NLDAS_MOS0125_M_002_evcwsfc:GRIB_param_name = "Canopy_water_evaporation" ;
		NLDAS_MOS0125_M_002_evcwsfc:GRIB_param_short_name = "EVCW" ;
		NLDAS_MOS0125_M_002_evcwsfc:GRIB_center_id = 7 ;
		NLDAS_MOS0125_M_002_evcwsfc:GRIB_table_id = 130 ;
		NLDAS_MOS0125_M_002_evcwsfc:GRIB_param_number = 200 ;
		NLDAS_MOS0125_M_002_evcwsfc:GRIB_param_id = 1, 7, 130, 200 ;
		NLDAS_MOS0125_M_002_evcwsfc:GRIB_product_definition_type = "Average" ;
		NLDAS_MOS0125_M_002_evcwsfc:GRIB_level_type = 1 ;
		NLDAS_MOS0125_M_002_evcwsfc:GRIB_VectorComponentFlag = "easterlyNortherlyRelative" ;
		NLDAS_MOS0125_M_002_evcwsfc:standard_name = "canopy_water_evaporation" ;
		NLDAS_MOS0125_M_002_evcwsfc:_FillValue = -9999.f ;
		NLDAS_MOS0125_M_002_evcwsfc:quantity_type = "Evaporation" ;
		NLDAS_MOS0125_M_002_evcwsfc:product_short_name = "NLDAS_MOS0125_M" ;
		NLDAS_MOS0125_M_002_evcwsfc:product_version = "002" ;
		NLDAS_MOS0125_M_002_evcwsfc:long_name = "Canopy water evaporation" ;
		NLDAS_MOS0125_M_002_evcwsfc:units = "W/m^2" ;
		NLDAS_MOS0125_M_002_evcwsfc:group_type = "SEASON" ;
		NLDAS_MOS0125_M_002_evcwsfc:group_value = "MAM" ;
		NLDAS_MOS0125_M_002_evcwsfc:coordinates = "time" ;
		NLDAS_MOS0125_M_002_evcwsfc:plot_hint_legend_label = "MAM" ;
	double lat_bnds(time, latv) ;
		lat_bnds:units = "degrees_north" ;
		lat_bnds:cell_methods = "lat: mean" ;
	double lon_bnds(time, lonv) ;
		lon_bnds:units = "degrees_east" ;
		lon_bnds:cell_methods = "lon: mean" ;
	int time_bnds(time, nv) ;
		time_bnds:units = "seconds since 1970-01-01 00:00:00" ;
		time_bnds:cell_methods = "time: mean" ;

// global attributes:
		:Conventions = "CF-1.4" ;
		:temporal_resolution = "monthly" ;
		:nco_openmp_thread_number = 1 ;
		:start_time = "2009-03-01T00:00:00Z" ;
		:end_time = "2016-05-31T23:59:59Z" ;
		:userstartdate = "2009-01-01T00:00:00Z" ;
		:userenddate = "2016-12-31T23:59:59Z" ;
		:title = "Interannual time series Canopy water evaporation monthly 0.125 deg. [NLDAS Model NLDAS_MOS0125_M v002] W/m^2 over 2009-Mar - 2016-May, Region 88.5937W, 34.5703N, 77.3437W, 41.6016N" ;
		:plot_hint_title = "Interannual time series Canopy water evaporation monthly 0.125 deg. [NLDAS Model" ;
		:plot_hint_subtitle = "NLDAS_MOS0125_M v002] W/m^2 over 2009-Mar - 2016-May, Region 88.5937W, 34.5703N, 77.3437W, 41.6016N" ;
		:plot_hint_time_axis_values = "1262304000,1420070400,1577836800" ;
		:plot_hint_time_axis_labels = "2010,2015,2020" ;
		:plot_hint_time_axis_minor = "1230768000,1293840000,1325376000,1356998400,1388534400,1451606400" ;
		:history = "Tue Aug  8 16:42:47 2017: ncatted -a plot_hint_time_axis_values,global,c,c,1262304000,1420070400,1577836800 -a plot_hint_time_axis_labels,global,c,c,2010,2015,2020 -a plot_hint_time_axis_minor,global,c,c,1230768000,1293840000,1325376000,1356998400,1388534400,1451606400 /var/giovanni/session/452EB79C-7C55-11E7-ABCA-C521F1999D63/56FD3C76-7C57-11E7-9260-D168F1999D63/56FF054C-7C57-11E7-9260-D168F1999D63/g4.ints.NLDAS_MOS0125_M_002_evcwsfc.20090101-20161231.SEASON_MAM.88W_34N_77W_41N.nc" ;
		:plot_hint_caption = "- Seasons with missing months are discarded.\n",
			"- DJF seasons are plotted against the year of the January and February data granules." ;
data:

 datayear = 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 ;

 time = 1235865600, 1267401600, 1298937600, 1330560000, 1362096000, 
    1393632000, 1425168000, 1456790400 ;

 NLDAS_MOS0125_M_002_evcwsfc = -15.41854, -12.1115, -16.26739, -9.990607, 
    -11.71909, -11.03266, -11.68018, -12.01754 ;

 lat_bnds =
  38.0065727390533, 38.1315727390532,
  38.0065727390533, 38.1315727390532,
  38.0065727390533, 38.1315727390532,
  38.0065727390533, 38.1315727390532,
  38.0065727390533, 38.1315727390532,
  38.0065727390533, 38.1315727390532,
  38.0065727390533, 38.1315727390532,
  38.0065727390533, 38.1315727390532 ;

 lon_bnds =
  -83.0625, -82.9375,
  -83.0625, -82.9375,
  -83.0625, -82.9375,
  -83.0625, -82.9375,
  -83.0625, -82.9375,
  -83.0625, -82.9375,
  -83.0625, -82.9375,
  -83.0625, -82.9375 ;

 time_bnds =
  1238515200, 1241164799,
  1270051200, 1272700799,
  1301587200, 1304236799,
  1333209600, 1335859199,
  1364745600, 1367395199,
  1396281600, 1398931199,
  1427817600, 1430467199,
  1459440000, 1462089599 ;
}"""

        cdl_file = os.path.join(self.dir, "ints2.cdl")
        handle = open(cdl_file, 'w')
        handle.write(cdl)
        handle.close()

        # run ncgen
        nc_file = os.path.join(self.dir, "ints.SEASON_MAM.88W_34N_77W_41N.nc")
        netcdf.ncgen(cdl_file, nc_file)
        self.file1 = nc_file

        cdl = """netcdf g4.ints.NLDAS_MOS0125_M_002_evcwsfc.20090101-20161231.SEASON_SON.88W_34N_77W_41N {
dimensions:
	time = UNLIMITED ; // (8 currently)
	latv = 2 ;
	lonv = 2 ;
	nv = 2 ;
variables:
	int datayear(time) ;
		datayear:long_name = "Data year" ;
	int time(time) ;
		time:standard_name = "time" ;
		time:units = "seconds since 1970-01-01 00:00:00" ;
	float NLDAS_MOS0125_M_002_evcwsfc(time) ;
		NLDAS_MOS0125_M_002_evcwsfc:cell_methods = "time: mean lat, lon: mean" ;
		NLDAS_MOS0125_M_002_evcwsfc:GRIB_param_name = "Canopy_water_evaporation" ;
		NLDAS_MOS0125_M_002_evcwsfc:GRIB_param_short_name = "EVCW" ;
		NLDAS_MOS0125_M_002_evcwsfc:GRIB_center_id = 7 ;
		NLDAS_MOS0125_M_002_evcwsfc:GRIB_table_id = 130 ;
		NLDAS_MOS0125_M_002_evcwsfc:GRIB_param_number = 200 ;
		NLDAS_MOS0125_M_002_evcwsfc:GRIB_param_id = 1, 7, 130, 200 ;
		NLDAS_MOS0125_M_002_evcwsfc:GRIB_product_definition_type = "Average" ;
		NLDAS_MOS0125_M_002_evcwsfc:GRIB_level_type = 1 ;
		NLDAS_MOS0125_M_002_evcwsfc:GRIB_VectorComponentFlag = "easterlyNortherlyRelative" ;
		NLDAS_MOS0125_M_002_evcwsfc:standard_name = "canopy_water_evaporation" ;
		NLDAS_MOS0125_M_002_evcwsfc:_FillValue = -9999.f ;
		NLDAS_MOS0125_M_002_evcwsfc:quantity_type = "Evaporation" ;
		NLDAS_MOS0125_M_002_evcwsfc:product_short_name = "NLDAS_MOS0125_M" ;
		NLDAS_MOS0125_M_002_evcwsfc:product_version = "002" ;
		NLDAS_MOS0125_M_002_evcwsfc:long_name = "Canopy water evaporation" ;
		NLDAS_MOS0125_M_002_evcwsfc:units = "W/m^2" ;
		NLDAS_MOS0125_M_002_evcwsfc:group_type = "SEASON" ;
		NLDAS_MOS0125_M_002_evcwsfc:group_value = "SON" ;
		NLDAS_MOS0125_M_002_evcwsfc:coordinates = "time" ;
		NLDAS_MOS0125_M_002_evcwsfc:plot_hint_legend_label = "SON" ;
	double lat_bnds(time, latv) ;
		lat_bnds:units = "degrees_north" ;
		lat_bnds:cell_methods = "lat: mean" ;
	double lon_bnds(time, lonv) ;
		lon_bnds:units = "degrees_east" ;
		lon_bnds:cell_methods = "lon: mean" ;
	int time_bnds(time, nv) ;
		time_bnds:units = "seconds since 1970-01-01 00:00:00" ;
		time_bnds:cell_methods = "time: mean" ;

// global attributes:
		:Conventions = "CF-1.4" ;
		:temporal_resolution = "monthly" ;
		:nco_openmp_thread_number = 1 ;
		:start_time = "2009-09-01T00:00:00Z" ;
		:end_time = "2016-11-30T23:59:59Z" ;
		:userstartdate = "2009-01-01T00:00:00Z" ;
		:userenddate = "2016-12-31T23:59:59Z" ;
		:title = "Interannual time series Canopy water evaporation monthly 0.125 deg. [NLDAS Model NLDAS_MOS0125_M v002] W/m^2 over 2009-Sep - 2016-Nov, Region 88.5937W, 34.5703N, 77.3437W, 41.6016N" ;
		:plot_hint_title = "Interannual time series Canopy water evaporation monthly 0.125 deg. [NLDAS Model" ;
		:plot_hint_subtitle = "NLDAS_MOS0125_M v002] W/m^2 over 2009-Sep - 2016-Nov, Region 88.5937W, 34.5703N, 77.3437W, 41.6016N" ;
		:plot_hint_time_axis_values = "1262304000,1420070400,1577836800" ;
		:plot_hint_time_axis_labels = "2010,2015,2020" ;
		:plot_hint_time_axis_minor = "1230768000,1293840000,1325376000,1356998400,1388534400,1451606400" ;
		:history = "Tue Aug  8 16:42:31 2017: ncatted -a plot_hint_time_axis_values,global,c,c,1262304000,1420070400,1577836800 -a plot_hint_time_axis_labels,global,c,c,2010,2015,2020 -a plot_hint_time_axis_minor,global,c,c,1230768000,1293840000,1325376000,1356998400,1388534400,1451606400 /var/giovanni/session/452EB79C-7C55-11E7-ABCA-C521F1999D63/56FD3C76-7C57-11E7-9260-D168F1999D63/56FF054C-7C57-11E7-9260-D168F1999D63/g4.ints.NLDAS_MOS0125_M_002_evcwsfc.20090101-20161231.SEASON_SON.88W_34N_77W_41N.nc" ;
		:plot_hint_caption = "- Seasons with missing months are discarded.\n",
			"- DJF seasons are plotted against the year of the January and February data granules." ;
data:

 datayear = 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 ;

 time = 1251763200, 1283299200, 1314835200, 1346457600, 1377993600, 
    1409529600, 1441065600, 1472688000 ;

 NLDAS_MOS0125_M_002_evcwsfc = -12.65944, -9.100002, -14.36509, -11.0224, 
    -8.935831, -10.81711, -11.40564, -7.198822 ;

 lat_bnds =
  38.0065727390533, 38.1315727390532,
  38.0065727390533, 38.1315727390532,
  38.0065727390533, 38.1315727390532,
  38.0065727390533, 38.1315727390532,
  38.0065727390533, 38.1315727390532,
  38.0065727390533, 38.1315727390532,
  38.0065727390533, 38.1315727390532,
  38.0065727390533, 38.1315727390532 ;

 lon_bnds =
  -83.0625, -82.9375,
  -83.0625, -82.9375,
  -83.0625, -82.9375,
  -83.0625, -82.9375,
  -83.0625, -82.9375,
  -83.0625, -82.9375,
  -83.0625, -82.9375,
  -83.0625, -82.9375 ;

 time_bnds =
  1254384000, 1257004799,
  1285920000, 1288540799,
  1317456000, 1320076799,
  1349078400, 1351699199,
  1380614400, 1383235199,
  1412150400, 1414771199,
  1443686400, 1446307199,
  1475308800, 1477929599 ;
}"""
        cdl_file = os.path.join(self.dir, "ints3.cdl")
        handle = open(cdl_file, 'w')
        handle.write(cdl)
        handle.close()

        # run ncgen
        nc_file = os.path.join(self.dir, "ints.SEASON_SON.88W_34N_77W_41N.nc")
        netcdf.ncgen(cdl_file, nc_file)
        self.file3 = nc_file

        xml_mfst = "<manifest><fileList><file>" + self.file1 + "</file></fileList><fileList>" + \
                   "<file>" + self.file2  + "</file></fileList><fileList>" + \
                   "<file>" + self.file3  + "</file></fileList></manifest>"

        self.xml_mfst_file = os.path.join(
            self.dir,
            "mfst.combine+sInTs.SEASON_JJA_MAM_SON.88W_34N_77W_41N.xml")
        handle = open(self.xml_mfst_file, 'w')
        handle.write(xml_mfst)
        handle.close()

        bbox_input_file = """<input><referer>https://dev.gesdisc.eosdis.nasa.gov/~rstrub/giovanni/index-debug.html</referer><query>session=452EB79C-7C55-11E7-ABCA-C521F1999D63&amp;service=InTs&amp;starttime=2009-01-01T00:00:00Z&amp;endtime=2016-12-31T23:59:59Z&amp;seasons=MAM,JJA,SON&amp;bbox=-88.5937,34.5703,-77.3437,41.6016&amp;data=NLDAS_MOS0125_M_002_evcwsfc&amp;variableFacets=dataFieldMeasurement%3AEvaporation%3B&amp;portal=GIOVANNI&amp;format=json</query><title>Time Series, Seasonal</title><description>Seasonal (inter annual) time series from 2009 to 2016 for Mar-Apr-May(MAM),Jun-Jul-Aug(JJA),Sep-Oct-Nov(SON) over -88.5937,34.5703,-77.3437,41.6016</description><result id="56FF054C-7C57-11E7-9260-D168F1999D63"><dir>/var/giovanni/session/452EB79C-7C55-11E7-ABCA-C521F1999D63/56FD3C76-7C57-11E7-9260-D168F1999D63/56FF054C-7C57-11E7-9260-D168F1999D63/</dir></result><bbox>-88.5937,34.5703,-77.3437,41.6016</bbox><data>NLDAS_MOS0125_M_002_evcwsfc</data><endtime>2016-12-31T23:59:59Z</endtime><portal>GIOVANNI</portal><seasons>MAM,JJA,SON</seasons><service>InTs</service><session>452EB79C-7C55-11E7-ABCA-C521F1999D63</session><starttime>2009-01-01T00:00:00Z</starttime><variableFacets>dataFieldMeasurement:Evaporation;</variableFacets></input> """

        self.input_file = os.path.join(self.dir, "input.xml")
        handle = open(self.input_file, 'w')
        handle.write(bbox_input_file)
        handle.close()
    def setUp(self):
        self.dir = tempfile.mkdtemp()

        cdl = """netcdf g4.ints.M2IMNPANA_5_12_4_H.500hPa.19980101-20021231.SEASON_DJF.38E_32N_59E_40N {
dimensions:
	time = UNLIMITED ; // (5 currently)
	lev = 1 ;
	latv = 2 ;
	lonv = 2 ;
	nv = 2 ;
variables:
	int datayear(time) ;
		datayear:long_name = "Data year" ;
	int time(time) ;
		time:standard_name = "time" ;
		time:units = "seconds since 1970-01-01 00:00:00" ;
	float M2IMNPANA_5_12_4_H(time, lev) ;
		M2IMNPANA_5_12_4_H:_FillValue = 1.e+15f ;
		M2IMNPANA_5_12_4_H:missing_value = 1.e+15f ;
		M2IMNPANA_5_12_4_H:fmissing_value = 1.e+15f ;
		M2IMNPANA_5_12_4_H:vmax = 1.e+15f ;
		M2IMNPANA_5_12_4_H:vmin = -1.e+15f ;
		M2IMNPANA_5_12_4_H:origname = "H" ;
		M2IMNPANA_5_12_4_H:fullnamepath = "/H" ;
		M2IMNPANA_5_12_4_H:standard_name = "geopotential_height" ;
		M2IMNPANA_5_12_4_H:quantity_type = "Geopotential" ;
		M2IMNPANA_5_12_4_H:product_short_name = "M2IMNPANA" ;
		M2IMNPANA_5_12_4_H:product_version = "5.12.4" ;
		M2IMNPANA_5_12_4_H:long_name = "Geopotential height" ;
		M2IMNPANA_5_12_4_H:units = "m" ;
		M2IMNPANA_5_12_4_H:cell_methods = "lat, lon: mean time: mean" ;
		M2IMNPANA_5_12_4_H:group_type = "SEASON" ;
		M2IMNPANA_5_12_4_H:group_value = "DJF" ;
		M2IMNPANA_5_12_4_H:coordinates = "time lev" ;
		M2IMNPANA_5_12_4_H:plot_hint_legend_label = "DJF" ;
		M2IMNPANA_5_12_4_H:z_slice = "500hPa" ;
		M2IMNPANA_5_12_4_H:z_slice_type = "pressure" ;
	double lat_bnds(time, latv) ;
		lat_bnds:units = "degrees_north" ;
		lat_bnds:cell_methods = "lat: mean" ;
	double lev(lev) ;
		lev:long_name = "vertical level" ;
		lev:positive = "down" ;
		lev:vmax = 1.e+15f ;
		lev:vmin = -1.e+15f ;
		lev:origname = "lev" ;
		lev:fullnamepath = "/lev" ;
		lev:standard_name = "lev" ;
		lev:units = "hPa" ;
	double lon_bnds(time, lonv) ;
		lon_bnds:units = "degrees_east" ;
		lon_bnds:cell_methods = "lon: mean" ;
	int time_bnds(time, nv) ;
		time_bnds:units = "seconds since 1970-01-01 00:00:00" ;
		time_bnds:cell_methods = "time: mean" ;

// global attributes:
		:Conventions = "CF-1.4" ;
		:temporal_resolution = "monthly" ;
		:nco_openmp_thread_number = 1 ;
		:start_time = "1997-12-01T00:00:00Z" ;
		:end_time = "2002-02-28T23:59:59Z" ;
		:userstartdate = "1998-01-01T00:00:00Z" ;
		:userenddate = "2002-12-31T23:59:59Z" ;
		:title = "Interannual time series Average Geopotential height monthly 0.5 x 0.625 deg. @500hPa [MERRA-2 Model M2IMNPANA v5.12.4] m for 1997-Dec - 2002-Feb, Region 38.6719E, 32.3438N, 59.7656E, 40.7813N" ;
		:plot_hint_title = "Interannual time series Average Geopotential height monthly 0.5 x 0.625 deg. @500hPa" ;
		:plot_hint_subtitle = "[MERRA-2 Model M2IMNPANA v5.12.4] m for 1997-Dec - 2002-Feb, Region 38.6719E, 32.3438N, 59.7656E, 40.7813N" ;
		:plot_hint_time_axis_values = "946684800,1104537600" ;
		:plot_hint_time_axis_labels = "2000,2005" ;
		:plot_hint_time_axis_minor = "883612800,915148800,978307200,1009843200" ;
		:history = "Fri Jul 13 16:31:15 2018: ncatted -a plot_hint_time_axis_values,global,c,c,946684800,1104537600 -a plot_hint_time_axis_labels,global,c,c,2000,2005 -a plot_hint_time_axis_minor,global,c,c,883612800,915148800,978307200,1009843200 /var/giovanni/session/4EDA6C06-86AD-11E8-A1E2-AD9512B0267B/BDED84F0-86B9-11E8-8B60-C9B211B0267B/BDEE363E-86B9-11E8-8B60-C9B211B0267B/g4.ints.M2IMNPANA_5_12_4_H.500hPa.19980101-20021231.SEASON_DJF.38E_32N_59E_40N.nc" ;
		:plot_hint_caption = "- Seasons with missing months are discarded.\n",
			"- DJF seasons are plotted against the year of the January and February data granules." ;
data:

 datayear = 1998, 1999, 2000, 2001, 2002 ;

 time = 880934400, 912470400, 944006400, 975628800, 1007164800 ;

 M2IMNPANA_5_12_4_H =
  5584.977,
  5647.564,
  5621.082,
  5615.685,
  5623.948 ;

 lat_bnds =
  36.1724829205357, 36.6724829205357,
  36.1724829205357, 36.6724829205357,
  36.1724829205357, 36.6724829205357,
  36.1724829205357, 36.6724829205357,
  36.1724829205357, 36.6724829205357 ;

 lev = 500 ;

 lon_bnds =
  48.75, 49.375,
  48.75, 49.375,
  48.75, 49.375,
  48.75, 49.375,
  48.75, 49.375 ;

 time_bnds =
  883612800, 886204799,
  915148800, 917740799,
  946684800, 949305599,
  978307200, 980899199,
  1009843200, 1012435199 ;
}"""

        cdl_file = os.path.join(self.dir, "ints.cdl")
        handle = open(cdl_file, 'w')
        handle.write(cdl)
        handle.close()

        # run ncgen
        nc_file = os.path.join(self.dir, "ints.MONTH_01.nc")
        netcdf.ncgen(cdl_file, nc_file)
        self.infile = nc_file

        xml_mfst = "<manifest><fileList><file>" + nc_file + "</file></fileList></manifest>"

        self.xml_mfst_file = os.path.join(self.dir,
                                          "mfst.combine+sInTs.MONTH_01.xml")
        handle = open(self.xml_mfst_file, 'w')
        handle.write(xml_mfst)
        handle.close()

        input_file = """<input><referer>https://dev.gesdisc.eosdis.nasa.gov/~rstrub/giovanni/</referer><query>session=4EDA6C06-86AD-11E8-A1E2-AD9512B0267B&amp;service=InTs&amp;starttime=1998-01-01T00:00:00Z&amp;endtime=2002-12-31T23:59:59Z&amp;seasons=DJF&amp;bbox=38.6719,32.3438,59.7656,40.7813&amp;data=M2IMNPANA_5_12_4_H(z%3D500)&amp;variableFacets=dataFieldMeasurement%3AGeopotential%3B&amp;dataKeyword=MERRA-2&amp;portal=GIOVANNI&amp;format=json</query><title>Time Series, Seasonal</title><description>Seasonal (inter annual) time series from 1998 to 2002 for Dec-Jan-Feb(DJF) over 38.6719,32.3438,59.7656,40.7813</description><result id="2E00B95C-86BE-11E8-A253-000512B0267B"><dir>/var/giovanni/session/4EDA6C06-86AD-11E8-A1E2-AD9512B0267B/2DFE6A58-86BE-11E8-A253-000512B0267B/2E00B95C-86BE-11E8-A253-000512B0267B/</dir></result><bbox>38.6719,32.3438,59.7656,40.7813</bbox><data zValue="500">M2IMNPANA_5_12_4_H</data><dataKeyword>MERRA-2</dataKeyword><endtime>2002-12-31T23:59:59Z</endtime><portal>GIOVANNI</portal><seasons>DJF</seasons><service>InTs</service><session>4EDA6C06-86AD-11E8-A1E2-AD9512B0267B</session><starttime>1998-01-01T00:00:00Z</starttime><variableFacets>dataFieldMeasurement:Geopotential;</variableFacets></input>"""

        self.input_file = os.path.join(self.dir, "input.xml")
        handle = open(self.input_file, 'w')
        handle.write(input_file)
        handle.close()
Exemple #7
0
    def testNcGenAndDump(self):
        """
        testNcGenAndDump: This tests ncgen, ncdump, and diff_nc_files.
        """

        cdl = """netcdf g4.dimensionAveraged.OMAERUVd_003_FinalAerosolAbsOpticalDepth500.20070101-20070531.180W_90S_180E_90N {
dimensions:
    lat = 180 ;
variables:
    float OMAERUVd_003_FinalAerosolAbsOpticalDepth500(lat) ;
        OMAERUVd_003_FinalAerosolAbsOpticalDepth500:_FillValue = -1.267651e+30f ;
        OMAERUVd_003_FinalAerosolAbsOpticalDepth500:units = "1" ;
        OMAERUVd_003_FinalAerosolAbsOpticalDepth500:title = "Final Aerosol Absorption Optical Depth at 500 nm" ;
        OMAERUVd_003_FinalAerosolAbsOpticalDepth500:UniqueFieldDefinition = "Aura-Shared" ;
        OMAERUVd_003_FinalAerosolAbsOpticalDepth500:missing_value = -1.267651e+30f ;
        OMAERUVd_003_FinalAerosolAbsOpticalDepth500:origname = "FinalAerosolAbsOpticalDepth500" ;
        OMAERUVd_003_FinalAerosolAbsOpticalDepth500:fullnamepath = "/HDFEOS/GRIDS/Aerosol NearUV Grid/Data Fields/FinalAerosolAbsOpticalDepth500" ;
        OMAERUVd_003_FinalAerosolAbsOpticalDepth500:orig_dimname_list = "XDim " ;
        OMAERUVd_003_FinalAerosolAbsOpticalDepth500:standard_name = "finalaerosolabsopticaldepth500" ;
        OMAERUVd_003_FinalAerosolAbsOpticalDepth500:quantity_type = "Component Aerosol Optical Depth" ;
        OMAERUVd_003_FinalAerosolAbsOpticalDepth500:product_short_name = "OMAERUVd" ;
        OMAERUVd_003_FinalAerosolAbsOpticalDepth500:product_version = "003" ;
        OMAERUVd_003_FinalAerosolAbsOpticalDepth500:long_name = "Aerosol Absorption Optical Depth 500 nm" ;
        OMAERUVd_003_FinalAerosolAbsOpticalDepth500:coordinates = "lat" ;
        OMAERUVd_003_FinalAerosolAbsOpticalDepth500:cell_methods = "time: mean time: mean lon: mean" ;
    float lat(lat) ;
        lat:units = "degrees_north" ;
        lat:standard_name = "latitude" ;
        lat:long_name = "Latitude" ;
    int time ;
        time:standard_name = "time" ;
        time:units = "seconds since 1970-01-01 00:00:00" ;
        time:cell_methods = "time: mean time: mean" ;

// global attributes:
        :nco_openmp_thread_number = 1 ;
        :Conventions = "CF-1.4" ;
        :start_time = "2007-01-01T00:00:00Z" ;
        :end_time = "2007-05-31T23:59:59Z" ;
        :NCO = "4.4.4" ;
        :title = "Zonal Mean of Aerosol Absorption Optical Depth 500 nm daily 1 deg. [OMI OMAERUVd v003] over 2007-01-01 - 2007-05-31, Region 180W, 90S, 180E, 90N " ;
        :userstartdate = "2007-01-01T00:00:00Z" ;
        :userenddate = "2007-05-31T23:59:59Z" ;
        :plot_hint_title = "Zonal Mean of Aerosol Absorption Optical Depth 500 nm daily 1 deg. [OMI OMAERUVd v003]" ;
        :plot_hint_subtitle = "over 2007-01-01 - 2007-05-31, Region 180W, 90S, 180E, 90N " ;
data:

 OMAERUVd_003_FinalAerosolAbsOpticalDepth500 = _, _, _, _, _, _, _, _, _, _,
    _, 0.005732692, 0.006581111, 0.007075, 0.009131111, 0.004580555,
    0.005465476, 0.007679146, 0.009428572, 0.01065788, 0.01075311,
    0.01020044, 0.01059343, 0.01057464, 0.01093628, 0.01054243, 0.01040399,
    0.01024107, 0.010555, 0.01058991, 0.01082234, 0.01120079, 0.01109179,
    0.01098205, 0.01090842, 0.01067376, 0.01084355, 0.0105546, 0.01102721,
    0.0108445, 0.01062187, 0.01086002, 0.01097366, 0.01089651, 0.0108049,
    0.0111255, 0.01132336, 0.01183876, 0.01190265, 0.01238493, 0.01284299,
    0.01273277, 0.01274212, 0.01318873, 0.0133806, 0.01266411, 0.0123679,
    0.01223416, 0.0122082, 0.01239032, 0.01283799, 0.01264289, 0.01335857,
    0.01406726, 0.0136835, 0.01354076, 0.01346605, 0.01407613, 0.01449858,
    0.01540472, 0.01636874, 0.01727555, 0.01697236, 0.01710043, 0.01886979,
    0.02071303, 0.0209736, 0.02122237, 0.02191506, 0.02317924, 0.02311635,
    0.02437284, 0.02510679, 0.02756837, 0.02940871, 0.03088564, 0.03095269,
    0.03290334, 0.03656573, 0.04043462, 0.02227949, 0.0241449, 0.0256703,
    0.02667642, 0.02811306, 0.02749476, 0.02779504, 0.02673381, 0.02709048,
    0.02630195, 0.02669799, 0.02745636, 0.02823166, 0.0287596, 0.02966023,
    0.03021878, 0.02934904, 0.02881913, 0.02977417, 0.0290994, 0.02990918,
    0.02926073, 0.02920911, 0.02991091, 0.03026013, 0.03118533, 0.03071805,
    0.03067967, 0.03001351, 0.03018758, 0.02917851, 0.02880954, 0.02710553,
    0.02733052, 0.02530651, 0.02425399, 0.02319269, 0.02246948, 0.02213282,
    0.02045375, 0.0192234, 0.01820018, 0.0165542, 0.0151861, 0.01542374,
    0.01480468, 0.01349664, 0.01279164, 0.01236739, 0.01189257, 0.01247538,
    0.01188147, 0.01306759, 0.01346336, 0.01303782, 0.0130661, 0.01388488,
    0.01337894, 0.0126784, 0.0114906, 0.01030282, 0.008109493, 0.008321685,
    0.008804344, 0.009125766, 0.007295664, 0.008229486, 0.01352808,
    0.02181816, 0.02002032, 0.01834002, 0.01460644, 0.01919092, 0.02036057,
    0.01825572, 0.02255302, 0.02398033, 0.04331125, 0.1132933, 0.007104762,
    0, _, _, _, _, _, _, _, _, _ ;

 lat = -89.5, -88.5, -87.5, -86.5, -85.5, -84.5, -83.5, -82.5, -81.5, -80.5,
    -79.5, -78.5, -77.5, -76.5, -75.5, -74.5, -73.5, -72.5, -71.5, -70.5,
    -69.5, -68.5, -67.5, -66.5, -65.5, -64.5, -63.5, -62.5, -61.5, -60.5,
    -59.5, -58.5, -57.5, -56.5, -55.5, -54.5, -53.5, -52.5, -51.5, -50.5,
    -49.5, -48.5, -47.5, -46.5, -45.5, -44.5, -43.5, -42.5, -41.5, -40.5,
    -39.5, -38.5, -37.5, -36.5, -35.5, -34.5, -33.5, -32.5, -31.5, -30.5,
    -29.5, -28.5, -27.5, -26.5, -25.5, -24.5, -23.5, -22.5, -21.5, -20.5,
    -19.5, -18.5, -17.5, -16.5, -15.5, -14.5, -13.5, -12.5, -11.5, -10.5,
    -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
    2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5,
    15.5, 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5, 24.5, 25.5, 26.5,
    27.5, 28.5, 29.5, 30.5, 31.5, 32.5, 33.5, 34.5, 35.5, 36.5, 37.5, 38.5,
    39.5, 40.5, 41.5, 42.5, 43.5, 44.5, 45.5, 46.5, 47.5, 48.5, 49.5, 50.5,
    51.5, 52.5, 53.5, 54.5, 55.5, 56.5, 57.5, 58.5, 59.5, 60.5, 61.5, 62.5,
    63.5, 64.5, 65.5, 66.5, 67.5, 68.5, 69.5, 70.5, 71.5, 72.5, 73.5, 74.5,
    75.5, 76.5, 77.5, 78.5, 79.5, 80.5, 81.5, 82.5, 83.5, 84.5, 85.5, 86.5,
    87.5, 88.5, 89.5 ;

 time = 1174089600 ;
}
"""
        cdl_file = os.path.join(self.dir, "data.cdl")
        handle = open(cdl_file, 'w')
        handle.write(cdl)
        handle.close()

        # run ncgen
        nc_file = os.path.join(self.dir, "data.nc")
        netcdf.ncgen(cdl_file, nc_file)

        self.assertTrue(os.path.exists(nc_file), "Netcdf file created")

        # now dump it. If it wasn't really a netcdf file, this won't work!
        dump = netcdf.ncdump(nc_file)
        self.assertTrue(re.match("^netcdf.*{.*}\n$", dump, re.DOTALL),
                        "Got something CDL-ish back out again")

        # now dump it as XML
        doc = netcdf.ncdump(nc_file, '-x')
        namespaces = {
            "nc": "http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2"
        }

        self.assertEqual(
            doc.xpath('/nc:netcdf/nc:dimension[@name="lat"]',
                      namespaces=namespaces)[0].get('length'), "180",
            'Got a node out')

        # run ncgen again with a different filename
        nc_file2 = os.path.join(self.dir, "newname.nc")
        netcdf.ncgen(cdl_file, nc_file2)

        # change the units to '1' for OMAERUVd_003_FinalAerosolAbsOpticalDepth500.
        # It's already 1, of course, but this will add to the history. Then we
        # can make sure the comparison works.
        nco.edit_attributes(
            nc_file2,
            nc_file2, [{
                'att_name': 'units',
                'var_name': 'OMAERUVd_003_FinalAerosolAbsOpticalDepth500',
                'att_type': 'c',
                'att_val': '1'
            }],
            overwrite=True,
            stderr=subprocess.PIPE,
            stdout=subprocess.PIPE)

        (are_different, diff) = netcdf.diff_nc_files(nc_file, nc_file2)
        self.assertFalse(are_different,
                         "NCO files are different: \n%s" % "\n".join(diff))

        out = netcdf.diff_nc_files(nc_file, nc_file2, ignore_history=False)
        self.assertTrue(out[0], "NCO files do have different history")
Exemple #8
0
    def testGetAttribute(self):
        """
        This tests get_attribute
        """

        cdl = """netcdf g4.dimensionAveraged.OMAERUVd_003_FinalAerosolAbsOpticalDepth500.20070101-20070531.180W_90S_180E_90N {
dimensions:
    lat = 180 ;
variables:
    float OMAERUVd_003_FinalAerosolAbsOpticalDepth500(lat) ;
        OMAERUVd_003_FinalAerosolAbsOpticalDepth500:_FillValue = -1.267651e+30f ;
        OMAERUVd_003_FinalAerosolAbsOpticalDepth500:units = "1" ;
        OMAERUVd_003_FinalAerosolAbsOpticalDepth500:title = "Final Aerosol Absorption Optical Depth at 500 nm" ;
        OMAERUVd_003_FinalAerosolAbsOpticalDepth500:UniqueFieldDefinition = "Aura-Shared" ;
        OMAERUVd_003_FinalAerosolAbsOpticalDepth500:missing_value = -1.267651e+30f ;
        OMAERUVd_003_FinalAerosolAbsOpticalDepth500:origname = "FinalAerosolAbsOpticalDepth500" ;
        OMAERUVd_003_FinalAerosolAbsOpticalDepth500:fullnamepath = "/HDFEOS/GRIDS/Aerosol NearUV Grid/Data Fields/FinalAerosolAbsOpticalDepth500" ;
        OMAERUVd_003_FinalAerosolAbsOpticalDepth500:orig_dimname_list = "XDim " ;
        OMAERUVd_003_FinalAerosolAbsOpticalDepth500:standard_name = "finalaerosolabsopticaldepth500" ;
        OMAERUVd_003_FinalAerosolAbsOpticalDepth500:quantity_type = "Component Aerosol Optical Depth" ;
        OMAERUVd_003_FinalAerosolAbsOpticalDepth500:product_short_name = "OMAERUVd" ;
        OMAERUVd_003_FinalAerosolAbsOpticalDepth500:product_version = "003" ;
        OMAERUVd_003_FinalAerosolAbsOpticalDepth500:long_name = "Aerosol Absorption Optical Depth 500 nm" ;
        OMAERUVd_003_FinalAerosolAbsOpticalDepth500:coordinates = "lat" ;
        OMAERUVd_003_FinalAerosolAbsOpticalDepth500:cell_methods = "time: mean time: mean lon: mean" ;
    float lat(lat) ;
        lat:units = "degrees_north" ;
        lat:standard_name = "latitude" ;
        lat:long_name = "Latitude" ;
    int time ;
        time:standard_name = "time" ;
        time:units = "seconds since 1970-01-01 00:00:00" ;
        time:cell_methods = "time: mean time: mean" ;

// global attributes:
        :nco_openmp_thread_number = 1 ;
        :Conventions = "CF-1.4" ;
        :start_time = "2007-01-01T00:00:00Z" ;
        :end_time = "2007-05-31T23:59:59Z" ;
        :NCO = "4.4.4" ;
        :title = "Zonal Mean of Aerosol Absorption Optical Depth 500 nm daily 1 deg. [OMI OMAERUVd v003] over 2007-01-01 - 2007-05-31, Region 180W, 90S, 180E, 90N " ;
        :userstartdate = "2007-01-01T00:00:00Z" ;
        :userenddate = "2007-05-31T23:59:59Z" ;
        :plot_hint_title = "Zonal Mean of Aerosol Absorption Optical Depth 500 nm daily 1 deg. [OMI OMAERUVd v003]" ;
        :plot_hint_subtitle = "over 2007-01-01 - 2007-05-31, Region 180W, 90S, 180E, 90N " ;
data:

 OMAERUVd_003_FinalAerosolAbsOpticalDepth500 = _, _, _, _, _, _, _, _, _, _,
    _, 0.005732692, 0.006581111, 0.007075, 0.009131111, 0.004580555,
    0.005465476, 0.007679146, 0.009428572, 0.01065788, 0.01075311,
    0.01020044, 0.01059343, 0.01057464, 0.01093628, 0.01054243, 0.01040399,
    0.01024107, 0.010555, 0.01058991, 0.01082234, 0.01120079, 0.01109179,
    0.01098205, 0.01090842, 0.01067376, 0.01084355, 0.0105546, 0.01102721,
    0.0108445, 0.01062187, 0.01086002, 0.01097366, 0.01089651, 0.0108049,
    0.0111255, 0.01132336, 0.01183876, 0.01190265, 0.01238493, 0.01284299,
    0.01273277, 0.01274212, 0.01318873, 0.0133806, 0.01266411, 0.0123679,
    0.01223416, 0.0122082, 0.01239032, 0.01283799, 0.01264289, 0.01335857,
    0.01406726, 0.0136835, 0.01354076, 0.01346605, 0.01407613, 0.01449858,
    0.01540472, 0.01636874, 0.01727555, 0.01697236, 0.01710043, 0.01886979,
    0.02071303, 0.0209736, 0.02122237, 0.02191506, 0.02317924, 0.02311635,
    0.02437284, 0.02510679, 0.02756837, 0.02940871, 0.03088564, 0.03095269,
    0.03290334, 0.03656573, 0.04043462, 0.02227949, 0.0241449, 0.0256703,
    0.02667642, 0.02811306, 0.02749476, 0.02779504, 0.02673381, 0.02709048,
    0.02630195, 0.02669799, 0.02745636, 0.02823166, 0.0287596, 0.02966023,
    0.03021878, 0.02934904, 0.02881913, 0.02977417, 0.0290994, 0.02990918,
    0.02926073, 0.02920911, 0.02991091, 0.03026013, 0.03118533, 0.03071805,
    0.03067967, 0.03001351, 0.03018758, 0.02917851, 0.02880954, 0.02710553,
    0.02733052, 0.02530651, 0.02425399, 0.02319269, 0.02246948, 0.02213282,
    0.02045375, 0.0192234, 0.01820018, 0.0165542, 0.0151861, 0.01542374,
    0.01480468, 0.01349664, 0.01279164, 0.01236739, 0.01189257, 0.01247538,
    0.01188147, 0.01306759, 0.01346336, 0.01303782, 0.0130661, 0.01388488,
    0.01337894, 0.0126784, 0.0114906, 0.01030282, 0.008109493, 0.008321685,
    0.008804344, 0.009125766, 0.007295664, 0.008229486, 0.01352808,
    0.02181816, 0.02002032, 0.01834002, 0.01460644, 0.01919092, 0.02036057,
    0.01825572, 0.02255302, 0.02398033, 0.04331125, 0.1132933, 0.007104762,
    0, _, _, _, _, _, _, _, _, _ ;

 lat = -89.5, -88.5, -87.5, -86.5, -85.5, -84.5, -83.5, -82.5, -81.5, -80.5,
    -79.5, -78.5, -77.5, -76.5, -75.5, -74.5, -73.5, -72.5, -71.5, -70.5,
    -69.5, -68.5, -67.5, -66.5, -65.5, -64.5, -63.5, -62.5, -61.5, -60.5,
    -59.5, -58.5, -57.5, -56.5, -55.5, -54.5, -53.5, -52.5, -51.5, -50.5,
    -49.5, -48.5, -47.5, -46.5, -45.5, -44.5, -43.5, -42.5, -41.5, -40.5,
    -39.5, -38.5, -37.5, -36.5, -35.5, -34.5, -33.5, -32.5, -31.5, -30.5,
    -29.5, -28.5, -27.5, -26.5, -25.5, -24.5, -23.5, -22.5, -21.5, -20.5,
    -19.5, -18.5, -17.5, -16.5, -15.5, -14.5, -13.5, -12.5, -11.5, -10.5,
    -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
    2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5,
    15.5, 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5, 24.5, 25.5, 26.5,
    27.5, 28.5, 29.5, 30.5, 31.5, 32.5, 33.5, 34.5, 35.5, 36.5, 37.5, 38.5,
    39.5, 40.5, 41.5, 42.5, 43.5, 44.5, 45.5, 46.5, 47.5, 48.5, 49.5, 50.5,
    51.5, 52.5, 53.5, 54.5, 55.5, 56.5, 57.5, 58.5, 59.5, 60.5, 61.5, 62.5,
    63.5, 64.5, 65.5, 66.5, 67.5, 68.5, 69.5, 70.5, 71.5, 72.5, 73.5, 74.5,
    75.5, 76.5, 77.5, 78.5, 79.5, 80.5, 81.5, 82.5, 83.5, 84.5, 85.5, 86.5,
    87.5, 88.5, 89.5 ;

 time = 1174089600 ;
}
"""
        cdl_file = os.path.join(self.dir, "data.cdl")
        handle = open(cdl_file, 'w')
        handle.write(cdl)
        handle.close()

        # run ncgen
        nc_file = os.path.join(self.dir, "data.nc")
        netcdf.ncgen(cdl_file, nc_file)

        self.assertEqual(
            netcdf.get_attribute(
                nc_file, "units",
                "OMAERUVd_003_FinalAerosolAbsOpticalDepth500"), "1",
            "Got out units")
        self.assertEqual(netcdf.get_attribute(nc_file, "NCO"), "4.4.4",
                         "Got out NCO global attribute")

        try:
            netcdf.get_attribute(nc_file, "FAKE")
            self.fail("An invalid attribute should throw an error")
        except netcdf.NetCDFError:
            # nothing to do. This is correct.
            pass