Skip to content

gmtselect issue (gmt6) #5368

Closed
Closed

Description

@mvanneste

All,
I have the following observation with gmtselect, using either an area (-R) or polygon (-F) on a file which has x y and a third column which can be mixed as a text string or number. The outcome is that sometimes the text strings are printed as NaN, and this seems to depend on the value in the first line.

The example underneath illustrates this issue. The only difference between the two tests is that I exchanged the first 2 lines, so the results should be identical. The result of test 1 gives me NaN instead of A and C, the result of test 2 is correct.

echo “Test 1”
echo “.5 .5 1” > temp
echo “.25 .25 A” >> temp
echo “1.7 .7 B” >> temp
echo “.7 .7 C” >> temp
gmtselect -R0/1/0/1 temp
Result:
0.5 0.5 1
0.25 0.25 NaN
0.7 0.7 NaN

echo “Test 2”
echo “.25 .25 A” > temp
echo “.5 .5 1” >> temp
echo “1.7 .7 B” >> temp
echo “.7 .7 C” >> temp
gmtselect -R0/1/0/1 temp
Result:
0.25 0.25 A
0.5 0.5 1
0.7 0.7 C

The bug here may be that the t in -i0-1,2t is being ignored.

  • Operating system: linux
  • GMT version: 6.0 and 6.2

(note: I am wondering if a similar behaviour may appear with grdtrack where one column of the input file may also have a mix)

Activity

  1. added
    bug
    on Jun 20, 2021
  2. welcome commented on Jun 20, 2021

    @welcome

    👋 Thanks for opening your first issue here! Please make sure you filled out the template with as much detail as possible. We appreciate that you took the time to contribute!

    Please make sure you read our Contributing Guide and abide by our Code of Conduct.

  3. PaulWessel commented on Jun 20, 2021

    @PaulWessel
    Contributor

    It should be gmt select temp -i0,1,t but anyway it does not work. I think we need something like that to work as it is not possible for some gmt modules like select, which is reading record by record, to detect that a later record than the first has in fact trailing text rather than the number field found at first. With -i0,1,t we would like it to use that knowledge rather than auto-figuring things out like now.

  4. joa-quim commented on Jun 20, 2021

    @joa-quim
    Member

    That's what I said in the forum post, though I thought the syntax should be -i0,1,2t

  5. PaulWessel commented on Jun 20, 2021

    @PaulWessel
    Contributor

    Actually, the way -i works it would not be a good place to tell a module that column 3 is text. This is a job for -f2s I think (s for string since t is already taken for time), which we currently don't have. If -f2s were implemented it would mean x and y are whatever they are for this module, but after the 2nd column everything should be considered trailing text.

  6. joa-quim commented on Jun 20, 2021

    @joa-quim
    Member

    OK, but then what's the purpose of -icolt?

  7. PaulWessel commented on Jun 20, 2021

    @PaulWessel
    Contributor
  8. PaulWessel commented on Jun 20, 2021

    @PaulWessel
    Contributor

    OK, while we are taking I have implemented -fcols:

    gmt select -R0/1/0/1 temp -f2s
    0.5	0.5	1
    0.25	0.25	A
    0.7	0.7	C
    
  9. joa-quim commented on Jun 20, 2021

    @joa-quim
    Member

    I did read but the meaning of t is not obvious. Specially when it says you must explicitly add the column t to retain the text.. Which column t?

  10. PaulWessel commented on Jun 21, 2021

    @PaulWessel
    Contributor

    "which column t" is nonsensical. t refers to the entire trailing text once it has been ingested into GMT. There are n numerical columns (n >= 0) plus optionally some trailing text. In a case like the one posted here, where the users third column cannot reliably be identified as trailing text based on the first column, we flag the third column as start of trailing text via -f2s and then all works consistently.

  11. added a commit that references this issue on Jun 21, 2021
    aef0e2d
  12. joa-quim commented on Jun 21, 2021

    @joa-quim
    Member

    Sorry, but still far from clear. If one need to use t to retain the text why the -in? It seems -in equals no t.

    Finally, -in will simply read the numerical input and skip any trailing text.

  13. PaulWessel commented on Jun 21, 2021

    @PaulWessel
    Contributor

    OK, if it is unclear to you I will re-read it and see if I can improve it, but

    1. Default action reads the whole record, including trailing text (if the module can use it - i.e., not in surface etc). You never specify t to include trailing text, but you can use -in to skip it entirely. Would not do you any good in the poster's case since col 3 was identified as data and you end up with those NaNs
    2. On output, again trailing text is the default for most/all modules that pass records through (ie.., not block* etc). If you do not want text on output you use -on, and if you want a mix of columns you use t, e.g., -o2,3,t
    3. If you have the above case and need to explicitly say trailing text starts with column 2 then you use -f2s.
  14. joa-quim commented on Jun 21, 2021

    @joa-quim
    Member

    I may being particularly dumb tonight but when would we use -it then?

  15. PaulWessel commented on Jun 21, 2021

    @PaulWessel
    Contributor

    I think you never use -it. E.g.

    echo 1 2 3 text | gmt convert -it
    gmtconvert [ERROR]: Selection -it (just trailing text, no numerical input) is not allowed.  Consider using -ot instead, if available.
    

    However, you do use it if you select columns and want to include the trailing text:

    echo 1 2 3 text | gmt convert -i2,1,t
    3	2	text
    

    versus

    echo 1 2 3 text | gmt convert -i2,1  
    3	2
    
  16. added a commit that references this issue on Jun 21, 2021
    14af7af
  17. joa-quim commented on Jun 21, 2021

    @joa-quim
    Member

    Ah, finally got it. So instead of

    used you must explicitly add the column t to retain the text

    say something like:

    used you must explicitly add the t modifier to always retain the text on output

  18. PaulWessel commented on Jun 21, 2021

    @PaulWessel
    Contributor

    OK, I can fix that.

  19. mvanneste commented on Jun 21, 2021

    @mvanneste
    Author

    Thanks for the swift response and actions! Impressive (as usual).

  20. mvanneste commented on Jun 21, 2021

    @mvanneste
    Author

    (Note: the same issue occurs with grdtrack)

  21. PaulWessel commented on Jun 21, 2021

    @PaulWessel
    Contributor

    grdtrack uses the same -i, -f, -o as any other modules. This is after the update? What is the symptoms?

  22. mvanneste commented on Jun 21, 2021

    @mvanneste
    Author
  23. PaulWessel commented on Jun 21, 2021

    @PaulWessel
    Contributor

    Works fine for me with master and the updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions