|
2 | 2 | binstats - Bin spatial data and determine statistics per bin |
3 | 3 | """ |
4 | 4 |
|
| 5 | +from pygmt.alias import Alias, AliasSystem |
5 | 6 | from pygmt.clib import Session |
6 | 7 | from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias |
7 | 8 |
|
8 | 9 |
|
9 | 10 | @fmt_docstring |
10 | 11 | @use_alias( |
11 | | - C="statistic", |
12 | 12 | E="empty", |
13 | 13 | I="spacing", |
14 | 14 | N="normalize", |
|
23 | 23 | r="registration", |
24 | 24 | ) |
25 | 25 | @kwargs_to_strings(I="sequence", R="sequence", i="sequence_comma") |
26 | | -def binstats(data, outgrid: str | None = None, **kwargs): |
| 26 | +def binstats( |
| 27 | + data, |
| 28 | + outgrid: str | None = None, |
| 29 | + statistic=None, |
| 30 | + quantile_value=50, |
| 31 | + **kwargs, # noqa: ARG001 |
| 32 | +): |
27 | 33 | r""" |
28 | 34 | Bin spatial data and determine statistics per bin. |
29 | 35 |
|
@@ -69,6 +75,8 @@ def binstats(data, outgrid: str | None = None, **kwargs): |
69 | 75 | - **u** for maximum (upper) |
70 | 76 | - **U** for maximum of negative values only |
71 | 77 | - **z** for the sum |
| 78 | + quantile_value : float |
| 79 | + The quantile value if ``statistic="quantile". |
72 | 80 | empty : float |
73 | 81 | Set the value assigned to empty nodes [Default is NaN]. |
74 | 82 | normalize : bool |
@@ -102,13 +110,41 @@ def binstats(data, outgrid: str | None = None, **kwargs): |
102 | 110 | - None if ``outgrid`` is set (grid output will be stored in file set by |
103 | 111 | ``outgrid``) |
104 | 112 | """ |
| 113 | + alias = AliasSystem( |
| 114 | + C=Alias( |
| 115 | + "statistic", |
| 116 | + mapping={ |
| 117 | + "mean": "a", |
| 118 | + "mad": "d", |
| 119 | + "full": "g", |
| 120 | + "interquartile": "i", |
| 121 | + "min": "l", |
| 122 | + "minpos": "L", |
| 123 | + "median": "m", |
| 124 | + "number": "n", |
| 125 | + "lms": "o", |
| 126 | + "mode": "p", |
| 127 | + "quantile": "q", |
| 128 | + "rms": "r", |
| 129 | + "stddev": "s", |
| 130 | + "max": "u", |
| 131 | + "maxneg": "U", |
| 132 | + "sum": "z", |
| 133 | + }, |
| 134 | + ), |
| 135 | + G="outgrid", |
| 136 | + ) |
| 137 | + if statistic == "quantile": |
| 138 | + statistic += str(quantile_value) |
| 139 | + |
| 140 | + kwdict = alias.kwdict |
105 | 141 | with Session() as lib: |
106 | 142 | with ( |
107 | 143 | lib.virtualfile_in(check_kind="vector", data=data) as vintbl, |
108 | 144 | lib.virtualfile_out(kind="grid", fname=outgrid) as voutgrd, |
109 | 145 | ): |
110 | | - kwargs["G"] = voutgrd |
| 146 | + kwdict["G"] = voutgrd |
111 | 147 | lib.call_module( |
112 | | - module="binstats", args=build_arg_list(kwargs, infile=vintbl) |
| 148 | + module="binstats", args=build_arg_list(kwdict, infile=vintbl) |
113 | 149 | ) |
114 | 150 | return lib.virtualfile_to_raster(vfname=voutgrd, outgrid=outgrid) |
0 commit comments