pygmt.clib.Session.virtualfile_from_vectors

Session.virtualfile_from_vectors(*vectors)[source]

Store 1-D arrays as columns of a table inside a virtual file.

Use the virtual file name to pass in the data in 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 the with 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, and pygmt.clib.Session.open_virtual_file.

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 (1-D arrays) – The vectors that will be included in the array. All must be of the same size.

Yields

fname (str) – The name of virtual file. Pass this as a file name argument to a GMT module.

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", f"{fin} ->{fout.name}")
...             print(fout.read().strip())
...
<vector memory>: N = 3 <1/3> <4/6> <7/9>