smos package¶
Subpackages¶
Submodules¶
smos.grid module¶
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:
MultiTemporalImageBaseClass 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:
- 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:
- 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:
ImageBaseClass 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.
- 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:
- 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
smos.misc module¶
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