sup3r.preprocessing.rasterizers.base.BaseRasterizer#
- class BaseRasterizer(loader, features='all', target=None, shape=None, time_slice=slice(None, None, None), threshold=None)[source]#
Bases:
Container
Container subclass with additional methods for extracting a spatiotemporal extent from contained data.
Note
This Rasterizer base class is for 3D rasterized data. This usually comes from NETCDF files but can also be cached H5 files saved from previously rasterized data. For 3D, whether H5 or NETCDF, the full domain will be rasterized automatically if no target / shape are provided.
- Parameters:
loader (Loader) – Loader type container with .data attribute exposing data to extract.
features (list | str) – Features to return in loaded dataset. If ‘all’ then all available features will be returned.
target (tuple) – (lat, lon) lower left corner of raster. Either need target+shape or raster_file.
shape (tuple) – (rows, cols) grid size. Either need target+shape or raster_file.
time_slice (slice | list) – Slice specifying extent and step of temporal extraction. e.g. slice(start, stop, step). If equal to slice(None, None, 1) the full time dimension is selected. Can be also be a list
[start, stop, step]
threshold (float) – Nearest neighbor euclidean distance threshold. If the coordinates are more than this value away from the target lat/lon, an error is raised.
Methods
check_target_and_shape
(full_lat_lon)The data is assumed to use a regular grid so if either target or shape is not given we can easily find the values that give the maximum extent.
get_closest_row_col
(lat_lon, target)Get closest indices to target lat lon
Get the 2D array of coordinates corresponding to the requested target and shape.
Get set of slices or indices selecting the requested region from the contained data.
post_init_log
([args_dict])Log additional arguments after initialization.
Get rasterized data.
wrap
(data)Return a
Sup3rDataset
object or tuple of such.Attributes
Return underlying data.
Return the grid_shape based on the raster_index, since self._grid_shape does not need to be provided as an input if the raster_file is.
Get 2D grid of coordinates with target as the lower left coordinate.
Get shape of underlying data.
Return the true value based on the closest lat lon instead of the user provided value self._target, which is used to find the closest lat lon.
Return time slice for rasterized time period.
- property data#
Return underlying data.
- Returns:
See also
- property time_slice#
Return time slice for rasterized time period.
- property target#
Return the true value based on the closest lat lon instead of the user provided value self._target, which is used to find the closest lat lon.
- property grid_shape#
Return the grid_shape based on the raster_index, since self._grid_shape does not need to be provided as an input if the raster_file is.
- property lat_lon#
Get 2D grid of coordinates with target as the lower left coordinate. (lats, lons, 2)
- post_init_log(args_dict=None)#
Log additional arguments after initialization.
- property shape#
Get shape of underlying data.
- wrap(data)#
Return a
Sup3rDataset
object or tuple of such. This is a tuple when the .data attribute belongs to aCollection
object likeBatchHandler
. Otherwise this isSup3rDataset
object, which is either a wrapped 2-tuple or 1-tuple (e.g.len(data) == 2
orlen(data) == 1)
. This is a 2-tuple when.data
belongs to a dual container object likeDualSampler
and a 1-tuple otherwise.
- check_target_and_shape(full_lat_lon)[source]#
The data is assumed to use a regular grid so if either target or shape is not given we can easily find the values that give the maximum extent.
- get_raster_index()[source]#
Get set of slices or indices selecting the requested region from the contained data.
- get_closest_row_col(lat_lon, target)[source]#
Get closest indices to target lat lon
- Parameters:
lat_lon (ndarray) – Array of lat/lon (spatial_1, spatial_2, 2) Last dimension in order of (lat, lon)
target (tuple) – (lat, lon) for target coordinate
- Returns:
row (int) – row index for closest lat/lon to target lat/lon
col (int) – col index for closest lat/lon to target lat/lon