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

Resetting default GMT parameters - pygmt.config #486

Open
hemmelig opened this issue Jun 22, 2020 · 3 comments
Open

Resetting default GMT parameters - pygmt.config #486

hemmelig opened this issue Jun 22, 2020 · 3 comments
Labels
feature request New feature wanted help wanted Helping hands are appreciated longterm Long standing issues that need to be resolved upstream Bug or missing feature of upstream core GMT

Comments

@hemmelig
Copy link
Contributor

Description of the desired feature

The pygmt.config class/context manager allows the user to permanently or temporarily override default GMT config parameters. If a parameter is set permanently (particularly in a notebook), it would be useful to be able to reset back to the default without having to reset the kernel / use pygmt.config as a context manager. Motivated by #482 (comment)

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

I've been able to override and reset everything myself by terminating and restarting the global session:

from pygmt import session_management

session_management.end()
session_management.begin()

but this is obviously not ideal, and I fear this may have unintended consequences of which I'm ignorant. I see this feature more as something to facilitate figure development in a notebook, but not so much for finalised figure scripts/notebooks, so it's perhaps not a huge issue?

Ideal usage would be something like:

pygmt.config().reset()

I'm still familiarising myself with the inner workings, so I apologise if I've missed/misunderstood something important.

@seisman seisman added feature request New feature wanted help wanted Helping hands are appreciated labels Jun 22, 2020
@weiji14
Copy link
Member

weiji14 commented Jun 23, 2020

GMT has a gmtdefaults function that may help with this. However, it might not respect the user's gmt.conf properly (correct me if I'm wrong)? Was actually mentioned in #293 (review) when we wrote the test case, but we just reverted it like so

# Revert to default settings
config(FONT_ANNOT_PRIMARY="black")

Alternatively, there might be a way to 'store' a global list of all the configurations a user has made and reuse some part of the __exit__ code:

pygmt/pygmt/modules.py

Lines 180 to 186 in 0fc2e94

def __exit__(self, exc_type, exc_value, traceback):
# revert to initial values
arg_str = " ".join(
["{}={}".format(key, value) for key, value in self.old_defaults.items()]
)
with Session() as lib:
lib.call_module("set", arg_str)

@seisman
Copy link
Member

seisman commented Jul 22, 2020

I think things is a little different after we bump to GMT>6.1.

In GMT 6.1, the GMT settings also have a hierarchical level. Each session, figure and subplot all can have its own configurations.

See https://docs.generic-mapping-tools.org/6.1/cookbook/features.html#gmt-modern-mode-hierarchical-levels.

@weiji14 weiji14 added this to the 0.4.0 milestone Nov 22, 2020
@weiji14 weiji14 modified the milestones: 0.4.0, 0.5.0 Jun 2, 2021
@weiji14 weiji14 modified the milestones: 0.5.0, 0.6.0 Sep 30, 2021
@weiji14 weiji14 modified the milestones: 0.6.0, 0.7.0 Mar 1, 2022
@seisman seisman modified the milestones: 0.7.0, 0.8.0 Jun 19, 2022
@weiji14 weiji14 added the longterm Long standing issues that need to be resolved label Nov 29, 2022
@seisman
Copy link
Member

seisman commented Dec 4, 2022

GMT has a gmtdefaults function that may help with this. However, it might not respect the user's gmt.conf properly (correct me if I'm wrong)?

I think you're right. gmtdefaults can only list: (1) the current defaults; (2) the system defaults (either in SI or US units).

Alternatively, there might be a way to 'store' a global list of all the configurations a user has made and reuse some part of the __exit__ code:

Yes, it's possible to have a _global_defaults property which can store the session-level defaults.

So, perhaps we can have pygmt.config().reset(type="user") in which type can be:

  • user: can be reset by using the _global_defaults property.
  • system_us and system_si: can be reset by using the gmtdefaults module.

Or we can ask an upstream feature request to allow gmtdefaults report the session-level defaults?

@seisman seisman modified the milestones: 0.8.0, 0.9.0 Dec 11, 2022
@seisman seisman modified the milestones: 0.9.0, 0.10.0 Mar 16, 2023
@weiji14 weiji14 removed this from the 0.10.0 milestone Aug 24, 2023
@weiji14 weiji14 added the upstream Bug or missing feature of upstream core GMT label Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature wanted help wanted Helping hands are appreciated longterm Long standing issues that need to be resolved upstream Bug or missing feature of upstream core GMT
Projects
None yet
Development

No branches or pull requests

3 participants