blockmedian

Block average (x,y,z) data tables by median estimation

Synopsis

gmt blockmedian [ table ] -Iincrement -Rregion [ -Afields ] [ -C ] [ -E[b|r|s[+l|h]] ] [ -G[grdfile] ] [ -Q ] [ -Tquantile ] [ -V[level] ] [ -W[i|o][+s|w] ] [ -aflags ] [ -bbinary ] [ -dnodata[+ccol] ] [ -eregexp ] [ -fflags ] [ -hheaders ] [ -iflags ] [ -oflags ] [ -qflags ] [ -rreg ] [ -wflags ] [ -:[i|o] ] [ --PAR=value ]

Note: No space is allowed between the option flag and the associated arguments.

Description

blockmedian reads arbitrarily located (x,y,z) triplets [or optionally weighted quadruplets (x,y,z,w)] from standard input [or table] and writes to standard output a median position and value for every non-empty block in a grid region defined by the -R and -I arguments. See -G for writing gridded output directly. Either blockmean, blockmedian, or blockmode should be used as a pre-processor before running surface to avoid aliasing short wavelengths. These routines are also generally useful for decimating or averaging (x,y,z) data. You can modify the precision of the output format by editing the FORMAT_FLOAT_OUT parameter in your gmt.conf file, or you may choose binary input and/or output to avoid loss of precision.

Required Arguments

table

3 (or 4, see -W) column ASCII data table file(s) (or binary, see -bi) holding (x,y,z[,w]) data values, where [w] is an optional weight for the data. If no file is specified, blockmedian will read from standard input.

-Ix_inc[+e|n][/y_inc[+e|n]]

Set the grid spacing as x_inc [and optionally y_inc].

Geographical (degrees) coordinates: Optionally, append an increment unit. Choose among:

  • d - Indicate arc degrees

  • m - Indicate arc minutes

  • s - Indicate arc seconds

If one of e (meter), f (foot), k (km), M (mile), n (nautical mile) or u (US survey foot), the the increment will be converted to the equivalent degrees longitude at the middle latitude of the region (the conversion depends on PROJ_ELLIPSOID). If y_inc is not given or given but set to 0 it will be reset equal to x_inc; otherwise it will be converted to degrees latitude.

All coordinates: The following modifiers are supported:

  • +e - Slightly adjust the max x (east) or y (north) to fit exactly the given increment if needed [Default is to slightly adjust the increment to fit the given domain].

  • +n - Define the number of nodes rather than the increment, in which case the increment is recalculated from the number of nodes, the registration (see GMT File Formats), and the domain. Note: If -Rgrdfile is used then the grid spacing and the registration have already been initialized; use -I and -R to override these values.

-Rxmin/xmax/ymin/ymax[+r][+uunit]

Specify the region of interest. (See full description) (See cookbook information).

Optional Arguments

-Afields

Select which fields to write to individual grids. Requires -G. Append the codes for available fields: z (the median data z, but see -T), s (the L1 scale of the median), l (lowest value), q25 (the 25% quartile), q75 (the 75% quartile), h (highest value), and w (the output weight; requires -W). Note s|l|h requires -E, while l|q25|q75|h requires -Eb, and Es|r cannot be used. [Default is just z].

-C

Use the center of the block as the output location [Default uses the median x and median y as location (but see -Q)].

-E[b|r|s[+l|h]]

Provide Extended reporting beyond the default x,y,z[,w]. One of several directives affects what the extended output record contains. In all cases, see -W for appending weights w to the output record:

  • b: Write output suitable for box-and-whisker plots. Output will include x,y,z,l,q25,q75,h[,w], where q25 and q75 are the 25% and 75% quantiles, respectively.

  • r: Append the record number associated with the median value. If tied then report the record number of the higher of the two values (i.e., +h is the default). Append +l to instead report the record number of the lower median value.

  • s: Append the source id associated with the median value. We expect input records of the form x,y,z[,w],sid, where sid is an unsigned integer source id. If tied then report the source id of the higher of the two median values (i.e., +h is the default). Append +l to instead report the source id of the lower median value.

If no directive is given then we compute s, the L1 scale of the median, i.e., 1.4826 * median absolute deviation [MAD]), l, the lowest value, and h, the highest value for each block. Output order becomes x,y,z,s,l,h[,w]. Note: -E may be repeated so that both -Er|s[+l|h] and -E[b] can be specified.

-Ggrdfile

