Skip to content

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

Closed

Description

@weiji14

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

Activity

  1. added
    enhancement
    on Aug 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions