pygmi.raster.misc#

Miscellaneous functions.

Functions#

aspect2(data)

Aspect of a dataset.

check_dataid(out)

Check dataid for duplicates and renames where necessary.

currentshader(data[, cell, theta, phi, alpha])

Blinn shader - used for sun shading.

cut_raster(data, ibnd[, showlog, deepcopy])

Cut a raster dataset.

histcomp(img[, perc, uperc])

Histogram Compaction.

histeq(img[, nbrbins])

Histogram Equalization.

img2rgb(img[, cbar])

Image to RGB.

lstack(dat, *[, piter, dxy, showlog, commonmask, ...])

Layer stack datasets found in a single PyGMI data object.

norm2(dat[, datmin, datmax])

Normalise array vector between 0 and 1.

norm255(dat)

Normalise array vector between 1 and 255.

Module Contents#

pygmi.raster.misc.aspect2(data)#

Aspect of a dataset.

Parameters:

data (numpy MxN array) – input data used for the aspect calculation

Returns:

  • adeg (numpy masked array) – aspect in degrees

  • dzdx (numpy array) – gradient in x direction

  • dzdy (numpy array) – gradient in y direction

pygmi.raster.misc.check_dataid(out)#

Check dataid for duplicates and renames where necessary.

Parameters:

out (list of pygmi.raster.datatypes.Data) – PyGMI raster data.

Returns:

out – PyGMI raster data.

Return type:

list of pygmi.raster.datatypes.Data

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 array) – 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:

R – array containing the shaded results.

self.phi = -np.pi/4. self.theta = np.pi/4. self.cell = 100. self.alpha = .0

Return type:

numpy array

pygmi.raster.misc.cut_raster(data, ibnd, showlog=print, deepcopy=True)#

Cut a raster dataset.

Parameters:
  • data (list of pygmi.raster.datatypes.Data) – PyGMI Dataset

  • ibnd (str or GeoDataFrame, or tuple of bounds) – shapefile or GeoDataFrame used to cut data.

  • showlog (function, optional) – Function for printing text. The default is print.

  • deepcopy (bool) – Make a copy of the data array before use.

Returns:

data – PyGMI Dataset

Return type:

list of pygmi.raster.datatypes.Data

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 array) – 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) – upper percentage to clip. If uperc is None, then it is set to the same value as perc, default is None

Returns:

  • img2 (numpy array) – compacted array

  • svalue (float) – Start value

  • evalue (float) – End value

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 array) – input data to be equalised

  • nbrbins (integer) – number of bins to be used in the calculation, default is 32768

Returns:

im2 – output data

Return type:

numpy array

pygmi.raster.misc.img2rgb(img, cbar=colormaps['jet'])#

Image to RGB.

convert image to 4 channel rgba colour image.

Parameters:
  • img (numpy array) – array to be converted to rgba image.

  • cbar (matplotlib colour map) – colormap to apply to the image, default is jet.

Returns:

im2 – output rgba image

Return type:

numpy array

pygmi.raster.misc.lstack(dat, *, piter=None, dxy=None, showlog=print, commonmask=False, masterid=None, nodeepcopy=False, resampling='nearest', 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 of pygmi.raster.datatypes.Data) – data object which stores datasets

  • piter (function, optional) – Progress bar iterator. The default is None.

  • dxy (float, optional) – Cell size. The default is None.

  • showlog (function, optional) – Display information. The default is print.

  • commonmask (bool, optional) – Create a common mask for all bands. The default is False.

  • masterid (str, optional) – ID of master dataset. The default is None.

Returns:

out – data object which stores datasets

Return type:

list of pygmi.raster.datatypes.Data

pygmi.raster.misc.norm2(dat, datmin=None, datmax=None)#

Normalise array vector between 0 and 1.

Parameters:
  • dat (numpy array) – array to be normalised

  • datmin (float) – data minimum, default is None

  • datmax (float) – data maximum, default is None

Returns:

out – normalised array

Return type:

numpy array of floats

pygmi.raster.misc.norm255(dat)#

Normalise array vector between 1 and 255.

Parameters:

dat (numpy array) – array to be normalised.

Returns:

out – normalised array

Return type:

numpy array of 8 bit integers