bounded_grid
- class gridkit.bounded_grid.BoundedGrid(data: ndarray, *args, bounds: tuple, nodata_value=None, prevent_copy: bool = False, **kwargs)[source]
Bases:
object
- property data
- property dtype
- property bounds: tuple
Raster Bounds
- Returns:
The bounds of the data in (left, bottom, right, top) or equivalently (min-x, min-y, max-x, max-y)
- Return type:
tuple
- property mpl_extent: tuple
Raster Bounds
- Returns:
The extent of the data as defined expected by matplotlib in (left, right, bottom, top) or equivalently (min-x, max-x, min-y, max-y)
- Return type:
tuple
- property corners
- property width
Raster width
- Returns:
The number of grid cells in x-direction
- Return type:
int
- property height
Raster height
- Returns:
The number of grid cells in y-direction
- Return type:
int
- property cellsize
Get the gridsize in (dx, dy)
- property nr_cells
Number of cells
- Returns:
The total number of cells in the grid
- Return type:
int
- abstract crop(new_bounds, bounds_crs=None)[source]
Cut out a slice of data contained within the supplied bounds.
- Parameters:
new_bounds (Tuple(minx, miny, maxx, maxy)) – The bounds defining the area to crop, in (minx, miny, maxx, maxy).
bounds_crs (pyproj.CRS (optional)) – The bounds defining the extent of the cropped data. The value can be anything accepted by pyproj.CRS.from_user_input().
- Returns:
A BoundedGrid containing the data included in the cropped area contained within the bounds.
- Return type:
class: BoundedGrid
- property indices
Return the indices within the bounds of the data
- value(index=None, oob_value=None)[source]
Return the value at the given cell index.
- Parameters:
index (
GridIndex
(optional)) – The index of the cell(s) of which to return the value. If not supplied, all values will be returned in a flattened array.oob_value (
float
(optional)) – The value assigned to values that are ‘out of bounds’. I.e. the value assigned toindex
entries not covered by the data. Default: numpy.nan
- Returns:
The values at the supplied index locations
- Return type:
numpy.ndarray
- interp_nodata(method='linear', in_place=False)[source]
Interpolate the cells containing nodata, if they are inside the convex hull of cells that do contain data.
- Parameters:
method (
str
) – The interpolation method to be used. Options are (“nearest”, “linear”, “cubic”). Default: “linear”.in_place (
bool
) – Boolean flag determining whether to fill the nodata values in-place. In-memory values are modified if in_place is Ture. A copy of the grid is made where nodata values are filled if in_place is False.
- Returns:
A copy of the grid with interpolated values.
- Return type:
tuple
- interpolate(sample_points, method: Literal['nearest', 'bilinear', 'inverse_distance'] = 'nearest', **interp_kwargs)[source]
Interpolate the value at the location of
sample_points
.Points that are outside of the bounds of the data are assigned self.nodata_value, or ‘NaN’ if no nodata value is set.
- Parameters:
sample_points (
numpy.ndarray
) – The coordinates of the points at which to sample the datamethod (
str
, ‘nearest’, ‘bilinear’, optional) – The interpolation method used to determine the value at the supplied sample_points. Supported methods: - “nearest”, for nearest neigbour interpolation, effectively sampling the value of the data cell containing the point - “bilinear”, linear interpolation using the four cells surrounding the point - “inverse_distance”, weighted inverse distance using the 4,3,6 nearby cells surrounding the point for Rect, Hex and Rect grid respectively. Default: “nearest”**interp_kwargs (dict) – The keyword argument passed to the interpolation function corresponding to the specified method
- Returns:
The interpolated values at the supplied points
- Return type:
numpy.ndarray
- argmax(*args, **kwargs)
- argmin(*args, **kwargs)
- max(*args, **kwargs)
- mean(*args, **kwargs)
- median(*args, **kwargs)
- min(*args, **kwargs)
- resample(alignment_grid, method='nearest', **interp_kwargs)[source]
Resample the grid onto another grid. This will take the locations of the grid cells of the other grid (here called
alignment_grid
) and determine the value on these location based on the values of the original grid (self
).- The steps are as follows:
Transform the bounds of the original data to the CRS of the alignment grid (if not already the same) No transformation is done if any of the grids has no CRS set.
Find the cells of the alignment grid within these transformed bounds
Find the cells of the original grid that are nearby each of the centroids of the cells found in 2. How many nearby cells are selected depends on the selected
method
Interpolate the values using the supplied
method
at each of the centroids of the alignment grid cells selected in 2.Create a new bounded grid using the attributes of the alignment grid
- Parameters:
alignment_grid (
BaseGrid
) – The grid with the desired attributes on which to resample.method (
str
, ‘nearest’, ‘bilinear’, ‘inverse_distance’, optional) – The interpolation method used to determine the value at the supplied sample_points. Supported methods: - “nearest”, for nearest neigbour interpolation, effectively sampling the value of the data cell containing the point - “bilinear”, linear interpolation using the 4,3,6 nearby cells surrounding the point for Rect, Hex and Rect grid respectively. - “inverse_distance”, weighted inverse distance using the 4,3,6 nearby cells surrounding the point for Rect, Hex and Rect grid respectively. Default: “nearest”**interp_kwargs (dict) – The keyword argument passed to the interpolation function corresponding to the specified method
- Returns:
The interpolated values at the supplied points
- Return type:
- std(*args, **kwargs)
- sum(*args, **kwargs)