Skip to content

Commit

Permalink
BUG: Fix CRS.to_cf for Pole rotation GRIB convention (#1167)
Browse files Browse the repository at this point in the history
  • Loading branch information
snowman2 authored Oct 28, 2022
1 parent b5166bc commit 2a62e36
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Latest
3.4.1
-----
- BUG: Changed so that the setup.cfg depends on the version code in the __init__.py instead of the other way around (issuue #1155)
- BUG: Fix :meth:`.CRS.to_cf` for Pole rotation GRIB convention (pull #1167)
- REF: Use upper case EPSG code when creating CRS (pull #1162)

3.4.0
Expand Down
14 changes: 12 additions & 2 deletions pyproj/crs/crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ def to_cf(
CF-1.8 version of the projection.
"""
# pylint: disable=too-many-branches
# pylint: disable=too-many-branches,too-many-return-statements
cf_dict: Dict[str, Any] = {"crs_wkt": self.to_wkt(wkt_version)}

# handle bound CRS
Expand Down Expand Up @@ -696,6 +696,16 @@ def to_cf(

if self.is_geographic:
if self.coordinate_operation:
if (
self.coordinate_operation.method_name.lower()
not in _INVERSE_GEOGRAPHIC_GRID_MAPPING_NAME_MAP
):
if errcheck:
warnings.warn(
"Unsupported coordinate operation: "
f"{self.coordinate_operation.method_name}"
)
return {"crs_wkt": cf_dict["crs_wkt"]}
cf_dict.update(
_INVERSE_GEOGRAPHIC_GRID_MAPPING_NAME_MAP[
self.coordinate_operation.method_name.lower()
Expand Down Expand Up @@ -729,7 +739,7 @@ def to_cf(
else:
warnings.warn("Coordinate operation not found.")

return {"crs_wkt": self.to_wkt(wkt_version)}
return {"crs_wkt": cf_dict["crs_wkt"]}

cf_dict.update(
_INVERSE_GRID_MAPPING_NAME_MAP[coordinate_operation_name](
Expand Down
37 changes: 37 additions & 0 deletions test/crs/test_crs_cf.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,43 @@ def test_rotated_pole_to_cf():
_test_roundtrip(expected_cf, "GEOGCRS[")


def test_grib_rotated_pole_to_cf():
rotated_pole_wkt = """GEOGCRS["Coordinate System imported from GRIB file",
BASEGEOGCRS["Coordinate System imported from GRIB file",
DATUM["unnamed",
ELLIPSOID["Sphere",6371229,0,
LENGTHUNIT["metre",1,
ID["EPSG",9001]]]],
PRIMEM["Greenwich",0,
ANGLEUNIT["degree",0.0174532925199433,
ID["EPSG",9122]]]],
DERIVINGCONVERSION["Pole rotation (GRIB convention)",
METHOD["Pole rotation (GRIB convention)"],
PARAMETER["Latitude of the southern pole (GRIB convention)",-33.443381,
ANGLEUNIT["degree",0.0174532925199433,
ID["EPSG",9122]]],
PARAMETER["Longitude of the southern pole (GRIB convention)",-93.536426,
ANGLEUNIT["degree",0.0174532925199433,
ID["EPSG",9122]]],
PARAMETER["Axis rotation (GRIB convention)",0,
ANGLEUNIT["degree",0.0174532925199433,
ID["EPSG",9122]]]],
CS[ellipsoidal,2],
AXIS["latitude",north,
ORDER[1],
ANGLEUNIT["degree",0.0174532925199433,
ID["EPSG",9122]]],
AXIS["longitude",east,
ORDER[2],
ANGLEUNIT["degree",0.0174532925199433,
ID["EPSG",9122]]]]"""
crs = CRS(rotated_pole_wkt)
with pytest.warns(UserWarning):
cf_dict = crs.to_cf(errcheck=True)
assert cf_dict.pop("crs_wkt").startswith("GEOGCRS[")
assert not cf_dict


def test_cf_lambert_conformal_conic_1sp():
crs = CRS.from_cf(
dict(
Expand Down

0 comments on commit 2a62e36

Please sign in to comment.