sgspy 1.0.1__cp312-cp312-manylinux_2_39_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. sgspy/__init__.py +82 -0
  2. sgspy/_sgs.cpython-312-x86_64-linux-gnu.so +0 -0
  3. sgspy/calculate/__init__.py +18 -0
  4. sgspy/calculate/pca/__init__.py +2 -0
  5. sgspy/calculate/pca/pca.py +152 -0
  6. sgspy/calculate/representation/__init__.py +2 -0
  7. sgspy/calculate/representation/representation.py +3 -0
  8. sgspy/sample/__init__.py +30 -0
  9. sgspy/sample/ahels/__init__.py +2 -0
  10. sgspy/sample/ahels/ahels.py +3 -0
  11. sgspy/sample/clhs/__init__.py +2 -0
  12. sgspy/sample/clhs/clhs.py +198 -0
  13. sgspy/sample/nc/__init__.py +2 -0
  14. sgspy/sample/nc/nc.py +3 -0
  15. sgspy/sample/srs/__init__.py +2 -0
  16. sgspy/sample/srs/srs.py +224 -0
  17. sgspy/sample/strat/__init__.py +2 -0
  18. sgspy/sample/strat/strat.py +390 -0
  19. sgspy/sample/systematic/__init__.py +2 -0
  20. sgspy/sample/systematic/systematic.py +229 -0
  21. sgspy/stratify/__init__.py +27 -0
  22. sgspy/stratify/breaks/__init__.py +2 -0
  23. sgspy/stratify/breaks/breaks.py +218 -0
  24. sgspy/stratify/kmeans/__init__.py +2 -0
  25. sgspy/stratify/kmeans/kmeans.py +3 -0
  26. sgspy/stratify/map/__init__.py +2 -0
  27. sgspy/stratify/map/map_stratifications.py +240 -0
  28. sgspy/stratify/poly/__init__.py +2 -0
  29. sgspy/stratify/poly/poly.py +166 -0
  30. sgspy/stratify/quantiles/__init__.py +2 -0
  31. sgspy/stratify/quantiles/quantiles.py +272 -0
  32. sgspy/utils/__init__.py +18 -0
  33. sgspy/utils/plot.py +143 -0
  34. sgspy/utils/raster.py +602 -0
  35. sgspy/utils/vector.py +262 -0
  36. sgspy-1.0.1.data/data/sgspy/libonedal.so.3 +0 -0
  37. sgspy-1.0.1.data/data/sgspy/proj.db +0 -0
  38. sgspy-1.0.1.dist-info/METADATA +13 -0
  39. sgspy-1.0.1.dist-info/RECORD +40 -0
  40. sgspy-1.0.1.dist-info/WHEEL +5 -0
