pygmi.raster.dataprep#
A set of raster data preparation routines.
Classes#
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. |
|
Raster to vector GUI. |
|
Raster to vector boundary GUI. |
Functions#
|
Convert cluster datasets to raster datasets. |
|
Get bounds from a shape file. |
|
Merge using median for rasterio, taking minimum value. |
|
Merge using median for rasterio, taking minimum value. |
|
Sort data in an order which ensures overlaps. |
|
Merge files with different numbers of bands and/or band order. |
|
Redistribute vertices in a geometry. |
|
Trim nulls from a raster dataset. |
|
Vertical derivative. |
Module Contents#
- class pygmi.raster.dataprep.DataCut(parent=None)#
Bases:
pygmi.misc.BasicModuleGUI to Cut Data using shapefiles.
This class cuts raster datasets using a boundary defined by a polygon shapefile.
- Parameters:
parent – Reference to the parent routine. The default is None.
- settings(nodialog=False)#
Entry point into item.
- Parameters:
nodialog (bool) – Run settings without a dialog. The default is False.
- Returns:
True if successful, False otherwise.
- Return type:
bool
- saveproj()#
Save project data from class.
- class pygmi.raster.dataprep.DataLayerStack(parent=None)#
Bases:
pygmi.misc.BasicModuleData 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 – Reference to the parent routine. The default is None.
- setupui()#
Set up UI.
- dxy_change()#
Update dxy.
This is the size of a grid cell in the x and y directions.
- settings(nodialog=False)#
Entry point into item.
- Parameters:
nodialog (bool) – Run settings without a dialog. The default is False.
- Returns:
True if successful, False otherwise.
- Return type:
bool
- saveproj()#
Save project data from class.
- acceptall()#
Accept option.
Updates self.outdata, which is used as input to other modules.
- class pygmi.raster.dataprep.DataMerge(parent=None)#
Bases:
pygmi.misc.BasicModuleData 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 – Reference to the parent routine. The default is None.
- setupui()#
Set up UI.
- method_change()#
Change method.
- get_idir()#
Get the input directory.
- get_sfile()#
Get the input shapefile.
- Returns:
True if successful, False otherwise.
- Return type:
bool
- 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.
- 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.BasicModuleRaster reprojection GUI.
This class reprojects datasets using the rasterio routines.
- Parameters:
parent – Reference to the parent routine. The default is None.
- setupui()#
Set up UI.
- acceptall()#
Accept option.
Updates self.outdata, which is used as input to other modules.
- settings(nodialog=False)#
Entry point into item.
- Parameters:
nodialog (bool) – Run settings without a dialog. The default is False.
- Returns:
True if successful, False otherwise.
- Return type:
bool
- saveproj()#
Save project data from class.
- class pygmi.raster.dataprep.GetProf(parent=None)#
Bases:
pygmi.misc.BasicModuleGUI to extract a profile from a raster dataset.
This class extracts a profile from a raster dataset using a line shapefile.
- Parameters:
parent – Reference to the parent routine. The default is None.
- settings(nodialog=False)#
Entry point into item.
- Parameters:
nodialog (bool) – Run settings without a dialog. The default is False.
- Returns:
True if successful, False otherwise.
- Return type:
bool
- saveproj()#
Save project data from class.
- class pygmi.raster.dataprep.Metadata(parent=None)#
Bases:
pygmi.misc.ContextModuleEdit raster metadata.
This class allows the editing of the metadata for a raster dataset using a GUI.
- Parameters:
parent – 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.
- acceptall()#
Accept option.
- rename_id()#
Rename the band name.
- update_vals()#
Update the values on the interface.
- run()#
Entry point into the routine, used to run context menu item.
- class pygmi.raster.dataprep.RasterToVector(parent=None)#
Bases:
pygmi.misc.BasicModuleRaster to vector GUI.
- Parameters:
parent – Reference to the parent routine. The default is None.
- setupui()#
Set up UI.
- settings(nodialog=False)#
Entry point into item.
- Parameters:
nodialog (bool) – Run settings without a dialog. The default is False.
- Returns:
True if successful, False otherwise.
- Return type:
bool
- saveproj()#
Save project data from class.
- class pygmi.raster.dataprep.RasterToVectorBoundary(parent=None)#
Bases:
pygmi.misc.BasicModuleRaster to vector boundary GUI.
- Parameters:
parent – Reference to the parent routine. The default is None.
- setupui()#
Set up UI.
- settings(nodialog=False)#
Entry point into item.
- Parameters:
nodialog (bool) – Run settings without a dialog. The default is False.
- Returns:
True if successful, False otherwise.
- Return type:
bool
- saveproj()#
Save project data from class.
- 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 (Data).
- Returns:
Dictionary of PyGMI datasets (Data).
- Return type:
dict
- pygmi.raster.dataprep.get_shape_bounds(sfile, crs=None, showlog=print)#
Get bounds from a shape file.
- Parameters:
sfile (str) – Filename for shapefile.
crs (int | str | pyproj.crs.CRS | None) – Target CRS for shapefile
showlog (collections.abc.Callable[..., None]) – Display information. The default is print.
- Returns:
Rasterio bounds.
- Return type:
tupleoffloats
- pygmi.raster.dataprep.merge_median_last(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.typing.NDArray) – Old data.
new_data (numpy.typing.NDArray) – New data to merge to old data.
merged_mask (numpy.typing.NDArray) – Old mask.
new_mask (numpy.typing.NDArray) – New mask.
index (int | None) – index of the current dataset within the merged dataset collection. The default is None.
roff (int | None) – row offset in base array. The default is None.
coff (int | None) – col offset in base array. The default is None.
- pygmi.raster.dataprep.merge_median_first(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.
- pygmi.raster.dataprep.merge_order(ifiles, igeoms)#
Sort data in an order which ensures overlaps.
- Parameters:
ifiles (list[str]) – list of filenames
igeoms (list[shapely.geometry.base.BaseGeometry]) – list of geometries
- Returns:
list of filenames
- Return type:
listofstr
- 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, ifiles=None, resampling='nearest')#
Merge files with different numbers of bands and/or band order.
This uses more memory, but is flexible.
- Parameters:
dat (list[pygmi.raster.datatypes.Data]) – List of PyGMI data bands to be merged. Can be empty if idir is provided.
idir (str | None) – Directory where file to be mosaiced are found. The default is None.
bfile (str | None) – Path to boundary file. Can be shapefile or raster. The default is None.
bandstofiles (bool) – Export output bands to files. The default is False.
piter (collections.abc.Iterable) – Progress bar iterable. The default is iter.
showlog (collections.abc.Callable[..., None]) – Function for printing text. The default is print.
singleband (bool) – Ignore band names, since there is only one band. The default is False.
forcetype (bool | None) – Force input data type. The default is None.
shifttomedian (bool) – Shift bands to median value. The default is False.
tmpdir (str | None) – Alternate directory for temporary files. The default is None.
nodata (float | numpy.floating | None) – Nodata value. The default is None.
method (str | object) – Mosaic method. Can be ‘first’, ‘last’, ‘min’, ‘max’, ‘merge_median_last’ or ‘merge_median_first. The default is ‘first’.
res (float | None) – Output resolution. Can be a tuple. The default is None.
ifiles (list[str] | None) – List of input files.
resampling (str) – Resampling type to use.
- Returns:
Output mosaiced dataset.
- Return type:
listofData
- 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.base.BaseGeometry) – Geometry from geopandas.
distance (float) – sampling distance.
- Raises:
ValueError – Error when there is an unknown geometry.
- Returns:
New geometry.
- Return type:
BaseGeometry
- 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[pygmi.raster.datatypes.Data]) – PyGMI dataset.
- Returns:
Trimmed PyGMI dataset.
- Return type:
listofData
- pygmi.raster.dataprep.verticalp(data, order=1, showlog=print, piter=iter)#
Vertical derivative.
- Parameters:
data (pygmi.raster.datatypes.Data) – Input raster data.
order (float) – Order. The default is 1.
showlog (collections.abc.Callable[..., None]) – Function for printing text. The default is print.
piter (collections.abc.Iterable) – Progress bar iterable. The default is iter.
- Returns:
Output data
- Return type:
ndarray