Write one or more fields directly to grids; no table data are written to standard output. If more than one fields are specified via -A then grdfile must contain the format flag %s so that we can embed the field code in the file names. Note: Options -C and -Q are irrelevant and not allowed.

-Q

(Quicker) Finds median z and (x,y) at that the median z [Default finds median x, median y independent of z]. Also see -C.

-Tquantile

Sets the quantile of the distribution to be returned [Default is 0.5 which returns the median z]. Here, 0 < quantile < 1.

-V[level]

Select verbosity level [w]. (See full description) (See cookbook information).

-W[i|o][+s|w]

Compute weighted results. Unweighted input and output have 3 columns x,y,z; weighted i/o has 4 columns x,y,z,w. Weights can be used in input to construct weighted median values for each block. Weight sums can be reported to output for later combining several runs, etc. Use -W for weighted i/o, -Wi for weighted input only, and -Wo for weighted output only [Default uses unweighted i/o]. If your weights are actually uncertainties (one sigma) then append +s and we compute weight = 1/sigma. Otherwise (or via +w) we use the weights directly.

-a[[col=]name[,]] (more …)

Set aspatial column associations col=name.

-birecord[+b|l] (more …)

Select native binary format for primary table input. [Default is 3 (or 4 if -Wi is set)].

-borecord[+b|l] (more …)

Select native binary format for table output. [Default is 3 (or 4 if -Wo is set)]. -E adds 3 additional columns.

-d[i|o][+ccol]nodata (more …)

Replace input columns that equal nodata with NaN and do the reverse on output.

-e[~]“pattern” | -e[~]/regexp/[i] (more …)

Only accept data records that match the given pattern.

-f[i|o]colinfo (more …)

Specify data types of input and/or output columns.

-h[i|o][n][+c][+d][+msegheader][+rremark][+ttitle] (more …)

Skip or produce header record(s).

-icols[+l][+ddivisor][+sscale|d|k][+ooffset][,][,t[word]] (more …)

Select input columns and transformations (0 is first column, t is trailing text, append word to read one word only).

-ocols[+l][+ddivisor][+sscale|d|k][+ooffset][,][,t[word]] (more …)

Select output columns and transformations (0 is first column, t is trailing text, append word to write one word only).

-q[i|o][~]rows|limits[+ccol][+a|t|s] (more …)

Select input or output rows or data limit(s) [all].

-r[g|p] (more …)

Set node registration [gridline]. Each block is the locus of points nearest the grid value location. Consider an example with -R10/15/10/15 and -I1: With -r or -rp, 10 <= (x,y) < 11 is one of 25 blocks; otherwise 9.5 <= (x,y) < 10.5 is one of 36 blocks.

-wy|a|w|d|h|m|s|cperiod[/phase][+ccol] (more …)

Convert an input coordinate to a cyclical coordinate.

-:[i|o] (more …)

Swap 1st and 2nd column on input and/or output.

-^ 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.

ASCII Format Precision

The ASCII output formats of numerical data are controlled by parameters in your gmt.conf file. Longitude and latitude are formatted according to FORMAT_GEO_OUT, absolute time is under the control of FORMAT_DATE_OUT and FORMAT_CLOCK_OUT, whereas general floating point values are formatted according to FORMAT_FLOAT_OUT. Be aware that the format in effect can lead to loss of precision in ASCII output, which can lead to various problems downstream. If you find the output is not written with enough precision, consider switching to binary output (-bo if available) or specify more decimals using the FORMAT_FLOAT_OUT setting.

Examples

To find 5 by 5 minute block medians from the ASCII data in ship_15.txt and output a binary table with double precision triplets, run:

gmt blockmedian @ship_15.txt -R245/255/20/30 -I5m -bo3d > ship_5x5.b

To compute the shape of a data distribution per bin via a box-and-whisker diagram we need the 0%, 25%, 50%, 75%, and 100% quantiles. To do so on a global 5 by 5 degree basis from the ASCII table mars370.txt and send output to an ASCII table, run:

gmt blockmedian @mars370.txt -Rg -I5 -Eb -r > mars_5x5.txt

To determine the median and L1 scale (MAD) on the median per 10 minute bin and save these to two separate grids called field_z.nc and field_s.nc, run:

gmt blockmedian @ship_15.txt -I10m -R-115/-105/20/30 -E -Gfield_%s.nc -Azs

See Also

blockmean, blockmode, gmt, gmt.conf, greenspline, nearneighbor, surface, sphtriangulate, triangulate