mdbartos / pysheds

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

Get rid of pyproj.FutureWarning #216

Closed philippkraft closed 1 year ago

philippkraft commented 1 year ago

210 is a about a future warning of pyproj. This pull request handles it for sgrid and sview - not pgrid / pview. All calls to pyproj in sgrid, sview and io are refactored into a new file projection.py which handles the different APIs of pyproj and exposes a consistent API to sgrid / sview / io, which resambles the 2.2 to 2.6 API of pyproj. This can be used for pgrid / pview, but I do not understand the functionality of pgrid and pview. test_grid.py passes.

distutiles.version.LooseVersion is also deprecated in Python 3.10 and is replaced in projection.py with packaging.Version.

mdbartos commented 1 year ago

Looks like tests are still failing.

See also https://github.com/mdbartos/pysheds/pull/214#issuecomment-1468888595

Thanks, MDB

philippkraft commented 1 year ago

Ok, the test was working on my system, I will investigate the problem here, but I will need some time.

philippkraft commented 1 year ago

Found the problem: test_grid.py runs now "really" on my system, and I solved the bug. Underlying issue: pyproj changed around Version 2 the semantics of the words "Projection" and "CRS". The code (my new one and your code) adds some confusion (at least I was completely confused). I would suppose to leave this as is for now, but as soon as you are fine to drop support for pyproj < 3, I can clean up the mess in projection.py.

mdbartos commented 1 year ago

I would be OK dropping support for pyproj < 3 if it is time. I would want to create a new version and release though if incorporating breaking changes.

With geospatial python I am always a bit hesitant, because I know that on certain systems I have had to revert to old versions of GDAL/Proj4/etc to get things working.

philippkraft commented 1 year ago

If you merge this PR we get rid of the annoying warning with the "new" pyproj, but still have full compatibility with even pyproj<2.1 (03/2019). If (whenever) you start a branch for a new version with dropping support on pyproj < 3 (from 11/2020), you can ping me and I will clean up the messy parts (compatibility layers) of projection.py.

mdbartos commented 1 year ago

Hi @philippkraft, let me know when this is ready to pull in. I'll create an issue reminding me to pull in a cleaned-up version at a later date when pyproj 2 can be deprecated with certainty. If possible, could you create another pull request on a different branch with the cleaned-up version?

philippkraft commented 1 year ago

I think it is ready to merge.

For the future version: If you create a fitting branch, I can create the PR against that branch. However cleaning this up will diverge pgrid and sgrid even more. I think I read in some issue, you are about to retire pgrid.py, perhaps the deprecation of pyproj2 would come together with retiring pgrid.py, if you plan it?

UPDATE: I still need to do some tests!

mdbartos commented 1 year ago

Hi @philippkraft, just checking if this is ready to pull in. You mentioned needing to do some tests in your last comment.

I've slated retiring pgrid as a to-do #221.

philippkraft commented 1 year ago

I checked it and I am working currently with the branch. You can pull it in. And I will subscribe to #221 and see when I can contribute the shortened version of projection.py