def test_reduceLatLonBoundingBox(self): test_ncfile = os.path.join(test_srcdir, 'erai.sfc.40N.0.75d.200301011200.nc') r = pyfimex0.createFileReader('netcdf', test_ncfile) extra = pyfimex0.createExtractor(r) extra.reduceLatLonBoundingBox(59, 60, 9, 11) del extra del r
def test_reduceTimeIso8601(self): test_ncfile = os.path.join(test_srcdir, 'erai.sfc.40N.0.75d.200301011200.nc') r = pyfimex0.createFileReader('netcdf', test_ncfile) extra = pyfimex0.createExtractor(r) extra.reduceTimeStartEnd('2017-05-22T06:00:00', '2017-05-22T07:00:00') with self.assertRaises(Exception): extra.reduceTimeStartEnd('ooops', '2017-05-22T07:00:00') del extra del r
def test_reduceDimension(self): test_ncfile = os.path.join(test_srcdir, 'testdata_vertical_ensemble_in.nc') r = pyfimex0.createFileReader('netcdf', test_ncfile) extra = pyfimex0.createExtractor(r) extra.reduceDimension('x', [0, 1, 3]) extra.reduceDimension('y', 1, 2) e_cdm = extra.getCDM() self.assertEqual(3, e_cdm.getDimension('x').getLength()) self.assertEqual(2, e_cdm.getDimension('y').getLength()) del extra del r
def test_selectVariables(self): test_ncfile = os.path.join(test_srcdir, 'erai.sfc.40N.0.75d.200301011200.nc') r = pyfimex0.createFileReader('netcdf', test_ncfile) extra = pyfimex0.createExtractor(r) extra.selectVariables(['x_wind_10m', 'x_wind_10m']) e_cdm = extra.getCDM() e_vars = e_cdm.getVariableNames() self.assertTrue('specific_humidity_ml' not in e_vars) del extra del r
def test_removeVariable(self): test_ncfile = os.path.join(test_srcdir, 'erai.sfc.40N.0.75d.200301011200.nc') r = pyfimex0.createFileReader('netcdf', test_ncfile) self.assertTrue('ga_skt' in r.getCDM().getVariableNames()) extra = pyfimex0.createExtractor(r) extra.removeVariable('ga_skt') self.assertTrue('ga_skt' not in extra.getCDM().getVariableNames()) del extra del r
def extractFromFile(self): """ Method for reducing dimension, i.e. temporal and/or spatial in addition to reduce number of variables.""" extractor = pyfimex0.createExtractor(self.fimex_reader) # Check reductions to be made based on input values if self.reduceBBNorth and self.reduceBBEast and self.reduceBBSouth and self.reduceBBWest: reduce_latLonBoundingBox = True else: reduce_latLonBoundingBox = False if self.selectVariables: reduce_variables = True else: reduce_variables = False # Reduce temporal extent if self.reduceTimeStart and self.reduceTimeEnd: extractor.reduceTimeStartEnd(self.reduceTimeStart, self.reduceTimeEnd) # Reduce dimension - NOTE: Not implemented.. reduce_dim = False if reduce_dim: extractor.reduceDimensionStartEnd( 'time', [self.reduceTimeStart, self.reduceTimeEnd]) extractor.reduceDimension('x', [0, 1, 3]) extractor.reduceDimension('y', 1, 2) # Reduce latitude/longitude Bounding Box if reduce_latLonBoundingBox: print('Reducing latitude and longitude bounding box') extractor.reduceLatLonBoundingBox(self.reduceBBSouth, self.reduceBBNorth, self.reduceBBWest, self.reduceBBEast) #print("DEBUG",extractor.getDataSlice('B2',0).values()) # Reduce number of variables if reduce_variables: print('Reducing number of variables from:') print(extractor.getCDM().getVariableNames()) print('to') print(self.selectVariables) extractor.selectVariables(self.selectVariables) return extractor
def test_writeExtracted(self): test_ncfile = os.path.join(test_srcdir, 'testdata_vertical_ensemble_in.nc') r1 = pyfimex0.createFileReader('netcdf', test_ncfile) v_x_wind = 'x_wind_10m' r1v_x_wind = r1.getDataSlice(v_x_wind, 0).values() extra = pyfimex0.createExtractor(r1) extra.selectVariables([v_x_wind]) outfile = "extracted_wind_x.nc" pyfimex0.createFileWriter(extra, 'netcdf', outfile) del extra del r1 r2 = pyfimex0.createFileReader('netcdf', outfile) r2v_x_wind = r2.getDataSlice(v_x_wind, 0).values() for v1, v2 in zip(r1v_x_wind, r2v_x_wind): self.assertEqual(v1, v2)