Skip to content

Commit

Permalink
Scrambled singlepass pyramids (#117)
Browse files Browse the repository at this point in the history
* Test more than the first pyramid layer

* Pyramid layers beyond the first one were scrambled

* Minor change to trigger Github, to see if it is behaving now

* Minor change to poke Github again

* Trying setup-miniconda v3

* Remove use of Mambaforge

* Remove Mambaforge from all test runs. Apparently it is no longer supported
  • Loading branch information
neilflood authored Oct 1, 2024
1 parent 51740f2 commit baef954
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 32 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ jobs:
- uses: conda-incubator/setup-miniconda@v2
with:
miniforge-version: latest
miniforge-variant: Mambaforge
- name: Install dependencies
shell: bash -l {0}
run: conda install gdal libgdal-kea cloudpickle scipy
Expand Down Expand Up @@ -62,7 +61,6 @@ jobs:
- uses: conda-incubator/setup-miniconda@v2
with:
miniforge-version: latest
miniforge-variant: Mambaforge
- name: Install dependencies
run: conda install gdal cloudpickle scipy
- name: Test with testrios
Expand All @@ -78,7 +76,6 @@ jobs:
- uses: conda-incubator/setup-miniconda@v2
with:
miniforge-version: latest
miniforge-variant: Mambaforge
- name: Install dependencies
shell: bash -l {0}
run: conda install gdal cloudpickle scipy
Expand Down
7 changes: 4 additions & 3 deletions rios/calcstats.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
This module creates pyramid layers and calculates statistics for image
files. Much of it was originally for ERDAS Imagine files but should work
files. Much of it was originally for ERDAS Imagine files but should work
with any other format that supports pyramid layers and statistics
"""
Expand Down Expand Up @@ -28,6 +28,7 @@
from . import cuiprogress
from .rioserrors import ProcessCancelledError, SinglePassActionsError


# When calculating overviews (i.e. pyramid layers), default behaviour
# is controlled by these
dfltOverviewLvls = os.getenv('RIOS_DFLT_OVERVIEWLEVELS')
Expand Down Expand Up @@ -831,8 +832,8 @@ def writeBlockPyramids(ds, arr, singlePassMgr, symbolicName, xOff, yOff):
for i in range(numBands):
band = ds.GetRasterBand(i + 1)
for j in range(nOverviews):
band_ov = band.GetOverview(i)
lvl = overviewLevels[i]
band_ov = band.GetOverview(j)
lvl = overviewLevels[j]
# Offset from top-left edge
o = lvl // 2
# Sub-sample by taking every lvl-th pixel in each direction
Expand Down
53 changes: 27 additions & 26 deletions rios/riostests/testpyramids.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def run():

# Create a test input file
rampInfile = 'ramp.img'
# Set a raster size which will result in exactly one pyramid layer
nRows = nCols = 1024
# Set a raster size which will result in exactly two pyramid layers
nRows = nCols = 2048
riostestutils.genRampImageFile(rampInfile, numRows=nRows, numCols=nCols)

infiles = applier.FilenameAssociations()
Expand Down Expand Up @@ -84,36 +84,37 @@ def checkPyramids(filename, singlePass):
band = ds.GetRasterBand(1)
arr = band.ReadAsArray()
numOverviews = band.GetOverviewCount()
if numOverviews != 1:
if numOverviews != 2:
msg = "Incorrect overview count: {}".format(numOverviews)
riostestutils.report(TESTNAME, msg)
ok = False

band_ov = band.GetOverview(0)
arr_ov = band_ov.ReadAsArray()

# Work out which offset (o) to use
factor = int(round(arr.shape[0] / arr_ov.shape[0]))
if singlePass:
o = int(round(factor / 2))
else:
# GDAL doesn't use an offset (sigh....)
o = 0

# The true sub-sampled overview array
true_arr_ov = arr[o::factor, o::factor]
if true_arr_ov.shape != arr_ov.shape:
msg = "Overview shape mis-match: {} != {}".format(true_arr_ov.shape,
arr_ov.shape)
riostestutils.report(TESTNAME, msg)
ok = False
else:
mismatch = (arr_ov != true_arr_ov)
numMismatch = numpy.count_nonzero(mismatch)
if numMismatch > 0:
msg = "Pyramid layer pixel mis-match for {} pixels".format(numMismatch)
for i in range(numOverviews):
band_ov = band.GetOverview(i)
arr_ov = band_ov.ReadAsArray()

# Work out which offset (o) to use
factor = int(round(arr.shape[0] / arr_ov.shape[0]))
if singlePass:
o = int(round(factor / 2))
else:
# GDAL doesn't use an offset (sigh....)
o = 0

# The true sub-sampled overview array
true_arr_ov = arr[o::factor, o::factor]
if true_arr_ov.shape != arr_ov.shape:
msg = "Overview shape mis-match: {} != {}".format(true_arr_ov.shape,
arr_ov.shape)
riostestutils.report(TESTNAME, msg)
ok = False
else:
mismatch = (arr_ov != true_arr_ov)
numMismatch = numpy.count_nonzero(mismatch)
if numMismatch > 0:
msg = "Pyramid layer pixel mis-match for {} pixels".format(numMismatch)
riostestutils.report(TESTNAME, msg)
ok = False

return ok

Expand Down

0 comments on commit baef954

Please sign in to comment.