Skip to content

Commit 95cd123

Browse files
seismanleouieda
authored andcommitted
Wrapper for gmt info (#106)
Missing aliases and more extensive documentation and tests. Defines the new `gmt/modules.py` file.
1 parent b57273a commit 95cd123

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

gmt/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# Import modules to make the high-level GMT Python API
1818
from .session_management import begin as _begin, end as _end
1919
from .figure import Figure
20+
from .modules import info
2021

2122

2223
# Get the version number through versioneer

gmt/modules.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
Non-plot GMT modules.
3+
"""
4+
5+
from .clib import LibGMT
6+
from .utils import build_arg_string
7+
from .decorators import fmt_docstring
8+
from .utils import GMTTempFile
9+
10+
11+
@fmt_docstring
12+
def info(fname, **kwargs):
13+
"""
14+
Get information about data tables.
15+
16+
{gmt_module_docs}
17+
18+
Parameters
19+
----------
20+
fname : str
21+
The file name of the input data table file.
22+
"""
23+
assert isinstance(fname, str), 'Only accepts file names.'
24+
25+
with GMTTempFile() as tmpfile:
26+
arg_str = ' '.join([fname, build_arg_string(kwargs),
27+
"->" + tmpfile.name])
28+
with LibGMT() as lib:
29+
lib.call_module('info', arg_str)
30+
return tmpfile.read()

gmt/tests/test_gmtinfo.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
Tests for gmtinfo
3+
"""
4+
import os
5+
6+
from .. import info
7+
8+
TEST_DATA_DIR = os.path.join(os.path.dirname(__file__), 'data')
9+
10+
11+
def test_gmtinfo():
12+
"Test gmtinfo"
13+
data_fname = os.path.join(TEST_DATA_DIR, 'points.txt')
14+
output = info(fname=data_fname, C=True)
15+
assert output == '11.5309 61.7074 -2.9289 7.8648 0.1412 0.9338\n'

0 commit comments

Comments
 (0)