def test_ReadGridded_aux(tmpdir, vars, expected): for var in vars: filename = 'aerocom3_TM5-met2010_AP3-CTRL2019_{}_Column_2010_daily.nc'.format( var) open(os.path.join(tmpdir, filename), 'a').close() r = ReadGridded(data_dir=str(tmpdir)) for var in expected: assert r.has_var(var) # calling has_var assert sorted(r.vars_provided) == sorted(expected)
def test_ReadGridded_years_avail(tmpdir, years, expected): for year in years: filename = 'aerocom3_TM5-met2010_AP3-CTRL2019_od550aer_Column_{}_daily.nc'.format( year) open(os.path.join(tmpdir, filename), 'a').close() r = ReadGridded(data_dir=str(tmpdir)) assert sorted(r.years_avail) == sorted(years)
def test_ReadGridded_class_empty(): r = ReadGridded() assert r.data_id == None assert r.data_dir == None from pyaerocom.io.aerocom_browser import AerocomBrowser assert isinstance(r.browser, AerocomBrowser) with pytest.raises(AttributeError): r.years_avail assert r.vars_filename == []
def browse_database(model_or_obs, verbose=False): """Browse Aerocom database using model or obs ID (or wildcard) Searches database for matches and prints information about all matches found (e.g. available variables, years, etc.) Parameters ---------- model_or_obs : str model or obs ID or search pattern verbose : bool if True, verbosity level will be set to debug, else to critical Returns ------- list list with data_ids of all matches Example ------- >>> import pyaerocom as pya >>> pya.io.browse_database('AATSR*ORAC*v4*') Pyaerocom ReadGridded --------------------- Model ID: AATSR_ORAC_v4.01 Data directory: /lustre/storeA/project/aerocom/aerocom-users-database/CCI-Aerosol/CCI_AEROSOL_Phase2/AATSR_ORAC_v4.01/renamed Available variables: ['abs550aer', 'ang4487aer', 'clt', 'landseamask', 'od550aer', 'od550dust', 'od550gt1aer', 'od550lt1aer', 'pixelcount'] Available years: [2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012] Available time resolutions ['daily'] """ if not verbose: change_verbosity('critical') else: change_verbosity('debug') browser = AerocomBrowser() matches = browser.find_matches(model_or_obs) if len(matches) == 0: print('No match could be found for {}'.format(model_or_obs)) return elif len(matches) > 20: print('Found more than 20 matches for input pattern {}:\n\n' 'Matches: {}\n\n' 'To receive more detailed information, please specify search ID ' 'more accurately'.format(model_or_obs, matches)) return for match in matches: try: if match in const.OBS_IDS_UNGRIDDED: reader = ReadUngridded(match) else: reader = ReadGridded(match) print(reader) except Exception as e: print('Reading failed for {}. Error: {}'.format(match, repr(e))) return matches
def dataset(): '''Read ECMWF data between 2003 and 2008 ''' return ReadGridded(name="ECMWF_CAMS_REAN", start="1-1-2003", stop="31-12-2007")
from pyaerocom.io.readgridded import ReadGridded gridded_reader = ReadGridded(data_id="EMEP_rv4.1.1.T2.1_ctl") data = gridded_reader.read_var(var_name='wetso4', ts_type="daily") print(data.unit) data.unit = 'mg/m2' print(data.unit)
def make_dataset(): return ReadGridded(data_id="ECMWF_CAMS_REAN")
from pyaerocom.plot import plotmaps from GLOB import OUT_DIR_MAPS # import standard output directory if __name__ == '__main__': import argparse default_model = "AATSR_SU_v4.3" parser = argparse.ArgumentParser( description='command line interface to the readgrid class') parser.add_argument("model", help="model to read", nargs="?", const=default_model, default=default_model, type=str) args = parser.parse_args() if args.model: model = args.model var = "od550aer" # Create data import object test = ReadGridded(model, '2010-01-01', '2011-12-31', verbose=True) print(test.vars) data = test.read_var("od550aer", ts_type="daily") #plotmaps(data, VerboseFlag=True, plotdir=OUT_DIR_MAPS)
def test_ReadGridded_experiments(tmpdir, experiments): for exp in experiments: filename = 'aerocom3_TM5-met2010_{}-CTRL2019_abs550aer_Column_2010_daily.nc'.format(exp) open(os.path.join(tmpdir, filename), 'a').close() r = ReadGridded(data_dir = str(tmpdir)) assert r.experiments == experiments
def test_ReadGridded_ts_types(): r = ReadGridded(data_dir=path_tm5) assert sorted(r.ts_types) == ['daily', 'monthly']
def reader_tm5(): return ReadGridded('TM5-met2010_CTRL-TEST')
def init_reader(): return ReadGridded(data_id="ECMWF_CAMS_REAN")
def test_ReadGridded_prefer_longer(options, expected): r = ReadGridded(data_dir=path_tm5) gridded = r.read_var('abs550aer', **options) assert gridded.ts_type == expected