Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
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
81 changes: 76 additions & 5 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,18 @@

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
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 "blockmode".

Returns
-------
Expand Down Expand Up @@ -210,3 +210,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",
i="incols",
o="outcols",
r="registration",
s="skiprows",
w="wrap",
)
@kwargs_to_strings(R="sequence")
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}
{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
)