@@ -60,14 +60,17 @@ def info(table, **kwargs):
6060 """
6161 Get information about data tables.
6262
63- Reads from files and finds the extreme values in each of the columns.
64- It recognizes NaNs and will print warnings if the number of columns vary
65- from record to record. As an option, it will find the extent of the first
66- n columns rounded up and down to the nearest multiple of the supplied
67- increments. By default, this output will be in the form *-Rw/e/s/n*,
68- or the output will be in column form for as many columns as there are
69- increments provided. The *nearest_multiple* option will provide a
70- *-Tzmin/zmax/dz* string for makecpt.
63+ Reads from files and finds the extreme values in each of the columns
64+ reported as min/max pairs. It recognizes NaNs and will print warnings if
65+ the number of columns vary from record to record. As an option, it will
66+ find the extent of the first two columns rounded up and down to the nearest
67+ multiple of the supplied increments given by *spacing*. Such output will be
68+ in a numpy.ndarray form ``[w, e, s, n]``, which can be used directly as the
69+ *region* argument for other modules (hence only dx and dy are needed). If
70+ the *per_column* option is combined with *spacing*, then the numpy.ndarray
71+ output will be rounded up/down for as many columns as there are increments
72+ provided in *spacing*. A similar option *nearest_multiple* option will
73+ provide a numpy.ndarray in the form of ``[zmin, zmax, dz]`` for makecpt.
7174
7275 Full option list at :gmt-docs:`gmtinfo.html`
7376
@@ -83,12 +86,21 @@ def info(table, **kwargs):
8386 spacing : str
8487 ``'[b|p|f|s]dx[/dy[/dz...]]'``.
8588 Report the min/max of the first n columns to the nearest multiple of
86- the provided increments and output results in the form *-Rw/e/s/n*
87- (unless *per_column* is set) .
89+ the provided increments and output results in the form
90+ ``[w, e, s, n]`` .
8891 nearest_multiple : str
8992 ``'dz[+ccol]'``
9093 Report the min/max of the first (0'th) column to the nearest multiple
91- of dz and output this as the string *-Tzmin/zmax/dz*.
94+ of dz and output this in the form ``[zmin, zmax, dz]``.
95+
96+ Returns
97+ -------
98+ output : np.ndarray or str
99+ Return type depends on whether any of the 'per_column', 'spacing', or
100+ 'nearest_multiple' parameters are set.
101+
102+ - np.ndarray if either of the above parameters are used.
103+ - str if none of the above parameters are used.
92104 """
93105 kind = data_kind (table )
94106 with Session () as lib :
@@ -108,7 +120,16 @@ def info(table, **kwargs):
108120 [fname , build_arg_string (kwargs ), "->" + tmpfile .name ]
109121 )
110122 lib .call_module ("info" , arg_str )
111- 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+ if result .startswith (("-R" , "-T" )): # e.g. -R0/1/2/3 or -T0/9/1
129+ result = result [2 :].replace ("/" , " " )
130+ result = np .loadtxt (result .splitlines ())
131+
132+ return result
112133
113134
114135@fmt_docstring
0 commit comments