pygeobase package¶
Submodules¶
pygeobase.io_base module¶
-
class
pygeobase.io_base.
GriddedBase
(path, grid, ioclass, mode='r', fn_format='{:04d}', ioclass_kws=None)[source]¶ Bases:
object
The GriddedBase class uses another IO class together with a grid object to read/write a dataset under the given path.
Parameters: - path (string) – Path to dataset.
- grid (pygeogrids.BasicGrid of CellGrid instance) – Grid on which the time series data is stored.
- ioclass (class) – IO class.
- mode (str, optional) – File mode and can be read ‘r’, write ‘w’ or append ‘a’. Default: ‘r’
- fn_format (str, optional) – The string format of the cell files. Default: ‘{:04d}’
- ioclass_kws (dict, optional) – Additional keyword arguments for the ioclass. Default: None
-
__enter__
()[source]¶ Context manager initialization.
Returns: self – self Return type: GriddedStaticBase object
-
__exit__
(exc_type, exc_value, traceback)[source]¶ Exit the runtime context related to this object. The file will be closed. The parameters describe the exception that caused the context to be exited.
exc_type :
exc_value :
traceback :
-
iter_gp
()[source]¶ Yield all values for all grid points.
Yields: - data (pandas.DataFrame) – Data set.
- gp (int) – Grid point.
-
class
pygeobase.io_base.
GriddedStaticBase
(path, grid, ioclass, mode='r', fn_format='{:04d}', ioclass_kws=None)[source]¶ Bases:
pygeobase.io_base.GriddedBase
The GriddedStaticBase class uses another IO class together with a grid object to read/write a dataset under the given path.
-
class
pygeobase.io_base.
GriddedTsBase
(path, grid, ioclass, mode='r', fn_format='{:04d}', ioclass_kws=None)[source]¶ Bases:
pygeobase.io_base.GriddedBase
The GriddedTsBase class uses another IO class together with a grid object to read/write a time series dataset under the given path.
-
iter_ts
()[source]¶ Yield time series for all grid points. :Yields: * data (object) –
pygeobase.object_base.TS object- gp (int) – Grid point.
-
-
class
pygeobase.io_base.
ImageBase
(filename, mode='r', **kwargs)[source]¶ Bases:
object
ImageBase class serves as a template for i/o objects used for reading and writing image data.
Parameters: - filename (str) – Filename path.
- mode (str, optional) – Opening mode. Default: r
-
read
(**kwargs)[source]¶ Read data of an image file.
Returns: image – pygeobase.object_base.Image object Return type: object
-
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
-
resample_data
(image, index, distance, windowRadius, **kwargs)[source]¶ Takes an image and resample (interpolate) the image data to arbitrary defined locations given by index and distance.
Parameters: - image (object) – pygeobase.object_base.Image object
- index (np.array) – Index into image data defining a look-up table for data elements used in the interpolation process for each defined target location.
- distance (np.array) – Array representing the distances of the image data to the arbitrary defined locations.
Returns: image – pygeobase.object_base.Image object
Return type:
-
class
pygeobase.io_base.
MultiTemporalImageBase
(path, ioclass, mode='r', fname_templ='', datetime_format='', subpath_templ=None, ioclass_kws=None, exact_templ=True, dtime_placeholder='datetime')[source]¶ Bases:
object
The MultiTemporalImageBase class make use of an ImageBase object to read/write a sequence of multi temporal images under a given path.
Parameters: - path (string) – Path to dataset.
- ioclass (class) – IO class.
- mode (str, optional) – File mode and can be read ‘r’, write ‘w’ or append ‘a’. Default: ‘r’
- fname_templ (str) – Filename template of the data to read. Default placeholder for parsing datetime information into the fname_templ is “{datetime}”. e.g. “ASCAT_{datetime}_image.nc” will be translated into the filename ASCAT_20070101_image.nc for the date 2007-01-01.
- datetime_format (str) – String specifying the format of the datetime object to be parsed into the fname_template. e.g. “%Y/%m” will result in 2007/01 for datetime 2007-01-01 12:15:00
- subpath_templ (list, optional) – If given it is used to generate a sub-paths from the given timestamp. Each item in the list represents one folder level. This can be used if the files for May 2007 are e.g. in folders 2007/05/ then the files can be accessed via the list [‘%Y’, ‘%m’].
- ioclass_kws (dict) – Additional keyword arguments for the ioclass.
- exact_templ (boolean, optional) – If True then the fname_templ matches the filename exactly. If False then the fname_templ will be used in glob to find the file.
- dtime_placeholder (str) – String used in fname_templ as placeholder for datetime. Default value is “datetime”.
-
__enter__
()[source]¶ Context manager initialization.
Returns: self – self Return type: GriddedBaseTs object
-
__exit__
(exc_type, exc_value, traceback)[source]¶ Exit the runtime context related to this object. The file will be closed. The parameters describe the exception that caused the context to be exited.
exc_type :
exc_value :
traceback :
-
daily_images
(day, **kwargs)[source]¶ Yield all images for a day.
Parameters: day (datetime.date) – Returns: img – pygeobase.object_base.Image object Return type: object
-
get_tstamp_from_filename
(filename)[source]¶ Return the timestamp contained in a given file name in accordance to the defined fname_templ.
Parameters: filename (string) – File name. Returns: tstamp – Time stamp according to fname_templ as datetime object. Return type: datetime.dateime
-
iter_images
(start_date, end_date, **kwargs)[source]¶ Yield all images for a given date range.
Parameters: - start_date (datetime.date or datetime.datetime) – start date
- end_date (datetime.date or datetime.datetime) – end date
Returns: image – pygeobase.object_base.Image object
Return type:
-
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 all valid timestamps in a given date range. This method must be implemented if iteration over images should be possible.
Parameters: - start_date (datetime.date or datetime.datetime) – start date
- end_date (datetime.date or datetime.datetime) – end date
Returns: dates – list of datetimes
Return type:
-
write
(timestamp, data, **kwargs)[source]¶ Write image data for a given timestamp.
Parameters: - timestamp (datetime.datetime) – exact timestamp of the image
- data (object) – pygeobase.object_base.Image object
-
class
pygeobase.io_base.
StaticBase
(filename, mode='r', **kwargs)[source]¶ Bases:
object
The StaticBase class serves as a template for i/o objects used in GriddedStaticBase.
Parameters: - filename (str) – File name.
- mode (str, optional) – Opening mode. Default: r
-
read
(gpi)[source]¶ Read data for given grid point.
Parameters: gpi (int) – Grid point index. Returns: data – Data set. Return type: numpy.ndarray
-
write
(data)[source]¶ Write data.
Parameters: data (numpy.ndarray) – Data records.
-
class
pygeobase.io_base.
TsBase
(filename, mode='r', **kwargs)[source]¶ Bases:
object
The TsBase class serves as a template for i/o objects used in GriddedTsBase.
Parameters: - filename (str) – File name.
- mode (str, optional) – Opening mode. Default: r
pygeobase.object_base module¶
-
class
pygeobase.object_base.
Image
(lon, lat, data, metadata, timestamp, timekey=None)[source]¶ Bases:
object
The Image class represents the base object of an image.
Parameters: - lon (numpy.array) – array of longitudes
- lat (numpy.array) – array of latitudes
- data (dict) – dictionary of numpy arrays that holds the image data for each variable of the dataset
- metadata (dict) – dictionary that holds metadata
- timestamp (datetime.datetime) – exact timestamp of the image
- timekey (str, optional) – Key of the time variable, if available, stored in data dictionary.
-
class
pygeobase.object_base.
TS
(gpi, lon, lat, data, metadata)[source]¶ Bases:
object
The TS class represents the base object of a time series.
Parameters: - lon (float) – Longitude of the time series
- lat (float) – Latitude of the time series
- data (pandas.DataFrame) – Pandas DataFrame that holds data for each variable of the time series
- metadata (dict) – dictionary that holds metadata