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

FutureWarning:Use of pyproj.transform is deprecated since pyproj>2.6.1 #210

Open
philippkraft opened this issue Jan 10, 2023 · 2 comments
Open

Comments

@philippkraft
Copy link
Contributor

Hi,

thank you for the great package. When running pysheds 0.3.3 with pyproj 3.4.1 I get a warning:

pysheds/sview.py:971: FutureWarning: This function is deprecated. See: https://pyproj4.github.io/pyproj/stable/gotchas.html#upgrading-to-pyproj-2-from-pyproj-1

According to the documentation of pyproj.transform calling this function is deprecated since pyproj 2.6.1. To fix it one need to change pysheds/sview.py:971 and all other occurences to something like:

transformer = pyproj.Transformer.from_proj(target_view.crs, data_view.crs, always_xy=True)
xt, yt = transformer.transform(x=x, y=y, errcheck=True)

I have not tested it yet. This is also necessary for all other occurences of pyproj.transform:

pysheds/pysheds/io.py

Lines 117 to 119 in 9d96096

extent = pyproj.transform(window_crs, crs, (xmin, xmax),
(ymin, ymax), errcheck=True,
always_xy=True)

pysheds/pysheds/pgrid.py

Lines 292 to 294 in 3b977e8

extent = pyproj.transform(window_crs, crs, (xmin, xmax),
(ymin, ymax), errcheck=True,
always_xy=True)

pysheds/pysheds/sview.py

Lines 237 to 238 in 1951f63

xb_p, yb_p = pyproj.transform(old_crs, new_crs, xb, yb,
errcheck=True, always_xy=True)

And of course the original one:

pysheds/pysheds/sview.py

Lines 971 to 972 in 1951f63

xt, yt = pyproj.transform(target_view.crs, data_view.crs, x=x, y=y,
errcheck=True, always_xy=True)

I can submit a PR, if it helps.

Regards, Philipp

@philippkraft
Copy link
Contributor Author

@mdbartos I would suggest the following refactoring:

Move all duplicated pyproj helper code (_OLD_PYPROJ and _pyproj_init) in a seperated python module (projection.py). In that file, the default projection is defined as well as a function for transformation, which is called instead of pyproj.transform and has the same interface. For old pyproj (<2.6.1), the function just calls pyproj.transform (as now) for newer pyproj the function first creates an transformer object and calls it with the provided data.

@philippkraft
Copy link
Contributor Author

Another question: is support for pyproj<2.2 (relase 04/2019) still necessary?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant