Problem creating Postscript file contoured map in Ubuntu 18.04 - pscontour: Error: Z-slice with dz = 0

I’m running a perl script which calls a Generic Mapping Tools (GMT) module, pscontour , with the following arguments

gmt pscontour '../../../TMP_files/hor/vpvs3 1.grd.xyz' -R-72.1999969/-69.5000000/-22.5000000/-18.5000000 -JX7c/11.0715172245984c -C'../../../DATA/GEO_DAT1/MODEL_01/data/dv_anom_NaN.cpt' -I -B1.0/0.5:"latitude, degrees"::."Vp/Vs, depth= 10 km":WeSn -Xa4c -Ya39.9284827754016c -O -K >> '../../../PICS/ps/GEO_DAT1/MODEL_01/vis_result_VpVs_3.ps'

where it essentially tries to create a contoured map as a PostScript file with the given input files and parameters. However, this line of code gives errors:

pscontour: Error: Z-slice with dz = 0
[Session gmt (0)]: Error returned from GMT API: GMT_CPT_READ_ERROR (8)
[Session gmt (0)]: Error returned from GMT API: GMT_CPT_READ_ERROR (8)
[Session gmt (0)]: Error returned from GMT API: GMT_CPT_READ_ERROR (8)

and thus the output is a blank .ps file (i.e. vis_result_VpVs_3.ps is empty).

The dv_anom_NaN.cpt contains

1.6     0/24/120        1.63    0/24/120
1.63    0/74/157        1.66    0/74/157
1.66    0/148/213       1.69    0/148/213
-10000  gray    -500    gray
-500    51/221/255      1.72    51/221/255
1.69    51/221/255      1.72    51/221/255
1.69    51/221/255      1.72    51/221/255
1.72    179/255/242     1.75    179/255/242
1.75    203/203/152     1.78    203/203/152
1.78    133/133/82      1.81    133/133/82
1.81    59/51/8 1.84    59/51/8
1.84    105/48/48       1.87    105/48/48
1.87    137/16/16       1.9     137/16/16
1.9     137/16/16       1.9     137/16/16
500     137/16/16       1.9     137/16/16
B       black
F       white
N       gray49

I don’t know what is the problem with the content of this file. When I compare this file with an example of a .cpt file in my GMT directories, the formatting seems okay to me. To give some clarities, this .cpt file is created with this line of code (inside the perl script):

gmt makecpt -Cblue_brown.cpt -T1.6/1.9/0.03 > dv_anom.cpt

where blue_brown.cpt contains

# blue brown 25lvl color pallete table 29/10/2009
#COLOR_MODEL = RGB 
0 0 0 102 1 0 0 102 
1 0 24 120 2 0 24 120 
2 0 49 139 3 0 49 139 
3 0 74 157 4 0 74 157 
4 0 98 176 5 0 98 176 
5 0 123 194 6 0 123 194 
6 0 148 213 7 0 148 213 
7 0 173 231 8 0 173 231 
8 0 197 250 9 0 197 250 
9 51 221 255 10 51 221 255 
10 120 244 255 11 120 244 255 
11 179 255 242 12 179 255 242 
12 229 255 217 13 229 255 217 
13 238 238 187 14 238 238 187 
14 203 203 152 15 203 203 152 
15 167 167 116 16 167 167 116 
16 133 133 82 17 133 133 82
17 100 100 49 18 100 100 49
18 67 67 16 19 67 67 16
19 59 51 8 20 59 51 8
20 74 51 8 21 74 51 8
21 89 51 38 22 89 51 38
22 105 48 48 23 105 48 48
23 121 32 32 24 121 32 32
24 137 16 16 25 137 16 16
25 153 0 0 26 153 0 0   
N 125 125 125 

and dv_anom.cpt contains

.6     0/24/120        1.63    0/24/120
1.63    0/74/157        1.66    0/74/157
1.66    0/148/213       1.69    0/148/213
1.69    51/221/255      1.72    51/221/255
1.72    179/255/242     1.75    179/255/242
1.75    203/203/152     1.78    203/203/152
1.78    133/133/82      1.81    133/133/82
1.81    59/51/8 1.84    59/51/8
1.84    105/48/48       1.87    105/48/48
1.87    137/16/16       1.9     137/16/16
B       black
F       white
N       gray49

At some point inside the perl script, dv_anom.cpt modifies the content of dv_anom_NaN.cpt .

Again, I suspect there is nothing wrong with the content and the formatting of these two files. I tried Googling this error, only to find a really old thread about the same error message (but different module used) here and here, which I doubt is still relevant (I’m using latest gmt version 5.4.3). Oh yeah, I’m running Ubuntu 18.04.

Sorry, I fail to see what is the question here. The problem seems clearly related to the dv_anom_NaN.cpt file that has those abnormal numbers.

1 Like

Looks like you are making an assumption that CPT slices do not have to be in ascending order. They do. Furthermore, you also have two overlapping slices: One for -500 to 1.72 and another from 1.69 to 1.72. So for a z-value of 1.70 there are two slices with different color on offer. This cannot work either.

1 Like

Hello again,

Thanks for giving feedbacks. I’m such a huge noob on GMT so please bear with me.

Finally I understood that I need to have the same structure of file as in dv_anom.cpt, and so let’s just forget why dv_anom_NaN.cpt even exists.

I run pscontour with this cpt file and it works, but then one thing bothers me: what I assume as background color B is set to something that is bizarre. I was able to convert the ps files into png (using pdftoppm), but the background color is greyish weird pattern. How can I parametrize this in makecpt command to produce a desirable background color? Or this might be due to another error that I miss?

I attach the converted png file to give you an idea.

Thanks again for the feedback.

Unless you added your own B to your cpt file it will pick up the GMT defaults background color which is black - and your plot looks black to me. See makecpt -D, -M, -N for various ways to deal with those colors and change them.
Also, if you use gmt modern mode then it can automatically convert to whatever graphic format you use; dealing with pdftoppm and similar tool is a waste of time and often gives bad conversions. Manually in classic gmt you can call psconvert to make rasters from PS.

Yes, you’re right. I wasn’t aware of that small detail. Thank you. I’ll try to perform automatic conversion with GMT as well, but that’s for another topic.

Even in classic mode you should use psconvert to convert from PS to other formats.
Have a look also at the pscontour tests