|
1 | 1 | """
|
2 | 2 | Non-plot GMT modules.
|
3 | 3 | """
|
4 |
| -import numpy as np |
5 | 4 | import xarray as xr
|
6 | 5 | from pygmt.clib import Session
|
7 | 6 | from pygmt.exceptions import GMTInvalidInput
|
@@ -55,141 +54,6 @@ def grdinfo(grid, **kwargs):
|
55 | 54 | return result
|
56 | 55 |
|
57 | 56 |
|
58 |
| -@fmt_docstring |
59 |
| -@use_alias(C="per_column", I="spacing", T="nearest_multiple", V="verbose") |
60 |
| -def info(table, **kwargs): |
61 |
| - """ |
62 |
| - Get information about data tables. |
63 |
| -
|
64 |
| - Reads from files and finds the extreme values in each of the columns |
65 |
| - reported as min/max pairs. It recognizes NaNs and will print warnings if |
66 |
| - the number of columns vary from record to record. As an option, it will |
67 |
| - find the extent of the first two columns rounded up and down to the nearest |
68 |
| - multiple of the supplied increments given by *spacing*. Such output will be |
69 |
| - in a numpy.ndarray form ``[w, e, s, n]``, which can be used directly as the |
70 |
| - *region* argument for other modules (hence only dx and dy are needed). If |
71 |
| - the *per_column* option is combined with *spacing*, then the numpy.ndarray |
72 |
| - output will be rounded up/down for as many columns as there are increments |
73 |
| - provided in *spacing*. A similar option *nearest_multiple* option will |
74 |
| - provide a numpy.ndarray in the form of ``[zmin, zmax, dz]`` for makecpt. |
75 |
| -
|
76 |
| - Full option list at :gmt-docs:`gmtinfo.html` |
77 |
| -
|
78 |
| - {aliases} |
79 |
| -
|
80 |
| - Parameters |
81 |
| - ---------- |
82 |
| - table : str or np.ndarray or pandas.DataFrame or xarray.Dataset |
83 |
| - Pass in either a file name to an ASCII data table, a 1D/2D numpy array, |
84 |
| - a pandas dataframe, or an xarray dataset made up of 1D xarray.DataArray |
85 |
| - data variables. |
86 |
| - per_column : bool |
87 |
| - Report the min/max values per column in separate columns. |
88 |
| - spacing : str |
89 |
| - ``'[b|p|f|s]dx[/dy[/dz...]]'``. |
90 |
| - Report the min/max of the first n columns to the nearest multiple of |
91 |
| - the provided increments and output results in the form |
92 |
| - ``[w, e, s, n]``. |
93 |
| - nearest_multiple : str |
94 |
| - ``'dz[+ccol]'`` |
95 |
| - Report the min/max of the first (0'th) column to the nearest multiple |
96 |
| - of dz and output this in the form ``[zmin, zmax, dz]``. |
97 |
| -
|
98 |
| - {V} |
99 |
| -
|
100 |
| - Returns |
101 |
| - ------- |
102 |
| - output : np.ndarray or str |
103 |
| - Return type depends on whether any of the 'per_column', 'spacing', or |
104 |
| - 'nearest_multiple' parameters are set. |
105 |
| -
|
106 |
| - - np.ndarray if either of the above parameters are used. |
107 |
| - - str if none of the above parameters are used. |
108 |
| - """ |
109 |
| - kind = data_kind(table) |
110 |
| - with Session() as lib: |
111 |
| - if kind == "file": |
112 |
| - file_context = dummy_context(table) |
113 |
| - elif kind == "matrix": |
114 |
| - try: |
115 |
| - # pandas.DataFrame and xarray.Dataset types |
116 |
| - arrays = [array for _, array in table.items()] |
117 |
| - except AttributeError: |
118 |
| - # Python lists, tuples, and numpy ndarray types |
119 |
| - arrays = np.atleast_2d(np.asanyarray(table).T) |
120 |
| - file_context = lib.virtualfile_from_vectors(*arrays) |
121 |
| - else: |
122 |
| - raise GMTInvalidInput(f"Unrecognized data type: {type(table)}") |
123 |
| - |
124 |
| - with GMTTempFile() as tmpfile: |
125 |
| - with file_context as fname: |
126 |
| - arg_str = " ".join( |
127 |
| - [fname, build_arg_string(kwargs), "->" + tmpfile.name] |
128 |
| - ) |
129 |
| - lib.call_module("info", arg_str) |
130 |
| - result = tmpfile.read() |
131 |
| - |
132 |
| - if any(arg in kwargs for arg in ["C", "I", "T"]): |
133 |
| - # Converts certain output types into a numpy array |
134 |
| - # instead of a raw string that is less useful. |
135 |
| - if result.startswith(("-R", "-T")): # e.g. -R0/1/2/3 or -T0/9/1 |
136 |
| - result = result[2:].replace("/", " ") |
137 |
| - result = np.loadtxt(result.splitlines()) |
138 |
| - |
139 |
| - return result |
140 |
| - |
141 |
| - |
142 |
| -@fmt_docstring |
143 |
| -@use_alias(G="download", V="verbose") |
144 |
| -def which(fname, **kwargs): |
145 |
| - """ |
146 |
| - Find the full path to specified files. |
147 |
| -
|
148 |
| - Reports the full paths to the files given through *fname*. We look for |
149 |
| - the file in (1) the current directory, (2) in $GMT_USERDIR (if defined), |
150 |
| - (3) in $GMT_DATADIR (if defined), or (4) in $GMT_CACHEDIR (if defined). |
151 |
| -
|
152 |
| - *fname* can also be a downloadable file (either a full URL, a |
153 |
| - `@file` special file for downloading from the GMT Site Cache, or |
154 |
| - `@earth_relief_*` topography grids). In these cases, use option *download* |
155 |
| - to set the desired behavior. If *download* is not used (or False), the file |
156 |
| - will not be found. |
157 |
| -
|
158 |
| - Full option list at :gmt-docs:`gmtwhich.html` |
159 |
| -
|
160 |
| - {aliases} |
161 |
| -
|
162 |
| - Parameters |
163 |
| - ---------- |
164 |
| - fname : str |
165 |
| - The file name that you want to check. |
166 |
| - download : bool or str |
167 |
| - If the file is downloadable and not found, we will try to download the |
168 |
| - it. Use True or 'l' (default) to download to the current directory. Use |
169 |
| - 'c' to place in the user cache directory or 'u' user data directory |
170 |
| - instead. |
171 |
| - {V} |
172 |
| -
|
173 |
| - Returns |
174 |
| - ------- |
175 |
| - path : str |
176 |
| - The path of the file, depending on the options used. |
177 |
| -
|
178 |
| - Raises |
179 |
| - ------ |
180 |
| - FileNotFoundError |
181 |
| - If the file is not found. |
182 |
| - """ |
183 |
| - with GMTTempFile() as tmpfile: |
184 |
| - arg_str = " ".join([fname, build_arg_string(kwargs), "->" + tmpfile.name]) |
185 |
| - with Session() as lib: |
186 |
| - lib.call_module("which", arg_str) |
187 |
| - path = tmpfile.read().strip() |
188 |
| - if not path: |
189 |
| - raise FileNotFoundError("File '{}' not found.".format(fname)) |
190 |
| - return path |
191 |
| - |
192 |
| - |
193 | 57 | class config: # pylint: disable=invalid-name
|
194 | 58 | """
|
195 | 59 | Set GMT defaults globally or locally.
|
|
0 commit comments