pyresample
pyresample copied to clipboard
Catch or fix pyproj UserWarning when loading an AreaDefinition from a netCDF/CF file
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:
- Keep using to_dict() but catch the UserWarning (as done elsewhere in pyresample);
- Access the parameters in another, more CRS-friendly way, that will not trigger a warning.
It looks like 2 main properties are looked at:
- Is this a geostationary projection?
- 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