-
Notifications
You must be signed in to change notification settings - Fork 366
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
Minimizing incompatibility between cartopy and shapely #805
Comments
👍 to upstreaming things. |
I really only use Fedora packages (which are almost always in sync), and only point to conda because it's the only one I know of that works on Macs. I'm all for moving things into shapely if that's the better location for things. |
Howdy, for the past month or so I've been working on a high level-plotting package which extends Fast forward a month later, and There are a few other complications, but this issue is the core of it. So I'm obviously interested in helping to resolve it. I could use some direction from you folks in doing so, since I have significantly more time than experience. To begin with, right now I'm trying to get the |
@ResidentMario I don't usually rebuild my environment, but when I do, I basically follow the steps from |
I think it's time to discuss this more--it's now impossible to build cartopy on travis (linux) against the 1.5.17 manylinux wheels that have been uploaded. In fact, I have to work harder to get pip to ignore those wheels. GIven that shapely is a full-fledged wrapper around GEOS, I think the sane solution is to add any APIs that cartopy needs to Shapely and eliminate cartopy's direct dependence on GEOS. Can someone on the CartoPy side weigh in on whether such a move would be supported? I'm willing to put in the work needed, but can only afford to do so if the effort won't go wasted. |
I don't see a patch doing what you've just described being rejected, given the concurring opinions of a |
Thanks @dopplershift - I'm in favour of doing what we can to improve ease of use and compatibility, and it is great you are keen to help. I think a good starting point would be to record here what the main changes will be for cartopy (i.e. what moves from cartopy to shapely, what needs to change in cartopy to accomodate this) and what (if any) will be the differences from an end-user perspective. |
Has there been any progress on this? Edit: There's a licensing incompatibility, see shapely #451 (again). |
License incompatibility. Of course there is. |
I've used the GPL before and have nothing against it, but it does mean that Shapely cannot lift the code from Cartopy. We'd need the copyright holder, British Crown Copyright 2011 - 2016, Met Office, to donate a new version of trace.pyx with a permissive license. |
I only hold the (L)GPL against people who assert that it doesn't create any problems--ones like this for instance. |
That's not really something that's unique to (L)GPL, so let's not get off topic here. At least we have one advantage with the CLA here; there's only one "person" to ask about re-licensing. But I think first we need to figure out what part. |
From a quick scan, all of the Met Office projects seem to be GPL or LGPL. So I think this is just their policy on things. They can do that because of UK crown copyright, AFAIK all GitHub code published by e.g. the NOAA in the US is unlicensed by default because federal law compels most work released by federal agencies to be public domain. @QuLogic It seems we just want them to release |
i'll pick this up and get it looked into in principal, I see no problems, I expect it is just some administration, but I will report back @sgillies @ResidentMario is thank you |
hello @sgillies I have looked into this and there are no issues with relicensing trace.pyx and moving it to shapely Regarding Licensing |
Is Cartopy not covered by the CLA I signed? |
Never mind, I forgot that was an LGPL-only grant. I agree with this re-licensing for Shapely. |
I've overlooked that _trace.pyx uses both GEOS and PROJ.4 APIs. I think a refactor would be needed before the GEOS calling code could be moved to Shapely, and I don't want to insist on such a refactor for Cartopy. Vendorizing Shapely may be the best option after all, yes? |
Hi @sgillies, Sorry for the radio silence on this 📻 . I've been somewhat pre-occupied with fluffy animals down-under recently 🐨 🙃 (I have been seconded in Australia for 6 months). I'm now back the right way up, and I'm keen to solve this issue once and for all. trace.pyx is a combination of GEOS and PROJ.4 - its responsibility is to produce interpolated geometries in their target projection. A good deal of the code was written some time ago, and although has held up well, is in some need of love. As I recall, the reason we ended up using GEOS directly was that there were a number of bottlenecks in Shapely's geometry creation (even in Cython) that we were able to significantly optimise by making prior assumptions about the incoming coordinate sequences. I'd like to split the conversation at this point into two threads: what we do in the short term; and what cartopy does in the long term. What we do in the short-term?The fact that Shapely's wheels bundle GEOS, and that cartopy depends on both shapely and GEOS means that cartopy MUST either:
Unfortunately we are in this situation because bundling third party dependencies in a binary format designed to contain a single package, such as is done with binary wheels, takes away a means for us to express dependencies fully. This is not a criticism of Shapely having done so - it is the only solution that is currently available to us for distributing binary packages through pip, and is the reason I continue to advocate the use of conda or a user's system package manager (the pip interface is excellent, and there are downsides to conda too, it is just that PythonPackaging doesn't deal with the concept of non-python packages well IMO). Anyway, this is not intended to be a rant (and I definitely don't want to criticise what I actually believe is the best tool for the job when it comes to pure python packages) - we are where we are, and I'm keen to find a sustainable solution. At this point, though it is my least favourite option, I believe vendoring shapely is the less brittle of the two options. The one question I have is whether the use of two potentially different versions of GEOS (the one from cartopy.shapely and the one from shapely) is likely to see shared symbol issues for GEOS functions? (shapely isn't statically linked in the wheels, right?) What cartopy does in the long-term?In the long term I can see a few feasible options:
At this point, [naturally] I prefer the idea of moving the optimisations out of cartopy and into Shapely. Not entirely unrelatedly, I'm expecting to be putting a significant effort into the trace code in the next 6-12 months in order to solidify cartopy for a major release. I think doing this will inform us some more about the direction of travel for cartopy in the long-term. This is somewhat longer than my normal comments, hope you're still with me! Would love to get your feedback/thoughts. Cheers, |
Isn't vendoring shapely simply going to shift the problem onto cartopy users who are using shapely manually? Wouldn't this: import cartopy
import shapely still only load one copy of the geos library, which will break one of those two? |
Thanks for putting my question more succinctly @dopplershift. That is the key question we need to be able to answer, otherwise at least one (but probably both cartopy and shapely) will need to vendor GEOS as well (and have to do unpleasant things with its namespace). Nobody wants to be doing that though, so we should get a concrete grip/PoC on answering that question. |
@marqh already opened shapely/shapely#479 which should be the long-term solution; he just didn't finish cleaning it up. Is that not enough? |
Oops, that PR was not supposed to close this issue; it was only a cross-reference. |
As a followup to #1251, I have a branch that converts to Shapely instead of GEOS directly, but as I recall, it was quite a bit slower. Perhaps using pygeos might work better. |
@QuLogic, have you tried your cartopy branch with the shapely 2.0 branch? I believe that incorporates a lot of the pygeos routines into shapely and could speed things up without having to switch to pygeos directly. |
I don't think that's the problem; it's more that we have to swap from Cython to Python to C, and flipping the GIL so much is quite slow. Checking current commit, doing this doubles the projection time. |
@QuLogic do you have a link to your branch? I am happy to take a look in case I can spot a potential performance improvement with the vectorized operations of pygeos/shapely 2.0 |
I've rebased the branch and pushed it here: https://github.com/QuLogic/cartopy/tree/shapely I think we could use the vectorized creation routines in pygeos (are those in shapely 2?) here: https://github.com/QuLogic/cartopy/blob/shapely/lib/cartopy/trace.pyx#L123 You can see the effect on projection here: https://qulogic.github.io/cartopy-bench/#project_linear.Suite.time_project_linear (in the sixth- to second-last commits) |
Yes, so if you have an array of coordinates, you can create linestrings from it with
(the coordinates can also be supplied as to separate 1D arrays instead of a single 2D array)
Those will be, but are not yet in the shapely-2.0 branch in the Shapely repo. So if you want to experiment with it, you will need to import them from pygeos at the moment. Now, the above is only for the geometry creation in |
Just pinging this issue again as we are getting a lot of new reports about incompatibilities again with the Shapely 1.8.1 release, which changed the packaging of Shapely. We can solve the installation problems with the old workaround of ignoring the binary shapely wheel: |
After the release of shapely 1.8.2, I encountered a tricky issue outlined here. |
amazing the problem hasn't been fixed!!! |
…y#805). Assume user has set up separately if using `deepsensor`'s `cartopy` plotting functionality.
Do we have any intelligence yet on whether using Docker containers for environment management improves this issue? |
We have just released v0.22 which should help with the compatibility between packages and installation much easier. Please open a new issue if you are still having problems. |
Cartopy has a module that both imports Shapely and adds new GEOS bindings: https://github.com/SciTools/cartopy/blob/master/lib/cartopy/trace.pyx. I think this is an unsound approach that can lead innocent cartopy users into DLL Hell.
I'd like to propose two better approaches.
Move all of cartopy's GEOS dependency into Shapely
The extension code in trace.pyx is rather small and could be moved to Shapely and deleted from cartopy. The DLL Hellmouth would be closed and cartopy users could benefit from binary Shapely wheels. There's still time to do this before Shapely 1.6.0.
Vendorize Shapely
Cartopy could copy the Shapely source and add build steps for it into setup.py, removing it from the list of dependencies that would be resolved by pip or setuptools. The internal copy of Shapely would be built using the same
geos_c
as cartopy'strace
module and the DLL Hellmouth would thus be closed.@QuLogic @pelson I see in other tickets here that conda is what you're focusing on. Neither of my proposed approaches are need for conda, though moving the extension code into Shapely will have the benefit of removing calls into Shapely's private internal API and thus making cartopy more forward compatible with Shapely. I think that's probably the better approach for making
pip install cartopy
work on OS X.The text was updated successfully, but these errors were encountered: