Skip to content

Commit

Permalink
FIX: Update pyproj functions to take string. (#1589)
Browse files Browse the repository at this point in the history
* FIX: Update pyproj functions to take string.

* STY: Update to use isinstance.
  • Loading branch information
zssherman authored May 28, 2024
1 parent f789a7f commit 99d65d9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
29 changes: 18 additions & 11 deletions pyart/core/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,26 +170,33 @@ def __setstate__(self, state):
def projection_proj(self):
# Proj instance as specified by the projection attribute.
# Raises a ValueError if the pyart_aeqd projection is specified.
projparams = self.get_projparams()
if projparams["proj"] == "pyart_aeqd":
raise ValueError(
"Proj instance can not be made for the pyart_aeqd projection"
)
if not _PYPROJ_AVAILABLE:
raise MissingOptionalDependency(
"PyProj is required to create a Proj instance but it "
+ "is not installed"
)
projparams = self.get_projparams()

# Check if projparams is dictionary and check for pyart_aeqd
if isinstance(projparams, dict):
if projparams["proj"] == "pyart_aeqd":
raise ValueError(
"Proj instance can not be made for the pyart_aeqd projection"
)
# Get proj instance from a proj str or dict
proj = pyproj.Proj(projparams)
return proj

def get_projparams(self):
"""Return a projparam dict from the projection attribute."""
projparams = self.projection.copy()
if projparams.pop("_include_lon_0_lat_0", False):
projparams["lon_0"] = self.origin_longitude["data"][0]
projparams["lat_0"] = self.origin_latitude["data"][0]
return projparams
"""Return a projparam dict or str from the projection attribute."""
if isinstance(self.projection, dict):
projparams = self.projection.copy()
if projparams.pop("_include_lon_0_lat_0", False):
projparams["lon_0"] = self.origin_longitude["data"][0]
projparams["lat_0"] = self.origin_latitude["data"][0]
return projparams
else:
return self.projection

def _find_and_check_nradar(self):
"""
Expand Down
7 changes: 7 additions & 0 deletions tests/core/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,13 @@ def test_projection_proj():
assert isinstance(grid.projection_proj, pyproj.Proj)


@pytest.mark.skipif(not _PYPROJ_AVAILABLE, reason="PyProj is not installed.")
def test_projection_proj_str():
grid = pyart.testing.make_target_grid()
grid.projection = "+proj=aeqd"
assert isinstance(grid.projection_proj, pyproj.Proj)


def test_projection_proj_raised():
grid = pyart.testing.make_target_grid()

Expand Down

0 comments on commit 99d65d9

Please sign in to comment.