pygmi.raster package¶
Submodules¶
pygmi.raster.anaglyph module¶
Anaglyph routine.
- class pygmi.raster.anaglyph.MyMplCanvas(parent=None)¶
Bases:
FigureCanvasQTAgg
Canvas for the actual plot.
- axes¶
- Type:
matplotlib subplot
- parent¶
reference to the parent routine
- Type:
parent
- update_atype(atype='dubois')¶
Update anaglyph type.
- Parameters:
atype (str, optional) – Anaglyph type. The default is ‘dubois’.
- Return type:
None.
- update_colors(doshade=False, cmap=<matplotlib.colors.LinearSegmentedColormap object>, atype='dubois')¶
Update colors.
- Parameters:
doshade (bool, optional) – Option to choose sunshading. The default is False.
cmap (matplotlib.colors.LinearSegmentedColormap, optional) – Matplotlib colormap. The default is jet.
atype (str, optional) – Anaglyph type. The default is ‘dubois’.
- Return type:
None.
- update_contours(data1, scale=7, rotang=10)¶
Update the contour plot.
- Parameters:
data1 (PyGMI raster data.) – raster dataset to be used in contouring.
scale (float, optional) – Scale. The default is 7.
rotang (float, optional) – Rotation in degrees. The default is 10.
- Return type:
None.
- update_raster(data1, scale=7, rotang=10, atype='dubois', cmap=<matplotlib.colors.LinearSegmentedColormap object>, shade=False)¶
Update the raster plot.
- Parameters:
data1 (PyGMI raster Data) – raster dataset to be used in contouring
scale (float, optional) – Scale. The default is 7.
rotang (float, optional) – Rotation in degrees. The default is 10.
atype (str, optional) – Anaglyph type. The default is ‘dubois’.
cmap (matplotlib.colors.LinearSegmentedColormap, optional) – Matplotlib colormap. The default is jet.
shade (bool, optional) – Option to choose sunshading. The default is False.
- Return type:
None.
- class pygmi.raster.anaglyph.PlotAnaglyph(parent=None)¶
Bases:
ContextModule
Graph Window - The QDialog window which will contain our image.
- change_all()¶
Update from all combos.
- Return type:
None.
- change_atype()¶
Update anaglyph type.
- Return type:
None.
- change_colors()¶
Update colour bar.
- Return type:
None.
- change_contours()¶
Update contours.
- Return type:
None.
- change_image()¶
Change Image, setting defaults.
- Return type:
None.
- run()¶
Run.
- Return type:
None.
- pygmi.raster.anaglyph.anaglyph(red, blue, atype='dubois')¶
Colour Anaglyph.
- Parameters:
red (numpy array) – Dataset for red channel.
blue (numpy array) – Dataset for blue channel.
atype (str, optional) – Anaglyph type. The default is ‘dubois’.
- Returns:
rgb – Output dataset.
- Return type:
numpy array
- pygmi.raster.anaglyph.currentshader(data, cell, theta, phi, alpha)¶
Blinn shader.
- Parameters:
data (numpy array) – input MxN data to be imaged.
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.
- Returns:
R – Output data.
- Return type:
numpy array
- pygmi.raster.anaglyph.histcomp(img, nbr_bins=256, perc=5.0)¶
Histogram compaction.
- Parameters:
img (numpy masked array) – Input data.
nbr_bins (int, optional) – Number of bins. The default is 256.
perc (float, optional) – Percentage to clip. The default is 5.
- Returns:
img2 – Output data.
- Return type:
numpy array
- pygmi.raster.anaglyph.norm2(dat, datmin=None, datmax=None)¶
Normalise vector.
- Parameters:
dat (numpy array) – Vector to be normalised.
datmin (float, optional) – Minimum dat value. The default is None.
datmax (float, optional) – Maximum dat value. The default is None.
- Returns:
Normalised output data.
- Return type:
numpy array
- pygmi.raster.anaglyph.rot_and_clean(x, y, z, rotang=5, rtype='red')¶
Rotate and clean rotated data for 2d view.
- Parameters:
x (numpy array) – X coordinates.
y (numpy array) – Y coordinates.
z (numpy array) – Z coordinates (or data values).
rotang (float, optional) – Rotation angle. The default is 5.
rtype (str, optional) – Rotation type. The default is ‘red’.
- Returns:
zmap – Output data.
- Return type:
numpy array
- pygmi.raster.anaglyph.sunshade(data, azim=-0.7853981633974483, elev=0.7853981633974483, alpha=1, cell=100, cmap=<matplotlib.colors.LinearSegmentedColormap object>)¶
Perform Sunshading on data.
- Parameters:
data (numpy array) – input MxN data to be imaged.
azim (float, optional) – Sun azimuth. The default is -np.pi/4..
elev (float, optional) – Sun elevation. The default is np.pi/4..
alpha (float, optional) – how much incident light is reflected (0 to 1). The default is 1.
cell (float, optional) – between 1 and 100 - controls sunshade detail. The default is 100.
cmap (matplotlib.colors.LinearSegmentedColormap, optional) – Matplotlib colormap.
- Returns:
colormap – Output colour mapped array (MxNx4).
- Return type:
numpy array
pygmi.raster.cooper module¶
A collection of routines by Gordon Cooper.
- class pygmi.raster.cooper.AGC(parent=None)¶
Bases:
BasicModule
Class used to gather information via a GUI, for function AGC.
- wsize¶
window size, must be odd
- Type:
int
- saveproj()¶
Save project data from class.
- Return type:
None.
- settings(nodialog=False)¶
Entry point into item.
- Parameters:
nodialog (bool, optional) – Run settings without a dialog. The default is False.
- Returns:
True if successful, False otherwise.
- Return type:
bool
- setupui()¶
Set up UI.
- Return type:
None.
- class pygmi.raster.cooper.Gradients(parent=None)¶
Bases:
BasicModule
Class used to gather information via a GUI, for function gradients.
- azi¶
Azimuth/filter direction (degrees)
- Type:
float
- elev¶
Elevation (for sunshading, degrees from horizontal)
- Type:
float
- order¶
Order of DR filter - see paper. Try 1 first.
- Type:
int
- radiochange()¶
Check radio button state.
- Return type:
None.
- saveproj()¶
Save project data from class.
- Return type:
None.
- settings(nodialog=False)¶
Entry point into item.
- Parameters:
nodialog (bool, optional) – Run settings without a dialog. The default is False.
- Returns:
True if successful, False otherwise.
- Return type:
bool
- setupui()¶
Set up UI.
- Return type:
None.
- class pygmi.raster.cooper.Visibility2d(parent=None)¶
Bases:
BasicModule
Class used to gather information via a GUI, for function visibility2d.
- wsize¶
window size, must be odd
- Type:
int
- dh¶
height of observer above surface
- Type:
float
- saveproj()¶
Save project data from class.
- Return type:
None.
- settings(nodialog=False)¶
Entry point into item.
- Parameters:
nodialog (bool, optional) – Run settings without a dialog. The default is False.
- Returns:
True if successful, False otherwise.
- Return type:
bool
- setupui()¶
Set up UI.
- Return type:
None.
- pygmi.raster.cooper.agc(data, wsize, atype='mean', nodata=0.0, piter=<built-in function iter>)¶
AGC for map data, based on code by Gordon Cooper.
- Parameters:
data (numpy array) – Raster data.
wsize (int) – Window size, must be odd.
atype (str, optional) – AGC type - can be median or mean, default is ‘mean’.
nodata (float, optional) – no data value, default is 0.
piter (function, optional) – Progress bar iterable. The default is iter.
- Returns:
agcdata – Output AGC data
- Return type:
numpy array
- pygmi.raster.cooper.derivative_ratio(data, azi, order)¶
Compute derivative ratio of image data. Based on code by Gordon Cooper.
- Parameters:
data (numpy array) – input numpy data array
azi (float) – Filter direction (degrees)
order (int) – Order of DR filter - see paper. Try 1 first.
- Returns:
dr – returns derivative ratio
- Return type:
float
- pygmi.raster.cooper.gradients(data, azi, xint, yint)¶
Gradients.
Compute directional derivative of image data. Based on code by Gordon Cooper.
- Parameters:
data (numpy array) – input numpy data array
azi (float) – Filter direction (degrees)
xint (float) – X interval/distance.
yint (float) – Y interval/distance.
- Returns:
dt1 – returns directional derivative
- Return type:
float
- pygmi.raster.cooper.nextpow2(n)¶
Next power of 2.
- Parameters:
n (float or numpy array) – Current value.
- Returns:
m_i – Output.
- Return type:
float or numpy array
- pygmi.raster.cooper.thgrad(data, xint, yint)¶
Gradients.
Compute total horizontal gradient.
- Parameters:
data (numpy array) – input numpy data array
xint (float) – X interval/distance.
yint (float) – Y interval/distance.
- Returns:
dt1 – returns gradient.
- Return type:
float
- pygmi.raster.cooper.vertical(data, npts=None, xint=1, order=1)¶
Vertical derivative.
- Parameters:
data (numpy array) – Input data.
npts (int, optional) – Number of points. The default is None.
xint (float, optional) – X interval. The default is 1.
order (int, optional) – Order. The default is 1.
- Returns:
dz – Output data
- Return type:
numpy array
- pygmi.raster.cooper.visibility2d(data, wsize, dh, piter=<built-in function iter>)¶
Compute visibility as a textural measure.
Compute vertical derivatives by calculating the visibility at different heights above the surface (see paper)
- Parameters:
data (numpy array) – input dataset - numpy MxN array
wsize (int) – window size, must be odd
dh (float) – height of observer above surface
piter (function, optional) – Progress bar iterable. The default is iter.
- Returns:
vtot (numpy array) – Total visibility.
vstd (numpy array) – Visibility variation.
vsum (numpy array) – Visibility vector resultant.
- pygmi.raster.cooper.visibilitytot(data, wsize, dh)¶
Compute visibility as a textural measure.
Compute vertical derivatives by calculating the visibility at different heights above the surface (see paper)
- Parameters:
data (numpy array) – input dataset - numpy MxN array
wsize (int) – window size, must be odd
dh (float) – height of observer above surface
piter (function, optional) – Progress bar iterable. The default is iter.
- Returns:
vtot (numpy array) – Total visibility.
vstd (numpy array) – Visibility variation.
vsum (numpy array) – Visibility vector resultant.
pygmi.raster.dataprep module¶
A set of Raster Data Preparation routines.
- class pygmi.raster.dataprep.Continuation(parent=None)¶
Bases:
BasicModule
Perform upward and downward continuation on potential field data.
- acceptall()¶
Accept option.
Updates self.outdata, which is used as input to other modules.
- Return type:
None.
- saveproj()¶
Save project data from class.
- Return type:
None.
- settings(nodialog=False)¶
Entry point into item.
- Parameters:
nodialog (bool, optional) – Run settings without a dialog. The default is False.
- Returns:
True if successful, False otherwise.
- Return type:
bool
- setupui()¶
Set up UI.
- Return type:
None.
- class pygmi.raster.dataprep.DataCut(parent=None)¶
Bases:
BasicModule
Cut Data using shapefiles.
This class cuts raster datasets using a boundary defined by a polygon shapefile.
- saveproj()¶
Save project data from class.
- Return type:
None.
- settings(nodialog=False)¶
Entry point into item.
- Parameters:
nodialog (bool, optional) – Run settings without a dialog. The default is False.
- Returns:
True if successful, False otherwise.
- Return type:
bool
- class pygmi.raster.dataprep.DataLayerStack(parent=None)¶
Bases:
BasicModule
Data Layer Stack.
This class merges datasets which have different rows and columns. It resamples them so that they have the same rows and columns.
- acceptall()¶
Accept option.
Updates self.outdata, which is used as input to other modules.
- Return type:
None.
- dxy_change()¶
Update dxy.
This is the size of a grid cell in the x and y directions.
- Return type:
None.
- saveproj()¶
Save project data from class.
- Return type:
None.
- settings(nodialog=False)¶
Entry point into item.
- Parameters:
nodialog (bool, optional) – Run settings without a dialog. The default is False.
- Returns:
True if successful, False otherwise.
- Return type:
bool
- setupui()¶
Set up UI.
- Return type:
None.
- class pygmi.raster.dataprep.DataMerge(parent=None)¶
Bases:
BasicModule
Data Merge.
This class merges datasets which have different rows and columns. It resamples them so that they have the same rows and columns.
- acceptall()¶
Accept option.
Updates self.outdata, which is used as input to other modules.
- Returns:
Success of routine.
- Return type:
bool
- filesdiffchanged()¶
Files different clicked.
- Return type:
None.
- get_idir()¶
Get the input directory.
- Return type:
None.
- get_sfile()¶
Get the input shapefile.
- Return type:
None.
- merge_different()¶
Merge files with different numbers of bands and/or band order.
This uses more memory, but is flexible.
- Returns:
Success of routine.
- Return type:
bool
- merge_same()¶
Mosaic files with same numbers of bands and band order.
This uses much less memory, but is less flexible.
- Returns:
Success of routine.
- Return type:
bool
- method_change()¶
Change method.
- Return type:
None.
- saveproj()¶
Save project data from class.
- Return type:
None.
- settings(nodialog=False)¶
Entry point into item.
- Parameters:
nodialog (bool, optional) – Run settings without a dialog. The default is False.
- Returns:
True if successful, False otherwise.
- Return type:
bool
- setupui()¶
Set up UI.
- Return type:
None.
- shiftchanged()¶
Shift mean clicked.
- Return type:
None.
- class pygmi.raster.dataprep.DataReproj(parent=None)¶
Bases:
BasicModule
Reprojections.
This class reprojects datasets using the rasterio routines.
- acceptall()¶
Accept option.
Updates self.outdata, which is used as input to other modules.
- Return type:
None.
- saveproj()¶
Save project data from class.
- Return type:
None.
- settings(nodialog=False)¶
Entry point into item.
- Parameters:
nodialog (bool, optional) – Run settings without a dialog. The default is False.
- Returns:
True if successful, False otherwise.
- Return type:
bool
- setupui()¶
Set up UI.
- Return type:
None.
- class pygmi.raster.dataprep.GetProf(parent=None)¶
Bases:
BasicModule
Get a Profile.
This class extracts a profile from a raster dataset using a line shapefile.
- saveproj()¶
Save project data from class.
- Return type:
None.
- settings(nodialog=False)¶
Entry point into item.
- Parameters:
nodialog (bool, optional) – Run settings without a dialog. The default is False.
- Returns:
True if successful, False otherwise.
- Return type:
bool
- class pygmi.raster.dataprep.GroupProj(title='Projection', parent=None)¶
Bases:
QWidget
Group Proj.
Custom widget
- combo_change()¶
Change Combo.
- Return type:
None.
- combo_datum_change()¶
Change Combo.
- Return type:
None.
- set_current(wkt)¶
Set new WKT for current option.
- Parameters:
wkt (str) – Well Known Text descriptions for coordinates (WKT).
- Return type:
None.
- class pygmi.raster.dataprep.Metadata(parent=None)¶
Bases:
ContextModule
Edit Metadata.
This class allows the editing of the metadata for a raster dataset using a GUI.
- banddata¶
band data
- Type:
dictionary
- bandid¶
dictionary of strings containing band names.
- Type:
dictionary
- acceptall()¶
Accept option.
- Return type:
None.
- rename_id()¶
Rename the band name.
- Return type:
None.
- run()¶
Entry point to start this routine.
- Returns:
tmp – True if successful, False otherwise.
- Return type:
bool
- setupui()¶
Set up UI.
- Return type:
None.
- update_vals()¶
Update the values on the interface.
- Return type:
None.
- pygmi.raster.dataprep.check_dataid(out)¶
Check dataid for duplicates and renames where necessary.
- Parameters:
out (list of PyGMI Data) – PyGMI raster data.
- Returns:
out – PyGMI raster data.
- Return type:
list of PyGMI Data
- pygmi.raster.dataprep.cluster_to_raster(indata)¶
Convert cluster datasets to raster datasets.
Some routines will not understand the datasets produced by cluster analysis routines, since they are designated ‘Cluster’ and not ‘Raster’. This provides a work-around for that.
- pygmi.raster.dataprep.cut_raster(data, ifile, showlog=<built-in function print>, deepcopy=True)¶
Cut a raster dataset.
Cut a raster dataset using a shapefile.
- Parameters:
data (list of PyGMI Data) – PyGMI Dataset
ifile (str) – shapefile used to cut data
showlog (function, optional) – Function for printing text. The default is print.
- Returns:
data – PyGMI Dataset
- Return type:
list of PyGMI Data
- pygmi.raster.dataprep.data_reproject(data, ocrs, otransform=None, orows=None, ocolumns=None, icrs=None)¶
Reproject dataset.
- Parameters:
data (PyGMI Data) – PyGMI dataset.
ocrs (CRS) – output crs.
otransform (Affine, optional) – Output affine transform. The default is None.
orows (int, optional) – output rows. The default is None.
ocolumns (int, optional) – output columns. The default is None.
icrs (CRS, optional) – input crs. The default is None.
- Returns:
data2 – Reprojected dataset.
- Return type:
PyGMI Data
- pygmi.raster.dataprep.fft_getkxy(fftmod, xdim, ydim)¶
Get KX and KY.
- Parameters:
fftmod (numpy array) – FFT data.
xdim (float) – cell x dimension.
ydim (float) – cell y dimension.
- Returns:
KX (numpy array) – x sample frequencies.
KY (numpy array) – y sample frequencies.
- pygmi.raster.dataprep.fftcont(data, h)¶
Continuation.
- Parameters:
data (PyGMI Data) – PyGMI raster data.
h (float) – Height.
- Returns:
dat – PyGMI raster data.
- Return type:
PyGMI Data
- pygmi.raster.dataprep.fftprep(data)¶
FFT preparation.
- Parameters:
data (PyGMI Data type) – Input dataset.
- Returns:
zfin (numpy array.) – Output prepared data.
rdiff (int) – rows divided by 2.
cdiff (int) – columns divided by 2.
datamedian (float) – Median of data.
- pygmi.raster.dataprep.get_shape_bounds(sfile, crs=None, showlog=<built-in function print>)¶
Get bounds from a shape file.
- Parameters:
sfile (str) – Filename for shapefile.
crs (rasterio CRS) – target crs for shapefile
showlog (function, optional) – Display information. The default is print.
- Returns:
bounds – Rasterio bounds.
- Return type:
list
- pygmi.raster.dataprep.getepsgcodes()¶
Routine used to get a list of EPSG codes.
- Returns:
pcodes – Dictionary of codes per projection in WKT format.
- Return type:
dictionary
- pygmi.raster.dataprep.lstack(dat, piter=None, dxy=None, showlog=<built-in function 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 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 Data
- pygmi.raster.dataprep.merge_max(merged_data, new_data, merged_mask, new_mask, index=None, roff=None, coff=None)¶
Merge using maximum for rasterio, taking maximum value.
- Parameters:
merged_data (numpy array) – Old data.
new_data (numpy array) – New data to merge to old data.
merged_mask (float) – Old mask.
new_mask (float) – New mask.
index (int, optional) – index of the current dataset within the merged dataset collection. The default is None.
roff (int, optional) – row offset in base array. The default is None.
coff (int, optional) – col offset in base array. The default is None.
- Return type:
None.
- pygmi.raster.dataprep.merge_median(merged_data, new_data, merged_mask, new_mask, index=None, roff=None, coff=None)¶
Merge using median for rasterio, taking minimum value.
- Parameters:
merged_data (numpy array) – Old data.
new_data (numpy array) – New data to merge to old data.
merged_mask (float) – Old mask.
new_mask (float) – New mask.
index (int, optional) – index of the current dataset within the merged dataset collection. The default is None.
roff (int, optional) – row offset in base array. The default is None.
coff (int, optional) – col offset in base array. The default is None.
- Return type:
None.
- pygmi.raster.dataprep.merge_min(merged_data, new_data, merged_mask, new_mask, index=None, roff=None, coff=None)¶
Merge using minimum for rasterio, taking minimum value.
- Parameters:
merged_data (numpy array) – Old data.
new_data (numpy array) – New data to merge to old data.
merged_mask (float) – Old mask.
new_mask (float) – New mask.
index (int, optional) – index of the current dataset within the merged dataset collection. The default is None.
roff (int, optional) – row offset in base array. The default is None.
coff (int, optional) – col offset in base array. The default is None.
- Return type:
None.
- pygmi.raster.dataprep.redistribute_vertices(geom, distance)¶
Redistribute vertices in a geometry.
From https://stackoverflow.com/questions/34906124/interpolating-every-x-distance-along-multiline-in-shapely, and by Mike-T.
- Parameters:
geom (shapely geometry) – Geometry from geopandas.
distance (float) – sampling distance.
- Raises:
ValueError – Error when there is an unknown geometry.
- Returns:
New geometry.
- Return type:
shapely geometry
- pygmi.raster.dataprep.taylorcont(data, h)¶
Taylor Continuation.
- Parameters:
data (PyGMI Data) – PyGMI raster data.
h (float) – Height.
- Returns:
dat – PyGMI raster data.
- Return type:
PyGMI Data
- pygmi.raster.dataprep.trim_raster(olddata)¶
Trim nulls from a raster dataset.
This function trims entire rows or columns of data which are masked, and are on the edges of the dataset. Masked values are set to the null value.
- Parameters:
olddata (list of PyGMI Data) – PyGMI dataset
- Returns:
olddata – PyGMI dataset
- Return type:
list of PyGMI Data
- pygmi.raster.dataprep.verticalp(data, order=1)¶
Vertical derivative.
- Parameters:
data (numpy array) – Input data.
order (float, optional) – Order. The default is 1.
- Returns:
dout – Output data
- Return type:
numpy array
pygmi.raster.datatypes module¶
Class for raster data types and conversion routines.
- class pygmi.raster.datatypes.Data¶
Bases:
object
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.
This routine will clear metadata during copy.
- Returns:
data – PyGMI data type.
- Return type:
PyGMI Data
- 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.
- meta_from_rasterio(dataset)¶
Set transform, bounds, extent, xdim and ydim from a rasterio dataset.
- Parameters:
dataset (rasterio dataset) – Rasterio dataset.
- 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 (list, optional) – list containing offsets etc in event of cutting data. 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
- class pygmi.raster.datatypes.RasterMeta¶
Bases:
object
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 Data) – PyGMI data object.
- Return type:
None.
- 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.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).
pygmi.raster.equation_editor module¶
Equation editor.
- class pygmi.raster.equation_editor.EquationEditor(parent=None)¶
Bases:
BasicModule
Equation Editor.
This class allows the input of equations using raster datasets as variables. This is commonly done in remote sensing applications, where there is a requirement for band ratioing etc. It uses the numexpr library.
- equation¶
string with the equation in it
- Type:
str
- bands¶
dictionary of bands
- Type:
dictionary
- combo()¶
Update combo information.
- Return type:
None.
- eq_fix(indata)¶
Corrects names in equation to variable names.
- Parameters:
indata (list of PyGMI Data.) – PyGMI raster dataset.
- Returns:
neweq – Corrected equation.
- Return type:
str
- mean(eq, localdict)¶
Get mean pixel value of all input bands.
- Parameters:
eq (str) – Equation with std command.
localdict (dictionary) – Dictionary of data.
- Returns:
findat – Output array.
- Return type:
numpy array
- mosaic(eq, localdict)¶
Mosaics data into a single band dataset.
- Parameters:
eq (str) – Equation with mosaic command.
localdict (dictionary) – Dictionary of data.
- Returns:
findat – Output array.
- Return type:
numpy array
- saveproj()¶
Save project data from class.
- Return type:
None.
- settings(nodialog=False)¶
Entry point into item.
- Parameters:
nodialog (bool, optional) – Run settings without a dialog. The default is False.
- Returns:
True if successful, False otherwise.
- Return type:
bool
- setupui()¶
Set up UI.
- Return type:
None.
- std(eq, localdict)¶
Get standard deviation pixel value of all input bands.
- Parameters:
eq (str) – Equation with std command.
localdict (dictionary) – Dictionary of data.
- Returns:
findat – Output array.
- Return type:
numpy array
- pygmi.raster.equation_editor.hmode(data)¶
Use a histogram to generate a fast mode estimate.
- Parameters:
data (list) – list of values to generate the mode from.
- Returns:
mode2 – mode value.
- Return type:
float
pygmi.raster.ginterp module¶
Plot Raster Data.
This is the raster data interpretation module. This module allows for the display of raster data in a variety of modes, as well as the export of that display to GeoTIFF format.
- Currently the following is supported
Pseudo Colour - data mapped to a colour map
Contours with solid contours
RGB ternary images
CMYK ternary images
Sun shaded or hill shaded images
It can be very effectively used in conjunction with a GIS package which supports GeoTIFF files.
- class pygmi.raster.ginterp.MyMplCanvas(parent=None)¶
Bases:
FigureCanvasQTAgg
Canvas for the actual plot.
- htype¶
string indicating the histogram stretch to apply to the data
- Type:
str
- hstype¶
string indicating the histogram stretch to apply to the sun data
- Type:
str
- cbar¶
colour map to be used for pseudo colour bars
- Type:
matplotlib colour map
- data¶
list of PyGMI raster data objects - used for colour images
- Type:
list of PyGMI Data
- sdata¶
list of PyGMI raster data objects - used for shaded images
- Type:
list of PyGMI Data
- gmode¶
string containing the graphics mode - Contour, Ternary, Sunshade, Single Colour Map.
- Type:
str
- argb¶
list of matplotlib subplots. There are up to three.
- Type:
list
- hhist¶
matplotlib hist associated with argb
- Type:
list
- hband¶
list of strings containing the band names to be used.
- Type:
list
- htxt¶
list of strings associated with hhist, denoting a raster value (where mouse is currently hovering over on image)
- Type:
list
- image¶
imshow instance - this is the primary way of displaying an image.
- Type:
imshow
- cnt¶
contour instance - used for the contour image
- Type:
matplotlib contour
- cntf¶
contourf instance - used for the contour image
- Type:
matplotlib contourf
- background¶
image bounding box - used in blitting
- Type:
matplotlib bounding box
- bbox_hist_red¶
red histogram bounding box
- Type:
matplotlib bounding box
- bbox_hist_green¶
green histogram bounding box
- Type:
matplotlib bounding box
- bbox_hist_blue¶
blue histogram bounding box
- Type:
matplotlib bounding box
- axes¶
axes for the plot
- Type:
matplotlib axes
- pinit¶
calculated with aspect - used in sunshading
- Type:
numpy array
- qinit¶
calculated with aspect - used in sunshading
- Type:
numpy array
- phi¶
azimuth (sunshading)
- Type:
float
- theta¶
sun elevation (sunshading)
- Type:
float
- cell¶
between 1 and 100 - controls sunshade detail.
- Type:
float
- alpha¶
how much incident light is reflected (0 to 1)
- Type:
float
- kval¶
k value for CMYK mode
- Type:
float
- init_graph()¶
Initialize the graph.
- Return type:
None.
- move(event)¶
Mouse is moving over canvas.
- Parameters:
event (matplotlib.backend_bases.MouseEvent) – Mouse event.
- Return type:
None.
- revent(event)¶
Resize event.
- Parameters:
event (matplotlib.backend_bases.ResizeEvent) – Resize event.
- Return type:
None.
- update_contour()¶
Update contours.
- Return type:
None.
- update_graph()¶
Update plot.
- Return type:
None.
- update_hist_rgb(zval)¶
Update the rgb histograms.
- Parameters:
zval (numpy array) – Data values.
- Returns:
bnum – Bin numbers.
- Return type:
list
- update_hist_single(zval=None, hno=0)¶
Update the colour on a single histogram.
- Parameters:
zval (float) – Data value.
hno (int, optional) – Histogram number. The default is 0.
- Returns:
binnum – Number of bins.
- Return type:
int
- update_hist_text(hst, zval)¶
Update the value on the histogram.
- Parameters:
hst (histogram) – Histogram.
zval (float) – Data value.
- Return type:
None.
- update_rgb()¶
Update the RGB Ternary Map.
- Return type:
None.
- update_shade()¶
Update sun shade plot.
- Return type:
None.
- update_shade_plot()¶
Update shade plot for export.
- Returns:
Sunshader data.
- Return type:
numpy array
- update_single_color_map()¶
Update the single colour map.
- Return type:
None.
- class pygmi.raster.ginterp.MySunCanvas(parent=None)¶
Bases:
FigureCanvasQTAgg
Canvas for the sunshading tool.
- sun¶
plot of a circle ‘o’ showing where the sun is
- Type:
matplotlib plot instance
- axes¶
axes on which the sun is drawn
- Type:
matplotlib axes instance
- init_graph()¶
Initialise graph.
- Return type:
None.
- class pygmi.raster.ginterp.PlotInterp(parent=None)¶
Bases:
BasicModule
The primary class for the raster data interpretation module.
The main interface is set up from here, as well as monitoring of the mouse over the sunshading.
The PlotInterp class allows for the display of raster data in a variety of modes, as well as the export of that display to GeoTIFF format.
- self.mmc¶
main canvas containing the image
- Type:
pygmi.raster.ginterp.MyMplCanvas, FigureCanvas
- self.msc¶
small canvas containing the sunshading control
- Type:
pygmi.raster.ginterp.MySunCanvas, FigureCanvas
- change_allclip()¶
Change all clip percentages to the current one.
- Return type:
None.
- change_blue()¶
Change the blue or third display band.
- Return type:
None.
- change_cbar()¶
Change the colour map for the colour bar.
- Return type:
None.
- change_clipband()¶
Change the clip percentage band.
- Return type:
None.
- change_dtype()¶
Change display type.
- Return type:
None.
- change_green()¶
Change the green or second band.
- Return type:
None.
- change_htype()¶
Change the histogram stretch to apply to the normal data.
- Return type:
None.
- change_kval()¶
Change the CMYK K value.
- Return type:
None.
- change_lclip()¶
Change the linear clip percentage.
- Return type:
None.
- change_red()¶
Change the red or first band.
- Return type:
None.
- change_sun()¶
Change the sunshade band.
- Return type:
None.
- change_sun_checkbox()¶
Use when sunshading checkbox is clicked.
- Return type:
None.
- change_sunsliders()¶
Change the sun shading sliders.
- Return type:
None.
- data_init()¶
Initialise Data.
Entry point into routine. This entry point exists for the case where data must be initialised before entering at the standard ‘settings’ sub module.
- Return type:
None.
- move(event)¶
Move event is used to track changes to the sunshading.
- Parameters:
event (matplotlib.backend_bases.MouseEvent) – Mouse event.
- Return type:
None.
- run()¶
Run the module as a context menu.
- save_img()¶
Save image as a GeoTIFF.
- Returns:
True if successful, False otherwise.
- Return type:
bool
- saveproj()¶
Save project data from class.
- Return type:
None.
- settings(nodialog=False)¶
Entry point into item.
- Parameters:
nodialog (bool, optional) – Run settings without a dialog. The default is False.
- Returns:
True if successful, False otherwise.
- Return type:
bool
- setupui()¶
Set up UI.
- Return type:
None.
pygmi.raster.graphs module¶
Plot Raster Data.
This module provides a variety of methods to plot raster data via the context menu. The following are supported:
Correlation coefficients
Images
Surfaces
Histograms
- class pygmi.raster.graphs.MyMplCanvas(parent=None)¶
Bases:
FigureCanvasQTAgg
Canvas for the actual plot.
- axes¶
- Type:
matplotlib subplot
- parent¶
reference to the parent routine
- Type:
parent
- update_ccoef(data1, dmat)¶
Update the correlation coefficient plot.
- Parameters:
data1 (PyGMI raster Data) – raster dataset to be used.
dmat (numpy array) – dummy matrix of numbers to be plotted using pcolor.
- Return type:
None.
- update_hexbin(data1, data2)¶
Update the hexbin plot.
- Parameters:
data1 (PyGMI raster Data) – raster dataset to be used
data2 (PyGMI raster Data) – raster dataset to be used
- Return type:
None.
- update_hist(data1, ylog, iscum)¶
Update the histogram plot.
- Parameters:
data1 (PyGMI raster Data) – raster dataset to be used
ylog (bool) – Boolean for a log scale on y-axis.
iscum (bool) – Boolean for a cumulative distribution.
- Return type:
None.
- update_raster(data1, cmap)¶
Update the raster plot.
- Parameters:
data1 (PyGMI raster Data) – raster dataset to be used in contouring
cmap (str) – Matplotlib colormap description
- Return type:
None.
- update_surface(data, cmap)¶
Update the surface plot.
- Parameters:
data (PyGMI raster Data) – raster dataset to be used
cmap (str) – Matplotlib colormap description
- Return type:
None.
- class pygmi.raster.graphs.PlotCCoef(parent=None)¶
Bases:
ContextModule
Plot 2D Correlation Coefficients.
- run()¶
Run.
- Return type:
None.
- class pygmi.raster.graphs.PlotHist(parent=None)¶
Bases:
ContextModule
Plot Histogram Class.
- change_band()¶
Combo box to choose band.
- Return type:
None.
- run()¶
Run.
- Return type:
None.
- class pygmi.raster.graphs.PlotRaster(parent=None)¶
Bases:
ContextModule
Plot Raster Class.
- change_band()¶
Combo box to choose band.
- Return type:
None.
- run()¶
Run.
- Return type:
None.
- class pygmi.raster.graphs.PlotScatter(parent=None)¶
Bases:
ContextModule
Plot Hexbin Class.
A Hexbin is a type of scatter plot which is raster.
- change_band()¶
Combo box to choose band.
- Return type:
None.
- run()¶
Run.
- Return type:
None.
- class pygmi.raster.graphs.PlotSurface(parent=None)¶
Bases:
ContextModule
Plot Surface Class.
- change_band()¶
Combo box to choose band.
- Return type:
None.
- run()¶
Run.
- Return type:
None.
- pygmi.raster.graphs.check_bands(data)¶
Check that band sizes are the same.
- Parameters:
data (list of PyGMI Data) – PyGMI raster dataset.
- Returns:
chk – True if sizes are the same, False otherwise.
- Return type:
bool
- pygmi.raster.graphs.corr2d(dat1, dat2)¶
Calculate the 2D correlation.
- Parameters:
dat1 (numpy array) – dataset 1 for use in correlation calculation.
dat2 (numpy array) – dataset 2 for use in correlation calculation.
- Returns:
out – array of correlation coefficients
- Return type:
numpy array
pygmi.raster.iodefs module¶
Import raster data.
- class pygmi.raster.iodefs.BandSelect(parent=None)¶
Bases:
ContextModule
A combobox to select data bands.
- run()¶
Run.
- Returns:
True if successful, False otherwise.
- Return type:
bool
- class pygmi.raster.iodefs.ExportData(parent=None)¶
Bases:
ContextModule
Export Data.
- ofile¶
output file name.
- Type:
str
- acceptall()¶
Accept choice.
- export_ascii(data)¶
Export ASCII file.
- Parameters:
data (PyGMI raster Data) – dataset to export
- Return type:
None.
- export_ascii_xyz(data)¶
Export and xyz file.
- Parameters:
data (PyGMI raster Data) – dataset to export
- Return type:
None.
- export_gxf(data)¶
Export GXF data.
- Parameters:
data (PyGMI raster Data) – dataset to export
- Return type:
None.
- export_surfer(data)¶
Routine to export a surfer binary grid.
- Parameters:
data (PyGMI raster Data) – dataset to export
- Return type:
None.
- get_filename(data, ext)¶
Get a valid filename in the case of multi band image.
- Parameters:
data (PyGMI raster Data) – dataset to get filename from
ext (str) – filename extension to use
- Returns:
file_out – Output filename.
- Return type:
str
- get_ofile()¶
Get output directory.
- run()¶
Run.
- Returns:
True if successful, False otherwise.
- Return type:
bool
- setupui()¶
Set up UI.
- Return type:
None.
- class pygmi.raster.iodefs.ImportData(parent=None, ifile='', filt='')¶
Bases:
BasicModule
Import Data - Interfaces with rasterio routines.
- saveproj()¶
Save project data from class.
- Return type:
None
- settings(nodialog=False)¶
Entry point into item.
- Parameters:
nodialog (bool, optional) – Run settings without a dialog. The default is False.
- Returns:
True if successful, False otherwise.
- Return type:
bool
- class pygmi.raster.iodefs.ImportRGBData(parent=None)¶
Bases:
BasicModule
Import RGB Image - Interfaces with rasterio routines.
- saveproj()¶
Save project data from class.
- Return type:
None.
- settings(nodialog=False)¶
Entry point into item.
- Parameters:
nodialog (bool, optional) – Run settings without a dialog. The default is False.
- Returns:
True if successful, False otherwise.
- Return type:
bool
- pygmi.raster.iodefs.calccov(data, showlog=<built-in function print>)¶
Calculate covariance from PyGMI Data.
This routine assumes all bands are co-located, with the same size. Otherwise, run lstack first.
- Parameters:
data (list of PyGMI Data) – List of PyGMI data.
- Returns:
dcov – Covariances.
- Return type:
numpy array
- pygmi.raster.iodefs.clusterprep(dat)¶
Prepare Cluster data from raster data.
- Parameters:
dat (list of PyGMI Data) – List of PyGMI datasets.
- Returns:
dat2 – List of PyGMI datasets.
- Return type:
list of PyGMI Data
- pygmi.raster.iodefs.export_raster(ofile, dat, drv='GTiff', piter=None, compression='NONE', bandsort=True, showlog=<built-in function print>, updatestats=True)¶
Export to rasterio format.
- Parameters:
ofile (str) – Output file name.
dat (list or dictionary of PyGMI raster Data) – dataset to export
drv (str) – name of the rasterio driver to use
piter (function, optional) – Progressbar iterable. The default is None.
compression (str, optional) – Compression for GeoTIFF. Can be NONE, DEFLATE or ZSTD. The default is NONE.
bandsort (bool, optional) – sort the bands by dataid. The default is True
- Return type:
None.
- pygmi.raster.iodefs.get_ascii(ifile)¶
Import ascii raster dataset.
- Parameters:
ifile (str) – filename to import
- Returns:
dat – dataset imported
- Return type:
PyGMI raster Data
- pygmi.raster.iodefs.get_bil(ifile, bands, cols, rows, dtype, piter, iraster=None, interleave='LINE')¶
Get BIL format file.
This routine is called from get_raster
- Parameters:
ifile (str) – filename to import
bands (int) – Number of bands.
cols (int) – Number of columns.
rows (int) – Number of rows.
dtype (data type) – Data type.
piter (function) – progress bar iterable
- Returns:
datin – dataset imported
- Return type:
PyGMI raster Data
- pygmi.raster.iodefs.get_geopak(hfile)¶
Geopak Import.
- Parameters:
hfile (str) – filename to import
- Returns:
dat – PyGMI raster dataset.
- Return type:
list of PyGMI Data
- pygmi.raster.iodefs.get_geosoft(hfile)¶
Get Geosoft file.
- Parameters:
ifile (str) – filename to import
- Returns:
dat – Dataset imported
- Return type:
list of PyGMI Data
- pygmi.raster.iodefs.get_raster(ifile, nval=None, piter=None, showlog=<built-in function print>, iraster=None, driver=None, bounds=None, dataid=None, tnames=None, metaonly=False, out_shape=None)¶
Get raster dataset.
This function loads a raster dataset off the disk using the rasterio libraries. It returns the data in a PyGMI data object.
- Parameters:
ifile (str) – filename to import
nval (float, optional) – Nodata/null value. The default is None.
piter (function, optional) – progress bar iterable, default is None.
showlog (function, optional) – Routine to show text messages. The default is print.
iraster (None or tuple) – Incremental raster import, to import a section of a file. The tuple is (xoff, yoff, xsize, ysize)
driver (str) – GDAL raster driver name. The default is None.
- Returns:
dat – Raster dataset imported
- Return type:
list of PyGMI Data
pygmi.raster.misc module¶
Miscellaneous functions.
- 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.currentshader(data, cell=1.0, theta=0.7853981633974483, phi=-0.7853981633974483, 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.histcomp(img, nbr_bins=None, 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
nbr_bins (int) – number of bins to use in compaction, default is None
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, nbr_bins=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
nbr_bins (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=<matplotlib.colors.LinearSegmentedColormap object>)¶
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.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
pygmi.raster.modest_image module¶
Modest Image.
Modification of Chris Beaumont’s mpl-modest-image package to allow the use of set_extent as well as better integration into PyGMI
pcole, 2021 - Bug fix to allow for correct zooming if origin is set to ‘upper’
- class pygmi.raster.modest_image.ModestImage(*args, **kwargs)¶
Bases:
AxesImage
Computationally modest image class.
ModestImage is an extension of the Matplotlib AxesImage class better suited for the interactive display of larger images. Before drawing, ModestImage resamples the data array based on the screen resolution and view window. This has very little affect on the appearance of the image, but can substantially cut down on computation since calculations of unresolved or clipped pixels are skipped.
The interface of ModestImage is the same as AxesImage. However, it does not currently support setting the ‘extent’ property. There may also be weird coordinate warping operations for images that I’m not aware of. Don’t expect those to work either.
- draw(renderer, *args, **kwargs)¶
Draw.
- draw_sunshade(colormap=None)¶
Apply sunshading.
- Return type:
None.
- draw_ternary()¶
Draw ternary.
- Return type:
None.
- format_cursor_data(data)¶
Format z data on graph.
- Parameters:
data (float) – Data value to display.
- Returns:
zval – Formatted string to display.
- Return type:
str
- get_array()¶
Override to return the full-resolution array.
- Returns:
Return data array of full resolution.
- Return type:
numpy array
- get_cursor_data(event)¶
Correct z-value display when zoomed.
- Parameters:
event (matpltolib cursor event.) – Cursor event.
- Returns:
z-value or NAN.
- Return type:
float
- invalidate_cache()¶
Invalidate cache.
- Return type:
None.
- set(*, agg_filter=<UNSET>, alpha=<UNSET>, animated=<UNSET>, array=<UNSET>, clim=<UNSET>, clim_std=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, cmap=<UNSET>, data=<UNSET>, extent=<UNSET>, filternorm=<UNSET>, filterrad=<UNSET>, gid=<UNSET>, in_layout=<UNSET>, interpolation=<UNSET>, interpolation_stage=<UNSET>, label=<UNSET>, mouseover=<UNSET>, norm=<UNSET>, path_effects=<UNSET>, picker=<UNSET>, rasterized=<UNSET>, resample=<UNSET>, shade=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, transform=<UNSET>, url=<UNSET>, visible=<UNSET>, zorder=<UNSET>)¶
Set multiple properties at once.
Supported properties are
- Properties:
agg_filter: a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array and two offsets from the bottom left corner of the image alpha: float or 2D array-like or None animated: bool array: array-like clim: (vmin: float, vmax: float) clim_std: float clip_box: ~matplotlib.transforms.BboxBase or None clip_on: bool clip_path: Patch or (Path, Transform) or None cmap: .Colormap or str or None data: numpy/PIL Image A extent: tuple figure: ~matplotlib.figure.Figure filternorm: bool filterrad: positive float gid: str in_layout: bool interpolation: {‘antialiased’, ‘nearest’, ‘bilinear’, ‘bicubic’, ‘spline16’, ‘spline36’, ‘hanning’, ‘hamming’, ‘hermite’, ‘kaiser’, ‘quadric’, ‘catrom’, ‘gaussian’, ‘bessel’, ‘mitchell’, ‘sinc’, ‘lanczos’, ‘none’} or None interpolation_stage: {‘data’, ‘rgba’} or None label: object mouseover: bool norm: .Normalize or str or None path_effects: list of .AbstractPathEffect picker: None or bool or float or callable rasterized: bool resample: bool or None shade: bool sketch_params: (scale: float, length: float, randomness: float) snap: bool or None transform: ~matplotlib.transforms.Transform url: str visible: bool zorder: float
- set_clim_std(mult)¶
Set the vmin and vmax to mult*std(self._A).
This routine only works on a 2D array.
- Parameters:
mult (float) – Multiplier.
- Return type:
None.
- set_data(A)¶
Set data.
- Parameters:
A (numpy/PIL Image A) – A numpy or PIL image.
- Raises:
TypeError – Error when data has incorrect dimensions.
- Return type:
None.
- set_extent(extent)¶
Set extent.
- Parameters:
extent (tuple) – Extent of data.
- Return type:
None.
- set_shade(doshade, cell=None, theta=None, phi=None, alpha=None)¶
Set the shade information.
- Parameters:
doshade (bool) – Check for whether to shade or not.
cell (float, optional) – Sunshade detail, between 1 and 100. The default is None.
theta (float, optional) – Sun inclination or elevation. The default is None.
phi (float, optional) – Sun declination or azimuth. The default is None.
alpha (float, optional) – Light reflectance, between 0 and 1. The default is None.
- Return type:
None.
- pygmi.raster.modest_image.extract_matched_slices(axes=None, shape=None, transform=<matplotlib.transforms.IdentityTransform object>)¶
Determine the slice parameters to use, matched to the screen.
Indexing the full resolution array as array[y0:y1:sy, x0:x1:sx] returns a view well-matched to the axes’ resolution and extent
- Parameters:
axes (Axes, optional) – Axes object to query. It’s extent and pixel size determine the slice parameters. The default is None.
shape (tuple, optional) – Tuple of the full image shape to slice into. Upper boundaries for slices will be cropped to fit within this shape. The default is None.
transform (rasterio transform, optional) – Rasterio transform. The default is IDENTITY_TRANSFORM.
- Returns:
x0 (int) – x minimum.
x1 (int) – x maximum.
sx (int) – x stride.
y0 (int) – y minimum.
y1 (int) – y maximum.
sy (int) – y stride.
- pygmi.raster.modest_image.imshow(axes, X, cmap=None, norm=None, aspect=None, interpolation=None, alpha=None, vmin=None, vmax=None, origin=None, extent=None, shape=None, filternorm=1, filterrad=4.0, imlim=None, resample=None, url=None, suncell=None, suntheta=None, sunphi=None, sunalpha=None, **kwargs)¶
Similar to matplotlib’s imshow command, but produces a ModestImage.
Unlike matplotlib version, must explicitly specify axes.
pygmi.raster.modest_ioimage module¶
Modest IO Image.
Modification of Chris Beaumont’s mpl-modest-image package to allow the use of set_extent as well as better integration into PyGMI. It is changed to read data directly from disk.
- class pygmi.raster.modest_ioimage.ModestImage(*args, **kwargs)¶
Bases:
AxesImage
Computationally modest image class.
ModestImage is an extension of the Matplotlib AxesImage class better suited for the interactive display of larger images. Before drawing, ModestImage resamples the data array based on the screen resolution and view window. This has very little affect on the appearance of the image, but can substantially cut down on computation since calculations of unresolved or clipped pixels are skipped.
The interface of ModestImage is the same as AxesImage. However, it does not currently support setting the ‘extent’ property. There may also be weird coordinate warping operations for images that I’m not aware of. Don’t expect those to work either.
- draw(renderer, *args, **kwargs)¶
Draw.
- draw_sunshade(colormap=None)¶
Apply sunshading.
- Return type:
None.
- draw_ternary()¶
Draw ternary.
- Return type:
None.
- format_cursor_data(data)¶
Format z data on graph.
- Parameters:
data (float) – Data value to display.
- Returns:
zval – Formatted string to display.
- Return type:
str
- get_array()¶
Override to return the full-resolution array.
- Returns:
Return data array of full resolution.
- Return type:
numpy array
- get_cursor_data(event)¶
Correct z-value display when zoomed.
- Parameters:
event (matplotlib cursor event.) – Cursor event.
- Returns:
z-value or NAN.
- Return type:
float
- invalidate_cache()¶
Invalidate cache.
- Return type:
None.
- set(*, agg_filter=<UNSET>, alpha=<UNSET>, animated=<UNSET>, array=<UNSET>, clim=<UNSET>, clim_std=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, cmap=<UNSET>, data=<UNSET>, extent=<UNSET>, filternorm=<UNSET>, filterrad=<UNSET>, gid=<UNSET>, in_layout=<UNSET>, interpolation=<UNSET>, interpolation_stage=<UNSET>, label=<UNSET>, mouseover=<UNSET>, norm=<UNSET>, path_effects=<UNSET>, picker=<UNSET>, rasterized=<UNSET>, resample=<UNSET>, shade=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, transform=<UNSET>, url=<UNSET>, visible=<UNSET>, zorder=<UNSET>)¶
Set multiple properties at once.
Supported properties are
- Properties:
agg_filter: a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array and two offsets from the bottom left corner of the image alpha: float or 2D array-like or None animated: bool array: array-like clim: (vmin: float, vmax: float) clim_std: float clip_box: ~matplotlib.transforms.BboxBase or None clip_on: bool clip_path: Patch or (Path, Transform) or None cmap: .Colormap or str or None data: numpy/PIL Image A extent: tuple figure: ~matplotlib.figure.Figure filternorm: bool filterrad: positive float gid: str in_layout: bool interpolation: {‘antialiased’, ‘nearest’, ‘bilinear’, ‘bicubic’, ‘spline16’, ‘spline36’, ‘hanning’, ‘hamming’, ‘hermite’, ‘kaiser’, ‘quadric’, ‘catrom’, ‘gaussian’, ‘bessel’, ‘mitchell’, ‘sinc’, ‘lanczos’, ‘none’} or None interpolation_stage: {‘data’, ‘rgba’} or None label: object mouseover: bool norm: .Normalize or str or None path_effects: list of .AbstractPathEffect picker: None or bool or float or callable rasterized: bool resample: bool or None shade: bool sketch_params: (scale: float, length: float, randomness: float) snap: bool or None transform: ~matplotlib.transforms.Transform url: str visible: bool zorder: float
- set_clim_std(mult)¶
Set the vmin and vmax to mult*std(self._A).
This routine only works on a 2D array.
- Parameters:
mult (float) – Multiplier.
- Return type:
None.
- set_data(A)¶
Set data.
- Parameters:
A (numpy/PIL Image A) – A numpy or PIL image.
- Raises:
TypeError – Error when data has incorrect dimensions.
- Return type:
None.
- set_extent(extent)¶
Set extent.
- Parameters:
extent (tuple) – Extent of data.
- Return type:
None.
- set_shade(doshade, cell=None, theta=None, phi=None, alpha=None)¶
Set the shade information.
- Parameters:
doshade (bool) – Check for whether to shade or not.
cell (float, optional) – Sunshade detail, between 1 and 100. The default is None.
theta (float, optional) – Sun inclination or elevation. The default is None.
phi (float, optional) – Sun declination or azimuth. The default is None.
alpha (float, optional) – Light reflectance, between 0 and 1. The default is None.
- Return type:
None.
- pygmi.raster.modest_ioimage.extract_matched_slices(axes=None, shape=None, transform=<matplotlib.transforms.IdentityTransform object>)¶
Determine the slice parameters to use, matched to the screen.
Indexing the full resolution array as array[y0:y1:sy, x0:x1:sx] returns a view well-matched to the axes’ resolution and extent
- Parameters:
axes (Axes, optional) – Axes object to query. It’s extent and pixel size determine the slice parameters. The default is None.
shape (tuple, optional) – Tuple of the full image shape to slice into. Upper boundaries for slices will be cropped to fit within this shape. The default is None.
transform (rasterio transform, optional) – Rasterio transform. The default is IDENTITY_TRANSFORM.
- Returns:
x0 (int) – x minimum.
x1 (int) – x maximum.
sx (int) – x stride.
y0 (int) – y minimum.
y1 (int) – y maximum.
sy (int) – y stride.
- pygmi.raster.modest_ioimage.imshow(axes, X, cmap=None, norm=None, aspect=None, interpolation=None, alpha=None, vmin=None, vmax=None, origin=None, extent=None, shape=None, filternorm=1, filterrad=4.0, imlim=None, resample=None, url=None, suncell=None, suntheta=None, sunphi=None, sunalpha=None, piter=<built-in function iter>, showlog=<built-in function print>, **kwargs)¶
Similar to matplotlib’s imshow command, but produces a ModestImage.
Unlike matplotlib version, must explicitly specify axes.
pygmi.raster.normalisation module¶
Normalisation function.
- class pygmi.raster.normalisation.Normalisation(parent=None)¶
Bases:
BasicModule
Class Normalisation.
- saveproj()¶
Save project data from class.
- Return type:
None.
- settings(nodialog=False)¶
Entry point into item.
- Parameters:
nodialog (bool, optional) – Run settings without a dialog. The default is False.
- Returns:
True if successful, False otherwise.
- Return type:
bool
- setupui()¶
Set up UI.
- Return type:
None.
- pygmi.raster.normalisation.datacommon(data, tmp1, tmp2)¶
Variables used in the process routine.
- Parameters:
data (PyGMI Data.) – PyGMI raster dataset.
tmp1 (float) – Parameter 1. Can be min, mean or median.
tmp2 (float) – Parameter 2. Can be range, std, or mad.
- Returns:
data (PyGMI Data) – PyGMI raster dataset.
transform (numpy array.) – Transformation applied to data.
pygmi.raster.show_table module¶
Routine which displays a table graphically with various stats.
- class pygmi.raster.show_table.BasicStats(parent=None)¶
Bases:
ContextModule
Show a summary of basic stats.
- combo()¶
Combo.
- Return type:
None.
- run()¶
Run.
- Return type:
None.
- save()¶
Save Table.
- Returns:
True if successful, False otherwise.
- Return type:
bool
- setupui()¶
Set up UI.
- Return type:
None.
- class pygmi.raster.show_table.ClusterStats(parent=None)¶
Bases:
ContextModule
Show a summary of basic statistics.
- combo()¶
Combo.
- Return type:
None.
- run()¶
Run.
- Returns:
True if successful, False otherwise.
- Return type:
bool
- save()¶
Save Table.
- Returns:
True if successful, False otherwise.
- Return type:
bool
- setupui()¶
Set up UI.
- Return type:
None.
- pygmi.raster.show_table.basicstats_calc(data)¶
Calculate statistics.
- Parameters:
data (PyGMI Data.) – PyGMI raster dataset.
- Returns:
bands (list) – Band list, currently only ‘Data Column’
cols (list) – Columns for the table
dattmp (list) – List of arrays containing statistics.
- pygmi.raster.show_table.savetable(ofile, bands, cols, data)¶
Save tabular data.
- Parameters:
ofile (str) – Output file name.
bands (list) – List of bands.
cols (list) – List of column headings.
data (list) – List of arrays containing statistics.
- Return type:
None.
pygmi.raster.smooth module¶
Smooth Data.
- class pygmi.raster.smooth.Smooth(parent=None)¶
Bases:
BasicModule
Smooth.
- choosefilter()¶
Section to choose the filter.
- Return type:
None.
- mov_win_filt(dat, fmat, itype)¶
Apply moving window filter function to data.
- Parameters:
dat (numpy masked array.) – Data for a PyGMI raster dataset.
fmat (numpy array) – Filter matrix.
itype (str) – Filter type. Can be ‘2D Mean’ or ‘2D Median’.
- Returns:
out – Data for a PyGMI raster dataset.
- Return type:
numpy masked array
- msgbox(title, message)¶
Message box.
- Parameters:
title (str) – Title for message box.
message (str) – Text for message box.
- Return type:
None.
- saveproj()¶
Save project data from class.
- Return type:
None.
- settings(nodialog=False)¶
Entry point into item.
- Parameters:
nodialog (bool, optional) – Run settings without a dialog. The default is False.
- Returns:
True if successful, False otherwise.
- Return type:
bool
- setupui()¶
Set up UI.
- Return type:
None.
- updatetable()¶
Update table.
- Return type:
None.
- pygmi.raster.smooth.filters2d(filtertype, sze, *sigma)¶
Filter 2D.
These filter definitions have been translated from the octave function ‘fspecial’.
Copyright (C) 2005 Peter Kovesi
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
FSPECIAL - Create spatial filters for image processing
Usage: f = fspecial(filtertype, optional parameters)
filtertype can be
‘average’ - Rectangular averaging filter‘disc’ - Circular averaging filter.‘gaussian’ - Gaussian filter.The parameters that need to be specified depend on the filtertype
Examples of use and associated default values:
f = fspecial(‘average’,sze) sze can be a 1 or 2 vectordefault is [3 3].f = fspecial(‘disk’,radius) default radius = 5f = fspecial(‘gaussian’,sze, sigma) default sigma is 0.5Where sze is specified as a single value the filter will be square.
Author: Peter Kovesi <pk@csse.uwa.edu.au> Keywords: image processing, spatial filters Created: August 2005
- Parameters:
filtertype (str) – Type of filter. Can be ‘average’, ‘disc’ or ‘gaussian’.
sze (numpy array or integer)) – This is a integer radius for ‘disc’ or a vector containing rows and columns otherwise.
sigma (numpy array) – numpy array containing std deviation. Used in ‘gaussian’.
- Returns:
f – Returns the filter to be used.
- Return type:
numpy array
Module contents¶
Raster Routines.