pygmi.raster.datatypes#
Class for raster data types and conversion routines.
Classes#
PyGMI Data Object. |
|
PyGMI Raster Metadata Object. |
Functions#
|
Convert an MxN numpy array into a PyGMI data object. |
|
Convert a PyGMI data object into an MxN numpy array. |
|
Create a raster transform from vector grid bounds and dxy. |
|
Find the intersection between some bounds and a dataset. |
Module Contents#
- 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).
- Parameters:
data (numpy array) – MxN array
pdata (pygmi.raster.datatypes.Data) – PyGMI raster dataset
dataid (str or None) – name for the band of data.
- Returns:
tmp – PyGMI raster dataset
- Return type:
- pygmi.raster.datatypes.pygmi_to_numpy(tmp)#
Convert a PyGMI data object into an MxN numpy array.
- Parameters:
tmp (pygmi.raster.datatypes.Data) – PyGMI raster dataset
- Returns:
MxN numpy array
- Return type:
numpy array
- 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) – Bounds of data as (left, bottom, right, top)
dxy (float) – Raster pixel size.
- Returns:
transform (list of Affine) – rasterio transform.
shape (tuple) – tuple of rows, cols.
- pygmi.raster.datatypes.bounds_intersection(dataset, bounds, showlog=print)#
Find the intersection between some bounds and a dataset.
- Parameters:
dataset (rasterio dataset) – Rasterio dataset.
bounds (tuple) – Bounds of data as (left, bottom, right, top).
showlog (function, optional) – Display information. The default is print.
- Returns:
window (rasterio window) – Intersection area as window.
newbounds (tuple) – Intersection area as bounds.
- class pygmi.raster.datatypes.Data#
PyGMI Data Object.
- data#
array to contain raster data
- Type:
numpy masked array
- 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:
list of Affine, optional
- crs#
rasterio crs of data
- Type:
CRS
- datetime#
Date of dataset.
- Type:
date
- copy(resetmeta=False)#
Make a deepcopy of the function.
- Parameters:
resetmeta (bool, optional) – This will clear metadata during copy. The default is False.
- Returns:
data – PyGMI data type.
- Return type:
- in_bounds(bounds)#
Check if dataset is in bounds supplied.
- Parameters:
bounds (tuple) – 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) – Rasterio dataset.
bounds (tuple, optional) – Bounds of data as (left, bottom, right, top). The default is None.
- Return type:
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 (array) – Boolean array of new mask to modify old one.
oper (str, optional) – Logical operation to be performed between masks. Can be ‘or’ or ‘and’. The default is ‘or’.
- Return type:
None.
- set_mask(mask)#
Replace the existing mask with a new one.
The routine also fills the masked areas with nodata.
- Parameters:
mask (array) – Boolean array of new mask to modify old one.
- Return type:
None.
- 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, optional) – x dimension. The default is None.
xmin (float, optional) – x minimum. The default is None.
ydim (float, optional) – y dimension. The default is None.
ymax (float, optional) – y maximum. The default is None.
transform (list of Affine, optional) – transform. The default is None.
iraster (None or tuple) – Incremental raster import, to import a section of a file. The tuple is (xoff, yoff, xsize, ysize). The default is None.
rows (int, optional) – rows in dataset. The default is None.
cols (int, optional) – columns in dataset. The default is None.
- Return type:
None.
- to_mem()#
Create a rasterio memory file from one band.
- Returns:
raster – rasterio memory file.
- Return type:
MemoryFile
- get_vmin_vmax(std=2.5)#
Get vmin and vmax for use in imshow.
- Parameters:
std (float, optional) – Multiplier for standard deviations to include about mean. The default is 2.5.
- Returns:
vmin (float) – Value minimum.
vmax (float) – Value maximum.
- 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
- fromData(dat)#
Populate class from a Data class.
- Parameters:
dat (pygmi.raster.datatypes.Data) – PyGMI data object.
- Return type:
None.