pygmt.clib.Session.virtualfile_from_vectors
- Session.virtualfile_from_vectors(vectors, *args)[source]
Store a sequence of 1-D vectors as columns of a dataset inside a virtual file.
Use the virtual file name to pass the dataset with your vectors to a GMT module.
Context manager (use in a
with
block). Yields the virtual file name that you can pass as an argument to a GMT module call. Closes the virtual file upon exit of thewith
block.Use this instead of creating the data container and virtual file by hand with
pygmt.clib.Session.create_data
,pygmt.clib.Session.put_vector
, andpygmt.clib.Session.open_virtualfile
.If the arrays are C contiguous blocks of memory, they will be passed without copying to GMT. If they are not (e.g., they are columns of a 2-D array), they will need to be copied to a contiguous block.
- Parameters:
vectors (
Sequence
) – A sequence of vectors that will be stored in the dataset. All must be of the same size.- Yields:
fname – The name of virtual file. Pass this as a file name argument to a GMT module.
- Return type:
Examples
>>> from pygmt.helpers import GMTTempFile >>> import numpy as np >>> import pandas as pd >>> x = [1, 2, 3] >>> y = np.array([4, 5, 6]) >>> z = pd.Series([7, 8, 9]) >>> with Session() as ses: ... with ses.virtualfile_from_vectors((x, y, z)) as fin: ... # Send the output to a file so that we can read it ... with GMTTempFile() as fout: ... ses.call_module("info", [fin, f"->{fout.name}"]) ... print(fout.read().strip()) <vector memory>: N = 3 <1/3> <4/6> <7/9>