pygmi.raster.dataprep#
A set of Raster Data Preparation routines.
Classes#
GUI to perform upward and downward continuation on potential field data. |
|
GUI to Cut Data using shapefiles. |
|
Data Layer Stack GUI. |
|
Data merge or mosaic GUI. |
|
Raster reprojection GUI. |
|
GUI to extract a profile from a raster dataset. |
|
Edit raster metadata. |
Functions#
|
Convert cluster datasets to raster datasets. |
|
FFT preparation. |
|
Get KX and KY. |
|
Continuation. |
|
Get bounds from a shape file. |
|
Merge using median for rasterio, taking minimum value. |
|
Merge using minimum for rasterio, taking minimum value. |
|
Merge using maximum for rasterio, taking maximum value. |
|
Merge files with different numbers of bands and/or band order. |
|
Redistribute vertices in a geometry. |
|
Taylor Continuation. |
|
Trim nulls from a raster dataset. |
|
Vertical derivative. |
Module Contents#
- class pygmi.raster.dataprep.Continuation(parent=None)#
Bases:
pygmi.misc.BasicModule
GUI to perform upward and downward continuation on potential field data.
- Parameters:
parent (parent, optional) – Reference to the parent routine. The default is None.
- setupui()#
Set up UI.
- 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
- saveproj()#
Save project data from class.
- Return type:
None.
- acceptall()#
Accept option.
Updates self.outdata, which is used as input to other modules.
- Return type:
None.
- class pygmi.raster.dataprep.DataCut(parent=None)#
Bases:
pygmi.misc.BasicModule
GUI to Cut Data using shapefiles.
This class cuts raster datasets using a boundary defined by a polygon shapefile.
- Parameters:
parent (parent, optional) – Reference to the parent routine. The default is 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
- saveproj()#
Save project data from class.
- Return type:
None.
- class pygmi.raster.dataprep.DataLayerStack(parent=None)#
Bases:
pygmi.misc.BasicModule
Data Layer Stack GUI.
This class merges datasets which have different rows and columns. It resamples them so that they have the same rows and columns.
- Parameters:
parent (parent, optional) – Reference to the parent routine. The default is None.
- setupui()#
Set up UI.
- Return type:
None.
- dxy_change()#
Update dxy.
This is the size of a grid cell in the x and y directions.
- 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
- saveproj()#
Save project data from class.
- Return type:
None.
- acceptall()#
Accept option.
Updates self.outdata, which is used as input to other modules.
- Return type:
None.
- class pygmi.raster.dataprep.DataMerge(parent=None)#
Bases:
pygmi.misc.BasicModule
Data merge or mosaic GUI.
This class merges datasets which have different rows and columns. It resamples them so that they have the same rows and columns.
- Parameters:
parent (parent, optional) – Reference to the parent routine. The default is None.
- setupui()#
Set up UI.
- Return type:
None.
- method_change()#
Change method.
- Return type:
None.
- get_idir()#
Get the input directory.
- Return type:
None.
- get_sfile()#
Get the input shapefile.
- 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
- saveproj()#
Save project data from class.
- 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
- class pygmi.raster.dataprep.DataReproj(parent=None)#
Bases:
pygmi.misc.BasicModule
Raster reprojection GUI.
This class reprojects datasets using the rasterio routines.
- Parameters:
parent (parent, optional) – Reference to the parent routine. The default is None.
- setupui()#
Set up UI.
- Return type:
None.
- acceptall()#
Accept option.
Updates self.outdata, which is used as input to other modules.
- 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
- saveproj()#
Save project data from class.
- Return type:
None.
- class pygmi.raster.dataprep.GetProf(parent=None)#
Bases:
pygmi.misc.BasicModule
GUI to extract a profile from a raster dataset.
This class extracts a profile from a raster dataset using a line shapefile.
- Parameters:
parent (parent, optional) – Reference to the parent routine. The default is 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
- saveproj()#
Save project data from class.
- Return type:
None.
- class pygmi.raster.dataprep.Metadata(parent=None)#
Bases:
pygmi.misc.ContextModule
Edit raster metadata.
This class allows the editing of the metadata for a raster dataset using a GUI.
- Parameters:
parent (parent, optional) – Reference to the parent routine. The default is None.
- banddata#
band data
- Type:
dictionary
- bandid#
dictionary of strings containing band names.
- Type:
dictionary
- setupui()#
Set up UI.
- Return type:
None.
- acceptall()#
Accept option.
- Return type:
None.
- rename_id()#
Rename the band name.
- Return type:
None.
- update_vals()#
Update the values on the interface.
- Return type:
None.
- run()#
Entry point into the routine, used to run context menu item.
- Returns:
tmp – True if successful, False otherwise.
- Return type:
bool
- 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.
- Parameters:
indata (dict) – Dictionary of PyGMI datasets.
- Returns:
indata – Dictionary of PyGMI datasets.
- Return type:
dict
- pygmi.raster.dataprep.fftprep(data)#
FFT preparation.
- Parameters:
data (pygmi.raster.datatypes.Data) – 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.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.raster.datatypes.Data) – PyGMI raster data.
h (float) – Height.
- Returns:
dat – PyGMI raster data.
- Return type:
- pygmi.raster.dataprep.get_shape_bounds(sfile, crs=None, showlog=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.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.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.mosaic(dat, *, idir=None, bfile=None, bandstofiles=False, piter=iter, showlog=print, singleband=False, forcetype=None, shifttomedian=False, tmpdir=None, nodata=None, method='first', res=None)#
Merge files with different numbers of bands and/or band order.
This uses more memory, but is flexible.
- Parameters:
dat (list) – List of PyGMI data bands to be merged. Can be empty if idir is provided.
idir (str, optional) – Directory where file to be mosaiced are found. The default is None.
bfile (str, optional) – Path to boundary file. Can be shapefile or raster. The default is None.
bandstofiles (bool, optional) – Export output bands to files. The default is False.
piter (function, optional) – Progress bar iterable. The default is iter.
showlog (function, optional) – Function for printing text. The default is print.
singleband (bool, optional) – Ignore band names, since there is only one band. The default is False.
forcetype (bool, optional) – Force input data type. The default is None.
shifttomedian (bool, optional) – Shift bands to median value. The default is False.
tmpdir (str, optional) – Alternate directory for temporary files. The default is None.
nodata (float, optional) – Nodata value. The default is None.
method (str, optional) – Mosaic method. Can be ‘first’, ‘last’, ‘merge_min’, ‘merge_max’ or ‘merge_median. The default is ‘first’.
res (float, optional) – Output resolution. Can be a tuple. The default is None.
- Returns:
outdat – Output mosaiced dataset.
- Return type:
PyGMI raster data
- 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.raster.datatypes.Data) – PyGMI raster data.
h (float) – Height.
- Returns:
dat – PyGMI raster data.
- Return type:
- 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.raster.datatypes.Data) – PyGMI dataset.
- Returns:
olddata – PyGMI dataset.
- Return type:
list of pygmi.raster.datatypes.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