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

Support datetime types in region argument #561

Closed
weiji14 opened this issue Aug 13, 2020 · 4 comments · Fixed by #562
Closed

Support datetime types in region argument #561

weiji14 opened this issue Aug 13, 2020 · 4 comments · Fixed by #562
Labels
enhancement Improving an existing feature

Comments

@weiji14
Copy link
Member

weiji14 commented Aug 13, 2020

Description of the desired feature

Support passing in 'datetime' like inputs into the 'region' or '-R' argument in plot.

  • The region argument doesn't work with numpy datetime64 objects, have to convert to a string using np.datetime_as_string in order to set the map frame bounds.

The decorator kwargs_to_strings convert the list [w, e, s, n] to a string w/e/s/n. We need to convert datetime64 object to string internally, but it's not ideal to do the conversion in the decorator. I don't have a good solution now.

Originally posted by @seisman in #464 (comment)

Minimal working example:

import pandas as pd
import pygmt

fig = pygmt.Figure()
fig.plot(x=["2020-06-30"], y=[1], region=[pd.Timestamp("2020-01-01"), pd.Timestamp("2020-12-31"), 0, 2])
fig.show()

The error message is:

GMTCLibError: Module 'plot' failed with status code 71:
plot [ERROR]: Option -R parsing failure. Correct syntax:
plot [ERROR]: Offending option -R2020-01-01

This workaround does work, but it's cumbersome:

fig = pygmt.Figure()
fig.plot(
    x=[pd.Timestamp("2020-06-30")],
    y=[1],
    region=[
        pd.Timestamp("2020-01-01").isoformat(),
        pd.Timestamp("2020-12-31").isoformat(),
        0,
        2,
    ],
    style="a10c",
    frame=True,
)
fig.show()

produces:

Expected plot with star in middle

Are you willing to help implement and maintain this feature? Yes, but where should this code logic go?

@weiji14 weiji14 added the enhancement Improving an existing feature label Aug 13, 2020
@seisman
Copy link
Member

seisman commented Aug 13, 2020

Add a check in the kwargs_to_strings decorator?

def kwargs_to_strings(convert_bools=True, **conversions):

@weiji14
Copy link
Member Author

weiji14 commented Aug 13, 2020

I'm wondering if this functionality is specific to plot only, or if there are other places which can take datetime-like 'region' arguments.

@seisman
Copy link
Member

seisman commented Aug 14, 2020

Almost any modules can accept datetime-like region, for example, basemap, histogram, and even grdimage (maybe, but never tried).

@weiji14
Copy link
Member Author

weiji14 commented Aug 14, 2020

Ok, the extra 'datetime' check might slow things down by a bit, but since it's only checking for 4 (or 6) items in a list, it should be fine.

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.

2 participants