diff --git a/pyart/core/grid.py b/pyart/core/grid.py index 5821c73f7a..9026f5d35b 100644 --- a/pyart/core/grid.py +++ b/pyart/core/grid.py @@ -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): """ diff --git a/tests/core/test_grid.py b/tests/core/test_grid.py index 09e9c2be87..bdc2ba68ab 100644 --- a/tests/core/test_grid.py +++ b/tests/core/test_grid.py @@ -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()