34
34
)
35
35
from pygmt .helpers import (
36
36
data_kind ,
37
- fmt_docstring ,
38
37
tempfile_from_geojson ,
39
38
tempfile_from_image ,
40
39
)
@@ -146,7 +145,7 @@ class Session:
146
145
... with GMTTempFile() as fout:
147
146
... # Call the grdinfo module with the virtual file as input
148
147
... # and the temp file as output.
149
- ... ses.call_module("grdinfo", f"{ fin} -C ->{fout.name}")
148
+ ... ses.call_module("grdinfo", [ fin, "-C", f" ->{fout.name}"] )
150
149
... # Read the contents of the temp file before it's deleted.
151
150
... print(fout.read().strip())
152
151
-55 -47 -24 -10 190 981 1 1 8 14 1 1
@@ -543,18 +542,20 @@ def get_common(self, option):
543
542
Examples
544
543
--------
545
544
>>> with Session() as lib:
546
- ... lib.call_module("basemap", "-R0/10/10/15 -JX5i/2.5i -Baf -Ve")
545
+ ... lib.call_module(
546
+ ... "basemap", ["-R0/10/10/15", "-JX5i/2.5i", "-Baf", "-Ve"]
547
+ ... )
547
548
... region = lib.get_common("R")
548
549
... projection = lib.get_common("J")
549
550
... timestamp = lib.get_common("U")
550
551
... verbose = lib.get_common("V")
551
- ... lib.call_module("plot", "-T -Xw+1i -Yh-1i")
552
+ ... lib.call_module("plot", [ "-T", " -Xw+1i", " -Yh-1i"] )
552
553
... xshift = lib.get_common("X") # xshift/yshift are in inches
553
554
... yshift = lib.get_common("Y")
554
555
>>> print(region, projection, timestamp, verbose, xshift, yshift)
555
556
[ 0. 10. 10. 15.] True False 3 6.0 1.5
556
557
>>> with Session() as lib:
557
- ... lib.call_module("basemap", "-R0/10/10/15 -JX5i/2.5i -Baf")
558
+ ... lib.call_module("basemap", [ "-R0/10/10/15", " -JX5i/2.5i", " -Baf"] )
558
559
... lib.get_common("A")
559
560
Traceback (most recent call last):
560
561
...
@@ -1180,8 +1181,7 @@ def open_virtualfile(self, family, geometry, direction, data):
1180
1181
... with lib.open_virtualfile(*vfargs) as vfile:
1181
1182
... # Send the output to a temp file so that we can read it
1182
1183
... with GMTTempFile() as ofile:
1183
- ... args = f"{vfile} ->{ofile.name}"
1184
- ... lib.call_module("info", args)
1184
+ ... lib.call_module("info", [vfile, f"->{ofile.name}"])
1185
1185
... print(ofile.read().strip())
1186
1186
<vector memory>: N = 5 <0/4> <5/9>
1187
1187
"""
@@ -1288,7 +1288,7 @@ def virtualfile_from_vectors(self, *vectors):
1288
1288
... with ses.virtualfile_from_vectors(x, y, z) as fin:
1289
1289
... # Send the output to a file so that we can read it
1290
1290
... with GMTTempFile() as fout:
1291
- ... ses.call_module("info", f"{ fin} ->{fout.name}")
1291
+ ... ses.call_module("info", [ fin, f" ->{fout.name}"] )
1292
1292
... print(fout.read().strip())
1293
1293
<vector memory>: N = 3 <1/3> <4/6> <7/9>
1294
1294
"""
@@ -1398,7 +1398,7 @@ def virtualfile_from_matrix(self, matrix):
1398
1398
... with ses.virtualfile_from_matrix(data) as fin:
1399
1399
... # Send the output to a file so that we can read it
1400
1400
... with GMTTempFile() as fout:
1401
- ... ses.call_module("info", f"{ fin} ->{fout.name}")
1401
+ ... ses.call_module("info", [ fin, f" ->{fout.name}"] )
1402
1402
... print(fout.read().strip())
1403
1403
<matrix memory>: N = 4 <0/9> <1/10> <2/11>
1404
1404
"""
@@ -1478,8 +1478,9 @@ def virtualfile_from_grid(self, grid):
1478
1478
... with ses.virtualfile_from_grid(data) as fin:
1479
1479
... # Send the output to a file so that we can read it
1480
1480
... with GMTTempFile() as fout:
1481
- ... args = f"{fin} -L0 -Cn ->{fout.name}"
1482
- ... ses.call_module("grdinfo", args)
1481
+ ... ses.call_module(
1482
+ ... "grdinfo", [fin, "-L0", "-Cn", f"->{fout.name}"]
1483
+ ... )
1483
1484
... print(fout.read().strip())
1484
1485
-55 -47 -24 -10 190 981 1 1 8 14 1 1
1485
1486
>>> # The output is: w e s n z0 z1 dx dy n_columns n_rows reg gtype
@@ -1510,7 +1511,6 @@ def virtualfile_from_grid(self, grid):
1510
1511
with self .open_virtualfile (* args ) as vfile :
1511
1512
yield vfile
1512
1513
1513
- @fmt_docstring
1514
1514
def virtualfile_in ( # noqa: PLR0912
1515
1515
self ,
1516
1516
check_kind = None ,
@@ -1571,7 +1571,7 @@ def virtualfile_in( # noqa: PLR0912
1571
1571
... with ses.virtualfile_in(check_kind="vector", data=data) as fin:
1572
1572
... # Send the output to a file so that we can read it
1573
1573
... with GMTTempFile() as fout:
1574
- ... ses.call_module("info", fin + " ->" + fout.name)
1574
+ ... ses.call_module("info", [ fin, f"->{ fout.name}"] )
1575
1575
... print(fout.read().strip())
1576
1576
<vector memory>: N = 3 <7/9> <4/6> <1/3>
1577
1577
"""
@@ -1718,15 +1718,15 @@ def virtualfile_out(
1718
1718
... # Create a virtual file for storing the output table.
1719
1719
... with Session() as lib:
1720
1720
... with lib.virtualfile_out(kind="dataset") as vouttbl:
1721
- ... lib.call_module("read", f"{ tmpfile.name} { vouttbl} -Td")
1721
+ ... lib.call_module("read", [ tmpfile.name, vouttbl, " -Td"] )
1722
1722
... ds = lib.read_virtualfile(vouttbl, kind="dataset")
1723
1723
... assert isinstance(ds.contents, _GMT_DATASET)
1724
1724
...
1725
1725
... # Write data to an actual file without creating a virtual file.
1726
1726
... with Session() as lib:
1727
1727
... with lib.virtualfile_out(fname=tmpfile.name) as vouttbl:
1728
1728
... assert vouttbl == tmpfile.name
1729
- ... lib.call_module("read", f"{ tmpfile.name} { vouttbl} -Td")
1729
+ ... lib.call_module("read", [ tmpfile.name, vouttbl, " -Td"] )
1730
1730
... line = Path(vouttbl).read_text()
1731
1731
... assert line == "1\t2\t3\tTEXT\n"
1732
1732
"""
@@ -1798,7 +1798,7 @@ def read_virtualfile(
1798
1798
... with Path(tmpfile.name).open(mode="w") as fp:
1799
1799
... print("1.0 2.0 3.0 TEXT", file=fp)
1800
1800
... with lib.virtualfile_out(kind="dataset") as vouttbl:
1801
- ... lib.call_module("read", f"{ tmpfile.name} { vouttbl} -Td")
1801
+ ... lib.call_module("read", [ tmpfile.name, vouttbl, " -Td"] )
1802
1802
... # Read the virtual file as a void pointer
1803
1803
... void_pointer = lib.read_virtualfile(vouttbl)
1804
1804
... assert isinstance(void_pointer, int) # void pointer is an int
@@ -1809,7 +1809,7 @@ def read_virtualfile(
1809
1809
>>> # Read grid from a virtual file
1810
1810
>>> with Session() as lib:
1811
1811
... with lib.virtualfile_out(kind="grid") as voutgrd:
1812
- ... lib.call_module("read", f "@earth_relief_01d_g { voutgrd} -Tg")
1812
+ ... lib.call_module("read", [ "@earth_relief_01d_g", voutgrd, " -Tg"] )
1813
1813
... # Read the virtual file as a void pointer
1814
1814
... void_pointer = lib.read_virtualfile(voutgrd)
1815
1815
... assert isinstance(void_pointer, int) # void pointer is an int
@@ -1905,7 +1905,7 @@ def virtualfile_to_dataset(
1905
1905
... with lib.virtualfile_out(
1906
1906
... kind="dataset", fname=outtmp.name
1907
1907
... ) as vouttbl:
1908
- ... lib.call_module("read", f"{ tmpfile.name} { vouttbl} -Td")
1908
+ ... lib.call_module("read", [ tmpfile.name, vouttbl, " -Td"] )
1909
1909
... result = lib.virtualfile_to_dataset(
1910
1910
... vfname=vouttbl, output_type="file"
1911
1911
... )
@@ -1915,7 +1915,7 @@ def virtualfile_to_dataset(
1915
1915
... # strings output
1916
1916
... with Session() as lib:
1917
1917
... with lib.virtualfile_out(kind="dataset") as vouttbl:
1918
- ... lib.call_module("read", f"{ tmpfile.name} { vouttbl} -Td")
1918
+ ... lib.call_module("read", [ tmpfile.name, vouttbl, " -Td"] )
1919
1919
... outstr = lib.virtualfile_to_dataset(
1920
1920
... vfname=vouttbl, output_type="strings"
1921
1921
... )
@@ -1925,7 +1925,7 @@ def virtualfile_to_dataset(
1925
1925
... # numpy output
1926
1926
... with Session() as lib:
1927
1927
... with lib.virtualfile_out(kind="dataset") as vouttbl:
1928
- ... lib.call_module("read", f"{ tmpfile.name} { vouttbl} -Td")
1928
+ ... lib.call_module("read", [ tmpfile.name, vouttbl, " -Td"] )
1929
1929
... outnp = lib.virtualfile_to_dataset(
1930
1930
... vfname=vouttbl, output_type="numpy"
1931
1931
... )
@@ -1934,7 +1934,7 @@ def virtualfile_to_dataset(
1934
1934
... # pandas output
1935
1935
... with Session() as lib:
1936
1936
... with lib.virtualfile_out(kind="dataset") as vouttbl:
1937
- ... lib.call_module("read", f"{ tmpfile.name} { vouttbl} -Td")
1937
+ ... lib.call_module("read", [ tmpfile.name, vouttbl, " -Td"] )
1938
1938
... outpd = lib.virtualfile_to_dataset(
1939
1939
... vfname=vouttbl, output_type="pandas"
1940
1940
... )
@@ -1943,7 +1943,7 @@ def virtualfile_to_dataset(
1943
1943
... # pandas output with specified column names
1944
1944
... with Session() as lib:
1945
1945
... with lib.virtualfile_out(kind="dataset") as vouttbl:
1946
- ... lib.call_module("read", f"{ tmpfile.name} { vouttbl} -Td")
1946
+ ... lib.call_module("read", [ tmpfile.name, vouttbl, " -Td"] )
1947
1947
... outpd2 = lib.virtualfile_to_dataset(
1948
1948
... vfname=vouttbl,
1949
1949
... output_type="pandas",
@@ -2026,7 +2026,7 @@ def virtualfile_to_raster(
2026
2026
... with GMTTempFile(suffix=".nc") as tmpfile:
2027
2027
... outgrid = tmpfile.name
2028
2028
... with lib.virtualfile_out(kind="grid", fname=outgrid) as voutgrd:
2029
- ... lib.call_module("read", f "@earth_relief_01d_g { voutgrd} -Tg")
2029
+ ... lib.call_module("read", [ "@earth_relief_01d_g", voutgrd, " -Tg"] )
2030
2030
... result = lib.virtualfile_to_raster(
2031
2031
... vfname=voutgrd, outgrid=outgrid
2032
2032
... )
@@ -2036,7 +2036,7 @@ def virtualfile_to_raster(
2036
2036
... # xarray.DataArray output
2037
2037
... outgrid = None
2038
2038
... with lib.virtualfile_out(kind="grid", fname=outgrid) as voutgrd:
2039
- ... lib.call_module("read", f "@earth_relief_01d_g { voutgrd} -Tg")
2039
+ ... lib.call_module("read", [ "@earth_relief_01d_g", voutgrd, " -Tg"] )
2040
2040
... result = lib.virtualfile_to_raster(vfname=voutgrd, outgrid=outgrid)
2041
2041
... assert isinstance(result, xr.DataArray)
2042
2042
"""
0 commit comments