From 9761b8181b223f21fccf1e86e179bf11afa3de37 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 23 Sep 2021 08:51:45 +0100 Subject: [PATCH 1/9] add cstyle docstring --- pygmt/src/grd2xyz.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pygmt/src/grd2xyz.py b/pygmt/src/grd2xyz.py index c6404febf63..fdf4f4f21ba 100644 --- a/pygmt/src/grd2xyz.py +++ b/pygmt/src/grd2xyz.py @@ -18,8 +18,11 @@ @fmt_docstring @use_alias( + C="cstyle", R="region", V="verbose", + W="weight", + Z="binary", o="outcols", ) @kwargs_to_strings(R="sequence", o="sequence_comma") @@ -48,6 +51,13 @@ def grd2xyz(grid, output_type="pandas", outfile=None, **kwargs): - ``file`` - ASCII file (requires ``outfile``) outfile : str The file name for the output ASCII file. + cstyle : str + [**f**\|\ **i**]. + Replace the x- and y-coordinates on output with the corresponding + column and row numbers. These start at 0 (C-style counting); append + **f** to start at 1 (Fortran-style counting). Alternatively, append + **i** to write just the two columns *index* and *z*, where *index* + is the 1-D indexing that GMT uses when referring to grid nodes. {R} Adding ``region`` will select a subsection of the grid. If this subsection exceeds the boundaries of the grid, only the common region From 0c598b6e940969188b45b7ebe42d57c1debf283a Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 23 Sep 2021 08:55:40 +0100 Subject: [PATCH 2/9] add weight docstring --- pygmt/src/grd2xyz.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pygmt/src/grd2xyz.py b/pygmt/src/grd2xyz.py index fdf4f4f21ba..1f545ae6b41 100644 --- a/pygmt/src/grd2xyz.py +++ b/pygmt/src/grd2xyz.py @@ -62,6 +62,17 @@ def grd2xyz(grid, output_type="pandas", outfile=None, **kwargs): Adding ``region`` will select a subsection of the grid. If this subsection exceeds the boundaries of the grid, only the common region will be output. + weight : str + [**a**\ [**+u**\ *unit*]\|\ *weight*]. + Write out *x,y,z,w*\ , where *w* is the supplied *weight* (or 1 if not + supplied) [Default writes *x,y,z* only]. Choose **a** to compute + weights equal to the area each node represents. For Cartesian grids + this is simply the product of the *x* and *y* increments (except for + gridline-registered grids at all sides [half] and corners [quarter]). + For geographic grids we default to a length unit of **k**. Change + this by appending **+u**\ *unit*. For such grids, the area + varies with latitude and also sees special cases for + gridline-registered layouts at sides, corners, and poles. {V} {o} From 6abf01f4f6a435555ca6a7ff500f768d260584f6 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 23 Sep 2021 09:03:36 +0100 Subject: [PATCH 3/9] add docstring for binary and replace --- pygmt/src/grd2xyz.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/pygmt/src/grd2xyz.py b/pygmt/src/grd2xyz.py index 1f545ae6b41..35728f738d9 100644 --- a/pygmt/src/grd2xyz.py +++ b/pygmt/src/grd2xyz.py @@ -23,6 +23,7 @@ V="verbose", W="weight", Z="binary", + d="replace", o="outcols", ) @kwargs_to_strings(R="sequence", o="sequence_comma") @@ -74,6 +75,47 @@ def grd2xyz(grid, output_type="pandas", outfile=None, **kwargs): varies with latitude and also sees special cases for gridline-registered layouts at sides, corners, and poles. {V} + binary : str + [*flags*]. + Write a 1-column ASCII [or binary] table. Output will be organized + according to the specified ordering convention contained in *flags*. + If data should be written by rows, make *flags* start with + **T** (op) if first row is y = ymax or + **B** (ottom) if first row is y = ymin. Then, + append **L** or **R** to indicate that first element should start at + left or right end of row. Likewise for column formats: start with + **L** or **R** to position first column, and then append **T** or + **B** to position first element in a row. For gridline registered + grids: If grid is periodic in x but the written data should not + contain the (redundant) column at x = xmax, append **x**. For grid + periodic in y, skip writing the redundant row at y = ymax by + appending **y**. If the byte-order needs to be swapped, append + **w**. Select one of several data types (all binary except **a**): + + * **a** ASCII representation of a single item per record + * **c** int8_t, signed 1-byte character + * **u** uint8_t, unsigned 1-byte character + * **h** int16_t, short 2-byte integer + * **H** uint16_t, unsigned short 2-byte integer + * **i** int32_t, 4-byte integer + * **I** uint32_t, unsigned 4-byte integer + * **l** int64_t, long (8-byte) integer + * **L** uint64_t, unsigned long (8-byte) integer + * **f** 4-byte floating point single precision + * **d** 8-byte floating point double precision + + Default format is scanline orientation of ASCII numbers: **TLa**. + replace : str + **i**\|\ **o**\ *nodata*. + For input only, use **i**\ *nodata* to examine all input columns. + If any item equals *nodata*, the value is interpreted as a + missing data item and is substituted with the value NaN. + + For output only, use **o**\ *nodata* to examine all output columns. + If any item equals NaN, the NaN value is substituted with the + chosen missing data value *nodata*. + + {o} Returns From 7fef0f3599360b52ff8e9427837e4e340f57afe0 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 23 Sep 2021 09:04:24 +0100 Subject: [PATCH 4/9] run make format --- pygmt/src/grd2xyz.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pygmt/src/grd2xyz.py b/pygmt/src/grd2xyz.py index 35728f738d9..c0856458378 100644 --- a/pygmt/src/grd2xyz.py +++ b/pygmt/src/grd2xyz.py @@ -107,12 +107,12 @@ def grd2xyz(grid, output_type="pandas", outfile=None, **kwargs): Default format is scanline orientation of ASCII numbers: **TLa**. replace : str **i**\|\ **o**\ *nodata*. - For input only, use **i**\ *nodata* to examine all input columns. - If any item equals *nodata*, the value is interpreted as a + For input only, use **i**\ *nodata* to examine all input columns. + If any item equals *nodata*, the value is interpreted as a missing data item and is substituted with the value NaN. - For output only, use **o**\ *nodata* to examine all output columns. - If any item equals NaN, the NaN value is substituted with the + For output only, use **o**\ *nodata* to examine all output columns. + If any item equals NaN, the NaN value is substituted with the chosen missing data value *nodata*. From fcc5b0aeabc9838d5ac18d328d2d074ce7f65e03 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Mon, 11 Oct 2021 14:51:15 +0100 Subject: [PATCH 5/9] Apply suggestions from code review Co-authored-by: Meghan Jones --- pygmt/src/grd2xyz.py | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/pygmt/src/grd2xyz.py b/pygmt/src/grd2xyz.py index c0856458378..fdc9e2be080 100644 --- a/pygmt/src/grd2xyz.py +++ b/pygmt/src/grd2xyz.py @@ -23,7 +23,7 @@ V="verbose", W="weight", Z="binary", - d="replace", + d="nodata", o="outcols", ) @kwargs_to_strings(R="sequence", o="sequence_comma") @@ -105,17 +105,7 @@ def grd2xyz(grid, output_type="pandas", outfile=None, **kwargs): * **d** 8-byte floating point double precision Default format is scanline orientation of ASCII numbers: **TLa**. - replace : str - **i**\|\ **o**\ *nodata*. - For input only, use **i**\ *nodata* to examine all input columns. - If any item equals *nodata*, the value is interpreted as a - missing data item and is substituted with the value NaN. - - For output only, use **o**\ *nodata* to examine all output columns. - If any item equals NaN, the NaN value is substituted with the - chosen missing data value *nodata*. - - + {d} {o} Returns From a8c6ac83e35878902effb8145d3d05e5f7170131 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Mon, 11 Oct 2021 16:03:34 +0100 Subject: [PATCH 6/9] replace "binary" with "z_convention" --- pygmt/src/grd2xyz.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pygmt/src/grd2xyz.py b/pygmt/src/grd2xyz.py index fdc9e2be080..d8b7ffaf541 100644 --- a/pygmt/src/grd2xyz.py +++ b/pygmt/src/grd2xyz.py @@ -22,7 +22,7 @@ R="region", V="verbose", W="weight", - Z="binary", + Z="z_convention", d="nodata", o="outcols", ) @@ -75,7 +75,7 @@ def grd2xyz(grid, output_type="pandas", outfile=None, **kwargs): varies with latitude and also sees special cases for gridline-registered layouts at sides, corners, and poles. {V} - binary : str + z_convention : str [*flags*]. Write a 1-column ASCII [or binary] table. Output will be organized according to the specified ordering convention contained in *flags*. From 7e1560a4f3310da5c0aa3df49297d0d66d3404ac Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Mon, 11 Oct 2021 16:05:24 +0100 Subject: [PATCH 7/9] add binary option --- pygmt/src/grd2xyz.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pygmt/src/grd2xyz.py b/pygmt/src/grd2xyz.py index d8b7ffaf541..2f6a787ad42 100644 --- a/pygmt/src/grd2xyz.py +++ b/pygmt/src/grd2xyz.py @@ -23,6 +23,7 @@ V="verbose", W="weight", Z="z_convention", + b="binary", d="nodata", o="outcols", ) @@ -105,6 +106,7 @@ def grd2xyz(grid, output_type="pandas", outfile=None, **kwargs): * **d** 8-byte floating point double precision Default format is scanline orientation of ASCII numbers: **TLa**. + {b} {d} {o} From 1238a0ccff01fdfdebc222751583965e241b2b8c Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sat, 23 Oct 2021 07:43:08 +0100 Subject: [PATCH 8/9] change z_convention to convention --- pygmt/src/grd2xyz.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pygmt/src/grd2xyz.py b/pygmt/src/grd2xyz.py index 2f6a787ad42..51655ae78f4 100644 --- a/pygmt/src/grd2xyz.py +++ b/pygmt/src/grd2xyz.py @@ -22,7 +22,7 @@ R="region", V="verbose", W="weight", - Z="z_convention", + Z="convention", b="binary", d="nodata", o="outcols", @@ -76,7 +76,7 @@ def grd2xyz(grid, output_type="pandas", outfile=None, **kwargs): varies with latitude and also sees special cases for gridline-registered layouts at sides, corners, and poles. {V} - z_convention : str + convention : str [*flags*]. Write a 1-column ASCII [or binary] table. Output will be organized according to the specified ordering convention contained in *flags*. From 194d684893c8078c4e32eb124f819c20334a5caa Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 28 Oct 2021 07:20:57 +0100 Subject: [PATCH 9/9] Apply suggestions from code review Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- pygmt/src/grd2xyz.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pygmt/src/grd2xyz.py b/pygmt/src/grd2xyz.py index 51655ae78f4..0a33a5bbe67 100644 --- a/pygmt/src/grd2xyz.py +++ b/pygmt/src/grd2xyz.py @@ -25,7 +25,10 @@ Z="convention", b="binary", d="nodata", + f="coltypes", + h="header", o="outcols", + s="skiprows", ) @kwargs_to_strings(R="sequence", o="sequence_comma") def grd2xyz(grid, output_type="pandas", outfile=None, **kwargs): @@ -108,7 +111,10 @@ def grd2xyz(grid, output_type="pandas", outfile=None, **kwargs): Default format is scanline orientation of ASCII numbers: **TLa**. {b} {d} + {f} + {h} {o} + {s} Returns -------