Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Update pyproj functions to take string. #1589

Merged
merged 2 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading