1
1
"""
2
2
Non-plot GMT modules.
3
3
"""
4
+ import re
5
+
6
+ import numpy as np
4
7
import xarray as xr
5
8
6
9
from .clib import Session
@@ -59,14 +62,17 @@ def info(table, **kwargs):
59
62
"""
60
63
Get information about data tables.
61
64
62
- Reads from files and finds the extreme values in each of the columns.
63
- It recognizes NaNs and will print warnings if the number of columns vary
64
- from record to record. As an option, it will find the extent of the first
65
- n columns rounded up and down to the nearest multiple of the supplied
66
- increments. By default, this output will be in the form *-Rw/e/s/n*,
67
- or the output will be in column form for as many columns as there are
68
- increments provided. The *nearest_multiple* option will provide a
69
- *-Tzmin/zmax/dz* string for makecpt.
65
+ Reads from files and finds the extreme values in each of the columns
66
+ reported as min/max pairs. It recognizes NaNs and will print warnings if
67
+ the number of columns vary from record to record. As an option, it will
68
+ find the extent of the first two columns rounded up and down to the nearest
69
+ multiple of the supplied increments given by *spacing*. Such output will be
70
+ in a numpy.ndarray form ``[w, e, s, n]``, which can be used directly as the
71
+ *region* argument for other modules (hence only dx and dy are needed). If
72
+ the *per_column* option is combined with *spacing*, then the numpy.ndarray
73
+ output will be rounded up/down for as many columns as there are increments
74
+ provided in *spacing*. A similar option *nearest_multiple* option will
75
+ provide a numpy.ndarray in the form of ``[zmin, zmax, dz]`` for makecpt.
70
76
71
77
Full option list at :gmt-docs:`gmtinfo.html`
72
78
@@ -81,12 +87,21 @@ def info(table, **kwargs):
81
87
spacing : str
82
88
``'[b|p|f|s]dx[/dy[/dz...]]'``.
83
89
Report the min/max of the first n columns to the nearest multiple of
84
- the provided increments and output results in the form *-Rw/e/s/n*
85
- (unless *per_column* is set) .
90
+ the provided increments and output results in the form
91
+ ``[w, e, s, n]`` .
86
92
nearest_multiple : str
87
93
``'dz[+ccol]'``
88
94
Report the min/max of the first (0'th) column to the nearest multiple
89
- of dz and output this as the string *-Tzmin/zmax/dz*.
95
+ of dz and output this in the form ``[zmin, zmax, dz]``.
96
+
97
+ Returns
98
+ -------
99
+ output : np.ndarray or str
100
+ Return type depends on whether any of the 'per_column', 'spacing', or
101
+ 'nearest_multiple' parameters are set.
102
+
103
+ - np.ndarray if either of the above parameters are used.
104
+ - str if none of the above parameters are used.
90
105
"""
91
106
kind = data_kind (table )
92
107
with Session () as lib :
@@ -105,7 +120,16 @@ def info(table, **kwargs):
105
120
[fname , build_arg_string (kwargs ), "->" + tmpfile .name ]
106
121
)
107
122
lib .call_module ("info" , arg_str )
108
- return tmpfile .read ()
123
+ result = tmpfile .read ()
124
+
125
+ if any (arg in kwargs for arg in ["C" , "I" , "T" ]):
126
+ # Converts certain output types into a numpy array
127
+ # instead of a raw string that is less useful.
128
+ result = np .loadtxt (
129
+ re .sub (pattern = "-R|-T|/" , repl = " " , string = result ).splitlines ()
130
+ )
131
+
132
+ return result
109
133
110
134
111
135
@fmt_docstring
0 commit comments