gldas package

Submodules

gldas.download module

Module managing download of NOAH GLDAS data.

gldas.download.get_first_formatted_dir_in_dir(folder, fmt)[source]

Get the (alphabetically) first directory in a directory which can be formatted according to fmt.

Parameters
  • folder (str) – Folder name.

  • fmt (str) – Format string.

Returns

first_elem – First formatted directory.

Return type

str

gldas.download.get_first_gldas_folder(root, subpaths)[source]

Get first GLDAS folder name.

Parameters
  • root (str) – Root path.

  • subpaths (list of str) – Subpath information.

Returns

directory – First folder name.

Return type

str

gldas.download.get_gldas_start_date(product)[source]

Get NOAH GLDAS start date.

Parameters

product (str) – Product name.

Returns

start_date – Start date of NOAH GLDAS product.

Return type

datetime

gldas.download.get_last_formatted_dir_in_dir(folder, fmt)[source]

Get the (alphabetically) last directory in a directory which can be formatted according to fmt.

Parameters
  • folder (str) – Folder name.

  • fmt (str) – Format string.

Returns

last_elem – Last formatted directory.

Return type

str

gldas.download.get_last_gldas_folder(root, subpaths)[source]

Get last GLDAS folder name.

Parameters
  • root (str) – Root path.

  • subpaths (list of str) – Subpath information.

Returns

directory – Last folder name.

Return type

str

gldas.download.gldas_folder_get_version_first_last(root, fmt=None, subpaths=['{time:%Y}', '{time:%j}'])[source]

Get product version and first and last product which exists under the root folder.

Parameters
  • root (string) – Root folder on local filesystem

  • fmt (string, optional) – Formatting string (default: “GLDAS_NOAH025_3H.A{time:%Y%m%d.%H%M}.0{version:2s}.nc4”)

  • subpaths (list, optional) – Format of the subdirectories under root (default: [‘{:%Y}’, ‘{:%j}’]).

Returns

  • version (string) – Found product version

  • start (datetime.datetime) – First found product datetime

  • end (datetime.datetime) – Last found product datetime

gldas.download.main(args)[source]

Main routine used for command line interface.

Parameters

args (list of str) – Command line arguments.

gldas.download.parse_args(args)[source]

Parse command line parameters for recursive download.

Parameters

args (list of str) – Command line parameters as list of strings.

Returns

args – Command line arguments.

Return type

argparse.Namespace

gldas.download.run()[source]

gldas.grid module

gldas.grid.GLDAS025Cellgrid()[source]

Alias to create a global 0.25 DEG grid without gaps w. 5 DEG cells

gldas.grid.GLDAS025Grids(only_land=False)[source]

Create global 0.25 DEG gldas grids (origin in bottom left)

Parameters

only_land (bool, optional (default: False)) – Uses the land mask to reduce the GLDAS 0.25DEG land grid to land points only.

Returns

grid – Either a land grid or a global grid

Return type

pygeogrids.CellGrid

gldas.grid.GLDAS025LandGrid()[source]

Alias to create a global 0.25 DEG grid over land only w. 5 DEG cells

gldas.grid.load_grid(land_points=True, bbox=None)[source]

Load gldas grid.

Parameters
  • land_points (bool, optional (default: True)) – Reshuffle only land points

  • bbox (tuple, optional (default: True)) – (min_lat, min_lon, max_lat, max_lon) Bounding box to limit reshuffling to.

gldas.grid.subgrid4bbox(grid, min_lon, min_lat, max_lon, max_lat)[source]

Select a spatial subset for the grid by bound box corner points

Parameters
  • grid (BasicGrid or CellGrid) – Grid object to trim.

  • min_lon (float) – Lower left corner longitude

  • min_lat (float) – Lower left corner latitude

  • max_lon (float) – Upper right corner longitude

  • max_lat (float) – Upper right corner latitude

Returns

subgrid – Subset of the input grid.

Return type

BasicGrid or CellGrid

gldas.interface module

class gldas.interface.GLDASTs(ts_path, grid_path=None, **kwargs)[source]

Bases: GriddedNcOrthoMultiTs

class gldas.interface.GLDAS_Noah_v1_025Ds(data_path, parameter='086_L1', subgrid=None, array_1D=False)[source]

Bases: MultiTemporalImageBase

Class for reading GLDAS images in grib format.

Parameters
  • data_path (string) – path to the grib files

  • parameter (string or list, optional) –

    one or list of [‘001’, ‘011’, ‘032’, ‘051’, ‘057’, ‘065’, ‘071’,

    ’085_L1’, ‘085_L2’, ‘085_L3’, ‘085_L4’, ‘086_L1’, ‘086_L2’, ‘086_L3’, ‘086_L4’, ‘099’, ‘111’, ‘112’, ‘121’, ‘122’, ‘131’, ‘132’, ‘138’, ‘155’, ‘204’, ‘205’, ‘234’, ‘235’]

    parameters to read, see GLDAS documentation for more information Default : ‘086_L1’

  • subgrid (Cell Grid) – Subgrid of the global GLDAS Grid to use for reading image data (e.g only land points)

  • array_1D (boolean, optional) – if set then the data is read into 1D arrays. Needed for some legacy code.

tstamps_for_daterange(start_date, end_date)[source]

