grdedit

grdedit(cmd0::String="", arg1=nothing, kwargs...)

keywords: GMT, Julia, grid edit

Modify header or content of a grid

Description

grdedit reads the header information in a binary 2-D grid file and replaces the information with values provided on the command line [if any]. As an option, global, geographical grids (with 360 degrees longitude range) can be rotated in the east-west direction, and individual nodal values can be replaced from a table of x, y, z values. grdedit only operates on files containing a grid header. Note: If it is important to retain the original data you should use outgrid to save the modified grid to a new file.

Required Arguments

ingrid : – A grid file name or a Grid type

Optional Arguments

  • A or adjust_inc : – adjust_inc=true
    If necessary, adjust the file's x_inc, y_inc to be compatible with its domain(or a new domain set with region). Older grid files (i.e., created prior to GMT 3.1) often had excessive slop in x_inc, y_inc and an adjustment is necessary. Newer files are created correctly.

  • E or flip : – flip=:a|:e|:h|:l|:r|:t|:v
    Transform the grid in one of six ways and (for l|r|t) interchange the x and y information:

    • flip=:a will flip the grid both horizontally and vertically,

    • flip=:e will exchange the x (longitude) and y (latitude) dimensions,

    • flip=:h will flip the grid horizontally (left-to-right),

    • flip=:l will rotate the grid 90 degrees counter-clockwise (left),

    • flip=:r will rotate the grid 90 degrees clockwise (right),

    • flip=:t will transpose the grid [Default],

    • flip=:v will flip the grid vertically (top-to-bottom).

    Incompatible with the other options (except outgrid).

  • G or save or outgrid or outfile : – outgrid=[=ID][+ddivisor][+ninvalid][+ooffset|a][+sscale|a][:driver[dataType][+coptions]]
    Give the name of the output grid file. Optionally, append =ID for writing a specific file format (See full description). The following modifiers are supported:

    • +d - Divide data values by given divisor [Default is 1].

    • +n - Replace data values matching invalid with a NaN.

    • +o - Offset data values by the given offset, or append a for automatic range offset to preserve precision for integer grids [Default is 0].

    • +s - Scale data values by the given scale, or append a for automatic scaling to preserve precision for integer grids [Default is 1].

Note1: Any offset is added before any scaling. +sa also sets +oa (unless overridden). To write specific formats via GDAL, use =gd and supply driver (and optionally dataType) and/or one or more concatenated GDAL -co options using +c. See the “Writing grids and images” cookbook section for more details.

Note2: This is optional and to be used only when saving the result directly on disk. Otherwise, just use the G = modulename(...) form.

Normally, grdedit will overwrite the existing grid with the modified grid. Use this option to write the modified grid to the file outgrid instead.

  • L or adjust_lon : – adjust_lon=true | adjust_lon="+n|+p"
    Adjust the longitude values in the grid (only applies to geographic grids). By default we will try to adjust west and east so that west >= -180 or east <= +180, but this depends on the range of the longitudes. Use adjust_lon="+n" to force negative longitude values and +p to force positive longitude values.

  • N or replace : – replace=table | replace="tablename"
    Use a Mx3 matrix with x,y,z values (or read them from file "tablename") and replace the corresponding nodal values in the grid with these values.

  • R or region or limits : – limits=(xmin, xmax, ymin, ymax) | limits=(BB=(xmin, xmax, ymin, ymax),) | limits=(LLUR=(xmin, xmax, ymin, ymax),units="unit") | ...more
    Specify the region of interest. More at limits. For perspective view view, optionally add zmin,zmax. This option may be used to indicate the range used for the 3-D axes. You may ask for a larger w/e/s/n region to have more room between the image and the axes.

  • S or wrap : – wrap=true
    For global, geographical grids only. Grid values will be shifted longitudinally according to the new borders given in region (if given, othersise use grid limits).

  • T or toggle_reg or toggle : – toggle=true
    Make necessary changes in the header to convert a gridline-registered grid to a pixel-registered grid, or vice-versa. Basically, gridline-registered grids will have their domain extended by half the x- and y-increments whereas pixel-registered grids will have their domain shrunk by the same amount. This is a non-destructive grid change; see Switching registrations.

  • V or verbose : – verbose=true | verbose=level
    Select verbosity level. More at verbose

  • bi or binary_in : – binary_in=??
    Select native binary format for primary table input. More at

  • di or nodata_in : – nodata_in=??
    Substitute specific values with NaN. More at

  • e or pattern : – pattern=??
    Only accept ASCII data records that contain the specified pattern. More at

  • f or colinfo : – colinfo=??
    Specify the data types of input and/or output columns (time or geographical data). More at

  • h or header : – header=??
    Specify that input and/or output file(s) have n header records. More at

  • i or incol or incols : – incol=col_num | incol="opts"
    Select input columns and transformations (0 is first column, t is trailing text, append word to read one word only). More at incol

Geographical And Time Coordinates

When the output grid type is netCDF, the coordinates will be labeled "longitude", "latitude", or "time" based on the attributes of the input data or grid (if any) or on the colinfo or region options. For example, both colinfo="0x" colinfo="1t" and region="90w/90e/0t/3t" will result in a longitude/time grid. When the x, y, or z coordinate is time, it will be stored in the grid as relative time since epoch as specified by TIME_UNIT and TIME_EPOCH in the gmt.conf file or on the command line. In addition, the unit attribute of the time variable will indicate both this unit and epoch.

Examples

Let us assume the file data.nc covers the area 300/310/10/30. We want to change the boundaries from geodetic longitudes to geographic and put a new title in the header. We accomplish this by:

grdedit("data.nc", region=(-60,-50,10,30), D="+t\"Gravity Anomalies\"")

The grid world.nc has the limits 0/360/-72/72. To shift the data so that the limits would be -180/180/-72/72, use:

grdedit world.nc -R-180/180/-72/72 -S

The file junk.nc was created prior to GMT 3.1 with incompatible region and increment arguments. To reset the x- and y-increments we run:

grdedit("junk.nc", adjust_inc=true)

The file junk.nc was created prior to GMT 4.1.3 and does not contain the required information to indicate that the grid is geographic. To add this information, run:

grdedit("junk.nc", colinfo=:g)

To rotate the grid oblique.nc 90 degrees counter-clockwise and write out the rotated grid to a new file, run::

gmt grdedit oblique.nc -El -Goblique_rot.nc

To ensure that the grid depths.nc only has positive longitude values, run::

gmt grdedit depths.nc -L+p

The grid bad.nc has latitude as x-coordinates an longitude as y-coordinates. We can exchange the two dimension by running::

gmt grdedit bad.nc -Ee -Gnew.nc

Notes

This module is not a general editor for netCDF files. If your netCDF file contains more than one 2-D (or higher dimension) data layer, then only the selected layer will be written out if changes are requested. Likewise, if you have additional netCDF attributes then those will also be lost in any revised output.

See Also

:doc:grd2xyz, :doc:grdfill, :doc:grdinfo, :doc:xyz2grd