Topics

Silencing NotGeoreferencedWarning


Guillaume Lostis
 

Hi,

I'm frequently working with GeoTIFF datasets that don't have a geotransform because they are georeferenced through other means (Sentinel-1 SLC images through the satellite state vectors, or non-orthorectified optical imagery through RPCs). Whenever I open such a dataset with rasterio, I get a warning:

NotGeoreferencedWarning: Dataset has no geotransform set. The identity matrix may be returned.

This warning is not useful to me as it is raised on every file I open, so I was looking for a way to silence it systematically. I've found that by doing:

import warnings
import rasterio
warnings.filterwarnings("ignore", category=rasterio.errors.NotGeoreferencedWarning)

it silences most warnings, but sometimes some of them get through the filter in for loops for example, or in the context of pytest. And it also has the disadvantage of having to show up everywhere in my code.

Is there a more radical way to always silence this warning?

Thanks!

Guillaume Lostis


vincent.sarago@...
 

Hi Guillaume,
thanks for raising this, it happens to me often too.

I'm thinking about multiple solutions:
- check if the file has other georeferenced information (like rpc or gpc) internally before raising this warning. 
- instead of raising a warning maybe a logging.info would be sufficent ? 

I also encounter this when saving file like png or jpg that don't have georeference which appears to me unnecessary. 


Guillaume Lostis
 

Hi Vincent,

Option 1 with RPCs and GCPs would be perfect for my use case because all of the datasets I open have one of them.
But it would still leave warnings when you write a png or jpg with no georeference as you pointed out.

I have to admit I didn't know rasterio had logs... What's the rationale behind deciding what goes to logs, and what goes to stderr/warnings?

On Thu, 23 Jan 2020 at 15:40, <vincent.sarago@...> wrote:
Hi Guillaume,
thanks for raising this, it happens to me often too.

I'm thinking about multiple solutions:
- check if the file has other georeferenced information (like rpc or gpc) internally before raising this warning. 
- instead of raising a warning maybe a logging.info would be sufficent ? 

I also encounter this when saving file like png or jpg that don't have georeference which appears to me unnecessary. 


Sean Gillies
 

Hi Guillaume,

Rasterio logs, mostly at DEBUG level, so that you can run programs and see what the state was before a failure. You don't see them unless you turn the warning level down to DEBUG. A program can't easily react to log messages, they go out to the environment and are inspected (or discarded) after the program terminates.

Rasterio warns in a few places instead of using logging because at these places a user may want their program to react to the warning and use different logic, retry, add missing georeferencing, fix the alpha band shadowing, or whatever. An exception would be too strong in the georeferencing case, I think. But we can, with a couple lines of code, turn any NotGeoreferencedWarning into an exception that can be handled appropriately.

Certainly rasterio is lagging in the RPC/GCP realm and we should think about not warning after we add the missing capabilities to the package.


On Thu, Jan 23, 2020 at 7:49 AM Guillaume Lostis <g.lostis@...> wrote:
Hi Vincent,

Option 1 with RPCs and GCPs would be perfect for my use case because all of the datasets I open have one of them.
But it would still leave warnings when you write a png or jpg with no georeference as you pointed out.

I have to admit I didn't know rasterio had logs... What's the rationale behind deciding what goes to logs, and what goes to stderr/warnings?

On Thu, 23 Jan 2020 at 15:40, <vincent.sarago@...> wrote:
Hi Guillaume,
thanks for raising this, it happens to me often too.

I'm thinking about multiple solutions:
- check if the file has other georeferenced information (like rpc or gpc) internally before raising this warning. 
- instead of raising a warning maybe a logging.info would be sufficent ? 

I also encounter this when saving file like png or jpg that don't have georeference which appears to me unnecessary. 

--
Sean Gillies


Guillaume Lostis
 

Hi Sean,

Thanks for your answer.
I understand why you would want to keep this as a warning so that a user can act upon it if needed.

If I understand correctly, rasterio currently lacks the ability to georeference an image properly through its RPC/GCP, so you will keep the warning as is for now?
I'd be happy to contribute what I can, at my level, to help move forward on these topics.
On RPCs, @underchemist has a WIP open here: https://github.com/mapbox/rasterio/pull/1845
On GCPs, Vincent contributed a method to estimate a transform matrix here: https://github.com/mapbox/rasterio/pull/1749

