Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numpy2 fixes #90

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions rios/calcstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))

Expand All @@ -315,19 +315,19 @@ 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
gtmiddle = hist.cumsum() >= middlenum
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)))

Expand Down
4 changes: 4 additions & 0 deletions rios/riostests/testvector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading