Skip to content

Support passing a list of file names as input #2723

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
seisman opened this issue Oct 8, 2023 · 2 comments · Fixed by #3214
Closed

Support passing a list of file names as input #2723

seisman opened this issue Oct 8, 2023 · 2 comments · Fixed by #3214
Labels
documentation Improvements or additions to documentation
Milestone

Comments

@seisman
Copy link
Member

seisman commented Oct 8, 2023

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.

@seisman seisman added the feature request New feature wanted label Oct 8, 2023
@weiji14 weiji14 changed the title Support passing a list of file names as input Support passing a list of file names as input via positional arguments Oct 15, 2023
@weiji14 weiji14 changed the title Support passing a list of file names as input via positional arguments Support passing a list of file names as input Oct 15, 2023
@seisman
Copy link
Member Author

seisman commented Apr 9, 2024

I think the feature will be implemented in PR #3132. We need to:

  1. Make sure everything work as expected
  2. Add some tests
  3. In the tutorial https://www.pygmt.org/dev/get_started/04_table_inputs.html, mention that a list of files are allowed.

@seisman
Copy link
Member Author

seisman commented Apr 19, 2024

  • Make sure everything work as expected
  • Add some tests

We already have some tests that pass a list of files to pygmt.which and Figure.text, so it should be find to say that passing a list of file names is supported.

3. In the tutorial https://www.pygmt.org/dev/get_started/04_table_inputs.html, mention that a list of files are allowed.

So we only need to improve the documentation.

@seisman seisman added the help wanted Helping hands are appreciated label Apr 19, 2024
@seisman seisman added this to the 0.12.0 milestone Apr 19, 2024
@seisman seisman added documentation Improvements or additions to documentation and removed feature request New feature wanted labels Apr 23, 2024
@seisman seisman removed this from the 0.12.0 milestone Apr 29, 2024
@seisman seisman added this to the 0.12.0 milestone Apr 30, 2024
@seisman seisman removed the help wanted Helping hands are appreciated label Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
1 participant