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.grdcontour: Adjust processing of arguments passed to the "annotation" and "interval" parameters, deprecate "sequence_plus" #3116

Merged
merged 54 commits into from
Apr 27, 2024

Conversation

yvonnefroehlich
Copy link
Member

@yvonnefroehlich yvonnefroehlich commented Mar 17, 2024

Description of proposed changes

This PR aims to adjust the arguments passed to the annotation and interval parameters of Figure.grdcontour:

  • input options
    - a fixed interval als float 100 -> 100
    - one level as list: [100] -> 100, (mention the trailing comma)
    - multiple levels as list: [100, 200] -> 100,200
    - no as string: "n" -> n (syntax of GMT 6.5)
  • Deprecated sequence_plus for annotation instead use one string, e.g., [100, "f10p", "gred"], now "100+f10p+gred"
  • Update docstrings
  • Add tests for one level and multiple levels

Related:

Preview: https://pygmt-dev--3116.org.readthedocs.build/en/3116/api/generated/pygmt.Figure.grdcontour.html

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.
  • Use underscores (not hyphens) in names of Python files and directories.

Slash Commands

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

  • /format: automatically format and lint the code

Comment on lines 64 to 65
``"annot_int+e+f10p+gred"`` or with a list of arguments
``[annot_int, "e", "f10p", "gred"]``.
Copy link
Member Author

@yvonnefroehlich yvonnefroehlich Mar 17, 2024

Choose a reason for hiding this comment

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

I am wondering whether here the squared brackets are used to indicate that annot_int should be replaced with the desired value by the user. I find this a bit misleading.

The rounded brackets should be replaced by squared brackets as we write "list of arguments".

Copy link
Member

Choose a reason for hiding this comment

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

I don't think the description is correct. In the PyGMT world, a list of arguments means the option is repeatable. For example frame=["WSen", "xaf", "yaf"] is translated to -BWSen -Bxaf -Byaf. For this parameter, it must be annot_int+e+f10+gred, not a list.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm. I tried the following code to understand the input expected by annotation. It works for passing a list and I get the same output as for passing a string.

# orientated on https://www.pygmt.org/dev/api/generated/pygmt.Figure.grdcontour.html
# last access: 2024/03/18

import pygmt

region = [-92.5, -82.5, -3, 7]

grid = pygmt.datasets.load_earth_relief(resolution="15m", region=region)

fig = pygmt.Figure()
fig.grdcontour(
    projection="M10c",
    region=region,
    grid=grid,
    # annotation="500+f10p+gred",  # string -> WORKS
    # annotation=([500], "f10p", "gred"),  # -> FAILS
    # annotation=(500, "f10p", "gred"),  # -> WORKS
    annotation=[500, "f10p", "gred"],  # list -> WORKS
    frame=True,
)
fig.show()

# fig.savefig(fname="grdcontour_A_string.png")
# fig.savefig(fname="grdcontour_A_list.png")

Output figure
grdcontour_A_list

Copy link
Member

Choose a reason for hiding this comment

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

@kwargs_to_strings(
R="sequence", L="sequence", A="sequence_plus", c="sequence_comma", p="sequence"
)

I see. It's because A is defined like above, so the list of arguments is joined by +.

Actually, this is the only parameter that sets to sequence_plus.

Copy link
Member

Choose a reason for hiding this comment

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

I think we should disallow the syntax like annotation=[500, "f10p", "gred"], because:

  1. From a user's perspective, it's no different from passing a string like 500+f10p+gred
  2. The syntax is not well documented and is only used for this single parameter
  3. It's not Pythonic at all, and it's very likely that we won't support such syntax in the new alias system (POC: WIP: New alias system #2949 but still WIP)

So, I think we should remove A="sequence_plus" and update the documentation.

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 was actually also a bit wondering if we need this possibility, as such a list does not improve the readability significantly compared to the corresponding string. So, I think I am fine with removing A"sequence_plus".

@yvonnefroehlich yvonnefroehlich changed the title grdcontour: Fix typo in documentation grdcontour: Remove list input option fro "annotation" parameter Mar 19, 2024
@yvonnefroehlich yvonnefroehlich added the documentation Improvements or additions to documentation label Mar 19, 2024
@yvonnefroehlich yvonnefroehlich added this to the 0.12.0 milestone Mar 19, 2024
@yvonnefroehlich yvonnefroehlich added the maintenance Boring but important stuff for the core devs label Mar 19, 2024
@seisman seisman added deprecation Deprecating a feature and removed documentation Improvements or additions to documentation maintenance Boring but important stuff for the core devs labels Mar 19, 2024
pygmt/src/grdcontour.py Outdated Show resolved Hide resolved
@yvonnefroehlich yvonnefroehlich changed the title grdcontour: Remove list input option fro "annotation" parameter grdcontour: Remove list input option for "annotation" parameter Mar 19, 2024
@seisman
Copy link
Member

seisman commented Mar 19, 2024

contours is annotation interval in data units; it is ignored if contour levels are given in a file via -C. [Default is no annotations]. Prepend n to disable all annotations implied by -C. To just select a few specific contours give them as a comma-separated string; if only a single contour please add a trailing comma so it is seen as a list and not a contour interval.

