grdimage¶
Project and plot grids or images
Synopsis¶
gmt grdimage grd_z | img | grd_r grd_g grd_b [ -Aout_img[=driver] ] [ -B[p|s]parameters ] [ -Ccpt ] [ -D[r] ] [ -E[i|dpi] ] -Jparameters [ -Gcolor[+b|+f] ] [ -I[intensfile|intensity|modifiers] ] [ -Jz|-Zparameters ] [ -K ] [ -M ] [ -N ] [ -O ] [ -P ] [ -Q ] [ -Rwest/east/south/north[/zmin/zmax][+r][+uunit] ] [ -U[stamp] ] [ -V[level] ] [ -X[a|c|f|r][xshift] ] [ -Y[a|c|f|r][yshift] ] [ -fflags ] [ -nflags ] [ -pflags ] [ -ttransp ] [ -x[[-]n] ] [ --PAR=value ]
Note: No space is allowed between the option flag and the associated arguments.
Description¶
grdimage reads one 2-D grid file and produces a gray-shaded (or colored) map by plotting rectangles centered on each grid node and assigning them a gray-shade (or color) based on the z-value. Alternatively, grdimage reads three 2-D grid files with the red, green, and blue components directly (all must be in the 0-255 range). Optionally, illumination may be added by providing a file with intensities in the (-1,+1) range or instructions to derive intensities from the input data grid. Values outside this range will be clipped. Such intensity files can be created from the grid using grdgradient and, optionally, modified by grdmath or grdhisteq. A third alternative is available when GMT is build with GDAL support. Pass img which can be an image file (geo-referenced or not). In this case the images can optionally be illuminated with the file provided via the -I option. Here, if image has no coordinates then those of the intensity file will be used.
When using map projections, the grid is first resampled on a new rectangular grid with the same dimensions. Higher resolution images can be obtained by using the -E option. To obtain the resampled value (and hence shade or color) of each map pixel, its location is inversely projected back onto the input grid after which a value is interpolated between the surrounding input grid values. By default bi-cubic interpolation is used. Aliasing is avoided by also forward projecting the input grid nodes. If two or more nodes are projected onto the same pixel, their average will dominate in the calculation of the pixel value. Interpolation and aliasing is controlled with the -n option.
The -R option can be used to select a map region larger or smaller than that implied by the extent of the grid.
Required Arguments¶
- grd_z | img | grd_r grd_g grd_b
2-D gridded data set (or red, green, blue grids) or image to be imaged (See GRID FILE FORMATS below.)
- -Jparameters (more …)
Select map projection.
Optional Arguments¶
- -Aout_img[=driver]
Save an image in a raster format instead of PostScript. Use extension .ppm for a Portable Pixel Map format which is the only raster format GMT can natively write. For GMT installations configured with GDAL support there are more choices: Append out_img to select the image file name and extension. If the extension is one of .bmp, .gif, .jpg, .png, or .tif then no driver information is required. For other output formats you must append the required GDAL driver. The driver is the driver code name used by GDAL; see your GDAL installation’s documentation for available drivers. Append a +coptions string where options is a list of one or more concatenated number of GDAL -co options. For example, to write a GeoPDF with the TerraGo format use =PDF+cGEO_ENCODING=OGC_BP. Notes: (1) If a tiff file (.tif) is selected then we will write a GeoTiff image if the GMT projection syntax translates into a PROJ syntax, otherwise a plain tiff file is produced. (2) Any vector elements will be lost.
- -B[p|s]parameters (more …)
Set map boundary frame and axes attributes.
- -C[cpt|master[+h[hinge]][+izinc][+u|Uunit] |color1,color2[,color3,…]]
Name of the CPT. Alternatively, supply the name of a GMT color master dynamic CPT [turbo, but we use geo for @earth_relief and srtm for @srtm_relief data] to automatically determine a continuous CPT from the grid’s z-range; you may round the range to the nearest multiple of zinc by adding +izinc. If given a GMT Master soft-hinge CPT (see Of Colors and Color Legends) then you can enable the hinge at data value hinge [0] via +h, whereas for hard-hinge CPTs you can adjust the location of the hinge [0]. For other CPTs, you may convert their z-values from meter to another distance unit (append +Uunit) or from another unit to meter (append +uunit), with unit taken from e|f|k|M|n|u. Yet another option is to specify -Ccolor1,color2[,color3,…] to build a linear continuous CPT from those colors automatically. In this case colorn can be a r/g/b triplet, a color name, or an HTML hexadecimal color (e.g. #aabbcc). If no argument is given to -C then under modern mode we select the current CPT.
- -D[r]
GMT will automatically detect standard image files (Geotiff, TIFF, JPG, PNG, GIF, etc.) and will read those via GDAL. For very obscure image formats you may need to explicitly set -D, which specifies that the grid is in fact an image file to be read via GDAL. Append r to assign the region specified by -R to the image. For example, if you have used -Rd then the image will be assigned a global domain. This mode allows you to project a raw image (an image without referencing coordinates).
- -E[i|dpi]
Sets the resolution of the projected grid that will be created if a map projection other than Linear or Mercator was selected [100]. By default, the projected grid will be of the same size (rows and columns) as the input file. Specify i to use the PostScript image operator to interpolate the image at the device resolution.
- -Gcolor[+b|f]
This option only applies when a resulting 1-bit image otherwise would consist of only two colors: black (0) and white (255). If so, this option will instead use the image as a transparent mask and paint the mask with the given color. Append +b to paint the background pixels (1) or +f for the foreground pixels [Default].
- -I[intensfile|intensity|modifiers]
Gives the name of a grid file with intensities in the (-1,+1) range, or a constant intensity to apply everywhere (affects the ambient light). Alternatively, derive an intensity grid from the input data grid grd_z via a call to grdgradient; append +aazimuth, +nargs, and +mambient to specify azimuth, intensity, and ambient arguments for that module, or just give +d to select the default arguments (+a-45+nt1+m0). If you want a more specific intensity scenario then run grdgradient separately first. If we should derive intensities from another file than grd_z, specify the file [Default is no illumination].
- -M
Force conversion to monochrome image using the (television) YIQ transformation. Cannot be used with -Q.
- -N
Do not clip the image at the map boundary (only relevant for non-rectangular maps).
- -Q
Make grid nodes with z = NaN transparent, using the color-masking feature in PostScript Level 3 (the PS device must support PS Level 3).
- -Rxmin/xmax/ymin/ymax[+r][+uunit] (more …)
Specify the region of interest.
For perspective view -p, optionally append /zmin/zmax. (more …) You may ask for a larger w/e/s/n region to have more room between the image and the axes. A smaller region than specified in the grid file will result in a subset of the grid [Default is the region given by the grid file].
- -U[label][+c][+jjust][+odx/dy] (more …)
Draw GMT time stamp logo on plot.
- -V[level] (more …)
Select verbosity level [w].
-X[a|c|f|r][xshift]
- -Y[a|c|f|r][yshift] (more …)
Shift plot origin.
- -f[i|o]colinfo (more …)
Specify data types of input and/or output columns.
- -n[b|c|l|n][+a][+bBC][+c][+tthreshold] (more …)
Select interpolation mode for grids.
- -p[x|y|z]azim[/elev[/zlevel]][+wlon0/lat0[/z0]][+vx0/y0] (more …)
Select perspective view.
- -t[transp] (more …)
Set transparency level in percent.
- -x[[-]n] (more …)
Limit number of cores used in multi-threaded algorithms (OpenMP required).
- -^ or just -
Print a short message about the syntax of the command, then exit (NOTE: on Windows just use -).
- -+ or just +
Print an extensive usage (help) message, including the explanation of any module-specific option (but not the GMT common options), then exit.
- -? or no arguments
Print a complete usage (help) message, including the explanation of all options, then exit.
- --PAR=value
Temporarily override a GMT default setting; repeatable. See gmt.conf for parameters.
Grid File Formats¶
By default GMT writes out grid as single precision floats in a COARDS-complaint netCDF file format. However, GMT is able to produce grid files in many other commonly used grid file formats and also facilitates so called “packing” of grids, writing out floating point data as 1- or 2-byte integers. (more …)
Global Relief Datasets¶
By using grids named @earth_relief_res[_reg] we download global relief grids (or only the needed tiles) from the GMT server. Here, rr is a 2-digit integer specifying the grid resolution in the unit u, where u is either d, m or s for arc degree, arc minute or arc second, respectively. Optionally, you can append _g or _p to specifically get the gridline-registered or pixel-registered version (if they both exist). If reg is not specified we will return the pixel-registered version unless only the gridline-registered file is available. The following codes for rru and the optional reg are supported. These grids are saved in folders under your ~/.gmt/server/earth directory. Files and tiles are only downloaded once and are later accessed from ~/.gmt. You can clear your data via gmt clear data and you can pre-download data via gmt gmtget. Dimensions are listed for pixel-registered grids; gridline-registered grids increment dimensions by one.
Code |
Dimensions |
Reg |
Size |
Description |
---|---|---|---|---|
01d |
360 x 180 |
g,p |
128 KB |
1 arc degree global relief (SRTM15+V2.1 @ 111 km) |
30m |
720 x 360 |
g,p |
435 KB |
30 arc minute global relief (SRTM15+V2.1 @ 55 km) |
20m |
1080 x 540 |
g,p |
918 KB |
20 arc minute global relief (SRTM15+V2.1 @ 37 km) |
15m |
1440 x 720 |
g,p |
1.6 MB |
15 arc minute global relief (SRTM15+V2.1 @ 28 km) |
10m |
2160 x 1080 |
g,p |
3.4 MB |
10 arc minute global relief (SRTM15+V2.1 @ 18 km) |
06m |
3600 x 1800 |
g,p |
8.8 MB |
6 arc minute global relief (SRTM15+V2.1 @ 10 km) |
05m |
4320 x 2160 |
g,p |
13 MB |
5 arc minute global relief (SRTM15+V2.1 @ 9 km) |
04m |
5400 x 2700 |
g,p |
19 MB |
4 arc minute global relief (SRTM15+V2.1 @ 7.5 km) |
03m |
7200 x 3600 |
g,p |
33 MB |
3 arc minute global relief (SRTM15+V2.1 @ 5.6 km) |
02m |
10800 x 5400 |
g,p |
71 MB |
2 arc minute global relief (SRTM15+V2.1 @ 3.7 km) |
01m |
21600 x 10800 |
g,p |
258 MB |
1 arc minute global relief (SRTM15+V2.1 @ 1.9 km) |
30s |
43200 x 21600 |
g,p |
935 MB |
30 arc second global relief (SRTM15+V2.1 @ 1.0 km) |
15s |
86400 x 43200 |
p |
3.2 GB |
15 arc second global relief (SRTM15+V2.1) |
03s |
432000 x 216000 |
g |
6.8 GB |
3 arc second global relief (SRTM3S) |
01s |
1296000 x 432000 |
g |
41 GB |
1 arc second global relief (SRTM1S) |
Classic Mode Arguments¶
These options are used to manipulate the building of layered GMT PostScript plots in classic mode. They are not available when using GMT modern mode.
- -K (more …)
Do not finalize the PostScript plot.
- -O (more …)
Append to existing PostScript plot.
- -P (more …)
Select “Portrait” plot orientation.
Imaging Grids With Nans¶
Be aware that if your input grid contains patches of NaNs, these patches can become larger as a consequence of the resampling that must take place with most map projections. Because grdimage uses the PostScript colorimage operator, for most non-linear projections we must resample your grid onto an equidistant rectangular lattice. If you find that the NaN areas are not treated adequately, consider (a) use a linear projection, or (b) use grdview -Ts instead.
Consequences of grid resampling¶
Except for Cartesian cases, we need to resample your geographic grid onto an equidistant projected grid. In doing so various algorithms come into play that projects data from one lattice to another while avoiding anti-aliasing, leading to possible distortions. One expected effect of resampling with splines is the tendency for the new resampled grid to slightly exceed the global min/max limits of the original grid. If this is coupled with tight CPT limits you may find that some map areas may show up with fore- or background color due to the resampling. In that case you have two options: (1) Modify your CPT to fit the resampled extrema (reported with -V) or (2) Impose clipping of resampled values so they do not exceed the input min/max values (add +c to your -n option).
Image formats recognized¶
We automatically recognize image formats via their magic bytes. For formats that could contain either an image of a data set (e.g., geotiff) we determine which case it is and act accordingly. If your favorite image format is not automatically detected then please let us know its magic bytes so we can add it.
Examples¶
Note: Below are some examples of valid syntax for this module.
The examples that use remote files (file names starting with @
)
can be cut and pasted into your terminal for testing.
Other commands requiring input files are just dummy examples of the types
of uses that are common but cannot be run verbatim as written.
For a quick-and-dirty illuminated color map of the data in the file stuff.nc, with the maximum map dimension limited to be 6 inches, try
gmt grdimage stuff.nc -JX6i+ -I+d -P > quick.ps
To gray-shade the file hawaii_grav.nc with shades given in shades.cpt on a Lambert map at 1.5 cm/degree along the standard parallels 18 and 24, and using 1 degree tickmarks:
gmt grdimage hawaii_grav.nc -Jl18/24/1.5c -Cshades.cpt -B1 -P > hawaii_grav_image.ps
To create an illuminated color PostScript plot of the gridded data set image.nc, using the intensities provided by the file intens.nc, and color levels in the file colors.cpt, with linear scaling at 10 inch/x-unit, tickmarks every 5 units:
gmt grdimage image.nc -Jx10i -Ccolors.cpt -Iintens.nc -B5 -P > image.ps
To create an false color PostScript plot from the three grid files red.nc, green.nc, and blue.nc, with linear scaling at 10 inch/x-unit, tickmarks every 5 units:
gmt grdimage red.nc green.nc blue.nc -Jx10i -B5 -P > rgbimage.ps
When GDAL support is built in: To create a sinusoidal projection of a remotely located Jessica Rabbit
gmt grdimage -JI15c -Rd http://larryfire.files.wordpress.com/2009/07/untooned_jessicarabbit.jpg -P > jess.ps
See Also¶
gmt, gmt.conf, grd2kml, grdcontour, grdview, grdgradient, grdhisteq