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

grdcontour Implementation #225

Merged

Conversation

akshmakov
Copy link
Contributor

@akshmakov akshmakov commented Aug 19, 2018

Implemented Figure.grdcontour that uses grdcontour gmt module

Plots grids to contours, with its own set of distinct inputs from pscontour

Test and Initial Documentation is complete

TODO

  • Expand Docstring for function.
  • Review chosen shorthand arguments for consistency with other modules
  • Refine tests
  • Regenerate baseline images.

@@ -125,8 +125,51 @@ def coast(self, **kwargs):
with Session() as lib:
lib.call_module("coast", build_arg_string(kwargs))


@fmt_docstring

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)

from ..exceptions import GMTInvalidInput
from ..datasets import load_earth_relief

@pytest.mark.mpl_image_compare

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

def test_grdcontour():
"""Plot a contour image using an xarray grid
with fixed contour interval
"""

Choose a reason for hiding this comment

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

W291 trailing whitespace

projection="W0/6i")
return fig

@pytest.mark.mpl_image_compare

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

contour_interval="1000",
annotation_interval="5000",
projection="W0/6i",
pen=["a1p,red","c0.5p,black"],

Choose a reason for hiding this comment

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

E231 missing whitespace after ','

lib.call_module("grdcontour", arg_str)


@fmt_docstring

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)

@akshmakov akshmakov force-pushed the pr/grdcontour-plotting-module branch from a84e5ab to 3292ba1 Compare August 19, 2018 06:50
@akshmakov
Copy link
Contributor Author

@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

@leouieda
Copy link
Member

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

A="annotation_interval",
C="contour_interval",
B="frame",
G="label_placement",
Copy link
Member

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 so fig.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.

Copy link
Member

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

Copy link
Contributor Author

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?

Copy link
Contributor Author

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

Copy link
Contributor

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

Copy link
Member

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.

Copy link
Contributor Author

@akshmakov akshmakov Aug 23, 2018

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

separators = {"sequence": "/",
"sequence_comma": ",",
"sequence_plus": "+",
}

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

projection="W0/6i")
return fig

@pytest.mark.mpl_image_compare

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

)
return fig

@pytest.mark.mpl_image_compare

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

projection="M6i")
return fig

@pytest.mark.mpl_image_compare

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

)
return fig

@pytest.mark.mpl_image_compare

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

fig.grdcontour(
**comargs,
limit=(-25000,-1),
pen=["a1p,blue","c0.5p,blue"],

Choose a reason for hiding this comment

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

E231 missing whitespace after ','

**comargs,
limit=(-25000,-1),
pen=["a1p,blue","c0.5p,blue"],
)

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

pen=["a1p,blue","c0.5p,blue"],
)
fig.grdcontour(
**comargs,

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

fig.grdcontour(
**comargs,
limit="0",
pen=["a1p,black","c0.5p,black"],

Choose a reason for hiding this comment

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

E231 missing whitespace after ','

**comargs,
limit="0",
pen=["a1p,black","c0.5p,black"],
)

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
@akshmakov akshmakov force-pushed the pr/grdcontour-plotting-module branch from a21f2c3 to 1bc1686 Compare August 23, 2018 07:04
separators = {"sequence": "/", "sequence_comma": ","}
separators = {"sequence": "/",
"sequence_comma": ",",
"sequence_plus": "+",}

Choose a reason for hiding this comment

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

E231 missing whitespace after ','

""" Plot based on external contour level file """
fig = Figure()
comargs = {
'region': [-161.5,-154,18.5,23],

Choose a reason for hiding this comment

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

E231 missing whitespace after ','


fig.grdcontour(
**comargs,
limit=(-25000,-1),

Choose a reason for hiding this comment

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

E231 missing whitespace after ','

limit=(-25000,-1),
pen=["a1p,blue", "c0.5p,blue"],
)

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
@akshmakov akshmakov force-pushed the pr/grdcontour-plotting-module branch from 1bc1686 to 2d56e57 Compare August 23, 2018 07:07
@akshmakov akshmakov changed the title WIP: grdcontour Implementation grdcontour Implementation Aug 23, 2018
@akshmakov
Copy link
Contributor Author

@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
Copy link
Contributor Author

image

@leouieda
Copy link
Member

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

@leouieda leouieda merged commit 43badcd into GenericMappingTools:master Sep 18, 2018
@leouieda
Copy link
Member

Thanks @akshmakov! Please feel free to add yourself to the AUTHORS.md file (through another PR).

@akshmakov
Copy link
Contributor Author

@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 black flag these instances? I only recently installed and learned to use it, so my future PR's shouldn't be annoying

P.S. I have some suspicion that baseline mismatches may be related to default system fonts.

@leouieda
Copy link
Member

Is there a style guide that I can review?

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 make check is happy then everything should be fine :)

I have some suspicion that baseline mismatches may be related to default system fonts.

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!

@weiji14 weiji14 mentioned this pull request Dec 28, 2018
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants