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

Wrap blockmode #1456

Merged
merged 16 commits into from
Sep 15, 2021
1 change: 1 addition & 0 deletions doc/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ Operations on tabular data:

blockmean
blockmedian
blockmode
surface

Operations on grids:
Expand Down
1 change: 1 addition & 0 deletions pygmt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from pygmt.src import (
blockmean,
blockmedian,
blockmode,
config,
grd2cpt,
grdclip,
Expand Down
2 changes: 1 addition & 1 deletion pygmt/src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# pylint: disable=import-outside-toplevel

from pygmt.src.basemap import basemap
from pygmt.src.blockm import blockmean, blockmedian
from pygmt.src.blockm import blockmean, blockmedian, blockmode
from pygmt.src.coast import coast
from pygmt.src.colorbar import colorbar
from pygmt.src.config import config
Expand Down
86 changes: 79 additions & 7 deletions pygmt/src/blockm.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
blockm - Block average (x,y,z) data tables by mean or median estimation.
blockm - Block average (x,y,z) data tables by mean, median, or mode estimation.
"""
import pandas as pd
from pygmt.clib import Session
Expand All @@ -14,18 +14,19 @@

def _blockm(block_method, table, outfile, x, y, z, **kwargs):
r"""
Block average (x,y,z) data tables by mean or median estimation.
Block average (x,y,z) data tables by mean, median, or mode estimation.

Reads arbitrarily located (x,y,z) triples [or optionally weighted
quadruples (x,y,z,w)] from a table and writes to the output a mean or
median (depending on ``block_method``) position and value for every
non-empty block in a grid region defined by the ``region`` and ``spacing``
parameters.
quadruples (x,y,z,w)] from a table and writes to the output a mean,
median, or mode (depending on ``block_method``) position and value for
every non-empty block in a grid region defined by the ``region`` and
``spacing`` parameters.

Parameters
----------
block_method : str
Name of the GMT module to call. Must be "blockmean" or "blockmedian".
Name of the GMT module to call. Must be "blockmean" "blockmedian" or
arleaman marked this conversation as resolved.
Show resolved Hide resolved
"blockmode".

Returns
-------
Expand Down Expand Up @@ -210,3 +211,74 @@ def blockmedian(table=None, outfile=None, *, x=None, y=None, z=None, **kwargs):
z=z,
**kwargs
)


@fmt_docstring
@use_alias(
I="spacing",
R="region",
V="verbose",
a="aspatial",
f="coltypes",
arleaman marked this conversation as resolved.
Show resolved Hide resolved
i="incols",
o="outcols",
r="registration",
s="skiprows",
w="wrap",
)
@kwargs_to_strings(R="sequence")
arleaman marked this conversation as resolved.
Show resolved Hide resolved
def blockmode(table=None, outfile=None, *, x=None, y=None, z=None, **kwargs):
r"""
Block average (x,y,z) data tables by mode estimation.

Reads arbitrarily located (x,y,z) triples [or optionally weighted
quadruples (x,y,z,w)] and writes to the output a mode position and value
for every non-empty block in a grid region defined by the ``region`` and
``spacing`` parameters.

Takes a matrix, xyz triplets, or a file name as input.

Must provide either ``table`` or ``x``, ``y``, and ``z``.

Full option list at :gmt-docs:`blockmode.html`

{aliases}

Parameters
----------
table : str or {table-like}
Pass in (x, y, z) or (longitude, latitude, elevation) values by
providing a file name to an ASCII data table, a 2D
{table-classes}.
x/y/z : 1d arrays
Arrays of x and y coordinates and values z of the data points.

{I}

{R}

outfile : str
The file name for the output ASCII file.

{V}
{a}
{f}
arleaman marked this conversation as resolved.
Show resolved Hide resolved
{i}
{o}
{r}
{s}
{w}

Returns
-------
output : pandas.DataFrame or None
Return type depends on whether the ``outfile`` parameter is set:

- :class:`pandas.DataFrame` table with (x, y, z) columns if ``outfile``
is not set.
- None if ``outfile`` is set (filtered output will be stored in file
set by ``outfile``).
"""
return _blockm(
block_method="blockmode", table=table, outfile=outfile, x=x, y=y, z=z, **kwargs
)