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

Figure.show: Allow keyword arguments passed to Figure.psconvert #2078

Merged
merged 4 commits into from
Aug 29, 2022

Conversation

seisman
Copy link
Member

@seisman seisman commented Aug 23, 2022

Description of proposed changes

Add **kwargs to Figure.show so that it can pass any keyword arguments to Figure.psconvert.

Figure.savefig() already have **kwargs.

Fixes #2038

Reminders

  • Run make format and make check to make sure the code follows the style guide.
  • Add tests for new features or tests that would have caught the bug that you're fixing.
  • Add new public functions/methods/classes to doc/api/index.rst.
  • Write detailed docstrings for all functions/methods.
  • If wrapping a new module, open a 'Wrap new GMT module' issue and submit reasonably-sized PRs.
  • If adding new functionality, add an example to docstrings or tutorials.

Slash Commands

You can write slash commands (/command) in the first line of a comment to perform
specific operations. Supported slash commands are:

  • /format: automatically format and lint the code
  • /test-gmt-dev: run full tests on the latest GMT development version

@seisman seisman added the enhancement Improving an existing feature label Aug 23, 2022
@seisman seisman added this to the 0.8.0 milestone Aug 23, 2022
pygmt/figure.py Outdated
Comment on lines 292 to 294
**kwargs : dict
Additional keyword arguments passed to
:meth:`pygmt.Figure.psconvert`.
Copy link
Member Author

Choose a reason for hiding this comment

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

Unsure if we should use kwargs or **kwargs here.

Copy link
Member

Choose a reason for hiding this comment

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

I had a look at some projects and there seems to be a mix 😅. Let's go with **kwargs following https://docs.xarray.dev/en/v2022.06.0/generated/xarray.open_dataset.html, unless anyone else has a good reason on why not.

@seisman seisman added the needs review This PR has higher priority and needs review. label Aug 25, 2022
pygmt/figure.py Outdated
Comment on lines 289 to 294
dpi : int
Set raster resolution in dpi. Default is 720 for PDF, 300 for
others.
**kwargs : dict
Additional keyword arguments passed to
:meth:`pygmt.Figure.psconvert`.
Copy link
Member

@weiji14 weiji14 Aug 25, 2022

Choose a reason for hiding this comment

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

I find it a bit confusing that dpi (an option in psconvert) was previously an extra option or kwarg, but now there's both dpi and **kwargs in the Figure.savefig(...) method shown in the documentation:
image.

Not sure what's the best solution here. Removing the dpi parameter documentation doesn't seem ideal, nor does including all of psconvert's parameters in savefig. Would it make sense then to put the dpi documentation under **kwargs? Or is there a cleaner solution?

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree. Actually some of psconvert's parameters (e.g., prefix, fmt) can NOT be used in Figure.show or Figure.savefig.

Perhaps we should say:

**kwargs: dict
    Additional keyword arguments passed to `pygmt.Figure.pscovert`. 
    Valid parameters are `gs_path`, `gs_option`, `resize`, `bb_style`, and `verbose`.

Copy link
Member

Choose a reason for hiding this comment

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

Yes! Also need to do a similar thing for the fig.show docstring.

@seisman seisman removed the needs review This PR has higher priority and needs review. label Aug 27, 2022
@seisman seisman added the needs review This PR has higher priority and needs review. label Aug 28, 2022
@weiji14 weiji14 added final review call This PR requires final review and approval from a second reviewer and removed needs review This PR has higher priority and needs review. labels Aug 28, 2022
@seisman seisman merged commit edf500e into main Aug 29, 2022
@seisman seisman deleted the show-kwargs branch August 29, 2022 11:28
@seisman seisman removed the final review call This PR requires final review and approval from a second reviewer label Aug 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improving an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add "-G" flag passthrough to psconvert for finding the correct gs version
3 participants