コード例 #1
0
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)
コード例 #2
0
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)
コード例 #3
0
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 == []
コード例 #4
0
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
コード例 #5
0
def dataset():
    '''Read ECMWF data between 2003 and 2008
    '''
    return ReadGridded(name="ECMWF_CAMS_REAN",
                       start="1-1-2003",
                       stop="31-12-2007")
コード例 #6
0
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)
コード例 #7
0
def make_dataset():
    return ReadGridded(data_id="ECMWF_CAMS_REAN")
コード例 #8
0
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)
コード例 #9
0
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
コード例 #10
0
def test_ReadGridded_ts_types():
    r = ReadGridded(data_dir=path_tm5)
    assert sorted(r.ts_types) == ['daily', 'monthly']
コード例 #11
0
def reader_tm5():
    return ReadGridded('TM5-met2010_CTRL-TEST')
コード例 #12
0
def init_reader():
    return ReadGridded(data_id="ECMWF_CAMS_REAN")
コード例 #13
0
def test_ReadGridded_prefer_longer(options, expected):
    r = ReadGridded(data_dir=path_tm5)
    gridded = r.read_var('abs550aer', **options)
    assert gridded.ts_type == expected