Skip to content
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

gmtstrainplot python verion error #38

Closed
xanthospap opened this issue Nov 28, 2018 · 2 comments · Fixed by #39
Closed

gmtstrainplot python verion error #38

xanthospap opened this issue Nov 28, 2018 · 2 comments · Fixed by #39
Labels
Milestone

Comments

@xanthospap
Copy link
Contributor

Describe the bug
Bug at program gmtstrainplot.sh
The bug is caused when bash calls python to compute/print computation results. Some of the calls
cause errors in Python3.x (e.g sclat=$(echo print ${south} + ${tmp_scrate} | python)). These lines
are ok for previous versions of Python.

To Reproduce
Steps to reproduce the behavior:

  1. run command './gmtstrainplot.sh -jpg -vhor station_info.dat -psta -l -o output_vel'
    using Python 3.6
  2. check for errors
"<stdin>", line 1
print 34 + 0.4

or

File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for -: 'builtin_function_or_method' and 'float'

Expected behavior
All of the lines just compute a bash variable (to be used later on)

Screenshots

Desktop (please complete the following information):

  • OS: [Windows]
  • Python: [3.6]
  • GMT: [e.g. 5.2.1] -- irrelevant
  • StrainTool: [v1.0-rc2.0]

Additional context
Bug reported by Varvara

@xanthospap xanthospap added the bug label Nov 28, 2018
@xanthospap
Copy link
Contributor Author

Tried to fix this via computing all quantities with bc, but that is probably not an option. Python does complicated manipulations (like print(round(${T},-1)+10)); this is not possible with bc (at least not in less than a few lines).

@xanthospap
Copy link
Contributor Author

xanthospap commented Nov 28, 2018

Trying a new approach:

  1. add a function in the script, to resolve system's python version (resolve_py_version())
  2. make a function alias to python; this is called pythonc. If the system Python version is 3.x.x, then
    this function just collapses to alias pythonc="python -c". Else, if the version is 2.x.x, then the alias is
    python -c "from __future__ import print_function;.

Hence, now

  1. When calling Python's print in the script, always use Python 3.x.x syntax
  2. Instead of writing
python -c "print int((${south} + ${north})/2)"

we write

pythonc "print(int((${south} + ${north})/2))"

remember that is python 3.x print is a function, hence it must have parenthesis, print 5 is invalid, print(5) is ok!
Also, never use the piped version, aka echo print ${south} + ${tmp_scrate} | python

@xanthospap xanthospap reopened this Nov 28, 2018
@demanasta demanasta added this to the v1.0 milestone Nov 29, 2018
demanasta pushed a commit that referenced this issue Nov 29, 2018
demanasta pushed a commit that referenced this issue Nov 29, 2018
@demanasta demanasta mentioned this issue Nov 30, 2018
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants