diff --git a/rios/calcstats.py b/rios/calcstats.py index 501b5cc..6db7e9a 100644 --- a/rios/calcstats.py +++ b/rios/calcstats.py @@ -294,7 +294,7 @@ def addStatistics(ds, progress, ignore=None, approx_ok=False): modebin = numpy.argmax(hist) modeval = modebin * histstep + histmin if band.DataType == gdal.GDT_Float32 or band.DataType == gdal.GDT_Float64: - tmpmeta["STATISTICS_MODE"] = repr(modeval) + tmpmeta["STATISTICS_MODE"] = repr(float(modeval)) else: tmpmeta["STATISTICS_MODE"] = repr(int(round(modeval))) @@ -315,11 +315,11 @@ def addStatistics(ds, progress, ignore=None, approx_ok=False): else: # Use GDAL's original metadata interface, for drivers which # don't support the more modern approach - tmpmeta["STATISTICS_HISTOBINVALUES"] = '|'.join(map(repr, hist)) + '|' + tmpmeta["STATISTICS_HISTOBINVALUES"] = '|'.join(map(str, hist)) + '|' tmpmeta["STATISTICS_HISTOMIN"] = repr(histmin) tmpmeta["STATISTICS_HISTOMAX"] = repr(histmax) - tmpmeta["STATISTICS_HISTONUMBINS"] = repr(histnbins) + tmpmeta["STATISTICS_HISTONUMBINS"] = int(histnbins) # estimate the median - bin with the middle number middlenum = hist.sum() / 2 @@ -327,7 +327,7 @@ def addStatistics(ds, progress, ignore=None, approx_ok=False): medianbin = gtmiddle.nonzero()[0][0] medianval = medianbin * histstep + histmin if band.DataType == gdal.GDT_Float32 or band.DataType == gdal.GDT_Float64: - tmpmeta["STATISTICS_MEDIAN"] = repr(medianval) + tmpmeta["STATISTICS_MEDIAN"] = repr(float(medianval)) else: tmpmeta["STATISTICS_MEDIAN"] = repr(int(round(medianval))) diff --git a/rios/riostests/testvector.py b/rios/riostests/testvector.py index d69637c..a2437c8 100644 --- a/rios/riostests/testvector.py +++ b/rios/riostests/testvector.py @@ -47,6 +47,10 @@ def run(): meanVal_rios = calcMeanWithRiosApplier(imgfile, vecfile) ok = True + # Since numpy-2, these have different precisions. The numpy-calculated + # value is numpy.float64, while the rios-calculated one is numpy.float32. + # So, cast the longer one to match the shorter. Sigh..... + meanVal_numpy = numpy.asarray(meanVal_numpy, dtype=meanVal_rios.dtype) if meanVal_numpy == meanVal_rios: riostestutils.report(TESTNAME, "Passed") else: