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

Add tutorial for pygmt.config #482

Merged
merged 13 commits into from
Oct 29, 2020

Conversation

hemmelig
Copy link
Contributor

@hemmelig hemmelig commented Jun 20, 2020

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

  • Run make format and make check to make sure the code follows the style guide.
  • Add new public functions/methods/classes to doc/api/index.rst.
  • Write detailed docstrings for all functions/methods.

hemmelig added 2 commits June 18, 2020 14:58
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
examples/tutorials/text.py Outdated Show resolved Hide resolved
examples/tutorials/text.py Outdated Show resolved Hide resolved
@hemmelig
Copy link
Contributor Author

hemmelig commented Jun 20, 2020

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?

@seisman
Copy link
Member

seisman commented Jun 20, 2020

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?

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.

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?

Currently not. I believe it's a very useful feature. Please open an issue for it.

@weiji14 weiji14 added the documentation Improvements or additions to documentation label Jun 21, 2020
Remove pygmt.Figure.text tutorial from this particular pull request, leaving
only the pygmt.config tutorial.
doc/index.rst Outdated Show resolved Hide resolved
examples/tutorials/gmt-config.py Outdated Show resolved Hide resolved
examples/tutorials/gmt-config.py Outdated Show resolved Hide resolved
examples/tutorials/gmt-config.py Outdated Show resolved Hide resolved
Comment on lines 38 to 39
pygmt.config(MAP_FRAME_TYPE="plain")
pygmt.config(FORMAT_GEO_MAP="ddd.xx")
Copy link
Member

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().

Copy link
Contributor Author

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!)

Copy link
Contributor Author

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)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, subplot and inset are not implemented in PyGMT yet, but see #412 and #427.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just opened up an issue for inset at #663, we can discuss over there. The subplot implementation at #427 is also ready for review 😄

Copy link
Contributor Author

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.

Comment on lines 51 to 52
# 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
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

@weiji14 weiji14 mentioned this pull request Sep 6, 2020
11 tasks
@seisman
Copy link
Member

seisman commented Sep 19, 2020

@hemmelig Do you still have time working on this PR? These are all good examples for pygmt.config() and should be merged into the documentation.

@seisman
Copy link
Member

seisman commented Oct 21, 2020

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.

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!).
@hemmelig
Copy link
Contributor Author

Pushed up changes required to address main comments.

examples/tutorials/configuration.py Outdated Show resolved Hide resolved
examples/tutorials/configuration.py Outdated Show resolved Hide resolved
examples/tutorials/configuration.py Outdated Show resolved Hide resolved
@weiji14 weiji14 mentioned this pull request Oct 24, 2020
14 tasks
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.
examples/tutorials/configuration.py Outdated Show resolved Hide resolved
examples/tutorials/configuration.py Outdated Show resolved Hide resolved
examples/tutorials/configuration.py Outdated Show resolved Hide resolved
examples/tutorials/configuration.py Outdated Show resolved Hide resolved
examples/tutorials/configuration.py Outdated Show resolved Hide resolved
examples/tutorials/configuration.py Outdated Show resolved Hide resolved
examples/tutorials/configuration.py Outdated Show resolved Hide resolved
examples/tutorials/configuration.py Outdated Show resolved Hide resolved
@seisman
Copy link
Member

seisman commented Oct 27, 2020

@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.

Copy link
Member

@weiji14 weiji14 left a 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.

examples/tutorials/configuration.py Outdated Show resolved Hide resolved
examples/tutorials/configuration.py Outdated Show resolved Hide resolved
examples/tutorials/configuration.py Outdated Show resolved Hide resolved
@seisman seisman added this to the 0.2.1 milestone Oct 27, 2020
@seisman
Copy link
Member

seisman commented Oct 29, 2020

/format

@seisman seisman changed the title Tutorial covering pygmt.config Add tutorial for pygmt.config Oct 29, 2020
@seisman seisman merged commit 2c14fbd into GenericMappingTools:master Oct 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add documents/tutorial explaining how pygmt.config() works
5 participants