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

Grid2GMT: upgrade supported GMT version and change to bash script #30

Closed
wants to merge 8 commits into from

Conversation

sean0921
Copy link
Contributor

@sean0921 sean0921 commented Aug 23, 2022

Although this program has been almost replaced by SeismicityViewer for visualizing NLLoc locations, but when we want to customize to visualization of results generated by this program, Grid2GMT are still valuable for reference. So I still want to make PR for this program.

This PR mainly make these changes( #15 ):

  • Let generated GMT script compatible with >= 5, make more people access this tool without install GMT 4.x manually
  • Change script type from csh to bash and use more POSIX and bash feature (e.g. set -x) for easier tracing and debugging GMT scripts.

@alomax
Copy link
Collaborator

alomax commented Aug 23, 2022

Hi @sean0921
This is fabulous - needed for a long time! I will try and find time soon to verify that the GMT 4 version works as before and that GMT 5 output is the same or similar.
Can you tell me what tests you have made? Have you verified for GMT 4 and 5?

Also feel free to add your credit and contact information in the comments at the top of the file, if you wish, I hope so!

Thanks,
Anthony

@sean0921
Copy link
Contributor Author

sean0921 commented Aug 24, 2022

Compilation

GMT4

mkdir build
CFLAGS='-DGMT_VER_4' cmake -Bbuild .
make -C build
#copy binary under bin/ to your path
rm -rvf build/

GMT5 or 6

mkdir build
cmake -Bbuild .
make -C build
#copy binary under bin/ to your path
rm -rvf build/

Test the App

I have tested it with my own data before, and I will post the result pictures tested with /nlloc_sample_test in this repository later.

@alomax
Copy link
Collaborator

alomax commented Aug 25, 2022

Hi

For an existing NLL model grid, I tried running the upgraded Grid2GMT with
#define GMT_VER_4
using GMT4. It fails, I get:

(base) gmt_test> setGMT4
(base) gmt_test> gmt --version
GMT Version 4.5.7

(base) gmt_test> Grid2GMT Parkfield_2004B_Oppenheimer_1993_SW-NE.in Oppenheimer1993_SW.P.mod gmt_out/ V G 1 0 1 5001

Grid2GMT Arguments: <Grid2GMT> <Parkfield_2004B_Oppenheimer_1993_SW-NE.in> <Oppenheimer1993_SW.P.mod> <gmt_out/> <V> <G> <1> <0> <1> <5001> 
args: <G>
Grid2GMT (NonLinLoc v7.00.14 31May2022) 

Processing files Oppenheimer1993_SW.P.mod.*
Output files gmt_out/Oppenheimer1993_SW.P.mod.VG.*
DEBUG: Grid3dFile: Oppenheimer1993_SW.P.mod, type:SLOW_LEN
INFO: cannot open hypocenter file: Oppenheimer1993_SW.P.mod.hyp
Generating Y section view...
501 rows and 5001 columns written
Longitude Section: -120.503557
Grid value min = 1.250000e-02,  value max = 4.444445e-02
INFO: cannot open station list file: Oppenheimer1993_SW.P.mod.stations
RVAL: RECT/X: 0.000000/500.000000 RECTY:-5.000000/45.000000
GetContourInterval htick_int R: GetContourInterval: vmin 0.00e+00 vmax 5.00e+02  contour_int 1.00e+02  nstep 6 
GetContourInterval vtick_int R: GetContourInterval: vmin -5.00e+00 vmax 4.50e+01  contour_int 1.00e+01  nstep 6 
GetContourInterval contour_int iFirstPlot: GetContourInterval: vmin 1.25e-02 vmax 4.44e-02  contour_int 2.00e-03  nstep 16 
Signature:    Grid2GMT:v7.00.14 25Aug2022 17h30m27

Running GMT script gmt_out/Oppenheimer1993_SW.P.mod.VG.gmt ...
+ gmtset PAGE_ORIENTATION portrait X_ORIGIN 0.5 Y_ORIGIN 0.5
+ gmtset ANNOT_FONT_SIZE_PRIMARY 14 ANNOT_FONT_SIZE_SECONDARY 14 HEADER_FONT_SIZE 14 LABEL_FONT_SIZE 14
+ gmtset ANNOT_FONT_PRIMARY 4 ANNOT_FONT_SECONDARY 4 HEADER_FONT 4 LABEL_FONT 4
+ gmtset LABEL_OFFSET 0.1c ANNOT_OFFSET_PRIMARY 0.1c ANNOT_OFFSET_SECONDARY 0.1c
+ gmtset VERBOSE TRUE
+ POSTSCRIPT_NAME=gmt_out/Oppenheimer1993_SW.P.mod.VG
+ rm -f gmt_out/Oppenheimer1993_SW.P.mod.VG.ps
+ unset PLOT_LAT_LONG
+ psbasemap -R0.5/1.0/0.5/1.0 -Bf10N -JX20.000000/28.700000 -K
psbasemap: Constructing basemap
+ RVAL=-R0.000000/500.000000/-5.000000/45.000000/-9999/9999
+ BVAL='-B100.000000:Y(km):/10.000000:Z(km)::.gmt_out/Oppenheimer1993_SW.P.mod.VG__(1_0_->_1_5001):WESN'
+ JVAL='-Jx0.032500/-0.032500 -Jz0.032500'
+ psbasemap -Jx0.032500/-0.032500 -Jz0.032500 -R0.000000/500.000000/-5.000000/45.000000/-9999/9999 '-B100.000000:Y(km):/10.000000:Z(km)::.gmt_out/Oppenheimer1993_SW.P.mod.VG__(1_0_->_1_5001):WESN' -X1.750000 -Y3.750000 -K -O
psbasemap: Constructing basemap
+ xyz2grd gmt_out/Oppenheimer1993_SW.P.mod.VG.X.grd -Ggmt_out/Oppenheimer1993_SW.P.mod.VG.X.grdgmt -I0.100000/0.100000 -R0.000000/500.000000/-5.000000/45.000000/-9999/9999 -Dkm/km/=/0.0/0.0/gmt_out/Oppenheimer1993_SW.P.mod.VG/remark -V -Z -b
xyz2grd: GMT Warning.  -Z overrides -bi
xyz2grd: nx = 5001  ny = 501
xyz2grd: Working on file gmt_out/Oppenheimer1993_SW.P.mod.VG.X.grd
xyz2grd: Found 177811 records, but 2505501 was expected (aborting)!

I then tried with
//#define GMT_VER_4
using GMT6. It also fails, I get:

(base) gmt_test> setGMT6
(base) gmt_test> gmt --version
6.2.0
(base) gmt_test> which gmt
/Applications/GMT-6.2.0.app/Contents/Resources/bin/gmt

(base) gmt_test> Grid2GMT Parkfield_2004B_Oppenheimer_1993_SW-NE.in Oppenheimer1993_SW.P.mod gmt_out/ V G 1 0 1 5001

Grid2GMT Arguments: <Grid2GMT> <Parkfield_2004B_Oppenheimer_1993_SW-NE.in> <Oppenheimer1993_SW.P.mod> <gmt_out/> <V> <G> <1> <0> <1> <5001> 
args: <G>
Grid2GMT (NonLinLoc v7.00.14 31May2022) 

Processing files Oppenheimer1993_SW.P.mod.*
Output files gmt_out/Oppenheimer1993_SW.P.mod.VG.*
DEBUG: Grid3dFile: Oppenheimer1993_SW.P.mod, type:SLOW_LEN
INFO: cannot open hypocenter file: Oppenheimer1993_SW.P.mod.hyp
Generating Y section view...
501 rows and 5001 columns written
Longitude Section: -120.503557
Grid value min = 1.250000e-02,  value max = 4.444445e-02
INFO: cannot open station list file: Oppenheimer1993_SW.P.mod.stations
RVAL: RECT/X: 0.000000/500.000000 RECTY:-5.000000/45.000000
GetContourInterval htick_int R: GetContourInterval: vmin 0.00e+00 vmax 5.00e+02  contour_int 1.00e+02  nstep 6 
GetContourInterval vtick_int R: GetContourInterval: vmin -5.00e+00 vmax 4.50e+01  contour_int 1.00e+01  nstep 6 
GetContourInterval contour_int iFirstPlot: GetContourInterval: vmin 1.25e-02 vmax 4.44e-02  contour_int 2.00e-03  nstep 16 
Signature:    Grid2GMT:v7.00.14 25Aug2022 17h35m10

Running GMT script gmt_out/Oppenheimer1993_SW.P.mod.VG.gmt ...
+ gmt gmtset FONT_ANNOT_PRIMARY 14 FONT_ANNOT_SECONDARY 14 FONT_TITLE 14
+ gmt gmtset PS_PAGE_ORIENTATION portrait MAP_ORIGIN_X 0.5 MAP_ORIGIN_Y 0.5
+ gmt gmtset FONT_ANNOT_PRIMARY 8 FONT_ANNOT_SECONDARY 6 FONT_HEADING 12 FONT_LABEL 10
+ gmt gmtset MAP_LABEL_OFFSET 0.1c MAP_ANNOT_OFFSET_PRIMARY 0.1c MAP_ANNOT_OFFSET_SECONDARY 0.1c
+ gmt gmtset GMT_VERBOSE i
+ POSTSCRIPT_NAME=gmt_out/Oppenheimer1993_SW.P.mod.VG
+ rm -f gmt_out/Oppenheimer1993_SW.P.mod.VG.ps
+ unset PLOT_LAT_LONG
+ gmt psbasemap -R0.5/1.0/0.5/1.0 -Bf10N -JX20.000000/28.700000 -K
psbasemap [INFORMATION]: Constructing the basemap
psbasemap [INFORMATION]: Linear projection implies y-axis distance exaggeration relative to the x-axis by a factor of 1.435
psbasemap [INFORMATION]: Map scale is 2.5e-05 km per cm or 1:2.5.
+ RVAL=-R0.000000/500.000000/-5.000000/45.000000/-9999/9999
+ BVAL='-B100.000000:Y(km):/10.000000:Z(km)::.gmt_out/Oppenheimer1993_SW.P.mod.VG__(1_0_->_1_5001):WESN'
+ JVAL='-Jx0.032500/-0.032500 -Jz0.032500'
+ gmt psbasemap -Jx0.032500/-0.032500 -Jz0.032500 -R0.000000/500.000000/-5.000000/45.000000/-9999/9999 '-B100.000000:Y(km):/10.000000:Z(km)::.gmt_out/Oppenheimer1993_SW.P.mod.VG__(1_0_->_1_5001):WESN' -X1.750000 -Y3.750000 -K -O
psbasemap [INFORMATION]: Constructing the basemap
psbasemap [INFORMATION]: Linear projection implies x-axis distance exaggeration relative to the y-axis by a factor of -1
psbasemap [INFORMATION]: Map scale is 0.0307692 km per cm or 1:3076.92.
+ gmt xyz2grd gmt_out/Oppenheimer1993_SW.P.mod.VG.X.grd -Ggmt_out/Oppenheimer1993_SW.P.mod.VG.X.grdgmt -I0.100000/0.100000 -R0.000000/500.000000/-5.000000/45.000000/-9999/9999 -Dkm/km/=/0.0/0.0/gmt_out/Oppenheimer1993_SW.P.mod.VG/remark -V -Z -b
xyz2grd [INFORMATION]: -R with six parameters but no -Jz|Z given - ignore zmin/zmax
xyz2grd [ERROR]: -Z overrides -bi
xyz2grd [INFORMATION]: Processing input table data
xyz2grd [INFORMATION]: Cartesian input grid
xyz2grd [INFORMATION]: Cartesian input grid
xyz2grd [INFORMATION]: n_columns = 5001  n_rows = 501  nm = 2505501  size = 2505501
xyz2grd [INFORMATION]: Reading Data Table from file gmt_out/Oppenheimer1993_SW.P.mod.VG.X.grd
xyz2grd [ERROR]: Found 177811 records, but 2505501 was expected (aborting)!
xyz2grd [ERROR]: (You are probably misterpreting xyz2grd with an interpolator; see 'surface' man page)

This runs fine with the old Grid2GMT using GMT4...

Here are the required files to run this test: https://www.dropbox.com/sh/clslnyynw2chtg9/AABYIKJlTwWNJhrdiHl1EAxaa?dl=0

Any thoughts?

Thanks
Anthony

@sean0921
Copy link
Contributor Author

Thanks for your feedback and helpful information! I'm trying to reproduce this problem, if there is any idea and related fix about this, I will post here.

Thanks
Sean

@sean0921
Copy link
Contributor Author

After comparing two version of generated scripts. I found that I've ignored GMT_VER_3_3_4 1 is always defined in original version.

I will push related commits in this PR after this problem is fixed.

@alomax
Copy link
Collaborator

alomax commented Sep 20, 2022

The introduction of the GMT_VER_3_3_4 define was an attempt a long, long time ago to chase GMT version changes and lack of backwards compatibility. You can consider it as THIS_SHOULD_ALWAYS_BE DEFINED to allow GMT 4 plotting.

- cleanup unused code block due to GMT_VER_3_3_4 is always defined
- remove GMT_VER_3_3_4 defined macro
- add GMT_VER_5 macro for enable 5 and later verion capability
enable GMT_VER_5 can generate gmt >=5 compatible script
If we use default build procedure, and not define anything
it will still generate script that uses gmt 4.x
@sean0921
Copy link
Contributor Author

sean0921 commented Sep 20, 2022

Compilation

GMT 4

Use original build procedure

GMT 5 or 6

edit CMakeLists.txt to uncomment following line:

add_compile_options(-D GMT_VER_5)

then:

cd src
rm CMakeCache.txt
cmake .
make

Test the App

I have tested it with:

  1. This dataset: https://www.dropbox.com/sh/clslnyynw2chtg9/AABYIKJlTwWNJhrdiHl1EAxaa?dl=0 ([1])
  2. /nlloc_sample_test in this repository. ([2])

Result

Dataset [1]

  • origin code: 圖片
  • code after pr (gmt4): 圖片
  • code after pr (gmt5): 圖片

Dataset [2]

Google Drive link: https://drive.google.com/drive/folders/1OvMsQIQfOKf_LEG1KQDwMjJkq_bNIitQ?usp=sharing

@sean0921
Copy link
Contributor Author

I have fixed this problem and simply wrote up the way to test new code in PR and README.md, and add contact info at the top of the file. Please help to check if there's further information I need to complete. Thanks for your patience.

Regards,
Sean

@alomax
Copy link
Collaborator

alomax commented Sep 21, 2022

Hi Sean,
This sounds great, thanks! I am away through end of next week, so I will try and take a look in 2 weeks or so...
Maybe anyone else interested can also take a look.
Anthony

@alomax alomax mentioned this pull request Oct 27, 2022
@alomax
Copy link
Collaborator

alomax commented Feb 2, 2023

Hi Sean

Sorry for the big delay. I am finally using Grid2GMT and have time to experiment with your modifications.

Running with GMT6 seems to work fine, but gives one error message:

> which gmt
/Applications/GMT-6.2.0.app/Contents/Resources/bin/gmt
...
xyz2grd [INFORMATION]: Writing grid to file gmt/hybrid_3.P.IF1C.time.VG.X.grdgmt
+ SCALE_FLAG=
+ '[-f' Grid2GMT.cpt ']'
gmt/hybrid_3.P.IF1C.time.VG.gmt: line 47: [-f: command not found
...

But GMT5 fails:

> which gmt
/Applications/GMT-5.4.5.app/Contents/Resources/bin/gmt
...
Running GMT script gmt/hybrid_3.P.IF1C.time.VG.gmt ...
+ gmt gmtset FONT_ANNOT_PRIMARY 14 FONT_ANNOT_SECONDARY 14 FONT_TITLE 14
+ gmt gmtset PS_PAGE_ORIENTATION portrait MAP_ORIGIN_X 0.5 MAP_ORIGIN_Y 0.5
+ gmt gmtset FONT_ANNOT_PRIMARY 8 FONT_ANNOT_SECONDARY 6 FONT_HEADING 12 FONT_LABEL 10
gmtset: Syntax error: Unrecognized keyword FONT_HEADING.
gmtset:  1 GMT Defaults conversion errors from command options
...

So basically I can and will use GMT6. If we can get GMT5 running, all the better.
After a bit of testing, I will push all to the github main.

Thanks so much again! A great improvement for all users of NonLinLoc.

Anthony

@sean0921
Copy link
Contributor Author

sean0921 commented Feb 19, 2023

It seems that FONT_HEADING in gmt.conf is not supported yet in GMT 5.x, which is used to replace HEADER_FONT_SIZE in GMT 4.x config.

Maybe I will temporary remove this option in order to support both GMT version, if the generated layout still seems to be fine.

@alomax
Copy link
Collaborator

alomax commented Apr 17, 2023

Hi Sean

I have merged and tested all your changes remotely and pushed to the main branch here.
So all may be OK for GMT 5 and 6. I have found that running Grid2GMT with GMT 4 works here (Mac OS X) when the compile flag is set for GMT 6.

Anthony

@alomax alomax closed this Jun 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants