pygmi.raster.misc#
Miscellaneous functions for raster data.
Functions#
|
Aspect of a dataset. |
|
Check dataid for duplicates and renames where necessary. |
|
Blinn shader - used for sun shading. |
|
Cut a raster dataset. |
|
Fill array using closest value. |
|
Histogram Compaction. |
|
Histogram Equalization. |
|
Image to RGB. |
|
Layer stack datasets found in a single PyGMI data object. |
|
Normalise array vector between 0 and 1. |
|
Normalise array vector between 1 and 255. |
Module Contents#
- pygmi.raster.misc.aspect2(data)#
Aspect of a dataset.
- Parameters:
data (numpy.typing.NDArray) – Input data used for the aspect calculation
- Returns:
adeg (
ndarray) – aspect in degreesdzdx (
ndarray) – gradient in x directiondzdy (
ndarray) – gradient in y direction
- Return type:
tuple[numpy.ma.MaskedArray, numpy.typing.NDArray, numpy.typing.NDArray]
- pygmi.raster.misc.check_dataid(out)#
Check dataid for duplicates and renames where necessary.
- Parameters:
out (list[pygmi.raster.datatypes.Data]) – PyGMI raster data.
- Returns:
PyGMI raster data.
- Return type:
listofData
- pygmi.raster.misc.currentshader(data, cell=1.0, theta=np.pi / 4.0, phi=-np.pi / 4.0, alpha=1.0)#
Blinn shader - used for sun shading.
- Parameters:
data (numpy.typing.NDArray | numpy.ma.MaskedArray) – Dataset to be shaded.
cell (float) – between 1 and 100 - controls sunshade detail.
theta (float) – sun elevation (also called g in code below)
phi (float) – azimuth
alpha (float) – how much incident light is reflected (0 to 1)
- Returns:
array containing the shaded results.
- Return type:
MaskedArray
- pygmi.raster.misc.cut_raster(data, ibnd, showlog=print, deepcopy=True)#
Cut a raster dataset.
- Parameters:
data (list[pygmi.raster.datatypes.Data]) – Input PyGMI Dataset
ibnd (str | geopandas.GeoDataFrame | tuple) – shapefile or GeoDataFrame or tuple of bounds used to cut data.
showlog (collections.abc.Callable[..., None]) – Function for printing text. The default is print.
deepcopy (bool) – Make a copy of the data array before use, by default True.
- Returns:
Cut version of Dataset
- Return type:
listofData
- pygmi.raster.misc.fill_nd_closest(arr)#
Fill array using closest value.
- Parameters:
arr (numpy.ma.MaskedArray) – Input array.
- Returns:
Filled array.
- Return type:
NDArray
- pygmi.raster.misc.histcomp(img, perc=5.0, uperc=None)#
Histogram Compaction.
This compacts a % of the outliers in data, allowing for a cleaner, linear representation of the data.
- Parameters:
img (numpy.ma.MaskedArray) – data to compact
perc (float) – percentage of histogram to clip. If uperc is not None, then this is the lower percentage, default is 5.
uperc (float | None) – upper percentage to clip. If uperc is None, then it is set to the same value as perc, default is None
- Returns:
img2 (
MaskedArray) – compacted arraysvalue (
float) – Start valueevalue (
float) – End value
- Return type:
tuple[numpy.ma.MaskedArray, float, float]
- pygmi.raster.misc.histeq(img, nbrbins=32768)#
Histogram Equalization.
Equalizes the histogram to colours. This allows for seeing as much data as possible in the image, at the expense of knowing the real value of the data at a point. It bins the data equally - flattening the distribution.
- Parameters:
img (numpy.ma.MaskedArray) – input data to be equalised
nbrbins (int) – number of bins to be used in the calculation, default is 32768
- Returns:
output data
- Return type:
MaskedArray
- pygmi.raster.misc.img2rgb(img, cbar=colormaps['jet'])#
Image to RGB.
convert image to 4 channel rgba colour image.
- Parameters:
img (numpy.typing.NDArray) – array to be converted to rgba image.
cbar (
matplotlib colour map) – colormap to apply to the image, default is jet.
- Returns:
Output RGBA image.
- Return type:
ndarray
- pygmi.raster.misc.lstack(dat, *, piter=ProgressBarText().iter, dxy=None, showlog=print, commonmask=False, masterid=None, nodeepcopy=False, resampling='cubic_spline', checkdataid=True)#
Layer stack datasets found in a single PyGMI data object.
The aim is to ensure that all datasets have the same number of rows and columns.
- Parameters:
dat (list[pygmi.raster.datatypes.Data]) – data object which stores datasets
piter (collections.abc.Iterable) – Progress bar iterator. The default is None.
dxy (float | None) – Cell size. The default is None.
showlog (collections.abc.Callable[..., None]) – Display information. The default is print.
commonmask (bool) – Create a common mask for all bands. The default is False.
masterid (str | None) – ID of master dataset. The default is None.
nodeepcopy (bool) – Flag to avoid making a copy of the input data, by default False.
resampling (str) – The resampling to be used on output date. The default is ‘nearest’.
checkdataid (bool) – Check to make sure there are no duplicate data ids. The default is True
- Returns:
list of raster data.
- Return type:
listofData
- pygmi.raster.misc.norm2(dat, datmin=None, datmax=None)#
Normalise array vector between 0 and 1.
- Parameters:
dat (numpy.ma.MaskedArray) – array to be normalised
datmin (float | None) – data minimum, default is None
datmax (float | None) – data maximum, default is None
- Returns:
normalised array
- Return type:
MaskedArray
- pygmi.raster.misc.norm255(dat)#
Normalise array vector between 1 and 255.
- Parameters:
dat (numpy.typing.NDArray) – array to be normalised.
- Returns:
normalised array
- Return type:
ndarrayof8 bit integers