Skip to content

Commit

Permalink
Generalize virtualfile_to_gmtgrid to virtualfile_to_data so it works …
Browse files Browse the repository at this point in the history
…for both grid and dataset
  • Loading branch information
seisman committed Oct 10, 2023
1 parent 0042728 commit 849ed60
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions pygmt/clib/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -1648,29 +1648,37 @@ def read_virtualfile(self, vfname):
return c_read_virtualfile(self.session_pointer, vfname.encode())

@contextmanager
def virtualfile_from_gmtgrid(self, grid_pointer):
def virtualfile_to_data(self, kind):
"""
Create a virtual file for reading a GMT_GRID object.
Create a virtual file for writing a GMT data container.
Parameter
---------
grid_pointer : ctp.POINTER(GMT_GRID)
Pointer to a GMT_GRID object.
Parameters
----------
kind : str
The kind of data container to create. Choose from "grid" or
"dataset".
Yields
------
vfile : str
Name of the virtual file.
"""
family = "GMT_IS_GRID"
geometry = "GMT_IS_SURFACE"
with self.open_virtual_file(family, geometry, "GMT_IN", grid_pointer) as vfile:
family, geometry = {
"grid": ("GMT_IS_GRID", "GMT_IS_SURFACE"),
"dataset": ("GMT_IS_DATASET", "GMT_IS_PLP"),
}[kind]
with self.open_virtual_file(family, geometry, "GMT_OUT", None) as vfile:
yield vfile

@contextmanager
def virtualfile_to_gmtgrid(self):
def virtualfile_from_gmtgrid(self, grid_pointer):
"""
Create a virtual file for writing a GMT_GRID object.
Create a virtual file for reading a GMT_GRID object.
Parameter
---------
grid_pointer : ctp.POINTER(GMT_GRID)
Pointer to a GMT_GRID object.
Yields
------
Expand All @@ -1679,7 +1687,7 @@ def virtualfile_to_gmtgrid(self):
"""
family = "GMT_IS_GRID"
geometry = "GMT_IS_SURFACE"
with self.open_virtual_file(family, geometry, "GMT_OUT", None) as vfile:
with self.open_virtual_file(family, geometry, "GMT_IN", grid_pointer) as vfile:
yield vfile

@contextmanager
Expand Down

0 comments on commit 849ed60

Please sign in to comment.