dea-tools 0.4.7.dev11__tar.gz → 0.4.8.dev12__tar.gz
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.
- {dea_tools-0.4.7.dev11 → dea_tools-0.4.8.dev12}/PKG-INFO +1 -1
- {dea_tools-0.4.7.dev11 → dea_tools-0.4.8.dev12}/Tools/dea_tools/validation.py +18 -9
- {dea_tools-0.4.7.dev11 → dea_tools-0.4.8.dev12}/.gitignore +0 -0
- {dea_tools-0.4.7.dev11 → dea_tools-0.4.8.dev12}/LICENSE +0 -0
- {dea_tools-0.4.7.dev11 → dea_tools-0.4.8.dev12}/Tools/README.md +0 -0
- {dea_tools-0.4.7.dev11 → dea_tools-0.4.8.dev12}/Tools/dea_tools/__init__.py +0 -0
- {dea_tools-0.4.7.dev11 → dea_tools-0.4.8.dev12}/Tools/dea_tools/__main__.py +0 -0
- {dea_tools-0.4.7.dev11 → dea_tools-0.4.8.dev12}/Tools/dea_tools/app/__init__.py +0 -0
- {dea_tools-0.4.7.dev11 → dea_tools-0.4.8.dev12}/Tools/dea_tools/app/animations.py +0 -0
- {dea_tools-0.4.7.dev11 → dea_tools-0.4.8.dev12}/Tools/dea_tools/app/changefilmstrips.py +0 -0
- {dea_tools-0.4.7.dev11 → dea_tools-0.4.8.dev12}/Tools/dea_tools/app/crophealth.py +0 -0
- {dea_tools-0.4.7.dev11 → dea_tools-0.4.8.dev12}/Tools/dea_tools/app/deacoastlines.py +0 -0
- {dea_tools-0.4.7.dev11 → dea_tools-0.4.8.dev12}/Tools/dea_tools/app/geomedian.py +0 -0
- {dea_tools-0.4.7.dev11 → dea_tools-0.4.8.dev12}/Tools/dea_tools/app/imageexport.py +0 -0
- {dea_tools-0.4.7.dev11 → dea_tools-0.4.8.dev12}/Tools/dea_tools/app/miningrehab.py +0 -0
- {dea_tools-0.4.7.dev11 → dea_tools-0.4.8.dev12}/Tools/dea_tools/app/wetlandsinsighttool.py +0 -0
- {dea_tools-0.4.7.dev11 → dea_tools-0.4.8.dev12}/Tools/dea_tools/app/widgetconstructors.py +0 -0
- {dea_tools-0.4.7.dev11 → dea_tools-0.4.8.dev12}/Tools/dea_tools/bandindices.py +0 -0
- {dea_tools-0.4.7.dev11 → dea_tools-0.4.8.dev12}/Tools/dea_tools/bom.py +0 -0
- {dea_tools-0.4.7.dev11 → dea_tools-0.4.8.dev12}/Tools/dea_tools/classification.py +0 -0
- {dea_tools-0.4.7.dev11 → dea_tools-0.4.8.dev12}/Tools/dea_tools/coastal.py +0 -0
- {dea_tools-0.4.7.dev11 → dea_tools-0.4.8.dev12}/Tools/dea_tools/dask.py +0 -0
- {dea_tools-0.4.7.dev11 → dea_tools-0.4.8.dev12}/Tools/dea_tools/datahandling.py +0 -0
- {dea_tools-0.4.7.dev11 → dea_tools-0.4.8.dev12}/Tools/dea_tools/landcover.py +0 -0
- {dea_tools-0.4.7.dev11 → dea_tools-0.4.8.dev12}/Tools/dea_tools/maps.py +0 -0
- {dea_tools-0.4.7.dev11 → dea_tools-0.4.8.dev12}/Tools/dea_tools/mosaics/README.md +0 -0
- {dea_tools-0.4.7.dev11 → dea_tools-0.4.8.dev12}/Tools/dea_tools/mosaics/__init__.py +0 -0
- {dea_tools-0.4.7.dev11 → dea_tools-0.4.8.dev12}/Tools/dea_tools/mosaics/cog.py +0 -0
- {dea_tools-0.4.7.dev11 → dea_tools-0.4.8.dev12}/Tools/dea_tools/mosaics/styling.py +0 -0
- {dea_tools-0.4.7.dev11 → dea_tools-0.4.8.dev12}/Tools/dea_tools/mosaics/utils.py +0 -0
- {dea_tools-0.4.7.dev11 → dea_tools-0.4.8.dev12}/Tools/dea_tools/mosaics/vrt.py +0 -0
- {dea_tools-0.4.7.dev11 → dea_tools-0.4.8.dev12}/Tools/dea_tools/plotting.py +0 -0
- {dea_tools-0.4.7.dev11 → dea_tools-0.4.8.dev12}/Tools/dea_tools/spatial.py +0 -0
- {dea_tools-0.4.7.dev11 → dea_tools-0.4.8.dev12}/Tools/dea_tools/temporal.py +0 -0
- {dea_tools-0.4.7.dev11 → dea_tools-0.4.8.dev12}/Tools/dea_tools/waterbodies.py +0 -0
- {dea_tools-0.4.7.dev11 → dea_tools-0.4.8.dev12}/Tools/dea_tools/wetlands.py +0 -0
- {dea_tools-0.4.7.dev11 → dea_tools-0.4.8.dev12}/pyproject.toml +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dea-tools
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.8.dev12
|
|
4
4
|
Summary: Open-source tools for geospatial analysis with Digital Earth Australia, Open Data Cube, and Xarray
|
|
5
5
|
Project-URL: Homepage, https://knowledge.dea.ga.gov.au/notebooks/Tools/
|
|
6
6
|
Project-URL: Repository, https://github.com/GeoscienceAustralia/dea-notebooks
|
|
@@ -98,8 +98,10 @@ def xr_random_sampling(
|
|
|
98
98
|
sampling="stratified_random",
|
|
99
99
|
manual_class_ratios=None,
|
|
100
100
|
oversample_factor=5,
|
|
101
|
+
random_seed=None,
|
|
101
102
|
out_fname=None,
|
|
102
103
|
verbose=True,
|
|
104
|
+
|
|
103
105
|
):
|
|
104
106
|
"""
|
|
105
107
|
Efficient and scalable random sampling of a 2D classified xarray.DataArray.
|
|
@@ -143,6 +145,8 @@ def xr_random_sampling(
|
|
|
143
145
|
Increasing this value can improve success rates when sampling sparse or
|
|
144
146
|
spatially fragmented classes in large datasets, at the cost of more memory
|
|
145
147
|
and computation.
|
|
148
|
+
random_seed : int | None, optional
|
|
149
|
+
Controls the random number generation for reproducibility.
|
|
146
150
|
out_fname : str, optional
|
|
147
151
|
If providing a filepath name, e.g 'sample_points.geojson', the
|
|
148
152
|
function will export a geojson (or shapefile) of the sampling
|
|
@@ -175,6 +179,10 @@ def xr_random_sampling(
|
|
|
175
179
|
if not isinstance(da, xr.DataArray):
|
|
176
180
|
raise ValueError("This function only accepts xarray.DataArrays as input")
|
|
177
181
|
|
|
182
|
+
# --- Setup local RNG ---
|
|
183
|
+
# random_seed=None → entropy; int → reproducible
|
|
184
|
+
rng = np.random.default_rng(random_seed)
|
|
185
|
+
|
|
178
186
|
# Ensure da has a .odc.* accessor using odc.geo.
|
|
179
187
|
da = add_geobox(da)
|
|
180
188
|
|
|
@@ -187,10 +195,10 @@ def xr_random_sampling(
|
|
|
187
195
|
unique_classes, class_counts = np.unique(data[~np.isnan(data)], return_counts=True)
|
|
188
196
|
|
|
189
197
|
unique_classes = unique_classes.astype(int)
|
|
190
|
-
|
|
198
|
+
|
|
191
199
|
# store our samples in a list
|
|
192
200
|
samples = []
|
|
193
|
-
|
|
201
|
+
|
|
194
202
|
if sampling == "random":
|
|
195
203
|
# first check num of samples doesn't exceed pixels
|
|
196
204
|
total_valid = (~np.isnan(data)).sum()
|
|
@@ -204,7 +212,7 @@ def xr_random_sampling(
|
|
|
204
212
|
flat_indices = np.flatnonzero(~np.isnan(data))
|
|
205
213
|
|
|
206
214
|
# sample the flat indices
|
|
207
|
-
sampled =
|
|
215
|
+
sampled = rng.choice(flat_indices, size=n, replace=False)
|
|
208
216
|
|
|
209
217
|
# get coords and class values from sample indices
|
|
210
218
|
for idx in sampled:
|
|
@@ -242,9 +250,9 @@ def xr_random_sampling(
|
|
|
242
250
|
if class_count > 1e9: # For v. large classes, sample random coords first and check matches
|
|
243
251
|
# Try oversampling until we get enough
|
|
244
252
|
n_try = int(sample_size * oversample_factor)
|
|
245
|
-
rand_x = np.random.choice(np.arange(len(da.x)), n_try, replace=False)
|
|
246
253
|
|
|
247
|
-
|
|
254
|
+
rand_x = rng.choice(np.arange(len(da.x)), n_try, replace=False)
|
|
255
|
+
rand_y = rng.choice(np.arange(len(da.y)), n_try, replace=False)
|
|
248
256
|
|
|
249
257
|
# find matches with class id
|
|
250
258
|
match = data[rand_y, rand_x] == cls
|
|
@@ -258,8 +266,8 @@ def xr_random_sampling(
|
|
|
258
266
|
f"Warning: insufficient matches for class {cls}, "
|
|
259
267
|
f"try increasing oversampling. Returning {len(rand_y)} matches"
|
|
260
268
|
)
|
|
261
|
-
|
|
262
|
-
|
|
269
|
+
idx = rng.choice(np.arange(len(rand_y)), size=len(rand_y), replace=False)
|
|
270
|
+
|
|
263
271
|
for i in idx:
|
|
264
272
|
y = da[y_dim].values[rand_y[i]]
|
|
265
273
|
x = da[x_dim].values[rand_x[i]]
|
|
@@ -268,7 +276,8 @@ def xr_random_sampling(
|
|
|
268
276
|
else:
|
|
269
277
|
# If more matches than samples, then randomly sample the matches so we get the
|
|
270
278
|
# the right number of samples.
|
|
271
|
-
idx =
|
|
279
|
+
idx = rng.choice(np.arange(len(rand_y)), size=sample_size, replace=False)
|
|
280
|
+
|
|
272
281
|
for i in idx:
|
|
273
282
|
y = da[y_dim].values[rand_y[i]]
|
|
274
283
|
x = da[x_dim].values[rand_x[i]]
|
|
@@ -286,7 +295,7 @@ def xr_random_sampling(
|
|
|
286
295
|
continue
|
|
287
296
|
|
|
288
297
|
# Randomly sample from those flat indices
|
|
289
|
-
sampled =
|
|
298
|
+
sampled = rng.choice(flat_indices, size=sample_size, replace=False)
|
|
290
299
|
|
|
291
300
|
# Convert flat indices to (y, x), then to coordinates
|
|
292
301
|
for idx in sampled:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|