How to plot rotated cross and color them with cpt palette

Hi,
I’m a new pygmt user and I would plot text symbols rotated by a defined angle that I provide as input.
In older version of GMT (up to 5) I did this with command as

awk ‘{if ($7>=0 && $7<45) {print $1, $2, 90-$7, “+”}}’ ./filename |
pstext ${R} ${P} -O -K -F+a -F+f18p,Times-Roman,${AAA} >> ${output}

where $7 is the angle of rotation of the symbol +.
How can I adapt this command in pygmt? and how can I color the symbols in agreement with a color table defines the angle of rotation?
Thanks in advance and let me know if I should provide more details,
SImone

using text to plot symbol will only bring hardship since you cannot color things via CPT. Use plot for these things and make a simple custom symbol that allows for rotation.

Dear Paul,
tanks for your reply. I checked between custom symbols and the most appropriate for me is the cross.
I tried to plot them as

        fig.plot(x=null_sel.lon_pp, y=null_sel.lat_pp,
             direction=[null_sel.baz.array,null_sel.dt.array+0.9],
             style="kcross/1c", pen="thin,+z",
             zvalue=null_sel.baz.array, 
             cmap='cmapBAZ.cpt')     

where baz, dt, lon_pp and lat_pp are pd.Series composing the null_sel pd.dataframe.
Using this command what I obtain is the map with cross colored according to the baz values but not rotated to the right angle (always defined by the baz ps.Series).
Reading here https://docs.generic-mapping-tools.org/latest/cookbook/custom-symbols.html#custom-symbols it seem that the angle of rotation for the cross symbols could be given in input as extra_parameters (defined by N option) but I haven’t find the same option in the plot module for pygmt. What is the option I should give in input to pygmt to plot it?
Thanks,
Simone

There is no such module option. You will need to make your own custom symbol, say rotplus.def that looks something like this:

N: 1 a     # Expect variable azimuth as an extra argument
O $1       # Rotate coordinate system by this azimuth
0 0 +      # Plot the plus symbol after rotation

and use style=“krotplus/1c” and pass in lon, lat, azimuth.

Minor correction, should be $1 O for rotation. Here is a simple example of showing the direction of an azimuth. Call this file rot.def:

# Custom symbol showing a rotation
N:	1 a
0	0	0.1	c
$1 O
0	0	M
0	0.5	D

On the command line I test this via

echo 0 0 30 | gmt plot -R-3/3/-3/3 -JM10c -Skrot/4c -W2p -B -png map

yielding

Hi,
following your suggestion I create a file mycross.def as

N: 1 a # Expect variable azimuth as an extra argument

$1 O # Rotate coordinate system by this azimuth

0 0 + # Plot the plus symbol after rotation

and tried to plot them as

datatmp=null_sel[[‘lon_pp’,‘lat_pp’,‘baz’]]
fig.plot(data=datatmp,
style=“kmycross/1c”, pen=“thin,+z”,
zvalue=null_sel.baz.array,
cmap=‘cmapBAZ.cpt’)

but I get this error

plot [ERROR]: Failed to parse symbol commands in file mycross.def
plot [ERROR]: Offending line: $1 O # Rotate coordinate system by this azimuth
plot [ERROR]: Option -S: Parsing failure


GMTCLibError Traceback (most recent call last)
in
71 datatmp=null_sel[[‘lon_pp’,‘lat_pp’,‘baz’]]
72 #print(datatmp)
—> 73 fig.plot(data=datatmp,
74 style=“kmycross/1c”, pen=“thin,+z”,
75 zvalue=null_sel.baz.array,

~/anaconda3/envs/pygmt/lib/python3.9/site-packages/pygmt/helpers/decorators.py in new_module(*args, **kwargs)
286 if alias in kwargs:
287 kwargs[arg] = kwargs.pop(alias)
→ 288 return module_func(*args, **kwargs)
289
290 new_module.aliases = aliases

~/anaconda3/envs/pygmt/lib/python3.9/site-packages/pygmt/helpers/decorators.py in new_module(*args, **kwargs)
430 kwargs[arg] = separators[fmt].join(f"{item}" for item in value)
431 # Execute the original function and return its output
→ 432 return module_func(*args, **kwargs)
433
434 return new_module

~/anaconda3/envs/pygmt/lib/python3.9/site-packages/pygmt/src/plot.py in plot(self, x, y, data, sizes, direction, **kwargs)
231 with file_context as fname:
232 arg_str = " ".join([fname, build_arg_string(kwargs)])
→ 233 lib.call_module(“plot”, arg_str)

~/anaconda3/envs/pygmt/lib/python3.9/site-packages/pygmt/clib/session.py in call_module(self, module, args)
502 )
503 if status != 0:
→ 504 raise GMTCLibError(
505 “Module ‘{}’ failed with status code {}:\n{}”.format(
506 module, status, self._error_message

GMTCLibError: Module ‘plot’ failed with status code 71:
plot [ERROR]: Failed to parse symbol commands in file mycross.def
plot [ERROR]: Offending line: $1 O # Rotate coordinate system by this azimuth
plot [ERROR]: Option -S: Parsing failure

The same errors I get using your rot.def symbol.
Am I missing something in the plot option? or do you know what is the problem??

Simone

Maybe we cannot have those ## comments at the end. Try to remove them or put them on separate lines.

Yes, that was it. Now fixed in master.

Hi,
I tried to remove any comment lines but the problem remain the same.
However I did some other test and I found two more indication:

  • the line “$1 O” it seem option not recognized by pygmt, if I delete this line the script works to the end (even if symbols are not rotated).
  • If in my def file I substitute the “+” symbols with other standard one (as circle or square) the script works, while if I use the “+” symbols I get the error

plot [ERROR]: Unrecognized symbol code (43 = ‘+’) passed to gmt_draw_custom_symbol

I don’t know if these two more indication could be useful but at the moment the problem remain.

Simone

It is just neither of us are really paying attention to the syntax listed in the table in the custom symbols section…

Here is a working def file:

N: 1 a
$1 O
0 0 1 +

Ok, found the mistake.
I was using pygmt 0.3 and GMT 1.1, after update to pygmt 0.4 and GMT 6.2 the symbols are plotted correctly. Surely is my fault that I didn’t check earlier.
Thanks for the help,
Simone