Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

grdconvert.rst 13 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
  1. .. index:: ! grdconvert
  2. .. include:: module_core_purpose.rst_
  3. ***********
  4. grdconvert
  5. ***********
  6. |grdconvert_purpose|
  7. Synopsis
  8. --------
  9. .. include:: common_SYN_OPTs.rst_
  10. **gmt grdconvert** *ingrdfile* |-G|\ *outgrdfile*
  11. [ |-N| ]
  12. [ |SYN_OPT-R| ]
  13. [ |SYN_OPT-V| ]
  14. [ |-Z|\ [**+s**\ *factor*][**+o**\ *offset*] ]
  15. [ |SYN_OPT-f| ]
  16. [ |SYN_OPT--| ]
  17. |No-spaces|
  18. Description
  19. -----------
  20. **grdconvert** reads a grid file in one format and writes it out using
  21. another format. As an option the user may select a subset of the data to
  22. be written and to specify scaling, translation, and NaN-value.
  23. Required Arguments
  24. ------------------
  25. *ingrdfile*\ [=id[**+s**\ *scale*][**+o**\ *offset*][**+n**\ *invalid*]]
  26. The grid file to be read. Append format =\ *id* code if not a
  27. standard COARDS-compliant netCDF grid file. If =\ *id* is set (see
  28. below), you may optionally append any of **+s**\ *scale*, **+o**\ *offset*,
  29. and **+n**\ *invalid*. The first two options will scale the data
  30. and then offset them with the specified amounts after reading
  31. while the latter lets you supply a value that represents an invalid
  32. grid entry, i.e., 'Not-a-Number' (for floating-point grids this is
  33. unnecessary since the IEEE NaN is used; however integers need a
  34. value which means no data available). When *id=gd*, the file will
  35. be read using the GDAL library, which will take care to detect the
  36. format of the file being read. This mechanism is actually used
  37. automatically when the file format is not one of those that GMT
  38. recognize. However, sometimes the guessing may fail, so adding
  39. *id=gd* forces a read via GDAL.
  40. See Section :ref:`grid-file-format` of the GMT Technical Reference and Cookbook for more information.
  41. .. _-G:
  42. **-G**\ *outgrdfile*\ [=id[**+s**\ *scale*][**+o**\ *offset*][**+n**\ *invalid*]][*:driver*\ [/*datatype*]]]
  43. The grid file to be written. Append format =\ *id* code if not a
  44. standard COARDS-compliant netCDF grid file. If =\ *id* is set (see
  45. below), you may optionally append any of **+s**\ *scale*,
  46. **+o**\ *offset*, and **+n**\ *invalid*. These modifiers are
  47. particularly practical when storing the data as integers, by
  48. first removing an offset and then scaling down the values.
  49. Since the scale and offset are applied in reverse order when
  50. reading, this does not affect the data values (except for
  51. round-offs). The **+n** modifier let you append a value
  52. that represents 'Not-a-Number' (for floating-point grids this is
  53. unnecessary since the IEEE NaN is used; however integers need a
  54. value which means no data available). You may specify **+s**\ *a*
  55. for auto-adjusting the scale and/or offset of packed integer grids
  56. (=\ *id*\ **+s**\ *a* is a shorthand for =\ *id*\ **+s**\ *a*\ **+o**\ *a*).
  57. When *id*\ =\ *gd*, the file will be saved using the
  58. GDAL library. Append the format *:driver* and optionally the output
  59. *datatype*. The driver names are those used by GDAL itself (e.g.,
  60. netCDF, GTiFF, etc.), and the data type is one of
  61. *u8*\|\ *u16*\|\ *i16*\|\ *u32*\|\ *i32*\|\ *float32*,
  62. where 'i' and 'u' denote signed and unsigned integers respectively.
  63. The default type is *float32*. Note also that both driver names and
  64. data types are case insensitive.
  65. See Section :ref:`grid-file-format` of the GMT Technical Reference and Cookbook for more information.
  66. Consider setting :term:`IO_NC4_DEFLATION_LEVEL`
  67. to reduce file size and to further increase read/write performance.
  68. Especially when working with subsets of global grids, masks, and grids with
  69. repeating grid values, the improvement is usually significant.
  70. Optional Arguments
  71. ------------------
  72. .. _-N:
  73. **-N**
  74. Suppress the writing of the GMT header structure. This is useful
  75. when you want to write a native grid to be used by external tools
  76. that do not recognize GMT headers. It
  77. only applies to native grids and is ignored for netCDF output.
  78. .. _-R:
  79. .. |Add_-R| unicode:: 0x20 .. just an invisible code
  80. .. include:: explain_-R.rst_
  81. .. _-V:
  82. .. |Add_-V| unicode:: 0x20 .. just an invisible code
  83. .. include:: explain_-V.rst_
  84. .. _-Z:
  85. **-Z**\ [**+s**\ *factor*][**+o**\ *offset*]
  86. Use to subtract *offset* from the data and then multiply the results by
  87. *factor* before writing the output file [1/0]. **Note**: This
  88. *changes* the values in the grid. In contrast, while options to supply
  89. a scale and offset via the **+s** and **+o** modifiers in a file
  90. name also adjust the data accordingly they also set the scale and
  91. offset in the metadata, so upon reading the new file you recover
  92. the original range. Typically, those options are used to enable
  93. packing of data via the use of an integer format (see table).
  94. .. |Add_-f| unicode:: 0x20 .. just an invisible code
  95. .. include:: explain_-f.rst_
  96. .. include:: explain_help.rst_
  97. Format Identifier
  98. -----------------
  99. By default, grids will be written as floating point data stored in
  100. binary files using the netCDF format and meta-data structure. This
  101. format is conform the COARDS conventions. GMT versions prior to 4.1
  102. produced netCDF files that did not conform to these conventions.
  103. Although these files are still supported, their use is deprecated. To
  104. write other than floating point COARDS-compliant netCDF files, append
  105. the =\ *id* suffix to the filename *outgrdfile*.
  106. When reading files, **grdconvert** and other GMT programs will try
  107. to automatically recognize the type of the input grid file. If this
  108. fails you may append the =\ *id* suffix to the filename *ingrdfile*.
  109. +----------+---------------------------------------------------------------+
  110. | ID | Explanation |
  111. +----------+---------------------------------------------------------------+
  112. | **nb** | GMT netCDF format (8-bit integer, COARDS, CF-1.5) |
  113. +----------+---------------------------------------------------------------+
  114. | **ns** | GMT netCDF format (16-bit integer, COARDS, CF-1.5) |
  115. +----------+---------------------------------------------------------------+
  116. | **ni** | GMT netCDF format (32-bit integer, COARDS, CF-1.5) |
  117. +----------+---------------------------------------------------------------+
  118. | **nf** | GMT netCDF format (32-bit float, COARDS, CF-1.5) |
  119. +----------+---------------------------------------------------------------+
  120. | **nd** | GMT netCDF format (64-bit float, COARDS, CF-1.5) |
  121. +----------+---------------------------------------------------------------+
  122. | **cb** | GMT netCDF format (8-bit integer, deprecated) |
  123. +----------+---------------------------------------------------------------+
  124. | **cs** | GMT netCDF format (16-bit integer, deprecated) |
  125. +----------+---------------------------------------------------------------+
  126. | **ci** | GMT netCDF format (32-bit integer, deprecated) |
  127. +----------+---------------------------------------------------------------+
  128. | **cf** | GMT netCDF format (32-bit float, deprecated) |
  129. +----------+---------------------------------------------------------------+
  130. | **cd** | GMT netCDF format (64-bit float, deprecated) |
  131. +----------+---------------------------------------------------------------+
  132. | **bm** | GMT native, C-binary format (bit-mask) |
  133. +----------+---------------------------------------------------------------+
  134. | **bb** | GMT native, C-binary format (8-bit integer) |
  135. +----------+---------------------------------------------------------------+
  136. | **bs** | GMT native, C-binary format (16-bit integer) |
  137. +----------+---------------------------------------------------------------+
  138. | **bi** | GMT native, C-binary format (32-bit integer) |
  139. +----------+---------------------------------------------------------------+
  140. | **bf** | GMT native, C-binary format (32-bit float) |
  141. +----------+---------------------------------------------------------------+
  142. | **bd** | GMT native, C-binary format (64-bit float) |
  143. +----------+---------------------------------------------------------------+
  144. | **rb** | SUN rasterfile format (8-bit standard) |
  145. +----------+---------------------------------------------------------------+
  146. | **rf** | GEODAS grid format GRD98 (NCEI) |
  147. +----------+---------------------------------------------------------------+
  148. | **sf** | Golden Software Surfer format 6 (32-bit float) |
  149. +----------+---------------------------------------------------------------+
  150. | **sd** | Golden Software Surfer format 7 (64-bit float, read-only) |
  151. +----------+---------------------------------------------------------------+
  152. | **af** | Atlantic Geoscience Center format AGC (32-bit float) |
  153. +----------+---------------------------------------------------------------+
  154. | **ei** | ESRI Arc/Info ASCII Grid Interchange format (ASCII integer) |
  155. +----------+---------------------------------------------------------------+
  156. | **ef** | ESRI Arc/Info ASCII Grid Interchange format (ASCII float) |
  157. +----------+---------------------------------------------------------------+
  158. | **gd** | Import/export through GDAL |
  159. +----------+---------------------------------------------------------------+
  160. GMT Standard Netcdf Files
  161. -------------------------
  162. The standard format used for grdfiles is based on netCDF and conforms to
  163. the COARDS conventions. Files written in this format can be read by
  164. numerous third-party programs and are platform-independent. Some
  165. disk-space can be saved by storing the data as bytes or shorts in stead
  166. of integers. Use the *scale* and *offset* parameters to make this work
  167. without loss of data range or significance. For more details, see
  168. :ref:`GMT File Formats` and :ref:`Write-grids-images`.
  169. **Multi-variable grid files**
  170. By default, GMT programs will read the first 2-dimensional grid
  171. contained in a COARDS-compliant netCDF file. Alternatively, use
  172. *ingrdfile*\ **?**\ *varname* (ahead of any optional suffix **=**\ *id*)
  173. to specify the requested variable *varname*. Since **?** has special
  174. meaning as a wildcard, escape this meaning by placing the full filename
  175. and suffix between quotes.
  176. **Multi-dimensional grids**
  177. To extract one *layer* or *level* from a 3-dimensional grid stored in a
  178. COARDS-compliant netCDF file, append both the name of the variable and
  179. the index associated with the layer (starting at zero) in the form:
  180. *ingrdfile*\ **?**\ *varname*\ **[**\ *layer*\ **]**. Alternatively,
  181. specify the value associated with that layer using parentheses in stead
  182. of brackets:
  183. *ingridfile*\ **?**\ *varname*\ **(**\ *layer*\ **)**.
  184. In a similar way layers can be extracted from 4- or even 5-dimensional
  185. grids. For example, if a grid has the dimensions (parameter, time,
  186. depth, latitude, longitude), a map can be selected by using:
  187. *ingridfile*\ **?**\ *varname*\ **(**\ *parameter*,\ *time*,\ *depth*\ **)**.
  188. Since question marks, brackets and parentheses have special meanings on
  189. the command line, escape these meanings by placing the full filename and
  190. suffix between quotes.
  191. Native Binary Files
  192. -------------------
  193. For binary native GMT files the size of the GMT grid header block
  194. is *hsize* = 892 bytes, and the total size of the file is *hsize* + *nx*
  195. \* *ny* \* *item_size*, where *item_size* is the size in bytes of each
  196. element (1, 2, 4). Bit grids are stored using 4-byte integers, each
  197. holding 32 bits, so for these files the size equation is modified by
  198. using ceil (*nx* / 32) \* 4 instead of *nx*. Note that these files are
  199. platform-dependent. Files written on Little Endian machines (e.g., PCs)
  200. can not be read on Big Endian machines (e.g., most workstations). Also
  201. note that it is not possible for GMT to determine uniquely if a
  202. 4-byte grid is float or int; in such cases it is best to use the *=ID*
  203. mechanism to specify the file format. In all cases a native grid is
  204. considered to be signed (i.e., there are no provision for unsigned short
  205. ints or unsigned bytes). For header and grid details, see :ref:`GMT File Formats`.
  206. .. include:: explain_float.rst_
  207. Examples
  208. --------
  209. .. include:: explain_example.rst_
  210. To extract the second layer from a 3-dimensional grid named temp from a
  211. COARDS-compliant netCDF file climate.nc:
  212. ::
  213. gmt grdconvert climate.nc?temp[1] -Gtemp.nc -V
  214. To create a 4-byte native floating point grid from the COARDS-compliant
  215. remote netCDF file AFR.nc:
  216. ::
  217. gmt grdconvert @AFR.nc -GAFR_bin.b4=bf -V
  218. To make a 2-byte short integer file, scale it by 10, subtract 32000,
  219. setting NaNs to -9999, do
  220. ::
  221. gmt grdconvert values.nc -Gshorts.i2=bs+s10+o-32000+n-9999 -V
  222. To create a Sun standard 8-bit rasterfile for a subset of the data file
  223. image.nc, assuming the range in image.nc is 0-1 and we need 0-255, run
  224. ::
  225. gmt grdconvert image.nc -R-60/-40/-40/-30 -Gimage.ras8=rb+s255 -V
  226. See Also
  227. --------
  228. :doc:`gmt.conf`,
  229. :doc:`gmt`,
  230. :doc:`grdmath`
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...