Skip to content

Commit

Permalink
♻️ Improve lonlat_to_xy code and documentation
Browse files Browse the repository at this point in the history
Bumping pyproj from 2.6.0 to 3.0.0 allows us to get rid of the __array__ workaround added in be98dde/#40. Also took the opportunity to improve the documentation of the function's input parameters and output results.
  • Loading branch information
weiji14 committed Sep 22, 2020
1 parent 71e4bf9 commit 2f3abed
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions deepicedrain/spatiotemporal.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,30 @@ def lonlat_to_xy(
"""
Reprojects longitude/latitude EPSG:4326 coordinates to x/y coordinates.
Default conversion is to Antarctic Stereographic Projection EPSG:3031.
See also https://pyproj4.github.io/pyproj/latest/api/proj.html#pyproj-proj
Parameters
----------
longitude : xr.DataArray or dask.dataframe.core.Series
Input longitude coordinate(s).
latitude : xr.DataArray or dask.dataframe.core.Series
Input latitude coordinate(s).
epsg : int
EPSG integer code for the desired output coordinate system. Default is
3031 for Antarctic Polar Stereographic Projection.
Returns
-------
x : xr.DataArray or dask.dataframe.core.Series
The transformed x coordinate(s).
y : xr.DataArray or dask.dataframe.core.Series
The transformed y coordinate(s).
"""
if hasattr(longitude, "__array__") and callable(longitude.__array__):
# TODO upgrade to PyProj 3.0 to remove this workaround for passing in
# dask.dataframe.core.Series or xarray.DataArray objects
# Based on https://github.com/pyproj4/pyproj/pull/625
_longitude = longitude.__array__()
_latitude = latitude.__array__()

x, y = pyproj.Proj(projparams=epsg)(_longitude, _latitude)
x, y = pyproj.Proj(projparams=epsg)(longitude, latitude)

if hasattr(longitude, "coords"):
return (
Expand Down

0 comments on commit 2f3abed

Please sign in to comment.