-
Notifications
You must be signed in to change notification settings - Fork 224
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
Add tutorial for pygmt.config #482
Add tutorial for pygmt.config #482
Conversation
Add tutorial detailing how to add text annotations to PyGMT figures. Follows the style of the other tutorials available, showing how to use the currently available arguments in the binding to the underlying GMT program 'text'. Fixes GenericMappingTools#469
Add tutorial detailing how the pygmt.config class can be used to override GMT default parameters, both permanently (globally) or temporarily (locally). Follows the style of the other tutorials available. Fixes GenericMappingTools#458
I realise I must have branched off my text_tutorial branch rather than going back to master first - apologies! Should I remove the text tutorial and resubmit? Also, one thing I was wondering is whether it's possible to return to the original set of defaults after they have been overwritten globally without restarting the kernel? |
You can directly remove the two text-tutorial files and remove the text.rst entry from doc/index.rst, and then commit directly to this branch. No need to resubmit a new PR.
Currently not. I believe it's a very useful feature. Please open an issue for it. |
Remove pygmt.Figure.text tutorial from this particular pull request, leaving only the pygmt.config tutorial.
examples/tutorials/gmt-config.py
Outdated
pygmt.config(MAP_FRAME_TYPE="plain") | ||
pygmt.config(FORMAT_GEO_MAP="ddd.xx") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In GMT 6.1.0, each session can have a global gmt.conf file, and each figure can also have its own gmt.conf (see https://docs.generic-mapping-tools.org/6.1/cookbook/features.html#gmt-modern-mode-hierarchical-levels).
Now these two lines no longer works as we expected. They actually change the defaults of the figure above. To change the defaults of the current figure, we need to move these two lines after fig=pygmt.Figure()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So hierarchically one must do something like:
# Set global (session) configuration
fig = pygmt.Figure() # This will change the current 'level' from session to figure
# Set figure configuration
etc
That makes sense, I'll fix this up (and finish the two PRs I've opened!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would one trigger the further levels mentioned in the GMT 6.1.0 documentation (subplot
, panel
, inset
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just read it! I'll have a look at it, thanks.
examples/tutorials/gmt-config.py
Outdated
# It is also possible to temporarily override the default parameters, which is a very | ||
# useful for limiting the scope of changes to a particular plot. :class:`pygmt.config` is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As explained above, no need to use the with
statement to limit the scope of changes to a single figure, but it's still useful if we want to limit the changes to one or a few calls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still like the syntax of using a context manager. For me, it's far more intuitive/easy to see the scope of the changes being made than tracking the level based on Figure
calls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it works the same as the figure level configurations, just needs one more indentation. I'm OK with the example, but the main idea of the context manager is to mimic the command line parameter gmt basemap --PARAMETER=value
, which only affect one single command. So perhaps we can keep this example, and add one more example.
@hemmelig Do you still have time working on this PR? These are all good examples for |
Ping @hemmelig again to see if he still wants to work on this PR. I will try to finalize and merge it if there is no response in 7 days. |
Co-authored-by: Dongdong Tian <[email protected]>
Update the config tutorial to: - Move the pygmt.config calls to after an instance of Figure has been created. - Demonstrate the use of pygmt.config as a context manager in two instances: firstly, to override the defaults for a single command (akin to the --PARAMETER=<val> method in GMT); secondly, to override the defaults for a sequence of commands.
Rename the pygmt.config tutorial from gmt-config to configuration (as, presumably, the GMT bit is implied!).
Pushed up changes required to address main comments. |
Correct the list of frame types available and slightly adjust the final example to show the difference made when using pygmt.config as a context manager to override the default settings for a single command.
Co-authored-by: Dongdong Tian <[email protected]>
@weiji14 I think this PR is good to merge (except the conflict and the pending CI). Please give it a final review if you have time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@weiji14 I think this PR is good to merge (except the conflict and the pending CI). Please give it a final review if you have time.
Looks good, just some very minor suggestions. The merge conflict will be fun to resolve, does @hemmelig want to give it a go at https://github.com/GenericMappingTools/pygmt/pull/482/conflicts? If not, I can handle it 😄
Once this is completed, I think we can expand on the pygmt.config
tutorial a bit more in a separate PR, maybe have separate sections for changing FONT_, COLOR_, MAP_, etc as listed in https://docs.generic-mapping-tools.org/latest/gmt.conf.html.
Co-authored-by: Wei Ji <[email protected]>
/format |
Description of proposed changes
Initial pull request for a tutorial going over the basics of pygmt.config and it's use as a context manager.
Fixes #458
Preview: https://pygmt-git-configtutorial.gmt.vercel.app/tutorials/configuration.html
Reminders
make format
andmake check
to make sure the code follows the style guide.doc/api/index.rst
.