Ejemplo n.º 1
0
def test_reshuffle_v022():
    """
    test for the reshuffle function
    """
    inpath = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                          "esa_cci_sm-test-data", "esa_cci_sm_dailyImages",
                          "v02.2", "combined")
    startdate = "2014-01-01T00:00"
    enddate = "2014-01-02T00:00"
    parameters = ["--parameters", "sm"]
    ts_path = tempfile.mkdtemp()
    args = [inpath, ts_path, startdate, enddate] + parameters
    main(args)
    ds = CCITs(ts_path)
    assert len(glob.glob(os.path.join(ts_path, "*.nc"))) == 2593
    assert ds.grid.find_nearest_gpi(-6.625, 21.625)[0] == 642933
    ts_1d = ds.read(642933)
    ts_2d = ds.read(-6.625, 21.625)  # 0031.nc
    ts_values_should = np.array([0.1422, 0.1216], dtype=np.float32)
    nptest.assert_allclose(ts_1d['sm'].values, ts_values_should, rtol=1e-5)
    nptest.assert_allclose(ts_2d['sm'].values, ts_values_should, rtol=1e-5)

    ds = Dataset(os.path.join(ts_path, '2244.nc'))
    assert ds.getncattr('resolution') == u'0.25 degree'
    assert ds.getncattr(
        'product') == u'ESACCI-SOILMOISTURE-L3S-SSMV-COMBINED-2.2'

    assert ds.variables['sm'].getncattr(
        'full_name') == u'Volumetric Soil Moisture'
    assert ds.variables['sm'].getncattr('units') == u'm3 m-3'
Ejemplo n.º 2
0
def test_reshuffle_v042():
    """
    test for the reshuffle function
    """
    inpath = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                          "esa_cci_sm-test-data", "esa_cci_sm_dailyImages",
                          "v04.2", "passive")
    startdate = "2016-06-06T00:00"
    enddate = "2016-06-07T00:00"
    parameters = ["--parameters", "sm"]
    ts_path = tempfile.mkdtemp()
    args = [inpath, ts_path, startdate, enddate] + parameters
    main(args)
    ds = CCITs(ts_path)
    assert len(glob.glob(os.path.join(ts_path, "*.nc"))) == 2593
    assert ds.grid.find_nearest_gpi(-179.875, 68.375)[0] == 911520
    ts_1d = ds.read(911520)
    ts_2d = ds.read(-179.875, 68.375)  # 0031.nc
    ts_values_should = np.array([0.31, 0.40], dtype=np.float32)
    nptest.assert_allclose(ts_1d['sm'].values, ts_values_should, rtol=1e-5)
    nptest.assert_allclose(ts_2d['sm'].values, ts_values_should, rtol=1e-5)

    # metadata check
    ds = Dataset(os.path.join(ts_path, '2244.nc'))
    assert ds.getncattr('resolution') == u'0.25 degree'
    assert ds.getncattr(
        'product') == u'ESACCI-SOILMOISTURE-L3S-SSMV-PASSIVE-4.2'

    assert ds.variables['sm'].getncattr(
        'full_name') == u'Volumetric Soil Moisture'
    assert ds.variables['sm'].getncattr('units') == u'm3 m-3'
Ejemplo n.º 3
0
def create_reader(dataset, version):
    reader = None

    folder_name = path.join(dataset.storage_path, version.short_name)

    if dataset.short_name == globals.ISMN:
        reader = ISMN_Interface(folder_name)

    if dataset.short_name == globals.C3S:
        c3s_data_folder = path.join(folder_name,
                                    'TCDR/063_images_to_ts/combined-daily')
        reader = c3s_read(c3s_data_folder, ioclass_kws={'read_bulk': True})

    if (dataset.short_name == globals.CCI or dataset.short_name == globals.CCIA
            or dataset.short_name == globals.CCIP):
        reader = CCITs(folder_name, ioclass_kws={'read_bulk': True})

    if dataset.short_name == globals.GLDAS:
        reader = GLDASTs(folder_name, ioclass_kws={'read_bulk': True})

    if dataset.short_name == globals.SMAP:
        smap_data_folder = path.join(folder_name, 'netcdf')
        reader = SMAPTs(smap_data_folder, ioclass_kws={'read_bulk': True})

    if dataset.short_name == globals.ASCAT:
        ascat_data_folder = path.join(folder_name, 'data')
        ascat_grid_path = first_file_in(path.join(folder_name, 'grid'), '.nc')
        fn_format = "{:04d}"
        reader = AscatNc(path=ascat_data_folder,
                         fn_format=fn_format,
                         grid_filename=ascat_grid_path,
                         static_layer_path=None,
                         ioclass_kws={'read_bulk': True})

    if dataset.short_name == globals.SMOS:
        reader = SMOSTs(folder_name, ioclass_kws={'read_bulk': True})

    if dataset.short_name == globals.ERA5:
        reader = ERATs(folder_name, ioclass_kws={'read_bulk': True})

    if dataset.short_name == globals.ERA5_LAND:
        reader = ERATs(folder_name, ioclass_kws={'read_bulk': True})

    if not reader:
        raise ValueError(
            "Reader for dataset '{}' not available".format(dataset))

    reader = TimezoneAdapter(reader)

    return reader
