pyresample icon indicating copy to clipboard operation
pyresample copied to clipboard

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

Open TomLav opened this issue 10 months ago • 1 comments

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.

TomLav avatar Oct 16 '23 07:10 TomLav

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

djhoese avatar Oct 16 '23 13:10 djhoese