Skip to content

Commit

Permalink
Adds Lambert Conformal support (#303)
Browse files Browse the repository at this point in the history
* Adds Lambert Conformal support

* Adds standard parallel conversion from proj strings to earthkit Projections

* Makes standard parallel extraction more concise
  • Loading branch information
JamesVarndell authored Feb 20, 2024
1 parent 942829b commit 9cc58e5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
7 changes: 7 additions & 0 deletions earthkit/data/utils/projections/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ class LambertAzimuthalEqualArea(Projection):
CARTOPY_CRS = "LambertAzimuthalEqualArea"


class LambertConformal(Projection):
PROJ_NAME = "lcc"
CF_GRID_MAPPING_NAME = "lambert_conformal_conic"
CARTOPY_CRS = "LambertConformal"


class AlbersEqualArea(Projection):
PROJ_NAME = "aea"
CF_GRID_MAPPING_NAME = "albers_conical_equal_area"
Expand All @@ -131,6 +137,7 @@ class Mercator(Projection):
EquidistantCylindrical,
LongLat,
LambertAzimuthalEqualArea,
LambertConformal,
AlbersEqualArea,
Mercator,
]
8 changes: 8 additions & 0 deletions earthkit/data/utils/projections/proj.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"proj": "proj_name",
}

STANDARD_PARALLELS = ["lat_1", "lat_2"]

PROJ_PARAMS_TO_GLOBE_KWARGS = {
"a": "semimajor_axis",
"b": "semiminor_axis",
Expand Down Expand Up @@ -63,4 +65,10 @@ def to_projection_kwargs(proj_params):
}
kwargs["globe"] = globe_params

standard_parallels = tuple(
proj_params[param] for param in STANDARD_PARALLELS if param in proj_params
)
if standard_parallels:
kwargs["standard_parallels"] = standard_parallels

return kwargs
10 changes: 10 additions & 0 deletions tests/utils/test_projections.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ def test_from_proj_string_laea():
}


def test_from_proj_string_lcc():
proj_string = "+proj=lcc +lon_0=-90 +lat_1=33 +lat_2=45"
projection = projections.Projection.from_proj_string(proj_string)
assert isinstance(projection, projections.LambertConformal)
assert projection.parameters == {
"central_longitude": -90.0,
"standard_parallels": (33.0, 45.0),
}


def test_from_cf_grid_mapping_aea():
grid_mapping = {
"grid_mapping_name": "albers_conical_equal_area",
Expand Down

0 comments on commit 9cc58e5

Please sign in to comment.