From 37b53a1dbc03eaa768e798ef05f5961de96b7e1d Mon Sep 17 00:00:00 2001 From: Neil Flood Date: Fri, 24 May 2024 11:47:24 +1000 Subject: [PATCH] Guard against trying to subsample >100% of the data --- pyshepseg/tiling.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pyshepseg/tiling.py b/pyshepseg/tiling.py index 91b2b53..5be5b0f 100644 --- a/pyshepseg/tiling.py +++ b/pyshepseg/tiling.py @@ -171,8 +171,11 @@ def fitSpectralClustersWholeFile(inDs, bandNumbers, numClusters=60, # We will try to sample roughly this many pixels dfltTotalPixels = 1000000 totalImagePixels = inDs.RasterXSize * inDs.RasterYSize - # subsampleProp is the proportion of rows and columns sampled + # subsampleProp is the proportion of rows and columns sampled (hence + # sqrt of total proportion). subsampleProp = numpy.sqrt(dfltTotalPixels / totalImagePixels) + # Must be <= 1, i.e. sampling 100% of the data + subsampleProp = min(1, subsampleProp) # subsamplePcnt is the percentage of total pixels sampled subsamplePcnt = 100 * subsampleProp**2 else: