smos package

Subpackages

Submodules

smos.grid module

class smos.grid.EASE25CellGrid(bbox=None, only_land=False)[source]

Bases: CellGrid

CellGrid version of EASE25 Grid as used in SMOS IC

cut() CellGrid[source]

smos.interface module

class smos.interface.SMOSDs(data_path, ioclass, parameters=None, flatten=False, grid=<smos.grid.EASE25CellGrid object>, filename_templ=None, read_flags=(0, 1), float_fillval=nan, additional_kws=None)[source]

Bases: MultiTemporalImageBase

Class for reading SMOS images in nc format. Images are orgnaised in subdirs for each year.

Parameters:
  • data_path (str) – Path to the nc files

  • parameter (str or list, optional (default: None)) – one or list of parameters to read, see SMOS documentation for more information (default: ‘Soil_Moisture’).

  • flatten (bool, optional (default: False)) – If set then the data is read into 1D arrays. This is used to e.g reshuffle the data.

  • grid (pygeogrids.CellGrid, optional (default: EASE25CellGrid)) – Grid that the image data is organised on, by default the global EASE25 grid is used.

  • read_flags (tuple or None, optional (default: (0, 1))) – Filter values to read based on the selected QUALITY_FLAGS. Values for locations that are not assigned any of the here passed flags are replaces with NaN (by default only the missing-data, i.e. flag=2, locations are filtered out).

  • float_fillval (float or None, optional (default: np.nan)) – Fill Value for masked pixels, this is only applied to float variables. Therefore e.g. mask variables are never filled but use the fill value as in the data.

read(timestamp, **kwargs)[source]

Return an image for a specific timestamp.

Parameters:

timestamp (datetime.datetime) – Time stamp.

Returns:

image – pygeobase.object_base.Image object

Return type:

object

tstamps_for_daterange(start_date, end_date)[source]

return timestamps for daterange, :param start_date: start of date range :type start_date: datetime.datetime :param end_date: end of date range :type end_date: datetime.datetime

Returns:

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

Return type:

list

write_multiple(root_path, start_date, end_date, stackfile='stack.nc', **kwargs)[source]

Create multiple netcdf files or a netcdf stack in the passed directoy for a range of time stamps. Note that stacking gets slower when the stack gets larger. Empty images (if no original data can be loaded) are excluded here as well.

Parameters:
  • root (str) – Directory where the files / the stack are/is stored

  • start_date (datetime) – Start date of images to write down

  • end_date – Last date of images to write down

  • stackfile (str, optional (default: 'stack.nc')) – Name of the stack file to create in root_path. If no name is passed we create single images instead of a stack with the same name as the original images (faster).

  • kwargs – kwargs that are passed to the image reading function

class smos.interface.SMOSImg(filename, mode='r', parameters=None, flatten=False, grid=<smos.grid.EASE25CellGrid object>, read_flags=(0, 1), float_fillval=nan)[source]

Bases: ImageBase

Class for reading one SMOS netcdf image file.

Parameters:
  • filename (str) – filename of the SMOS nc image file

  • mode (str, optional (default: 'r')) – mode of opening the file, only ‘r’ is implemented at the moment

  • parameters (str or list, optional (default: None)) – one or list of parameters to read. We add ‘Quality_Flags’ if ‘read_flags’ is not None. All parameters are described in docs/varnames.rst. If None are passed, all parameters are read.

  • flatten (bool, optional (default: False)) – If set then the data is read into 1D arrays. This is used to e.g reshuffle the data.

  • grid (pygeogrids.CellGrid, optional (default: EASE25CellGrid)) – Grid that the image data is organised on, by default the global EASE25 grid is used.

  • read_flags (tuple or None, optional (default: (0, 1))) – Filter values to read based on the selected QUALITY_FLAGS. Values for locations that are not assigned any of the here passed flags are replaces with NaN (by default only the missing-data, i.e. flag=2, locations are filtered out). If None is passed, no flags are considered.

  • float_fillval (float or None, optional (default: np.nan)) – Fill Value for masked pixels, this is only applied to float variables. Therefore e.g. mask variables are never filled but use the fill value as in the data.

close()[source]

Close file.

flush()[source]

Flush data.

get_global_attrs(exclude=('history', 'NCO', 'netcdf_version_id', 'contact', 'institution', 'creation_time'))[source]
read(timestamp)[source]

Read a single SMOS image, if it exists, otherwise fill an empty image

Parameters:

timestamp (datetime) – Time stamp for the image to read.

read_masked_data(**kwargs)[source]

Read data of an image file and mask the data according to specifications.

Returns:

image – pygeobase.object_base.Image object

Return type:

object

write(image, **kwargs)[source]

Write the image to a separate output path. E.g. after reading only a subset of the parameters, or when reading a spatial subset (with a subgrid). If there is already a file, the new image is appended along the time dimension.

Parameters:
  • image (str) – Path to netcdf file to create.

  • kwargs – Additional kwargs are given to netcdf4.Dataset

class smos.interface.SMOSTs(ts_path, grid_path=None, index_add_time=False, drop_missing=True, **kwargs)[source]

Bases: GriddedNcOrthoMultiTs

read(*args, **kwargs)[source]

Read time series by grid point index, or by lonlat. Convert columns to ints if possible (if there are no Nans in it).

Parameters:
  • lon (float) – Location longitude

  • lat (float) – Location latitude

  • OR (..)

  • gpi (int) – Grid point Index

Returns:

df – Time Series data at the selected location

Return type:

pd.DataFrame

smos.misc module

smos.misc.get_first_last_day_images(img_path: str)[source]
smos.misc.read_summary_yml(path: str) dict[source]

Read image summary and return fields as dict.

smos.reshuffle module

smos.reshuffle.firstfile(input_root)[source]

Find the first file and read lat and lon and all variables

Parameters:

input_root (str) – Path to the root dir of image files

Returns:

  • firstfile (str) – Path to the first found image file in the input_root

  • vars (list) – List of variables in the file

smos.reshuffle.mkdate(datestring)[source]

Create date string. :param datestring: Date string. :type datestring: str

Returns:

datestr – Date string as datetime.

Return type:

datetime

smos.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

smos.reshuffle.str2bool(val)[source]

Module contents