.\" Man page generated from reStructuredText. . .TH "IMG2GRD" "1gmt" "Jan 10, 2019" "5.4.5" "GMT" .SH NAME img2grd \- Extract subset of img file in Mercator or Geographic format . .nr rst2man-indent-level 0 . .de1 rstReportMargin \\$1 \\n[an-margin] level \\n[rst2man-indent-level] level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] - \\n[rst2man-indent0] \\n[rst2man-indent1] \\n[rst2man-indent2] .. .de1 INDENT .\" .rstReportMargin pre: . RS \\$1 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] . nr rst2man-indent-level +1 .\" .rstReportMargin post: .. .de UNINDENT . RE .\" indent \\n[an-margin] .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] .nr rst2man-indent-level -1 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. .SH SYNOPSIS .sp \fBimg2grd\fP \fIimgfile\fP \fB\-G\fP\fIgrdfile\fP \fB\-R\fP\fIregion\fP \fB\-T\fP\fItype\fP [ \fB\-C\fP ] [ \fB\-D\fP[\fIminlat/maxlat\fP] ] [ \fB\-E\fP ] [ \fB\-I\fP\fIminutes\fP ] [ \fB\-M\fP ] [ \fB\-N\fP\fInavg\fP ] [ \fB\-S\fP[\fIscale\fP] ] [ \fB\-V\fP[\fIlevel\fP] ] [ \fB\-W\fP\fImaxlon\fP ] [ \fB\-n\fPflags ] .sp \fBNote:\fP No space is allowed between the option flag and the associated arguments. .SH DESCRIPTION .sp \fBimg2grd\fP reads an img format file, extracts a subset, and writes it to a grid file. The \fB\-M\fP option dictates whether or not the Spherical Mercator projection of the img file is preserved or if a Geographic grid should be written by undoing the Mercator projection. If geographic grid is selected you can also request a resampling onto the exact \fB\-R\fP given. .SH REQUIRED ARGUMENTS .INDENT 0.0 .TP .B \fIimgfile\fP A Mercator img format file such as the marine gravity or seafloor topography fields estimated from satellite altimeter data by Sandwell and Smith. If the user has set an environment variable \fB$GMT_DATADIR\fP, then \fBimg2grd\fP will try to find \fIimgfile\fP in \fB$GMT_DATADIR\fP; else it will try to open \fIimgfile\fP directly. .UNINDENT .INDENT 0.0 .TP \fB\-G\fP\fIgrdfile\fP \fIgrdfile\fP is the name of the output grid file. .UNINDENT .INDENT 0.0 .TP \fB\-R\fP\fIwest\fP/\fIeast\fP/\fIsouth\fP/\fInorth\fP[/\fIzmin\fP/\fIzmax\fP][\fB+r\fP][\fB+u\fP\fIunit\fP] \fIwest\fP, \fIeast\fP, \fIsouth\fP, and \fInorth\fP specify the region of interest, and you may specify them in decimal degrees or in [±]dd:mm[:ss.xxx][\fBW\fP|\fBE\fP|\fBS\fP|\fBN\fP] format Append \fB+r\fP if lower left and upper right map coordinates are given instead of w/e/s/n. The two shorthands \fB\-Rg\fP and \fB\-Rd\fP stand for global domain (0/360 and \-180/+180 in longitude respectively, with \-90/+90 in latitude). Alternatively for grid creation, give \fBR\fP\fIcode\fP\fIlon\fP/\fIlat\fP/\fInx\fP/\fIny\fP, where \fIcode\fP is a 2\-character combination of L, C, R (for left, center, or right) and T, M, B for top, middle, or bottom. e.g., BL for lower left. This indicates which point on a rectangular region the \fIlon\fP/\fIlat\fP coordinate refers to, and the grid dimensions \fInx\fP and \fIny\fP with grid spacings via \fB\-I\fP is used to create the corresponding region. Alternatively, specify the name of an existing grid file and the \fB\-R\fP settings (and grid spacing, if applicable) are copied from the grid. Appending \fB+u\fP\fIunit\fP expects projected (Cartesian) coordinates compatible with chosen \fB\-J\fP and we inversely project to determine actual rectangular geographic region. For perspective view (\fB\-p\fP), optionally append /\fIzmin\fP/\fIzmax\fP\&. In case of perspective view (\fB\-p\fP), a z\-range (\fIzmin\fP, \fIzmax\fP) can be appended to indicate the third dimension. This needs to be done only when using the \fB\-Jz\fP option, not when using only the \fB\-p\fP option. In the latter case a perspective view of the plane is plotted, with no third dimension. .UNINDENT .SH OPTIONAL ARGUMENTS .INDENT 0.0 .TP \fB\-C\fP Set the x and y Mercator coordinates relative to projection center [Default is relative to lower left corner of grid]. Requires \fB\-M\fP\&. .UNINDENT .INDENT 0.0 .TP \fB\-D\fP[\fIminlat/maxlat\fP] Use the extended latitude range \-80.738/+80.738. Alternatively, append \fIminlat/maxlat\fP as the latitude extent of the input img file. [Default is \-72.006/72.006]. Not usually required since we can determine the extent from inspection of the file size. .UNINDENT .INDENT 0.0 .TP \fB\-E\fP Can be used when \fB\-M\fP is not set to force the final grid to have the exact same region as requested with \fB\-R\fP\&. By default, the final region is a direct projection of the original Mercator region and will typically extend slightly beyond the requested latitude range, and furthermore the grid increment in latitude does not match the longitude increment. However, the extra resampling introduces small interpolation errors and should only be used if the output grid must match the requested region and have x_inc = y_inc. In this case the region set by \fB\-R\fP must be given in multiples of the increment (.e.g, \fB\-R\fP0/45/45/72). .UNINDENT .INDENT 0.0 .TP \fB\-I\fP Indicate \fIminutes\fP as the width of an input img pixel in minutes of longitude. [Default is 2.0]. Not usually required since we can determine the pixel size from inspection of the size. .UNINDENT .INDENT 0.0 .TP \fB\-M\fP Output a Spherical Mercator grid [Default is a geographic lon/lat grid]. The Spherical Mercator projection of the img file is preserved, so that the region \fB\-R\fP set by the user is modified slightly; the modified region corresponds to the edges of pixels [or groups of \fInavg\fP pixels]. The grid file header is set so that the x and y axis lengths represent distance from the west and south edges of the image, measured in user default units, with \fB\-Jm\fP1 and the adjusted \fB\-R\fP\&. By setting the default \fBPROJ_ ELLIPSOID\fP = Sphere, the user can make overlays with the adjusted \fB\-R\fP so that they match. See \fBEXAMPLES\fP below. The adjusted \fB\-R\fP is also written in the grid header remark, so it can be found later. See \fB\-C\fP to set coordinates relative to projection center. .UNINDENT .INDENT 0.0 .TP \fB\-N\fP\fInavg\fP Average the values in the input img pixels into \fInavg\fP by \fInavg\fP squares, and create one output pixel for each such square. If used with \fB\-T\fP\fI3\fP it will report an average constraint between 0 and 1. If used with \fB\-T\fP\fI2\fP the output will be average data value or NaN according to whether average constraint is > 0.5. \fInavg\fP must evenly divide into the dimensions of the imgfile in pixels. [Default \fI1\fP does no averaging]. .UNINDENT .INDENT 0.0 .TP \fB\-S\fP[\fIscale\fP] Multiply the img file values by \fIscale\fP before storing in grid file. [Default is 1.0]. For recent img files: img topo files are stored in (corrected) meters [\fB\-S\fP1]; free\-air gravity files in mGal*10 [\fB\-S\fP0.1 to get mGal]; vertical deflection files in micro\-radians*10 [\fB\-S\fP0.1 to get micro\-radians], vertical gravity gradient files in Eotvos*10 [\fB\-S\fP0.1 to get Eotvos, or \fB\-S\fP0.01 to get mGal/km]). If no \fIscale\fP is given we try to determine the scale by examining the file name for clues. .UNINDENT .INDENT 0.0 .TP \fB\-T\fP\fItype\fP \fItype\fP handles the encoding of constraint information. \fItype\fP = 0 indicates that no such information is encoded in the img file (used for pre\-1995 versions of the gravity data) and gets all data. \fItype\fP > 0 indicates that constraint information is encoded (1995 and later (current) versions of the img files) so that one may produce a grid file as follows: \fB\-T\fP\fI1\fP gets data values at all points, \fB\-T\fP\fI2\fP gets data values at constrained points and NaN at interpolated points; \fB\-T\fP\fI3\fP gets 1 at constrained points and 0 at interpolated points [Default is 1]. .UNINDENT .INDENT 0.0 .TP \fB\-V\fP[\fIlevel\fP] (more ...) Select verbosity level [c]. Particularly recommended here, as it is helpful to see how the coordinates are adjusted. .UNINDENT .INDENT 0.0 .TP \fB\-W\fP\fImaxlon\fP Indicate \fImaxlon\fP as the maximum longitude extent of the input img file. Versions since 1995 have had \fImaxlon\fP = 360.0, while some earlier files had \fImaxlon\fP = 390.0. [Default is 360.0]. .UNINDENT .INDENT 0.0 .TP \fB\-n\fP[\fBb\fP|\fBc\fP|\fBl\fP|\fBn\fP][\fB+a\fP][\fB+b\fP\fIBC\fP][\fB+c\fP][\fB+t\fP\fIthreshold\fP] (more ...) Select interpolation mode for grids. .UNINDENT .INDENT 0.0 .TP \fB\-^\fP or just \fB\-\fP Print a short message about the syntax of the command, then exits (NOTE: on Windows just use \fB\-\fP). .TP \fB\-+\fP or just \fB+\fP Print an extensive usage (help) message, including the explanation of any module\-specific option (but not the GMT common options), then exits. .TP \fB\-?\fP or no arguments Print a complete usage (help) message, including the explanation of all options, then exits. .UNINDENT .SH GEOGRAPHIC EXAMPLES .sp The \fB\-M\fP option should be excluded if you need the output grid to be in geographic coordinates. To extract data in the region \fB\-R\fP\-40/40/\-70/\-30 from \fIworld_grav.img.7.2\fP and reproject to yield geographic coordinates, you can try .INDENT 0.0 .INDENT 3.5 .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C img2grd world_grav.img.16.1 \-Gmerc_grav.nc \-R\-40/40/\-70/\-30 \-V .ft P .fi .UNINDENT .UNINDENT .UNINDENT .UNINDENT .sp Because the latitude spacing in the img file is equidistant in Mercator units, the resulting grid will not match the specified \fB\-R\fP exactly, and the latitude spacing will not equal the longitude spacing. If you need an exact match with your \fB\-R\fP and the same spacing in longitude and latitude, use the \fB\-E\fP option: .INDENT 0.0 .INDENT 3.5 .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C img2grd world_grav.img.16.1 \-Gmerc_grav.nc \-R\-40/40/\-70/\-30 \-E \-V .ft P .fi .UNINDENT .UNINDENT .UNINDENT .UNINDENT .SH MERCATOR EXAMPLES .sp Since the img files are in a Mercator projection, you should NOT extract a geographic grid if your plan is to make a Mercator map. If you did that you end of projecting and reprojection the grid, losing short\-wavelength detail. Better to use \fB\-M\fP and plot the grid using a linear projection with the same scale as the desired Mercator projection (see GMT Example 29). To extract data in the region \fB\-R\fP\-40/40/\-70/\-30 from \fIworld_grav.img.7.2\fP, run .INDENT 0.0 .INDENT 3.5 .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C gmt img2grd \-M world_grav.img.7.2 \-Gmerc_grav.nc \-R\-40/40/\-70/\-30 \-V .ft P .fi .UNINDENT .UNINDENT .UNINDENT .UNINDENT .sp Note that the \fB\-V\fP option tells us that the range was adjusted to \fB\-R\fP\-40/40/\-70.0004681551/\-29.9945810754. For scripting purposes we can extract this original region string using grdinfo \fB\-Ii\fP\&. Furthermore, we can also use grdinfo to find that the grid file header shows its region to be \fB\-R\fP0/80/0/67.9666667. This is the range of x,y we will get from a Spherical Mercator projection using \fB\-R\fP\-40/40/\-70.0004681551/\-29.9945810754 and \fB\-Jm\fP1. Thus, to take ship.lonlatgrav and use it to sample the merc_grav.nc, we can do this: .INDENT 0.0 .INDENT 3.5 .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C gmt set PROJ_ELLIPSOID Sphere gmt mapproject \-R\-40/40/\-70.0004681551/\-29.9945810754 \-Jm1i ship.lonlatgrav | \e gmt grdtrack \-Gmerc_grav.nc | gmt mapproject \e \-R\-40/40/\-70.0004681551/\-29.9945810754 \-Jm1i \-I > ship.lonlatgravsat .ft P .fi .UNINDENT .UNINDENT .UNINDENT .UNINDENT .sp It is recommended to use the above method of projecting and unprojecting the data in such an application, because then there is only one interpolation step (in grdtrack). If one first tries to convert the grid file to lon,lat and then sample it, there are two interpolation steps (in conversion and in sampling). .sp To make a lon,lat grid from the above grid we can use .INDENT 0.0 .INDENT 3.5 .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C gmt grdproject merc_grav.nc \-R\-40/40/\-70.0004681551/\-29.9945810754 \-Jm1i \-I \-D2m \-Ggrav.nc .ft P .fi .UNINDENT .UNINDENT .UNINDENT .UNINDENT .sp In some cases this will not be easy as the \fB\-R\fP in the two coordinate systems may not align well. When this happens, we can also use (in fact, it may be always better to use) .INDENT 0.0 .INDENT 3.5 .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C gmt grd2xyz merc_grav.nc | gmt mapproject \e \-R\-40/40/\-70.0004681551/\-29.994581075 \-Jm1i \-I | \e gmt surface \-R\-40/40/\-70/70 \-I2m \-Ggrav.nc .ft P .fi .UNINDENT .UNINDENT .UNINDENT .UNINDENT .sp To make a Mercator map of the above region, suppose our gmt.conf value for PROJ_LENGTH_UNIT is inch. Then since the above merc_grav.nc file is projected with \fB\-Jm\fP1i it is 80 inches wide. We can make a map 8 inches wide by using \fB\-Jx\fP0.1i on any map programs applied to this grid (e.g., grdcontour, grdimage, grdview), and then for overlays which work in lon,lat (e.g., psxy, pscoast) we can use the above adjusted \fB\-R\fP and \fB\-Jm\fP0.1 to get the two systems to match up. .sp However, we can be smarter than this. Realizing that the input img file had pixels 2.0 minutes wide (or checking the nx and ny with grdinfo merc_grav.nc) we realize that merc_grav.nc used the full resolution of the img file and it has 2400 by 2039 pixels, and at 8 inches wide this is 300 pixels per inch. We decide we do not need that many and we will be satisfied with 100 pixels per inch, so we want to average the data into 3 by 3 squares. (If we want a contour plot we will probably choose to average the data much more (e.g., 6 by 6) to get smooth contours.) Since 2039 isn\(aqt divisible by 3 we will get a different adjusted \fB\-R\fP this time: .INDENT 0.0 .INDENT 3.5 .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C gmt img2grd \-M world_grav.img.7.2 \-Gmerc_grav_2.nc \-R\-40/40/\-70/\-30 \-N3 \-V .ft P .fi .UNINDENT .UNINDENT .UNINDENT .UNINDENT .sp This time we find the adjusted region is \fB\-R\fP\-40/40/\-70.023256525/\-29.9368261101 and the output is 800 by 601 pixels, a better size for us. Now we can create an artificial illumination file for this using grdgradient: .INDENT 0.0 .INDENT 3.5 .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C gmt grdgradient merc_grav_2.nc \-Gillum.nc \-A0/270 \-Ne0.6 .ft P .fi .UNINDENT .UNINDENT .UNINDENT .UNINDENT .sp and if we also have a CPT called "grav.cpt" we can create a color shaded relief map like this: .INDENT 0.0 .INDENT 3.5 .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C gmt grdimage merc_grav_2.nc \-Iillum.nc \-Cgrav.cpt \-Jx0.1i \-K > map.ps gmt psbasemap \-R\-40/40/\-70.023256525/\-29.9368261101 \-Jm0.1i \-Ba10 \-O >> map.ps .ft P .fi .UNINDENT .UNINDENT .UNINDENT .UNINDENT .sp Suppose you want to obtain only the constrained data values from an img file, in lat/lon coordinates. Then run \fBimg2grd\fP with the \fB\-T\fP2 option, use grd2xyz to dump the values, pipe through grep \-v NaN to eliminate NaNs, and pipe through mapproject with the inverse projection as above. .SH SEE ALSO .sp gmt .SH COPYRIGHT 2019, P. Wessel, W. H. F. Smith, R. Scharroo, J. Luis, and F. Wobbe .\" Generated by docutils manpage writer. .