Modern mode : should I?

See this comment from @pwessel

I’m currently in a very low productivity period, and I occupy my days cleaning / updating / rewriting my codes. And now GMT ones time has come.

The vast majority of my scripts consists in reading some data (netcdf and txt) generated by Matlab (I know @Joaquim, I should try the wrapper… But I really don’t want to make a mess of my soon to be clean system) to plot nice figures (maps, histogram, time-series…). Sometimes within for loop to create multiple figures at once or do animations. (see example hereafter)

Before starting, I’d like your opinion:
Should I rewrite all my GMT5 codes with the Modern mode syntax (which implies learning it) or not ?

Example given : The following example creates several pdf pages containing two [longitude-time “hovmöller”] diagrams side by side. Each page overlap with the precedent such as p.1 goes from 1980 to 1985, p.2 1982 to 1987 and so on…

for i in $(seq $start $inc $stop);
do

k1=$(echo "$i -${inc};" | bc)
k2=$(echo "$i +${inc};" | bc)
day1="$k1-01-01"
day2="$k2-12-31"
region1="-R$lon1a/$lon1b/$day1/$day2"
region2="-R$lon2a/$lon2b/$day1/$day2"

## Left side
if [[ $i == ${start} ]];
then
gmt grdimage $region1 $projection1 $DATA1 -Ccolr.cpt -K > $psFile
else
gmt grdimage $region1 $projection1 $DATA1 -Ccolr.cpt -K >> $psFile
fi
gmt psbasemap -R -J -Bxa20g10f10 -Bsya1Y -Bpya6Og4Of1O -BWSen -O -K >> $psFile

## Right side

gmt grdimage ${region2} ${projection2} $DATA2 -Ccolr.cpt -X${gap}c -K >> $psFile
gmt psxy -R -J -W1.0,black,-. -O -K <<EOF>> $psFile
180 0
180 15000
EOF

gmt psbasemap -R -J -Bxa20g20f10 -Byg4Of1O -BwSen+t"$TITLE" -O -K >> $psFile
gmt psscale -R -J -Ccolr.cpt $COLORBAR $TITLE_scale -Np -O >> $psFile

done

It really depends on your time management. GMT classic mode is not going away so your scripts will still run in GMT 7 etc. And rewriting these to modern mode will be a learning experience that clearly will take some time, and in the end they will result in the same plots. And there may be setbacks when you run into a bug that requires us to fix it (which is good for all in the long run but can be frustrating if it is a hard bug to fix).

However, there are some benefits:

  1. In the long run, you will spend less time writing long GMT scripts since the modern ones are typically ~40+ % shorter.
  2. For animations you will leverage all the cores on your computer at no extra effort since gmt movie automates that and hides much of the complications of turning frames to MP4 or GIF.
  3. For the example above, which is not an animation, there is gmt batch which, like gmt movie, will automate the use of all your cores and you just need to write the modern mode script that creates one plot, with the variables coming from either a -T option (in your case maybe -T1982/2020/2) or a table with columns holding needed information per plot.
  4. Modern mode script are much closer to what the wrappers do, but not really, as @Joaquim will point out . However, this will change once we introduce longer options (keyword/values) for the command line (e.g., --region=w/e/s/n). Also, I do not think (but am not sure) if movie and batch are available in GMT.jl or PyGMT, yet.
  5. So far, mostly the brave are trying out gmt movie and gmt batch. These can be made better if people try them and give constructive feedback.

Given you are looking for things to fill time for you, during the pandemic, I think this would be a useful investment for you, but that is your decision to make.

The GMT team is looking into offering user workshop online as we revise our tutorial material, but unlikely to happen until late Spring. I would like to give one on animation for users already familiar with GMT.

Ok @pwessel : I’m giving it a shot. So far I’m not sure to be fond of the way arguments are implicitly given (colormaps for example), but I think I can get used to it… And you’re right, the length of the script is significantly shorter (which improves a lot the legibility).

I’m currently trying to reproduce a simple map with grdimage, so far so good … But I know I will run into troubles soon with grdvector. so far so good.

1 Like