pytroll / pyresample

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

Suppress PROJ4 warning about losing projection by using `to_cf()` instead of `to_dict()` #572

Closed pnuu closed 9 months ago

pnuu commented 9 months ago

This PR removes a warning when getting actual projection details that are needed for CF by using to_cf() instead of to_dict(). This is part of Satpy reader cleanup started in https://github.com/pytroll/satpy/pull/2689

codecov[bot] commented 9 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (e82bf47) 94.06% compared to head (c9b9787) 94.23%. Report is 82 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #572 +/- ## ========================================== + Coverage 94.06% 94.23% +0.16% ========================================== Files 85 87 +2 Lines 13250 13484 +234 ========================================== + Hits 12463 12706 +243 + Misses 787 778 -9 ``` | [Flag](https://app.codecov.io/gh/pytroll/pyresample/pull/572/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pytroll) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/pytroll/pyresample/pull/572/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pytroll) | `94.23% <100.00%> (+0.16%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pytroll#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

mraspaud commented 9 months ago

How about using pyproj's crs.to_cf() as a first guess instead of catching the warning? Here's an example output:

In [27]: crs.to_cf()
Out[27]: 
{'crs_wkt': 'PROJCRS["unknown",BASEGEOGCRS["unknown",DATUM["Unknown based on WGS 84 ellipsoid",ELLIPSOID["WGS 84",6378137,298.257223563,LENGTHUNIT["metre",1],ID["EPSG",7030]]],PRIMEM["Greenwich",0,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8901]]],CONVERSION["unknown",METHOD["Polar Stereographic (variant B)",ID["EPSG",9829]],PARAMETER["Latitude of standard parallel",60,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8832]],PARAMETER["Longitude of origin",0,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8833]],PARAMETER["False easting",0,LENGTHUNIT["metre",1],ID["EPSG",8806]],PARAMETER["False northing",0,LENGTHUNIT["metre",1],ID["EPSG",8807]]],CS[Cartesian,2],AXIS["(E)",south,MERIDIAN[90,ANGLEUNIT["degree",0.0174532925199433,ID["EPSG",9122]]],ORDER[1],LENGTHUNIT["metre",1,ID["EPSG",9001]]],AXIS["(N)",south,MERIDIAN[180,ANGLEUNIT["degree",0.0174532925199433,ID["EPSG",9122]]],ORDER[2],LENGTHUNIT["metre",1,ID["EPSG",9001]]]]',
 'semi_major_axis': 6378137.0,
 'semi_minor_axis': 6356752.314245179,
 'inverse_flattening': 298.257223563,
 'reference_ellipsoid_name': 'WGS 84',
 'longitude_of_prime_meridian': 0.0,
 'prime_meridian_name': 'Greenwich',
 'geographic_crs_name': 'unknown',
 'horizontal_datum_name': 'Unknown based on WGS 84 ellipsoid',
 'projected_crs_name': 'unknown',
 'grid_mapping_name': 'polar_stereographic',
 'standard_parallel': 60.0,
 'straight_vertical_longitude_from_pole': 0.0,
 'false_easting': 0.0,
 'false_northing': 0.0}
pnuu commented 9 months ago

Oh, that's much better! I tried looking at the methods if any of them provided the needed information. I'll adjust in a bit.

djhoese commented 9 months ago

There is a utility context manager function in some utils module that does this. I use it in geometry.py and other places. I think i left this bit of the CF code because I was hoping we could use the CRS object directly.

coveralls commented 9 months ago

Coverage Status

coverage: 93.819%. remained the same when pulling c9b97877229d4b8d121b93186d35cd37150152b1 on pnuu:suppress-to-dict-warning into 522691dc2a39bae6e35a6ba3469920d6f90e592a on pytroll:main.