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

Let pygmt.info support pandas.DataFrame or 2D numpy.array inputs #564

Closed
weiji14 opened this issue Aug 16, 2020 · 0 comments · Fixed by #574
Closed

Let pygmt.info support pandas.DataFrame or 2D numpy.array inputs #564

weiji14 opened this issue Aug 16, 2020 · 0 comments · Fixed by #574
Labels
enhancement Improving an existing feature

Comments

@weiji14
Copy link
Member

weiji14 commented Aug 16, 2020

Description of the desired feature

The pygmt.info function should accept pandas.DataFrame or 2D numpy.array matrices as input. This was mentioned in passing when pygmt.info was originally implemented at #106 (comment). Currently it can only handle filename (str) types:

pygmt/pygmt/modules.py

Lines 89 to 90 in bedb48d

if not isinstance(fname, str):
raise GMTInvalidInput("'info' only accepts file names.")

What I'm particularly interested in is getting a nicely rounded xmin/xmax/ymin/ymax 'region' by simply passing in a pandas.DataFrame (Option 3 in the related issue at #147). Something like this:

import pandas as pd

df: pd.DataFrame = pygmt.datasets.load_ocean_ridge_points()
region = pygmt.info(df, spacing="0.1")  # pygmt.info("@ridge.txt", I="0.1")
print(region)
# would output '-R-180/180/-65.7/86.8\n', or better, a proper python list

Yes, it's possible to do region = [df.x.min(), df.x.max(), df.y.min(), df.y.max()], but gmtinfo -I does rounding (and I believe it rounds outside of the tight region?), and it has other smart functionality too.

It shouldn't be too hard to make pygmt.info support non-filename types, just need to use lib.virtualfile_from_vectors or the like.

Note that the return values of pygmt.info should be discussed at #147. This issue only tackles the input format type. Perhaps we should handle #147 before this tackling this issue.

Are you willing to help implement and maintain this feature? Yes

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

Successfully merging a pull request may close this issue.

1 participant