return timestamps for daterange,

Parameters
  • start_date (datetime) – start of date range

  • end_date (datetime) – end of date range

Returns

timestamps – list of datetime objects of each available image between start_date and end_date

Return type

list

class gldas.interface.GLDAS_Noah_v1_025Img(filename, mode='r', parameter='086_L1', subgrid=None, array_1D=False)[source]

Bases: ImageBase

Class for reading one GLDAS Noah v1 grib file in 0.25 deg grid.

Parameters
  • filename (string) – filename of the GLDAS grib file

  • mode (string, optional) – mode of opening the file, only ‘r’ is implemented at the moment

  • parameter (string or list, optional) –

    one or list of [‘001’, ‘011’, ‘032’, ‘051’, ‘057’, ‘065’, ‘071’,

    ’085_L1’, ‘085_L2’, ‘085_L3’, ‘085_L4’, ‘086_L1’, ‘086_L2’, ‘086_L3’, ‘086_L4’, ‘099’, ‘111’, ‘112’, ‘121’, ‘122’, ‘131’, ‘132’, ‘138’, ‘155’, ‘204’, ‘205’, ‘234’, ‘235’]

    parameters to read, see GLDAS documentation for more information Default : ‘086_L1’

  • subgrid (Cell Grid) – Subgrid of the global GLDAS Grid to use for reading image data (e.g only land points)

  • array_1D (boolean, optional) – if set then the data is read into 1D arrays. Needed for some legacy code.

close()[source]

Close file.

flush()[source]

Flush data.

read(timestamp=None)[source]

Read data of an image file.

Returns

image – pygeobase.object_base.Image object

Return type

object

write(data)[source]

Write data to an image file.

Parameters

image (object) – pygeobase.object_base.Image object

class gldas.interface.GLDAS_Noah_v21_025Ds(data_path, parameter='SoilMoi0_10cm_inst', subgrid=None, array_1D=False)[source]

Bases: MultiTemporalImageBase

Class for reading GLDAS v2.1 images in nc format.

Parameters
  • data_path (string) – Path to the nc files

  • parameter (string or list, optional) – one or list of parameters to read, see GLDAS v2.1 documentation for more information (default: ‘SoilMoi0_10cm_inst’).

  • subgrid (Cell Grid) – Subgrid of the global GLDAS Grid to use for reading image data (e.g only land points)

  • array_1D (boolean, optional) – If set then the data is read into 1D arrays. Needed for some legacy code.

tstamps_for_daterange(start_date, end_date)[source]

return timestamps for daterange,

Parameters
  • start_date (datetime) – start of date range

  • end_date (datetime) – end of date range

Returns

timestamps – list of datetime objects of each available image between start_date and end_date

Return type

list

class gldas.interface.GLDAS_Noah_v21_025Img(filename, mode='r', parameter='SoilMoi0_10cm_inst', subgrid=None, array_1D=False)[source]

Bases: GLDAS_Noah_v2_025Img

class gldas.interface.GLDAS_Noah_v2_025Img(filename, mode='r', parameter='SoilMoi0_10cm_inst', subgrid=None, array_1D=False)[source]

Bases: ImageBase

Class for reading one GLDAS Noah v2.1 nc file in 0.25 deg grid.

close()[source]

Close file.

flush()[source]

Flush data.

read(timestamp=None)[source]

Read data of an image file.

Returns

image – pygeobase.object_base.Image object

Return type

object

write(data)[source]

Write data to an image file.

Parameters

image (object) – pygeobase.object_base.Image object

gldas.reshuffle module

Module for a command line interface to convert the GLDAS data into a time series format using the repurpose package

gldas.reshuffle.get_filetype(inpath)[source]

Tries to find out the file type by searching for grib or nc files two subdirectories into the passed input path. If function fails, netcdf is assumed.

Parameters

input_root (str) – Input path where GLDAS data was downloaded

Returns

filetype – File type string.

Return type

str

gldas.reshuffle.main(args)[source]

Main routine used for command line interface.

Parameters

args (list of str) – Command line arguments.

gldas.reshuffle.mkdate(datestring)[source]

Create date string.

Parameters

datestring (str) – Date string.

Returns

datestr – Date string as datetime.

Return type

datetime

gldas.reshuffle.parse_args(args)[source]

Parse command line parameters for recursive download.

Parameters

args (list of str) – Command line parameters as list of strings.

Returns

args – Command line arguments.

Return type

argparse.Namespace

gldas.reshuffle.reshuffle(input_root, outputpath, startdate, enddate, parameters, input_grid=None, imgbuffer=50)[source]

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

  • input_grid (CellGrid, optional (default: None)) – Local input grid to read data for. If None is passed, we create the grid from data.

  • imgbuffer (int, optional) – How many images to read at once before writing time series.

gldas.reshuffle.run()[source]
gldas.reshuffle.str2bool(val)[source]

gldas.utils module

gldas.utils.deprecated(message: Optional[str] = None)[source]

Decorator for classes or functions to mark them as deprecated. If the decorator is applied without a specific message (@deprecated()), the default warning is shown when using the function/class. To specify a custom message use it like:

@deprecated(‘Don’t use this function anymore!’).

Parameters

message (str, optional (default: None)) – Custom message to show with the DeprecationWarning.

Module contents