-
Notifications
You must be signed in to change notification settings - Fork 226
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
grdcontour Implementation #225
grdcontour Implementation #225
Conversation
gmt/base_plotting.py
Outdated
@@ -125,8 +125,51 @@ def coast(self, **kwargs): | |||
with Session() as lib: | |||
lib.call_module("coast", build_arg_string(kwargs)) | |||
|
|||
|
|||
@fmt_docstring |
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.
E303 too many blank lines (2)
gmt/tests/test_grdcontour.py
Outdated
from ..exceptions import GMTInvalidInput | ||
from ..datasets import load_earth_relief | ||
|
||
@pytest.mark.mpl_image_compare |
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.
E302 expected 2 blank lines, found 1
gmt/tests/test_grdcontour.py
Outdated
def test_grdcontour(): | ||
"""Plot a contour image using an xarray grid | ||
with fixed contour interval | ||
""" |
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.
W291 trailing whitespace
gmt/tests/test_grdcontour.py
Outdated
projection="W0/6i") | ||
return fig | ||
|
||
@pytest.mark.mpl_image_compare |
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.
E302 expected 2 blank lines, found 1
gmt/tests/test_grdcontour.py
Outdated
contour_interval="1000", | ||
annotation_interval="5000", | ||
projection="W0/6i", | ||
pen=["a1p,red","c0.5p,black"], |
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.
E231 missing whitespace after ','
gmt/base_plotting.py
Outdated
lib.call_module("grdcontour", arg_str) | ||
|
||
|
||
@fmt_docstring |
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.
E303 too many blank lines (2)
a84e5ab
to
3292ba1
Compare
@leouieda Build fails, due to test image mismatches, I suspect the density of features is playing a role, since 2 fail and 2 do not, and the ones that fail are denser contours. I will make a todo to refine the tests, but I suspect regenerating the images on the same machine (like what needed to be done for #212) will help. Not sure how to handle it |
@akshmakov I don't know why, but in #212 the image generated on a Mac fails the linux tests but the image I generated on my linux machine passes all tests. Let me know when you're done with the code and I'll regenerate the images on my machine. |
gmt/base_plotting.py
Outdated
A="annotation_interval", | ||
C="contour_interval", | ||
B="frame", | ||
G="label_placement", |
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.
Choosing these names is really hard. I would rename them to single words:
A="annotation"
C="interval"
(contour is already in the method name sofig.grdcontour(contour_interval=..)
seems a bit repetitive)G="label"
I'm not sure about limit
. This type of things is often called a range
in other parts of GMT and some Python functions. But range
is a builtin function so we should use ranges
instead. I'm not a huge fan of that. Maybe we can leave limit
for now until we can think of something better. This is one of those options that should actually be multiple options.
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.
Please, feel free to disagree :) I'm not set on these names and am willing to change
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.
You can tell my C bias as this was my attempt at less verbosity.
One thought I had is that -C
can be aliased as cmap
as per countour
since it accepts a CPT
file input as well, it just also accepts a number for contour intervals so is not compatible the other way. @mjziebarth maybe has some thoughts as well?
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.
@leouieda One thing that happens is that something like contour_interval
increases the verbosity when using the functions directly, but makes it clearer to construct keyword dictionaries. Application designers are more likely to use this pattern but it is still useful for managing plot options in scripts.
e.g.
OPTS={
projection:"W0/6i",
coast:1,
borders:1,
annotation_interval:1000,
contour_interval:100,
}
fig.coast(**OPTS)
fig.grdcontour(grd, **OPTS)
vs
OPTS={
projection:"W0/6i",
annotation:1000,
interval:100,
}
# ...
More verbose names are easier to work with, and additionally reusing the keywords for incompatible parameters can prevent user from using a single dictionary to store common keyword arguments, but on the other hand this is already true in some cases and is certainly true for many GMT single letter arguments...
In any case I will take your advice for the names, and instead put my thoughts in #219 because I think this is a bigger discussion than grdcontour
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.
From someone new to GMT: The more verbose names may make the difference between intuitively being able to write the code and having to consult the man pages.
But I agree with @akshmakov that this is probably best for general discussion e.g. in #219
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.
Yeah, I agree. All of this will have to be updated at some point. For now, we need some time to use these functions and see where they fall short. No point in trying to predict all possible use cases.
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.
@leouieda Updated with the following simplified keywords
A="annotation",
B="frame",
C="interval",
G="label_placement",
J="projection",
L="limit",
Q="cut",
R="region",
S="resample",
U="logo",
W="pen",
label_placement
left as is to be consistent with Figure.contour
gmt/helpers/decorators.py
Outdated
separators = {"sequence": "/", | ||
"sequence_comma": ",", | ||
"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.
E124 closing bracket does not match visual indentation
gmt/tests/test_grdcontour.py
Outdated
projection="W0/6i") | ||
return fig | ||
|
||
@pytest.mark.mpl_image_compare |
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.
E302 expected 2 blank lines, found 1
gmt/tests/test_grdcontour.py
Outdated
) | ||
return fig | ||
|
||
@pytest.mark.mpl_image_compare |
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.
E302 expected 2 blank lines, found 1
gmt/tests/test_grdcontour.py
Outdated
projection="M6i") | ||
return fig | ||
|
||
@pytest.mark.mpl_image_compare |
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.
E302 expected 2 blank lines, found 1
gmt/tests/test_grdcontour.py
Outdated
) | ||
return fig | ||
|
||
@pytest.mark.mpl_image_compare |
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.
E302 expected 2 blank lines, found 1
gmt/tests/test_grdcontour.py
Outdated
fig.grdcontour( | ||
**comargs, | ||
limit=(-25000,-1), | ||
pen=["a1p,blue","c0.5p,blue"], |
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.
E231 missing whitespace after ','
gmt/tests/test_grdcontour.py
Outdated
**comargs, | ||
limit=(-25000,-1), | ||
pen=["a1p,blue","c0.5p,blue"], | ||
) |
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.
E126 continuation line over-indented for hanging indent
gmt/tests/test_grdcontour.py
Outdated
pen=["a1p,blue","c0.5p,blue"], | ||
) | ||
fig.grdcontour( | ||
**comargs, |
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.
E126 continuation line over-indented for hanging indent
gmt/tests/test_grdcontour.py
Outdated
fig.grdcontour( | ||
**comargs, | ||
limit="0", | ||
pen=["a1p,black","c0.5p,black"], |
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.
E231 missing whitespace after ','
gmt/tests/test_grdcontour.py
Outdated
**comargs, | ||
limit="0", | ||
pen=["a1p,black","c0.5p,black"], | ||
) |
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.
E126 continuation line over-indented for hanging indent
Plots grids to contours, with its own set of distinct inputs from `pscontour` Test and Initial Documentation is complete
a21f2c3
to
1bc1686
Compare
gmt/helpers/decorators.py
Outdated
separators = {"sequence": "/", "sequence_comma": ","} | ||
separators = {"sequence": "/", | ||
"sequence_comma": ",", | ||
"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.
E231 missing whitespace after ','
gmt/tests/test_grdcontour.py
Outdated
""" Plot based on external contour level file """ | ||
fig = Figure() | ||
comargs = { | ||
'region': [-161.5,-154,18.5,23], |
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.
E231 missing whitespace after ','
gmt/tests/test_grdcontour.py
Outdated
|
||
fig.grdcontour( | ||
**comargs, | ||
limit=(-25000,-1), |
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.
E231 missing whitespace after ','
gmt/tests/test_grdcontour.py
Outdated
limit=(-25000,-1), | ||
pen=["a1p,blue", "c0.5p,blue"], | ||
) | ||
|
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.
W293 blank line contains whitespace
…ptions. Added additional kwarg list type that combines elements with + Added file contour definition for file based grdcontour test
1bc1686
to
2d56e57
Compare
@leouieda Finished expanded docs and keyword expansion. Removed WIP Status, ready to merge pending updated baseline plots Are you on the island right now? Stay safe! 🌧️ P.s. Might baseline issue be due to default fonts? I am generating on linux machines as well and they fail on travis due to baseline mismatch, but pass on my machine |
@akshmakov thanks again for the contribution! I re-generated the baselines and fixed some code formatting issues. Once CI gods are happy, I'll merge this in! |
Thanks @akshmakov! Please feel free to add yourself to the |
@leouieda will do on another commit, hopefully for another issue, thank you for the baseline images, I'm happy to contribute! Is there a style guide that I can review? Would P.S. I have some suspicion that baseline mismatches may be related to default system fonts. |
Part of the appeal of using black is that it should handle this automatically. Still, I should clarify this in the contributing guide. In short, if your variable/function names are descriptive and
Yep, that seems like a very likely culprit. That's one of the issues with testing images but I don't think we can get around it easily. Thanks for all your work on GMT and GMT/Python! |
Implemented
Figure.grdcontour
that usesgrdcontour
gmt modulePlots grids to contours, with its own set of distinct inputs from
pscontour
Test and Initial Documentation is complete
TODO