Skip to content

Make PyGMT stateful #2388

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

Open
seisman opened this issue Mar 1, 2023 · 1 comment
Open

Make PyGMT stateful #2388

seisman opened this issue Mar 1, 2023 · 1 comment
Labels
question Further information is requested

Comments

@seisman
Copy link
Member

seisman commented Mar 1, 2023

I'm unsure if "stateful" is the appropriate word here. What I really mean is to let PyGMT keep track of its stats and some information, then later PyGMT calls can know what already happened.

I think the "stats" can be useful in many cases. Here are some quick ideas. Let's say we have a dict pygmt.__stats__ for PyGMT and a dict fig.__stats__ for each Figure instance, which can store anything we want. The variable names have double underscores so they are for internal use only, but it's also possible to make them public to users.

  1. pygmt.__stats__.call_history can be a list of commands that are passed to the GMT API via call_module. The list can be used to generate the equivalent bash script, although we can't handle virtual files and any other Python data structures.
  2. fig.__stats__.projection: the projection of the current figure
  3. fig.__stats__.region: the region parameter of the current figure (c.f. https://www.pygmt.org/dev/api/generated/pygmt.clib.Session.extract_region.html)
  4. fig.__stats__.dimensions: width and height of the current figure/frame/subplot/inset. Users can access these values via public functions, and then can do some mathematic calculates (e.g., to have an inset map with a width of 0.25 * w or shift the plot origin by 1.2 * w (w is the width of current figure stored in fig.__stats__.dimensions)).

I believe there are more interesting ideas about a stateful PyGMT, so thoughts and comments are welcomed.

@seisman seisman added the question Further information is requested label Mar 1, 2023
@willschlitzer
Copy link
Contributor

I think this is a good idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants