示例#1
0
 def testScan(self):
     argv = 'cdscan -q -d test -x some_junk.xml u_2000.nc u_2001.nc u_2002.nc v_2000.nc v_2001.nc v_2002.nc'.split(
     )
     pth = cdat_info.get_sampledata_path()
     os.chdir(pth)
     cdscan(argv)
     baseline = ET.parse("test.xml")
     new = ET.parse("some_junk.xml")
     b_root = baseline.getroot()
     new_root = new.getroot()
     results = diffElements(b_root, new_root)
     self.assertIsNone(results)
     os.unlink("some_junk.xml")
示例#2
0
 def testopenFile(self):
     '''
     retrieve value from cdscan 
     '''
     argv = 'cdscan -x test_dap.xml https://dataserver.nccs.nasa.gov/thredds/dodsC/bypass/CREATE-IP/reanalysis/MERRA/mon/atmos/zg.ncml'.split(
     )
     pth = cdat_info.get_sampledata_path()
     os.chdir(pth)
     cdscan(argv)
     f = cdms2.open("test_dap.xml")
     s = f['zg']
     self.assertAlmostEqual(s[0, 0, 0, 0], -73.563, 3)
     os.unlink("test_dap.xml")
示例#3
0
    def testopenFile(self):
        '''
        retrieve value from cdscan 
        '''
        data_file1 = "https://dpesgf03.nccs.nasa.gov/thredds/dodsC/CREATE-IP/reanalysis/NASA-GMAO/GEOS-5/MERRA/mon/atmos/cl/cl_Amon_reanalysis_MERRA_197901-197912.nc"
        data_file2 = "https://dpesgf03.nccs.nasa.gov/thredds/dodsC/CREATE-IP/reanalysis/NASA-GMAO/GEOS-5/MERRA/mon/atmos/cl/cl_Amon_reanalysis_MERRA_198001-198012.nc"
        f1 = cdms2.open(data_file1)
        f2 = cdms2.open(data_file2)
        cl1 = f1["cl"]
        cl2 = f2["cl"]

        argv = "cdscan -x test_dap.xml {f1} {f2}".format(
            f1=data_file1, f2=data_file2).split()
        pth = cdat_info.get_sampledata_path()
        os.chdir(pth)
        cdscan(argv)
        f = cdms2.open("test_dap.xml")
        s = f['cl']
        self.assertEqual(cl1[5, 20, 80, 140], s[5, 20, 80, 140])
        self.assertEqual(cl2[5, 20, 80, 140], s[17, 20, 80, 140])

        os.unlink("test_dap.xml")
示例#4
0
    def testForecast(self):

        # Generate some test data, then write it out.  This section doesn't
        # test anything.
        xaxis = cdms2.createAxis([0.1, 0.2], id='x')
        taxis = cdms2.createAxis([10.0, 20.0], id='t')
        taxis.units = 'seconds'  # required!
        #...  Note that this is seconds since the forecast was generated, i.e. the appropriate
        # standard_name is "forecast_period".
        taxis.standard_name = 'forecast_period'

        taxis.designateTime()
        v1 = cdms2.tvariable.TransientVariable([[1.1, 1.2], [2.1, 2.1]],
                                               axes=[taxis, xaxis],
                                               id='var')
        v2 = cdms2.tvariable.TransientVariable([[3.1, 3.2], [4.1, 4.1]],
                                               axes=[taxis, xaxis],
                                               id='var')
        v3 = cdms2.tvariable.TransientVariable([[5.1, 5.2], [6.1, 6.1]],
                                               axes=[taxis, xaxis],
                                               id='var')
        date1 = cdms2.tvariable.TransientVariable(20100825, id='nbdate')
        sec1 = cdms2.tvariable.TransientVariable(0, id='nbsec')
        date2 = cdms2.tvariable.TransientVariable(20100826, id='nbdate')
        sec2 = cdms2.tvariable.TransientVariable(0, id='nbsec')
        date3 = cdms2.tvariable.TransientVariable(20100827, id='nbdate')
        sec3 = cdms2.tvariable.TransientVariable(0, id='nbsec')
        f1 = self.getTempFile('test_fc1', 'w')
        f2 = self.getTempFile('test_fc2', 'w')
        f3 = self.getTempFile('test_fc3', 'w')
        print(("TEMP:", self.tempdir))
        f1.write(v1)
        f1.write(date1)
        f1.write(sec1)
        f2.write(v2)
        f2.write(date2)
        f2.write(sec2)
        f3.write(v3)
        f3.write(date3)
        f3.write(sec3)
        f1.close()
        f2.close()
        f3.close()

        os.chdir(self.tempdir)
        cdscan(
            "cdscan -q --forecast -x test_fc.xml test_fc1 test_fc2 test_fc3".
            split())
        # Read in the data.

        fcs = cdms2.forecast.forecasts('test_fc.xml',
                                       ("2010-08-25", "2010-08-27"))
        vin = fcs('var')
        fcaxis = vin._TransientVariable__domain[0][0]
        tinaxis = vin._TransientVariable__domain[1][0]
        xinaxis = vin._TransientVariable__domain[2][0]

        # Test vin against original data, looking especially at the forecast axis.
        # The following should be True, error otherwise:
        self.assertEqual(vin.id, v1.id)
        self.assertTrue(numpy.alltrue(vin[0, :, :] == v1[:, :]))
        self.assertTrue(numpy.alltrue(vin[1, :, :] == v2[:, :]))
        self.assertEqual(vin.shape, (2, 2, 2))
        self.assertTrue(numpy.allclose(tinaxis._data_, taxis._data_))
        self.assertTrue(numpy.allclose(xinaxis._data_, xaxis._data_))
        tinaxis = vin.getAxis(1)
        # self.assertTrue(tinaxis.isTime())
        self.assertFalse(xinaxis.isTime())
        self.assertFalse(fcaxis.isTime())
        self.assertTrue(fcaxis.isForecast())
        self.assertEqual(fcaxis.shape, (3, ))
        #...Note that fcaxis is an Axis so its shape comes from len(fcaxis.node) which is the
        # number of forecasts described in test_fc.xml; in contrast for TransientAxis the shape
        # would be len(fcaxis._data_) which is the number of forecasts that
        # have been read.
        self.assertEqual(fcaxis._data_, [2010082500000, 2010082600000])
        self.assertEqual(fcaxis.id, 'fctau0')