GenericMappingTools / GMT.jl

Generic Mapping Tools Library Wrapper for Julia
Other
196 stars 28 forks source link

Problem with automatic legend with grdvector #1499

Open amarux opened 3 months ago

amarux commented 3 months ago

Hello,

I am using the grdvector to represent ocean currents and would like to include a reference vector in the legend. I uploaded an example dataset I am using to: https://drive.google.com/file/d/1rrYrVIQMPHJl868BMZrr7Nqkhq6QXKVw/view?usp=sharing

The file contains Cartesian vectors with the eastward (ugos) and northward velocity components. To use the automatic labeling of GMT, I transformed Cartesian to polar coordinates. Finally the code that I used to represent the vector is:

grdvector(Gr, Gtheta, polar=true, spacing=0.5, 
    vec_scale=(scale="4.5c", scale_at_lat=true, refsize=1.), 
    arrow=(shape=:arrow, stop=true, pen=("20p,black",), 
    len=0.16, fill=:black, norm=2.), legend=(label="1 m/s", pos=:MiddleCenter))

However I obtained the following error:

grdvector [ERROR]: Option -S : No vector scale point is allowed for Cartesian vector

Could you help me to identify what I missing?

Thank you

joa-quim commented 3 months ago

Hi, I’m currently away in vacations till 15 August and cannot test you example. Not sure what that error message means, maybe it is something related to the polar coordinates case. But why do you say that you use polar in order to have automatic legend?

Anyway, as far as I remember to have automatic vectors in legends one must use the modern mode. That is, wrap the commands in a gmtbegin()… gmtend() because the classic mode legend is not able to plot arrows.

Try playing with the vec_scale options to see what needs to make the error message go away.

joa-quim commented 3 months ago

I find strange that the error says “Cartesian”. If you add the option Vd=1 you get the full GMT command. Does it have in it the option -A?

amarux commented 3 months ago

@joa-quim thank you for answer to my issue.

This is the full command I got when using the option Vd=1

GMT [DEBUG]: Revised options: -R -J -Vd -A -I0.5 -S4.5c+c+s1 -Q0.16+e+gblack+n2+p20p,black+h1 -Gblack -K -O ->>/tmp/GMTjl_amaru.ps @GMTAPI@-S-I-G-G-G-N-000028 @GMTAPI@-S-I-G-G-G-N-000029

I used polar coordinates instead of Cartesian because in the documentation it is indicated that (https://docs.generic-mapping-tools.org/latest/grdvector.html):

"+c[[slon/]slat] controls where on a geographic map a geovector’s refsize length applies. The modifier is neither needed nor available when plotting Cartesian vectors. "

On the other hand I am not used to used modern mode but, I think is good time to learn how to use it!

Enjoy your holidays.

Thanks again!

joa-quim commented 3 months ago

Continue the strange things. That message was printed by GMT, not by GMT.jl as it should so not sure about the missing -A.

The Cartesian referred in the docs means that they are not geographical and then, logically, one cannot use scake_at_lat. Are your grids geographical or Cartesian?

joa-quim commented 2 months ago

What does it print Vd=2 instead of Vd=1?

Note, it’s Vd=2, not V=“d” like I think you did.

joa-quim commented 2 months ago

But we are being dum. A polar grid is not geographic so can’t support scale_at_lat.

amarux commented 2 months ago

Yes! you are right I used V=1 and not Vd. Now, this is the message I got:

 grdvector  -R -J -Ve -A -I0.5 -S4.5c+c-88.0/25.0+s1 -Q0.16+e+gblack+n2+p20p,black+h1 -Gblack -K -O >> /tmp/GMTjl_amaru.ps
grdvector [ERROR]: Option -S : No vector scale point is allowed for Cartesian vector
ERROR: Something went wrong when calling the module. GMT error number = 72
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] gmt(::String, ::GMTgrid{Float64, 2}, ::Vararg{Any})
   @ GMT ~/.julia/packages/GMT/KSmVP/src/gmt_main.jl:169
 [3] finish_PS_module(::Dict{…}, ::Vector{…}, ::String, ::Bool, ::Bool, ::Bool, ::GMTgrid{…}, ::Vararg{…})
   @ GMT ~/.julia/packages/GMT/KSmVP/src/common_options.jl:4393
 [4] grdvector(arg1::GMTgrid{…}, arg2::GMTgrid{…}; first::Bool, kwargs::@Kwargs{…})
   @ GMT ~/.julia/packages/GMT/KSmVP/src/grdvector.jl:148
 [5] grdvector
   @ ~/.julia/packages/GMT/KSmVP/src/grdvector.jl:58 [inlined]
 [6] #grdvector!#445
   @ ~/.julia/packages/GMT/KSmVP/src/grdvector.jl:184 [inlined]
 [7] top-level scope
   @ ~/GMOG_CODE/GENERAL_PURPOSES/plot_slas_xiximis.jl:98
Some type information was truncated. Use `show(err)` to see complete types.

I am representing vectors in a geographical space (i.e. ocean currents in the Gulf of Mexico). However, even when I removed option -A the error persists when used grdvector with the original northward and eastward components of current velocity.

Thank you.

joa-quim commented 2 months ago

The examples at the end of https://www.generic-mapping-tools.org/GMTjl_doc/examples/arrows/10_arrows/#arrow_examples are in geogs and work well. I suspect that the problem is that your grids are not being recognized as geographic grids. Try adding the option f=:g Other option is to read the grids with gmtread and fill the proj4 member of each grid type with “+proj=longlat” There is a function to do that but can’t remember its name.