Ejemplo n.º 4
0
def test_reshuffle_v042():
    """
    test for the reshuffle function
    """
    inpath = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                          "esa_cci_sm-test-data", "esa_cci_sm_dailyImages",
                          "v04.2", "passive")
    startdate = "2016-06-06T00:00"
    enddate = "2016-06-07T00:00"
    parameters = ["--parameters", "sm", "sm_uncertainty"]
    land_points = ["--land_points", "True"]

    ts_path = tempfile.mkdtemp()
    args = [inpath, ts_path, startdate, enddate] + parameters + land_points
    main(args)

    ds = CCITs(ts_path,
               parameters=['sm'],
               ioclass_kws={
                   'read_bulk': True,
                   'read_dates': False
               })
    assert len(glob.glob(os.path.join(ts_path, "*.nc"))) == 1002
    assert ds.grid.find_nearest_gpi(-179.875, 68.375)[0] == 911520
    ts_1d = ds.read(911520)
    ts_2d = ds.read(-179.875, 68.375)  # 0031.nc
    ts_values_should = np.array([0.31, 0.40], dtype=np.float32)
    nptest.assert_allclose(ts_1d['sm'].values, ts_values_should, rtol=1e-5)
    nptest.assert_allclose(ts_2d['sm'].values, ts_values_should, rtol=1e-5)

    # metadata check
    ds = Dataset(os.path.join(ts_path, '2244.nc'))
    assert ds.getncattr('geospatial_lat_resolution') == u'0.25 degree'
    assert ds.getncattr(
        'title') == u'ESA CCI Surface Soil Moisture merged PASSIVE Product'
    assert ds.getncattr('product_version') == u'4'

    assert ds.variables['sm'].getncattr(
        'long_name') == u'Volumetric Soil Moisture'
    assert ds.variables['sm'].getncattr('units') == u'm3 m-3'
Ejemplo n.º 5
0
def test_reshuffle_v033():
    """
    test for the reshuffle function
    """
    inpath = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                          "esa_cci_sm-test-data", "esa_cci_sm_dailyImages",
                          "v03.3", "combined")
    startdate = "2016-01-01T00:00"
    enddate = "2016-01-03T00:00"
    parameters = ["--parameters", "sm", "sm_uncertainty"]
    land_points = ['--land_points', 'False']

    ts_path = tempfile.mkdtemp()
    args = [inpath, ts_path, startdate, enddate] + parameters + land_points
    main(args)
    ds = CCITs(ts_path,
               parameters=['sm'],
               ioclass_kws={
                   'read_bulk': True,
                   'read_dates': False
               })
    assert len(glob.glob(os.path.join(ts_path, "*.nc"))) == 2593
    assert ds.grid.find_nearest_gpi(-6.625, 39.125)[0] == 743733
    ts_1d = ds.read(743733)
    ts_2d = ds.read(-6.625, 39.125)  # 0031.nc
    ts_values_should = np.array([0.23484306, np.nan], dtype=np.float32)
    nptest.assert_allclose(ts_1d['sm'].values, ts_values_should, rtol=1e-5)
    nptest.assert_allclose(ts_2d['sm'].values, ts_values_should, rtol=1e-5)

    ds = Dataset(os.path.join(ts_path, '2244.nc'))
    assert ds.getncattr('geospatial_lat_resolution') == u'0.25 degree'
    assert ds.getncattr(
        'title') == u'ESA CCI Surface Soil Moisture merged COMBINED Product'
    assert ds.getncattr('product_version') == u'3'

    assert ds.variables['sm'].getncattr(
        'long_name') == u'Volumetric Soil Moisture'
    assert ds.variables['sm'].getncattr('units') == u'm3 m-3'