11""" 
22Non-plot GMT modules. 
33""" 
4+ import  re 
5+ 
6+ import  numpy  as  np 
47import  xarray  as  xr 
58
69from  .clib  import  Session 
@@ -59,14 +62,17 @@ def info(table, **kwargs):
5962    """ 
6063    Get information about data tables. 
6164
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. 
7076
7177    Full option list at :gmt-docs:`gmtinfo.html` 
7278
@@ -81,12 +87,21 @@ def info(table, **kwargs):
8187    spacing : str 
8288        ``'[b|p|f|s]dx[/dy[/dz...]]'``. 
8389        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]`` . 
8692    nearest_multiple : str 
8793        ``'dz[+ccol]'`` 
8894        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. 
90105    """ 
91106    kind  =  data_kind (table )
92107    with  Session () as  lib :
@@ -105,7 +120,16 @@ def info(table, **kwargs):
105120                    [fname , build_arg_string (kwargs ), "->"  +  tmpfile .name ]
106121                )
107122                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 
109133
110134
111135@fmt_docstring  
0 commit comments