Skip to content

Make PyGMT stateful #2388

Open
Open
@seisman

Description

@seisman

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions