Skip to content

clib: Rename the virtualfile_from_data method to virtualfile_in #3068

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions doc/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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::
Expand Down
7 changes: 5 additions & 2 deletions pygmt/clib/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Comment on lines +1612 to +1613
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Originally posted by @yvonnefroehlich in #3180 (comment)

Regarding the point

* clib: Rename the "virtualfile_from_data" method to "virtualfile_in" ([#3068](https://github.com/GenericMappingTools/pygmt/pull/3068))

I was / am a bit unsure, as there ins no FutureWarning added and not version stated when virtualfile_from_data is removed.

@seisman, did you want to keep this virtualfile_from_data alias around, or remove it at some point? If removing, should we start to raise a FutureWarning in v0.13.0, and remove it completely in v0.15.0?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If removing, should we start to raise a FutureWarning in v0.13.0, and remove it completely in v0.15.0?

Sounds good

Copy link
Member

@yvonnefroehlich yvonnefroehlich May 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also fine with me.

I have added this to the changelog for v0.12.0; feel free to remove it if you think it is better not to state it before we have implemented it.


@contextlib.contextmanager
def virtualfile_out(
self, kind: Literal["dataset", "grid"] = "dataset", fname: str | None = None
Expand Down
2 changes: 1 addition & 1 deletion pygmt/src/binstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pygmt/src/blockm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pygmt/src/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pygmt/src/dimfilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pygmt/src/filter1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pygmt/src/grd2cpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pygmt/src/grd2xyz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pygmt/src/grdclip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pygmt/src/grdcontour.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pygmt/src/grdcut.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pygmt/src/grdfill.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pygmt/src/grdfilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pygmt/src/grdgradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions pygmt/src/grdhisteq.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions pygmt/src/grdimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pygmt/src/grdinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion pygmt/src/grdproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pygmt/src/grdsample.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pygmt/src/grdtrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pygmt/src/grdview.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pygmt/src/grdvolume.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pygmt/src/histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pygmt/src/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion pygmt/src/meca.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
2 changes: 1 addition & 1 deletion pygmt/src/nearneighbor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pygmt/src/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
2 changes: 1 addition & 1 deletion pygmt/src/plot3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pygmt/src/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
2 changes: 1 addition & 1 deletion pygmt/src/rose.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
2 changes: 1 addition & 1 deletion pygmt/src/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pygmt/src/sph2grd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions pygmt/src/sphdistance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pygmt/src/sphinterpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pygmt/src/surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pygmt/src/ternary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion pygmt/src/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pygmt/src/tilemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading