コード例 #1
0
def test_GLDAS_Noah_v1_025Ds_timestamps_for_daterange():
    landgrid = GLDAS025LandGrid()
    parameter = ["086_L2", "086_L1", "085_L1", "138", "132", "051"]
    img = GLDAS_Noah_v1_025Ds(
        data_path=os.path.join(
            os.path.dirname(__file__), "test-data", "GLDAS_NOAH_image_data"
        ),
        parameter=parameter,
        subgrid=None,
        array_1D=True,
    )

    tstamps = img.tstamps_for_daterange(
        datetime(2000, 1, 1), datetime(2000, 1, 1)
    )
    assert len(tstamps) == 8
    assert tstamps == [
        datetime(2000, 1, 1, 0),
        datetime(2000, 1, 1, 3),
        datetime(2000, 1, 1, 6),
        datetime(2000, 1, 1, 9),
        datetime(2000, 1, 1, 12),
        datetime(2000, 1, 1, 15),
        datetime(2000, 1, 1, 18),
        datetime(2000, 1, 1, 21),
    ]
コード例 #2
0
def test_GLDAS_Noah_v1_025Ds_img_reading():
    parameter = ["086_L2", "086_L1", "085_L1", "138", "132", "051"]
    img = GLDAS_Noah_v1_025Ds(
        data_path=os.path.join(
            os.path.dirname(__file__), "test-data", "GLDAS_NOAH_image_data"
        ),
        parameter=parameter,
        subgrid=None,
        array_1D=True,
    )

    image = img.read(datetime(2015, 1, 1, 0))

    assert sorted(image.data.keys()) == sorted(parameter)
    assert image.timestamp == datetime(2015, 1, 1, 0)
    assert image.data["086_L1"][998529] == 30.7344
    assert image.data["086_L2"][998529] == 93.138
    assert image.data["085_L1"][206360] == 285.19
    assert image.data["138"][998529] == 237.27
    assert image.data["051"][998529] == 0
    assert image.lon.shape == (360 * 180 * (1 / 0.25) ** 2,)
    assert image.lon.shape == image.lat.shape
    assert sorted(list(image.metadata.keys())) == sorted(parameter)
    assert image.metadata["085_L1"]["units"] == u"K"
    assert (
        image.metadata["085_L1"]["long_name"]
        == u"ST Surface temperature of soil K"
    )
コード例 #3
0
ファイル: reshuffle.py プロジェクト: rameezu/gldas
def reshuffle(input_root, outputpath,
              startdate, enddate,
              parameters, land_points=True,
              imgbuffer=50):
    """
    Reshuffle method applied to GLDAS data.

    Parameters
    ----------
    input_root: string
        input path where gldas data was downloaded
    outputpath : string
        Output path.
    startdate : datetime
        Start date.
    enddate : datetime
        End date.
    parameters: list
        parameters to read and convert
    imgbuffer: int, optional
        How many images to read at once before writing time series.
    """

    if land_points:
        landgrid = GLDAS025LandGrid()
    else:
        landgrid = None

    if get_filetype(input_root) == 'grib':
        input_dataset = GLDAS_Noah_v1_025Ds(input_root, parameters,
                                            array_1D=True)
        if land_points:
            warnings.warn('Land Grid is fit to GLDAS 2.x netCDF data')
    else:
        input_dataset = GLDAS_Noah_v21_025Ds(input_root, parameters, landgrid,
                                             array_1D=True)

    if not os.path.exists(outputpath):
        os.makedirs(outputpath)

    global_attr = {'product': 'GLDAS'}

    # get time series attributes from first day of data.
    data = input_dataset.read(startdate)
    ts_attributes = data.metadata
    if landgrid:
        grid = landgrid
    else:
        grid = BasicGrid(data.lon, data.lat)

    reshuffler = Img2Ts(input_dataset=input_dataset, outputpath=outputpath,
                        startdate=startdate, enddate=enddate, input_grid=grid,
                        imgbuffer=imgbuffer, cellsize_lat=5.0,
                        cellsize_lon=5.0, global_attr=global_attr, zlib=True,
                        unlim_chunksize=1000, ts_attributes=ts_attributes)
    reshuffler.calc()
コード例 #4
0
ファイル: test_interface.py プロジェクト: rameezu/gldas
def test_GLDAS_Noah_v1_025Ds_img_reading():
    parameter = ['086_L2', '086_L1', '085_L1', '138', '132', '051']
    img = GLDAS_Noah_v1_025Ds(data_path=os.path.join(os.path.dirname(__file__),
                                                     'test-data',
                                                     'GLDAS_NOAH_image_data'),
                              parameter=parameter,
                              subgrid=None,
                              array_1D=True)

    image = img.read(
        datetime(2015, 1, 1, 0))

    assert sorted(image.data.keys()) == sorted(parameter)
    assert image.timestamp == datetime(2015, 1, 1, 0)
    assert image.data['086_L1'][998529] == 30.7344
    assert image.data['086_L2'][998529] == 93.138
    assert image.data['085_L1'][206360] == 285.19
    assert image.data['138'][998529] == 237.27
    assert image.data['051'][998529] == 0
    assert image.lon.shape == (360 * 180 * (1 / 0.25)**2,)
    assert image.lon.shape == image.lat.shape
    assert sorted(list(image.metadata.keys())) == sorted(parameter)
    assert image.metadata['085_L1']['units'] == u'K'
    assert image.metadata['085_L1']['long_name'] == u'ST Surface temperature of soil K'