Re: Is it possible to ignore existing overview when performing decimated read?
Denis Rykov
You can find an example how to do that here: https://github.com/mapbox/rasterio/issues/1929.
On Tue, Nov 10, 2020, 8:12 PM Loïc Dutrieux <loic.dutrieux@...> wrote: Hi everyone,
|
|
Is it possible to ignore existing overview when performing decimated read?
Loïc Dutrieux
Hi everyone,
I'm trying to perform a decimated read of a dataset that already contains overviews. Regardless of which value I pass to the resampling= argument of the read method, it seems that the already existing overview is used. Is there any way to ignore it? See the reproducible example below. Cheers, Loïc --- import tempfile import os import numpy as np import rasterio from rasterio.enums import Resampling filename = os.path.join(tempfile.gettempdir(), 'overview_test.tif') # Create random int array shape = (100, 100) arr = np.random.randint(0, 9999, size=shape, dtype=np.uint16) meta = {'height': 100, 'width': 100, 'driver': 'GTiff', 'dtype': np.uint16, 'count': 1} # Write random array to file and compute first overview with rasterio.open(filename, 'w', **meta) as dst: dst.write(arr, 1) dst.build_overviews([2], Resampling.nearest) # Read with downsample with rasterio.open(filename) as src: arr_avg = src.read(1, out_shape=(1,50,50), resampling=Resampling.average, out_dtype=np.float) arr_nrt = src.read(1, out_shape=(1,50,50), resampling=Resampling.nearest) print(np.max(arr_avg - arr_nrt)) # when the source file does not contain overviews, the max of the difference array # is > 0
|
|
Re: Does rasterio.warp.reproject use overviews?
Sean Gillies
Loïc, 1. Correct. To use overviews, you must pass a dataset explicitly opened on an overview using `rasterio.open("example.tif", OVERVIEW_LEVEL=1)`. 2. Correct again. We'll add an option to use an automatically determined source file overview, as gdalwarp does.
On Thu, Nov 5, 2020 at 10:29 AM Loïc Dutrieux <loic.dutrieux@...> wrote:
-- Sean Gillies
|
|
Re: Does rasterio.warp.reproject use overviews?
Loïc Dutrieux
Hi Sean,
Thank you for your response. Is it correct to interpret from your explanation that: 1- currently the reproject function will never use overviews of the source file, even when it involves downsampling. 2- In a future version `reproject()` will eventually use source file overviews. (and the user will be able to control that behavior via an argument (e.g. overviewLevel= as in gdal python API)?)
To provide some context about why I want to know that, I'm warping 10 m sentinel2 data to a 20 m grid and I want to make sure it does *not* use the source file overviews. Overviews are fine for visualization but often not suitable for analysis (unless they have been generated with the right resampling algorithm).
Thanks again, Cheers, Loïc
From: main@rasterio.groups.io <main@rasterio.groups.io> on behalf of Sean Gillies <sean.gillies@...>
Sent: 05 November 2020 16:27:12 To: main@rasterio.groups.io Subject: Re: [rasterio] Does rasterio.warp.reproject use overviews? Hi Loïc,
On Tue, Nov 3, 2020 at 8:55 AM Loïc Dutrieux <loic.dutrieux@...> wrote:
gdalwarp's logic is found in apps/gdalwarp_lib.cpp, not in gcore, so rasterio.warp.reproject() does not have it. We've got a rasterio ticket about switching over to use the main function in apps/gdalwarp_lib.cpp so that the behavior of rasterio.warp.reproject()
is exactly the same as gdalwarp, but haven't started work on it yet.
Sean Gillies
|
|
Re: Does rasterio.warp.reproject use overviews?
Sean Gillies
Hi Loïc, On Tue, Nov 3, 2020 at 8:55 AM Loïc Dutrieux <loic.dutrieux@...> wrote:
gdalwarp's logic is found in apps/gdalwarp_lib.cpp, not in gcore, so rasterio.warp.reproject() does not have it. We've got a rasterio ticket about switching over to use the main function in apps/gdalwarp_lib.cpp so that the behavior of rasterio.warp.reproject() is exactly the same as gdalwarp, but haven't started work on it yet. Sean Gillies
|
|
Does rasterio.warp.reproject use overviews?
Loïc Dutrieux
Hi everyone,
I read that the gdalwarp command line defaults to using the overview level nearest to target resolution. What about `rasterio.warp.reproject()`? Does it use overview at all?
Thank you and kind regards, Loïc
|
|
Re: HDF4 not recognized as a supported file format
leonidas_liakos@...
Thank you!
pip3 install rasterio --force-reinstall --no-binary rasterio did the job.
|
|
Re: HDF4 not recognized as a supported file format
Sean Gillies
Hi, On Mon, Nov 2, 2020 at 9:16 AM leonidas_liakos via groups.io <leonidas_liakos=yahoo.gr@groups.io> wrote: I have install rasterio with pip3 install rasterio --no-binary rasterio In https://github.com/mapbox/rasterio/issues/2026 you reported that you'd previously installed a wheel from PyPI. In that case, I think you need to add an option when reinstalling: pip3 install rasterio --force-reinstall --no-binary rasterio Sean Gillies
|
|
HDF4 not recognized as a supported file format
leonidas_liakos@...
I have install rasterio with pip3 install rasterio --no-binary rasterio
When I'm trying to read an HDF4 MODIS file I get an error: Matplotlib created a temporary config/cache directory at /tmp/matplotlib-m5kstvas because the default path (/home/kokkytos/.config/matplotlib) is not a writable directory; it is highly recommended to set the MPLCONFIGDIR environment variable to a writable directory, in particular to speed up the import of Matplotlib and to better support multiprocessing. During handling of the above exception, another exception occurred: Traceback (most recent call last):
|
|
rio-mbtiles 1.5.0
Sean Gillies
Hi all, Version 1.5.0 of rio-mbtiles is on PyPI now: https://pypi.org/project/rio-mbtiles/1.5.0/. Special thanks to James McBride for the reviews and feedback. Sean Gillies
|
|
Re: Silencing NotGeoreferencedWarning
Sean Gillies
Hi Nikos, On Thu, Oct 29, 2020 at 4:29 PM Nikos Alexandris <nik@...> wrote: Thank you for this. It's been bugging for quite some time. (data) vas-y:~ seang$ python -W "ignore:Dataset has no geotransform set" -c "import rasterio; rasterio.open('/Users/seang/Desktop/DSC_1549.jpg')" (data) vas-y:~ seang$ python -c "import rasterio; rasterio.open('/Users/seang/Desktop/DSC_1549.jpg')" /Users/seang/envs/data/lib/python3.6/site-packages/rasterio/__init__.py:218: NotGeoreferencedWarning: Dataset has no geotransform set. The identity matrix may be returned. s = DatasetReader(path, driver=driver, sharing=sharing, **kwargs) We're going to support RPCs in 1.2.0, so you'll see less of this warning, but in the meanwhile I can't suggest anything other than explicitly silencing warnings when you open a file using a context manager or changing Python's filter before you run a program like this: $ python -W "ignore:Dataset has no geotransform set" -c "import rasterio; rasterio.open('/Users/seang/Desktop/DSC_1549.jpg')" No warnings! Without -W you will get them. $ python -c "import rasterio; rasterio.open('/Users/seang/Desktop/DSC_1549.jpg')" /Users/seang/envs/data/lib/python3.6/site-packages/rasterio/__init__.py:218: NotGeoreferencedWarning: Dataset has no geotransform set. The identity matrix may be returned. s = DatasetReader(path, driver=driver, sharing=sharing, **kwargs) Sean Gillies
|
|
Re: Silencing NotGeoreferencedWarning
Thank you for this. It's been bugging for quite some time.
I use it here: https://gitlab.com/thermopolis/public/ecor/-/blob/master/ecor/utilities.py. I have the same question, as this snippet need to appear in every function that `rasterio.open()`s a HDF5 (sub)dataset: is there a more elegant way to silence this warning? Cheers
|
|
rio-mbtiles 1.5b3
Sean Gillies
Hi all, 1.5b3 is on PyPI now. It adds an option to constrain mbtiles output to only the tiles that cover a web mercator quadkey. See https://github.com/mapbox/rio-mbtiles/blob/master/CHANGES.txt#L4. This is probably the last change before 1.5.0. Sean Gillies
|
|
Re: Rasterio and GDAL_CACHEMAX
Angus Dickey
Sean, Awesome, thanks for the response. There are a couple of places in the docs where the example sets the cache in MBs: https://rasterio.readthedocs.io/en/latest/api/rasterio.env.html?highlight=GDAL_CACHEMAX https://rasterio.readthedocs.io/en/latest/topics/switch.html?highlight=GDAL_CACHEMAX Not a big deal, but might send people down the wrong path. Thanks again, Angus
|
|
Re: opening file with forced CRS
Alan Snow
This should be fixed in 1.1.5 IIRC: #1248
|
|
opening file with forced CRS
Hi all: as part of using rasterio for OGC API - Coverages work in pygeoapi, a client can pass
a Having said this, using example files in https://dd.weather.gc.ca/model_hrdps/continental/grib2/06/002, I'm unable to derive the native crs from rasterio in Python:
However, when running through
I need the crs value to be able to reproject the incoming lat/long bbox into native coordinates to subset accordingly. Is there a way to set a given dataset's CRS through code (in readonly mode)? Thanks ..Tom
|
|
Re: Rasterio and GDAL_CACHEMAX
Sean Gillies
Hi Angus, On Mon, Oct 26, 2020 at 6:04 PM Angus Dickey <angus@...> wrote:
Yes, GDAL_CACHEMAX passed to `Env()` must be in bytes (since https://github.com/mapbox/rasterio/pull/1042/files). Sean Gillies
|
|
Rasterio and GDAL_CACHEMAX
Angus Dickey
Does GDAL_CACHEMAX have to be set in bytes when using rasterio? I see in the docs there is an example using MBs but it seems to be causing rasterio to set a very small cache size when I use it. For example, accessing a COG in S3 using rasterio 1.1.8: # No problem here with rasterio.Env() as env: # Prints 851132006 (5% of my system RAM in bytes) print(get_gdal_config('GDAL_CACHEMAX')) with rasterio.open('s3://path/to/cog') as src: # Do stuff with the COG # No problem here either with rasterio.Env(GDAL_CACHEMAX=536870912) as env: # Prints 536870912 print(get_gdal_config('GDAL_CACHEMAX')) with rasterio.open('s3://path/to/cog') as src: # Do stuff with the COG # Really slow with rasterio.Env(GDAL_CACHEMAX=512) as env: # Prints 512 (in bytes?) print(get_gdal_config('GDAL_CACHEMAX')) with rasterio.open('s3://path/to/cog') as src: # Do stuff with the COG It seems like rasterio is setting the GDAL raster block cache to 512 bytes and this is causing the slow read. I don't really understand the internals of rasterio but it looks to be using GDALSetCacheMax() (which only accepts bytes) and is passing it 512. I might be misunderstanding the problem though, it could be something else slowing things down but that is the only change I am making. Any input is appreciated. Thanks, Angus
|
|
rasterio 1.1.8-1 wheels published to PyPI
Sean Gillies
Hi all, We found a bug in GDAL versions before 3.2.0 and have patched GDAL 2.4.4 and made new 1.1.8 binary wheels with a "-1" build tag. See https://pypi.org/project/rasterio/1.1.8/#files. If you want this fix and have already installed 1.1.8 wheels, run the following command. pip install -I --force-reinstall rasterio==1.1.8 Big thanks to Drew Bollinger for reporting the problem in https://github.com/mapbox/rasterio/issues/2022 and to Even Rouault for the quick fix. Sean Gillies
|
|
Re: Best way to sample all data in a raster
Alan Snow
I believe that this is what you are looking for: https://rasterio.readthedocs.io/en/latest/topics/resampling.html
|
|