GenericMappingTools / gmt-examples

Tutorials and guides for the Generic Mapping Tools
https://www.generic-mapping-tools.org/gmt-examples/
Creative Commons Attribution 4.0 International
4 stars 0 forks source link

Use data created on the fly for the tutorials in rst file #20

Closed Esteban82 closed 3 months ago

Esteban82 commented 4 months ago

I am making a tutorial about lines. I want to use some data created on the fly (as in the pygmt).

How can I do it? @seisman do you know?

I try the following but it fails:

     .. gmtplot::

      gmt begin line2 png
         gmt plot -Ra -JX10c -Baf -W <<- EOF
         1,8
         1,8
         EOF
      gmt end show

I think this are the messages related to those lines:

Exception occurred:
  File "/home/federico/.local/lib/python3.10/site-packages/sphinx_gmt/gmtplot.py", line 199, in eval_bash
    raise RuntimeError(
RuntimeError: GMT bash failed:
STDOUT: {proc.stdout.decode("utf-8")}
STDERR: {proc.stderr.decode("utf-8")}
The full traceback has been saved in /tmp/sphinx-err-8jhsedt1.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!
make: *** [Makefile:20: html] Error 2
seisman commented 4 months ago

Maybe the indentation is incorrect? Try this:

     .. gmtplot::

        gmt begin line2 png
            gmt plot -Ra -JX10c -Baf -W <<- EOF
            1,8
            1,8
            EOF
        gmt end show
Esteban82 commented 4 months ago

No, it didn't work. The indentaion is fine. I try with data from the cache and it worked.

     .. gmtplot::

        gmt begin line2 png
            gmt plot -Ra -JX10c -Baf -W @tut_data.txt 
        gmt end show  
seisman commented 4 months ago

It should be either

     .. gmtplot::

        gmt begin line2 png
            gmt plot -R0/10/0/10 -JX10c -Baf -W <<- 'EOF'
            1,8
            1,8
            EOF
        gmt end show

or

     .. gmtplot::

        gmt begin line2 png
            gmt plot -R0/10/0/10 -JX10c -Baf -W <<- 'EOF'
            1,8
            1,8
        EOF
        gmt end show
Esteban82 commented 4 months ago

It didn't work on my pc.

I got this:

image

joa-quim commented 4 months ago

Remember that that those EOF constructs do not work on pure Windows, which for a beginner's tutorial is not the best thing. I would prefer to have examples that are OS agnostic.

Esteban82 commented 4 months ago

Ok, I agree.

So what method should we use? tell the users to create a txt file with the data?

joa-quim commented 4 months ago

It's not pretty but we can use a double echo x1 y1 > file; echo x2 y2 >> file. But ideally should be some sort of gmtmath command.

seisman commented 4 months ago

Remember that that those EOF constructs do not work on pure Windows, which for a beginner's tutorial is not the best thing. I would prefer to have examples that are OS agnostic.

It's possible to use Sphinx-design's tab directive to have scripts for both Unix and Windows.

But ideally should be some sort of gmtmath command.

gmtmath is likely one of the most complicated modules that users rarely use, so it's not a good idea to use it in tutorials.

Esteban82 commented 3 months ago

It's not pretty but we can use a double echo x1 y1 > file; echo x2 y2 >> file.

This worked. I would prefer a method with cat