Skip to content

Return values of gmt.info #147

Description

@seisman

This issue is opened to further discuss the #106 (comment) about gmt.info.

Do you think we should print the output instead of returning it? There could be a flag to trigger a return instead of printing.

IMHO, returning the output makes more sense than printing it. It's easy for users to print it via print(gmt.info()) if they need.

Either way, if the returned string is just a list of numbers, it would be better to return an array/list of the number instead.

As far as I know, the outputs of gmt info can be divided into following types when different options are used:

Type 1

$ gmt info points.txt points.txt: N = 20	<11.5309/61.7074>	<-2.9289/7.8648>	<0.1412/0.9338>

I think this type is useless in most cases. We can leave it as it is.

Type 2

$ gmt info points.txt -C
11.5309	61.7074	-2.9289	7.8648	0.1412	0.9338

We can convert this type to a list/array.

Type 3

$ gmt info points.txt -I0.1 -R11.5/61.8/-3/7.9

-Rw/e/s/n is useless for Python. Should be convert to a list/array.

Type 4

$ gmt info points.txt -T0.1
-T11.5/61.8/0.1

Useless. Should be convert to a list/array.

Types 5

$ gmt info points.txt -Ib 11.5309	-2.9289
61.7074	-2.9289
61.7074	7.8648
11.5309	7.8648
11.5309	-2.9289

gmt info -Ib reports the bounding box polygon for the data files, which is usually used in further fig.plot(). So it may make more sense to return it as two arrays x and y. A much general way is to return it as a ndarray, so users can access the first column via output[:,0] and the ith column via output[:,i-1].

If -Af|s option is used, the output becomes more complicated, e.g.:

$ gmt info points.txt points-copy.txt -C -Af
11.5309	61.7074	-2.9289	7.8648	0.1412	0.9338
11.5309	61.7074	-2.9289	7.8648	0.1412	0.9338

In such cases, we can return the output as a ndarray.

Conclusion

What we can do with the gmt.info outputs:

  1. convert it to an array (type 2-4)
  2. convert it to a multi-dimensional ndarray (type 2-5 and some more complicated cases).
  3. leave the output as it is (type 1 and other cases not discussed in the issue).

Activity

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

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions