pytroll / pyresample

Geospatial image resampling in Python
http://pyresample.readthedocs.org
GNU Lesser General Public License v3.0
344 stars 95 forks source link

Catch or fix pyproj UserWarning when loading an AreaDefinition from a netCDF/CF file #550

Open TomLav opened 10 months ago

TomLav commented 10 months ago

What's the problem:

pyresample's load_cf_area() forwards a UserWarning from pyproj: UserWarning: You will likely lose important projection information when converting to a PROJ string from another format.

Severity:

Low. It is annoying to get the warning, but we know where it comes from.

Where does it come from: The warning is triggered because we call pyproj's CRS.to_dict(): https://github.com/pytroll/pyresample/blob/c0025ed8905cb8d026de4b3a48451346b802b36c/pyresample/utils/cf.py#L66

We use CRS.to_dict() to test the type of the projection, not to do any math / transformation with it.

Solutions: Two solutions: 1) Keep using to_dict() but catch the UserWarning (as done elsewhere in pyresample); 2) Access the parameters in another, more CRS-friendly way, that will not trigger a warning.

djhoese commented 10 months ago

It looks like 2 main properties are looked at:

  1. Is this a geostationary projection?
  2. Get satellite height

For geostationary check, I added a helper method a while back to the AreaDefinition that covers this:

https://github.com/pytroll/pyresample/blob/c0025ed8905cb8d026de4b3a48451346b802b36c/pyresample/geometry.py#L1565-L1571

Extracting that as a utility function would make sense.

For geostationary height there is already a utility function for that:

https://github.com/pytroll/pyresample/blob/c0025ed8905cb8d026de4b3a48451346b802b36c/pyresample/utils/proj4.py#L94-L98