From 27f5d20b85cd1bbfd237ef8e7e0455d07a6efb4d Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Fri, 11 Dec 2020 09:59:50 +0000 Subject: [PATCH 01/37] Add cyl_transverse_mercator.py --- .../cyl/cyl_transverse_mercator.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 examples/projections/cyl/cyl_transverse_mercator.py diff --git a/examples/projections/cyl/cyl_transverse_mercator.py b/examples/projections/cyl/cyl_transverse_mercator.py new file mode 100644 index 00000000000..fc8bb2198b9 --- /dev/null +++ b/examples/projections/cyl/cyl_transverse_mercator.py @@ -0,0 +1,19 @@ +""" +Transverse Mercator +=================== + +``T[lon0/][lat0/]width``: Give central meridian ``lon0``, the latitude of the +origin ``lat0`` (optional), and the figure width. +""" +import pygmt + +fig = pygmt.Figure() +fig.coast( + region=[20, 50, 30, 45], + projection="T35/12c", + land="lightbrown", + water="seashell", + shorelines="thinnest", + frame="afg", +) +fig.show() From d64983ff1ae3e046ba76697f8980e12c4600475c Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Fri, 11 Dec 2020 10:40:06 +0000 Subject: [PATCH 02/37] Add cyl_universal_transverse_mercator.py --- .../cyl/cyl_universal_transverse_mercator.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 examples/projections/cyl/cyl_universal_transverse_mercator.py diff --git a/examples/projections/cyl/cyl_universal_transverse_mercator.py b/examples/projections/cyl/cyl_universal_transverse_mercator.py new file mode 100644 index 00000000000..47259c5bd6c --- /dev/null +++ b/examples/projections/cyl/cyl_universal_transverse_mercator.py @@ -0,0 +1,19 @@ +""" +Universal Transverse Mercator +============================= + +``U[UTM Zone/][lat0/]width``: Give UTM Zone ``UTM Zone``, and the figure width. +""" +import pygmt + +fig = pygmt.Figure() +# UTM Zone is set to 52R +fig.coast( + region=[127.5, 128.5, 26, 27], + projection="U52R/12c", + land="lightgreen", + water="lightblue", + shorelines="thinnest", + frame="afg", +) +fig.show() From 6ba8185f68bc7dbc76a2787540083287204a7ea4 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Fri, 11 Dec 2020 10:48:29 +0000 Subject: [PATCH 03/37] Changing land color to red in cyl_mercator.py to match GMT docs example; changing units from US to SI --- examples/projections/cyl/cyl_mercator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/projections/cyl/cyl_mercator.py b/examples/projections/cyl/cyl_mercator.py index d2e54886e6f..bfe22ba87a9 100644 --- a/examples/projections/cyl/cyl_mercator.py +++ b/examples/projections/cyl/cyl_mercator.py @@ -8,5 +8,5 @@ import pygmt fig = pygmt.Figure() -fig.coast(region=[0, 360, -80, 80], frame="afg", land="gray", projection="M0/0/8i") +fig.coast(region=[0, 360, -80, 80], frame="afg", land="red", projection="M0/0/12c") fig.show() From 1466bb9cbc7d9c3b825acb7eadca439f7e241ea0 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 21 Jan 2021 19:11:24 +0000 Subject: [PATCH 04/37] Add region alias to grdinfo --- pygmt/modules.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pygmt/modules.py b/pygmt/modules.py index 2c591b6a0f4..b76441e87c1 100644 --- a/pygmt/modules.py +++ b/pygmt/modules.py @@ -11,12 +11,14 @@ data_kind, dummy_context, fmt_docstring, + kwargs_to_strings, use_alias, ) @fmt_docstring -@use_alias(V="verbose") +@use_alias(R="region", V="verbose") +@kwargs_to_strings(R="sequence") def grdinfo(grid, **kwargs): """ Get information about a grid. @@ -29,7 +31,7 @@ def grdinfo(grid, **kwargs): ---------- grid : str or xarray.DataArray The file name of the input grid or the grid loaded as a DataArray. - + {R} {V} Returns From 158ef5d74a1b1fb5e3b99fccf972951487642325 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 21 Jan 2021 19:39:26 +0000 Subject: [PATCH 05/37] Add grid argument name to existing tests --- pygmt/tests/test_grdinfo.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pygmt/tests/test_grdinfo.py b/pygmt/tests/test_grdinfo.py index 889cb7aef92..857c782c18d 100644 --- a/pygmt/tests/test_grdinfo.py +++ b/pygmt/tests/test_grdinfo.py @@ -13,7 +13,7 @@ def test_grdinfo(): Make sure grd info works as expected. """ grid = load_earth_relief(registration="gridline") - result = grdinfo(grid, L=0, C="n") + result = grdinfo(grid=grid, L=0, C="n") assert result.strip() == "-180 180 -90 90 -8592.5 5559 1 1 361 181 0 1" @@ -21,7 +21,7 @@ def test_grdinfo_file(): """ Test grdinfo with file input. """ - result = grdinfo("@earth_relief_01d", L=0, C="n") + result = grdinfo(grid="@earth_relief_01d", L=0, C="n") assert result.strip() == "-180 180 -90 90 -8182 5651.5 1 1 360 180 1 1" From a90ca99f45fa74c28aa8d03eb082eb603a1aad14 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 21 Jan 2021 19:54:16 +0000 Subject: [PATCH 06/37] Add tab, geographic, and zdata aliases --- pygmt/modules.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pygmt/modules.py b/pygmt/modules.py index b76441e87c1..8ab33f18da0 100644 --- a/pygmt/modules.py +++ b/pygmt/modules.py @@ -17,7 +17,7 @@ @fmt_docstring -@use_alias(R="region", V="verbose") +@use_alias(C="tab", F="geographic", L="zdata", R="region", V="verbose") @kwargs_to_strings(R="sequence") def grdinfo(grid, **kwargs): """ @@ -31,6 +31,7 @@ def grdinfo(grid, **kwargs): ---------- grid : str or xarray.DataArray The file name of the input grid or the grid loaded as a DataArray. + This is the only required argument. {R} {V} From cac7aff49d309bf32940f0b76cd84224098f70c3 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 21 Jan 2021 20:02:12 +0000 Subject: [PATCH 07/37] Add tab doc string --- pygmt/modules.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pygmt/modules.py b/pygmt/modules.py index 8ab33f18da0..8b87c2ae37d 100644 --- a/pygmt/modules.py +++ b/pygmt/modules.py @@ -17,7 +17,7 @@ @fmt_docstring -@use_alias(C="tab", F="geographic", L="zdata", R="region", V="verbose") +@use_alias(C="tab", F="geographic", L="zdata", M="zextemes", R="region", V="verbose") @kwargs_to_strings(R="sequence") def grdinfo(grid, **kwargs): """ @@ -33,6 +33,14 @@ def grdinfo(grid, **kwargs): The file name of the input grid or the grid loaded as a DataArray. This is the only required argument. {R} + tab : str or bool + **n**\ |**t** + Formats the report using tab-separated fields on a single line. The + output is name w e s n z0 z1 dx dy nx ny[ x0 y0 x1 y1 ] [ med scale ] + [mean std rms] [n_nan] registration gtype. The data in brackets are + output only if the corresponding options -M, -L1, -L2, and -M are + used, respectively. Use -Ct to place file name at the end of the output record or -Cn to only output numerical columns. The registration is either 0 (gridline) or 1 (pixel), while gtype is either 0 (Cartesian) or 1 (geographic). + {V} Returns From 73e0af7c2e3e8061ff203b1c487ee25f8450430c Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 21 Jan 2021 20:05:06 +0000 Subject: [PATCH 08/37] Add tab doc string --- pygmt/modules.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pygmt/modules.py b/pygmt/modules.py index 8b87c2ae37d..3153400f069 100644 --- a/pygmt/modules.py +++ b/pygmt/modules.py @@ -38,8 +38,11 @@ def grdinfo(grid, **kwargs): Formats the report using tab-separated fields on a single line. The output is name w e s n z0 z1 dx dy nx ny[ x0 y0 x1 y1 ] [ med scale ] [mean std rms] [n_nan] registration gtype. The data in brackets are - output only if the corresponding options -M, -L1, -L2, and -M are - used, respectively. Use -Ct to place file name at the end of the output record or -Cn to only output numerical columns. The registration is either 0 (gridline) or 1 (pixel), while gtype is either 0 (Cartesian) or 1 (geographic). + outputted depending on the `zdata` and `zextremes` arguments. + Use **t** to place file name at the end of the output record or, + **n** or `True` to only output numerical columns. The registration is + either 0 (gridline) or 1 (pixel), while gtype is either 0 (Cartesian) + or 1 (geographic). {V} From e6e8da0f27168392e0cd87ee8f2050e2b0cdb907 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 21 Jan 2021 20:33:19 +0000 Subject: [PATCH 09/37] Make grdinfo doc string an r-string --- pygmt/modules.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/modules.py b/pygmt/modules.py index 3153400f069..8a2740a237d 100644 --- a/pygmt/modules.py +++ b/pygmt/modules.py @@ -20,7 +20,7 @@ @use_alias(C="tab", F="geographic", L="zdata", M="zextemes", R="region", V="verbose") @kwargs_to_strings(R="sequence") def grdinfo(grid, **kwargs): - """ + r""" Get information about a grid. Can read the grid from a file or given as an xarray.DataArray grid. From 0e287000c1491e5514fd6bccd0ada6f6e01dd1de Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 21 Jan 2021 20:36:10 +0000 Subject: [PATCH 10/37] Update doc string formatting --- pygmt/modules.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pygmt/modules.py b/pygmt/modules.py index 8a2740a237d..f4426dfacbb 100644 --- a/pygmt/modules.py +++ b/pygmt/modules.py @@ -38,11 +38,11 @@ def grdinfo(grid, **kwargs): Formats the report using tab-separated fields on a single line. The output is name w e s n z0 z1 dx dy nx ny[ x0 y0 x1 y1 ] [ med scale ] [mean std rms] [n_nan] registration gtype. The data in brackets are - outputted depending on the `zdata` and `zextremes` arguments. + outputted depending on the ``zdata`` and ``zextremes`` arguments. Use **t** to place file name at the end of the output record or, - **n** or `True` to only output numerical columns. The registration is + **n** or ``True`` to only output numerical columns. The registration is either 0 (gridline) or 1 (pixel), while gtype is either 0 (Cartesian) - or 1 (geographic). + or 1 (geographic). The default value is ``False``. {V} From b4b74f42aad3e6e9d049d0e066cc45f39bf5488d Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 21 Jan 2021 20:41:15 +0000 Subject: [PATCH 11/37] Update doc string for geographic argument --- pygmt/modules.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pygmt/modules.py b/pygmt/modules.py index f4426dfacbb..7eb4a88a9eb 100644 --- a/pygmt/modules.py +++ b/pygmt/modules.py @@ -42,7 +42,12 @@ def grdinfo(grid, **kwargs): Use **t** to place file name at the end of the output record or, **n** or ``True`` to only output numerical columns. The registration is either 0 (gridline) or 1 (pixel), while gtype is either 0 (Cartesian) - or 1 (geographic). The default value is ``False``. + or 1 (geographic). The default value is ``False``. This cannot be + called if ``geographic`` is also set. + geographic : bool + Report grid domain and x/y-increments in world mapping format + The default value is ``False``. This cannot be called if ``tab`` is + also set. {V} From 9e85b305dd1d82e0d0e8f0293af9c64092f971b7 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 21 Jan 2021 20:44:48 +0000 Subject: [PATCH 12/37] Update zdata doc string --- pygmt/modules.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pygmt/modules.py b/pygmt/modules.py index 7eb4a88a9eb..a916171a652 100644 --- a/pygmt/modules.py +++ b/pygmt/modules.py @@ -48,7 +48,16 @@ def grdinfo(grid, **kwargs): Report grid domain and x/y-increments in world mapping format The default value is ``False``. This cannot be called if ``tab`` is also set. - + zdata : int or str + **0**\ |**1**\ |**2**\ |**p**\ |**a** + **0**\ : Report range of z after actually scanning the data, not just + reporting what the header says. + **1**\ : Report median and L1 scale of z (L1 scale = 1.4826 * Median + Absolute Deviation (MAD)). + **2**\ : Report mean, standard deviation, and root-mean-square (rms) + of z. + **p**\ : Report mode (LMS) and LMS scale of z. + **a**\ : Include all of the above. {V} Returns From 083b655eb1d039373ae1b80f64c5bc08ecf7c163 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 21 Jan 2021 20:45:32 +0000 Subject: [PATCH 13/37] Updating grdinfo C alias --- pygmt/modules.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pygmt/modules.py b/pygmt/modules.py index a916171a652..c00f09eae40 100644 --- a/pygmt/modules.py +++ b/pygmt/modules.py @@ -17,7 +17,7 @@ @fmt_docstring -@use_alias(C="tab", F="geographic", L="zdata", M="zextemes", R="region", V="verbose") +@use_alias(C="per_column", F="geographic", L="zdata", M="zextemes", R="region", V="verbose") @kwargs_to_strings(R="sequence") def grdinfo(grid, **kwargs): r""" @@ -33,7 +33,7 @@ def grdinfo(grid, **kwargs): The file name of the input grid or the grid loaded as a DataArray. This is the only required argument. {R} - tab : str or bool + per_column : str or bool **n**\ |**t** Formats the report using tab-separated fields on a single line. The output is name w e s n z0 z1 dx dy nx ny[ x0 y0 x1 y1 ] [ med scale ] From 87146de00f265a427b833fd573df4a6d54a98ee6 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 21 Jan 2021 20:48:36 +0000 Subject: [PATCH 14/37] Add/change grdinfo aliases --- pygmt/modules.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pygmt/modules.py b/pygmt/modules.py index c00f09eae40..23b66132abd 100644 --- a/pygmt/modules.py +++ b/pygmt/modules.py @@ -17,7 +17,17 @@ @fmt_docstring -@use_alias(C="per_column", F="geographic", L="zdata", M="zextemes", R="region", V="verbose") +@use_alias( + C="per_column", + D="tiles", + F="geographic", + I="spacing", + T="nearest_multiple", + L="force_scan", + M="minmax_pos", + R="region", + V="verbose", +) @kwargs_to_strings(R="sequence") def grdinfo(grid, **kwargs): r""" From 1d5d0eda96c17a78ca48550993c36f06d68b26a8 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 21 Jan 2021 20:53:20 +0000 Subject: [PATCH 15/37] Add minxmax_pos to doc string --- pygmt/modules.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pygmt/modules.py b/pygmt/modules.py index 23b66132abd..53b781fdd3c 100644 --- a/pygmt/modules.py +++ b/pygmt/modules.py @@ -58,7 +58,7 @@ def grdinfo(grid, **kwargs): Report grid domain and x/y-increments in world mapping format The default value is ``False``. This cannot be called if ``tab`` is also set. - zdata : int or str + force_scan : int or str **0**\ |**1**\ |**2**\ |**p**\ |**a** **0**\ : Report range of z after actually scanning the data, not just reporting what the header says. @@ -68,6 +68,9 @@ def grdinfo(grid, **kwargs): of z. **p**\ : Report mode (LMS) and LMS scale of z. **a**\ : Include all of the above. + minxmax_pos : bool + Include the x/y values at the location of the minimum and maximum + z-values {V} Returns From 720b5f3dadd542e4c58c71a6e3612a8145b8e4e4 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 21 Jan 2021 21:23:36 +0000 Subject: [PATCH 16/37] Fix typo --- pygmt/modules.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/modules.py b/pygmt/modules.py index 53b781fdd3c..35b2d626a12 100644 --- a/pygmt/modules.py +++ b/pygmt/modules.py @@ -70,7 +70,7 @@ def grdinfo(grid, **kwargs): **a**\ : Include all of the above. minxmax_pos : bool Include the x/y values at the location of the minimum and maximum - z-values + z-values. {V} Returns From 13829e310844737eea612e914af370ed610074bf Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 21 Jan 2021 21:28:18 +0000 Subject: [PATCH 17/37] Add tiles doc string --- pygmt/modules.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pygmt/modules.py b/pygmt/modules.py index 35b2d626a12..a7d8e4c6ec6 100644 --- a/pygmt/modules.py +++ b/pygmt/modules.py @@ -54,6 +54,16 @@ def grdinfo(grid, **kwargs): either 0 (gridline) or 1 (pixel), while gtype is either 0 (Cartesian) or 1 (geographic). The default value is ``False``. This cannot be called if ``geographic`` is also set. + tiles : str + *xoff*\ [/*yoff*\ ][**+i**\ ] + Divide a single grid’s domain (or the ``regio``n domain, if no grid + given) into tiles of size dx times dy (set via ``spacing``). You can + specify overlap between tiles by appending *xoff*\ [/*yoff*\ ]. If the + single grid is given you may use the modifier **+i** to ignore tiles + that have no data within each tile subregion. Default output is text + region strings. Use ``per_column`` to instead report four columns with \ + xmin xmax ymin ymax per tile, or use ``per_column=t`` to also have the + region string appended as trailing text. geographic : bool Report grid domain and x/y-increments in world mapping format The default value is ``False``. This cannot be called if ``tab`` is From dccc4b8bf72af028c1afdf77286193ea444f7055 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 21 Jan 2021 21:29:25 +0000 Subject: [PATCH 18/37] Fix typo --- pygmt/modules.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/modules.py b/pygmt/modules.py index a7d8e4c6ec6..8e7438b7c40 100644 --- a/pygmt/modules.py +++ b/pygmt/modules.py @@ -56,7 +56,7 @@ def grdinfo(grid, **kwargs): called if ``geographic`` is also set. tiles : str *xoff*\ [/*yoff*\ ][**+i**\ ] - Divide a single grid’s domain (or the ``regio``n domain, if no grid + Divide a single grid’s domain (or the ``region`` domain, if no grid given) into tiles of size dx times dy (set via ``spacing``). You can specify overlap between tiles by appending *xoff*\ [/*yoff*\ ]. If the single grid is given you may use the modifier **+i** to ignore tiles From 43372a0bc72262867b67ab8c27ad0c7b8e7d7dec Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 21 Jan 2021 21:31:28 +0000 Subject: [PATCH 19/37] Correct doc string for per_column rename --- pygmt/modules.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pygmt/modules.py b/pygmt/modules.py index 8e7438b7c40..fc0c7e4fe1c 100644 --- a/pygmt/modules.py +++ b/pygmt/modules.py @@ -66,8 +66,8 @@ def grdinfo(grid, **kwargs): region string appended as trailing text. geographic : bool Report grid domain and x/y-increments in world mapping format - The default value is ``False``. This cannot be called if ``tab`` is - also set. + The default value is ``False``. This cannot be called if + ``per_column`` is also set. force_scan : int or str **0**\ |**1**\ |**2**\ |**p**\ |**a** **0**\ : Report range of z after actually scanning the data, not just From 61ce2b6f303dc38aac9c53cbfc544ac24f0f7182 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 21 Jan 2021 21:34:49 +0000 Subject: [PATCH 20/37] Add doc string for spacing --- pygmt/modules.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pygmt/modules.py b/pygmt/modules.py index fc0c7e4fe1c..2b330a0ae86 100644 --- a/pygmt/modules.py +++ b/pygmt/modules.py @@ -68,6 +68,17 @@ def grdinfo(grid, **kwargs): Report grid domain and x/y-increments in world mapping format The default value is ``False``. This cannot be called if ``per_column`` is also set. + spacing : str + *dx*\ [/*dy*\ ]|**b**\ |**i**\ |**r**\ ] + Report the min/max of the region to the nearest multiple of dx and dy, + and output this in the form w/e/s/n (unless ``per_column`` is set). To + report the actual grid region, append **r**. For a grid produced by + the img supplement (a Cartesian Mercator grid), the exact geographic + region is given with **i** (if not found then we return the actual + grid region instead). If no argument is given then we report the grid + increment in the form *xinc*\ [/*yinc*\ ]. If **b** is given we write + each grid’s bounding box polygon instead. Finally, if ``tiles`` is in + effect then dx and dy are the dimensions of the desired tiles. force_scan : int or str **0**\ |**1**\ |**2**\ |**p**\ |**a** **0**\ : Report range of z after actually scanning the data, not just From 51c1c85af6b2ded2a680a9f67b3a59f29e1f2cf8 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 21 Jan 2021 21:40:50 +0000 Subject: [PATCH 21/37] Add nearest_multiple to grdinfo doc string --- pygmt/modules.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pygmt/modules.py b/pygmt/modules.py index 2b330a0ae86..e633376b50b 100644 --- a/pygmt/modules.py +++ b/pygmt/modules.py @@ -92,6 +92,17 @@ def grdinfo(grid, **kwargs): minxmax_pos : bool Include the x/y values at the location of the minimum and maximum z-values. + nearest_multiple : str + [*dz*\ ][**+a**\ [*alpha*\ ]][**+s**\ ] + Determine min and max z-value. If dz is provided then we first round + these values off to multiples of dz. To exclude the two tails of the + distribution when determining the min and max you can add **+a** to + set the *alpha* value (in percent): We then sort the grid, exclude the + data in the 0.5*\ *alpha* and 100 - 0.5*\ *alpha* tails, and revise + the min and max. To force a symmetrical range about zero, using + minus/plus the max absolute value of the two extremes, append **+s**\ . + We report the result via the text string *zmin/zmax* or *zmin/zmax/dz* + (if dz was given) as expected by makecpt. {V} Returns From 89ef66bf4b2fc8045c6fcbb6a83fea6ba1223665 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 21 Jan 2021 21:52:29 +0000 Subject: [PATCH 22/37] Add test for region argument --- pygmt/tests/test_grdinfo.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pygmt/tests/test_grdinfo.py b/pygmt/tests/test_grdinfo.py index 857c782c18d..a3413e9b9df 100644 --- a/pygmt/tests/test_grdinfo.py +++ b/pygmt/tests/test_grdinfo.py @@ -31,3 +31,16 @@ def test_grdinfo_fails(): """ with pytest.raises(GMTInvalidInput): grdinfo(np.arange(10).reshape((5, 2))) + + +def test_grdinfo_region(): + """ + Check that the region argument works in grdinfo. + """ + result = grdinfo( + grid="@earth_relief_01d", + force_scan=0, + per_column="n", + region=[-170, 170, -80, 80], + ) + assert result.strip() == "-170 170 -80 80 -8182 5651.5 1 1 340 160 1 1" From 71ae7736960a0c3ffa78d1f7c1108031d41389c1 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 21 Jan 2021 21:54:25 +0000 Subject: [PATCH 23/37] Style fix --- pygmt/modules.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/modules.py b/pygmt/modules.py index e633376b50b..11a66c9fb87 100644 --- a/pygmt/modules.py +++ b/pygmt/modules.py @@ -61,7 +61,7 @@ def grdinfo(grid, **kwargs): specify overlap between tiles by appending *xoff*\ [/*yoff*\ ]. If the single grid is given you may use the modifier **+i** to ignore tiles that have no data within each tile subregion. Default output is text - region strings. Use ``per_column`` to instead report four columns with \ + region strings. Use ``per_column`` to instead report four columns with xmin xmax ymin ymax per tile, or use ``per_column=t`` to also have the region string appended as trailing text. geographic : bool From 568f516e5fb61ae012798c200b917d6e96146e59 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Fri, 22 Jan 2021 11:09:52 +0000 Subject: [PATCH 24/37] Fix argument names in per_column docstring --- pygmt/modules.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/modules.py b/pygmt/modules.py index 11a66c9fb87..bc06ef02f20 100644 --- a/pygmt/modules.py +++ b/pygmt/modules.py @@ -48,7 +48,7 @@ def grdinfo(grid, **kwargs): Formats the report using tab-separated fields on a single line. The output is name w e s n z0 z1 dx dy nx ny[ x0 y0 x1 y1 ] [ med scale ] [mean std rms] [n_nan] registration gtype. The data in brackets are - outputted depending on the ``zdata`` and ``zextremes`` arguments. + outputted depending on the ``force_scan`` and ``minmax_pos`` arguments. Use **t** to place file name at the end of the output record or, **n** or ``True`` to only output numerical columns. The registration is either 0 (gridline) or 1 (pixel), while gtype is either 0 (Cartesian) From 5a7df5d227a23524eaa81942a042dfe74ac88389 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Fri, 22 Jan 2021 17:06:40 +0000 Subject: [PATCH 25/37] Fix formatting typo --- pygmt/modules.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/modules.py b/pygmt/modules.py index bc06ef02f20..91b5ea7d401 100644 --- a/pygmt/modules.py +++ b/pygmt/modules.py @@ -69,7 +69,7 @@ def grdinfo(grid, **kwargs): The default value is ``False``. This cannot be called if ``per_column`` is also set. spacing : str - *dx*\ [/*dy*\ ]|**b**\ |**i**\ |**r**\ ] + *dx*\ [/*dy*\ ]|\ **b**\ |**i**\ |**r**\ ] Report the min/max of the region to the nearest multiple of dx and dy, and output this in the form w/e/s/n (unless ``per_column`` is set). To report the actual grid region, append **r**. For a grid produced by From bfd027d9340cbe8221ed71f45d30b6f6294b3faa Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Fri, 5 Feb 2021 06:23:58 +0000 Subject: [PATCH 26/37] Apply suggestions from code review Co-authored-by: Dongdong Tian --- pygmt/modules.py | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/pygmt/modules.py b/pygmt/modules.py index 91b5ea7d401..f2967206ecb 100644 --- a/pygmt/modules.py +++ b/pygmt/modules.py @@ -28,7 +28,7 @@ R="region", V="verbose", ) -@kwargs_to_strings(R="sequence") +@kwargs_to_strings(R="sequence", D="sequence", I="sequence") def grdinfo(grid, **kwargs): r""" Get information about a grid. @@ -46,41 +46,41 @@ def grdinfo(grid, **kwargs): per_column : str or bool **n**\ |**t** Formats the report using tab-separated fields on a single line. The - output is name w e s n z0 z1 dx dy nx ny[ x0 y0 x1 y1 ] [ med scale ] - [mean std rms] [n_nan] registration gtype. The data in brackets are + output is name *w e s n z0 z1 dx dy nx ny* [ *x0 y0 x1 y1* ] [ *med scale* ] + [ *mean std rms* ] [ *n_nan* ] *registration gtype*. The data in brackets are outputted depending on the ``force_scan`` and ``minmax_pos`` arguments. Use **t** to place file name at the end of the output record or, **n** or ``True`` to only output numerical columns. The registration is either 0 (gridline) or 1 (pixel), while gtype is either 0 (Cartesian) or 1 (geographic). The default value is ``False``. This cannot be called if ``geographic`` is also set. - tiles : str - *xoff*\ [/*yoff*\ ][**+i**\ ] - Divide a single grid’s domain (or the ``region`` domain, if no grid + tiles : str or list + *xoff*\ [/*yoff*][**+i**] + Divide a single grid's domain (or the ``region`` domain, if no grid given) into tiles of size dx times dy (set via ``spacing``). You can - specify overlap between tiles by appending *xoff*\ [/*yoff*\ ]. If the + specify overlap between tiles by appending *xoff*\ [/*yoff*]. If the single grid is given you may use the modifier **+i** to ignore tiles that have no data within each tile subregion. Default output is text region strings. Use ``per_column`` to instead report four columns with - xmin xmax ymin ymax per tile, or use ``per_column=t`` to also have the + xmin xmax ymin ymax per tile, or use ``per_column="t"`` to also have the region string appended as trailing text. geographic : bool Report grid domain and x/y-increments in world mapping format The default value is ``False``. This cannot be called if ``per_column`` is also set. - spacing : str - *dx*\ [/*dy*\ ]|\ **b**\ |**i**\ |**r**\ ] + spacing : str or list + *dx*\ [/*dy*]\|\ **b**\|\ **i**\|\ **r** Report the min/max of the region to the nearest multiple of dx and dy, and output this in the form w/e/s/n (unless ``per_column`` is set). To report the actual grid region, append **r**. For a grid produced by the img supplement (a Cartesian Mercator grid), the exact geographic region is given with **i** (if not found then we return the actual grid region instead). If no argument is given then we report the grid - increment in the form *xinc*\ [/*yinc*\ ]. If **b** is given we write - each grid’s bounding box polygon instead. Finally, if ``tiles`` is in - effect then dx and dy are the dimensions of the desired tiles. + increment in the form *xinc*\ [/*yinc*]. If **b** is given we write + each grid's bounding box polygon instead. Finally, if ``tiles`` is in + effect then *dx* and *dy* are the dimensions of the desired tiles. force_scan : int or str - **0**\ |**1**\ |**2**\ |**p**\ |**a** + **0**\|\ **1**\|\ **2**\|\ **p**\|\ **a** **0**\ : Report range of z after actually scanning the data, not just reporting what the header says. **1**\ : Report median and L1 scale of z (L1 scale = 1.4826 * Median @@ -93,16 +93,16 @@ def grdinfo(grid, **kwargs): Include the x/y values at the location of the minimum and maximum z-values. nearest_multiple : str - [*dz*\ ][**+a**\ [*alpha*\ ]][**+s**\ ] - Determine min and max z-value. If dz is provided then we first round - these values off to multiples of dz. To exclude the two tails of the + [*dz*]\ [**+a**\ [*alpha*]]\ [**+s**] + Determine min and max z-value. If *dz* is provided then we first round + these values off to multiples of *dz*. To exclude the two tails of the distribution when determining the min and max you can add **+a** to set the *alpha* value (in percent): We then sort the grid, exclude the data in the 0.5*\ *alpha* and 100 - 0.5*\ *alpha* tails, and revise the min and max. To force a symmetrical range about zero, using minus/plus the max absolute value of the two extremes, append **+s**\ . We report the result via the text string *zmin/zmax* or *zmin/zmax/dz* - (if dz was given) as expected by makecpt. + (if *dz* was given) as expected by :meth:`pygmt.makecpt`. {V} Returns From c47d45a6cb2fc219e8738995b26e5f67560a41fd Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Fri, 5 Feb 2021 06:26:49 +0000 Subject: [PATCH 27/37] Change tests in test_grdinfo.py to use long form aliases --- pygmt/tests/test_grdinfo.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pygmt/tests/test_grdinfo.py b/pygmt/tests/test_grdinfo.py index a3413e9b9df..5526a23811e 100644 --- a/pygmt/tests/test_grdinfo.py +++ b/pygmt/tests/test_grdinfo.py @@ -13,7 +13,7 @@ def test_grdinfo(): Make sure grd info works as expected. """ grid = load_earth_relief(registration="gridline") - result = grdinfo(grid=grid, L=0, C="n") + result = grdinfo(grid=grid, force_scan=0, per_column="n") assert result.strip() == "-180 180 -90 90 -8592.5 5559 1 1 361 181 0 1" @@ -21,7 +21,7 @@ def test_grdinfo_file(): """ Test grdinfo with file input. """ - result = grdinfo(grid="@earth_relief_01d", L=0, C="n") + result = grdinfo(grid="@earth_relief_01d", force_scan=0, per_column="n") assert result.strip() == "-180 180 -90 90 -8182 5651.5 1 1 360 180 1 1" From ecce72332ab321783c16075da48f3171235e9019 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Fri, 5 Feb 2021 10:42:13 +0000 Subject: [PATCH 28/37] Apply suggestions from code review Co-authored-by: Dongdong Tian --- pygmt/modules.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pygmt/modules.py b/pygmt/modules.py index f2967206ecb..ca453b91418 100644 --- a/pygmt/modules.py +++ b/pygmt/modules.py @@ -44,7 +44,7 @@ def grdinfo(grid, **kwargs): This is the only required argument. {R} per_column : str or bool - **n**\ |**t** + **n**\|\ **t**. Formats the report using tab-separated fields on a single line. The output is name *w e s n z0 z1 dx dy nx ny* [ *x0 y0 x1 y1* ] [ *med scale* ] [ *mean std rms* ] [ *n_nan* ] *registration gtype*. The data in brackets are @@ -55,7 +55,7 @@ def grdinfo(grid, **kwargs): or 1 (geographic). The default value is ``False``. This cannot be called if ``geographic`` is also set. tiles : str or list - *xoff*\ [/*yoff*][**+i**] + *xoff*\ [/*yoff*][**+i**]. Divide a single grid's domain (or the ``region`` domain, if no grid given) into tiles of size dx times dy (set via ``spacing``). You can specify overlap between tiles by appending *xoff*\ [/*yoff*]. If the @@ -69,7 +69,7 @@ def grdinfo(grid, **kwargs): The default value is ``False``. This cannot be called if ``per_column`` is also set. spacing : str or list - *dx*\ [/*dy*]\|\ **b**\|\ **i**\|\ **r** + *dx*\ [/*dy*]\|\ **b**\|\ **i**\|\ **r**. Report the min/max of the region to the nearest multiple of dx and dy, and output this in the form w/e/s/n (unless ``per_column`` is set). To report the actual grid region, append **r**. For a grid produced by @@ -93,7 +93,7 @@ def grdinfo(grid, **kwargs): Include the x/y values at the location of the minimum and maximum z-values. nearest_multiple : str - [*dz*]\ [**+a**\ [*alpha*]]\ [**+s**] + [*dz*]\ [**+a**\ [*alpha*]]\ [**+s**]. Determine min and max z-value. If *dz* is provided then we first round these values off to multiples of *dz*. To exclude the two tails of the distribution when determining the min and max you can add **+a** to From 2a94c6cbee801af9e60c380f58bc044754d50d5b Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Fri, 5 Feb 2021 10:42:39 +0000 Subject: [PATCH 29/37] Update pygmt/modules.py Co-authored-by: Dongdong Tian --- pygmt/modules.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pygmt/modules.py b/pygmt/modules.py index ca453b91418..ffdfbbab6ea 100644 --- a/pygmt/modules.py +++ b/pygmt/modules.py @@ -80,7 +80,8 @@ def grdinfo(grid, **kwargs): each grid's bounding box polygon instead. Finally, if ``tiles`` is in effect then *dx* and *dy* are the dimensions of the desired tiles. force_scan : int or str - **0**\|\ **1**\|\ **2**\|\ **p**\|\ **a** + **0**\|\ **1**\|\ **2**\|\ **p**\|\ **a**. + **0**\ : Report range of z after actually scanning the data, not just reporting what the header says. **1**\ : Report median and L1 scale of z (L1 scale = 1.4826 * Median From 72ef404e5edecfd22adcebd8d007a0a827191e09 Mon Sep 17 00:00:00 2001 From: actions-bot <58130806+actions-bot@users.noreply.github.com> Date: Fri, 5 Feb 2021 21:26:22 +0000 Subject: [PATCH 30/37] [format-command] fixes --- pygmt/modules.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/modules.py b/pygmt/modules.py index ffdfbbab6ea..9fe5b7faedb 100644 --- a/pygmt/modules.py +++ b/pygmt/modules.py @@ -81,7 +81,7 @@ def grdinfo(grid, **kwargs): effect then *dx* and *dy* are the dimensions of the desired tiles. force_scan : int or str **0**\|\ **1**\|\ **2**\|\ **p**\|\ **a**. - + **0**\ : Report range of z after actually scanning the data, not just reporting what the header says. **1**\ : Report median and L1 scale of z (L1 scale = 1.4826 * Median From 140f8e2c01832a13ea70e7bb3413ff42e31f035b Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sat, 6 Feb 2021 07:45:09 +0000 Subject: [PATCH 31/37] Replace short aliases with long form aliases; fix line length issues --- pygmt/modules.py | 22 +++++++++++----------- pygmt/tests/test_grdcut.py | 4 ++-- pygmt/tests/test_grdfilter.py | 4 ++-- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/pygmt/modules.py b/pygmt/modules.py index c3badad7b0a..7d0552a72f4 100644 --- a/pygmt/modules.py +++ b/pygmt/modules.py @@ -45,14 +45,14 @@ def grdinfo(grid, **kwargs): per_column : str or bool **n**\|\ **t**. Formats the report using tab-separated fields on a single line. The - output is name *w e s n z0 z1 dx dy nx ny* [ *x0 y0 x1 y1* ] [ *med scale* ] - [ *mean std rms* ] [ *n_nan* ] *registration gtype*. The data in brackets are - outputted depending on the ``force_scan`` and ``minmax_pos`` arguments. - Use **t** to place file name at the end of the output record or, - **n** or ``True`` to only output numerical columns. The registration is - either 0 (gridline) or 1 (pixel), while gtype is either 0 (Cartesian) - or 1 (geographic). The default value is ``False``. This cannot be - called if ``geographic`` is also set. + output is name *w e s n z0 z1 dx dy nx ny* [ *x0 y0 x1 y1* ] + [ *med scale* ] [ *mean std rms* ] [ *n_nan* ] *registration gtype*. + The data in brackets are outputted depending on the ``force_scan`` + and ``minmax_pos`` arguments. Use **t** to place file name at the end + of the output record or, **n** or ``True`` to only output numerical + columns. The registration is either 0 (gridline) or 1 (pixel), while + gtype is either 0 (Cartesian) or 1 (geographic). The default value is + ``False``. This cannot be called if ``geographic`` is also set. tiles : str or list *xoff*\ [/*yoff*][**+i**]. Divide a single grid's domain (or the ``region`` domain, if no grid @@ -61,8 +61,8 @@ def grdinfo(grid, **kwargs): single grid is given you may use the modifier **+i** to ignore tiles that have no data within each tile subregion. Default output is text region strings. Use ``per_column`` to instead report four columns with - xmin xmax ymin ymax per tile, or use ``per_column="t"`` to also have the - region string appended as trailing text. + xmin xmax ymin ymax per tile, or use ``per_column="t"`` to also have + the region string appended as trailing text. geographic : bool Report grid domain and x/y-increments in world mapping format The default value is ``False``. This cannot be called if @@ -223,7 +223,7 @@ def __init__(self, xarray_obj): # From the shortened summary information of `grdinfo`, # get grid registration in column 10, and grid type in column 11 self._registration, self._gtype = map( - int, grdinfo(self._source, C="n", o="10,11").split() + int, grdinfo(self._source, per_column="n", o="10,11").split() ) except KeyError: self._registration = 0 # Default to Gridline registration diff --git a/pygmt/tests/test_grdcut.py b/pygmt/tests/test_grdcut.py index d3e5d5fbc00..d1676fca669 100644 --- a/pygmt/tests/test_grdcut.py +++ b/pygmt/tests/test_grdcut.py @@ -28,7 +28,7 @@ def test_grdcut_file_in_file_out(): result = grdcut("@earth_relief_01d", outgrid=tmpfile.name, region="0/180/0/90") assert result is None # return value is None assert os.path.exists(path=tmpfile.name) # check that outgrid exists - result = grdinfo(tmpfile.name, C=True) + result = grdinfo(tmpfile.name, per_column=True) assert result == "0 180 0 90 -8182 5651.5 1 1 180 90 1 1\n" @@ -60,7 +60,7 @@ def test_grdcut_dataarray_in_file_out(grid): with GMTTempFile(suffix=".nc") as tmpfile: result = grdcut(grid, outgrid=tmpfile.name, region="0/180/0/90") assert result is None # grdcut returns None if output to a file - result = grdinfo(tmpfile.name, C=True) + result = grdinfo(tmpfile.name, per_column=True) assert result == "0 180 0 90 -8182 5651.5 1 1 180 90 1 1\n" diff --git a/pygmt/tests/test_grdfilter.py b/pygmt/tests/test_grdfilter.py index a69bc0bbf50..bb064327223 100644 --- a/pygmt/tests/test_grdfilter.py +++ b/pygmt/tests/test_grdfilter.py @@ -45,7 +45,7 @@ def test_grdfilter_dataarray_in_file_out(grid): with GMTTempFile(suffix=".nc") as tmpfile: result = grdfilter(grid, outgrid=tmpfile.name, filter="g600", distance="4") assert result is None # grdfilter returns None if output to a file - result = grdinfo(tmpfile.name, C=True) + result = grdinfo(tmpfile.name, per_column=True) assert ( result == "-180 180 -90 90 -6147.47265625 5164.11572266 1 1 360 180 1 1\n" ) @@ -88,7 +88,7 @@ def test_grdfilter_file_in_file_out(): ) assert result is None # return value is None assert os.path.exists(path=tmpfile.name) # check that outgrid exists - result = grdinfo(tmpfile.name, C=True) + result = grdinfo(tmpfile.name, per_column=True) assert result == "0 180 0 90 -6147.49072266 5164.06005859 1 1 180 90 1 1\n" From 584d3e2e71dc749b94bbda4444af674e4217aea8 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sat, 6 Feb 2021 07:55:08 +0000 Subject: [PATCH 32/37] Move grdinfo function to grdinfo.py --- pygmt/__init__.py | 3 +- pygmt/modules.py | 114 +------------------------------------ pygmt/src/__init__.py | 1 + pygmt/src/grdinfo.py | 128 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 132 insertions(+), 114 deletions(-) create mode 100644 pygmt/src/grdinfo.py diff --git a/pygmt/__init__.py b/pygmt/__init__.py index 12c43328d65..f22df6dff7d 100644 --- a/pygmt/__init__.py +++ b/pygmt/__init__.py @@ -14,13 +14,14 @@ # Import modules to make the high-level GMT Python API from pygmt import datasets from pygmt.figure import Figure -from pygmt.modules import GMTDataArrayAccessor, config, grdinfo +from pygmt.modules import GMTDataArrayAccessor, config from pygmt.session_management import begin as _begin from pygmt.session_management import end as _end from pygmt.src import ( blockmedian, grdcut, grdfilter, + grdinfo, grdtrack, info, makecpt, diff --git a/pygmt/modules.py b/pygmt/modules.py index 7d0552a72f4..317c818dc9a 100644 --- a/pygmt/modules.py +++ b/pygmt/modules.py @@ -13,119 +13,7 @@ kwargs_to_strings, use_alias, ) - - -@fmt_docstring -@use_alias( - C="per_column", - D="tiles", - F="geographic", - I="spacing", - T="nearest_multiple", - L="force_scan", - M="minmax_pos", - R="region", - V="verbose", -) -@kwargs_to_strings(R="sequence", D="sequence", I="sequence") -def grdinfo(grid, **kwargs): - r""" - Get information about a grid. - - Can read the grid from a file or given as an xarray.DataArray grid. - - Full option list at :gmt-docs:`grdinfo.html` - - Parameters - ---------- - grid : str or xarray.DataArray - The file name of the input grid or the grid loaded as a DataArray. - This is the only required argument. - {R} - per_column : str or bool - **n**\|\ **t**. - Formats the report using tab-separated fields on a single line. The - output is name *w e s n z0 z1 dx dy nx ny* [ *x0 y0 x1 y1* ] - [ *med scale* ] [ *mean std rms* ] [ *n_nan* ] *registration gtype*. - The data in brackets are outputted depending on the ``force_scan`` - and ``minmax_pos`` arguments. Use **t** to place file name at the end - of the output record or, **n** or ``True`` to only output numerical - columns. The registration is either 0 (gridline) or 1 (pixel), while - gtype is either 0 (Cartesian) or 1 (geographic). The default value is - ``False``. This cannot be called if ``geographic`` is also set. - tiles : str or list - *xoff*\ [/*yoff*][**+i**]. - Divide a single grid's domain (or the ``region`` domain, if no grid - given) into tiles of size dx times dy (set via ``spacing``). You can - specify overlap between tiles by appending *xoff*\ [/*yoff*]. If the - single grid is given you may use the modifier **+i** to ignore tiles - that have no data within each tile subregion. Default output is text - region strings. Use ``per_column`` to instead report four columns with - xmin xmax ymin ymax per tile, or use ``per_column="t"`` to also have - the region string appended as trailing text. - geographic : bool - Report grid domain and x/y-increments in world mapping format - The default value is ``False``. This cannot be called if - ``per_column`` is also set. - spacing : str or list - *dx*\ [/*dy*]\|\ **b**\|\ **i**\|\ **r**. - Report the min/max of the region to the nearest multiple of dx and dy, - and output this in the form w/e/s/n (unless ``per_column`` is set). To - report the actual grid region, append **r**. For a grid produced by - the img supplement (a Cartesian Mercator grid), the exact geographic - region is given with **i** (if not found then we return the actual - grid region instead). If no argument is given then we report the grid - increment in the form *xinc*\ [/*yinc*]. If **b** is given we write - each grid's bounding box polygon instead. Finally, if ``tiles`` is in - effect then *dx* and *dy* are the dimensions of the desired tiles. - force_scan : int or str - **0**\|\ **1**\|\ **2**\|\ **p**\|\ **a**. - - **0**\ : Report range of z after actually scanning the data, not just - reporting what the header says. - **1**\ : Report median and L1 scale of z (L1 scale = 1.4826 * Median - Absolute Deviation (MAD)). - **2**\ : Report mean, standard deviation, and root-mean-square (rms) - of z. - **p**\ : Report mode (LMS) and LMS scale of z. - **a**\ : Include all of the above. - minxmax_pos : bool - Include the x/y values at the location of the minimum and maximum - z-values. - nearest_multiple : str - [*dz*]\ [**+a**\ [*alpha*]]\ [**+s**]. - Determine min and max z-value. If *dz* is provided then we first round - these values off to multiples of *dz*. To exclude the two tails of the - distribution when determining the min and max you can add **+a** to - set the *alpha* value (in percent): We then sort the grid, exclude the - data in the 0.5*\ *alpha* and 100 - 0.5*\ *alpha* tails, and revise - the min and max. To force a symmetrical range about zero, using - minus/plus the max absolute value of the two extremes, append **+s**\ . - We report the result via the text string *zmin/zmax* or *zmin/zmax/dz* - (if *dz* was given) as expected by :meth:`pygmt.makecpt`. - {V} - - Returns - ------- - info : str - A string with information about the grid. - """ - kind = data_kind(grid, None, None) - with GMTTempFile() as outfile: - with Session() as lib: - if kind == "file": - file_context = dummy_context(grid) - elif kind == "grid": - file_context = lib.virtualfile_from_grid(grid) - else: - raise GMTInvalidInput("Unrecognized data type: {}".format(type(grid))) - with file_context as infile: - arg_str = " ".join( - [infile, build_arg_string(kwargs), "->" + outfile.name] - ) - lib.call_module("grdinfo", arg_str) - result = outfile.read() - return result +from pygmt.src.grdinfo import grdinfo class config: # pylint: disable=invalid-name diff --git a/pygmt/src/__init__.py b/pygmt/src/__init__.py index 711af9ca6bd..d32666ac4dd 100644 --- a/pygmt/src/__init__.py +++ b/pygmt/src/__init__.py @@ -5,6 +5,7 @@ from pygmt.src.blockmedian import blockmedian from pygmt.src.grdcut import grdcut from pygmt.src.grdfilter import grdfilter +from pygmt.src.grdinfo import grdinfo from pygmt.src.grdtrack import grdtrack from pygmt.src.info import info from pygmt.src.inset import inset diff --git a/pygmt/src/grdinfo.py b/pygmt/src/grdinfo.py new file mode 100644 index 00000000000..a41f44ccd74 --- /dev/null +++ b/pygmt/src/grdinfo.py @@ -0,0 +1,128 @@ +""" +Non-plot GMT modules. +""" +import xarray as xr +from pygmt.clib import Session +from pygmt.exceptions import GMTInvalidInput +from pygmt.helpers import ( + GMTTempFile, + build_arg_string, + data_kind, + dummy_context, + fmt_docstring, + kwargs_to_strings, + use_alias, +) + + +@fmt_docstring +@use_alias( + C="per_column", + D="tiles", + F="geographic", + I="spacing", + T="nearest_multiple", + L="force_scan", + M="minmax_pos", + R="region", + V="verbose", +) +@kwargs_to_strings(R="sequence", D="sequence", I="sequence") +def grdinfo(grid, **kwargs): + r""" + Get information about a grid. + + Can read the grid from a file or given as an xarray.DataArray grid. + + Full option list at :gmt-docs:`grdinfo.html` + + Parameters + ---------- + grid : str or xarray.DataArray + The file name of the input grid or the grid loaded as a DataArray. + This is the only required argument. + {R} + per_column : str or bool + **n**\|\ **t**. + Formats the report using tab-separated fields on a single line. The + output is name *w e s n z0 z1 dx dy nx ny* [ *x0 y0 x1 y1* ] + [ *med scale* ] [ *mean std rms* ] [ *n_nan* ] *registration gtype*. + The data in brackets are outputted depending on the ``force_scan`` + and ``minmax_pos`` arguments. Use **t** to place file name at the end + of the output record or, **n** or ``True`` to only output numerical + columns. The registration is either 0 (gridline) or 1 (pixel), while + gtype is either 0 (Cartesian) or 1 (geographic). The default value is + ``False``. This cannot be called if ``geographic`` is also set. + tiles : str or list + *xoff*\ [/*yoff*][**+i**]. + Divide a single grid's domain (or the ``region`` domain, if no grid + given) into tiles of size dx times dy (set via ``spacing``). You can + specify overlap between tiles by appending *xoff*\ [/*yoff*]. If the + single grid is given you may use the modifier **+i** to ignore tiles + that have no data within each tile subregion. Default output is text + region strings. Use ``per_column`` to instead report four columns with + xmin xmax ymin ymax per tile, or use ``per_column="t"`` to also have + the region string appended as trailing text. + geographic : bool + Report grid domain and x/y-increments in world mapping format + The default value is ``False``. This cannot be called if + ``per_column`` is also set. + spacing : str or list + *dx*\ [/*dy*]\|\ **b**\|\ **i**\|\ **r**. + Report the min/max of the region to the nearest multiple of dx and dy, + and output this in the form w/e/s/n (unless ``per_column`` is set). To + report the actual grid region, append **r**. For a grid produced by + the img supplement (a Cartesian Mercator grid), the exact geographic + region is given with **i** (if not found then we return the actual + grid region instead). If no argument is given then we report the grid + increment in the form *xinc*\ [/*yinc*]. If **b** is given we write + each grid's bounding box polygon instead. Finally, if ``tiles`` is in + effect then *dx* and *dy* are the dimensions of the desired tiles. + force_scan : int or str + **0**\|\ **1**\|\ **2**\|\ **p**\|\ **a**. + + **0**\ : Report range of z after actually scanning the data, not just + reporting what the header says. + **1**\ : Report median and L1 scale of z (L1 scale = 1.4826 * Median + Absolute Deviation (MAD)). + **2**\ : Report mean, standard deviation, and root-mean-square (rms) + of z. + **p**\ : Report mode (LMS) and LMS scale of z. + **a**\ : Include all of the above. + minxmax_pos : bool + Include the x/y values at the location of the minimum and maximum + z-values. + nearest_multiple : str + [*dz*]\ [**+a**\ [*alpha*]]\ [**+s**]. + Determine min and max z-value. If *dz* is provided then we first round + these values off to multiples of *dz*. To exclude the two tails of the + distribution when determining the min and max you can add **+a** to + set the *alpha* value (in percent): We then sort the grid, exclude the + data in the 0.5*\ *alpha* and 100 - 0.5*\ *alpha* tails, and revise + the min and max. To force a symmetrical range about zero, using + minus/plus the max absolute value of the two extremes, append **+s**\ . + We report the result via the text string *zmin/zmax* or *zmin/zmax/dz* + (if *dz* was given) as expected by :meth:`pygmt.makecpt`. + {V} + + Returns + ------- + info : str + A string with information about the grid. + """ + kind = data_kind(grid, None, None) + with GMTTempFile() as outfile: + with Session() as lib: + if kind == "file": + file_context = dummy_context(grid) + elif kind == "grid": + file_context = lib.virtualfile_from_grid(grid) + else: + raise GMTInvalidInput("Unrecognized data type: {}".format(type(grid))) + with file_context as infile: + arg_str = " ".join( + [infile, build_arg_string(kwargs), "->" + outfile.name] + ) + lib.call_module("grdinfo", arg_str) + result = outfile.read() + return result From 3b1001f1cedf5ae14d0c8c6ccd8e38f8e20ba7f1 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sat, 6 Feb 2021 07:59:05 +0000 Subject: [PATCH 33/37] Remove unused imports --- pygmt/src/grdinfo.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pygmt/src/grdinfo.py b/pygmt/src/grdinfo.py index a41f44ccd74..f2ea07ecbc0 100644 --- a/pygmt/src/grdinfo.py +++ b/pygmt/src/grdinfo.py @@ -1,7 +1,6 @@ """ -Non-plot GMT modules. +Retrieve info about grid file. """ -import xarray as xr from pygmt.clib import Session from pygmt.exceptions import GMTInvalidInput from pygmt.helpers import ( From 0d31d525c278b33ee7515dde2ee8e49406439d89 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sat, 6 Feb 2021 08:17:43 +0000 Subject: [PATCH 34/37] Update pygmt/src/grdinfo.py Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- pygmt/src/grdinfo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/src/grdinfo.py b/pygmt/src/grdinfo.py index f2ea07ecbc0..614e07d0433 100644 --- a/pygmt/src/grdinfo.py +++ b/pygmt/src/grdinfo.py @@ -26,7 +26,7 @@ R="region", V="verbose", ) -@kwargs_to_strings(R="sequence", D="sequence", I="sequence") +@kwargs_to_strings(D="sequence", I="sequence", R="sequence") def grdinfo(grid, **kwargs): r""" Get information about a grid. From fe66e7ed4194232fc182a15d1ea59cb7559545d3 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sat, 6 Feb 2021 09:15:31 +0000 Subject: [PATCH 35/37] Remove unused imports; reorder aliases --- pygmt/modules.py | 9 --------- pygmt/src/grdinfo.py | 2 +- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/pygmt/modules.py b/pygmt/modules.py index 317c818dc9a..2dd6370f57e 100644 --- a/pygmt/modules.py +++ b/pygmt/modules.py @@ -4,15 +4,6 @@ import xarray as xr from pygmt.clib import Session from pygmt.exceptions import GMTInvalidInput -from pygmt.helpers import ( - GMTTempFile, - build_arg_string, - data_kind, - dummy_context, - fmt_docstring, - kwargs_to_strings, - use_alias, -) from pygmt.src.grdinfo import grdinfo diff --git a/pygmt/src/grdinfo.py b/pygmt/src/grdinfo.py index 614e07d0433..41515ab822b 100644 --- a/pygmt/src/grdinfo.py +++ b/pygmt/src/grdinfo.py @@ -20,10 +20,10 @@ D="tiles", F="geographic", I="spacing", - T="nearest_multiple", L="force_scan", M="minmax_pos", R="region", + T="nearest_multiple", V="verbose", ) @kwargs_to_strings(D="sequence", I="sequence", R="sequence") From 994e7dad8351f6cb3edd25ce6b036fa2f849df0f Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Sun, 7 Feb 2021 06:10:37 +1300 Subject: [PATCH 36/37] Update pygmt/src/grdinfo.py Co-authored-by: Dongdong Tian --- pygmt/src/grdinfo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/src/grdinfo.py b/pygmt/src/grdinfo.py index 41515ab822b..ab9ad6b26fa 100644 --- a/pygmt/src/grdinfo.py +++ b/pygmt/src/grdinfo.py @@ -1,5 +1,5 @@ """ -Retrieve info about grid file. +grdinfo - Retrieve info about grid file. """ from pygmt.clib import Session from pygmt.exceptions import GMTInvalidInput From 5c03c7aea88d2d4af3bea17743ef20dbae923d86 Mon Sep 17 00:00:00 2001 From: actions-bot <58130806+actions-bot@users.noreply.github.com> Date: Sun, 7 Feb 2021 10:15:56 +0000 Subject: [PATCH 37/37] [format-command] fixes --- pygmt/src/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/src/__init__.py b/pygmt/src/__init__.py index 41567b7764c..132cb80cece 100644 --- a/pygmt/src/__init__.py +++ b/pygmt/src/__init__.py @@ -10,8 +10,8 @@ from pygmt.src.grdcontour import grdcontour from pygmt.src.grdcut import grdcut from pygmt.src.grdfilter import grdfilter -from pygmt.src.grdinfo import grdinfo from pygmt.src.grdimage import grdimage +from pygmt.src.grdinfo import grdinfo from pygmt.src.grdtrack import grdtrack from pygmt.src.grdview import grdview from pygmt.src.image import image