def test_ERA5_reshuffle_grb(): # test reshuffling era5 netcdf images to time series inpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', "ecmwf_models-test-data", "ERA5", "netcdf") ts_path = tempfile.mkdtemp() startdate = '2010-01-01' enddate = '2010-01-01' parameters = ["swvl1"] #, "swvl2"] h_steps = ['--h_steps', '0', '12'] landpoints = ['--land_points', 'False'] args = [inpath, ts_path, startdate, enddate] + parameters + h_steps + landpoints try: main(args) assert len(glob.glob(os.path.join(ts_path, "*.nc"))) == 2593 # more files because all points ds = ERATs(ts_path, ioclass_kws={'read_bulk':True}) ts = ds.read(15, 48) swvl1_values_should = np.array([0.402824, 0.390979], dtype=np.float32) nptest.assert_allclose(ts['swvl1'].values, swvl1_values_should, rtol=1e-5) #swvl2_values_should = np.array([0.390514, 0.390980], dtype=np.float32) #nptest.assert_allclose(ts['swvl2'].values, swvl2_values_should, rtol=1e-5) shutil.rmtree(ts_path) except Exception as e: shutil.rmtree(ts_path) raise e
def test_ERA5_reshuffle_grb(): # test reshuffling era5 netcdf images to time series inpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', "ecmwf_models-test-data", "ERA5", "netcdf") startdate = '2010-01-01' enddate = '2010-01-01' parameters = ["swvl1", "swvl2"] h_steps = ['--h_steps', '0', '12'] landpoints = ['--land_points', 'False'] bbox = ['--bbox', "12", '46', '17', '50'] with tempfile.TemporaryDirectory() as ts_path: args = [inpath, ts_path, startdate, enddate] + parameters + \ h_steps + landpoints + bbox main(args) assert len(glob.glob(os.path.join(ts_path, "*.nc"))) == 5 ds = ERATs(ts_path, ioclass_kws={'read_bulk': True}) ts = ds.read(15, 48) ds.close() swvl1_values_should = np.array([0.402824, 0.390979], dtype=np.float32) nptest.assert_allclose(ts['swvl1'].values, swvl1_values_should, rtol=1e-5) swvl2_values_should = np.array([0.390514, 0.390980], dtype=np.float32) nptest.assert_allclose(ts['swvl2'].values, swvl2_values_should, rtol=1e-5)