diff --git a/doc/api/index.rst b/doc/api/index.rst index 0349fae1b3e..8758ef10423 100644 --- a/doc/api/index.rst +++ b/doc/api/index.rst @@ -289,13 +289,12 @@ conversion of Python variables to GMT virtual files: .. autosummary:: :toctree: generated - clib.Session.virtualfile_from_data clib.Session.virtualfile_from_matrix clib.Session.virtualfile_from_vectors clib.Session.virtualfile_from_grid + clib.Session.virtualfile_in clib.Session.virtualfile_out - Low level access (these are mostly used by the :mod:`pygmt.clib` package): .. autosummary:: diff --git a/pygmt/clib/session.py b/pygmt/clib/session.py index fca1d1997c1..d8544a7937b 100644 --- a/pygmt/clib/session.py +++ b/pygmt/clib/session.py @@ -1478,7 +1478,7 @@ def virtualfile_from_grid(self, grid): yield vfile @fmt_docstring - def virtualfile_from_data( # noqa: PLR0912 + def virtualfile_in( # noqa: PLR0912 self, check_kind=None, data=None, @@ -1535,7 +1535,7 @@ def virtualfile_from_data( # noqa: PLR0912 ... ), ... ) >>> with Session() as ses: - ... with ses.virtualfile_from_data(check_kind="vector", data=data) as fin: + ... with ses.virtualfile_in(check_kind="vector", data=data) as fin: ... # Send the output to a file so that we can read it ... with GMTTempFile() as fout: ... ses.call_module("info", fin + " ->" + fout.name) @@ -1609,6 +1609,9 @@ def virtualfile_from_data( # noqa: PLR0912 return file_context + # virtualfile_from_data was renamed to virtualfile_in since v0.12.0. + virtualfile_from_data = virtualfile_in + @contextlib.contextmanager def virtualfile_out( self, kind: Literal["dataset", "grid"] = "dataset", fname: str | None = None diff --git a/pygmt/src/binstats.py b/pygmt/src/binstats.py index f8d0620d0f4..5e5188915b4 100644 --- a/pygmt/src/binstats.py +++ b/pygmt/src/binstats.py @@ -111,7 +111,7 @@ def binstats(data, **kwargs): """ with GMTTempFile(suffix=".nc") as tmpfile: with Session() as lib: - file_context = lib.virtualfile_from_data(check_kind="vector", data=data) + file_context = lib.virtualfile_in(check_kind="vector", data=data) with file_context as infile: if (outgrid := kwargs.get("G")) is None: kwargs["G"] = outgrid = tmpfile.name # output to tmpfile diff --git a/pygmt/src/blockm.py b/pygmt/src/blockm.py index 9dff491ed93..8f0bde7f6f6 100644 --- a/pygmt/src/blockm.py +++ b/pygmt/src/blockm.py @@ -43,7 +43,7 @@ def _blockm(block_method, data, x, y, z, outfile, **kwargs): """ with GMTTempFile(suffix=".csv") as tmpfile: with Session() as lib: - table_context = lib.virtualfile_from_data( + table_context = lib.virtualfile_in( check_kind="vector", data=data, x=x, y=y, z=z, required_z=True ) # Run blockm* on data table diff --git a/pygmt/src/contour.py b/pygmt/src/contour.py index 78c4898a9b4..60e7038ccfa 100644 --- a/pygmt/src/contour.py +++ b/pygmt/src/contour.py @@ -115,7 +115,7 @@ def contour(self, data=None, x=None, y=None, z=None, **kwargs): kwargs = self._preprocess(**kwargs) with Session() as lib: - file_context = lib.virtualfile_from_data( + file_context = lib.virtualfile_in( check_kind="vector", data=data, x=x, y=y, z=z, required_z=True ) with file_context as fname: diff --git a/pygmt/src/dimfilter.py b/pygmt/src/dimfilter.py index d653f02ba4b..1dbaf89e632 100644 --- a/pygmt/src/dimfilter.py +++ b/pygmt/src/dimfilter.py @@ -151,7 +151,7 @@ def dimfilter(grid, **kwargs): with GMTTempFile(suffix=".nc") as tmpfile: with Session() as lib: - file_context = lib.virtualfile_from_data(check_kind="raster", data=grid) + file_context = lib.virtualfile_in(check_kind="raster", data=grid) with file_context as infile: if (outgrid := kwargs.get("G")) is None: kwargs["G"] = outgrid = tmpfile.name # output to tmpfile diff --git a/pygmt/src/filter1d.py b/pygmt/src/filter1d.py index bc07e6e1314..08232737210 100644 --- a/pygmt/src/filter1d.py +++ b/pygmt/src/filter1d.py @@ -119,7 +119,7 @@ def filter1d(data, output_type="pandas", outfile=None, **kwargs): with GMTTempFile() as tmpfile: with Session() as lib: - file_context = lib.virtualfile_from_data(check_kind="vector", data=data) + file_context = lib.virtualfile_in(check_kind="vector", data=data) with file_context as infile: if outfile is None: outfile = tmpfile.name diff --git a/pygmt/src/grd2cpt.py b/pygmt/src/grd2cpt.py index 5d0b8e8adaa..f0f0d4b8077 100644 --- a/pygmt/src/grd2cpt.py +++ b/pygmt/src/grd2cpt.py @@ -184,7 +184,7 @@ 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_from_data(check_kind="raster", data=grid) + file_context = lib.virtualfile_in(check_kind="raster", data=grid) with file_context as infile: if kwargs.get("H") is None: # if no output is set arg_str = build_arg_string(kwargs, infile=infile) diff --git a/pygmt/src/grd2xyz.py b/pygmt/src/grd2xyz.py index f7b70ea8c58..b4c94048634 100644 --- a/pygmt/src/grd2xyz.py +++ b/pygmt/src/grd2xyz.py @@ -158,7 +158,7 @@ def grd2xyz(grid, output_type="pandas", outfile=None, **kwargs): with GMTTempFile() as tmpfile: with Session() as lib: - file_context = lib.virtualfile_from_data(check_kind="raster", data=grid) + file_context = lib.virtualfile_in(check_kind="raster", data=grid) with file_context as infile: if outfile is None: outfile = tmpfile.name diff --git a/pygmt/src/grdclip.py b/pygmt/src/grdclip.py index 878d9db3af2..fe3325b75e2 100644 --- a/pygmt/src/grdclip.py +++ b/pygmt/src/grdclip.py @@ -97,7 +97,7 @@ def grdclip(grid, **kwargs): """ with GMTTempFile(suffix=".nc") as tmpfile: with Session() as lib: - file_context = lib.virtualfile_from_data(check_kind="raster", data=grid) + file_context = lib.virtualfile_in(check_kind="raster", data=grid) with file_context as infile: if (outgrid := kwargs.get("G")) is None: kwargs["G"] = outgrid = tmpfile.name # output to tmpfile diff --git a/pygmt/src/grdcontour.py b/pygmt/src/grdcontour.py index 570323d45d3..6c3707d3e93 100644 --- a/pygmt/src/grdcontour.py +++ b/pygmt/src/grdcontour.py @@ -122,7 +122,7 @@ def grdcontour(self, grid, **kwargs): """ kwargs = self._preprocess(**kwargs) with Session() as lib: - file_context = lib.virtualfile_from_data(check_kind="raster", data=grid) + file_context = lib.virtualfile_in(check_kind="raster", data=grid) with file_context as fname: lib.call_module( module="grdcontour", args=build_arg_string(kwargs, infile=fname) diff --git a/pygmt/src/grdcut.py b/pygmt/src/grdcut.py index eb6cb36ee5d..8b1f6d358ed 100644 --- a/pygmt/src/grdcut.py +++ b/pygmt/src/grdcut.py @@ -101,7 +101,7 @@ def grdcut(grid, **kwargs): """ with GMTTempFile(suffix=".nc") as tmpfile: with Session() as lib: - file_context = lib.virtualfile_from_data(check_kind="raster", data=grid) + file_context = lib.virtualfile_in(check_kind="raster", data=grid) with file_context as infile: if (outgrid := kwargs.get("G")) is None: kwargs["G"] = outgrid = tmpfile.name # output to tmpfile diff --git a/pygmt/src/grdfill.py b/pygmt/src/grdfill.py index aab1b788d53..8f48838afd1 100644 --- a/pygmt/src/grdfill.py +++ b/pygmt/src/grdfill.py @@ -79,7 +79,7 @@ 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_from_data(check_kind="raster", data=grid) + file_context = lib.virtualfile_in(check_kind="raster", data=grid) with file_context as infile: if (outgrid := kwargs.get("G")) is None: kwargs["G"] = outgrid = tmpfile.name # output to tmpfile diff --git a/pygmt/src/grdfilter.py b/pygmt/src/grdfilter.py index 5dbee11f57c..a7d2fc02c08 100644 --- a/pygmt/src/grdfilter.py +++ b/pygmt/src/grdfilter.py @@ -134,7 +134,7 @@ def grdfilter(grid, **kwargs): """ with GMTTempFile(suffix=".nc") as tmpfile: with Session() as lib: - file_context = lib.virtualfile_from_data(check_kind="raster", data=grid) + file_context = lib.virtualfile_in(check_kind="raster", data=grid) with file_context as infile: if (outgrid := kwargs.get("G")) is None: kwargs["G"] = outgrid = tmpfile.name # output to tmpfile diff --git a/pygmt/src/grdgradient.py b/pygmt/src/grdgradient.py index a05f7cb3ab6..544ac81d3f0 100644 --- a/pygmt/src/grdgradient.py +++ b/pygmt/src/grdgradient.py @@ -169,7 +169,7 @@ def grdgradient(grid, **kwargs): azimuth, direction, or radiance""" ) with Session() as lib: - file_context = lib.virtualfile_from_data(check_kind="raster", data=grid) + file_context = lib.virtualfile_in(check_kind="raster", data=grid) with file_context as infile: if (outgrid := kwargs.get("G")) is None: kwargs["G"] = outgrid = tmpfile.name # output to tmpfile diff --git a/pygmt/src/grdhisteq.py b/pygmt/src/grdhisteq.py index df66a9cf78e..0e2c8c9ea60 100644 --- a/pygmt/src/grdhisteq.py +++ b/pygmt/src/grdhisteq.py @@ -123,9 +123,7 @@ def equalize_grid(grid, **kwargs): """ with GMTTempFile(suffix=".nc") as tmpfile: with Session() as lib: - with lib.virtualfile_from_data( - check_kind="raster", data=grid - ) as vingrd: + 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( @@ -235,9 +233,7 @@ def compute_bins(grid, output_type="pandas", **kwargs): with GMTTempFile(suffix=".txt") as tmpfile: with Session() as lib: - with lib.virtualfile_from_data( - check_kind="raster", data=grid - ) as vingrd: + with lib.virtualfile_in(check_kind="raster", data=grid) as vingrd: if outfile is None: kwargs["D"] = outfile = tmpfile.name # output to tmpfile lib.call_module( diff --git a/pygmt/src/grdimage.py b/pygmt/src/grdimage.py index 5c476c13df4..1c9e3319ea2 100644 --- a/pygmt/src/grdimage.py +++ b/pygmt/src/grdimage.py @@ -163,9 +163,9 @@ def grdimage(self, grid, **kwargs): ) with Session() as lib: - with lib.virtualfile_from_data( + with lib.virtualfile_in( check_kind="raster", data=grid - ) as fname, lib.virtualfile_from_data( + ) as fname, lib.virtualfile_in( check_kind="raster", data=kwargs.get("I"), required_data=False ) as shadegrid: kwargs["I"] = shadegrid diff --git a/pygmt/src/grdinfo.py b/pygmt/src/grdinfo.py index b91ab0fbd6c..651e403eac7 100644 --- a/pygmt/src/grdinfo.py +++ b/pygmt/src/grdinfo.py @@ -111,7 +111,7 @@ def grdinfo(grid, **kwargs): """ with GMTTempFile() as outfile: with Session() as lib: - file_context = lib.virtualfile_from_data(check_kind="raster", data=grid) + file_context = lib.virtualfile_in(check_kind="raster", data=grid) with file_context as infile: lib.call_module( module="grdinfo", diff --git a/pygmt/src/grdproject.py b/pygmt/src/grdproject.py index c934bea2e02..3add55e421b 100644 --- a/pygmt/src/grdproject.py +++ b/pygmt/src/grdproject.py @@ -112,7 +112,7 @@ 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_from_data(check_kind="raster", data=grid) + file_context = lib.virtualfile_in(check_kind="raster", data=grid) with file_context as infile: if (outgrid := kwargs.get("G")) is None: kwargs["G"] = outgrid = tmpfile.name # output to tmpfile diff --git a/pygmt/src/grdsample.py b/pygmt/src/grdsample.py index 8e0db8c281e..2cdc30d3373 100644 --- a/pygmt/src/grdsample.py +++ b/pygmt/src/grdsample.py @@ -89,7 +89,7 @@ def grdsample(grid, **kwargs): """ with GMTTempFile(suffix=".nc") as tmpfile: with Session() as lib: - file_context = lib.virtualfile_from_data(check_kind="raster", data=grid) + file_context = lib.virtualfile_in(check_kind="raster", data=grid) with file_context as infile: if (outgrid := kwargs.get("G")) is None: kwargs["G"] = outgrid = tmpfile.name # output to tmpfile diff --git a/pygmt/src/grdtrack.py b/pygmt/src/grdtrack.py index 1d0daa1b800..8859e642fdb 100644 --- a/pygmt/src/grdtrack.py +++ b/pygmt/src/grdtrack.py @@ -292,9 +292,9 @@ def grdtrack(grid, points=None, newcolname=None, outfile=None, **kwargs): with GMTTempFile(suffix=".csv") as tmpfile: with Session() as lib: - with lib.virtualfile_from_data( + with lib.virtualfile_in( check_kind="raster", data=grid - ) as grdfile, lib.virtualfile_from_data( + ) as grdfile, lib.virtualfile_in( check_kind="vector", data=points, required_data=False ) as csvfile: kwargs["G"] = grdfile diff --git a/pygmt/src/grdview.py b/pygmt/src/grdview.py index d43a9c9a160..7ff4a5f7599 100644 --- a/pygmt/src/grdview.py +++ b/pygmt/src/grdview.py @@ -144,9 +144,9 @@ def grdview(self, grid, **kwargs): """ kwargs = self._preprocess(**kwargs) with Session() as lib: - with lib.virtualfile_from_data( + with lib.virtualfile_in( check_kind="raster", data=grid - ) as fname, lib.virtualfile_from_data( + ) as fname, lib.virtualfile_in( check_kind="raster", data=kwargs.get("G"), required_data=False ) as drapegrid: kwargs["G"] = drapegrid diff --git a/pygmt/src/grdvolume.py b/pygmt/src/grdvolume.py index 70d99e19b82..d64b7eb70e0 100644 --- a/pygmt/src/grdvolume.py +++ b/pygmt/src/grdvolume.py @@ -104,7 +104,7 @@ def grdvolume(grid, output_type="pandas", outfile=None, **kwargs): with GMTTempFile() as tmpfile: with Session() as lib: - file_context = lib.virtualfile_from_data(check_kind="raster", data=grid) + file_context = lib.virtualfile_in(check_kind="raster", data=grid) with file_context as infile: if outfile is None: outfile = tmpfile.name diff --git a/pygmt/src/histogram.py b/pygmt/src/histogram.py index b10200a490d..c059cf631eb 100644 --- a/pygmt/src/histogram.py +++ b/pygmt/src/histogram.py @@ -134,7 +134,7 @@ def histogram(self, data, **kwargs): """ kwargs = self._preprocess(**kwargs) with Session() as lib: - file_context = lib.virtualfile_from_data(check_kind="vector", data=data) + file_context = lib.virtualfile_in(check_kind="vector", data=data) with file_context as infile: lib.call_module( module="histogram", args=build_arg_string(kwargs, infile=infile) diff --git a/pygmt/src/info.py b/pygmt/src/info.py index 71fc96cdf35..abf5c4ebd5f 100644 --- a/pygmt/src/info.py +++ b/pygmt/src/info.py @@ -80,7 +80,7 @@ def info(data, **kwargs): - str if none of the above parameters are used. """ with Session() as lib: - file_context = lib.virtualfile_from_data(check_kind="vector", data=data) + file_context = lib.virtualfile_in(check_kind="vector", data=data) with GMTTempFile() as tmpfile: with file_context as fname: lib.call_module( diff --git a/pygmt/src/meca.py b/pygmt/src/meca.py index acaeb3957a3..b66a9529858 100644 --- a/pygmt/src/meca.py +++ b/pygmt/src/meca.py @@ -488,6 +488,6 @@ def meca( # noqa: PLR0912, PLR0913, PLR0915 # Assemble -S flag kwargs["S"] = f"{data_format}{scale}" with Session() as lib: - file_context = lib.virtualfile_from_data(check_kind="vector", data=spec) + 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)) diff --git a/pygmt/src/nearneighbor.py b/pygmt/src/nearneighbor.py index ba839f91aa3..5627cd6a280 100644 --- a/pygmt/src/nearneighbor.py +++ b/pygmt/src/nearneighbor.py @@ -145,7 +145,7 @@ 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_from_data( + table_context = lib.virtualfile_in( check_kind="vector", data=data, x=x, y=y, z=z, required_z=True ) with table_context as infile: diff --git a/pygmt/src/plot.py b/pygmt/src/plot.py index 3c6fe515acb..0c28b81b5a6 100644 --- a/pygmt/src/plot.py +++ b/pygmt/src/plot.py @@ -250,7 +250,7 @@ def plot( # noqa: PLR0912 kwargs[flag] = "" with Session() as lib: - file_context = lib.virtualfile_from_data( + file_context = lib.virtualfile_in( check_kind="vector", data=data, x=x, y=y, extra_arrays=extra_arrays ) diff --git a/pygmt/src/plot3d.py b/pygmt/src/plot3d.py index d313e062811..b783aba0d22 100644 --- a/pygmt/src/plot3d.py +++ b/pygmt/src/plot3d.py @@ -225,7 +225,7 @@ def plot3d( # noqa: PLR0912 kwargs[flag] = "" with Session() as lib: - file_context = lib.virtualfile_from_data( + file_context = lib.virtualfile_in( check_kind="vector", data=data, x=x, diff --git a/pygmt/src/project.py b/pygmt/src/project.py index 6ce7da4b521..bde40f150ed 100644 --- a/pygmt/src/project.py +++ b/pygmt/src/project.py @@ -227,7 +227,7 @@ 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_from_data( + table_context = lib.virtualfile_in( check_kind="vector", data=data, x=x, y=y, z=z, required_z=False ) diff --git a/pygmt/src/rose.py b/pygmt/src/rose.py index 5cc383d4c32..74c5592bc63 100644 --- a/pygmt/src/rose.py +++ b/pygmt/src/rose.py @@ -200,7 +200,7 @@ def rose(self, data=None, length=None, azimuth=None, **kwargs): kwargs = self._preprocess(**kwargs) with Session() as lib: - file_context = lib.virtualfile_from_data( + file_context = lib.virtualfile_in( check_kind="vector", data=data, x=length, y=azimuth ) diff --git a/pygmt/src/select.py b/pygmt/src/select.py index 4c057f83063..d819cadac73 100644 --- a/pygmt/src/select.py +++ b/pygmt/src/select.py @@ -198,7 +198,7 @@ def select(data=None, outfile=None, **kwargs): with GMTTempFile(suffix=".csv") as tmpfile: with Session() as lib: - table_context = lib.virtualfile_from_data(check_kind="vector", data=data) + table_context = lib.virtualfile_in(check_kind="vector", data=data) with table_context as infile: if outfile is None: outfile = tmpfile.name diff --git a/pygmt/src/sph2grd.py b/pygmt/src/sph2grd.py index 40342d691cf..9cf5bcf1fdc 100644 --- a/pygmt/src/sph2grd.py +++ b/pygmt/src/sph2grd.py @@ -73,7 +73,7 @@ def sph2grd(data, **kwargs): """ with GMTTempFile(suffix=".nc") as tmpfile: with Session() as lib: - file_context = lib.virtualfile_from_data(check_kind="vector", data=data) + file_context = lib.virtualfile_in(check_kind="vector", data=data) with file_context as infile: if (outgrid := kwargs.get("G")) is None: kwargs["G"] = outgrid = tmpfile.name # output to tmpfile diff --git a/pygmt/src/sphdistance.py b/pygmt/src/sphdistance.py index cfebb71c8d8..c57431f935e 100644 --- a/pygmt/src/sphdistance.py +++ b/pygmt/src/sphdistance.py @@ -117,9 +117,7 @@ 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_from_data( - check_kind="vector", data=data, x=x, y=y - ) + file_context = lib.virtualfile_in(check_kind="vector", data=data, x=x, y=y) with file_context as infile: if (outgrid := kwargs.get("G")) is None: kwargs["G"] = outgrid = tmpfile.name # output to tmpfile diff --git a/pygmt/src/sphinterpolate.py b/pygmt/src/sphinterpolate.py index 2a5d9e93b54..7be24a8523e 100644 --- a/pygmt/src/sphinterpolate.py +++ b/pygmt/src/sphinterpolate.py @@ -67,7 +67,7 @@ def sphinterpolate(data, **kwargs): """ with GMTTempFile(suffix=".nc") as tmpfile: with Session() as lib: - file_context = lib.virtualfile_from_data(check_kind="vector", data=data) + file_context = lib.virtualfile_in(check_kind="vector", data=data) with file_context as infile: if (outgrid := kwargs.get("G")) is None: kwargs["G"] = outgrid = tmpfile.name # output to tmpfile diff --git a/pygmt/src/surface.py b/pygmt/src/surface.py index 5d96a05ef29..37487ca5fdd 100644 --- a/pygmt/src/surface.py +++ b/pygmt/src/surface.py @@ -159,7 +159,7 @@ 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_from_data( + file_context = lib.virtualfile_in( check_kind="vector", data=data, x=x, y=y, z=z, required_z=True ) with file_context as infile: diff --git a/pygmt/src/ternary.py b/pygmt/src/ternary.py index 66ad4e2d7d9..bf3434c639b 100644 --- a/pygmt/src/ternary.py +++ b/pygmt/src/ternary.py @@ -86,7 +86,7 @@ def ternary(self, data, alabel=None, blabel=None, clabel=None, **kwargs): data = data.to_numpy() with Session() as lib: - file_context = lib.virtualfile_from_data(check_kind="vector", data=data) + file_context = lib.virtualfile_in(check_kind="vector", data=data) with file_context as infile: lib.call_module( module="ternary", diff --git a/pygmt/src/text.py b/pygmt/src/text.py index cd221b34672..16d409136a6 100644 --- a/pygmt/src/text.py +++ b/pygmt/src/text.py @@ -236,7 +236,7 @@ def text_( # noqa: PLR0912 ) with Session() as lib: - file_context = lib.virtualfile_from_data( + file_context = lib.virtualfile_in( check_kind="vector", data=textfiles, x=x, y=y, extra_arrays=extra_arrays ) with file_context as fname: diff --git a/pygmt/src/tilemap.py b/pygmt/src/tilemap.py index 99e82ce63e5..d2aeaad04d9 100644 --- a/pygmt/src/tilemap.py +++ b/pygmt/src/tilemap.py @@ -163,7 +163,7 @@ def tilemap( kwargs["R"] = "/".join(str(coordinate) for coordinate in region) with Session() as lib: - file_context = lib.virtualfile_from_data(check_kind="raster", data=raster) + file_context = lib.virtualfile_in(check_kind="raster", data=raster) with file_context as infile: lib.call_module( module="grdimage", args=build_arg_string(kwargs, infile=infile) diff --git a/pygmt/src/triangulate.py b/pygmt/src/triangulate.py index 73eba530686..e73ab92fe5e 100644 --- a/pygmt/src/triangulate.py +++ b/pygmt/src/triangulate.py @@ -136,7 +136,7 @@ def regular_grid(data=None, x=None, y=None, z=None, **kwargs): # Return an xarray.DataArray if ``outgrid`` is not set with GMTTempFile(suffix=".nc") as tmpfile: with Session() as lib: - with lib.virtualfile_from_data( + with lib.virtualfile_in( check_kind="vector", data=data, x=x, y=y, z=z, required_z=False ) as vintbl: if (outgrid := kwargs.get("G")) is None: @@ -245,7 +245,7 @@ def delaunay_triples( with GMTTempFile(suffix=".txt") as tmpfile: with Session() as lib: - with lib.virtualfile_from_data( + with lib.virtualfile_in( check_kind="vector", data=data, x=x, y=y, z=z, required_z=False ) as vintbl: if outfile is None: diff --git a/pygmt/src/velo.py b/pygmt/src/velo.py index 90e16296bb3..1a81a66b10e 100644 --- a/pygmt/src/velo.py +++ b/pygmt/src/velo.py @@ -253,7 +253,7 @@ def velo(self, data=None, **kwargs): ) with Session() as lib: - file_context = lib.virtualfile_from_data(check_kind="vector", data=data) + 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)) diff --git a/pygmt/src/wiggle.py b/pygmt/src/wiggle.py index 462218b3a49..0b31f179aab 100644 --- a/pygmt/src/wiggle.py +++ b/pygmt/src/wiggle.py @@ -107,7 +107,7 @@ def wiggle( kwargs["G"].append(fillnegative + "+n") with Session() as lib: - file_context = lib.virtualfile_from_data( + file_context = lib.virtualfile_in( check_kind="vector", data=data, x=x, y=y, z=z, required_z=True ) diff --git a/pygmt/src/xyz2grd.py b/pygmt/src/xyz2grd.py index 693d9f0eab7..fed9b82ed7f 100644 --- a/pygmt/src/xyz2grd.py +++ b/pygmt/src/xyz2grd.py @@ -151,7 +151,7 @@ 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_from_data( + file_context = lib.virtualfile_in( check_kind="vector", data=data, x=x, y=y, z=z, required_z=True ) with file_context as infile: diff --git a/pygmt/tests/test_clib_virtualfiles.py b/pygmt/tests/test_clib_virtualfiles.py index 73e05d0b8f8..8b4ae0ad957 100644 --- a/pygmt/tests/test_clib_virtualfiles.py +++ b/pygmt/tests/test_clib_virtualfiles.py @@ -128,7 +128,7 @@ def test_virtual_file_bad_direction(): ("array_func", "kind"), [(np.array, "matrix"), (pd.DataFrame, "vector"), (xr.Dataset, "vector")], ) -def test_virtualfile_from_data_required_z_matrix(array_func, kind): +def test_virtualfile_in_required_z_matrix(array_func, kind): """ Test that function works when third z column in a matrix is needed and provided. """ @@ -138,7 +138,7 @@ def test_virtualfile_from_data_required_z_matrix(array_func, kind): ) data = array_func(dataframe) with clib.Session() as lib: - with lib.virtualfile_from_data( + with lib.virtualfile_in( data=data, required_z=True, check_kind="vector" ) as vfile: with GMTTempFile() as outfile: @@ -154,20 +154,18 @@ def test_virtualfile_from_data_required_z_matrix(array_func, kind): assert output == expected -def test_virtualfile_from_data_required_z_matrix_missing(): +def test_virtualfile_in_required_z_matrix_missing(): """ Test that function fails when third z column in a matrix is needed but not provided. """ data = np.ones((5, 2)) with clib.Session() as lib: with pytest.raises(GMTInvalidInput): - with lib.virtualfile_from_data( - data=data, required_z=True, check_kind="vector" - ): + with lib.virtualfile_in(data=data, required_z=True, check_kind="vector"): pass -def test_virtualfile_from_data_fail_non_valid_data(data): +def test_virtualfile_in_fail_non_valid_data(data): """ Should raise an exception if too few or too much data is given. """ @@ -179,7 +177,7 @@ def test_virtualfile_from_data_fail_non_valid_data(data): continue with clib.Session() as lib: with pytest.raises(GMTInvalidInput): - lib.virtualfile_from_data(x=variable[0], y=variable[1]) + lib.virtualfile_in(x=variable[0], y=variable[1]) # Test all combinations where at least one data variable # is not given in the x, y, z case: @@ -189,14 +187,14 @@ def test_virtualfile_from_data_fail_non_valid_data(data): continue with clib.Session() as lib: with pytest.raises(GMTInvalidInput): - lib.virtualfile_from_data( + lib.virtualfile_in( x=variable[0], y=variable[1], z=variable[2], required_z=True ) # Should also fail if given too much data with clib.Session() as lib: with pytest.raises(GMTInvalidInput): - lib.virtualfile_from_data( + lib.virtualfile_in( x=data[:, 0], y=data[:, 1], z=data[:, 2],