So, valid arguments are for the -C option are:

  • 100 means every 100 contours
  • 100, means a single specific contour with value=100
  • 100,200,300 means multiple specific contours with value=100, 200 and 300
  • n means disable all contours

The corresponding Pythonic arguments are:

  • a float value: annotation=100
  • a list with a single value: annotation=[100]
  • a list with multiple values: annotation=[100, 200, 300]
  • a string: annotation="n"

I think we should change A="sequence_plus" to A="sequence" instead, to accept arguments like annotation=[100, 200, 300].

@yvonnefroehlich
Copy link
Member Author

Actually there is already PR #2706 which is about updating / improving annotation and the levels or interval parameters of Figure.contour and Figure.grdcontour. Probably it makes sense to bundle this change in one of these PRs and close the other one.

@seisman
Copy link
Member

seisman commented Mar 19, 2024

Actually there is already PR #2706 which is about updating / improving annotation and the levels or interval parameters of Figure.contour and Figure.grdcontour. Probably it makes sense to bundle this change in one of these PRs and close the other one.

It seems that grdcontour and contour have identical -A and -C options. I think we can focus on improving grdcontour in this PR and apply the same changes to contour in PR #2706.

@yvonnefroehlich yvonnefroehlich changed the title grdcontour: Remove list input option for "annotation" parameter Figure.grdcontour: Remove list input option for "annotation" parameter Mar 20, 2024
@yvonnefroehlich yvonnefroehlich changed the title Figure.grdcontour: Remove list input option for "annotation" parameter Figure.grdcontour: Update documentation of "annotation" and "interval" parameters Mar 20, 2024
@yvonnefroehlich yvonnefroehlich changed the title Figure.grdcontour: Update documentation of "annotation" and "interval" parameters Figure.grdcontour: Update docs of "annotation" and "interval" parameters Mar 20, 2024
@yvonnefroehlich yvonnefroehlich self-assigned this Mar 20, 2024
@seisman seisman marked this pull request as draft March 20, 2024 13:18
pygmt/src/grdcontour.py Show resolved Hide resolved
pygmt/src/grdcontour.py Outdated Show resolved Hide resolved
@yvonnefroehlich yvonnefroehlich marked this pull request as ready for review April 26, 2024 07:05
@yvonnefroehlich yvonnefroehlich changed the title Figure.grdcontour: Update docs of "annotation" and "interval" parameters Figure.grdcontour: Adjust processing agruments passed to "annotation" and "interval" parameters Apr 26, 2024
@seisman seisman mentioned this pull request Apr 26, 2024
9 tasks
@yvonnefroehlich yvonnefroehlich changed the title Figure.grdcontour: Adjust processing agruments passed to "annotation" and "interval" parameters Figure.grdcontour: Adjust processing agruments passed to "annotation" and "interval" parameters, deprecated "sequence_plus" Apr 26, 2024
@yvonnefroehlich yvonnefroehlich changed the title Figure.grdcontour: Adjust processing agruments passed to "annotation" and "interval" parameters, deprecated "sequence_plus" Figure.grdcontour: Adjust processing the agruments passed to the "annotation" and "interval" parameters, deprecated "sequence_plus" Apr 26, 2024
@yvonnefroehlich
Copy link
Member Author

Looks good. Please also update the PR title to reflect the changes.

I updated the title (a bit long now) and the description in the initial comment of this PR.

@yvonnefroehlich
Copy link
Member Author

Do we actually have to mention / warn that, due to removing sequence_plus for annotation arguments like [100, "f10p", "gred"] are no longer supported and "100+f10p+gred" should be used instead?

@seisman
Copy link
Member

seisman commented Apr 26, 2024

due to removing sequence_plus for annotation arguments like [100, "f10p", "gred"] are no longer supported and "100+f10p+gred" should be used instead?

The syntax is awkward. So maybe no one is actually using it. Or we may have to try hard to check if a list like [100, "f10p", "gred"] is passed.

@weiji14 weiji14 changed the title Figure.grdcontour: Adjust processing the agruments passed to the "annotation" and "interval" parameters, deprecated "sequence_plus" Figure.grdcontour: Adjust processing of arguments passed to the "annotation" and "interval" parameters, deprecated "sequence_plus" Apr 27, 2024
@weiji14 weiji14 changed the title Figure.grdcontour: Adjust processing of arguments passed to the "annotation" and "interval" parameters, deprecated "sequence_plus" Figure.grdcontour: Adjust processing of arguments passed to the "annotation" and "interval" parameters, deprecate "sequence_plus" Apr 27, 2024
@yvonnefroehlich
Copy link
Member Author

/format

pygmt/src/grdcontour.py Outdated Show resolved Hide resolved
pygmt/src/grdcontour.py Outdated Show resolved Hide resolved
@seisman seisman merged commit 0e630e3 into main Apr 27, 2024
19 of 20 checks passed
@seisman seisman deleted the fix-typos-63-grdcontour branch April 27, 2024 23:46
@seisman seisman removed the final review call This PR requires final review and approval from a second reviewer label Apr 27, 2024
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.

3 participants