From 3debefbb2757589b629aa1fecbafd947aa126f1e Mon Sep 17 00:00:00 2001 From: Aayush7788 Date: Thu, 30 Jul 2026 14:31:16 +0530 Subject: [PATCH 1/2] Add center parameter to block module functions --- pygmt/src/blockm.py | 18 ++++++++++++++++++ pygmt/tests/test_blockm.py | 26 ++++++++++++++++++++++++++ pygmt/tests/test_blockmedian.py | 13 +++++++++++++ 3 files changed, 57 insertions(+) diff --git a/pygmt/src/blockm.py b/pygmt/src/blockm.py index 434778138eb..af0c7f09653 100644 --- a/pygmt/src/blockm.py +++ b/pygmt/src/blockm.py @@ -88,6 +88,7 @@ def blockmean( z=None, output_type: Literal["pandas", "numpy", "file"] = "pandas", outfile: PathLike | None = None, + center: bool = False, spacing: Sequence[float | str] | None = None, region: Sequence[float | str] | str | None = None, verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] @@ -112,6 +113,7 @@ def blockmean( Full GMT docs at :gmt-docs:`blockmean.html`. $aliases + - C = center - I = spacing - R = region - V = verbose @@ -129,6 +131,9 @@ def blockmean( Arrays of x and y coordinates and values z of the data points. $output_type $outfile + center + Use the center of each block as the output location. By default, the + mean x and y coordinates are used. $spacing summary : str [**m**\|\ **n**\|\ **s**\|\ **w**]. @@ -170,6 +175,7 @@ def blockmean( >>> data_bmean = pygmt.blockmean(data=data, region=[245, 255, 20, 30], spacing="5m") """ aliasdict = AliasSystem( + C=Alias(center, name="center"), I=Alias(spacing, name="spacing", sep="/", size=2), ).add_common( R=region, @@ -203,6 +209,7 @@ def blockmedian( z=None, output_type: Literal["pandas", "numpy", "file"] = "pandas", outfile: PathLike | None = None, + center: bool = False, spacing: Sequence[float | str] | None = None, region: Sequence[float | str] | str | None = None, verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] @@ -227,6 +234,7 @@ def blockmedian( Full GMT docs at :gmt-docs:`blockmedian.html`. $aliases + - C = center - I = spacing - R = region - V = verbose @@ -244,6 +252,9 @@ def blockmedian( Arrays of x and y coordinates and values z of the data points. $output_type $outfile + center + Use the center of each block as the output location. By default, the + median x and median y coordinates are used. $spacing $region $verbose @@ -279,6 +290,7 @@ def blockmedian( ... ) """ aliasdict = AliasSystem( + C=Alias(center, name="center"), I=Alias(spacing, name="spacing", sep="/", size=2), ).add_common( R=region, @@ -318,6 +330,7 @@ def blockmode( z=None, output_type: Literal["pandas", "numpy", "file"] = "pandas", outfile: PathLike | None = None, + center: bool = False, spacing: Sequence[float | str] | None = None, region: Sequence[float | str] | str | None = None, verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] @@ -342,6 +355,7 @@ def blockmode( Full GMT docs at :gmt-docs:`blockmode.html`. $aliases + - C = center - I = spacing - R = region - V = verbose @@ -359,6 +373,9 @@ def blockmode( Arrays of x and y coordinates and values z of the data points. $output_type $outfile + center + Use the center of each block as the output location. By default, the + modal x and y coordinates are used. $spacing $region $verbose @@ -392,6 +409,7 @@ def blockmode( >>> data_bmode = pygmt.blockmode(data=data, region=[245, 255, 20, 30], spacing="5m") """ aliasdict = AliasSystem( + C=Alias(center, name="center"), I=Alias(spacing, name="spacing", sep="/", size=2), ).add_common( R=region, diff --git a/pygmt/tests/test_blockm.py b/pygmt/tests/test_blockm.py index b6d01d4e1f1..e9c73bbb5d7 100644 --- a/pygmt/tests/test_blockm.py +++ b/pygmt/tests/test_blockm.py @@ -34,6 +34,19 @@ def test_blockmean_input_dataframe(dataframe): npt.assert_allclose(output.iloc[0], [245.888877, 29.978707, -384.0]) +def test_blockmean_center(dataframe): + """ + Test setting the output location to the center of each block. + """ + output = blockmean( + data=dataframe, spacing="5m", center=True, region=[245, 255, 20, 30] + ) + expected = blockmean( + data=dataframe, spacing="5m", C=True, region=[245, 255, 20, 30] + ) + pd.testing.assert_frame_equal(left=output, right=expected) + + @pytest.mark.parametrize("array_func", [np.array, xr.Dataset]) def test_blockmean_input_table_matrix(array_func, dataframe): """ @@ -111,3 +124,16 @@ def test_blockmode_input_dataframe(dataframe): assert all(dataframe.columns == output.columns) assert output.shape == (5849, 3) npt.assert_allclose(output.iloc[0], [245.88819, 29.97895, -385.0]) + + +def test_blockmode_center(dataframe): + """ + Test setting the output location to the center of each block. + """ + output = blockmode( + data=dataframe, spacing="5m", center=True, region=[245, 255, 20, 30] + ) + expected = blockmode( + data=dataframe, spacing="5m", C=True, region=[245, 255, 20, 30] + ) + pd.testing.assert_frame_equal(left=output, right=expected) diff --git a/pygmt/tests/test_blockmedian.py b/pygmt/tests/test_blockmedian.py index 9bd4e08301d..0b81b5abb1b 100644 --- a/pygmt/tests/test_blockmedian.py +++ b/pygmt/tests/test_blockmedian.py @@ -32,6 +32,19 @@ def test_blockmedian_input_dataframe(dataframe): npt.assert_allclose(output.iloc[0], [245.88819, 29.97895, -385.0]) +def test_blockmedian_center(dataframe): + """ + Test setting the output location to the center of each block. + """ + output = blockmedian( + data=dataframe, spacing="5m", center=True, region=[245, 255, 20, 30] + ) + expected = blockmedian( + data=dataframe, spacing="5m", C=True, region=[245, 255, 20, 30] + ) + pd.testing.assert_frame_equal(left=output, right=expected) + + @pytest.mark.benchmark def test_blockmedian_input_table_matrix(dataframe): """ From d4b70637e8f7f3444b6074735bac6ff57f950ec9 Mon Sep 17 00:00:00 2001 From: Aayush7788 Date: Fri, 31 Jul 2026 21:42:37 +0530 Subject: [PATCH 2/2] Remove redundant alias tests --- pygmt/tests/test_blockm.py | 26 -------------------------- pygmt/tests/test_blockmedian.py | 13 ------------- 2 files changed, 39 deletions(-) diff --git a/pygmt/tests/test_blockm.py b/pygmt/tests/test_blockm.py index e9c73bbb5d7..b6d01d4e1f1 100644 --- a/pygmt/tests/test_blockm.py +++ b/pygmt/tests/test_blockm.py @@ -34,19 +34,6 @@ def test_blockmean_input_dataframe(dataframe): npt.assert_allclose(output.iloc[0], [245.888877, 29.978707, -384.0]) -def test_blockmean_center(dataframe): - """ - Test setting the output location to the center of each block. - """ - output = blockmean( - data=dataframe, spacing="5m", center=True, region=[245, 255, 20, 30] - ) - expected = blockmean( - data=dataframe, spacing="5m", C=True, region=[245, 255, 20, 30] - ) - pd.testing.assert_frame_equal(left=output, right=expected) - - @pytest.mark.parametrize("array_func", [np.array, xr.Dataset]) def test_blockmean_input_table_matrix(array_func, dataframe): """ @@ -124,16 +111,3 @@ def test_blockmode_input_dataframe(dataframe): assert all(dataframe.columns == output.columns) assert output.shape == (5849, 3) npt.assert_allclose(output.iloc[0], [245.88819, 29.97895, -385.0]) - - -def test_blockmode_center(dataframe): - """ - Test setting the output location to the center of each block. - """ - output = blockmode( - data=dataframe, spacing="5m", center=True, region=[245, 255, 20, 30] - ) - expected = blockmode( - data=dataframe, spacing="5m", C=True, region=[245, 255, 20, 30] - ) - pd.testing.assert_frame_equal(left=output, right=expected) diff --git a/pygmt/tests/test_blockmedian.py b/pygmt/tests/test_blockmedian.py index 0b81b5abb1b..9bd4e08301d 100644 --- a/pygmt/tests/test_blockmedian.py +++ b/pygmt/tests/test_blockmedian.py @@ -32,19 +32,6 @@ def test_blockmedian_input_dataframe(dataframe): npt.assert_allclose(output.iloc[0], [245.88819, 29.97895, -385.0]) -def test_blockmedian_center(dataframe): - """ - Test setting the output location to the center of each block. - """ - output = blockmedian( - data=dataframe, spacing="5m", center=True, region=[245, 255, 20, 30] - ) - expected = blockmedian( - data=dataframe, spacing="5m", C=True, region=[245, 255, 20, 30] - ) - pd.testing.assert_frame_equal(left=output, right=expected) - - @pytest.mark.benchmark def test_blockmedian_input_table_matrix(dataframe): """