From c43f016c68b91dc07378b8c9acf1b6fd21c0dbe3 Mon Sep 17 00:00:00 2001 From: Oliwia Baney Date: Thu, 19 Aug 2021 18:04:32 -0400 Subject: [PATCH 1/4] Rename outfile to outgrid in surface --- pygmt/src/surface.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/pygmt/src/surface.py b/pygmt/src/surface.py index 1d24a438595..857f8602c8e 100644 --- a/pygmt/src/surface.py +++ b/pygmt/src/surface.py @@ -9,6 +9,7 @@ GMTTempFile, build_arg_string, data_kind, + deprecate_parameter, dummy_context, fmt_docstring, kwargs_to_strings, @@ -17,10 +18,11 @@ @fmt_docstring +@deprecate_parameter("outfile", "outgrid", "v0.5.0", remove_version="v0.7.0") @use_alias( I="spacing", R="region", - G="outfile", + G="outgrid", V="verbose", a="aspatial", f="coltypes", @@ -60,7 +62,7 @@ def surface(x=None, y=None, z=None, data=None, **kwargs): *xmin/xmax/ymin/ymax*\[**+r**][**+u**\ *unit*]. Specify the region of interest. - outfile : str + outgrid : str Optional. The file name for the output netcdf file with extension .nc to store the grid in. @@ -72,11 +74,11 @@ def surface(x=None, y=None, z=None, data=None, **kwargs): Returns ------- ret: xarray.DataArray or None - Return type depends on whether the ``outfile`` parameter is set: + Return type depends on whether the ``outgrid`` parameter is set: - - :class:`xarray.DataArray`: if ``outfile`` is not set - - None if ``outfile`` is set (grid output will be stored in file set by - ``outfile``) + - :class:`xarray.DataArray`: if ``outgrid`` is not set + - None if ``outgrid`` is set (grid output will be stored in file set by + ``outgrid``) """ kind = data_kind(data, x, y, z) if kind == "vectors" and z is None: @@ -93,17 +95,17 @@ def surface(x=None, y=None, z=None, data=None, **kwargs): else: raise GMTInvalidInput("Unrecognized data type: {}".format(type(data))) with file_context as infile: - if "G" not in kwargs.keys(): # if outfile is unset, output to tmpfile + if "G" not in kwargs.keys(): # if outgrid is unset, output to tmpfile kwargs.update({"G": tmpfile.name}) - outfile = kwargs["G"] + outgrid = kwargs["G"] arg_str = " ".join([infile, build_arg_string(kwargs)]) lib.call_module(module="surface", args=arg_str) - if outfile == tmpfile.name: # if user did not set outfile, return DataArray - with xr.open_dataarray(outfile) as dataarray: + if outgrid == tmpfile.name: # if user did not set outgrid, return DataArray + with xr.open_dataarray(outgrid) as dataarray: result = dataarray.load() _ = result.gmt # load GMTDataArray accessor information - elif outfile != tmpfile.name: # if user sets an outfile, return None + elif outgrid != tmpfile.name: # if user sets an outgrid, return None result = None return result From d0d81cf3df739287e8bcea5cc0d7fe144f59fe51 Mon Sep 17 00:00:00 2001 From: Oliwia Baney Date: Thu, 19 Aug 2021 19:21:09 -0400 Subject: [PATCH 2/4] Switch outfile to outgrid in test file --- pygmt/tests/test_surface.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pygmt/tests/test_surface.py b/pygmt/tests/test_surface.py index 0b27d569a91..13536806c22 100644 --- a/pygmt/tests/test_surface.py +++ b/pygmt/tests/test_surface.py @@ -82,17 +82,17 @@ def test_surface_wrong_kind_of_input(ship_data): surface(data=data, spacing="5m", region=[245, 255, 20, 30]) -def test_surface_with_outfile_param(ship_data): +def test_surface_with_outgrid_param(ship_data): """ Run surface with the -Goutputfile.nc parameter. """ data = ship_data.values # convert pandas.DataFrame to numpy.ndarray try: output = surface( - data=data, spacing="5m", region=[245, 255, 20, 30], outfile=TEMP_GRID + data=data, spacing="5m", region=[245, 255, 20, 30], outgrid=TEMP_GRID ) - assert output is None # check that output is None since outfile is set - assert os.path.exists(path=TEMP_GRID) # check that outfile exists at path + assert output is None # check that output is None since outgrid is set + assert os.path.exists(path=TEMP_GRID) # check that outgrid exists at path with xr.open_dataarray(TEMP_GRID) as grid: assert isinstance(grid, xr.DataArray) # ensure netcdf grid loads ok finally: @@ -103,13 +103,13 @@ def test_surface_with_outfile_param(ship_data): def test_surface_short_aliases(ship_data): """ Run surface using short aliases -I for spacing, -R for region, -G for - outfile. + outgrid. """ data = ship_data.values # convert pandas.DataFrame to numpy.ndarray try: output = surface(data=data, I="5m", R=[245, 255, 20, 30], G=TEMP_GRID) - assert output is None # check that output is None since outfile is set - assert os.path.exists(path=TEMP_GRID) # check that outfile exists at path + assert output is None # check that output is None since outgrid is set + assert os.path.exists(path=TEMP_GRID) # check that outgrid exists at path with xr.open_dataarray(TEMP_GRID) as grid: assert isinstance(grid, xr.DataArray) # ensure netcdf grid loads ok finally: From aa041f3bf782e94167d804da0defe45a319e1f6c Mon Sep 17 00:00:00 2001 From: obaney <81708927+obaney@users.noreply.github.com> Date: Wed, 1 Sep 2021 14:19:02 -0400 Subject: [PATCH 3/4] Update pygmt/tests/test_surface.py Co-authored-by: Meghan Jones --- pygmt/tests/test_surface.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/pygmt/tests/test_surface.py b/pygmt/tests/test_surface.py index 13536806c22..89928199b3a 100644 --- a/pygmt/tests/test_surface.py +++ b/pygmt/tests/test_surface.py @@ -100,6 +100,27 @@ def test_surface_with_outgrid_param(ship_data): return output +def test_surface_deprecate_outfile_to_outgrid(ship_data): + """ + Make sure that the old parameter "outfile" is supported and it reports a + warning. + """ + with pytest.warns(expected_warning=FutureWarning) as record: + data = ship_data.values # convert pandas.DataFrame to numpy.ndarray + try: + output = surface( + data=data, spacing="5m", region=[245, 255, 20, 30], outfile=TEMP_GRID + ) + assert output is None # check that output is None since outfile is set + assert os.path.exists(path=TEMP_GRID) # check that file exists at path + + with xr.open_dataarray(TEMP_GRID) as grid: + assert isinstance(grid, xr.DataArray) # ensure netcdf grid loads ok + finally: + os.remove(path=TEMP_GRID) + assert len(record) == 1 # check that only one warning was raised + + def test_surface_short_aliases(ship_data): """ Run surface using short aliases -I for spacing, -R for region, -G for From a8c5b561e42fb7b67c535c820a133b60e3ca59e4 Mon Sep 17 00:00:00 2001 From: actions-bot <58130806+actions-bot@users.noreply.github.com> Date: Wed, 1 Sep 2021 18:57:46 +0000 Subject: [PATCH 4/4] [format-command] fixes --- pygmt/tests/test_surface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/tests/test_surface.py b/pygmt/tests/test_surface.py index 89928199b3a..8d9d84bc45a 100644 --- a/pygmt/tests/test_surface.py +++ b/pygmt/tests/test_surface.py @@ -118,7 +118,7 @@ def test_surface_deprecate_outfile_to_outgrid(ship_data): assert isinstance(grid, xr.DataArray) # ensure netcdf grid loads ok finally: os.remove(path=TEMP_GRID) - assert len(record) == 1 # check that only one warning was raised + assert len(record) == 1 # check that only one warning was raised def test_surface_short_aliases(ship_data):