@@ -0,0 +1,18 @@
1
+ ##
2
+ # @defgroup user_utils utils
3
+ # @ingroup user
4
+ #
5
+ # Explanations of both the SpatialRaster and SpatialVector classes.
6
+
7
+ from . import (
8
+ raster,
9
+ vector,
10
+ )
11
+
12
+ from .raster import SpatialRaster
13
+ from .vector import SpatialVector
14
+
15
+ __all__ = [
16
+ "SpatialRaster",
17
+ "spatialVector",
18
+ ]
sgspy/utils/plot.py ADDED
@@ -0,0 +1,143 @@
1
+ # ******************************************************************************
2
+ #
3
+ # Project: sgs
4
+ # Purpose: Plotting rasters and vectors with matplotlib.pyplot
5
+ # Author: Joseph Meyer
6
+ # Date: June, 2025
7
+ #
8
+ # ******************************************************************************
9
+
10
+ from typing import Optional
11
+
12
+ import numpy as np
13
+ import matplotlib.pyplot as plt
14
+ import matplotlib #for typing matplotlib.axes.Axes
15
+
16
+ def plot_raster(raster,
17
+ ax: matplotlib.axes.Axes,
18
+ target_width: int = 1000,
19
+ target_height: int = 1000,
20
+ band: Optional[int | str] = None,
21
+ **kwargs):
22
+ """
23
+ Plots the specified bands using matplotlib.pyplot.imshow function.
24
+
25
+ Parameters
26
+ --------------------
27
+ raster : SpatialRaster
28
+ raster to plot
29
+ ax : matplotlib axis
30
+ the axis to plot the image on
31
+ target_width : int
32
+ maximum width in pixels for the image (after downsampling)
33
+ target_height : int
34
+ maximum height in pxeils for the image (after downsampling)
35
+ band (optional) : int or str
36
+ specification of which band to plot
37
+ **kwargs (optional)
38
+ any parameters which may be passed to matplotlib.pyplot.imshow
39
+ """
40
+ #get bands argument as list of int
41
+ if band is None:
42
+ if raster.band_count > 1:
43
+ raise ValueError("'band' argument must be given if raster contains more than one band.")
44
+ band = 0
45
+ else:
46
+ band = raster.get_band_index(band)
47
+ title = raster.bands[band]
48
+
49
+ #calculate downsampled resolution and get downsampled raster
50
+ #for info on downsample resolution calculation:
51
+ #https://gdal.org/en/stable/api/gdaldataset_cpp.html#classGDALDataset_1ae66e21b09000133a0f4d99baabf7a0ec
52
+ target_downscaling_factor = min(raster.width / target_width, raster.height / target_height)
53
+ if (target_downscaling_factor <= 2 / 1.2):
54
+ downsampled_width = raster.width
55
+ downsampled_height = raster.height
56
+ elif (target_downscaling_factor <= 4 / 1.2):
57
+ downsampled_width = int(raster.width / 2)
58
+ downsampled_height = int(raster.height / 2)
59
+ elif (target_downscaling_factor <= 8 / 1.2):
60
+ downsampled_width = int(raster.width / 4)
61
+ downsampled_height = int(raster.height / 4)
62
+ else:
63
+ downsampled_width = int(raster.width / 8)
64
+ downsampled_height = int(raster.height / 8)
65
+
66
+ #get the raster data from the cpp object as a numpy array, and ensure no data is nan
67
+ no_data_val = raster.cpp_raster.get_band_nodata_value(band)
68
+ arr = np.asarray(
69
+ raster.cpp_raster.get_raster_as_memoryview(downsampled_width, downsampled_height, band),
70
+ copy=False
71
+ ).astype(np.float64, copy=True)
72
+ arr[arr == no_data_val] = np.nan
73
+
74
+ #get raster origin and raster extent
75
+ extent = (raster.xmin, raster.xmax, raster.ymin, raster.ymax) #(left, right, top, bottom)
76
+
77
+ #add image to matplotlib
78
+ plt.title(label=title)
79
+ ax.imshow(arr, origin='upper', extent=extent, **kwargs)
80
+
81
+ def plot_vector(vector,
82
+ ax: matplotlib.axes.Axes,
83
+ geomtype: str,
84
+ layer: Optional[int | str] = None,
85
+ **kwargs):
86
+ """
87
+ Plots the specified layer using matplotlib.pyplot.plot.
88
+ The parameter give by geomtype must be one of:
89
+ 'Point', 'MultiPoint', 'LineString', 'MultiLineString'.
90
+
91
+ The layer must contain only geometries of type Point and
92
+ MultiPoint in the case where 'Point' or 'MultiPoint is given,
93
+ or geometries of type LineString and MultiLineString
94
+ in the case where 'LineString' or 'MultiLineString' is given.
95
+
96
+ Parameters
97
+ --------------------
98
+ vector : SpatialVector
99
+ vector to plot
100
+ ax : matplotlib axis
101
+ the axis to plot the image on
102
+ geomtype : str
103
+ geometry type of the layer
104
+ layer : None | int | str
105
+ layer to plot
106
+ **kwargs (optional)
107
+ any parameter which may be passed to matplotlib.pyplot.plot
108
+
109
+ Raises
110
+ --------------------
111
+ ValueError:
112
+ if no layer was specified, and the image contains more than one layer
113
+ ValueError:
114
+ if geomtype is not one of 'Point', 'MultiPoint', 'LineString', 'MultiLineString'
115
+ RuntimeError (from C++):
116
+ if the layer contains a geometry NOT of an acceptable type
117
+ """
118
+
119
+ if type(layer) == str:
120
+ layer_name = layer
121
+ elif type(layer) == int:
122
+ layer_name = vector.layers[layer]
123
+ elif len(vector.layers) == 1: #layer is None
124
+ layer_name = vector.layers[0]
125
+ else:
126
+ ValueError("no layer was specified, and there is more than one layer in the vector. Specify a layer to plot.");
127
+
128
+ if geomtype == "Point" or geomtype == "MultiPoint":
129
+ points = vector.cpp_vector.get_points(layer_name)
130
+ if 'fmt' in kwargs:
131
+ ax.plot(points[0], points[1], **kwargs)
132
+ else:
133
+ ax.plot(points[0], points[1], '.r', **kwargs) #specify format as red points if format was not given
134
+ elif geomtype == "LineString" or geomtype == "MultiLineString":
135
+ lines = vector.cpp_vector.get_linestrings(layer_name)
136
+ if 'fmt' in kwargs:
137
+ for line in lines:
138
+ ax.plot(line[0], line[1], **kwargs)
139
+ else:
140
+ for line in lines:
141
+ ax.plot(line[0], line[1], '-k', **kwargs) #specify format as black lines if format was not give
142
+ else:
143
+ raise ValueError("geomtype must be of type 'Point', 'MultiPoint', 'LineString', or 'MultiLineString'");