def col_tm5_aero(model_id='TM5-met2010_CTRL-TEST', obs_id='AeronetSunV3L2Subset.daily', obs_vars='od550aer'): coloc = Colocator(model_id=model_id, obs_id=obs_id, obs_vars=obs_vars) coloc.raise_exceptions = True coloc.reanalyse_existing = True coloc.start = 2010 return coloc
def test_colocator__check_add_model_read_aux(): coloc = Colocator(raise_exceptions=True) r = ReadGridded('TM5-met2010_CTRL-TEST') assert not coloc._check_add_model_read_aux('od550aer', r) coloc.model_read_aux = { 'od550aer': dict(vars_required=['od550aer', 'od550aer'], fun=add_cubes) } assert coloc._check_add_model_read_aux('od550aer', r)
def test_colocator_instantiate_gridded_reader(path_emep): col = Colocator(gridded_reader_id={ 'model': 'ReadMscwCtm', 'obs': 'ReadGridded' }) col.filepath = path_emep['daily'] model_id = 'model' col.model_id = model_id r = col.instantiate_gridded_reader(what='model') assert isinstance(r, ReadMscwCtm) assert r.filepath == col.filepath assert r.data_id == model_id
def test_colocator__coldata_savename(data_tm5): col = Colocator(raise_exceptions=True) col.obs_name = 'obs' col.model_name = 'model' col.ts_type = 'monthly' col.filter_name = 'WORLD' savename = col._coldata_savename(data_tm5) assert isinstance(savename, str) assert savename == 'od550aer_REF-obs_MOD-model_20100101_20101231_monthly_WORLD.nc'
def test_colocator_update(tmpdir): col = Colocator(raise_exceptions=True) col.update(test="test") assert col.test == 'test' obs_id = 'test' col.update(obs_id=obs_id) assert col.obs_id == obs_id basedir = os.path.join(tmpdir, 'basedir') assert not os.path.isdir(basedir) col.update(basedir_coldata=basedir) assert os.path.isdir(basedir)
def test_colocator_with_obs_data_dir_gridded(): col = Colocator(save_coldata=False) col.model_id = 'TM5-met2010_CTRL-TEST' col.obs_id = 'TM5-met2010_CTRL-TEST' col.obs_vars = 'od550aer' col.ts_type = 'monthly' col.apply_time_resampling_constraints = False obs_dir = 'modeldata/TM5-met2010_CTRL-TEST/renamed' col.obs_data_dir = str(tda.testdatadir.joinpath(obs_dir)) data = col._run_gridded_gridded() assert len(data) == 1 cd = data['od550aer'] assert isinstance(cd, ColocatedData) assert cd.ts_type == 'monthly' assert str(cd.start) == '2010-01-15T00:00:00.000000000' assert str(cd.stop) == '2010-12-15T00:00:00.000000000'
def test_colocator_with_obs_data_dir_ungridded(): col = Colocator(save_coldata=False) col.model_id = 'TM5-met2010_CTRL-TEST' col.obs_id = 'AeronetSunV3L2Subset.daily' col.obs_vars = 'od550aer' col.ts_type = 'monthly' col.apply_time_resampling_constraints = False aeronet_loc = tda.ADD_PATHS['AeronetSunV3L2Subset.daily'] col.obs_data_dir = tda.testdatadir.joinpath(aeronet_loc) data = col._run_gridded_ungridded() assert len(data) == 1 cd = data['od550aer'] assert isinstance(cd, ColocatedData) assert cd.ts_type == 'monthly' assert str(cd.start) == '2010-01-15T00:00:00.000000000' assert str(cd.stop) == '2010-12-15T00:00:00.000000000'
def test_colocator_init_basedir_coldata(tmpdir): basedir = os.path.join(tmpdir, 'basedir') Colocator(raise_exceptions=True, basedir_coldata=basedir) assert os.path.isdir(basedir)
def test_colocator__get_gridded_reader_class(): gridded_reader_id = {'model': 'ReadMscwCtm', 'obs': 'ReadMscwCtm'} col = Colocator(gridded_reader_id=gridded_reader_id) for what in ['model', 'obs']: assert col._get_gridded_reader_class(what=what) == ReadMscwCtm
def col(): return Colocator(raise_exceptions=True, reanalyze_existing=True)
def test_colocator__infer_start_stop(): col = Colocator() reader = ReadGridded('TM5-met2010_CTRL-TEST') col._infer_start_stop(reader) assert col.start == 2010 assert col.stop == None
def test_colocator_call(): col = Colocator(raise_exceptions=True) with pytest.raises(NotImplementedError): col()
def test_colocator_read_model_data(): col = Colocator(raise_exceptions=True) model_id = 'TM5-met2010_CTRL-TEST' col.model_id = model_id data = col.read_model_data('od550aer') assert isinstance(data, GriddedData)
def test_colocator_read_ungridded(): col = Colocator(raise_exceptions=True) obs_id = 'AeronetSunV3L2Subset.daily' obs_var = 'od550aer' col.obs_filters = {'longitude': [-30, 30]} col.obs_id = obs_id col.read_opts_ungridded = {'last_file': 10} data = col.read_ungridded(obs_var) assert isinstance(data, UngriddedData) col.read_opts_ungridded = None col.obs_vars = ['od550aer'] with does_not_raise_exception(): data = col.read_ungridded() col.obs_vars = ['invalid'] with pytest.raises(DataCoverageError): data = col.read_ungridded()
def test_colocator_basedir_coldata(tmpdir): basedir = os.path.join(tmpdir, 'test') col = Colocator(raise_exceptions=True) col.basedir_coldata = basedir assert not os.path.isdir(basedir)
def test_colocator_filter_name(): with does_not_raise_exception(): Colocator(filter_name='WORLD') with pytest.raises(Exception): Colocator(filter_name='invalid')