On Thu, 23 Jan 2020 at 18:10, Sean Gillies via Groups.Io <sean=mapbox.com@groups.io> wrote:
Hi Guillaume,

Rasterio logs, mostly at DEBUG level, so that you can run programs and see what the state was before a failure. You don't see them unless you turn the warning level down to DEBUG. A program can't easily react to log messages, they go out to the environment and are inspected (or discarded) after the program terminates.

Rasterio warns in a few places instead of using logging because at these places a user may want their program to react to the warning and use different logic, retry, add missing georeferencing, fix the alpha band shadowing, or whatever. An exception would be too strong in the georeferencing case, I think. But we can, with a couple lines of code, turn any NotGeoreferencedWarning into an exception that can be handled appropriately.

Certainly rasterio is lagging in the RPC/GCP realm and we should think about not warning after we add the missing capabilities to the package.

On Thu, Jan 23, 2020 at 7:49 AM Guillaume Lostis <g.lostis@...> wrote:
Hi Vincent,

Option 1 with RPCs and GCPs would be perfect for my use case because all of the datasets I open have one of them.
But it would still leave warnings when you write a png or jpg with no georeference as you pointed out.

I have to admit I didn't know rasterio had logs... What's the rationale behind deciding what goes to logs, and what goes to stderr/warnings?

On Thu, 23 Jan 2020 at 15:40, <vincent.sarago@...> wrote:
Hi Guillaume,
thanks for raising this, it happens to me often too.

I'm thinking about multiple solutions:
- check if the file has other georeferenced information (like rpc or gpc) internally before raising this warning. 
- instead of raising a warning maybe a logging.info would be sufficent ? 

I also encounter this when saving file like png or jpg that don't have georeference which appears to me unnecessary. 

--
Sean Gillies


Yann-Sebastien Tremblay-Johnston
 

Just chiming in to say I've gotten busy and haven't had a chance to polish https://github.com/mapbox/rasterio/pull/1845 off yet


On Thu, Jan 23, 2020 at 9:56 AM Guillaume Lostis <g.lostis@...> wrote:
Hi Sean,

Thanks for your answer.
I understand why you would want to keep this as a warning so that a user can act upon it if needed.

If I understand correctly, rasterio currently lacks the ability to georeference an image properly through its RPC/GCP, so you will keep the warning as is for now?
I'd be happy to contribute what I can, at my level, to help move forward on these topics.
On RPCs, @underchemist has a WIP open here: https://github.com/mapbox/rasterio/pull/1845
On GCPs, Vincent contributed a method to estimate a transform matrix here: https://github.com/mapbox/rasterio/pull/1749

On Thu, 23 Jan 2020 at 18:10, Sean Gillies via Groups.Io <sean=mapbox.com@groups.io> wrote:
Hi Guillaume,

Rasterio logs, mostly at DEBUG level, so that you can run programs and see what the state was before a failure. You don't see them unless you turn the warning level down to DEBUG. A program can't easily react to log messages, they go out to the environment and are inspected (or discarded) after the program terminates.

Rasterio warns in a few places instead of using logging because at these places a user may want their program to react to the warning and use different logic, retry, add missing georeferencing, fix the alpha band shadowing, or whatever. An exception would be too strong in the georeferencing case, I think. But we can, with a couple lines of code, turn any NotGeoreferencedWarning into an exception that can be handled appropriately.

Certainly rasterio is lagging in the RPC/GCP realm and we should think about not warning after we add the missing capabilities to the package.

On Thu, Jan 23, 2020 at 7:49 AM Guillaume Lostis <g.lostis@...> wrote:
Hi Vincent,

Option 1 with RPCs and GCPs would be perfect for my use case because all of the datasets I open have one of them.
But it would still leave warnings when you write a png or jpg with no georeference as you pointed out.

I have to admit I didn't know rasterio had logs... What's the rationale behind deciding what goes to logs, and what goes to stderr/warnings?

On Thu, 23 Jan 2020 at 15:40, <vincent.sarago@...> wrote:
Hi Guillaume,
thanks for raising this, it happens to me often too.

I'm thinking about multiple solutions:
- check if the file has other georeferenced information (like rpc or gpc) internally before raising this warning. 
- instead of raising a warning maybe a logging.info would be sufficent ? 

I also encounter this when saving file like png or jpg that don't have georeference which appears to me unnecessary. 

--
Sean Gillies


 

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


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.
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

(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