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

Complete documentation of grdimage #620

Merged
merged 18 commits into from Sep 23, 2020
Merged

Conversation

weiji14
Copy link
Member

@weiji14 weiji14 commented Sep 20, 2020

Description of proposed changes

Time to put an end to all the noise about grdimage not being properly documented! To be fair, the documentation at https://www.pygmt.org/v0.2.0/api/generated/pygmt.Figure.grdimage.html is pretty embarrasing, considering that grdimage is one of the more widely used functions! For reference, upstream GMT docs is at https://docs.generic-mapping-tools.org/6.1/grdimage.html

Mentioned before at #364 (comment) and https://forum.generic-mapping-tools.org/t/grdgradient-in-pygmt/723/12.

Live documentation preview is at https://pygmt-git-grdimage-documentallargs.gmt.vercel.app/api/generated/pygmt.Figure.grdimage.html#pygmt.Figure.grdimage.

TODO:

Arguments/Aliases to document (see also https://www.generic-mapping-tools.org/GMT.jl/latest/#GMT.grdimage):

Fixes #

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 adding new functionality, add an example to docstrings or tutorials.

Add automatic docstrings for frame (B), cmap (C), projection (J), region (R), timestamp (U), verbose (V), and interpolation (n). Also removed alias pen (W) that  actually doesn't work.
@weiji14 weiji14 added the documentation Improvements or additions to documentation label Sep 20, 2020
@vercel vercel bot temporarily deployed to Preview September 20, 2020 04:13 Inactive
@weiji14 weiji14 added this to the 0.2.1 milestone Sep 20, 2020
pygmt/base_plotting.py Show resolved Hide resolved
pygmt/base_plotting.py Outdated Show resolved Hide resolved
pygmt/base_plotting.py Outdated Show resolved Hide resolved
@weiji14 weiji14 marked this pull request as ready for review September 21, 2020 06:05
@weiji14
Copy link
Member Author

weiji14 commented Sep 21, 2020

Ok, ready for review, and preview at https://pygmt-git-grdimage-documentallargs.gmt.vercel.app/api/generated/pygmt.Figure.grdimage.html#pygmt.Figure.grdimage! Best to take a closer look, I'm pretty sure I've messed up on some formatting. Also no rush to do it today since it's getting late.

This also helps with #618, documenting the fact that shading="intensfile" works. Will deal with xarray.DataArray inputs (a Python specific feature) separately another time.

pygmt/base_plotting.py Outdated Show resolved Hide resolved
pygmt/base_plotting.py Outdated Show resolved Hide resolved
pygmt/base_plotting.py Outdated Show resolved Hide resolved
pygmt/base_plotting.py Outdated Show resolved Hide resolved
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
Comment on lines 354 to 356
`grdmath` or `grdhisteq`. A third alternative is available when GMT is
build with GDAL support. Pass **image** which can be an image file
(geo-referenced or not). In this case the image can optionally be
Copy link
Member

Choose a reason for hiding this comment

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

It reads awkwardly.

Suggested change
`grdmath` or `grdhisteq`. A third alternative is available when GMT is
build with GDAL support. Pass **image** which can be an image file
(geo-referenced or not). In this case the image can optionally be
`grdmath` or `grdhisteq`. A third alternative is available when GMT is
build with GDAL support. Pass **image** which can be an image file
(geo-referenced or not). In this case the image can optionally be

Copy link
Member Author

Choose a reason for hiding this comment

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

Agree that this could be worded better, currently it's just copied from upstream GMT at https://github.com/GenericMappingTools/gmt/blob/8c0b548e52938f91bfb15f47f27d023488003ef8/doc/rst/source/grdimage_common.rst_#L14-L16. Maybe we should take out the grdgradient, grdmath and grdhisteq parts since they're not wrapped in PyGMT yet?

Copy link
Member

Choose a reason for hiding this comment

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

I'm afraid we may forget to add them back when the wrappers are available.

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe keep them for now, better to over-document than not. Doubt we'll see grdmath anytime soon (who uses Reverse Polish notation?!!), but grdgradient would definitely come, and grdhisteq will be a nice one for stretching colormaps.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I agree.

pygmt/base_plotting.py Outdated Show resolved Hide resolved
pygmt/base_plotting.py Outdated Show resolved Hide resolved
pygmt/base_plotting.py Outdated Show resolved Hide resolved
pygmt/base_plotting.py Outdated Show resolved Hide resolved
pygmt/base_plotting.py Outdated Show resolved Hide resolved
Comment on lines 354 to 356
`grdmath` or `grdhisteq`. A third alternative is available when GMT is
build with GDAL support. Pass **image** which can be an image file
(geo-referenced or not). In this case the image can optionally be
Copy link
Member Author

Choose a reason for hiding this comment

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

Agree that this could be worded better, currently it's just copied from upstream GMT at https://github.com/GenericMappingTools/gmt/blob/8c0b548e52938f91bfb15f47f27d023488003ef8/doc/rst/source/grdimage_common.rst_#L14-L16. Maybe we should take out the grdgradient, grdmath and grdhisteq parts since they're not wrapped in PyGMT yet?

Comment on lines 356 to 358
(geo-referenced or not). In this case the image can optionally be
illuminated with the file provided via the *shading* option. Here, if
image has no coordinates then those of the intensity file will be used.
Copy link
Member Author

Choose a reason for hiding this comment

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

What do you think about taking out this sentence about image, related to the change at https://github.com/GenericMappingTools/pygmt/pull/620/files#r492612750.

Copy link
Member

Choose a reason for hiding this comment

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

What do you think about taking out this sentence about image, related to the change at https://github.com/GenericMappingTools/pygmt/pull/620/files#r492612750.

The changes are big. It's unclear to me what you mean by "taking out this sentence about image"?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops, wrong link. Should be #620 (comment). The part where we took out grid | image.

Copy link
Member

@seisman seisman Sep 22, 2020

Choose a reason for hiding this comment

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

The reason to take out grid | image is, it's a little unclear what grid | image means, and for the grid argument, we already mention that grid could be a image:

       The file name or a DataArray containing the input 2-D gridded data
       set or image to be plotted

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, agree that taking grid | image is ok. But would this lead to confusion about this sentence:

        Pass **image** which can be an image file
        (geo-referenced or not). In this case the image can optionally be
        illuminated with the file provided via the *shading* option. Here, if
        image has no coordinates then those of the intensity file will be used.

I suppose we could just keep it to keep it in line with upstream GMT?

Copy link
Member

Choose a reason for hiding this comment

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

That's why I said these sentences don't read well in #620 (comment).

Perhaps we can change:

A third alternative is available when GMT is build with GDAL support. Pass image which can be an image file (geo-referenced or not). In this case the image can optionally be illuminated with the file provided via the -I option. Here, if image has no coordinates then those of the intensity file will be used.

to

If GMT is built with GDAL support, grid can be an image file (geo-referenced or not). In this case the image can optionally be illuminated with the file provided via the -I option. Here, if image has no coordinates then those of the intensity file will be used.

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks good enough (mentioning that image can be used with GDAL support). I'll commit the change.

@vercel vercel bot temporarily deployed to Preview September 22, 2020 21:28 Inactive
Co-Authored-By: Dongdong Tian <seisman.info@gmail.com>
Co-Authored-By: Dongdong Tian <seisman.info@gmail.com>
Comment on lines 435 to 436
grid via a call to `grdgradient`; append **+a** \\ *azimuth*,
**+n** \\ *args*, and **+m** \\ *ambient* to specify azimuth,
Copy link
Member

Choose a reason for hiding this comment

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

There should be no spaces between modifier and value:
image

Suggested change
grid via a call to `grdgradient`; append **+a** \\ *azimuth*,
**+n** \\ *args*, and **+m** \\ *ambient* to specify azimuth,
grid via a call to `grdgradient`; append **+a**\\ *azimuth*,
**+n**\\ *args*, and **+m**\\ *ambient* to specify azimuth,

Are you sure we need double back-slashes?

Copy link
Member Author

@weiji14 weiji14 Sep 22, 2020

Choose a reason for hiding this comment

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

Good catch. Single backslash would result in a flake8 error W605 invalid escape sequence '\ '

Copy link
Member

Choose a reason for hiding this comment

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

Single backslash would result in a flake8 error W605 invalid escape sequence '\ '

Double backslashes in ReST syntax doesn't give what we want if they're not in docstring: http://rst.ninjs.org/#KiorYSoqXFwgKmF6aW11dGgq

Why does flake8 check ReST syntax? Is it a flake8 bug? Or can we make flake8 ignore it for ReST strings?

Copy link
Member

Choose a reason for hiding this comment

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

Anyway, the documentation looks good now. We may see if we can avoid double backslashes in the future.

Copy link
Member Author

@weiji14 weiji14 Sep 22, 2020

Choose a reason for hiding this comment

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

Double backslashes in ReST syntax doesn't give what we want if they're not in docstring: http://rst.ninjs.org/#KiorYSoqXFwgKmF6aW11dGgq

The double backslash is needed for Python, the alternative would be to use a raw string (e.g. r" **+n**\ *args* "). We came across this at #525 (comment), might be good if we can standardize this in our CONTRIBUTING.md document (open an issue?).

Anyways, the rendered version looks fine:

image

Why does flake8 check ReST syntax? Is it a flake8 bug? Or can we make flake8 ignore it for ReST strings?

A quick search yields https://github.com/kataev/flake8-rst, but I haven't tried it, and don't know if it does what we want.

Copy link
Member

Choose a reason for hiding this comment

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

GMT uses singe backslash syntax like **+a**\ *azimuth*. If we copy documentation from GMT, then I expect we will see the same warning often.

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'll open up an issue for this to continue the discussion :)

Co-Authored-By: Dongdong Tian <seisman.info@gmail.com>
@weiji14
Copy link
Member Author

weiji14 commented Sep 22, 2020

Hmm, there's a strange failure on the Ubuntu Python 3.6 test at https://github.com/GenericMappingTools/pygmt/pull/620/checks?check_run_id=1152171757 with a missing earth_relief grid. I'll re-run just to be sure before merging.

@weiji14 weiji14 merged commit 593ca1a into master Sep 23, 2020
@weiji14 weiji14 deleted the grdimage/document_all_args branch September 23, 2020 00:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants