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

Allow raster_to_numpy_array to return arrays from overviews #315

Open
phargogh opened this issue Apr 6, 2023 · 0 comments
Open

Allow raster_to_numpy_array to return arrays from overviews #315

phargogh opened this issue Apr 6, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@phargogh
Copy link
Member

phargogh commented Apr 6, 2023

In the NCI water quality pipeline, it's convenient to be able to read overviews for some rasters, especially for use in a matplotlib graphic which will be downsampled anyways, rather than the full-resolution array. We can do this with GDAL, but it might be nice to have some of this boilerplate in a nicer function.

        factor = 2  # determined by another process
        pygeoprocessing.build_overviews(
            raster_path, resample_method='near', internal=False,
            overwrite=True, levels=[factor])

        raster = gdal.Open(raster_path)
        source_band = raster.GetRasterBand(1)
        if factor == 1:
            mapp = source_band.ReadAsArray()
        else:
            # We built overviews with factor 4, but these are available at the
            # 0th overview layer.
            overview_band = source_band.GetOverview(0)
            mapp = overview_band.ReadAsArray()

I'm thinking that it might be nice to be able to request `pygeoprocessing.raster_to_numpy_array(path, overview=2) and then have it determine the correct overview based on the resolution.

@phargogh phargogh added the enhancement New feature or request label Apr 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant