Skip to content

Added basic contour functionality #212

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

Merged
merged 15 commits into from
Aug 17, 2018

Conversation

mjziebarth
Copy link
Contributor

Hi everyone,
started using gmt-python yesterday and really like the project. Since I'll be writing some solutions for my own use, I figured I may contribute them right away. So, I am leaning a bit on the pull-request-style of development and don't expect this to be ready to merge straight away.

Changes proposed in this pull request

  • Add function to call gmt contour from BasePlotting.

Note

The code is copied from the plot function and is very basic so far. Tested only locally for crashes in Figure so far.

Looking forward to your input!

kwargs = self._preprocess(**kwargs)

kind = data_kind(data, x, y)

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

@leouieda
Copy link
Member

@mjziebarth thank you submitting this! I really appreciate it 👍

Don't worry too much about the whole flow of development, I'll try to help you through it. And there is no way to really break things. That's what all these automatic checks take care of.

I'm a little bit overwhelmed with the Scipy conference this week, so sorry for the late reply. I'll try to look over this on the weekend.

Thank you again for your contribution! It's really appreciated.

@leouieda
Copy link
Member

@mjziebarth the code looks ok to me. Are you getting crashes?

@leouieda
Copy link
Member

If not, then the only things we need are a bit more documentation and some tests.

For the tests, please have a look at this: https://github.com/GenericMappingTools/gmt-python/blob/master/CONTRIBUTING.md#testing-plots Let me know if you need any help.

For the documentation, I'm thinking of adding a few examples to all modules. Would be willing to try to add an example plot using our sphinx extension?

@mjziebarth
Copy link
Contributor Author

Thanks for the feedback!

I added some test cases. Not the most sophisticated but should get the job done.
The tests ultimately fail on my local machine (TypeError with the gmt.Figure) but the images were generated. Let's see how this works with the CI.

I could add a test case for sphinx, but that should probably be a little bit more real-world, I guess?

"Contour should raise an exception if no or not sufficient data "
"is given"
fig = Figure()
for x in [None,data[:,0]]:

Choose a reason for hiding this comment

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

E231 missing whitespace after ','

"is given"
fig = Figure()
for x in [None,data[:,0]]:
for y in [None,data[:,0]]:

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 = Figure()
for x in [None,data[:,0]]:
for y in [None,data[:,0]]:
for z in [None,data[:,0]]:

Choose a reason for hiding this comment

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

E231 missing whitespace after ','

if x is not None and y is not None and z is not None:
continue
with pytest.raises(GMTInvalidInput):
fig.contour(

Choose a reason for hiding this comment

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

E111 indentation is not a multiple of four

def test_contour_vec(region):
"Plot an x-centered gaussian kernel with different y scale"
fig = Figure()
x,y = np.meshgrid(np.linspace(region[0],region[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 ','

x = x.flatten()
y = y.flatten()
z = (x-0.5*(region[0]+region[1]))**2 + 4*y**2
z = np.exp(-z/10**2*np.log(2))

Choose a reason for hiding this comment

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

E226 missing whitespace around arithmetic operator

)
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
def test_contour_matrix(data,region):

Choose a reason for hiding this comment

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

E231 missing whitespace after ','

)
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

pen='#ffcb87'
)
return fig

Choose a reason for hiding this comment

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

W391 blank line at end of file

@mjziebarth
Copy link
Contributor Author

So right now there are errors left in some of the Travis runs. One is a one pixel width difference in the generated test images that prevents the comparison. From visual inspection, the images do not show obvious errors and it seems like the python 3.6 Travis runs without errors.

Another Travis run fails at some point before that.

Do you have any idea what could go wrong there or how that behavior could be fixed? I'm not familiar with the underlying testing framework.

Regarding the sphinx-example: Where would that go?

@leouieda
Copy link
Member

@mjziebarth I'm going through the CI logs to try to see what went wrong. I found a problem with our CI builds on 3.5. It seems that our code formatter black only works on 3.6. I'll fix this first so that your tests can pass.

@akshmakov
Copy link
Contributor

akshmakov commented Aug 17, 2018

I had a need for contours as well, started working on this and then saw it was already done! Nice.

I can help rebase on top of the existing master branch so the PR can go through, but am waiting for this functionality!

(if you don't have any merge conflicts as easy as git rebase master or my preference git rebase -i master to squash and re-word commits)

+1

@akshmakov
Copy link
Contributor

akshmakov commented Aug 17, 2018

The branch rebases cleanly on master, meaning a merge commit from master isn't required. For an up to date branch as an example https://github.com/nc5ng/gmt-python/tree/rebase/contour-pr-212

@leouieda Turns out that grdcontour that I was looking for is different than pscontour, would it be worth adding my grdcontour implementation to this PR or creating a new PR?

@mjziebarth
Copy link
Contributor Author

Okay, I did it using this button of github. Not sure what that actually does but hope that's okay!

@leouieda Please excuse if you've been busy, but is there anything else I should do in this PR?

@leouieda
Copy link
Member

@mjziebarth sorry for the absence. I was away on travel last week and spent this entire week trying to get things up and running again with the GMT conda package (so many headaches). We're up and running again now.

Only thing left to do here is list the Figure.contour method in doc/api/index.rst. After that, I'll merge as soon as the CIs builds are passing.

Thanks for your effort and your patience! I hope to see more of these 😃

@leouieda
Copy link
Member

@akshmakov yeah, grdcontour is a different module with different inputs. Would you mind adding it in another PR?

They were failing everything except python 3.6 on OSX for some reason.
@leouieda
Copy link
Member

@mjziebarth there was a strange problem with your baseline images and I'm not entirely sure what caused it. I regenerated them on my machine and went ahead and added the API entry so we can merge this.

@leouieda leouieda merged commit e5845ba into GenericMappingTools:master Aug 17, 2018
@welcome
Copy link

welcome bot commented Aug 17, 2018

🎉🎉🎉 Congrats on merging your first pull request and welcome to the team! 🎉🎉🎉

Please open a new pull request to add yourself to the AUTHORS.md file. We hope that this was a good experience for you. Let us know if there is any way that the contributing process could be improved.

@akshmakov akshmakov mentioned this pull request Aug 19, 2018
4 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