mdbartos / pysheds

:earth_americas: Simple and fast watershed delineation in python.
GNU General Public License v3.0
702 stars 188 forks source link

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

Open philippkraft opened 1 year ago

philippkraft commented 1 year ago

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:

https://github.com/mdbartos/pysheds/blob/9d960962bfe742c534da6577c3353169e6b6a501/pysheds/io.py#L117-L119

https://github.com/mdbartos/pysheds/blob/3b977e87f6c728c6b6b564c224aab3d448816967/pysheds/pgrid.py#L292-L294

https://github.com/mdbartos/pysheds/blob/1951f63f0a8971971ff98d2ea9d8b1d6a34cb266/pysheds/sview.py#L237-L238

And of course the original one:

https://github.com/mdbartos/pysheds/blob/1951f63f0a8971971ff98d2ea9d8b1d6a34cb266/pysheds/sview.py#L971-L972

I can submit a PR, if it helps.

Regards, Philipp

philippkraft commented 1 year ago

@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 commented 1 year ago

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