pygmi.raster.datatypes#
Classes for raster data types and conversion routines.
Classes#
PyGMI Data Object. |
|
PyGMI Raster Metadata Object. |
Functions#
|
Create a raster transform from vector grid bounds and dxy. |
|
Find the intersection between some bounds and a dataset. |
|
Recursively deep copies a dictionary, safely handling affine.Affine objects. |
|
Convert an MxN numpy array into a PyGMI data object. |
|
Convert a PyGMI data object into an MxN numpy array. |
Module Contents#
- pygmi.raster.datatypes.bounds_to_transform(bounds, dxy)#
Create a raster transform from vector grid bounds and dxy.
This accounts for the situation where xmax and ymax need to be readjusted slightly because dxy does not divide perfectly into bounds. It also adds dxy/2 buffer. Therefore it cannot be used with raster bounds.
- Parameters:
bounds (tuple[float, float, float, float]) – Bounds of data as (left, bottom, right, top)
dxy (float) – Raster pixel size.
- Returns:
transform (
Affine) – Rasterio transform.shape (
tuple) – Tuple of rows, cols.
- Return type:
tuple[rasterio.Affine, tuple[float, float]]
- pygmi.raster.datatypes.bounds_intersection(dataset, bounds, showlog=print)#
Find the intersection between some bounds and a dataset.
- Parameters:
dataset – Rasterio dataset.
bounds (tuple[float, float, float, float] | None) – Bounds of data as (left, bottom, right, top).
showlog (collections.abc.Callable[..., None]) – Display information. The default is print.
- Returns:
window (
Windows) – Intersection area as window.newbounds (
tuple) – Intersection area as bounds.
- Return type:
tuple[rasterio.windows.Window | bool | None, tuple[float, float, float, float] | bool | None]
- class pygmi.raster.datatypes.Data#
PyGMI Data Object.
- data#
Array to contain raster data
- Type:
MaskedArray
- extent#
Extent of data as (left, right, bottom, top)
- Type:
tuple
- bounds#
Bounds of data as (left, bottom, right, top)
- Type:
tuple
- xdim#
X-dimension of grid cell
- Type:
float
- ydim#
Y-dimension of grid cell
- Type:
float
- dataid#
Band name or id
- Type:
str
- nodata#
Grid null or no data value
- Type:
float
- units#
Description of units to be used with colour bars
- Type:
str
- isrgb#
Flag to signify an RGB image.
- Type:
bool
- metadata#
Miscellaneous metadata for file.
- Type:
dictionary
- meta#
Rasterio metadata for file.
- Type:
dictionary
- filename#
Filename of file.
- Type:
str
- transform#
Rasterio transform. The default is None.
- Type:
listofAffine, optional
- crs#
Rasterio crs of data
- Type:
CRS
- datetime#
Date of dataset.
- Type:
date
- copy(data0=None, resetmeta=False)#
Make a deepcopy of the function.
- Parameters:
data0 (numpy.typing.NDArray | None) – Input data to replace old data. Must have same shape.
resetmeta (bool) – This will clear metadata during copy. The default is False.
- Returns:
PyGMI data type.
- Return type:
- in_bounds(bounds)#
Check if dataset is in bounds supplied.
- Parameters:
bounds (tuple[float, float, float, float]) – Bounds of data as (left, bottom, right, top)
- Returns:
True if within bounds, otherwise False.
- Return type:
bool
- meta_from_rasterio(dataset, bounds=None)#
Set transform, bounds, extent, xdim and ydim from a rasterio dataset.
- Parameters:
dataset – Rasterio dataset.
bounds (tuple[float, float, float, float] | None) – Bounds of data as (left, bottom, right, top). The default is None.
- modify_mask(mask, oper='or')#
Modify the existing mask with a new one.
The routine also fills the masked areas with nodata.
- Parameters:
mask (numpy.typing.NDArray) – Boolean array of new mask to modify old one.
oper (str) – Logical operation to be performed between masks. Can be ‘or’ or ‘and’. The default is ‘or’.
- plot(ax)#
Plot data.
- Parameters:
ax (matplotlib.axes.Axes) – Matplotlib axes for plot.
- set_mask(mask=None)#
Replace the existing mask with a new one.
The routine also fills the masked areas with nodata.
- Parameters:
mask (numpy.typing.NDArray) – Boolean array of new mask to modify old one.
- set_transform(xdim=None, xmin=None, ydim=None, ymax=None, transform=None, iraster=None, rows=None, cols=None)#
Set the transform, xdim, ydim, extent and bounds.
This requires either transform as input OR xdim, ydim, xmin, ymax.
- Parameters:
xdim (float | None) – X dimension. The default is None.
xmin (float | None) – X minimum. The default is None.
ydim (float | None) – Y dimension. The default is None.
ymax (float | None) – Y maximum. The default is None.
transform (list[float] | rasterio.Affine | None) – Transform. The default is None.
iraster (tuple[float, float, float, float] | None) – Incremental raster import, to import a section of a file. The tuple is (xoff, yoff, xsize, ysize). The default is None.
rows (int | None) – Rows in dataset. The default is None.
cols (int | None) – Columns in dataset. The default is None.
- to_mem()#
Create a rasterio memory file from one band.
- Returns:
Rasterio memory file.
- Return type:
MemoryFile
- get_vmin_vmax(std=2.5)#
Get vmin and vmax for use in imshow.
- Parameters:
std (float) – Multiplier for standard deviations to include about mean. The default is 2.5.
- Returns:
vmin (
float) – Value minimum.vmax (
float) – Value maximum.
- Return type:
tuple[float, float]
- get_boundary()#
Get raster boundary.
Sets self.geometry to a Polygon of the raster boundary.
- class pygmi.raster.datatypes.RasterMeta#
PyGMI Raster Metadata Object.
- sensor#
Sensor used to measure data.
- Type:
str
- filename#
Filename of file.
- Type:
str
- crs#
Rasterio crs of data.
- Type:
CRS
- bands#
List of bands in dataset.
- Type:
list
- tnames#
List fo bands to process.
- Type:
list
- banddata#
List of band data.
- Type:
list
- to_sutm#
Flag to convert a file to SUTM.
- Type:
bool
- datetime#
Date and time of dataset.
- Type:
date
- nodata#
Grid null or no data value.
- Type:
float
- pygmi.raster.datatypes.deepcopy_nested_dict(data)#
Recursively deep copies a dictionary, safely handling affine.Affine objects.
- pygmi.raster.datatypes.numpy_to_pygmi(data, pdata=None, dataid=None)#
Convert an MxN numpy array into a PyGMI data object.
For convenience, if pdata is defined, parameters from another dataset will be used (such as xdim, ydim etc).