-
Notifications
You must be signed in to change notification settings - Fork 219
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
Conversation
pygmt/src/grdcontour.py
Outdated
``"annot_int+e+f10p+gred"`` or with a list of arguments | ||
``[annot_int, "e", "f10p", "gred"]``. |
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 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".
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 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.
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.
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")
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.
Lines 30 to 32 in 6fd4a00
@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
.
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 think we should disallow the syntax like annotation=[500, "f10p", "gred"]
, because:
- From a user's perspective, it's no different from passing a string like
500+f10p+gred
- The syntax is not well documented and is only used for this single parameter
- 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.
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 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"
.
So, valid arguments are for the
The corresponding Pythonic arguments are:
I think we should change |
Actually there is already PR #2706 which is about updating / improving |
It seems that |
I updated the title (a bit long now) and the description in the initial comment of this PR. |
Do we actually have to mention / warn that, due to removing |
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 |
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
/format |
Description of proposed changes
This PR aims to adjust the arguments passed to the
annotation
andinterval
parameters ofFigure.grdcontour
:- 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)sequence_plus
forannotation
instead use one string, e.g.,[100, "f10p", "gred"]
, now"100+f10p+gred"
Related:
annotation
: https://docs.generic-mapping-tools.org/dev/grdcontour.html#ainterval
: https://docs.generic-mapping-tools.org/dev/grdcontour.html#cFigure.contour
: Figure.contour: Adjust processing of arguments passed to the "annotation" and "levels" parameters #2706Preview: https://pygmt-dev--3116.org.readthedocs.build/en/3116/api/generated/pygmt.Figure.grdcontour.html
Reminders
make format
andmake check
to make sure the code follows the style guide.doc/api/index.rst
.Slash Commands
You can write slash commands (
/command
) in the first line of a comment to performspecific operations. Supported slash command is:
/format
: automatically format and lint the code