From 90071705dd92c5625fd125e591fd6535a460fbf5 Mon Sep 17 00:00:00 2001 From: JingHuiTong Date: Wed, 11 Jan 2023 12:44:16 +0800 Subject: [PATCH 01/24] alias surface.py T=tensor --- pygmt/src/surface.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pygmt/src/surface.py b/pygmt/src/surface.py index fc0869c3926..b7137471099 100644 --- a/pygmt/src/surface.py +++ b/pygmt/src/surface.py @@ -20,6 +20,7 @@ I="spacing", R="region", G="outgrid", + T='tensor', V="verbose", a="aspatial", b="binary", From 4b62f0ed9304f85586ee293584b803120077a1da Mon Sep 17 00:00:00 2001 From: JingHuiTong Date: Fri, 13 Jan 2023 18:38:04 +0800 Subject: [PATCH 02/24] surface.py add tension documnets --- pygmt/src/surface.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pygmt/src/surface.py b/pygmt/src/surface.py index b7137471099..5cd92e71a38 100644 --- a/pygmt/src/surface.py +++ b/pygmt/src/surface.py @@ -20,7 +20,7 @@ I="spacing", R="region", G="outgrid", - T='tensor', + T="tension", V="verbose", a="aspatial", b="binary", @@ -69,6 +69,16 @@ def surface(data=None, x=None, y=None, z=None, **kwargs): outgrid : str Optional. The file name for the output netcdf file with extension .nc to store the grid in. + tension: float or str + [**b**\|\ **i**] + Optional. These must be between 0 and 1. + Tension may be used in the interior solution (above equation, + where it suppresses spurious oscillations) and in the boundary conditions + (where it tends to flatten the solution approaching the edges). + Add **i**\ tension to set interior tension, and **b**\ tension to set boundary tension. + If you do not prepend **i**\ or **b**\, both will be set to the same value. + [Default = 0 for both gives minimum curvature solution.] + {verbose} {aspatial} From 803a27890cf5f570193fe3c4fe79d6890fe0902f Mon Sep 17 00:00:00 2001 From: JingHuiTong Date: Fri, 13 Jan 2023 23:26:29 +0800 Subject: [PATCH 03/24] surface add -L -M -C: --- pygmt/src/surface.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pygmt/src/surface.py b/pygmt/src/surface.py index 5cd92e71a38..43bf6469579 100644 --- a/pygmt/src/surface.py +++ b/pygmt/src/surface.py @@ -17,9 +17,12 @@ @fmt_docstring @use_alias( + C="convergence", I="spacing", + L="limit", R="region", G="outgrid", + M="max_radius", T="tension", V="verbose", a="aspatial", @@ -69,6 +72,25 @@ def surface(data=None, x=None, y=None, z=None, **kwargs): outgrid : str Optional. The file name for the output netcdf file with extension .nc to store the grid in. + convergence: float + Optional. Convergence limit. Iteration is assumed to have converged when the maximum + absolute change in any grid value is less than convergence_limit. + (Units same as data z units). Alternatively, give limit in percentage + of rms deviation by appending %. [Default is scaled to of the + root-mean-square deviation of the data from a best-fit (least-squares) plane.]. + This is the final convergence limit at the desired grid spacing; + for intermediate (coarser) grids the effective convergence limit + is divided by the grid spacing multiplier. + max_radius: str + Optional. After solving for the surface, apply a mask so that nodes farther than + max_radius away from a data constraint are set to NaN [no masking]. + Append a distance unit (see Units) if needed. One can also select the nodes to mask by + using the n_cells**c**\ form. Here n_cells means the number of cells around the node + controlled by a data point. As an example **0c**\ means that only the cell where the point + lies is filled, **1c**\ keeps one cell beyond that + (i.e. makes a 3x3 square neighborhood), and so on. + limit: float + tension: float or str [**b**\|\ **i**] Optional. These must be between 0 and 1. From fc0ba0816491cf89cdf9259978d4d49e2ebae5ba Mon Sep 17 00:00:00 2001 From: Tong <86273921+JingHuiTong@users.noreply.github.com> Date: Sat, 14 Jan 2023 23:20:34 +0800 Subject: [PATCH 04/24] Apply suggestions from code review Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- pygmt/src/surface.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pygmt/src/surface.py b/pygmt/src/surface.py index 43bf6469579..c3247dd881b 100644 --- a/pygmt/src/surface.py +++ b/pygmt/src/surface.py @@ -20,9 +20,9 @@ C="convergence", I="spacing", L="limit", + M="max_radius", R="region", G="outgrid", - M="max_radius", T="tension", V="verbose", a="aspatial", @@ -72,7 +72,7 @@ def surface(data=None, x=None, y=None, z=None, **kwargs): outgrid : str Optional. The file name for the output netcdf file with extension .nc to store the grid in. - convergence: float + convergence : float Optional. Convergence limit. Iteration is assumed to have converged when the maximum absolute change in any grid value is less than convergence_limit. (Units same as data z units). Alternatively, give limit in percentage @@ -81,7 +81,7 @@ def surface(data=None, x=None, y=None, z=None, **kwargs): This is the final convergence limit at the desired grid spacing; for intermediate (coarser) grids the effective convergence limit is divided by the grid spacing multiplier. - max_radius: str + max_radius : str Optional. After solving for the surface, apply a mask so that nodes farther than max_radius away from a data constraint are set to NaN [no masking]. Append a distance unit (see Units) if needed. One can also select the nodes to mask by @@ -91,8 +91,8 @@ def surface(data=None, x=None, y=None, z=None, **kwargs): (i.e. makes a 3x3 square neighborhood), and so on. limit: float - tension: float or str - [**b**\|\ **i**] + tension : float or str + [**b**\|\ **i**]. Optional. These must be between 0 and 1. Tension may be used in the interior solution (above equation, where it suppresses spurious oscillations) and in the boundary conditions From fbe59e239d009ef51918594e6fcd554ef831b337 Mon Sep 17 00:00:00 2001 From: JingHuiTong Date: Sat, 14 Jan 2023 22:54:28 +0800 Subject: [PATCH 05/24] surface add document: limit upper & lower --- pygmt/src/surface.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/pygmt/src/surface.py b/pygmt/src/surface.py index c3247dd881b..34957e7c5dd 100644 --- a/pygmt/src/surface.py +++ b/pygmt/src/surface.py @@ -21,6 +21,8 @@ I="spacing", L="limit", M="max_radius", + Ll="lower", + Lu="upper", R="region", G="outgrid", T="tension", @@ -89,9 +91,19 @@ def surface(data=None, x=None, y=None, z=None, **kwargs): controlled by a data point. As an example **0c**\ means that only the cell where the point lies is filled, **1c**\ keeps one cell beyond that (i.e. makes a 3x3 square neighborhood), and so on. - limit: float - - tension : float or str + lower: float + Optional. Impose limits on the output solution. Directive *lower*\ sets the lower bound. + *lower*\ can be the name of a grid file with lower bound values, a fixed value, + **d**\ to set to minimum input value, or **u**\ for unconstrained [Default] + Grid files used to set the limits may contain NaNs. In the presence of NaNs, + the limit of a node masked with NaN is unconstrained. + upper: float + Optional. Impose limits on the output solution. Directive *upper*\ sets the upper bound and + can be the name of a grid file with upper bound values, a fixed value, + **d**\ to set to maximum input value, or **u**\ for unconstrained [Default]. + Grid files used to set the limits may contain NaNs. In the presence of NaNs, + the limit of a node masked with NaN is unconstrained. + tension: float or str [**b**\|\ **i**]. Optional. These must be between 0 and 1. Tension may be used in the interior solution (above equation, From 6cf98c83eb265c306cd9697eabac139d74323d13 Mon Sep 17 00:00:00 2001 From: Tong <86273921+JingHuiTong@users.noreply.github.com> Date: Sat, 14 Jan 2023 23:48:21 +0800 Subject: [PATCH 06/24] Apply suggestions from code review Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- pygmt/src/surface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/src/surface.py b/pygmt/src/surface.py index 34957e7c5dd..99cbac0a120 100644 --- a/pygmt/src/surface.py +++ b/pygmt/src/surface.py @@ -83,7 +83,7 @@ def surface(data=None, x=None, y=None, z=None, **kwargs): This is the final convergence limit at the desired grid spacing; for intermediate (coarser) grids the effective convergence limit is divided by the grid spacing multiplier. - max_radius : str + max_radius : int or str Optional. After solving for the surface, apply a mask so that nodes farther than max_radius away from a data constraint are set to NaN [no masking]. Append a distance unit (see Units) if needed. One can also select the nodes to mask by From f917d9d17c0448c5d88ce6da284b6766af908128 Mon Sep 17 00:00:00 2001 From: Tong <86273921+JingHuiTong@users.noreply.github.com> Date: Sun, 15 Jan 2023 22:39:23 +0800 Subject: [PATCH 07/24] Apply suggestions from code review Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- pygmt/src/surface.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pygmt/src/surface.py b/pygmt/src/surface.py index 99cbac0a120..95f2322b8df 100644 --- a/pygmt/src/surface.py +++ b/pygmt/src/surface.py @@ -78,7 +78,7 @@ def surface(data=None, x=None, y=None, z=None, **kwargs): Optional. Convergence limit. Iteration is assumed to have converged when the maximum absolute change in any grid value is less than convergence_limit. (Units same as data z units). Alternatively, give limit in percentage - of rms deviation by appending %. [Default is scaled to of the + of rms deviation by appending %. [Default is scaled to :math:`10^{{-4}}` of the root-mean-square deviation of the data from a best-fit (least-squares) plane.]. This is the final convergence limit at the desired grid spacing; for intermediate (coarser) grids the effective convergence limit @@ -91,19 +91,19 @@ def surface(data=None, x=None, y=None, z=None, **kwargs): controlled by a data point. As an example **0c**\ means that only the cell where the point lies is filled, **1c**\ keeps one cell beyond that (i.e. makes a 3x3 square neighborhood), and so on. - lower: float + lower : float or str Optional. Impose limits on the output solution. Directive *lower*\ sets the lower bound. *lower*\ can be the name of a grid file with lower bound values, a fixed value, **d**\ to set to minimum input value, or **u**\ for unconstrained [Default] Grid files used to set the limits may contain NaNs. In the presence of NaNs, the limit of a node masked with NaN is unconstrained. - upper: float + upper : float or str Optional. Impose limits on the output solution. Directive *upper*\ sets the upper bound and can be the name of a grid file with upper bound values, a fixed value, **d**\ to set to maximum input value, or **u**\ for unconstrained [Default]. Grid files used to set the limits may contain NaNs. In the presence of NaNs, the limit of a node masked with NaN is unconstrained. - tension: float or str + tension : float or str [**b**\|\ **i**]. Optional. These must be between 0 and 1. Tension may be used in the interior solution (above equation, From add6d0a2a89200287284ff86435eb0d3663e53fd Mon Sep 17 00:00:00 2001 From: JingHuiTong Date: Sun, 15 Jan 2023 23:46:50 +0800 Subject: [PATCH 08/24] /format --- pygmt/src/surface.py | 69 ++++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 32 deletions(-) diff --git a/pygmt/src/surface.py b/pygmt/src/surface.py index 95f2322b8df..75c3cd5eaeb 100644 --- a/pygmt/src/surface.py +++ b/pygmt/src/surface.py @@ -75,43 +75,48 @@ def surface(data=None, x=None, y=None, z=None, **kwargs): Optional. The file name for the output netcdf file with extension .nc to store the grid in. convergence : float - Optional. Convergence limit. Iteration is assumed to have converged when the maximum - absolute change in any grid value is less than convergence_limit. - (Units same as data z units). Alternatively, give limit in percentage - of rms deviation by appending %. [Default is scaled to :math:`10^{{-4}}` of the - root-mean-square deviation of the data from a best-fit (least-squares) plane.]. - This is the final convergence limit at the desired grid spacing; - for intermediate (coarser) grids the effective convergence limit - is divided by the grid spacing multiplier. + Optional. Convergence limit. Iteration is assumed to have converged + when the maximum absolute change in any grid value is less than + *convergence_limit*. (Units same as data z units). Alternatively, + give limit in percentage of rms deviation by appending %. [Default + is scaled to :math:`10^{{-4}}` of the root-mean-square deviation of + the data from a best-fit (least-squares) plane.]. This is the final + convergence limit at the desired grid spacing; for intermediate + (coarser) grids the effective convergence limit is divided by the + grid spacing multiplier. max_radius : int or str - Optional. After solving for the surface, apply a mask so that nodes farther than - max_radius away from a data constraint are set to NaN [no masking]. - Append a distance unit (see Units) if needed. One can also select the nodes to mask by - using the n_cells**c**\ form. Here n_cells means the number of cells around the node - controlled by a data point. As an example **0c**\ means that only the cell where the point - lies is filled, **1c**\ keeps one cell beyond that - (i.e. makes a 3x3 square neighborhood), and so on. + Optional. After solving for the surface, apply a mask so that nodes + farther than max_radius away from a data constraint are set to NaN + [no masking]. Append a distance unit (see Units) if needed. One can + also select the nodes to mask by using the *n_cells*\**c** form. + Here *n_cells* means the number of cells around the node controlled + by a data point. As an example **0c** means that only the cell where + the point lies is filled, **1c** keeps one cell beyond that (i.e. + makes a 3x3 square neighborhood), and so on. lower : float or str - Optional. Impose limits on the output solution. Directive *lower*\ sets the lower bound. - *lower*\ can be the name of a grid file with lower bound values, a fixed value, - **d**\ to set to minimum input value, or **u**\ for unconstrained [Default] - Grid files used to set the limits may contain NaNs. In the presence of NaNs, - the limit of a node masked with NaN is unconstrained. + Optional. Impose limits on the output solution. Directive *lower* + sets the lower bound. *lower* can be the name of a grid file with + lower bound values, a fixed value, **d** to set to minimum input + value, or **u** for unconstrained [Default]. Grid files used to set + the limits may contain NaNs. In the presence of NaNs, the limit of + a node masked with NaN is unconstrained. upper : float or str - Optional. Impose limits on the output solution. Directive *upper*\ sets the upper bound and - can be the name of a grid file with upper bound values, a fixed value, - **d**\ to set to maximum input value, or **u**\ for unconstrained [Default]. - Grid files used to set the limits may contain NaNs. In the presence of NaNs, - the limit of a node masked with NaN is unconstrained. + Optional. Impose limits on the output solution. Directive *upper* + sets the upper bound and can be the name of a grid file with upper + bound values, a fixed value, **d** to set to maximum input value, + or **u** for unconstrained [Default]. Grid files used to set the + limits may contain NaNs. In the presence of NaNs, the limit of a + node masked with NaN is unconstrained. tension : float or str [**b**\|\ **i**]. - Optional. These must be between 0 and 1. - Tension may be used in the interior solution (above equation, - where it suppresses spurious oscillations) and in the boundary conditions - (where it tends to flatten the solution approaching the edges). - Add **i**\ tension to set interior tension, and **b**\ tension to set boundary tension. - If you do not prepend **i**\ or **b**\, both will be set to the same value. - [Default = 0 for both gives minimum curvature solution.] + Optional. Tension factor[s]. These must be between 0 and 1. Tension + may be used in the interior solution (above equation, where it + suppresses spurious oscillations) and in the boundary conditions + (where it tends to flatten the solution approaching the edges). Add + **i**\*tension* to set interior tension, and **b**\*tension*\ to + set boundary tension. If you do not prepend **i** or **b**, both + will be set to the same value. [Default = 0 for both gives minimum + curvature solution.] {verbose} From 5c77c5fde621f4c029f3a8989a104bb6e641d257 Mon Sep 17 00:00:00 2001 From: JingHuiTong Date: Mon, 16 Jan 2023 00:07:34 +0800 Subject: [PATCH 09/24] format --- pygmt/src/surface.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pygmt/src/surface.py b/pygmt/src/surface.py index 75c3cd5eaeb..2a5914540b6 100644 --- a/pygmt/src/surface.py +++ b/pygmt/src/surface.py @@ -18,13 +18,12 @@ @fmt_docstring @use_alias( C="convergence", + G="outgrid", I="spacing", - L="limit", - M="max_radius", Ll="lower", Lu="upper", + M="max_radius", R="region", - G="outgrid", T="tension", V="verbose", a="aspatial", @@ -88,7 +87,7 @@ def surface(data=None, x=None, y=None, z=None, **kwargs): Optional. After solving for the surface, apply a mask so that nodes farther than max_radius away from a data constraint are set to NaN [no masking]. Append a distance unit (see Units) if needed. One can - also select the nodes to mask by using the *n_cells*\**c** form. + also select the nodes to mask by using the *n_cells*\**c**\ form. Here *n_cells* means the number of cells around the node controlled by a data point. As an example **0c** means that only the cell where the point lies is filled, **1c** keeps one cell beyond that (i.e. @@ -98,8 +97,8 @@ def surface(data=None, x=None, y=None, z=None, **kwargs): sets the lower bound. *lower* can be the name of a grid file with lower bound values, a fixed value, **d** to set to minimum input value, or **u** for unconstrained [Default]. Grid files used to set - the limits may contain NaNs. In the presence of NaNs, the limit of - a node masked with NaN is unconstrained. + the limits may contain NaNs. In the presence of NaNs, the limit of + a node masked with NaN is unconstrained. upper : float or str Optional. Impose limits on the output solution. Directive *upper* sets the upper bound and can be the name of a grid file with upper @@ -113,7 +112,7 @@ def surface(data=None, x=None, y=None, z=None, **kwargs): may be used in the interior solution (above equation, where it suppresses spurious oscillations) and in the boundary conditions (where it tends to flatten the solution approaching the edges). Add - **i**\*tension* to set interior tension, and **b**\*tension*\ to + **i**\*tension*\ to set interior tension, and **b**\*tension*\ to set boundary tension. If you do not prepend **i** or **b**, both will be set to the same value. [Default = 0 for both gives minimum curvature solution.] From ae90cc30ce184f9bfcb1131f813ebaef64024093 Mon Sep 17 00:00:00 2001 From: JingHuiTong Date: Mon, 16 Jan 2023 14:29:20 +0800 Subject: [PATCH 10/24] format bold and space --- pygmt/src/surface.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pygmt/src/surface.py b/pygmt/src/surface.py index 2a5914540b6..2320207e882 100644 --- a/pygmt/src/surface.py +++ b/pygmt/src/surface.py @@ -87,7 +87,7 @@ def surface(data=None, x=None, y=None, z=None, **kwargs): Optional. After solving for the surface, apply a mask so that nodes farther than max_radius away from a data constraint are set to NaN [no masking]. Append a distance unit (see Units) if needed. One can - also select the nodes to mask by using the *n_cells*\**c**\ form. + also select the nodes to mask by using the *n_cells***c** form. Here *n_cells* means the number of cells around the node controlled by a data point. As an example **0c** means that only the cell where the point lies is filled, **1c** keeps one cell beyond that (i.e. @@ -112,7 +112,7 @@ def surface(data=None, x=None, y=None, z=None, **kwargs): may be used in the interior solution (above equation, where it suppresses spurious oscillations) and in the boundary conditions (where it tends to flatten the solution approaching the edges). Add - **i**\*tension*\ to set interior tension, and **b**\*tension*\ to + **i***tension* to set interior tension, and **b***tension* to set boundary tension. If you do not prepend **i** or **b**, both will be set to the same value. [Default = 0 for both gives minimum curvature solution.] From 9d194058f7503ef755499d7f3820d8dbe2afe337 Mon Sep 17 00:00:00 2001 From: Tong <86273921+JingHuiTong@users.noreply.github.com> Date: Sat, 21 Jan 2023 15:48:42 +0800 Subject: [PATCH 11/24] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Yvonne Fröhlich <94163266+yvonnefroehlich@users.noreply.github.com> --- pygmt/src/surface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/src/surface.py b/pygmt/src/surface.py index 2320207e882..1b3a8b3ea80 100644 --- a/pygmt/src/surface.py +++ b/pygmt/src/surface.py @@ -22,7 +22,7 @@ I="spacing", Ll="lower", Lu="upper", - M="max_radius", + M="maxradius", R="region", T="tension", V="verbose", From 38e80c064babaa10e896da4cd8b533de90c03175 Mon Sep 17 00:00:00 2001 From: Tong <86273921+JingHuiTong@users.noreply.github.com> Date: Sat, 21 Jan 2023 15:49:31 +0800 Subject: [PATCH 12/24] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Yvonne Fröhlich <94163266+yvonnefroehlich@users.noreply.github.com> --- pygmt/src/surface.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pygmt/src/surface.py b/pygmt/src/surface.py index 1b3a8b3ea80..66c7d39a3f0 100644 --- a/pygmt/src/surface.py +++ b/pygmt/src/surface.py @@ -83,15 +83,15 @@ def surface(data=None, x=None, y=None, z=None, **kwargs): convergence limit at the desired grid spacing; for intermediate (coarser) grids the effective convergence limit is divided by the grid spacing multiplier. - max_radius : int or str + maxradius : int or str Optional. After solving for the surface, apply a mask so that nodes farther than max_radius away from a data constraint are set to NaN - [no masking]. Append a distance unit (see Units) if needed. One can - also select the nodes to mask by using the *n_cells***c** form. - Here *n_cells* means the number of cells around the node controlled - by a data point. As an example **0c** means that only the cell where - the point lies is filled, **1c** keeps one cell beyond that (i.e. - makes a 3x3 square neighborhood), and so on. + [Default is no masking]. Append a distance unit (see Units) if needed. + One can also select the nodes to mask by using the *n_cells*\ **c** + form. Here *n_cells* means the number of cells around the node + controlled by a data point. As an example ``"0c"`` means that only + the cell where the point lies is filled, ``"1c"`` keeps one cell + beyond that (i.e. makes a 3x3 square neighborhood), and so on. lower : float or str Optional. Impose limits on the output solution. Directive *lower* sets the lower bound. *lower* can be the name of a grid file with @@ -112,10 +112,10 @@ def surface(data=None, x=None, y=None, z=None, **kwargs): may be used in the interior solution (above equation, where it suppresses spurious oscillations) and in the boundary conditions (where it tends to flatten the solution approaching the edges). Add - **i***tension* to set interior tension, and **b***tension* to + **i**\ *tension* to set interior tension, and **b**\ *tension* to set boundary tension. If you do not prepend **i** or **b**, both - will be set to the same value. [Default = 0 for both gives minimum - curvature solution.] + will be set to the same value. [Default is 0 for both and gives + minimum curvature solution.] {verbose} From 68f7fbfef454ce2f28634706697b404f6bf8deb7 Mon Sep 17 00:00:00 2001 From: JingHuiTong Date: Sat, 21 Jan 2023 16:27:31 +0800 Subject: [PATCH 13/24] add Unit links --- pygmt/src/surface.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/pygmt/src/surface.py b/pygmt/src/surface.py index 66c7d39a3f0..252c8cf1ba3 100644 --- a/pygmt/src/surface.py +++ b/pygmt/src/surface.py @@ -85,13 +85,14 @@ def surface(data=None, x=None, y=None, z=None, **kwargs): grid spacing multiplier. maxradius : int or str Optional. After solving for the surface, apply a mask so that nodes - farther than max_radius away from a data constraint are set to NaN - [Default is no masking]. Append a distance unit (see Units) if needed. - One can also select the nodes to mask by using the *n_cells*\ **c** - form. Here *n_cells* means the number of cells around the node - controlled by a data point. As an example ``"0c"`` means that only - the cell where the point lies is filled, ``"1c"`` keeps one cell - beyond that (i.e. makes a 3x3 square neighborhood), and so on. + farther than *maxradius* away from a data constraint are set to NaN + [Default is no masking]. Append a distance unit (see gmt-docs:`Units + `) if needed. One can also select the nodes to + mask by using the *n_cells*\ **c** form. Here *n_cells* means the + number of cells around the node is controlled by a data point. As an + example ``"0c"`` means that only the cell where the point lies is + filled, ``"1c"`` keeps one cell beyond that (i.e. makes a 3x3 square + neighborhood), and so on. lower : float or str Optional. Impose limits on the output solution. Directive *lower* sets the lower bound. *lower* can be the name of a grid file with @@ -116,8 +117,6 @@ def surface(data=None, x=None, y=None, z=None, **kwargs): set boundary tension. If you do not prepend **i** or **b**, both will be set to the same value. [Default is 0 for both and gives minimum curvature solution.] - - {verbose} {aspatial} {binary} From 78f721c903b348fe29ff234e7ee3b957c4b27ed6 Mon Sep 17 00:00:00 2001 From: JingHuiTong Date: Sat, 21 Jan 2023 17:05:33 +0800 Subject: [PATCH 14/24] add Unit links with : --- pygmt/src/surface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/src/surface.py b/pygmt/src/surface.py index 252c8cf1ba3..4df3b1a865a 100644 --- a/pygmt/src/surface.py +++ b/pygmt/src/surface.py @@ -86,7 +86,7 @@ def surface(data=None, x=None, y=None, z=None, **kwargs): maxradius : int or str Optional. After solving for the surface, apply a mask so that nodes farther than *maxradius* away from a data constraint are set to NaN - [Default is no masking]. Append a distance unit (see gmt-docs:`Units + [Default is no masking]. Append a distance unit (see :gmt-docs:`Units `) if needed. One can also select the nodes to mask by using the *n_cells*\ **c** form. Here *n_cells* means the number of cells around the node is controlled by a data point. As an From 15680a7a1d41b84fd2e313f661009140ec842617 Mon Sep 17 00:00:00 2001 From: JingHuiTong Date: Sat, 21 Jan 2023 17:28:17 +0800 Subject: [PATCH 15/24] add Unit links --- pygmt/src/surface.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pygmt/src/surface.py b/pygmt/src/surface.py index 4df3b1a865a..a16a4b0481e 100644 --- a/pygmt/src/surface.py +++ b/pygmt/src/surface.py @@ -86,13 +86,13 @@ def surface(data=None, x=None, y=None, z=None, **kwargs): maxradius : int or str Optional. After solving for the surface, apply a mask so that nodes farther than *maxradius* away from a data constraint are set to NaN - [Default is no masking]. Append a distance unit (see :gmt-docs:`Units - `) if needed. One can also select the nodes to - mask by using the *n_cells*\ **c** form. Here *n_cells* means the - number of cells around the node is controlled by a data point. As an - example ``"0c"`` means that only the cell where the point lies is - filled, ``"1c"`` keeps one cell beyond that (i.e. makes a 3x3 square - neighborhood), and so on. + [Default is no masking]. Append a distance unit (See + :gmt-docs:`Units `) if needed. One can also + select the nodes to mask by using the *n_cells*\ **c** form. Here + *n_cells* means the number of cells around the node is controlled + by a data point. As an example ``"0c"`` means that only the cell + where the point lies is filled, ``"1c"`` keeps one cell beyond + that (i.e. makes a 3x3 square neighborhood), and so on. lower : float or str Optional. Impose limits on the output solution. Directive *lower* sets the lower bound. *lower* can be the name of a grid file with From c6fcf499e1ce8ab44d39d642637f84952f437043 Mon Sep 17 00:00:00 2001 From: JingHuiTong Date: Sat, 21 Jan 2023 18:49:45 +0800 Subject: [PATCH 16/24] adding grdgradient_shading --- .../gallery/images/grdgradient_shading.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 examples/gallery/images/grdgradient_shading.py diff --git a/examples/gallery/images/grdgradient_shading.py b/examples/gallery/images/grdgradient_shading.py new file mode 100644 index 00000000000..0f3f0fb366e --- /dev/null +++ b/examples/gallery/images/grdgradient_shading.py @@ -0,0 +1,25 @@ +import pygmt + +# Define region of interest around Caucasus +region = [39, 50, 40, 45] + +# Load sample grid (3 arc-seconds global relief) in target area +grid = pygmt.datasets.load_earth_relief(resolution="03s", region=region) + +cmap = pygmt.makecpt(cmap='terra', series=[-5000, 5000]) +fig = pygmt.Figure() +with fig.subplot(nrows=3, ncols=3, figsize=("20c", "20c")): + for i, rad in enumerate(['210/0','210/45', '210/90']):#, 0.5, 1]: + for j, nor in enumerate([1, 10, 20]): + index = i * 3 + j + dgrid = pygmt.grdgradient(grid=grid, radiance=rad, normalize=nor) + + with fig.set_panel(panel=index): + fig.grdimage( + grid=grid, + projection="M5c", + frame=["WSrt", "a2f1"], + cmap=cmap + ) + +fig.show() From bffc4c27f166572b78c7305f8a1d5ec9c960ee3e Mon Sep 17 00:00:00 2001 From: actions-bot <58130806+actions-bot@users.noreply.github.com> Date: Mon, 23 Jan 2023 13:38:27 +0000 Subject: [PATCH 17/24] [format-command] fixes --- pygmt/src/surface.py | 70 ++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/pygmt/src/surface.py b/pygmt/src/surface.py index a0096968446..dc0fc07eefc 100644 --- a/pygmt/src/surface.py +++ b/pygmt/src/surface.py @@ -74,48 +74,48 @@ def surface(data=None, x=None, y=None, z=None, **kwargs): Optional. The file name for the output netcdf file with extension .nc to store the grid in. convergence : float - Optional. Convergence limit. Iteration is assumed to have converged - when the maximum absolute change in any grid value is less than - *convergence_limit*. (Units same as data z units). Alternatively, - give limit in percentage of rms deviation by appending %. [Default - is scaled to :math:`10^{{-4}}` of the root-mean-square deviation of - the data from a best-fit (least-squares) plane.]. This is the final - convergence limit at the desired grid spacing; for intermediate - (coarser) grids the effective convergence limit is divided by the + Optional. Convergence limit. Iteration is assumed to have converged + when the maximum absolute change in any grid value is less than + *convergence_limit*. (Units same as data z units). Alternatively, + give limit in percentage of rms deviation by appending %. [Default + is scaled to :math:`10^{{-4}}` of the root-mean-square deviation of + the data from a best-fit (least-squares) plane.]. This is the final + convergence limit at the desired grid spacing; for intermediate + (coarser) grids the effective convergence limit is divided by the grid spacing multiplier. maxradius : int or str - Optional. After solving for the surface, apply a mask so that nodes - farther than *maxradius* away from a data constraint are set to NaN - [Default is no masking]. Append a distance unit (See - :gmt-docs:`Units `) if needed. One can also - select the nodes to mask by using the *n_cells*\ **c** form. Here - *n_cells* means the number of cells around the node is controlled - by a data point. As an example ``"0c"`` means that only the cell - where the point lies is filled, ``"1c"`` keeps one cell beyond + Optional. After solving for the surface, apply a mask so that nodes + farther than *maxradius* away from a data constraint are set to NaN + [Default is no masking]. Append a distance unit (See + :gmt-docs:`Units `) if needed. One can also + select the nodes to mask by using the *n_cells*\ **c** form. Here + *n_cells* means the number of cells around the node is controlled + by a data point. As an example ``"0c"`` means that only the cell + where the point lies is filled, ``"1c"`` keeps one cell beyond that (i.e. makes a 3x3 square neighborhood), and so on. lower : float or str - Optional. Impose limits on the output solution. Directive *lower* - sets the lower bound. *lower* can be the name of a grid file with - lower bound values, a fixed value, **d** to set to minimum input - value, or **u** for unconstrained [Default]. Grid files used to set - the limits may contain NaNs. In the presence of NaNs, the limit of - a node masked with NaN is unconstrained. + Optional. Impose limits on the output solution. Directive *lower* + sets the lower bound. *lower* can be the name of a grid file with + lower bound values, a fixed value, **d** to set to minimum input + value, or **u** for unconstrained [Default]. Grid files used to set + the limits may contain NaNs. In the presence of NaNs, the limit of + a node masked with NaN is unconstrained. upper : float or str - Optional. Impose limits on the output solution. Directive *upper* - sets the upper bound and can be the name of a grid file with upper - bound values, a fixed value, **d** to set to maximum input value, - or **u** for unconstrained [Default]. Grid files used to set the - limits may contain NaNs. In the presence of NaNs, the limit of a - node masked with NaN is unconstrained. + Optional. Impose limits on the output solution. Directive *upper* + sets the upper bound and can be the name of a grid file with upper + bound values, a fixed value, **d** to set to maximum input value, + or **u** for unconstrained [Default]. Grid files used to set the + limits may contain NaNs. In the presence of NaNs, the limit of a + node masked with NaN is unconstrained. tension : float or str [**b**\|\ **i**]. - Optional. Tension factor[s]. These must be between 0 and 1. Tension - may be used in the interior solution (above equation, where it - suppresses spurious oscillations) and in the boundary conditions - (where it tends to flatten the solution approaching the edges). Add - **i**\ *tension* to set interior tension, and **b**\ *tension* to - set boundary tension. If you do not prepend **i** or **b**, both - will be set to the same value. [Default is 0 for both and gives + Optional. Tension factor[s]. These must be between 0 and 1. Tension + may be used in the interior solution (above equation, where it + suppresses spurious oscillations) and in the boundary conditions + (where it tends to flatten the solution approaching the edges). Add + **i**\ *tension* to set interior tension, and **b**\ *tension* to + set boundary tension. If you do not prepend **i** or **b**, both + will be set to the same value. [Default is 0 for both and gives minimum curvature solution.] {verbose} {aspatial} From 8c9505ad997895e52b6c1f73d16e51371fb90976 Mon Sep 17 00:00:00 2001 From: Tong <86273921+JingHuiTong@users.noreply.github.com> Date: Fri, 27 Jan 2023 15:23:08 +0800 Subject: [PATCH 18/24] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> Co-authored-by: Yvonne Fröhlich <94163266+yvonnefroehlich@users.noreply.github.com> --- pygmt/src/surface.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pygmt/src/surface.py b/pygmt/src/surface.py index dc0fc07eefc..035eabe3227 100644 --- a/pygmt/src/surface.py +++ b/pygmt/src/surface.py @@ -73,13 +73,13 @@ def surface(data=None, x=None, y=None, z=None, **kwargs): outgrid : str Optional. The file name for the output netcdf file with extension .nc to store the grid in. - convergence : float + convergence : float or str Optional. Convergence limit. Iteration is assumed to have converged when the maximum absolute change in any grid value is less than *convergence_limit*. (Units same as data z units). Alternatively, give limit in percentage of rms deviation by appending %. [Default is scaled to :math:`10^{{-4}}` of the root-mean-square deviation of - the data from a best-fit (least-squares) plane.]. This is the final + the data from a best-fit (least-squares) plane.] This is the final convergence limit at the desired grid spacing; for intermediate (coarser) grids the effective convergence limit is divided by the grid spacing multiplier. From e5f5c540b4e116068b925fcae82d1cc4b5273f4a Mon Sep 17 00:00:00 2001 From: JingHuiTong Date: Fri, 27 Jan 2023 19:14:24 +0800 Subject: [PATCH 19/24] code finish --- .../gallery/images/grdgradient_shading.py | 62 ++++++++++++++----- 1 file changed, 47 insertions(+), 15 deletions(-) diff --git a/examples/gallery/images/grdgradient_shading.py b/examples/gallery/images/grdgradient_shading.py index 0f3f0fb366e..ec015f03cea 100644 --- a/examples/gallery/images/grdgradient_shading.py +++ b/examples/gallery/images/grdgradient_shading.py @@ -1,25 +1,57 @@ +""" +Calculating grid gradient, azimuth and normalize +-------------------------------------- +The :func:`pygmt.grdgradient` function calculates the gradient of a grid file. +In the example shown below we will see how to calculate a hillshade map based +on a Data Elevation Model (DEM). As input :func:`pygmt.grdgradient` gets +a :class:`xarray.DataArray` object or a path string to a grid file, calculates +the respective gradient and returns it as an :class:`xarray.DataArray` object. +We will use the ``azimuth`` and ``normalize`` parameters in order to set the illumination light source +directions and enhacing the three-dimensional effect of topography. +""" import pygmt # Define region of interest around Caucasus -region = [39, 50, 40, 45] +region = [35, 50, 35, 45] -# Load sample grid (3 arc-seconds global relief) in target area -grid = pygmt.datasets.load_earth_relief(resolution="03s", region=region) +# Load sample grid (1 arc-minutes global relief) in target area +grid = pygmt.datasets.load_earth_relief(resolution="01m", region=region) +cmap = pygmt.makecpt(cmap='terra', series=[-7000, 7000]) -cmap = pygmt.makecpt(cmap='terra', series=[-5000, 5000]) fig = pygmt.Figure() -with fig.subplot(nrows=3, ncols=3, figsize=("20c", "20c")): - for i, rad in enumerate(['210/0','210/45', '210/90']):#, 0.5, 1]: - for j, nor in enumerate([1, 10, 20]): - index = i * 3 + j - dgrid = pygmt.grdgradient(grid=grid, radiance=rad, normalize=nor) +# define figure configuration +pygmt.config(MAP_FRAME_TYPE="plain", + FONT_TITLE='15p,5', + MAP_TITLE_OFFSET='5p', + FONT_ANNOT_PRIMARY="8p") +with fig.subplot(nrows=3, ncols=4, figsize=("25c", "20c")): + # azimuth: where is light source from. "0" means light source in the north + # direction. "0/180" means light source in the north and south directions. + # "0/270" means light source in the north and west directions. + for i, azi in enumerate(["0","0/180", "0/270"]): + # normalize enhances the three-dimensional effect of topography. It is + # more brighter(based on amplitude) to the light side. Conversely, it + # is more darker to the dark side. "e" and "t" are differenct ways to + # calculate gradient. + for j, nor in enumerate(["e0.5", "e2", "t0.5", "t2"]): + # index number starting from 0 + index = i * 4 + j + # Intensity file made from grdgradient + shade = pygmt.grdgradient(grid=grid, azimuth=azi, normalize=nor) + # Add a description of the parameter setting + title = f'A={azi}, N={nor}' with fig.set_panel(panel=index): fig.grdimage( - grid=grid, - projection="M5c", - frame=["WSrt", "a2f1"], - cmap=cmap - ) - + grid=grid, + shading=shade, + projection="M5c", + frame=["a4f1",f'WSne+t"{title}"'], + cmap=cmap + ) +# Add colorbar for gridded data +fig.colorbar(cmap=cmap, + position='x8.5c/-1.1c+w7c/0.25c+h+mc', + frame=["a2000f500", "x+lElevation", "y+lm"] + ) fig.show() From 3256f2b7005e20b7bab81a2a7db533e8efcd97bc Mon Sep 17 00:00:00 2001 From: Tong <86273921+JingHuiTong@users.noreply.github.com> Date: Mon, 6 Feb 2023 14:41:37 +0800 Subject: [PATCH 20/24] Apply suggestions from code review Co-authored-by: Dongdong Tian --- pygmt/src/surface.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pygmt/src/surface.py b/pygmt/src/surface.py index 035eabe3227..7436d3d3e7d 100644 --- a/pygmt/src/surface.py +++ b/pygmt/src/surface.py @@ -76,16 +76,16 @@ def surface(data=None, x=None, y=None, z=None, **kwargs): convergence : float or str Optional. Convergence limit. Iteration is assumed to have converged when the maximum absolute change in any grid value is less than - *convergence_limit*. (Units same as data z units). Alternatively, - give limit in percentage of rms deviation by appending %. [Default - is scaled to :math:`10^{{-4}}` of the root-mean-square deviation of + ``convergence``. (Units same as data z units). Alternatively, + give limit in percentage of root-mean-square (rms) deviation by appending %. [Default + is scaled to :math:`10^{{-4}}` of the rms deviation of the data from a best-fit (least-squares) plane.] This is the final convergence limit at the desired grid spacing; for intermediate (coarser) grids the effective convergence limit is divided by the grid spacing multiplier. maxradius : int or str Optional. After solving for the surface, apply a mask so that nodes - farther than *maxradius* away from a data constraint are set to NaN + farther than ``maxradius`` away from a data constraint are set to NaN [Default is no masking]. Append a distance unit (See :gmt-docs:`Units `) if needed. One can also select the nodes to mask by using the *n_cells*\ **c** form. Here @@ -94,14 +94,14 @@ def surface(data=None, x=None, y=None, z=None, **kwargs): where the point lies is filled, ``"1c"`` keeps one cell beyond that (i.e. makes a 3x3 square neighborhood), and so on. lower : float or str - Optional. Impose limits on the output solution. Directive *lower* - sets the lower bound. *lower* can be the name of a grid file with + Optional. Impose limits on the output solution. Parameter ``lower`` + sets the lower bound. ``lower`` can be the name of a grid file with lower bound values, a fixed value, **d** to set to minimum input value, or **u** for unconstrained [Default]. Grid files used to set the limits may contain NaNs. In the presence of NaNs, the limit of a node masked with NaN is unconstrained. upper : float or str - Optional. Impose limits on the output solution. Directive *upper* + Optional. Impose limits on the output solution. Parameter ``upper`` sets the upper bound and can be the name of a grid file with upper bound values, a fixed value, **d** to set to maximum input value, or **u** for unconstrained [Default]. Grid files used to set the From 2d433b038a01a30641f5a7ea192c636b5b1ecbb2 Mon Sep 17 00:00:00 2001 From: JingHuiTong Date: Mon, 6 Feb 2023 15:11:01 +0800 Subject: [PATCH 21/24] add tension more infomation --- pygmt/src/surface.py | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/pygmt/src/surface.py b/pygmt/src/surface.py index a0096968446..8fad65ea858 100644 --- a/pygmt/src/surface.py +++ b/pygmt/src/surface.py @@ -47,7 +47,22 @@ def surface(data=None, x=None, y=None, z=None, **kwargs): .. math:: (1 - t)\nabla^2(z)+t\nabla(z) = 0 where :math:`t` is a tension factor between 0 and 1, and :math:`\nabla` - indicates the Laplacian operator. + indicates the Laplacian operator. Here, :math:`t = 0` gives the + “minimum curvature” solution. Minimum curvature can cause undesired + oscillations and false local maxima or minima (See Smith and Wessel, + 1990), and you may wish to use :math:`t > 0` to suppress these effects. + Experience suggests :math:`t \sim 0.25` usually looks good for potential + field data and t should be larger (:math:`t \sim 0.35`) for steep + topography data. :math:`t = 1` gives a harmonic surface (no maxima or + minima are possible except at control data points). It is recommended that + the user preprocess the data with :class:`pygmt.blockmean`, + :class:`pygmt.blockmedian`, or :class:`pygmt.blockmode` to avoid spatial + aliasing and eliminate redundant data. You may impose lower and/or upper + bounds on the solution. These may be entered in the form of a fixed value, + a grid with values, or simply be the minimum/maximum input data values. + Natural boundary conditions are applied at the edges, except for + geographic data with 360-degree range where we apply periodic boundary + conditions in the longitude direction. Takes a matrix, (x, y, z) triplets, or a file name as input. @@ -76,16 +91,16 @@ def surface(data=None, x=None, y=None, z=None, **kwargs): convergence : float Optional. Convergence limit. Iteration is assumed to have converged when the maximum absolute change in any grid value is less than - *convergence_limit*. (Units same as data z units). Alternatively, - give limit in percentage of rms deviation by appending %. [Default - is scaled to :math:`10^{{-4}}` of the root-mean-square deviation of - the data from a best-fit (least-squares) plane.]. This is the final - convergence limit at the desired grid spacing; for intermediate - (coarser) grids the effective convergence limit is divided by the - grid spacing multiplier. + ``convergence``. (Units same as data z units). Alternatively, + give limit in percentage of root-mean-square (rms) deviation by + appending %. [Default is scaled to :math:`10^{{-4}}` of the rms + deviation of the data from a best-fit (least-squares) plane.]. + This is the final convergence limit at the desired grid spacing; + for intermediate (coarser) grids the effective convergence limit is + divided by the grid spacing multiplier. maxradius : int or str Optional. After solving for the surface, apply a mask so that nodes - farther than *maxradius* away from a data constraint are set to NaN + farther than ``maxradius`` away from a data constraint are set to NaN [Default is no masking]. Append a distance unit (See :gmt-docs:`Units `) if needed. One can also select the nodes to mask by using the *n_cells*\ **c** form. Here @@ -94,14 +109,14 @@ def surface(data=None, x=None, y=None, z=None, **kwargs): where the point lies is filled, ``"1c"`` keeps one cell beyond that (i.e. makes a 3x3 square neighborhood), and so on. lower : float or str - Optional. Impose limits on the output solution. Directive *lower* - sets the lower bound. *lower* can be the name of a grid file with + Optional. Impose limits on the output solution. Parameter ``lower`` + sets the lower bound. ``lower`` can be the name of a grid file with lower bound values, a fixed value, **d** to set to minimum input value, or **u** for unconstrained [Default]. Grid files used to set the limits may contain NaNs. In the presence of NaNs, the limit of a node masked with NaN is unconstrained. upper : float or str - Optional. Impose limits on the output solution. Directive *upper* + Optional. Impose limits on the output solution. Parameter ``upper`` sets the upper bound and can be the name of a grid file with upper bound values, a fixed value, **d** to set to maximum input value, or **u** for unconstrained [Default]. Grid files used to set the From 968bda3a28a0bc371c40e8be5c76d7211f7d3769 Mon Sep 17 00:00:00 2001 From: JingHuiTong Date: Mon, 6 Feb 2023 17:44:21 +0800 Subject: [PATCH 22/24] Fix conflicts --- .github/workflows/ci_tests.yaml | 2 +- .github/workflows/ci_tests_dev.yaml | 2 +- .github/workflows/ci_tests_legacy.yaml | 2 +- AUTHORS.md | 2 +- CITATION.cff | 2 +- doc/api/index.rst | 7 -- .../gallery/images/grdgradient_shading.py | 57 ---------- examples/gallery/symbols/bars.py | 1 - pygmt/datasets/__init__.py | 2 +- pygmt/datasets/earth_magnetic_anomaly.py | 4 +- pygmt/datasets/earth_relief.py | 8 +- pygmt/datasets/load_remote_dataset.py | 2 +- pygmt/datasets/samples.py | 53 +++------ pygmt/figure.py | 10 +- pygmt/helpers/tempfile.py | 5 +- pygmt/helpers/testing.py | 1 + pygmt/helpers/utils.py | 29 +++-- pygmt/src/surface.py | 74 ++++++------- pygmt/src/wiggle.py | 2 +- pygmt/tests/test_clib.py | 10 +- pygmt/tests/test_contour.py | 2 +- .../test_datasets_earth_magnetic_anomaly.py | 50 +++++---- pygmt/tests/test_datasets_samples.py | 10 +- pygmt/tests/test_dimfilter.py | 8 +- pygmt/tests/test_figure.py | 45 ++++++-- pygmt/tests/test_grdclip.py | 2 +- pygmt/tests/test_grdcut.py | 2 +- pygmt/tests/test_grdfill.py | 8 +- pygmt/tests/test_grdfilter.py | 8 +- pygmt/tests/test_grdgradient.py | 8 +- pygmt/tests/test_grdhisteq.py | 5 +- pygmt/tests/test_grdimage.py | 15 ++- pygmt/tests/test_grdlandmask.py | 8 +- pygmt/tests/test_grdproject.py | 8 +- pygmt/tests/test_grdsample.py | 8 +- pygmt/tests/test_grdtrack.py | 2 +- pygmt/tests/test_meca.py | 101 +++++++++--------- pygmt/tests/test_plot.py | 2 +- pygmt/tests/test_plot3d.py | 2 +- pygmt/tests/test_surface.py | 10 +- pygmt/tests/test_triangulate.py | 4 +- pygmt/tests/test_xyz2grd.py | 8 +- 42 files changed, 279 insertions(+), 312 deletions(-) delete mode 100644 examples/gallery/images/grdgradient_shading.py diff --git a/.github/workflows/ci_tests.yaml b/.github/workflows/ci_tests.yaml index 8c54ce73c5f..ab3a103680e 100644 --- a/.github/workflows/ci_tests.yaml +++ b/.github/workflows/ci_tests.yaml @@ -93,7 +93,7 @@ jobs: mamba install gmt=6.4.0 numpy=${{ matrix.numpy-version }} \ pandas xarray netCDF4 packaging \ ${{ matrix.optional-packages }} \ - build dvc make 'pytest>=6.0' \ + build dvc fsspec==2022.11.0 make 'pytest>=6.0' \ pytest-cov pytest-doctestplus pytest-mpl sphinx-gallery # Show installed pkg information for postmortem diagnostic diff --git a/.github/workflows/ci_tests_dev.yaml b/.github/workflows/ci_tests_dev.yaml index 80667672f25..69bc96b1157 100644 --- a/.github/workflows/ci_tests_dev.yaml +++ b/.github/workflows/ci_tests_dev.yaml @@ -101,7 +101,7 @@ jobs: geopandas ghostscript libnetcdf hdf5 zlib curl pcre make pip install --pre --prefer-binary \ numpy pandas xarray netCDF4 packaging \ - build dvc ipython 'pytest>=6.0' pytest-cov \ + build dvc fsspec==2022.11.0 ipython 'pytest>=6.0' pytest-cov \ pytest-doctestplus pytest-mpl sphinx-gallery # Pull baseline image data from dvc remote (DAGsHub) diff --git a/.github/workflows/ci_tests_legacy.yaml b/.github/workflows/ci_tests_legacy.yaml index 7cd00f3b4c2..36e7521ceab 100644 --- a/.github/workflows/ci_tests_legacy.yaml +++ b/.github/workflows/ci_tests_legacy.yaml @@ -67,7 +67,7 @@ jobs: mamba install gmt=${{ matrix.gmt_version }} numpy \ pandas xarray netCDF4 packaging \ geopandas ipython \ - build dvc make 'pytest>=6.0' \ + build dvc fsspec==2022.11.0 make 'pytest>=6.0' \ pytest-cov pytest-doctestplus pytest-mpl sphinx-gallery # Show installed pkg information for postmortem diagnostic diff --git a/AUTHORS.md b/AUTHORS.md index e4b35bda580..be7d005199d 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -20,7 +20,7 @@ The following people have contributed code and/or documentation to the project * [Max Jones](https://github.com/maxrjones) | [0000-0003-0180-8928](https://orcid.org/0000-0003-0180-8928) | University of Hawai'i at Mānoa, USA * [Michael Grund](https://github.com/michaelgrund) | [0000-0001-8759-2018](https://orcid.org/0000-0001-8759-2018) | Innoplexia GmbH, Germany * [Tyler Newton](http://www.tnewton.com/) | [0000-0002-1560-6553](https://orcid.org/0000-0002-1560-6553) | University of Oregon, USA -* [Wei Ji Leong](https://github.com/weiji14) | [0000-0003-2354-1988](https://orcid.org/0000-0003-2354-1988) | The Ohio State University, USA +* [Wei Ji Leong](https://github.com/weiji14) | [0000-0003-2354-1988](https://orcid.org/0000-0003-2354-1988) | Development Seed, USA * [William Schlitzer](https://github.com/willschlitzer) | [0000-0002-5843-2282](https://orcid.org/0000-0002-5843-2282) | Unaffiliated * [Yohai Magen](https://github.com/yohaimagen) | [0000-0002-4892-4013](https://orcid.org/0000-0002-4892-4013) | Tel Aviv University, Israel * [Yvonne Fröhlich](https://github.com/yvonnefroehlich) | [0000-0002-8566-0619](https://orcid.org/0000-0002-8566-0619) | Karlsruhe Institute of Technology, Germany diff --git a/CITATION.cff b/CITATION.cff index dcd45f9f488..1bd9a43c188 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -14,7 +14,7 @@ authors: orcid: https://orcid.org/0000-0001-7967-1197 - given-names: Wei Ji family-names: Leong - affiliation: The Ohio State University, USA + affiliation: Development Seed, USA orcid: https://orcid.org/0000-0003-2354-1988 - given-names: Max family-names: Jones diff --git a/doc/api/index.rst b/doc/api/index.rst index d8fdd877c1c..cf017a475bd 100644 --- a/doc/api/index.rst +++ b/doc/api/index.rst @@ -227,13 +227,6 @@ and store them in GMT's user data directory. datasets.load_earth_vertical_gravity_gradient datasets.load_sample_data -The following functions are deprecated since v0.6.0 and will be removed in v0.9.0. -Use :func:`pygmt.datasets.load_sample_data` instead. - -.. autosummary:: - :toctree: generated - - datasets.load_mars_shape .. currentmodule:: pygmt diff --git a/examples/gallery/images/grdgradient_shading.py b/examples/gallery/images/grdgradient_shading.py deleted file mode 100644 index ec015f03cea..00000000000 --- a/examples/gallery/images/grdgradient_shading.py +++ /dev/null @@ -1,57 +0,0 @@ -""" -Calculating grid gradient, azimuth and normalize --------------------------------------- -The :func:`pygmt.grdgradient` function calculates the gradient of a grid file. -In the example shown below we will see how to calculate a hillshade map based -on a Data Elevation Model (DEM). As input :func:`pygmt.grdgradient` gets -a :class:`xarray.DataArray` object or a path string to a grid file, calculates -the respective gradient and returns it as an :class:`xarray.DataArray` object. -We will use the ``azimuth`` and ``normalize`` parameters in order to set the illumination light source -directions and enhacing the three-dimensional effect of topography. -""" -import pygmt - -# Define region of interest around Caucasus -region = [35, 50, 35, 45] - -# Load sample grid (1 arc-minutes global relief) in target area -grid = pygmt.datasets.load_earth_relief(resolution="01m", region=region) -cmap = pygmt.makecpt(cmap='terra', series=[-7000, 7000]) - -fig = pygmt.Figure() -# define figure configuration -pygmt.config(MAP_FRAME_TYPE="plain", - FONT_TITLE='15p,5', - MAP_TITLE_OFFSET='5p', - FONT_ANNOT_PRIMARY="8p") - -with fig.subplot(nrows=3, ncols=4, figsize=("25c", "20c")): - # azimuth: where is light source from. "0" means light source in the north - # direction. "0/180" means light source in the north and south directions. - # "0/270" means light source in the north and west directions. - for i, azi in enumerate(["0","0/180", "0/270"]): - # normalize enhances the three-dimensional effect of topography. It is - # more brighter(based on amplitude) to the light side. Conversely, it - # is more darker to the dark side. "e" and "t" are differenct ways to - # calculate gradient. - for j, nor in enumerate(["e0.5", "e2", "t0.5", "t2"]): - # index number starting from 0 - index = i * 4 + j - # Intensity file made from grdgradient - shade = pygmt.grdgradient(grid=grid, azimuth=azi, normalize=nor) - # Add a description of the parameter setting - title = f'A={azi}, N={nor}' - with fig.set_panel(panel=index): - fig.grdimage( - grid=grid, - shading=shade, - projection="M5c", - frame=["a4f1",f'WSne+t"{title}"'], - cmap=cmap - ) -# Add colorbar for gridded data -fig.colorbar(cmap=cmap, - position='x8.5c/-1.1c+w7c/0.25c+h+mc', - frame=["a2000f500", "x+lElevation", "y+lm"] - ) -fig.show() diff --git a/examples/gallery/symbols/bars.py b/examples/gallery/symbols/bars.py index 666ae512c62..e5127b3cbb8 100644 --- a/examples/gallery/symbols/bars.py +++ b/examples/gallery/symbols/bars.py @@ -33,7 +33,6 @@ sharex=True, margins=["0.5c", "0.75c"], ): - pen = "1.5p" with fig.set_panel(panel=0): fill = "skyblue" diff --git a/pygmt/datasets/__init__.py b/pygmt/datasets/__init__.py index 37841dfdd2d..d7a099972fb 100644 --- a/pygmt/datasets/__init__.py +++ b/pygmt/datasets/__init__.py @@ -13,4 +13,4 @@ from pygmt.datasets.earth_vertical_gravity_gradient import ( load_earth_vertical_gravity_gradient, ) -from pygmt.datasets.samples import list_sample_data, load_mars_shape, load_sample_data +from pygmt.datasets.samples import list_sample_data, load_sample_data diff --git a/pygmt/datasets/earth_magnetic_anomaly.py b/pygmt/datasets/earth_magnetic_anomaly.py index 459c5360e41..8af7c63e13b 100644 --- a/pygmt/datasets/earth_magnetic_anomaly.py +++ b/pygmt/datasets/earth_magnetic_anomaly.py @@ -115,8 +115,8 @@ def load_earth_magnetic_anomaly( } if data_source not in magnetic_anomaly_sources: raise GMTInvalidInput( - f"Invalid earth magnetic anomaly 'data_source' {data_source}, " - "valid values are 'emag2', 'emag2_4km', and 'wdmam'." + f"Invalid earth magnetic anomaly data source '{data_source}'. " + "Valid values are 'emag2', 'emag2_4km', and 'wdmam'." ) dataset_prefix = magnetic_anomaly_sources[data_source] if data_source == "wdmam": diff --git a/pygmt/datasets/earth_relief.py b/pygmt/datasets/earth_relief.py index b23f24572df..ee708bf3746 100644 --- a/pygmt/datasets/earth_relief.py +++ b/pygmt/datasets/earth_relief.py @@ -129,8 +129,8 @@ def load_earth_relief( } if data_source not in earth_relief_sources: raise GMTInvalidInput( - f"Invalid earth relief 'data_source' {data_source}, " - "valid values are 'igpp', 'gebco', 'gebcosi' and 'synbath'." + f"Invalid earth relief data source '{data_source}'. " + "Valid values are 'igpp', 'gebco', 'gebcosi' and 'synbath'." ) # Choose earth relief data prefix if use_srtm and resolution in land_only_srtm_resolutions: @@ -138,8 +138,8 @@ def load_earth_relief( dataset_prefix = "srtm_relief_" else: raise GMTInvalidInput( - f"The {data_source} option is not available if 'use_srtm=True'." - " Set data_source to 'igpp'." + f"Option 'use_srtm=True' doesn't work with data source '{data_source}'." + " Please set 'data_source' to 'igpp'." ) else: dataset_prefix = earth_relief_sources[data_source] diff --git a/pygmt/datasets/load_remote_dataset.py b/pygmt/datasets/load_remote_dataset.py index f0dfba08325..f6cafc433f8 100644 --- a/pygmt/datasets/load_remote_dataset.py +++ b/pygmt/datasets/load_remote_dataset.py @@ -22,7 +22,7 @@ class Resolution(NamedTuple): tiled : bool States if the given resolution is tiled, which requires an - argument for ``region``." + argument for ``region``. """ registrations: list diff --git a/pygmt/datasets/samples.py b/pygmt/datasets/samples.py index aeb4f398436..72468c107ab 100644 --- a/pygmt/datasets/samples.py +++ b/pygmt/datasets/samples.py @@ -1,8 +1,6 @@ """ Functions to load sample data. """ -import warnings - import pandas as pd from pygmt.exceptions import GMTInvalidInput from pygmt.io import load_dataarray @@ -68,11 +66,6 @@ def load_sample_data(name): if name not in names: raise GMTInvalidInput(f"Invalid dataset name '{name}'.") - # Dictionary of public load functions for backwards compatibility - load_func_old = { - "mars_shape": load_mars_shape, - } - # Dictionary of private load functions load_func = { "bathymetry": _load_baja_california_bathymetry, @@ -80,19 +73,14 @@ def load_sample_data(name): "fractures": _load_fractures_compilation, "hotspots": _load_hotspots, "japan_quakes": _load_japan_quakes, + "mars_shape": _load_mars_shape, "maunaloa_co2": _load_maunaloa_co2, "notre_dame_topography": _load_notre_dame_topography, "ocean_ridge_points": _load_ocean_ridge_points, "rock_compositions": _load_rock_sample_compositions, "usgs_quakes": _load_usgs_quakes, } - - if name in load_func_old: - data = load_func_old[name](suppress_warning=True) - elif name in load_func: - data = load_func[name]() - - return data + return load_func[name]() def _load_japan_quakes(): @@ -221,40 +209,23 @@ def _load_hotspots(): ) -def load_mars_shape(**kwargs): +def _load_mars_shape(): """ - (Deprecated) Load a table of data for the shape of Mars. + Load a table of data for the shape of Mars as a pandas.DataFrame. - .. warning:: Deprecated since v0.6.0. This function has been replaced with - ``load_sample_data(name="mars_shape")`` and will be removed in - v0.9.0. - - This is the ``@mars370d.txt`` dataset used in GMT examples, with data and - information from Smith, D. E., and M. T. Zuber (1996), The shape of Mars - and the topographic signature of the hemispheric dichotomy. Data columns - are "longitude," "latitude", and "radius (meters)." - - The data are downloaded to a cache directory (usually ``~/.gmt/cache``) the - first time you invoke this function. Afterwards, it will load the data from - the cache. So you'll need an internet connection the first time around. + Data and information are from Smith, D. E., and M. T. Zuber (1996), + The shape of Mars and the topographic signature of the hemispheric + dichotomy. Returns ------- data : pandas.DataFrame - The data table with columns "longitude", "latitude", and "radius(m)". + The data table with column names "longitude", "latitude", and + "radius_m". """ - - if "suppress_warning" not in kwargs: - warnings.warn( - "This function has been deprecated since v0.6.0 and will be " - "removed in v0.9.0. Please use " - "load_sample_data(name='mars_shape') instead.", - category=FutureWarning, - stacklevel=2, - ) fname = which("@mars370d.txt", download="c") data = pd.read_csv( - fname, sep="\t", header=None, names=["longitude", "latitude", "radius(m)"] + fname, sep="\t", header=None, names=["longitude", "latitude", "radius_m"] ) return data @@ -289,7 +260,7 @@ def _load_notre_dame_topography(): The data table with columns "x", "y", and "z". """ fname = which("@Table_5_11.txt", download="c") - return pd.read_csv(fname, sep=r"\s+", header=None, names=["x", "y", "z"]) + return pd.read_csv(fname, delim_whitespace=True, header=None, names=["x", "y", "z"]) def _load_maunaloa_co2(): @@ -303,7 +274,7 @@ def _load_maunaloa_co2(): """ fname = which("@MaunaLoa_CO2.txt", download="c") return pd.read_csv( - fname, header=None, skiprows=1, sep=r"\s+", names=["date", "co2_ppm"] + fname, header=None, skiprows=1, delim_whitespace=True, names=["date", "co2_ppm"] ) diff --git a/pygmt/figure.py b/pygmt/figure.py index 2326d8f745a..76c148caec4 100644 --- a/pygmt/figure.py +++ b/pygmt/figure.py @@ -294,7 +294,15 @@ def savefig( ``gs_option``, ``resize``, ``bb_style``, and ``verbose``. """ # All supported formats - fmts = dict(png="g", pdf="f", jpg="j", bmp="b", eps="e", tif="t", kml="g") + fmts = { + "png": "g", + "pdf": "f", + "jpg": "j", + "bmp": "b", + "eps": "e", + "tif": "t", + "kml": "g", + } prefix, ext = os.path.splitext(fname) ext = ext[1:] # Remove the . diff --git a/pygmt/helpers/tempfile.py b/pygmt/helpers/tempfile.py index a21df6e3617..c184c5e73d3 100644 --- a/pygmt/helpers/tempfile.py +++ b/pygmt/helpers/tempfile.py @@ -59,8 +59,7 @@ class GMTTempFile: """ def __init__(self, prefix="pygmt-", suffix=".txt"): - args = dict(prefix=prefix, suffix=suffix, delete=False) - with NamedTemporaryFile(**args) as tmpfile: + with NamedTemporaryFile(prefix=prefix, suffix=suffix, delete=False) as tmpfile: self.name = tmpfile.name def __enter__(self): @@ -128,7 +127,7 @@ def tempfile_from_geojson(geojson): """ with GMTTempFile(suffix=".gmt") as tmpfile: os.remove(tmpfile.name) # ensure file is deleted first - ogrgmt_kwargs = dict(filename=tmpfile.name, driver="OGR_GMT", mode="w") + ogrgmt_kwargs = {"filename": tmpfile.name, "driver": "OGR_GMT", "mode": "w"} try: # Using geopandas.to_file to directly export to OGR_GMT format geojson.to_file(**ogrgmt_kwargs) diff --git a/pygmt/helpers/testing.py b/pygmt/helpers/testing.py index cd06e81fe45..ff9bdc8d16a 100644 --- a/pygmt/helpers/testing.py +++ b/pygmt/helpers/testing.py @@ -189,6 +189,7 @@ def download_test_data(): "@earth_mag_01d_g", "@S30W060.earth_mag_02m_p.nc", # Specific grid for 02m test "@earth_mag4km_01d_g", + "@S30W120.earth_mag4km_02m_p.nc", # Specific grid for 02m test # Earth mask grid "@earth_mask_01d_g", # Earth free-air anomaly grids diff --git a/pygmt/helpers/utils.py b/pygmt/helpers/utils.py index 1ffc95e211d..d972513ff6d 100644 --- a/pygmt/helpers/utils.py +++ b/pygmt/helpers/utils.py @@ -119,16 +119,17 @@ def dummy_context(arg): yield arg -def build_arg_string(kwdict, infile=None, outfile=None): +def build_arg_string(kwdict, confdict=None, infile=None, outfile=None): r""" - Convert a dict and optional input/output files into a GMT argument string. + Convert keyword dictionaries and input/output files into a GMT argument + string. Make sure all values in ``kwdict`` have been previously converted to a string representation using the ``kwargs_to_strings`` decorator. The only exceptions are True, False and None. Any lists or tuples left will be interpreted as multiple entries for the - same command line argument. For example, the kwargs entry ``'B': ['xa', + same command line option. For example, the kwargs entry ``'B': ['xa', 'yaf']`` will be converted to ``-Bxa -Byaf`` in the argument string. Note that spaces `` `` in arguments are converted to the equivalent octal @@ -139,7 +140,9 @@ def build_arg_string(kwdict, infile=None, outfile=None): Parameters ---------- kwdict : dict - A dict containing parsed keyword arguments. + A dictionary containing parsed keyword arguments. + confdict : dict + A dictionary containing configurable GMT parameters. infile : str or pathlib.Path The input file. outfile : str or pathlib.Path @@ -149,8 +152,10 @@ def build_arg_string(kwdict, infile=None, outfile=None): ------- args : str The space-delimited argument string with '-' inserted before each - keyword. The arguments are sorted alphabetically, with optional input - file at the beginning and optional output file at the end. + keyword, or '--' inserted before GMT configuration key-value pairs. + The keyword arguments are sorted alphabetically, followed by GMT + configuration key-value pairs, with optional input file at the + beginning and optional output file at the end. Examples -------- @@ -199,11 +204,12 @@ def build_arg_string(kwdict, infile=None, outfile=None): >>> print( ... build_arg_string( ... dict(A="0", B=True, C="rainbow"), + ... confdict=dict(FORMAT_DATE_MAP="o dd"), ... infile="input.txt", ... outfile="output.txt", ... ) ... ) - input.txt -A0 -B -Crainbow ->output.txt + input.txt -A0 -B -Crainbow --FORMAT_DATE_MAP="o dd" ->output.txt """ gmt_args = [] @@ -227,6 +233,10 @@ def build_arg_string(kwdict, infile=None, outfile=None): _value = str(kwdict[key]).replace(" ", "") gmt_args.append(rf"-{key}{_value}") gmt_args = sorted(gmt_args) + + if confdict: + gmt_args.extend(f'--{key}="{value}"' for key, value in confdict.items()) + if infile: gmt_args = [str(infile)] + gmt_args if outfile: @@ -283,7 +293,10 @@ def launch_external_viewer(fname, waiting=0): """ # Redirect stdout and stderr to devnull so that the terminal isn't filled # with noise - run_args = dict(stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + run_args = { + "stdout": subprocess.DEVNULL, + "stderr": subprocess.DEVNULL, + } # Open the file with the default viewer. # Fall back to the browser if can't recognize the operating system. diff --git a/pygmt/src/surface.py b/pygmt/src/surface.py index 8fad65ea858..d8b5904a310 100644 --- a/pygmt/src/surface.py +++ b/pygmt/src/surface.py @@ -88,49 +88,49 @@ def surface(data=None, x=None, y=None, z=None, **kwargs): outgrid : str Optional. The file name for the output netcdf file with extension .nc to store the grid in. - convergence : float - Optional. Convergence limit. Iteration is assumed to have converged - when the maximum absolute change in any grid value is less than - ``convergence``. (Units same as data z units). Alternatively, - give limit in percentage of root-mean-square (rms) deviation by - appending %. [Default is scaled to :math:`10^{{-4}}` of the rms - deviation of the data from a best-fit (least-squares) plane.]. - This is the final convergence limit at the desired grid spacing; - for intermediate (coarser) grids the effective convergence limit is - divided by the grid spacing multiplier. + convergence : float or str + Optional. Convergence limit. Iteration is assumed to have converged + when the maximum absolute change in any grid value is less than + ``convergence``. (Units same as data z units). Alternatively, + give limit in percentage of root-mean-square (rms) deviation by appending %. [Default + is scaled to :math:`10^{{-4}}` of the rms deviation of + the data from a best-fit (least-squares) plane.] This is the final + convergence limit at the desired grid spacing; for intermediate + (coarser) grids the effective convergence limit is divided by the + grid spacing multiplier. maxradius : int or str - Optional. After solving for the surface, apply a mask so that nodes - farther than ``maxradius`` away from a data constraint are set to NaN - [Default is no masking]. Append a distance unit (See - :gmt-docs:`Units `) if needed. One can also - select the nodes to mask by using the *n_cells*\ **c** form. Here - *n_cells* means the number of cells around the node is controlled - by a data point. As an example ``"0c"`` means that only the cell - where the point lies is filled, ``"1c"`` keeps one cell beyond + Optional. After solving for the surface, apply a mask so that nodes + farther than ``maxradius`` away from a data constraint are set to NaN + [Default is no masking]. Append a distance unit (See + :gmt-docs:`Units `) if needed. One can also + select the nodes to mask by using the *n_cells*\ **c** form. Here + *n_cells* means the number of cells around the node is controlled + by a data point. As an example ``"0c"`` means that only the cell + where the point lies is filled, ``"1c"`` keeps one cell beyond that (i.e. makes a 3x3 square neighborhood), and so on. lower : float or str - Optional. Impose limits on the output solution. Parameter ``lower`` - sets the lower bound. ``lower`` can be the name of a grid file with - lower bound values, a fixed value, **d** to set to minimum input - value, or **u** for unconstrained [Default]. Grid files used to set - the limits may contain NaNs. In the presence of NaNs, the limit of - a node masked with NaN is unconstrained. + Optional. Impose limits on the output solution. Parameter ``lower`` + sets the lower bound. ``lower`` can be the name of a grid file with + lower bound values, a fixed value, **d** to set to minimum input + value, or **u** for unconstrained [Default]. Grid files used to set + the limits may contain NaNs. In the presence of NaNs, the limit of + a node masked with NaN is unconstrained. upper : float or str - Optional. Impose limits on the output solution. Parameter ``upper`` - sets the upper bound and can be the name of a grid file with upper - bound values, a fixed value, **d** to set to maximum input value, - or **u** for unconstrained [Default]. Grid files used to set the - limits may contain NaNs. In the presence of NaNs, the limit of a - node masked with NaN is unconstrained. + Optional. Impose limits on the output solution. Parameter ``upper`` + sets the upper bound and can be the name of a grid file with upper + bound values, a fixed value, **d** to set to maximum input value, + or **u** for unconstrained [Default]. Grid files used to set the + limits may contain NaNs. In the presence of NaNs, the limit of a + node masked with NaN is unconstrained. tension : float or str [**b**\|\ **i**]. - Optional. Tension factor[s]. These must be between 0 and 1. Tension - may be used in the interior solution (above equation, where it - suppresses spurious oscillations) and in the boundary conditions - (where it tends to flatten the solution approaching the edges). Add - **i**\ *tension* to set interior tension, and **b**\ *tension* to - set boundary tension. If you do not prepend **i** or **b**, both - will be set to the same value. [Default is 0 for both and gives + Optional. Tension factor[s]. These must be between 0 and 1. Tension + may be used in the interior solution (above equation, where it + suppresses spurious oscillations) and in the boundary conditions + (where it tends to flatten the solution approaching the edges). Add + **i**\ *tension* to set interior tension, and **b**\ *tension* to + set boundary tension. If you do not prepend **i** or **b**, both + will be set to the same value. [Default is 0 for both and gives minimum curvature solution.] {verbose} {aspatial} diff --git a/pygmt/src/wiggle.py b/pygmt/src/wiggle.py index 97437cd01b1..82b7bf0a7d0 100644 --- a/pygmt/src/wiggle.py +++ b/pygmt/src/wiggle.py @@ -41,7 +41,7 @@ def wiggle( z=None, fillpositive=None, fillnegative=None, - **kwargs + **kwargs, ): r""" Plot z=f(x,y) anomalies along tracks. diff --git a/pygmt/tests/test_clib.py b/pygmt/tests/test_clib.py index 429b312fcab..6ad698c13ae 100644 --- a/pygmt/tests/test_clib.py +++ b/pygmt/tests/test_clib.py @@ -639,11 +639,11 @@ def test_virtualfile_from_vectors_pandas(dtypes): size = 13 for dtype in dtypes: data = pd.DataFrame( - data=dict( - x=np.arange(size, dtype=dtype), - y=np.arange(size, size * 2, 1, dtype=dtype), - z=np.arange(size * 2, size * 3, 1, dtype=dtype), - ) + data={ + "x": np.arange(size, dtype=dtype), + "y": np.arange(size, size * 2, 1, dtype=dtype), + "z": np.arange(size * 2, size * 3, 1, dtype=dtype), + } ) with clib.Session() as lib: with lib.virtualfile_from_vectors(data.x, data.y, data.z) as vfile: diff --git a/pygmt/tests/test_contour.py b/pygmt/tests/test_contour.py index e2f3de6c226..9bc2686935c 100644 --- a/pygmt/tests/test_contour.py +++ b/pygmt/tests/test_contour.py @@ -19,7 +19,7 @@ def fixture_data(): """ Load the point data from the test file. """ - return pd.read_table(POINTS_DATA, header=None, sep=r"\s+") + return pd.read_table(POINTS_DATA, header=None, delim_whitespace=True) @pytest.fixture(scope="module", name="region") diff --git a/pygmt/tests/test_datasets_earth_magnetic_anomaly.py b/pygmt/tests/test_datasets_earth_magnetic_anomaly.py index b9b045c5be7..71ad594d335 100644 --- a/pygmt/tests/test_datasets_earth_magnetic_anomaly.py +++ b/pygmt/tests/test_datasets_earth_magnetic_anomaly.py @@ -80,6 +80,22 @@ def test_earth_mag_incorrect_resolution_registration(): ) +def test_earth_mag_02m_default_registration(): + """ + Test that the grid returned by default for the 2 arc-minute resolution has + a "pixel" registration. + """ + data = load_earth_magnetic_anomaly(resolution="02m", region=[-10, -9, 3, 5]) + assert data.shape == (60, 30) + assert data.gmt.registration == 1 + npt.assert_allclose(data.coords["lat"].data.min(), 3.016666667) + npt.assert_allclose(data.coords["lat"].data.max(), 4.983333333) + npt.assert_allclose(data.coords["lon"].data.min(), -9.98333333) + npt.assert_allclose(data.coords["lon"].data.max(), -9.01666667) + npt.assert_allclose(data.min(), -231) + npt.assert_allclose(data.max(), 131.79999) + + def test_earth_mag4km_01d(): """ Test some properties of the magnetic anomaly 4km 01d data. @@ -114,34 +130,24 @@ def test_earth_mag4km_01d_with_region(): npt.assert_allclose(data.max(), 113.59985) -def test_earth_mag_02m_default_registration(): +def test_earth_mag4km_02m_default_registration(): """ Test that the grid returned by default for the 2 arc-minute resolution has a "pixel" registration. """ - data = load_earth_magnetic_anomaly(resolution="02m", region=[-10, -9, 3, 5]) - assert data.shape == (60, 30) - assert data.gmt.registration == 1 - npt.assert_allclose(data.coords["lat"].data.min(), 3.016666667) - npt.assert_allclose(data.coords["lat"].data.max(), 4.983333333) - npt.assert_allclose(data.coords["lon"].data.min(), -9.98333333) - npt.assert_allclose(data.coords["lon"].data.max(), -9.01666667) - npt.assert_allclose(data.min(), -231) - npt.assert_allclose(data.max(), 131.79999) - data = load_earth_magnetic_anomaly( - resolution="05m", + resolution="02m", region=[-115, -112, 4, 6], - registration="gridline", data_source="emag2_4km", ) - assert data.shape == (25, 37) - assert data.lat.min() == 4 - assert data.lat.max() == 6 - assert data.lon.min() == -115 - assert data.lon.max() == -112 - npt.assert_allclose(data.min(), -128.40015) - npt.assert_allclose(data.max(), 76.80005) + assert data.shape == (60, 90) + assert data.gmt.registration == 1 + npt.assert_allclose(data.coords["lat"].data.min(), 4.01666667) + npt.assert_allclose(data.coords["lat"].data.max(), 5.98333333) + npt.assert_allclose(data.coords["lon"].data.min(), -114.98333333) + npt.assert_allclose(data.coords["lon"].data.max(), -112.01666667) + npt.assert_allclose(data.min(), -132.80005) + npt.assert_allclose(data.max(), 79.59985) def test_earth_mag_01d_wdmam(): @@ -196,13 +202,13 @@ def test_earth_mag_03m_wdmam_with_region(): npt.assert_allclose(data.max(), 629.6) -def test_earth_mag_05m_wdmam_without_region(): +def test_earth_mag_03m_wdmam_without_region(): """ Test loading a high-resolution WDMAM grid without passing 'region'. """ with pytest.raises(GMTInvalidInput): load_earth_magnetic_anomaly( - resolution="05m", registration="gridline", data_source="wdmam" + resolution="03m", registration="gridline", data_source="wdmam" ) diff --git a/pygmt/tests/test_datasets_samples.py b/pygmt/tests/test_datasets_samples.py index ddf71afc863..010a58746d9 100644 --- a/pygmt/tests/test_datasets_samples.py +++ b/pygmt/tests/test_datasets_samples.py @@ -4,7 +4,7 @@ import numpy.testing as npt import pandas as pd import pytest -from pygmt.datasets import load_mars_shape, load_sample_data +from pygmt.datasets import load_sample_data from pygmt.exceptions import GMTInvalidInput @@ -128,16 +128,14 @@ def test_mars_shape(): """ Check that the @mars370d.txt dataset loads without errors. """ - with pytest.warns(expected_warning=FutureWarning) as record: - data = load_mars_shape() - assert len(record) == 1 + data = load_sample_data(name="mars_shape") assert data.shape == (370, 3) assert data["longitude"].min() == 0.008 assert data["longitude"].max() == 359.983 assert data["latitude"].min() == -79.715 assert data["latitude"].max() == 85.887 - assert data["radius(m)"].min() == -6930 - assert data["radius(m)"].max() == 15001 + assert data["radius_m"].min() == -6930 + assert data["radius_m"].max() == 15001 def test_hotspots(): diff --git a/pygmt/tests/test_dimfilter.py b/pygmt/tests/test_dimfilter.py index 9c8248c9f11..06723b2ab54 100644 --- a/pygmt/tests/test_dimfilter.py +++ b/pygmt/tests/test_dimfilter.py @@ -32,10 +32,10 @@ def fixture_expected_grid(): [367.5, 349.0, 385.5, 349.0], [435.0, 385.5, 413.5, 481.5], ], - coords=dict( - lon=[-54.5, -53.5, -52.5, -51.5], - lat=[-23.5, -22.5, -21.5, -20.5, -19.5], - ), + coords={ + "lon": [-54.5, -53.5, -52.5, -51.5], + "lat": [-23.5, -22.5, -21.5, -20.5, -19.5], + }, dims=["lat", "lon"], ) diff --git a/pygmt/tests/test_figure.py b/pygmt/tests/test_figure.py index 87d84962e96..2d5feaf676c 100644 --- a/pygmt/tests/test_figure.py +++ b/pygmt/tests/test_figure.py @@ -174,25 +174,54 @@ def mock_psconvert(*args, **kwargs): # pylint: disable=unused-argument fname = ".".join([prefix, "png"]) fig.savefig(fname) - assert kwargs_saved[-1] == dict(prefix=prefix, fmt="g", crop=True, Qt=2, Qg=2) + assert kwargs_saved[-1] == { + "prefix": prefix, + "fmt": "g", + "crop": True, + "Qt": 2, + "Qg": 2, + } fname = ".".join([prefix, "pdf"]) fig.savefig(fname) - assert kwargs_saved[-1] == dict(prefix=prefix, fmt="f", crop=True, Qt=2, Qg=2) + assert kwargs_saved[-1] == { + "prefix": prefix, + "fmt": "f", + "crop": True, + "Qt": 2, + "Qg": 2, + } fname = ".".join([prefix, "png"]) fig.savefig(fname, transparent=True) - assert kwargs_saved[-1] == dict(prefix=prefix, fmt="G", crop=True, Qt=2, Qg=2) + assert kwargs_saved[-1] == { + "prefix": prefix, + "fmt": "G", + "crop": True, + "Qt": 2, + "Qg": 2, + } fname = ".".join([prefix, "eps"]) fig.savefig(fname) - assert kwargs_saved[-1] == dict(prefix=prefix, fmt="e", crop=True, Qt=2, Qg=2) + assert kwargs_saved[-1] == { + "prefix": prefix, + "fmt": "e", + "crop": True, + "Qt": 2, + "Qg": 2, + } fname = ".".join([prefix, "kml"]) fig.savefig(fname) - assert kwargs_saved[-1] == dict( - prefix=prefix, fmt="g", crop=True, Qt=2, Qg=2, W="+k" - ) + assert kwargs_saved[-1] == { + "prefix": prefix, + "fmt": "g", + "crop": True, + "Qt": 2, + "Qg": 2, + "W": "+k", + } @pytest.mark.skipif(IPython is None, reason="run when IPython is installed") @@ -210,7 +239,7 @@ def test_figure_shift_origin(): """ Test if fig.shift_origin works. """ - kwargs = dict(region=[0, 3, 0, 5], projection="X3c/5c", frame=0) + kwargs = {"region": [0, 3, 0, 5], "projection": "X3c/5c", "frame": 0} fig = Figure() # First call shift_origin without projection and region. # Test issue https://github.com/GenericMappingTools/pygmt/issues/514 diff --git a/pygmt/tests/test_grdclip.py b/pygmt/tests/test_grdclip.py index 15d90b49452..43cad9f78c6 100644 --- a/pygmt/tests/test_grdclip.py +++ b/pygmt/tests/test_grdclip.py @@ -29,7 +29,7 @@ def fixture_expected_grid(): [1000.0, 1000.0, 571.5, 638.5], [555.5, 556.0, 580.0, 1000.0], ], - coords=dict(lon=[-52.5, -51.5, -50.5, -49.5], lat=[-18.5, -17.5, -16.5]), + coords={"lon": [-52.5, -51.5, -50.5, -49.5], "lat": [-18.5, -17.5, -16.5]}, dims=["lat", "lon"], ) diff --git a/pygmt/tests/test_grdcut.py b/pygmt/tests/test_grdcut.py index f77e92c372d..baa2e38a06d 100644 --- a/pygmt/tests/test_grdcut.py +++ b/pygmt/tests/test_grdcut.py @@ -37,7 +37,7 @@ def fixture_expected_grid(): [757.0, 570.5, 538.5, 524.0], [796.0, 886.0, 571.5, 638.5], ], - coords=dict(lon=[-52.5, -51.5, -50.5, -49.5], lat=[-19.5, -18.5, -17.5]), + coords={"lon": [-52.5, -51.5, -50.5, -49.5], "lat": [-19.5, -18.5, -17.5]}, dims=["lat", "lon"], ) diff --git a/pygmt/tests/test_grdfill.py b/pygmt/tests/test_grdfill.py index c6ffe9688d2..ed1967f6f29 100644 --- a/pygmt/tests/test_grdfill.py +++ b/pygmt/tests/test_grdfill.py @@ -50,9 +50,9 @@ def fixture_expected_grid(): [349.0, 313.0, 325.5, 247.0, 191.0, 225.0, 260.0, 452.5], [347.5, 331.5, 309.0, 282.0, 190.0, 208.0, 299.5, 348.0], ], - coords=dict( - lon=[-54.5, -53.5, -52.5, -51.5, -50.5, -49.5, -48.5, -47.5], - lat=[ + coords={ + "lon": [-54.5, -53.5, -52.5, -51.5, -50.5, -49.5, -48.5, -47.5], + "lat": [ -23.5, -22.5, -21.5, @@ -68,7 +68,7 @@ def fixture_expected_grid(): -11.5, -10.5, ], - ), + }, dims=["lat", "lon"], ) diff --git a/pygmt/tests/test_grdfilter.py b/pygmt/tests/test_grdfilter.py index 7a75a7b4b77..3a61f3a6db8 100644 --- a/pygmt/tests/test_grdfilter.py +++ b/pygmt/tests/test_grdfilter.py @@ -31,10 +31,10 @@ def fixture_expected_grid(): [614.6496, 601.4992, 569.9743, 606.0966], [661.41003, 656.9681, 625.1668, 664.40204], ], - coords=dict( - lon=[-52.5, -51.5, -50.5, -49.5], - lat=[-19.5, -18.5, -17.5], - ), + coords={ + "lon": [-52.5, -51.5, -50.5, -49.5], + "lat": [-19.5, -18.5, -17.5], + }, dims=["lat", "lon"], ) diff --git a/pygmt/tests/test_grdgradient.py b/pygmt/tests/test_grdgradient.py index 2236c2a7e6e..06dc1bed6e1 100644 --- a/pygmt/tests/test_grdgradient.py +++ b/pygmt/tests/test_grdgradient.py @@ -30,10 +30,10 @@ def fixture_expected_grid(): [-1.5880326e-03, -1.6113354e-03, -5.4624723e-04, -5.0047837e-04], [7.2569086e-04, 2.4801277e-04, 1.8859128e-05, -1.2269041e-03], ], - coords=dict( - lon=[-52.5, -51.5, -50.5, -49.5], - lat=[-19.5, -18.5, -17.5], - ), + coords={ + "lon": [-52.5, -51.5, -50.5, -49.5], + "lat": [-19.5, -18.5, -17.5], + }, dims=["lat", "lon"], ) diff --git a/pygmt/tests/test_grdhisteq.py b/pygmt/tests/test_grdhisteq.py index ab6b2315b26..df000bb0596 100644 --- a/pygmt/tests/test_grdhisteq.py +++ b/pygmt/tests/test_grdhisteq.py @@ -36,7 +36,10 @@ def fixture_expected_grid(): """ return xr.DataArray( data=[[0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 1, 1], [1, 1, 1, 1]], - coords=dict(lon=[-51.5, -50.5, -49.5, -48.5], lat=[-21.5, -20.5, -19.5, -18.5]), + coords={ + "lon": [-51.5, -50.5, -49.5, -48.5], + "lat": [-21.5, -20.5, -19.5, -18.5], + }, dims=["lat", "lon"], ) diff --git a/pygmt/tests/test_grdimage.py b/pygmt/tests/test_grdimage.py index fc08a4f6a90..566d7626caa 100644 --- a/pygmt/tests/test_grdimage.py +++ b/pygmt/tests/test_grdimage.py @@ -119,14 +119,13 @@ def test_grdimage_shading_xarray(grid, shading): https://github.com/GenericMappingTools/pygmt/issues/618. """ fig_ref, fig_test = Figure(), Figure() - kwargs = dict( - region=[-180, 180, -90, 90], - frame=True, - projection="Cyl_stere/6i", - cmap="geo", - shading=shading, - ) - + kwargs = { + "region": [-180, 180, -90, 90], + "frame": True, + "projection": "Cyl_stere/6i", + "cmap": "geo", + "shading": shading, + } fig_ref.grdimage("@earth_relief_01d_g", **kwargs) fig_test.grdimage(grid, **kwargs) return fig_ref, fig_test diff --git a/pygmt/tests/test_grdlandmask.py b/pygmt/tests/test_grdlandmask.py index f5dedf895e3..85f9e795932 100644 --- a/pygmt/tests/test_grdlandmask.py +++ b/pygmt/tests/test_grdlandmask.py @@ -24,10 +24,10 @@ def fixture_expected_grid(): [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 1.0, 1.0, 0.0, 0.0], ], - coords=dict( - lon=[125.0, 126.0, 127.0, 128.0, 129.0, 130.0], - lat=[30.0, 31.0, 32.0, 33.0, 34.0, 35.0], - ), + coords={ + "lon": [125.0, 126.0, 127.0, 128.0, 129.0, 130.0], + "lat": [30.0, 31.0, 32.0, 33.0, 34.0, 35.0], + }, dims=["lat", "lon"], ) diff --git a/pygmt/tests/test_grdproject.py b/pygmt/tests/test_grdproject.py index f4257c0899d..b8e9d49e1a6 100644 --- a/pygmt/tests/test_grdproject.py +++ b/pygmt/tests/test_grdproject.py @@ -32,10 +32,10 @@ def fixture_expected_grid(): [794.233, 829.4449, 764.12225], [749.37445, 834.55994, 831.2627], ], - coords=dict( - x=[1.666667, 5.0, 8.333333], - y=[1.572432, 4.717295, 7.862158, 11.007022, 14.151885], - ), + coords={ + "x": [1.666667, 5.0, 8.333333], + "y": [1.572432, 4.717295, 7.862158, 11.007022, 14.151885], + }, dims=["y", "x"], ) diff --git a/pygmt/tests/test_grdsample.py b/pygmt/tests/test_grdsample.py index 56111ff5d20..970ac55e910 100644 --- a/pygmt/tests/test_grdsample.py +++ b/pygmt/tests/test_grdsample.py @@ -47,10 +47,10 @@ def fixture_expected_grid(): [551.75, 666.6875, 958.21875], [411.3125, 518.4375, 931.28125], ], - coords=dict( - lon=[-52, -50, -48], - lat=[-19.5, -18.5, -17.5, -16.5, -15.5], - ), + coords={ + "lon": [-52, -50, -48], + "lat": [-19.5, -18.5, -17.5, -16.5, -15.5], + }, dims=["lat", "lon"], ) diff --git a/pygmt/tests/test_grdtrack.py b/pygmt/tests/test_grdtrack.py index 89e9aac8e05..41691b0db48 100644 --- a/pygmt/tests/test_grdtrack.py +++ b/pygmt/tests/test_grdtrack.py @@ -51,7 +51,7 @@ def fixture_dataframe(): Load a pandas DataFrame with points. """ return pd.read_csv( - POINTS_DATA, sep=r"\s+", header=None, names=["longitude", "latitude"] + POINTS_DATA, delim_whitespace=True, header=None, names=["longitude", "latitude"] ) diff --git a/pygmt/tests/test_meca.py b/pygmt/tests/test_meca.py index aa61212c631..5f5e0518b5d 100644 --- a/pygmt/tests/test_meca.py +++ b/pygmt/tests/test_meca.py @@ -17,7 +17,7 @@ def test_meca_spec_dictionary(): fig = Figure() # Right lateral strike slip focal mechanism fig.meca( - spec=dict(strike=0, dip=90, rake=0, magnitude=5), + spec={"strike": 0, "dip": 90, "rake": 0, "magnitude": 5}, longitude=0, latitude=5, depth=0, @@ -37,9 +37,12 @@ def test_meca_spec_dict_list(): """ fig = Figure() # supply focal mechanisms as a dict of lists - focal_mechanisms = dict( - strike=[330, 350], dip=[30, 50], rake=[90, 90], magnitude=[3, 2] - ) + focal_mechanisms = { + "strike": [330, 350], + "dip": [30, 50], + "rake": [90, 90], + "magnitude": [3, 2], + } fig.meca( spec=focal_mechanisms, longitude=[-123.5, -124.5], @@ -61,17 +64,16 @@ def test_meca_spec_dataframe(): """ fig = Figure() - # supply focal mechanisms to meca as a dataframe - focal_mechanisms = dict( - strike=[324, 353], - dip=[20.6, 40], - rake=[83, 90], - magnitude=[3.4, 2.9], - longitude=[-124, -124.4], - latitude=[48.1, 48.2], - depth=[12, 11.0], - ) + focal_mechanisms = { + "strike": [324, 353], + "dip": [20.6, 40], + "rake": [83, 90], + "magnitude": [3.4, 2.9], + "longitude": [-124, -124.4], + "latitude": [48.1, 48.2], + "depth": [12, 11.0], + } fig.meca( spec=pd.DataFrame(data=focal_mechanisms), region=[-125, -122, 47, 49], @@ -181,9 +183,12 @@ def test_meca_loc_array(): """ fig = Figure() # specify focal mechanisms - focal_mechanisms = dict( - strike=[327, 350], dip=[41, 50], rake=[68, 90], magnitude=[3, 2] - ) + focal_mechanisms = { + "strike": [327, 350], + "dip": [41, 50], + "rake": [68, 90], + "magnitude": [3, 2], + } # longitude, latitude, and depth may be specified as an int, float, # list, or 1-D numpy array longitude = np.array([-123.3, -124.4]) @@ -209,16 +214,16 @@ def test_meca_gcmt_convention(): """ fig = Figure() # specify focal mechanisms - focal_mechanisms = dict( - strike1=180, - dip1=18, - rake1=-88, - strike2=0, - dip2=72, - rake2=-90, - mantissa=5.5, - exponent=0, - ) + focal_mechanisms = { + "strike1": 180, + "dip1": 18, + "rake1": -88, + "strike2": 0, + "dip2": 72, + "rake2": -90, + "mantissa": 5.5, + "exponent": 0, + } fig.meca( spec=focal_mechanisms, scale="1c", @@ -239,7 +244,7 @@ def test_meca_dict_offset(): Test offsetting beachballs for a dict input. """ fig = Figure() - focal_mechanism = dict(strike=330, dip=30, rake=90, magnitude=3) + focal_mechanism = {"strike": 330, "dip": 30, "rake": 90, "magnitude": 3} fig.basemap(region=[-125, -122, 47, 49], projection="M6c", frame=True) fig.meca( spec=focal_mechanism, @@ -262,14 +267,14 @@ def test_meca_dict_offset_in_dict(): See https://github.com/GenericMappingTools/pygmt/issues/2016. """ fig = Figure() - focal_mechanism = dict( - strike=330, - dip=30, - rake=90, - magnitude=3, - plot_longitude=-124.5, - plot_latitude=47.5, - ) + focal_mechanism = { + "strike": 330, + "dip": 30, + "rake": 90, + "magnitude": 3, + "plot_longitude": -124.5, + "plot_latitude": 47.5, + } fig.basemap(region=[-125, -122, 47, 49], projection="M6c", frame=True) fig.meca( spec=focal_mechanism, @@ -287,7 +292,7 @@ def test_meca_dict_eventname(): Test offsetting beachballs for a dict input. """ fig = Figure() - focal_mechanism = dict(strike=330, dip=30, rake=90, magnitude=3) + focal_mechanism = {"strike": 330, "dip": 30, "rake": 90, "magnitude": 3} fig.basemap(region=[-125, -122, 47, 49], projection="M6c", frame=True) fig.meca( spec=focal_mechanism, @@ -306,7 +311,7 @@ def test_meca_dict_offset_eventname(): Test offsetting beachballs for a dict input. """ fig = Figure() - focal_mechanism = dict(strike=330, dip=30, rake=90, magnitude=3) + focal_mechanism = {"strike": 330, "dip": 30, "rake": 90, "magnitude": 3} fig.basemap(region=[-125, -122, 47, 49], projection="M6c", frame=True) fig.meca( spec=focal_mechanism, @@ -332,16 +337,16 @@ def test_meca_spec_dict_all_scalars(): fig = Figure() fig.basemap(region=[-125, -122, 47, 49], projection="M6c", frame=True) fig.meca( - spec=dict( - strike=330, - dip=30, - rake=90, - magnitude=3, - longitude=-124, - latitude=48, - depth=12.0, - event_name="Event20220311", - ), + spec={ + "strike": 330, + "dip": 30, + "rake": 90, + "magnitude": 3, + "longitude": -124, + "latitude": 48, + "depth": 12.0, + "event_name": "Event20220311", + }, scale="1c", ) return fig diff --git a/pygmt/tests/test_plot.py b/pygmt/tests/test_plot.py index 8a020d1c3b2..5f56d5b0dda 100644 --- a/pygmt/tests/test_plot.py +++ b/pygmt/tests/test_plot.py @@ -99,7 +99,7 @@ def test_plot_fail_1d_array_with_data(data, region): are used with matrix. """ fig = Figure() - kwargs = dict(data=data, region=region, projection="X10c", frame="afg") + kwargs = {"data": data, "region": region, "projection": "X10c", "frame": "afg"} with pytest.raises(GMTInvalidInput): fig.plot(style="c0.2c", fill=data[:, 2], **kwargs) with pytest.raises(GMTInvalidInput): diff --git a/pygmt/tests/test_plot3d.py b/pygmt/tests/test_plot3d.py index 4378b350c03..37dd1775819 100644 --- a/pygmt/tests/test_plot3d.py +++ b/pygmt/tests/test_plot3d.py @@ -80,7 +80,7 @@ def test_plot3d_fail_1d_array_with_data(data, region): are used with matrix. """ fig = Figure() - kwargs = dict(data=data, region=region, projection="X10c", frame="afg") + kwargs = {"data": data, "region": region, "projection": "X10c", "frame": "afg"} with pytest.raises(GMTInvalidInput): fig.plot3d(style="c0.2c", fill=data[:, 2], **kwargs) with pytest.raises(GMTInvalidInput): diff --git a/pygmt/tests/test_surface.py b/pygmt/tests/test_surface.py index 2950fa5c4bd..6ecb1802daf 100644 --- a/pygmt/tests/test_surface.py +++ b/pygmt/tests/test_surface.py @@ -18,7 +18,7 @@ def fixture_data(): """ fname = which("@Table_5_11_mean.xyz", download="c") return pd.read_csv( - fname, sep=r"\s+", header=None, names=["x", "y", "z"], skiprows=1 + fname, delim_whitespace=True, header=None, names=["x", "y", "z"], skiprows=1 ) @@ -55,10 +55,10 @@ def fixture_expected_grid(): [897.4532, 822.9642, 756.4472, 687.594, 626.2299], [910.2932, 823.3307, 737.9952, 651.4994, 565.9981], ], - coords=dict( - y=[0, 1, 2, 3, 4, 5, 6, 7, 8], - x=[0, 1, 2, 3, 4], - ), + coords={ + "y": [0, 1, 2, 3, 4, 5, 6, 7, 8], + "x": [0, 1, 2, 3, 4], + }, dims=[ "y", "x", diff --git a/pygmt/tests/test_triangulate.py b/pygmt/tests/test_triangulate.py index 618aa612f6f..0334af560ef 100644 --- a/pygmt/tests/test_triangulate.py +++ b/pygmt/tests/test_triangulate.py @@ -19,7 +19,7 @@ def fixture_dataframe(): """ fname = which("@Table_5_11_mean.xyz", download="c") return pd.read_csv( - fname, sep=r"\s+", header=None, names=["x", "y", "z"], skiprows=1 + fname, delim_whitespace=True, header=None, names=["x", "y", "z"], skiprows=1 )[:10] @@ -54,7 +54,7 @@ def fixture_expected_grid(): """ return xr.DataArray( data=[[779.6264, 752.1539, 749.38776], [771.2882, 726.9792, 722.1368]], - coords=dict(y=[5, 6], x=[2, 3, 4]), + coords={"y": [5, 6], "x": [2, 3, 4]}, dims=["y", "x"], ) diff --git a/pygmt/tests/test_xyz2grd.py b/pygmt/tests/test_xyz2grd.py index ad6c7a0f1f8..9427a13d0d0 100644 --- a/pygmt/tests/test_xyz2grd.py +++ b/pygmt/tests/test_xyz2grd.py @@ -31,10 +31,10 @@ def fixture_expected_grid(): [-2546.2512, -1977.8754, -963.23303], [-352.3795, -1025.4508, np.nan], ], - coords=dict( - x=[245.0, 250.0, 255.0], - y=[20.0, 25.0, 30.0], - ), + coords={ + "x": [245.0, 250.0, 255.0], + "y": [20.0, 25.0, 30.0], + }, dims=["y", "x"], ) From 5653ef1431a58512a2b1bb57f9bb3ad5e6ae307e Mon Sep 17 00:00:00 2001 From: actions-bot <58130806+actions-bot@users.noreply.github.com> Date: Mon, 6 Feb 2023 11:08:06 +0000 Subject: [PATCH 23/24] [format-command] fixes --- pygmt/src/surface.py | 56 ++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/pygmt/src/surface.py b/pygmt/src/surface.py index bf262e67d7e..b79ccc0812d 100644 --- a/pygmt/src/surface.py +++ b/pygmt/src/surface.py @@ -47,21 +47,21 @@ def surface(data=None, x=None, y=None, z=None, **kwargs): .. math:: (1 - t)\nabla^2(z)+t\nabla(z) = 0 where :math:`t` is a tension factor between 0 and 1, and :math:`\nabla` - indicates the Laplacian operator. Here, :math:`t = 0` gives the - “minimum curvature” solution. Minimum curvature can cause undesired - oscillations and false local maxima or minima (See Smith and Wessel, + indicates the Laplacian operator. Here, :math:`t = 0` gives the + “minimum curvature” solution. Minimum curvature can cause undesired + oscillations and false local maxima or minima (See Smith and Wessel, 1990), and you may wish to use :math:`t > 0` to suppress these effects. - Experience suggests :math:`t \sim 0.25` usually looks good for potential - field data and t should be larger (:math:`t \sim 0.35`) for steep - topography data. :math:`t = 1` gives a harmonic surface (no maxima or - minima are possible except at control data points). It is recommended that - the user preprocess the data with :class:`pygmt.blockmean`, - :class:`pygmt.blockmedian`, or :class:`pygmt.blockmode` to avoid spatial - aliasing and eliminate redundant data. You may impose lower and/or upper - bounds on the solution. These may be entered in the form of a fixed value, - a grid with values, or simply be the minimum/maximum input data values. - Natural boundary conditions are applied at the edges, except for - geographic data with 360-degree range where we apply periodic boundary + Experience suggests :math:`t \sim 0.25` usually looks good for potential + field data and t should be larger (:math:`t \sim 0.35`) for steep + topography data. :math:`t = 1` gives a harmonic surface (no maxima or + minima are possible except at control data points). It is recommended that + the user preprocess the data with :class:`pygmt.blockmean`, + :class:`pygmt.blockmedian`, or :class:`pygmt.blockmode` to avoid spatial + aliasing and eliminate redundant data. You may impose lower and/or upper + bounds on the solution. These may be entered in the form of a fixed value, + a grid with values, or simply be the minimum/maximum input data values. + Natural boundary conditions are applied at the edges, except for + geographic data with 360-degree range where we apply periodic boundary conditions in the longitude direction. Takes a matrix, (x, y, z) triplets, or a file name as input. @@ -89,14 +89,14 @@ def surface(data=None, x=None, y=None, z=None, **kwargs): Optional. The file name for the output netcdf file with extension .nc to store the grid in. convergence : float - Optional. Convergence limit. Iteration is assumed to have converged - when the maximum absolute change in any grid value is less than - ``convergence``. (Units same as data z units). Alternatively, - give limit in percentage of root-mean-square (rms) deviation by - appending %. [Default is scaled to :math:`10^{{-4}}` of the rms - deviation of the data from a best-fit (least-squares) plane.]. - This is the final convergence limit at the desired grid spacing; - for intermediate (coarser) grids the effective convergence limit is + Optional. Convergence limit. Iteration is assumed to have converged + when the maximum absolute change in any grid value is less than + ``convergence``. (Units same as data z units). Alternatively, + give limit in percentage of root-mean-square (rms) deviation by + appending %. [Default is scaled to :math:`10^{{-4}}` of the rms + deviation of the data from a best-fit (least-squares) plane.]. + This is the final convergence limit at the desired grid spacing; + for intermediate (coarser) grids the effective convergence limit is divided by the grid spacing multiplier. maxradius : int or str Optional. After solving for the surface, apply a mask so that nodes @@ -116,12 +116,12 @@ def surface(data=None, x=None, y=None, z=None, **kwargs): the limits may contain NaNs. In the presence of NaNs, the limit of a node masked with NaN is unconstrained. upper : float or str - Optional. Impose limits on the output solution. Parameter ``upper`` - sets the upper bound and can be the name of a grid file with upper - bound values, a fixed value, **d** to set to maximum input value, - or **u** for unconstrained [Default]. Grid files used to set the - limits may contain NaNs. In the presence of NaNs, the limit of a - node masked with NaN is unconstrained. + Optional. Impose limits on the output solution. Parameter ``upper`` + sets the upper bound and can be the name of a grid file with upper + bound values, a fixed value, **d** to set to maximum input value, + or **u** for unconstrained [Default]. Grid files used to set the + limits may contain NaNs. In the presence of NaNs, the limit of a + node masked with NaN is unconstrained. tension : float or str [**b**\|\ **i**]. Optional. Tension factor[s]. These must be between 0 and 1. Tension From 8da18ee55d29308b489469e0ab11fce321c4d3fb Mon Sep 17 00:00:00 2001 From: Tong <86273921+JingHuiTong@users.noreply.github.com> Date: Tue, 7 Feb 2023 17:01:02 +0800 Subject: [PATCH 24/24] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> Co-authored-by: Yvonne Fröhlich <94163266+yvonnefroehlich@users.noreply.github.com> --- pygmt/src/surface.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pygmt/src/surface.py b/pygmt/src/surface.py index b79ccc0812d..bb6b499d51a 100644 --- a/pygmt/src/surface.py +++ b/pygmt/src/surface.py @@ -48,15 +48,15 @@ def surface(data=None, x=None, y=None, z=None, **kwargs): where :math:`t` is a tension factor between 0 and 1, and :math:`\nabla` indicates the Laplacian operator. Here, :math:`t = 0` gives the - “minimum curvature” solution. Minimum curvature can cause undesired - oscillations and false local maxima or minima (See Smith and Wessel, + "minimum curvature" solution. Minimum curvature can cause undesired + oscillations and false local maxima or minima (see Smith and Wessel, 1990), and you may wish to use :math:`t > 0` to suppress these effects. Experience suggests :math:`t \sim 0.25` usually looks good for potential field data and t should be larger (:math:`t \sim 0.35`) for steep topography data. :math:`t = 1` gives a harmonic surface (no maxima or minima are possible except at control data points). It is recommended that - the user preprocess the data with :class:`pygmt.blockmean`, - :class:`pygmt.blockmedian`, or :class:`pygmt.blockmode` to avoid spatial + the user preprocess the data with :func:`pygmt.blockmean`, + :func:`pygmt.blockmedian`, or :func:`pygmt.blockmode` to avoid spatial aliasing and eliminate redundant data. You may impose lower and/or upper bounds on the solution. These may be entered in the form of a fixed value, a grid with values, or simply be the minimum/maximum input data values. @@ -94,14 +94,14 @@ def surface(data=None, x=None, y=None, z=None, **kwargs): ``convergence``. (Units same as data z units). Alternatively, give limit in percentage of root-mean-square (rms) deviation by appending %. [Default is scaled to :math:`10^{{-4}}` of the rms - deviation of the data from a best-fit (least-squares) plane.]. + deviation of the data from a best-fit (least-squares) plane.] This is the final convergence limit at the desired grid spacing; for intermediate (coarser) grids the effective convergence limit is divided by the grid spacing multiplier. maxradius : int or str Optional. After solving for the surface, apply a mask so that nodes farther than ``maxradius`` away from a data constraint are set to NaN - [Default is no masking]. Append a distance unit (See + [Default is no masking]. Append a distance unit (see :gmt-docs:`Units `) if needed. One can also select the nodes to mask by using the *n_cells*\ **c** form. Here *n_cells* means the number of cells around the node is controlled