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

pygmt.sphdistance: data should be an optional parameter if voronoi is used #1641

Open
maxrjones opened this issue Dec 4, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@maxrjones
Copy link
Member

Description of the problem

pygmt.sphdistance will give a GMTInvalidInput: No input data provided error if datais not used. However, the purpose of the voronoi parameter is to allow precomputed Voronoi polygons to be provided instead of raw data. So, the data parameter should be made optional if Voronoi is set.

Full code that generated the error

precompute using gmt's sphtriangulate:

gmt sphtriangulate @gshhs_c.txt -Qv -D > tt.pol
import pygmt
fig = pygmt.Figure()
grid = pygmt.sphdistance(voronoi="tt.pol", region="g", spacing=1, unit="k")

Full error message

     67     """
     68     if data is None and x is None and y is None:
---> 69         raise GMTInvalidInput("No input data provided.")
     70     if data is not None and (x is not None or y is not None or z is not None):
     71         raise GMTInvalidInput("Too much data. Use either data or x and y.")

GMTInvalidInput: No input data provided.

System information

Please paste the output of python -c "import pygmt; pygmt.show_versions()":

pygmt: v0.5.0
gmt: 6.3.0
@maxrjones maxrjones added the bug Something isn't working label Dec 4, 2021
@willschlitzer
Copy link
Contributor

This issue comes from data_kind in utils.py. I'm don't know how Voronoi polygons would be used in place of data, but would the easiest solution be to replace data with the string passed to voronoi? Otherwise, I would assume we would need to add a sphdistance-specific if statement and pass voronoi to build_arg_string.

@maxrjones
Copy link
Member Author

This issue comes from data_kind in utils.py. I'm don't know how Voronoi polygons would be used in place of data, but would the easiest solution be to replace data with the string passed to voronoi? Otherwise, I would assume we would need to add a sphdistance-specific if statement and pass voronoi to build_arg_string.

If tabular data is provided to sphdistance, the module will first compute the Voronoi polygons which are used to compute distances for each node in a grid. If you want to do this for multiple grids, it can get quite slow. One can skip the compute polygons step (the most time consuming step) by instead providing the polygons to -Q in GMT (voronoi in PyGMT). This is done by calling sphtriangulate before sphdistance to compute the polygons(e.g., example 2 versus example 3 in https://docs.generic-mapping-tools.org/dev/sphdistance.html#examples).

Since this feature is so closely tied to sphtriangulate, it might be worth drafting out the implementation of that module to make sure there are no unforeseen consequences of the bug fix for the voronoi parameter. I think your suggestion would work for passing file names, but eventually it would be nice to have sphtriangulate return an in-memory object which could be passed to sphdistance. I'm not sure whether it would work for that case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants