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

Add inline example for grdvolume #1726

Merged
merged 15 commits into from
Mar 16, 2022
Merged
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions pygmt/src/grdvolume.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use_alias,
)

__doctest_skip__ = ["grdvolume"]


@fmt_docstring
@use_alias(
Expand Down Expand Up @@ -75,6 +77,22 @@ def grdvolume(grid, output_type="pandas", outfile=None, **kwargs):
- :class:`pandas.DataFrame` or :class:`numpy.ndarray` if ``outfile``
is not set (depends on ``output_type`` [Default is
class:`pandas.DataFrame`])
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved

Example
-------
>>> import pygmt
>>> # Load a grid of @earth_relief_30m data, with an x-range of 10 to 30
>>> # degrees, and a y-range of 15 to 25 degrees
>>> grid = pygmt.datasets.load_earth_relief(
... resolution="30m", region=[10, 30, 15, 25]
... )
>>> # Create a numpy ndarray that contains the contour, area, volume, and
>>> # maximum mean height above the plane specified by the given contour
>>> # and below the surface; set the minimum contour z-value to 200, the
>>> # maximum to 400, and the interval to 50.
>>> output_array = pygmt.grdvolume(
... grid=grid, contour=[200, 400, 50], output_type="numpy"
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved
... )
"""
Copy link
Member

Choose a reason for hiding this comment

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

Ideally, we would have nice column names like in grdhisteq:

>>> bins = pygmt.grdhisteq.compute_bins(grid=grid, divisions=5)
>>> print(bins)
start stop
bin_id
0 179.0 397.5
1 397.5 475.5
2 475.5 573.5
3 573.5 710.5
4 710.5 2103.0

But for the sake of time, and just finish this inline example, let's go with this:

Suggested change
"""
>>> print(output_dataframe)
0 1 2 3
0 200 2.144285e+12 7.972228e+14 371.789489
1 250 2.104042e+12 6.908183e+14 328.329232
2 300 2.014978e+12 5.877195e+14 291.675420
3 350 1.892109e+12 4.897545e+14 258.840510
4 400 1.744792e+12 3.988316e+14 228.584026
"""

if output_type not in ["numpy", "pandas", "file"]:
raise GMTInvalidInput(
Expand Down