Skip to content

Support passing a list of file names as input #2723

@seisman

Description

@seisman

When working on #2722, I realized most PyGMT functions/methods don't allow a list of file names as input. For example,

import pygmt
fig = pygmt.Figure()
fig.plot(data=["@hotspots.txt", "@Table_5_11.txt"])
pygmt-session [WARNING]: Unable to parse 2 longitude strings

The main reason is that the data_kind function incorrectly returns a matrix type:

>>> from pygmt.helpers import data_kind
>>> data_kind(data=["@hotspots.txt", "@Table_5_11.txt"])
'matrix'

then we call the virtualfile_from_vectors to pass the data to the GMT API, which is expected to fail.

Then, the question is, if a list is passed to data, how do we know if it's a list of files or a valid record (e.g., data=[0, 1]).

To answer the question, we need to have a strict definition for "table files". As defined (based on my personal understanding) in #2722,

  • A table is a 2D array of data, with M rows and N columns. Each column
    represents a different variable (e.g., x, y and z) and each row
    represents a different record.

Under this definition, a table should always be a 2D array/list, even if it has only one row. Thus, data=[[0, 1]] is a valid table, and data=[0, 1] is not).

If we agree with the strict definition, then the solution is to check if data is 1-D or 2-D array. If 1-D, then it's a list of file names, otherwise, it's a 2-D table.

With this solution, it also means the issue report #1132 is no longer valid.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions