diff --git a/gmt/__init__.py b/gmt/__init__.py index 1374fd765df..d3169d25243 100644 --- a/gmt/__init__.py +++ b/gmt/__init__.py @@ -17,6 +17,7 @@ # Import modules to make the high-level GMT Python API from .session_management import begin as _begin, end as _end from .figure import Figure +from .modules import info # Get the version number through versioneer diff --git a/gmt/modules.py b/gmt/modules.py new file mode 100644 index 00000000000..448b510beac --- /dev/null +++ b/gmt/modules.py @@ -0,0 +1,30 @@ +""" +Non-plot GMT modules. +""" + +from .clib import LibGMT +from .utils import build_arg_string +from .decorators import fmt_docstring +from .utils import GMTTempFile + + +@fmt_docstring +def info(fname, **kwargs): + """ + Get information about data tables. + + {gmt_module_docs} + + Parameters + ---------- + fname : str + The file name of the input data table file. + """ + assert isinstance(fname, str), 'Only accepts file names.' + + with GMTTempFile() as tmpfile: + arg_str = ' '.join([fname, build_arg_string(kwargs), + "->" + tmpfile.name]) + with LibGMT() as lib: + lib.call_module('info', arg_str) + return tmpfile.read() diff --git a/gmt/tests/test_gmtinfo.py b/gmt/tests/test_gmtinfo.py new file mode 100644 index 00000000000..276cf2d3a93 --- /dev/null +++ b/gmt/tests/test_gmtinfo.py @@ -0,0 +1,15 @@ +""" +Tests for gmtinfo +""" +import os + +from .. import info + +TEST_DATA_DIR = os.path.join(os.path.dirname(__file__), 'data') + + +def test_gmtinfo(): + "Test gmtinfo" + data_fname = os.path.join(TEST_DATA_DIR, 'points.txt') + output = info(fname=data_fname, C=True) + assert output == '11.5309 61.7074 -2.9289 7.8648 0.1412 0.9338\n'