diff --git a/pygmt/src/binstats.py b/pygmt/src/binstats.py index 3304ee9ea54..f34ad8ca911 100644 --- a/pygmt/src/binstats.py +++ b/pygmt/src/binstats.py @@ -112,12 +112,11 @@ def binstats(data, **kwargs): """ with GMTTempFile(suffix=".nc") as tmpfile: with Session() as lib: - file_context = lib.virtualfile_in(check_kind="vector", data=data) - with file_context as infile: + with lib.virtualfile_in(check_kind="vector", data=data) as vintbl: if (outgrid := kwargs.get("G")) is None: kwargs["G"] = outgrid = tmpfile.name # output to tmpfile lib.call_module( - module="binstats", args=build_arg_string(kwargs, infile=infile) + module="binstats", args=build_arg_string(kwargs, infile=vintbl) ) return load_dataarray(outgrid) if outgrid == tmpfile.name else None diff --git a/pygmt/src/blockm.py b/pygmt/src/blockm.py index 038066cacac..c863f32f3b0 100644 --- a/pygmt/src/blockm.py +++ b/pygmt/src/blockm.py @@ -44,16 +44,15 @@ def _blockm(block_method, data, x, y, z, outfile, **kwargs): """ with GMTTempFile(suffix=".csv") as tmpfile: with Session() as lib: - table_context = lib.virtualfile_in( + with lib.virtualfile_in( check_kind="vector", data=data, x=x, y=y, z=z, required_z=True - ) - # Run blockm* on data table - with table_context as infile: + ) as vintbl: + # Run blockm* on data table if outfile is None: outfile = tmpfile.name lib.call_module( module=block_method, - args=build_arg_string(kwargs, infile=infile, outfile=outfile), + args=build_arg_string(kwargs, infile=vintbl, outfile=outfile), ) # Read temporary csv output to a pandas table diff --git a/pygmt/src/contour.py b/pygmt/src/contour.py index 60e7038ccfa..9a481a167fa 100644 --- a/pygmt/src/contour.py +++ b/pygmt/src/contour.py @@ -115,10 +115,9 @@ def contour(self, data=None, x=None, y=None, z=None, **kwargs): kwargs = self._preprocess(**kwargs) with Session() as lib: - file_context = lib.virtualfile_in( + with lib.virtualfile_in( check_kind="vector", data=data, x=x, y=y, z=z, required_z=True - ) - with file_context as fname: + ) as vintbl: lib.call_module( - module="contour", args=build_arg_string(kwargs, infile=fname) + module="contour", args=build_arg_string(kwargs, infile=vintbl) ) diff --git a/pygmt/src/dimfilter.py b/pygmt/src/dimfilter.py index 1dbaf89e632..fc9355b7f43 100644 --- a/pygmt/src/dimfilter.py +++ b/pygmt/src/dimfilter.py @@ -151,12 +151,11 @@ def dimfilter(grid, **kwargs): with GMTTempFile(suffix=".nc") as tmpfile: with Session() as lib: - file_context = lib.virtualfile_in(check_kind="raster", data=grid) - with file_context as infile: + with lib.virtualfile_in(check_kind="raster", data=grid) as vingrd: if (outgrid := kwargs.get("G")) is None: kwargs["G"] = outgrid = tmpfile.name # output to tmpfile lib.call_module( - module="dimfilter", args=build_arg_string(kwargs, infile=infile) + module="dimfilter", args=build_arg_string(kwargs, infile=vingrd) ) return load_dataarray(outgrid) if outgrid == tmpfile.name else None diff --git a/pygmt/src/filter1d.py b/pygmt/src/filter1d.py index 08232737210..79163e2b0dd 100644 --- a/pygmt/src/filter1d.py +++ b/pygmt/src/filter1d.py @@ -119,13 +119,12 @@ def filter1d(data, output_type="pandas", outfile=None, **kwargs): with GMTTempFile() as tmpfile: with Session() as lib: - file_context = lib.virtualfile_in(check_kind="vector", data=data) - with file_context as infile: + with lib.virtualfile_in(check_kind="vector", data=data) as vintbl: if outfile is None: outfile = tmpfile.name lib.call_module( module="filter1d", - args=build_arg_string(kwargs, infile=infile, outfile=outfile), + args=build_arg_string(kwargs, infile=vintbl, outfile=outfile), ) # Read temporary csv output to a pandas table diff --git a/pygmt/src/grd2cpt.py b/pygmt/src/grd2cpt.py index f0f0d4b8077..9ba6c5aa5bf 100644 --- a/pygmt/src/grd2cpt.py +++ b/pygmt/src/grd2cpt.py @@ -184,13 +184,12 @@ def grd2cpt(grid, **kwargs): if kwargs.get("W") is not None and kwargs.get("Ww") is not None: raise GMTInvalidInput("Set only categorical or cyclic to True, not both.") with Session() as lib: - file_context = lib.virtualfile_in(check_kind="raster", data=grid) - with file_context as infile: + with lib.virtualfile_in(check_kind="raster", data=grid) as vingrd: if kwargs.get("H") is None: # if no output is set - arg_str = build_arg_string(kwargs, infile=infile) + arg_str = build_arg_string(kwargs, infile=vingrd) else: # if output is set outfile, kwargs["H"] = kwargs["H"], True if not outfile or not isinstance(outfile, str): raise GMTInvalidInput("'output' should be a proper file name.") - arg_str = build_arg_string(kwargs, infile=infile, outfile=outfile) + arg_str = build_arg_string(kwargs, infile=vingrd, outfile=outfile) lib.call_module(module="grd2cpt", args=arg_str) diff --git a/pygmt/src/grd2xyz.py b/pygmt/src/grd2xyz.py index b4c94048634..eade93473c2 100644 --- a/pygmt/src/grd2xyz.py +++ b/pygmt/src/grd2xyz.py @@ -158,13 +158,12 @@ def grd2xyz(grid, output_type="pandas", outfile=None, **kwargs): with GMTTempFile() as tmpfile: with Session() as lib: - file_context = lib.virtualfile_in(check_kind="raster", data=grid) - with file_context as infile: + with lib.virtualfile_in(check_kind="raster", data=grid) as vingrd: if outfile is None: outfile = tmpfile.name lib.call_module( module="grd2xyz", - args=build_arg_string(kwargs, infile=infile, outfile=outfile), + args=build_arg_string(kwargs, infile=vingrd, outfile=outfile), ) # Read temporary csv output to a pandas table diff --git a/pygmt/src/grdclip.py b/pygmt/src/grdclip.py index fe3325b75e2..03a75421bf4 100644 --- a/pygmt/src/grdclip.py +++ b/pygmt/src/grdclip.py @@ -97,12 +97,11 @@ def grdclip(grid, **kwargs): """ with GMTTempFile(suffix=".nc") as tmpfile: with Session() as lib: - file_context = lib.virtualfile_in(check_kind="raster", data=grid) - with file_context as infile: + with lib.virtualfile_in(check_kind="raster", data=grid) as vingrd: if (outgrid := kwargs.get("G")) is None: kwargs["G"] = outgrid = tmpfile.name # output to tmpfile lib.call_module( - module="grdclip", args=build_arg_string(kwargs, infile=infile) + module="grdclip", args=build_arg_string(kwargs, infile=vingrd) ) return load_dataarray(outgrid) if outgrid == tmpfile.name else None diff --git a/pygmt/src/grdcontour.py b/pygmt/src/grdcontour.py index 4bedea245bd..89268d8fe51 100644 --- a/pygmt/src/grdcontour.py +++ b/pygmt/src/grdcontour.py @@ -123,8 +123,7 @@ def grdcontour(self, grid, **kwargs): """ kwargs = self._preprocess(**kwargs) with Session() as lib: - file_context = lib.virtualfile_in(check_kind="raster", data=grid) - with file_context as fname: + with lib.virtualfile_in(check_kind="raster", data=grid) as vingrd: lib.call_module( - module="grdcontour", args=build_arg_string(kwargs, infile=fname) + module="grdcontour", args=build_arg_string(kwargs, infile=vingrd) ) diff --git a/pygmt/src/grdcut.py b/pygmt/src/grdcut.py index 8b1f6d358ed..9ffcda213d6 100644 --- a/pygmt/src/grdcut.py +++ b/pygmt/src/grdcut.py @@ -101,12 +101,11 @@ def grdcut(grid, **kwargs): """ with GMTTempFile(suffix=".nc") as tmpfile: with Session() as lib: - file_context = lib.virtualfile_in(check_kind="raster", data=grid) - with file_context as infile: + with lib.virtualfile_in(check_kind="raster", data=grid) as vingrd: if (outgrid := kwargs.get("G")) is None: kwargs["G"] = outgrid = tmpfile.name # output to tmpfile lib.call_module( - module="grdcut", args=build_arg_string(kwargs, infile=infile) + module="grdcut", args=build_arg_string(kwargs, infile=vingrd) ) return load_dataarray(outgrid) if outgrid == tmpfile.name else None diff --git a/pygmt/src/grdfill.py b/pygmt/src/grdfill.py index 8f48838afd1..4eae3818257 100644 --- a/pygmt/src/grdfill.py +++ b/pygmt/src/grdfill.py @@ -79,12 +79,11 @@ def grdfill(grid, **kwargs): raise GMTInvalidInput("At least parameter 'mode' or 'L' must be specified.") with GMTTempFile(suffix=".nc") as tmpfile: with Session() as lib: - file_context = lib.virtualfile_in(check_kind="raster", data=grid) - with file_context as infile: + with lib.virtualfile_in(check_kind="raster", data=grid) as vingrd: if (outgrid := kwargs.get("G")) is None: kwargs["G"] = outgrid = tmpfile.name # output to tmpfile lib.call_module( - module="grdfill", args=build_arg_string(kwargs, infile=infile) + module="grdfill", args=build_arg_string(kwargs, infile=vingrd) ) return load_dataarray(outgrid) if outgrid == tmpfile.name else None diff --git a/pygmt/src/grdfilter.py b/pygmt/src/grdfilter.py index a7d2fc02c08..a4a544819ad 100644 --- a/pygmt/src/grdfilter.py +++ b/pygmt/src/grdfilter.py @@ -134,12 +134,11 @@ def grdfilter(grid, **kwargs): """ with GMTTempFile(suffix=".nc") as tmpfile: with Session() as lib: - file_context = lib.virtualfile_in(check_kind="raster", data=grid) - with file_context as infile: + with lib.virtualfile_in(check_kind="raster", data=grid) as vingrd: if (outgrid := kwargs.get("G")) is None: kwargs["G"] = outgrid = tmpfile.name # output to tmpfile lib.call_module( - module="grdfilter", args=build_arg_string(kwargs, infile=infile) + module="grdfilter", args=build_arg_string(kwargs, infile=vingrd) ) return load_dataarray(outgrid) if outgrid == tmpfile.name else None diff --git a/pygmt/src/grdgradient.py b/pygmt/src/grdgradient.py index 544ac81d3f0..783ef7de48c 100644 --- a/pygmt/src/grdgradient.py +++ b/pygmt/src/grdgradient.py @@ -169,12 +169,11 @@ def grdgradient(grid, **kwargs): azimuth, direction, or radiance""" ) with Session() as lib: - file_context = lib.virtualfile_in(check_kind="raster", data=grid) - with file_context as infile: + with lib.virtualfile_in(check_kind="raster", data=grid) as vingrd: if (outgrid := kwargs.get("G")) is None: kwargs["G"] = outgrid = tmpfile.name # output to tmpfile lib.call_module( - module="grdgradient", args=build_arg_string(kwargs, infile=infile) + module="grdgradient", args=build_arg_string(kwargs, infile=vingrd) ) return load_dataarray(outgrid) if outgrid == tmpfile.name else None diff --git a/pygmt/src/grdimage.py b/pygmt/src/grdimage.py index d670ba1ebaf..281bc5a9016 100644 --- a/pygmt/src/grdimage.py +++ b/pygmt/src/grdimage.py @@ -165,12 +165,12 @@ def grdimage(self, grid, **kwargs): with Session() as lib: with ( - lib.virtualfile_in(check_kind="raster", data=grid) as fname, + lib.virtualfile_in(check_kind="raster", data=grid) as vingrd, lib.virtualfile_in( check_kind="raster", data=kwargs.get("I"), required_data=False - ) as shadegrid, + ) as vshadegrid, ): - kwargs["I"] = shadegrid + kwargs["I"] = vshadegrid lib.call_module( - module="grdimage", args=build_arg_string(kwargs, infile=fname) + module="grdimage", args=build_arg_string(kwargs, infile=vingrd) ) diff --git a/pygmt/src/grdinfo.py b/pygmt/src/grdinfo.py index a0b18795133..02de4924775 100644 --- a/pygmt/src/grdinfo.py +++ b/pygmt/src/grdinfo.py @@ -112,11 +112,10 @@ def grdinfo(grid, **kwargs): """ with GMTTempFile() as outfile: with Session() as lib: - file_context = lib.virtualfile_in(check_kind="raster", data=grid) - with file_context as infile: + with lib.virtualfile_in(check_kind="raster", data=grid) as vingrd: lib.call_module( module="grdinfo", - args=build_arg_string(kwargs, infile=infile, outfile=outfile.name), + args=build_arg_string(kwargs, infile=vingrd, outfile=outfile.name), ) result = outfile.read() return result diff --git a/pygmt/src/grdproject.py b/pygmt/src/grdproject.py index 4c4b06f361d..7903a090f67 100644 --- a/pygmt/src/grdproject.py +++ b/pygmt/src/grdproject.py @@ -113,12 +113,11 @@ def grdproject(grid, **kwargs): raise GMTInvalidInput("The projection must be specified.") with GMTTempFile(suffix=".nc") as tmpfile: with Session() as lib: - file_context = lib.virtualfile_in(check_kind="raster", data=grid) - with file_context as infile: + with lib.virtualfile_in(check_kind="raster", data=grid) as vingrd: if (outgrid := kwargs.get("G")) is None: kwargs["G"] = outgrid = tmpfile.name # output to tmpfile lib.call_module( - module="grdproject", args=build_arg_string(kwargs, infile=infile) + module="grdproject", args=build_arg_string(kwargs, infile=vingrd) ) return load_dataarray(outgrid) if outgrid == tmpfile.name else None diff --git a/pygmt/src/grdsample.py b/pygmt/src/grdsample.py index 2cdc30d3373..350da05ff84 100644 --- a/pygmt/src/grdsample.py +++ b/pygmt/src/grdsample.py @@ -89,12 +89,11 @@ def grdsample(grid, **kwargs): """ with GMTTempFile(suffix=".nc") as tmpfile: with Session() as lib: - file_context = lib.virtualfile_in(check_kind="raster", data=grid) - with file_context as infile: + with lib.virtualfile_in(check_kind="raster", data=grid) as vingrd: if (outgrid := kwargs.get("G")) is None: kwargs["G"] = outgrid = tmpfile.name # output to tmpfile lib.call_module( - module="grdsample", args=build_arg_string(kwargs, infile=infile) + module="grdsample", args=build_arg_string(kwargs, infile=vingrd) ) return load_dataarray(outgrid) if outgrid == tmpfile.name else None diff --git a/pygmt/src/grdtrack.py b/pygmt/src/grdtrack.py index fe13bb02b2d..1e5df5ffbda 100644 --- a/pygmt/src/grdtrack.py +++ b/pygmt/src/grdtrack.py @@ -294,17 +294,17 @@ def grdtrack(grid, points=None, newcolname=None, outfile=None, **kwargs): with GMTTempFile(suffix=".csv") as tmpfile: with Session() as lib: with ( - lib.virtualfile_in(check_kind="raster", data=grid) as grdfile, + lib.virtualfile_in(check_kind="raster", data=grid) as vingrd, lib.virtualfile_in( check_kind="vector", data=points, required_data=False - ) as csvfile, + ) as vintbl, ): - kwargs["G"] = grdfile + kwargs["G"] = vingrd if outfile is None: # Output to tmpfile if outfile is not set outfile = tmpfile.name lib.call_module( module="grdtrack", - args=build_arg_string(kwargs, infile=csvfile, outfile=outfile), + args=build_arg_string(kwargs, infile=vintbl, outfile=outfile), ) # Read temporary csv output to a pandas table diff --git a/pygmt/src/grdview.py b/pygmt/src/grdview.py index 601648b13d7..4863c3b9d9b 100644 --- a/pygmt/src/grdview.py +++ b/pygmt/src/grdview.py @@ -146,12 +146,12 @@ def grdview(self, grid, **kwargs): kwargs = self._preprocess(**kwargs) with Session() as lib: with ( - lib.virtualfile_in(check_kind="raster", data=grid) as fname, + lib.virtualfile_in(check_kind="raster", data=grid) as vingrd, lib.virtualfile_in( check_kind="raster", data=kwargs.get("G"), required_data=False - ) as drapegrid, + ) as vdrapegrid, ): - kwargs["G"] = drapegrid + kwargs["G"] = vdrapegrid lib.call_module( - module="grdview", args=build_arg_string(kwargs, infile=fname) + module="grdview", args=build_arg_string(kwargs, infile=vingrd) ) diff --git a/pygmt/src/grdvolume.py b/pygmt/src/grdvolume.py index d5c6515ee1e..1bb696e9e04 100644 --- a/pygmt/src/grdvolume.py +++ b/pygmt/src/grdvolume.py @@ -105,13 +105,12 @@ def grdvolume(grid, output_type="pandas", outfile=None, **kwargs): with GMTTempFile() as tmpfile: with Session() as lib: - file_context = lib.virtualfile_in(check_kind="raster", data=grid) - with file_context as infile: + with lib.virtualfile_in(check_kind="raster", data=grid) as vingrd: if outfile is None: outfile = tmpfile.name lib.call_module( module="grdvolume", - args=build_arg_string(kwargs, infile=infile, outfile=outfile), + args=build_arg_string(kwargs, infile=vingrd, outfile=outfile), ) # Read temporary csv output to a pandas table diff --git a/pygmt/src/histogram.py b/pygmt/src/histogram.py index 50ae0a71fa2..93b4fff2345 100644 --- a/pygmt/src/histogram.py +++ b/pygmt/src/histogram.py @@ -135,8 +135,7 @@ def histogram(self, data, **kwargs): """ kwargs = self._preprocess(**kwargs) with Session() as lib: - file_context = lib.virtualfile_in(check_kind="vector", data=data) - with file_context as infile: + with lib.virtualfile_in(check_kind="vector", data=data) as vintbl: lib.call_module( - module="histogram", args=build_arg_string(kwargs, infile=infile) + module="histogram", args=build_arg_string(kwargs, infile=vintbl) ) diff --git a/pygmt/src/info.py b/pygmt/src/info.py index ee0e98c676a..e0497d3b162 100644 --- a/pygmt/src/info.py +++ b/pygmt/src/info.py @@ -81,12 +81,11 @@ def info(data, **kwargs): - str if none of the above parameters are used. """ with Session() as lib: - file_context = lib.virtualfile_in(check_kind="vector", data=data) with GMTTempFile() as tmpfile: - with file_context as fname: + with lib.virtualfile_in(check_kind="vector", data=data) as vintbl: lib.call_module( module="info", - args=build_arg_string(kwargs, infile=fname, outfile=tmpfile.name), + args=build_arg_string(kwargs, infile=vintbl, outfile=tmpfile.name), ) result = tmpfile.read() diff --git a/pygmt/src/meca.py b/pygmt/src/meca.py index e4a64c933ee..9161e0dcd0d 100644 --- a/pygmt/src/meca.py +++ b/pygmt/src/meca.py @@ -489,6 +489,5 @@ def meca( # noqa: PLR0912, PLR0913, PLR0915 # Assemble -S flag kwargs["S"] = f"{data_format}{scale}" with Session() as lib: - file_context = lib.virtualfile_in(check_kind="vector", data=spec) - with file_context as fname: - lib.call_module(module="meca", args=build_arg_string(kwargs, infile=fname)) + with lib.virtualfile_in(check_kind="vector", data=spec) as vintbl: + lib.call_module(module="meca", args=build_arg_string(kwargs, infile=vintbl)) diff --git a/pygmt/src/nearneighbor.py b/pygmt/src/nearneighbor.py index 5627cd6a280..a9c7a22ca14 100644 --- a/pygmt/src/nearneighbor.py +++ b/pygmt/src/nearneighbor.py @@ -145,14 +145,13 @@ def nearneighbor(data=None, x=None, y=None, z=None, **kwargs): """ with GMTTempFile(suffix=".nc") as tmpfile: with Session() as lib: - table_context = lib.virtualfile_in( + with lib.virtualfile_in( check_kind="vector", data=data, x=x, y=y, z=z, required_z=True - ) - with table_context as infile: + ) as vintbl: if (outgrid := kwargs.get("G")) is None: kwargs["G"] = outgrid = tmpfile.name # output to tmpfile lib.call_module( - module="nearneighbor", args=build_arg_string(kwargs, infile=infile) + module="nearneighbor", args=build_arg_string(kwargs, infile=vintbl) ) return load_dataarray(outgrid) if outgrid == tmpfile.name else None diff --git a/pygmt/src/plot.py b/pygmt/src/plot.py index aa9171d033e..b4c01b9438e 100644 --- a/pygmt/src/plot.py +++ b/pygmt/src/plot.py @@ -251,9 +251,7 @@ def plot( # noqa: PLR0912 kwargs[flag] = "" with Session() as lib: - file_context = lib.virtualfile_in( + with lib.virtualfile_in( check_kind="vector", data=data, x=x, y=y, extra_arrays=extra_arrays - ) - - with file_context as fname: - lib.call_module(module="plot", args=build_arg_string(kwargs, infile=fname)) + ) as vintbl: + lib.call_module(module="plot", args=build_arg_string(kwargs, infile=vintbl)) diff --git a/pygmt/src/plot3d.py b/pygmt/src/plot3d.py index c22e2270e4a..029820bcec4 100644 --- a/pygmt/src/plot3d.py +++ b/pygmt/src/plot3d.py @@ -226,7 +226,7 @@ def plot3d( # noqa: PLR0912 kwargs[flag] = "" with Session() as lib: - file_context = lib.virtualfile_in( + with lib.virtualfile_in( check_kind="vector", data=data, x=x, @@ -234,9 +234,7 @@ def plot3d( # noqa: PLR0912 z=z, extra_arrays=extra_arrays, required_z=True, - ) - - with file_context as fname: + ) as vintbl: lib.call_module( - module="plot3d", args=build_arg_string(kwargs, infile=fname) + module="plot3d", args=build_arg_string(kwargs, infile=vintbl) ) diff --git a/pygmt/src/project.py b/pygmt/src/project.py index f20cb4a97e6..99738bfd9c8 100644 --- a/pygmt/src/project.py +++ b/pygmt/src/project.py @@ -228,13 +228,11 @@ def project(data=None, x=None, y=None, z=None, outfile=None, **kwargs): outfile = tmpfile.name with Session() as lib: if kwargs.get("G") is None: - table_context = lib.virtualfile_in( + with lib.virtualfile_in( check_kind="vector", data=data, x=x, y=y, z=z, required_z=False - ) - - # Run project on the temporary (csv) data table - with table_context as infile: - arg_str = build_arg_string(kwargs, infile=infile, outfile=outfile) + ) as vintbl: + # Run project on the temporary (csv) data table + arg_str = build_arg_string(kwargs, infile=vintbl, outfile=outfile) else: arg_str = build_arg_string(kwargs, outfile=outfile) lib.call_module(module="project", args=arg_str) diff --git a/pygmt/src/rose.py b/pygmt/src/rose.py index 74c5592bc63..189e68546a2 100644 --- a/pygmt/src/rose.py +++ b/pygmt/src/rose.py @@ -200,9 +200,7 @@ def rose(self, data=None, length=None, azimuth=None, **kwargs): kwargs = self._preprocess(**kwargs) with Session() as lib: - file_context = lib.virtualfile_in( + with lib.virtualfile_in( check_kind="vector", data=data, x=length, y=azimuth - ) - - with file_context as fname: - lib.call_module(module="rose", args=build_arg_string(kwargs, infile=fname)) + ) as vintbl: + lib.call_module(module="rose", args=build_arg_string(kwargs, infile=vintbl)) diff --git a/pygmt/src/select.py b/pygmt/src/select.py index 653b005da01..fe132b356f9 100644 --- a/pygmt/src/select.py +++ b/pygmt/src/select.py @@ -199,13 +199,12 @@ def select(data=None, outfile=None, **kwargs): with GMTTempFile(suffix=".csv") as tmpfile: with Session() as lib: - table_context = lib.virtualfile_in(check_kind="vector", data=data) - with table_context as infile: + with lib.virtualfile_in(check_kind="vector", data=data) as vintbl: if outfile is None: outfile = tmpfile.name lib.call_module( module="select", - args=build_arg_string(kwargs, infile=infile, outfile=outfile), + args=build_arg_string(kwargs, infile=vintbl, outfile=outfile), ) # Read temporary csv output to a pandas table diff --git a/pygmt/src/sph2grd.py b/pygmt/src/sph2grd.py index 582167e5313..53e4f8be280 100644 --- a/pygmt/src/sph2grd.py +++ b/pygmt/src/sph2grd.py @@ -74,12 +74,11 @@ def sph2grd(data, **kwargs): """ with GMTTempFile(suffix=".nc") as tmpfile: with Session() as lib: - file_context = lib.virtualfile_in(check_kind="vector", data=data) - with file_context as infile: + with lib.virtualfile_in(check_kind="vector", data=data) as vintbl: if (outgrid := kwargs.get("G")) is None: kwargs["G"] = outgrid = tmpfile.name # output to tmpfile lib.call_module( - module="sph2grd", args=build_arg_string(kwargs, infile=infile) + module="sph2grd", args=build_arg_string(kwargs, infile=vintbl) ) return load_dataarray(outgrid) if outgrid == tmpfile.name else None diff --git a/pygmt/src/sphdistance.py b/pygmt/src/sphdistance.py index 118e4733e75..e2dc839b0cc 100644 --- a/pygmt/src/sphdistance.py +++ b/pygmt/src/sphdistance.py @@ -118,12 +118,11 @@ def sphdistance(data=None, x=None, y=None, **kwargs): raise GMTInvalidInput("Both 'region' and 'spacing' must be specified.") with GMTTempFile(suffix=".nc") as tmpfile: with Session() as lib: - file_context = lib.virtualfile_in(check_kind="vector", data=data, x=x, y=y) - with file_context as infile: + with lib.virtualfile_in(check_kind="vector", data=data, x=x, y=y) as vintbl: if (outgrid := kwargs.get("G")) is None: kwargs["G"] = outgrid = tmpfile.name # output to tmpfile lib.call_module( - module="sphdistance", args=build_arg_string(kwargs, infile=infile) + module="sphdistance", args=build_arg_string(kwargs, infile=vintbl) ) return load_dataarray(outgrid) if outgrid == tmpfile.name else None diff --git a/pygmt/src/sphinterpolate.py b/pygmt/src/sphinterpolate.py index 461cdff31f0..82bae2eef3a 100644 --- a/pygmt/src/sphinterpolate.py +++ b/pygmt/src/sphinterpolate.py @@ -68,13 +68,12 @@ def sphinterpolate(data, **kwargs): """ with GMTTempFile(suffix=".nc") as tmpfile: with Session() as lib: - file_context = lib.virtualfile_in(check_kind="vector", data=data) - with file_context as infile: + with lib.virtualfile_in(check_kind="vector", data=data) as vintbl: if (outgrid := kwargs.get("G")) is None: kwargs["G"] = outgrid = tmpfile.name # output to tmpfile lib.call_module( module="sphinterpolate", - args=build_arg_string(kwargs, infile=infile), + args=build_arg_string(kwargs, infile=vintbl), ) return load_dataarray(outgrid) if outgrid == tmpfile.name else None diff --git a/pygmt/src/surface.py b/pygmt/src/surface.py index 4e218ad209c..019267a5078 100644 --- a/pygmt/src/surface.py +++ b/pygmt/src/surface.py @@ -160,14 +160,13 @@ def surface(data=None, x=None, y=None, z=None, **kwargs): """ with GMTTempFile(suffix=".nc") as tmpfile: with Session() as lib: - file_context = lib.virtualfile_in( + with lib.virtualfile_in( check_kind="vector", data=data, x=x, y=y, z=z, required_z=True - ) - with file_context as infile: + ) as vintbl: if (outgrid := kwargs.get("G")) is None: kwargs["G"] = outgrid = tmpfile.name # output to tmpfile lib.call_module( - module="surface", args=build_arg_string(kwargs, infile=infile) + module="surface", args=build_arg_string(kwargs, infile=vintbl) ) return load_dataarray(outgrid) if outgrid == tmpfile.name else None diff --git a/pygmt/src/ternary.py b/pygmt/src/ternary.py index fb984457c82..d3761c21b0d 100644 --- a/pygmt/src/ternary.py +++ b/pygmt/src/ternary.py @@ -87,9 +87,8 @@ def ternary(self, data, alabel=None, blabel=None, clabel=None, **kwargs): data = data.to_numpy() with Session() as lib: - file_context = lib.virtualfile_in(check_kind="vector", data=data) - with file_context as infile: + with lib.virtualfile_in(check_kind="vector", data=data) as vintbl: lib.call_module( module="ternary", - args=build_arg_string(kwargs, infile=infile), + args=build_arg_string(kwargs, infile=vintbl), ) diff --git a/pygmt/src/text.py b/pygmt/src/text.py index 5087e9b2186..91432cf9d87 100644 --- a/pygmt/src/text.py +++ b/pygmt/src/text.py @@ -237,8 +237,7 @@ def text_( # noqa: PLR0912 ) with Session() as lib: - file_context = lib.virtualfile_in( + with lib.virtualfile_in( check_kind="vector", data=textfiles, x=x, y=y, extra_arrays=extra_arrays - ) - with file_context as fname: - lib.call_module(module="text", args=build_arg_string(kwargs, infile=fname)) + ) as vintbl: + lib.call_module(module="text", args=build_arg_string(kwargs, infile=vintbl)) diff --git a/pygmt/src/tilemap.py b/pygmt/src/tilemap.py index 7e94b29b7ff..35e41e1c414 100644 --- a/pygmt/src/tilemap.py +++ b/pygmt/src/tilemap.py @@ -164,8 +164,7 @@ def tilemap( kwargs["R"] = "/".join(str(coordinate) for coordinate in region) with Session() as lib: - file_context = lib.virtualfile_in(check_kind="raster", data=raster) - with file_context as infile: + with lib.virtualfile_in(check_kind="raster", data=raster) as vingrd: lib.call_module( - module="grdimage", args=build_arg_string(kwargs, infile=infile) + module="grdimage", args=build_arg_string(kwargs, infile=vingrd) ) diff --git a/pygmt/src/velo.py b/pygmt/src/velo.py index 3f0d485df68..2c349c6b265 100644 --- a/pygmt/src/velo.py +++ b/pygmt/src/velo.py @@ -254,7 +254,5 @@ def velo(self, data=None, **kwargs): ) with Session() as lib: - file_context = lib.virtualfile_in(check_kind="vector", data=data) - - with file_context as fname: - lib.call_module(module="velo", args=build_arg_string(kwargs, infile=fname)) + with lib.virtualfile_in(check_kind="vector", data=data) as vintbl: + lib.call_module(module="velo", args=build_arg_string(kwargs, infile=vintbl)) diff --git a/pygmt/src/wiggle.py b/pygmt/src/wiggle.py index 0b31f179aab..96bf3be0f6d 100644 --- a/pygmt/src/wiggle.py +++ b/pygmt/src/wiggle.py @@ -107,11 +107,9 @@ def wiggle( kwargs["G"].append(fillnegative + "+n") with Session() as lib: - file_context = lib.virtualfile_in( + with lib.virtualfile_in( check_kind="vector", data=data, x=x, y=y, z=z, required_z=True - ) - - with file_context as fname: + ) as vintbl: lib.call_module( - module="wiggle", args=build_arg_string(kwargs, infile=fname) + module="wiggle", args=build_arg_string(kwargs, infile=vintbl) ) diff --git a/pygmt/src/xyz2grd.py b/pygmt/src/xyz2grd.py index 3cd26181608..fcd7a2211b8 100644 --- a/pygmt/src/xyz2grd.py +++ b/pygmt/src/xyz2grd.py @@ -152,14 +152,13 @@ def xyz2grd(data=None, x=None, y=None, z=None, **kwargs): with GMTTempFile(suffix=".nc") as tmpfile: with Session() as lib: - file_context = lib.virtualfile_in( + with lib.virtualfile_in( check_kind="vector", data=data, x=x, y=y, z=z, required_z=True - ) - with file_context as infile: + ) as vintbl: if (outgrid := kwargs.get("G")) is None: kwargs["G"] = outgrid = tmpfile.name # output to tmpfile lib.call_module( - module="xyz2grd", args=build_arg_string(kwargs, infile=infile) + module="xyz2grd", args=build_arg_string(kwargs, infile=vintbl) ) return load_dataarray(outgrid) if outgrid == tmpfile.name else None