From c355a0fdc076e07dad2e7427966a13fc2b3dda40 Mon Sep 17 00:00:00 2001 From: Joaquim Luis Date: Tue, 25 Dec 2018 18:23:42 +0000 Subject: [PATCH] Many changes in the psxy avatars. No longer use K, O. Add a mat2ds function. --- src/GMT.jl | 6 +- src/blocks.jl | 21 +--- src/common_docs.jl | 16 +-- src/common_options.jl | 82 +++++++++----- src/gmt_main.jl | 54 ++++++--- src/gmtinfo.jl | 2 +- src/plot.jl | 250 +++++++++++++++++------------------------- src/psxy.jl | 138 ++--------------------- test/runtests.jl | 19 +++- 9 files changed, 237 insertions(+), 351 deletions(-) diff --git a/src/GMT.jl b/src/GMT.jl index 902f00ca5b..c9ba4aaf2e 100644 --- a/src/GMT.jl +++ b/src/GMT.jl @@ -34,8 +34,8 @@ export grd2cpt, grd2kml, grd2xyz, grdblend, grdclip, grdcontour, grdcontour!, grdcut, grdedit, grdfft, grdfilter, grdgradient, grdhisteq, grdimage, grdimage!, grdinfo, grdlandmask, grdpaste, grdproject, grdsample, grdtrack, grdtrend, grdvector, grdvector!, grdview, grdview!, grdvolume, greenspline, - mat2grid, histogram, histogram!, image, image!, imshow, imshow!, kml2gmt, logo, logo!, makecpt, - mask, mask!, mapproject, nearneighbor, plot, plot!, plot3d, plot3d!, project, + mat2ds, mat2grid, mat2img, histogram, histogram!, image, image!, imshow, imshow!, kml2gmt, logo, logo!, + makecpt, mask, mask!, mapproject, nearneighbor, plot, plot!, plot3d, plot3d!, project, pscontour, pscontour!, psconvert, psbasemap, psbasemap!, psclip, psclip!, pscoast, pscoast!, pshistogram, pshistogram!, psimage, psimage!, psmask, psmask!, psrose, psrose!, psscale, psscale!, pssolar, pssolar!, psternary, psternary!, pstext, pstext!, pswiggle, pswiggle!, psxy, psxy!, psxyz, @@ -95,6 +95,7 @@ include("kml2gmt.jl") include("makecpt.jl") include("mapproject.jl") include("nearneighbor.jl") +include("plot.jl") include("project.jl") include("psbasemap.jl") include("psclip.jl") @@ -111,7 +112,6 @@ include("pssolar.jl") include("pstext.jl") include("psxy.jl") include("pswiggle.jl") -include("plot.jl") include("sample1d.jl") include("spectrum1d.jl") include("sphdistance.jl") diff --git a/src/blocks.jl b/src/blocks.jl index 0049930fb9..f53e6cd12b 100644 --- a/src/blocks.jl +++ b/src/blocks.jl @@ -30,7 +30,7 @@ Parameters outputs x,y,z[,w]. See -W for w output. If -Ep is used we assume weights are 1/(sigma squared) and s becomes the propagated error of the mean. [`-E`](http://gmt.soest.hawaii.edu/doc/latest/blockmean.html#e) -- **G** : **grid** : -- Str or [] -- +- **G** : **grid** : **gridfile** : -- Str or [] -- Write one or more fields directly to grids on disk; no table data are return. If more than one fields are specified via **A** then grdfile must contain the format flag %s so that we can embed the @@ -61,8 +61,7 @@ function blockmean(cmd0::String="", arg1=[]; kwargs...) length(kwargs) == 0 && return monolitic("blockmean", cmd0, arg1) # Speedy mode d = KW(kwargs) - cmd = add_opt("", 'E', d, [:E :extended]) - cmd = add_opt(cmd, 'S', d, [:S :npts :number_of_points]) + cmd = parse_these_opts("", d, [[:E :extended], [:S :npts :number_of_points]]) return common_blocks(cmd0, arg1, d, cmd, "blockmean", kwargs...) end @@ -79,9 +78,7 @@ function blockmedian(cmd0::String="", arg1=[]; kwargs...) length(kwargs) == 0 && return monolitic("blockmedian", cmd0, arg1) # Speedy mode d = KW(kwargs) - cmd = add_opt("", 'E', d, [:E :extended]) - cmd = add_opt(cmd, 'Q', d, [:Q :quick]) - cmd = add_opt(cmd, 'T', d, [:T :quantile]) + cmd = parse_these_opts("", d, [[:E :extended], [:Q :quick], [:T :quantile]]) return common_blocks(cmd0, arg1, d, cmd, "blockmedian", kwargs...) end @@ -98,18 +95,14 @@ function blockmode(cmd0::String="", arg1=[]; kwargs...) length(kwargs) == 0 && return monolitic("blockmode", cmd0, arg1) # Speedy mode d = KW(kwargs) - cmd = add_opt("", 'E', d, [:E :extended]) - cmd = add_opt(cmd, 'D', d, [:D :histogram_binning]) - cmd = add_opt(cmd, 'Q', d, [:Q :quick]) + cmd = parse_these_opts("", d, [[:E :extended], [:D :histogram_binning], [:Q :quick]]) return common_blocks(cmd0, arg1, d, cmd, "blockmode", kwargs...) end # --------------------------------------------------------------------------------------------------- function common_blocks(cmd0, arg1, d, cmd, proggy, kwargs...) - cmd = add_opt(cmd, 'A', d, [:A :fields]) - cmd = add_opt(cmd, 'C', d, [:C :center]) - cmd = add_opt(cmd, 'G', d, [:G :grid]) + cmd = parse_these_opts(cmd, d, [[:A :fields], [:C :center], [:G :grid :gridfile], [:I :inc], [:W :weights]]) if (occursin("-G", cmd) && !occursin("-A", cmd)) cmd = cmd * " -Az" # So that we can use plain -G to mean write grid end @@ -117,10 +110,8 @@ function common_blocks(cmd0, arg1, d, cmd, proggy, kwargs...) @warn("Computing grids is only possible with GMT version >= 6") return nothing end - cmd = parse_common_opts(d, cmd, [:R :V_params :bi :di :e :f :h :i :o :r :xy]) + cmd = parse_common_opts(d, cmd, [:R :V_params :bi :di :e :f :h :i :o :r :yx]) - cmd = add_opt(cmd, 'I', d, [:I :inc]) - cmd = add_opt(cmd, 'W', d, [:W :weights]) cmd, got_fname, arg1 = find_data(d, cmd0, cmd, 1, arg1) if (occursin("-G", cmd)) # GMT API does not allow a -G from externals diff --git a/src/common_docs.jl b/src/common_docs.jl index ce80936063..0f03683888 100644 --- a/src/common_docs.jl +++ b/src/common_docs.jl @@ -2,8 +2,8 @@ const GMTdoc = "http://gmt.soest.hawaii.edu/doc/latest/" const opt_C = "**C** : **color** : **cmap** : -- Str -- ``Flags = [cpt |master[+izinc] |color1,color2[,*color3*,…]]`` - Name of the CPT (for grd_z only). Alternatively, supply the name of a GMT color - master dynamic CPT. + Give a CPT name or specify -Ccolor1,color2[,color3,...] to build a linear continuous CPT from those + colors automatically. [`-C`](http://gmt.soest.hawaii.edu/doc/latest/grdimage.html#c)" const opt_J = "**J** : **proj** : -- ::String -- @@ -104,28 +104,28 @@ const opt_g = "**g** : **gaps** : -- Str -- ``Flags = [a]x|y|d|X|Y|D|[ Examine the spacing between consecutive data points in order to impose breaks in the line. [`-g`](http://gmt.soest.hawaii.edu/doc/latest/gmt.html#g-full)" -const opt_h = "**h** : **headers** : -- Str -- ``Flags = [i|o][n][+c][+d][+rremark][+ttitle]`` +const opt_h = "**h** : **header** : -- Str -- ``Flags = [i|o][n][+c][+d][+rremark][+ttitle]`` Primary input file(s) has header record(s). [`-h`](http://gmt.soest.hawaii.edu/doc/latest/gmt.html#h-full)" -const opt_i = "**i** : **input_col** : -- Str -- ``Flags = cols[+l][+sscale][+ooffset][,…]`` +const opt_i = "**i** : **incol** : -- Str -- ``Flags = cols[+l][+sscale][+ooffset][,…]`` Select specific data columns for primary input, in arbitrary order. [`-i`](http://gmt.soest.hawaii.edu/doc/latest/gmt.html#icols-full)" -const opt_n = "**n** : **interp** : -- Str -- ``Flags = [b|c|l|n][+a][+bBC][+c][+tthreshold]`` +const opt_n = "**n** : **interp** : **interpol** : -- Str -- ``Flags = [b|c|l|n][+a][+bBC][+c][+tthreshold]`` Select grid interpolation mode by adding b for B-spline smoothing, c for bicubic interpolation, l for bilinear interpolation, or n for nearest-neighbor value. [`-n`](http://gmt.soest.hawaii.edu/doc/latest/gmt.html#n-full)" -const opt_o = "**o** : **output_col** : -- Str -- ``Flags = cols[,…]`` +const opt_o = "**o** : **outcol** : -- Str -- ``Flags = cols[,…]`` Select specific data columns for primary output, in arbitrary order. [`-o`](http://gmt.soest.hawaii.edu/doc/latest/gmt.html#ocols-full)" -const opt_p = "**p** : **view** : -- Str or List -- `Flags = [x|y|z]azim[/elev[/zlevel]][+wlon0/lat0[/z0]][+vx0/y0]` +const opt_p = "**p** : **view** : **perspective** : -- Str or List -- `Flags = [x|y|z]azim[/elev[/zlevel]][+wlon0/lat0[/z0]][+vx0/y0]` Selects perspective view and sets the azimuth and elevation of the viewpoint [180/90]. [`-p`](http://gmt.soest.hawaii.edu/doc/latest/gmt.html#perspective-full)" @@ -145,7 +145,7 @@ const opt_t = "**t** : **alpha** : **transparency** : -- Str -- ``Flags = tran Set PDF transparency level for an overlay, in (0-100] percent range. [Default is 0, i.e., opaque]. [`-t`](http://gmt.soest.hawaii.edu/doc/latest/gmt.html#t-full)" -const opt_x = "**x** : **n_threads** : -- Str or Number -- ``Flags = [[-]n]`` +const opt_x = "**x** : **cores** : **n_threads** : -- Str or Number -- ``Flags = [[-]n]`` Limit the number of cores to be used in any OpenMP-enabled multi-threaded algorithms. [`-x`](http://gmt.soest.hawaii.edu/doc/latest/gmt.html#x-full)" diff --git a/src/common_options.jl b/src/common_options.jl index c911d05f5d..e311e41a4b 100644 --- a/src/common_options.jl +++ b/src/common_options.jl @@ -354,31 +354,31 @@ end # --------------------------------------------------------------------------------------------------- function parse_h(cmd::String, d::Dict) # Parse the global -h option. Return CMD same as input if no -h option in args - return parse_helper(cmd, d, [:h :headers], " -h") + return parse_helper(cmd, d, [:h :header], " -h") end # --------------------------------------------------------------------------------------------------- function parse_i(cmd::String, d::Dict) # Parse the global -i option. Return CMD same as input if no -i option in args - return parse_helper(cmd, d, [:i :input_col], " -i") + return parse_helper(cmd, d, [:i :incol], " -i") end # --------------------------------------------------------------------------------------------------- function parse_n(cmd::String, d::Dict) # Parse the global -n option. Return CMD same as input if no -n option in args - return parse_helper(cmd, d, [:n :interp :interp_method], " -n") + return parse_helper(cmd, d, [:n :interp :interpol], " -n") end # --------------------------------------------------------------------------------------------------- function parse_o(cmd::String, d::Dict) # Parse the global -o option. Return CMD same as input if no -o option in args - return parse_helper(cmd, d, [:o :output_col], " -o") + return parse_helper(cmd, d, [:o :outcol], " -o") end # --------------------------------------------------------------------------------------------------- function parse_p(cmd::String, d::Dict) # Parse the global -p option. Return CMD same as input if no -p option in args - return parse_helper(cmd, d, [:p :view], " -p") + return parse_helper(cmd, d, [:p :view :perspective], " -p") end # --------------------------------------------------------------------------------------------------- @@ -403,7 +403,7 @@ end # --------------------------------------------------------------------------------------------------- function parse_x(cmd::String, d::Dict) # Parse the global -x option. Return CMD same as input if no -x option in args - return parse_helper(cmd, d, [:x :n_threads], " -x") + return parse_helper(cmd, d, [:x :cores :n_threads], " -x") end # --------------------------------------------------------------------------------------------------- @@ -1400,15 +1400,13 @@ function read_data(d::Dict, fname::String, cmd, arg, opt_R="", opt_i="", opt_bi= if (opt_R == "" || opt_R[1] == '/') info = gmt("gmtinfo -C" * opt_i, arg) # Here we are reading from an original GMTdataset or Array - if (opt_R != "" && opt_R[1] == '/') # Modify waht will be reported as a -R string - # Example "/-1/1/0//" will extend x axis +/- 0.1, set y_min=0 and no change to y_max + if (opt_R != "" && opt_R[1] == '/') # Modify what will be reported as a -R string + # Example "/-0.1/0.1/0//" will extend x axis +/- 0.1, set y_min=0 and no change to y_max rs = split(opt_R, '/') for k = 2:length(rs) if (rs[k] != "") x = parse(Float64, rs[k]) - if (x == 0.0) info[1].data[k-1] = x - else info[1].data[k-1] += x - end + (x == 0.0) ? info[1].data[k-1] = x : info[1].data[k-1] += x end end end @@ -1420,7 +1418,7 @@ function read_data(d::Dict, fname::String, cmd, arg, opt_R="", opt_i="", opt_bi= opt_R = @sprintf(" -R%.12g/%.12g/%.12g/%.12g", info[1].data[1], info[1].data[2], info[1].data[3], info[1].data[4]) end - cmd = cmd * opt_R + cmd *= opt_R end return cmd, arg, opt_R, opt_i @@ -1712,30 +1710,61 @@ mutable struct legend_bag end # -------------------------------------------------------------------------------------------------- -function put_in_legend_bag(d::Dict, cmd) +function put_in_legend_bag(d::Dict, cmd, arg=nothing) # So far this fun is only called from plot() and stores line/symbol info in global var LEGEND_TYPE global legend_type - if ((val = find_in_dict(d, [:lab :label])[1]) !== nothing) + #if ((val = find_in_dict(d, [:lab :label])[1]) !== nothing) + #lab = [val] + #elseif (legend_type === nothing) lab = ["y1"] + #else lab = [@sprintf("y%d", size(legend_type.label ,1))] + #end + + cmd_ = cmd # Starts to be just a shallow copy + if (isa(arg, Array{GMT.GMTdataset,1})) # Multi-segments can have different settings per line + cmd_ = deepcopy(cmd) # OK, in this case we need to make it a deep copy + pens = Array{String,1}(undef,length(arg)) + for k = 1:length(arg) + pens[k] = " -W," * scan_opt(arg[k].header, "-W"); + end + lab = Array{String,1}(undef,length(arg)) + if ((val = find_in_dict(d, [:lab :label])[1]) !== nothing) # Have label(s) + if (!isa(val, Array)) # One single label, take it as a label prefix + for k = 1:length(arg) lab[k] = string(val,k) end + else + for k = 1:min(length(arg), length(val)) lab[k] = string(val[k],k) end + if (length(val) < length(arg)) # Probably shit, but don't error because of it + for k = length(val)+1:length(arg) lab[k] = string(val[end],k) end + end + end + else + for k = 1:length(arg) lab[k] = string('y',k) end + end + # Now need to append the 'pens' var to the input arg CMD + if (isa(cmd, String)) cmd_ = append!([cmd_], pens) + else append!(cmd_, pens) + end + elseif ((val = find_in_dict(d, [:lab :label])[1]) !== nothing) lab = [val] elseif (legend_type === nothing) lab = ["y1"] else lab = [@sprintf("y%d", size(legend_type.label ,1))] end - if ((isa(cmd, Array{String, 1}) && !occursin("-O", cmd[1])) || (isa(cmd, String) && !occursin("-O", cmd))) + if ((isa(cmd_, Array{String, 1}) && !occursin("-O", cmd_[1])) || (isa(cmd_, String) && !occursin("-O", cmd_))) legend_type = nothing # Make sure that we always start with an empty one end if (legend_type === nothing) legend_type = legend_bag(Array{String,1}(undef,1), Array{String,1}(undef,1)) - legend_type.label = lab; legend_type.cmd = cmd + legend_type.label = lab; legend_type.cmd = cmd_ else if (!isassigned(legend_type.label, 1)) # Some previous error left it in an #undef state - legend_type.label[1] = lab; legend_type.cmd[1] = cmd + legend_type.label[1] = lab; legend_type.cmd[1] = cmd_ else - append!(legend_type.label, lab); append!(legend_type.cmd, cmd) + append!(legend_type.label, lab); append!(legend_type.cmd, cmd_) end end + end # -------------------------------------------------------------------------------------------------- @@ -1746,27 +1775,28 @@ function digests_legend_bag(d::Dict) if ((val = find_in_dict(d, [:leg :legend])[1]) !== nothing) (legend_type === nothing) && @warn("This module does not support automatic legends") && return + fs = 10 # Font size in points + symbW = 0.75 # Symbol width. Default to 0.75 cm (good for lines) nl = length(legend_type.label) leg = Array{String,1}(undef,nl) for k = 1:nl # Loop over number of entries symb = scan_opt(legend_type.cmd[k], "-S"); if (symb == "") symb = "-" end fill = scan_opt(legend_type.cmd[k], "-G"); if (fill == "") fill = "-" end - pen = scan_opt(legend_type.cmd[k], "-W"); + pen = scan_opt(legend_type.cmd[k], "-W"); (pen == "" && symb != "-" && fill != "-") ? pen = "-" : (pen == "" ? pen = "0.25p" : pen = pen) - leg[k] = "S 0.5 " * symb * " 1 " * fill * " " * pen * " 1.2 " * legend_type.label[k] + leg[k] = @sprintf("S %.3fc %s %.2fc %s %s %.2fc %s", symbW/2, symb, symbW, fill, pen, symbW+0.14, legend_type.label[k]) end - symb_width = 1 # Default to 1 cm (good for lines) - lab_width = maximum(length.(legend_type.label[:])) * 12 / 72 * 2.54 * 0.55 + 0.15 # Guess label width in cm + lab_width = maximum(length.(legend_type.label[:])) * fs / 72 * 2.54 * 0.55 + 0.15 # Guess label width in cm if ((opt_D = add_opt("", "", d, [:leg_pos :legend_pos :legend_position], (map_coord="g",plot_coord="x",norm="n",pos="j",width="+w",justify="+j",spacing="+l",offset="+o"))) == "") just = "TR" # The default if (isa(val, String) || isa(val, Symbol)) just = justify(val) end - opt_D = @sprintf("j%s+w%.3f+o0.2", just, symb_width*1.2 + lab_width) + opt_D = @sprintf("j%s+w%.3f+o0.1", just, symbW*1.2 + lab_width) else if (opt_D[1] != 'j' && opt_D[1] != 'g' && opt_D[1] != 'x' && opt_D[1] != 'n') opt_D = "jTR" * opt_D end - if (!occursin("+w", opt_D)) opt_D = @sprintf("%s+w%.3f", opt_D, symb_width*1.2 + lab_width) end - if (!occursin("+o", opt_D)) opt_D *= "+o0.2" end + if (!occursin("+w", opt_D)) opt_D = @sprintf("%s+w%.3f", opt_D, symbW*1.2 + lab_width) end + if (!occursin("+o", opt_D)) opt_D *= "+o0.1" end end if ((opt_F = add_opt("", "", d, [:box_pos :box_position], @@ -1776,7 +1806,7 @@ function digests_legend_bag(d::Dict) if (!occursin("+p", opt_F)) opt_F *= "+p0.5" end if (!occursin("+g", opt_F)) opt_F *= "+gwhite" end end - legend!(text_record(leg), F=opt_F, D=opt_D) + legend!(text_record(leg), F=opt_F, D=opt_D, par=(:FONT_ANNOT_PRIMARY, fs)) legend_type = nothing # Job done, now empty the bag end end diff --git a/src/gmt_main.jl b/src/gmt_main.jl index a9e07fa8ef..20aa317537 100644 --- a/src/gmt_main.jl +++ b/src/gmt_main.jl @@ -145,7 +145,7 @@ function gmt(cmd::String, args...) # 2+ Add -F to psconvert if user requested a return image but did not give -F. # The problem is that we can't use nargout to decide what to do, so we use -T to solve the ambiguity. if (g_module == "psconvert" && (isempty(r) || !occursin("-F", r)) ) - if (isempty(r)) + if (r == "") r = "-F" else if (!occursin("-T", r)) @@ -1427,9 +1427,7 @@ function ps_init(API::Ptr{Nothing}, module_input, ps, dir::Integer) return P end - if (!isa(ps, GMTps)) - error("Expected a PS structure for input") - end + if (!isa(ps, GMTps)) error("Expected a PS structure for input") end # Passing dim[0] = 0 since we dont want any allocation of a PS string pdim = pointer([0]) @@ -1457,7 +1455,7 @@ function ps_init(API::Ptr{Nothing}, module_input, ps, dir::Integer) end -# --------------------------------------------------------------------------------------------------- +#= --------------------------------------------------------------------------------------------------- function convert_string(str) # Convert a string stored in one of those GMT.Array_XXX_Uint8 types into an ascii string k = 1 @@ -1467,7 +1465,7 @@ function convert_string(str) out = join([Char(str.(n)) for n=1:k]) end -#= --------------------------------------------------------------------------------------------------- +# --------------------------------------------------------------------------------------------------- function GMTJL_type(API::Ptr{Nothing}) # Set default export type value = " " # 8 spaces GMT_Get_Default(API, "GMT_EXPORT_TYPE", value) @@ -1508,7 +1506,7 @@ end # --------------------------------------------------------------------------------------------------- function strncmp(str1, str2, num) -# Pseudo strncmp + # Pseudo strncmp a = str1[1:min(num,length(str1))] == str2 end @@ -1533,10 +1531,8 @@ function mutateit(API::Ptr{Nothing}, t_type, member::String, val) ind = findfirst(isequal(Symbol(member)), fieldnames(dt)) # Find the index of the "is_continuous" member # This would work too # ind = ccall(:jl_field_index, Cint, (Any, Any, Cint), dt, symbol(member), 1) + 1 - if (isa(val, AbstractString)) # No idea why I have to do this - p_val = pointer(val) - else - p_val = pointer([val]) + if (isa(val, AbstractString)) p_val = pointer(val) # No idea why I have to do this + else p_val = pointer([val]) end GMT_blind_change_struct(API, p_type, p_val, @sprintf("%s",ft[ind]), fo[ind]) typeof(p_type); typeof(p_val) # Just to be sure that GC doesn't kill them before their due time @@ -1619,7 +1615,32 @@ end text_record(text) = text_record(Array{Float64,2}(undef,0,0), text) text_record(text::Array{String}, hdr::String) = text_record(Array{Float64,2}(undef,0,0), text, hdr) -## --------------------------------------------------------------------------------------------------- +# --------------------------------------------------------------------------------------------------- +function mat2ds(mat; hdr=nothing, color=nothing) + n_ds = size(mat, 2) - 1 + D = Array{GMTdataset, 1}(undef, n_ds) + if (color !== nothing) + n_colors = length(color) + if (hdr == nothing) + hdr = Array{String,1}(undef, n_ds) + for k = 1:n_ds + k != n_colors ? n = k % n_colors : n = n_colors + hdr[k] = " -W" * arg2str(color[n]) + end + else + for k = 1:n_ds + k != n_colors ? n = k % n_colors : n = n_colors + hdr[k] *= " -W" * arg2str(color[n]) + end + end + end + for k = 1:n_ds + D[k] = GMTdataset(mat[:,[1,k+1]], Array{String,1}(), (hdr === nothing ? "" : hdr[k]), Array{String,1}(), "", "") + end + return D +end + +# --------------------------------------------------------------------------------------------------- function mat2img(mat::Array{UInt8}, proj4::String="", wkt::String="") # Take a 2D array of uint8 and turn it into a GMTimage. NOT FINISHED YEY nx = size(mat, 2); ny = size(mat, 1); @@ -1628,7 +1649,6 @@ function mat2img(mat::Array{UInt8}, proj4::String="", wkt::String="") I = GMTimage(proj4, wkt, [1.0, nx, 1, ny, minimum(mat), maximum(mat)], [1.0, 1.0], 0, NaN, "", "", "", "", x,y,mat, "", "", "", colormap, 0, zeros(UInt8,ny,nx), "TRPa") end -## # --------------------------------------------------------------------------------------------------- """ @@ -1672,7 +1692,7 @@ end function Base.:+(G1::GMTgrid, G2::GMTgrid) # Add two grids, element by element. Inherit header parameters from G1 grid if (size(G1.z) != size(G2.z)) - error("The two grids have not the same size, so thay cannot be added.") + error("The two grids have not the same size, so they cannot be added.") end G3 = GMTgrid(G1.proj4, G1.wkt, G1.range, G1.inc, G1.registration, G1.nodata, G1.title, G1.remark, G1.command, G1.datatype, G1.x, G1.y, G1.z .+ G2.z, G1.x_unit, G1.y_unit, G1.z_unit, G1.layout) @@ -1685,7 +1705,7 @@ end function Base.:-(G1::GMTgrid, G2::GMTgrid) # Subtract two grids, element by element. Inherit header parameters from G1 grid if (size(G1.z) != size(G2.z)) - error("The two grids have not the same size, so thay cannot be subtracted.") + error("The two grids have not the same size, so they cannot be subtracted.") end G3 = GMTgrid(G1.proj4, G1.wkt, G1.range, G1.inc, G1.registration, G1.nodata, G1.title, G1.remark, G1.command, G1.datatype, G1.x, G1.y, G1.z .- G2.z, G1.x_unit, G1.y_unit, G1.z_unit, G1.layout) @@ -1698,7 +1718,7 @@ end function Base.:*(G1::GMTgrid, G2::GMTgrid) # Multiply two grids, element by element. Inherit header parameters from G1 grid if (size(G1.z) != size(G2.z)) - error("The two grids have not the same size, so thay cannot be multiplied.") + error("The two grids have not the same size, so they cannot be multiplied.") end G3 = GMTgrid(G1.proj4, G1.wkt, G1.range, G1.inc, G1.registration, G1.nodata, G1.title, G1.remark, G1.command, G1.datatype, G1.x, G1.y, G1.z .* G2.z, G1.x_unit, G1.y_unit, G1.z_unit, G1.layout) @@ -1711,7 +1731,7 @@ end function Base.:/(G1::GMTgrid, G2::GMTgrid) # Divide two grids, element by element. Inherit header parameters from G1 grid if (size(G1.z) != size(G2.z)) - error("The two grids have not the same size, so thay cannot be divided.") + error("The two grids have not the same size, so they cannot be divided.") end G3 = GMTgrid(G1.proj4, G1.wkt, G1.range, G1.inc, G1.registration, G1.nodata, G1.title, G1.remark, G1.command, G1.datatype, G1.x, G1.y, G1.z ./ G2.z, G1.x_unit, G1.y_unit, G1.z_unit, G1.layout) diff --git a/src/gmtinfo.jl b/src/gmtinfo.jl index 9df0596960..3b66dc2372 100644 --- a/src/gmtinfo.jl +++ b/src/gmtinfo.jl @@ -39,7 +39,7 @@ Parameters [`-L`](http://gmt.soest.hawaii.edu/doc/latest/gmtinfo.html#l) - **S** : **for_error_bars** : -- Str or [] -- - Add extra space for error bars. Useful together with I option and when later plotting with psxy E. + Add extra space for error bars. Useful together with I option and when later plotting with `plot E`. [`-S`](http://gmt.soest.hawaii.edu/doc/latest/gmtinfo.html#s) - **T** : **nearest_multiple** : -- Number or Str -- diff --git a/src/plot.jl b/src/plot.jl index 2bff6da799..81256cdc64 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -16,10 +16,7 @@ Parameters - $(GMT.opt_J) - $(GMT.opt_R) - $(GMT.opt_B) -- **C** : **color** : -- Str -- - - Give a CPT or specify -Ccolor1,color2[,color3,...] to build a linear continuous CPT from those colors automatically. - [`-C`](http://gmt.soest.hawaii.edu/doc/latest/psxy.html#c) +- $(GMT.opt_C) - **D** : **offset** : -- Str -- Offset the plot symbol or line locations by the given amounts dx/dy. @@ -68,17 +65,24 @@ Parameters + **s**, **square** + **t**, **^**, **triangle** + **x**, **cross** - + **y**, **y_dash** -- **W** : **line_attribs** : **markeredgecolor** : **MarkerEdgeColor** : -- Str -- + + **y**, **y_dash** + + and select their sizes with the **markersize** or **size** keyword [default is 7p]. + The marker size can be a scalar or a vector with same size numeber of rows of data. Units are + points unless specified otherwise with (for example for cm) *par=(PROJ_LENGTH_UNIT="c")* + +- **W** : **pen** : **markeredgecolor** : -- Str -- Set pen attributes for lines or the outline of symbols [`-W`](http://gmt.soest.hawaii.edu/doc/latest/psxy.html#w) WARNING: the pen attributes will set the pen of polygons OR symbols but not the two together. - If your plot has polygons and symbols, use **W** or **line_attribs** for the polygons and - **markeredgecolor** or **MarkerEdgeColor** for filling the symbols. Similar to S above. + If your plot has polygons and symbols, use **W** or **pen** for the polygons and + **markeredgecolor** for filling the symbols. Similar to S above. - $(GMT.opt_U) - $(GMT.opt_V) - $(GMT.opt_X) - $(GMT.opt_Y) +- **axis** : **aspect** : -- Str -- + When equal to "equal" makes a square plot. - $(GMT.opt_a) - $(GMT.opt_bi) - $(GMT.opt_di) @@ -89,23 +93,18 @@ Parameters - $(GMT.opt_i) - $(GMT.opt_p) - $(GMT.opt_t) +- $(GMT.opt_swap_xy) """ -plot(arg1; K=false, O=false, first=true, kw...) = psxy("", arg1; caller="plot", K=K, O=O, first=first, kw...) -plot!(arg1; K=true, O=true, first=false, kw...) = psxy("", arg1; caller="plot", K=K, O=O, first=first, kw...) +plot(arg1; kw...) = common_plot_xyz("", cat_1_arg(arg1), "plot", true, false, kw...) +plot!(arg1; kw...) = common_plot_xyz("", cat_1_arg(arg1), "plot", false, false, kw...) -plot(cmd0::String="", arg1=[]; K=false, O=false, first=true, kw...) = - psxy(cmd0, arg1; caller="plot", K=K, O=O, first=first, kw...) -plot!(cmd0::String="", arg1=[]; K=true, O=true, first=false, kw...) = - psxy(cmd0, arg1; caller="plot", K=K, O=O, first=first, kw...) +plot(cmd0::String="", arg1=[]; kw...) = common_plot_xyz(cmd0, arg1, "plot", true, false, kw...) +plot!(cmd0::String="", arg1=[]; kw...) = common_plot_xyz(cmd0, arg1, "plot", false, false, kw...) -# ------------------------------------------------------------------------------------------------------ -function plot(arg1::AbstractArray, arg2::AbstractArray; K=false, O=false, first=true, kw...) - arg = cat_2_arg2(arg1, arg2) # If they are vectors, cat them into a Mx2 matrix - psxy("", arg; caller="plot", K=K, O=O, first=first, kw...) -end -function plot!(arg1::AbstractArray, arg2::AbstractArray; K=false, O=false, first=true, kw...) - psxy("", cat_2_arg2(arg1, arg2); caller="plot", K=true, O=true, first=false, kw...) -end +plot(arg1, arg2; kw...) = common_plot_xyz("", cat_2_arg2(arg1, arg2), "plot", true, false, kw...) +plot!(arg1, arg2; kw...) = common_plot_xyz("", cat_2_arg2(arg1, arg2), "plot", false, false, kw...) +plot(arg1::Number, arg2::Number; kw...) = common_plot_xyz("", cat_2_arg2([arg1], [arg2]), "plot", true, false, kw...) +plot!(arg1::Number, arg2::Number; kw...) = common_plot_xyz("", cat_2_arg2([arg1], [arg2]), "plot", false, false, kw...) # ------------------------------------------------------------------------------------------------------ """ @@ -200,57 +199,23 @@ Parameters - $(GMT.opt_p) - $(GMT.opt_t) """ -plot3d(arg1; K=false, O=false, first=true, kw...) = - psxyz("", arg1; caller="plot3d", K=K, O=O, first=first, kw...) -plot3d!(arg1; K=false, O=false, first=true, kw...) = - psxyz("", arg1; caller="plot3d", K=true, O=true, first=false, kw...) +plot3d(arg1; kw...) = common_plot_xyz("", cat_1_arg(arg1), "plot3d", true, true, kw...) +plot3d!(arg1; kw...) = common_plot_xyz("", cat_1_arg(arg1), "plot3d", false, true, kw...) -# ------------------------------------------------------------------------------------------------------ -plot3d(cmd0::String; K=false, O=false, first=true, kw...) = - psxyz(cmd0; caller="plot3d", K=K, O=O, first=first, kw...) -plot3d!(cmd0::String; K=false, O=false, first=true, kw...) = - psxyz(cmd0; caller="plot3d", K=true, O=true, first=false, kw...) +plot3d(cmd0::String="", arg1=[]; kw...) = common_plot_xyz(cmd0, arg1, "plot3d", true, true, kw...) +plot3d!(cmd0::String="", arg1=[]; kw...) = common_plot_xyz(cmd0, arg1, "plot3d", false, true, kw...) # ------------------------------------------------------------------------------------------------------ -function plot3d(arg1::AbstractArray, arg2::AbstractArray, arg3::AbstractArray; K=false, O=false, first=true, kw...) +function plot3d(arg1::AbstractArray, arg2::AbstractArray, arg3::AbstractArray; kw...) arg = hcat(arg1[:], arg2[:], arg3[:]) - psxyz("", arg; caller="plot3d", K=K, O=O, first=first, kw...) + common_plot_xyz("", arg, "plot3d", true, true, kw...) end -function plot3d!(arg1::AbstractArray, arg2::AbstractArray, arg3::AbstractArray; K=false, O=false, first=true, kw...) +function plot3d!(arg1::AbstractArray, arg2::AbstractArray, arg3::AbstractArray; kw...) arg = hcat(arg1[:], arg2[:], arg3[:]) - psxyz("", arg; caller="plot3d", K=true, O=true, first=false, kw...) + common_plot_xyz("", arg, "plot3d", false, true, kw...) end # ------------------------------------------------------------------------------------------------------ - -# ------------------------------------------------------------------------------------------------------ -scatter(arg1; K=false, O=false, first=true, kw...) = scatter("", arg1; K=K, O=O, first=first, is3D=false, kw...) -scatter!(arg1; K=true, O=true, first=false, kw...) = scatter("", arg1; K=K, O=O, first=first, is3D=false, kw...) -scatter3(arg1; K=false, O=false, first=true, kw...) = scatter("", arg1; K=K, O=O, first=first, is3D=true, kw...) -scatter3!(arg1; K=true, O=true, first=false, kw...) = scatter("", arg1; K=K, O=O, first=first, is3D=true, kw...) - -function scatter(arg::AbstractArray; K=false, O=false, first=true, kw...) - arg = cat_1_arg(arg) # If ARG is a vector, prepend it with a 1:N x column - scatter("", arg; K=K, O=O, first=first, kw...) -end -scatter!(arg::AbstractArray; K=false, O=false, first=true, kw...) = scatter(arg; K=K, O=O, first=first, kw...) -function scatter(arg1::AbstractArray, arg2::AbstractArray; K=false, O=false, first=true, kw...) - arg = cat_2_arg2(arg1, arg2) # If they are vectors, cat them into a Mx2 matrix - scatter("", arg; K=K, O=O, first=first, is3D=false, kw...) -end -function scatter!(arg1::AbstractArray, arg2::AbstractArray; K=true, O=true, first=false, kw...) - arg = cat_2_arg2(arg1, arg2) # If they are vectors, cat them into a Mx2 matrix - scatter("", arg; K=K, O=O, first=first, is3D=false, kw...) -end -function scatter3(arg1::AbstractArray, arg2::AbstractArray, arg3::AbstractArray; K=false, O=false, first=true, kw...) - arg = hcat(arg1, arg2, arg3) - scatter("", arg; K=K, O=O, first=first, is3D=true, kw...) -end -function scatter3!(arg1::AbstractArray, arg2::AbstractArray, arg3::AbstractArray; K=true, O=true, first=false, kw...) - #arg = hcat(arg1, arg2, arg3) - scatter("", hcat(arg1, arg2, arg3); K=K, O=O, first=first, is3D=true, kw...) -end - """ scatter(cmd0::String="", arg1=[], kwargs...) @@ -305,42 +270,30 @@ Parameters [`Full man page`](https://genericmappingtools.github.io/GMT.jl/latest/scatter/) [`GMT man page`](http://gmt.soest.hawaii.edu/doc/latest/plot.html) """ -function scatter(cmd0::String="", arg1=[]; K=false, O=false, first=true, is3D=false, kwargs...) - if (is3D) GMT.common_plot_xyz(cmd0, arg1, "scatter3", K, O, first, is3D, kwargs...) - else GMT.common_plot_xyz(cmd0, arg1, "scatter", K, O, first, is3D, kwargs...) - end -end -# ------------------------------------------------------------------------------------------------------ +scatter(cmd0::String="", arg1=[]; kw...) = common_plot_xyz(cmd0, arg1, "scatter", true, false, kw...) +scatter!(cmd0::String="", arg1=[]; kw...) = common_plot_xyz(cmd0, arg1, "scatter", false, false, kw...) +scatter(arg; kw...) = common_plot_xyz("", cat_1_arg(arg), "scatter", true, false, kw...) +scatter!(arg; kw...) = common_plot_xyz("", cat_1_arg(arg), "scatter", false, false, kw...) -# ------------------------------------------------------------------------------------------------------ -function bar(arg1::NTuple; K=false, O=false, first=true, kw...) - bar(1:length(arg1), collect(arg1); K=K, O=O, first=first, kw...) -end -bar!(arg1::NTuple; K=true, O=true, first=false, kw...) = bar(arg1; K=K, O=O, first=first, kw...) - -function bar(arg1::NTuple, arg2::NTuple; K=false, O=false, first=true, kw...) - bar(collect(arg1), collect(arg2); K=K, O=O, first=first, kw...) -end -bar!(arg1::NTuple, arg2::NTuple; K=true, O=true, first=false, kw...) = - bar(arg1, arg2; K=K, O=O, first=first, kw...) +scatter(arg1, arg2; kw...) = common_plot_xyz("", cat_2_arg2(arg1, arg2), "scatter", true, false, kw...) +scatter!(arg1, arg2; kw...) = common_plot_xyz("", cat_2_arg2(arg1, arg2), "scatter", false, false, kw...) -function bar(arg1::AbstractArray, arg2::AbstractArray; K=false, O=false, first=true, kw...) - arg = cat_2_arg2(arg1, arg2) # If they are vectors, cat them into a Mx2 matrix - bar("", arg; K=K, O=O, first=first, kw...) +# ------------------------------------------------------------------------------------------------------ +scatter3(cmd0::String="", arg1=[]; kw...) = common_plot_xyz(cmd0, arg1, "scatter3", true, true, kw...) +scatter3!(cmd0::String="", arg1=[]; kw...) = common_plot_xyz(cmd0, arg1, "scatter3", false, true, kw...) +scatter3(arg; kw...) = common_plot_xyz("", cat_1_arg(arg), "scatte3", true, false, kw...) +scatter3!(arg; kw...) = common_plot_xyz("", cat_1_arg(arg), "scatte3", false, false, kw...) +function scatter3(arg1::AbstractArray, arg2::AbstractArray, arg3::AbstractArray; kw...) + common_plot_xyz("", hcat(arg1, arg2, arg3), "scatter3", true, true, kw...) end -bar!(arg1::AbstractArray, arg2::AbstractArray; K=true, O=true, first=false, kw...) = - bar(arg1, arg2; K=K, O=O, first=first, kw...) - -function bar(arg::AbstractArray; K=false, O=false, first=true, kw...) - arg = cat_1_arg(arg) # If ARG is a vector, prepend it with a 1:N x column - bar("", arg; K=K, O=O, first=first, kw...) +function scatter3!(arg1::AbstractArray, arg2::AbstractArray, arg3::AbstractArray; kw...) + common_plot_xyz("", hcat(arg1, arg2, arg3), "scatter3", false, true, kw...) end -bar!(arg::AbstractArray; K=true, O=true, first=false, kw...) = bar(arg; K=false, O=false, first=true, kw...) - # ------------------------------------------------------------------------------------------------------ + """ - bar(cmd0::String="", arg1=[], arg2=[], kwargs...) + bar(cmd0::String="", arg1=[], kwargs...) Reads a file or (x,y) pairs and plots vertical bars extending from base to y. @@ -363,12 +316,18 @@ Example: bar(sort(randn(10)), fill=:black, frame=:auto, show=true) """ -function bar(cmd0::String="", arg=[]; K=false, O=false, first=true, kwargs...) +function bar(cmd0::String="", arg=[]; first=true, kw...) if (cmd0 == "") arg = cat_1_arg(arg) end # If ARG is a vector, prepend it with a 1:N x column - GMT.common_plot_xyz(cmd0, arg, "bar", K, O, first, false, kwargs...) + GMT.common_plot_xyz(cmd0, arg, "bar", first, false, kw...) end +bar!(cmd0::String="", arg=[]; kw...) = bar(cmd0, arg; first=false, kw...) +bar(arg1, arg2; kw...) = common_plot_xyz("", cat_2_arg2(arg1, arg2), "bar", true, false, kw...) +bar!(arg1, arg2; kw...) = common_plot_xyz("", cat_2_arg2(arg1, arg2), "bar", false, false, kw...) +bar(arg; kw...) = common_plot_xyz("", cat_1_arg(arg), "bar", true, false, kw...) +bar!(arg; kw...) = common_plot_xyz("", cat_1_arg(arg), "bar", false, false, kw...) # ------------------------------------------------------------------------------------------------------ + """ bar3(cmd0::String="", arg1=[], kwargs...) @@ -391,7 +350,7 @@ Example: G = gmt("grdmath -R-15/15/-15/15 -I0.5 X Y HYPOT DUP 2 MUL PI MUL 8 DIV COS EXCH NEG 10 DIV EXP MUL ="); bar3(G, lw=:thinnest, show=true) """ -function bar3(cmd0::String="", arg=[]; K=false, O=false, first=true, kwargs...) +function bar3(cmd0::String="", arg=[]; first=true, kwargs...) # Contrary to "bar" this one has specific work to do here. d = KW(kwargs) opt_z = "" @@ -415,7 +374,7 @@ function bar3(cmd0::String="", arg=[]; K=false, O=false, first=true, kwargs...) elseif (haskey(d, :Nbands)) opt_z = string("+Z", d[:Nbands]) end end - opt, = parse_R("", d, O) + opt, = parse_R("", d, !first) if (opt == "") # OK, no R but we know it here so put it in 'd' if (arg1.registration == 1) # Fine, grid is already pixel reg push!(d, :R => arg1.range) @@ -453,15 +412,14 @@ function bar3(cmd0::String="", arg=[]; K=false, O=false, first=true, kwargs...) caller = "bar3|" * opt_S * opt_z - GMT.common_plot_xyz(cmd0, arg1, caller, K, O, first, true, d...) + common_plot_xyz(cmd0, arg1, caller, first, true, d...) end +bar3(arg1; kw...) = bar3("", arg1; first=true, kw...) +bar3!(cmd0::String="", arg1=[]; kw...) = bar3(cmd0, arg1; first=false, kw...) +bar3!(arg1; kw...) = bar3("", arg1; first=false, kw...) # ------------------------------------------------------------------------------------------------------ -bar3(arg1; K=false, O=false, first=true, kw...) = bar3("", arg1; K=K, O=O, first=first, kw...) -bar3!(cmd0::String="", arg1=[]; K=true, O=true, first=false, kw...) = bar3(cmd0, arg1; K=K, O=O, first=first, kw...) -bar3!(arg1; K=true, O=true, first=false, kw...) = bar3("", arg1; K=K, O=O, first=first, kw...) -# ------------------------------------------------------------------------------------------------------ """ arrows(cmd0::String="", arg1=[], arrow=(...), kwargs...) @@ -493,7 +451,7 @@ Example: arrows([0 8.2 0 6], limits=(-2,4,0,9), arrow=(len=2,stop=1,shape=0.5,fill=:red), J=14, frame=:a, pen="6p", show=true) """ -function arrows(cmd0::String="", arg1=[]; K=false, O=false, first=true, kwargs...) +function arrows(cmd0::String="", arg1=[]; first=true, kwargs...) # A arrows plotting method of plot d = KW(kwargs) @@ -502,7 +460,7 @@ function arrows(cmd0::String="", arg1=[]; K=false, O=false, first=true, kwargs.. else cmd = " -S" * cmd end - GMT.common_plot_xyz(cmd0, arg1, cmd, K, O, first, false, d...) + GMT.common_plot_xyz(cmd0, arg1, cmd, first, false, d...) end function helper_arrows(d::Dict, del::Bool=false) @@ -527,20 +485,15 @@ function helper_arrows(d::Dict, del::Bool=false) end return cmd end +arrows!(cmd0::String="", arg1=[]; kw...) = arrows(cmd0, arg1; first=false, kw...) +arrows(arg1; kw...) = arrows("", arg1; first=true, kw...) +arrows!(arg1; kw...) = arrows("", arg1; first=false, kw...) # ------------------------------------------------------------------------------------------------------ -# ------------------------------------------------------------------------------------------------------ -arrows(arg1; K=false, O=false, first=true, kw...) = arrows("", arg1; K=K, O=O, first=first, kw...) -arrows!(cmd0::String="", arg1=[]; K=true, O=true, first=false, kw...) = - arrows(cmd0, arg1; K=K, O=O, first=first, kw...) -arrows!(arg1; K=true, O=true, first=false, kw...) = arrows("", arg1; K=K, O=O, first=first, kw...) - - -# ------------------------------------------------------------------------------------------------------ """ lines(cmd0::String="", arg1=[], decorated=(...), kwargs...) -Reads a file or (x,y) pairs and plots a nice collection of different line with decorations +Reads a file or (x,y) pairs and plots a collection of different line with decorations - $(GMT.opt_B) - $(GMT.opt_J) @@ -555,9 +508,8 @@ Example: lines([0 0; 10 20], limits=(-2,12,-2,22), proj="M2.5", pen=1, fill=:red, decorated=(dist=(val=1,size=0.25), symbol=:box), show=true) """ -function lines(cmd0::String="", arg1=[]; K=false, O=false, first=true, kwargs...) +function lines(cmd0::String="", arg1=[]; first=true, kwargs...) # A lines plotting method of plot - d = KW(kwargs) cmd = "" if (haskey(d, :decorated)) @@ -568,60 +520,58 @@ function lines(cmd0::String="", arg1=[]; K=false, O=false, first=true, kwargs... end end - GMT.common_plot_xyz(cmd0, arg1, cmd, K, O, first, false, d...) + common_plot_xyz(cmd0, arg1, cmd, first, false, d...) end +lines!(cmd0::String="", arg=[]; kw...) = lines(cmd0, arg; first=false, kw...) +lines(arg1, arg2; kw...) = lines("", cat_2_arg2(arg1, arg2); first=true, kw...) +lines!(arg1, arg2; kw...) = lines("", cat_2_arg2(arg1, arg2); first=false, kw...) +lines(arg; kw...) = lines("", cat_1_arg(arg); first=true, kw...) +lines!(arg; kw...) = lines("", cat_1_arg(arg); first=false, kw...) # ------------------------------------------------------------------------------------------------------ -function lines(arg1::AbstractArray, arg2::AbstractArray; K=false, O=false, first=true, kw...) - arg = cat_2_arg2(arg1, arg2) # If they are vectors, cat them into a Mx2 matrix - lines("", arg; K=K, O=O, first=first, kw...) -end -function lines!(arg1::AbstractArray, arg2::AbstractArray; K=true, O=true, first=false, kw...) - arg = cat_2_arg2(arg1, arg2) # If they are vectors, cat them into a Mx2 matrix - lines("", arg; K=K, O=O, first=first, kw...) -end - -function lines(arg::AbstractArray; K=false, O=false, first=true, kw...) - arg = cat_1_arg(arg) # If ARG is a vector, prepend it with a 1:N x column - lines("", arg; K=K, O=O, first=first, kw...) -end -function lines!(arg; K=true, O=true, first=false, kw...) - #arg = cat_1_arg(arg) # If ARG is a vector, prepend it with a 1:N x column - lines("", cat_1_arg(arg); K=K, O=O, first=first, kw...) -end -lines!(cmd0::String="", arg=[]; K=true, O=true, first=false, kw...) = - lines(cmd0, arg; K=K, O=O, first=first, kw...) # ------------------------------------------------------------------------------------------------------ -function ternary(cmd0::String="", arg1=[]; first=true, kwargs...) +function ternary(cmd0::String="", arg1=[]; kwargs...) # A wrapper for psternary - GMT.common_plot_xyz(cmd0, arg1, "ternary", false, false, first, false, kwargs...) + common_plot_xyz(cmd0, arg1, "ternary", true, false, kwargs...) end -ternary!(cmd0::String="", arg1=[]; first=false, kw...) = ternary(cmd0, arg1; first=first, kw...) -ternary(arg1=[]; first=true, kw...) = ternary("", arg1; first=first, kw...) -ternary!(arg1=[]; first=false, kw...) = ternary("", arg1; first=first, kw...) +ternary!(cmd0::String="", arg1=[]; kw...) = ternary(cmd0, arg1; first=false, kw...) +ternary(arg1=[]; kw...) = ternary("", arg1; first=true, kw...) +ternary!(arg1=[]; kw...) = ternary("", arg1; first=false, kw...) const psternary = ternary # Aliases const psternary! = ternary! # Aliases # ------------------------------------------------------------------------------------------------------ function cat_1_arg(arg) - # When functions that expect matrices get only a vector, add a first col with 1:nx - if (!isa(arg, Array{GMT.GMTdataset,1}) && (isa(arg, Vector) || isa(arg, UnitRange) || isa(arg, StepRangeLen)) ) - arg = hcat(1:length(arg), arg) + # Add a first column with 1:n to all args that are not GMTdatasets + if (!isa(arg, Array{GMT.GMTdataset,1}) && !isa(arg, GMT.GMTdataset)) + if (isa(arg, Vector) || isa(arg, Matrix) || isa(arg, UnitRange) || isa(arg, StepRangeLen)) + if (!isa(arg, Matrix)) arg = hcat(1:length(arg), arg) + elseif ((isa(arg, Matrix) && size(arg,1) == 1)) arg = hcat(1:length(arg), arg') + else arg = hcat(1:size(arg,1), arg) + end + elseif (isa(arg, NTuple)) + arg = hcat(1:length(arg), collect(arg)) + end end return arg end # ------------------------------------------------------------------------------------------------------ function cat_2_arg2(arg1, arg2) - # Cat two vectors in a Mx2 matrix - if (!isa(arg1, Array{GMT.GMTdataset,1}) && !isa(arg2, Array{GMT.GMTdataset,1}) && - (isa(arg1, Vector) || isa(arg1, UnitRange) || isa(arg1, StepRangeLen)) && - (isa(arg2, Vector) || isa(arg2, UnitRange) || isa(arg2, StepRangeLen)) ) + # Cat two vectors (or tuples) or a vector (or tuple) and a matrix in a Mx2 matrix + + if ((isa(arg1, Vector) || isa(arg1, UnitRange) || isa(arg1, StepRangeLen) || isa(arg1, NTuple)) && + (isa(arg2, Vector) || isa(arg2, UnitRange) || isa(arg2, StepRangeLen) || isa(arg2, NTuple) || + isa(arg2, Matrix)) ) + + if (isa(arg1, NTuple)) arg1 = collect(arg1) end + if (isa(arg2, NTuple)) arg2 = collect(arg2) end arg = hcat(arg1, arg2) - else - @show(isa(arg1, Vector) || isa(arg1, UnitRange)) - error("The two array args must be vectors or ONE column (or row) matrices.") + elseif (!isa(arg1, Array{GMT.GMTdataset,1}) && !isa(arg1, GMT.GMTdataset) && + !isa(arg2, Array{GMT.GMTdataset,1}) && !isa(arg2, GMT.GMTdataset) ) + error(@sprintf("Unknown types (%s) and (%s) in cat_2_arg2() function", typeof(arg1), typeof(arg2))) end + end \ No newline at end of file diff --git a/src/psxy.jl b/src/psxy.jl index de61e965cc..515c657875 100644 --- a/src/psxy.jl +++ b/src/psxy.jl @@ -1,120 +1,10 @@ -""" - psxy(cmd0::String="", arg1=[]; kwargs...) - -reads (x,y) pairs and plot lines, polygons, or symbols at those locations on a map. - -Full option list at [`psxy`](http://gmt.soest.hawaii.edu/doc/latest/plot.html) - -Parameters ----------- - -- **A** : **straight_lines** : -- Str -- - - By default, geographic line segments are drawn as great circle arcs. To draw them as straight - lines, use the -A flag. - [`-A`](http://gmt.soest.hawaii.edu/doc/latest/plot.html#a) -- $(GMT.opt_J) -- $(GMT.opt_R) -- $(GMT.opt_B) -- $(GMT.opt_C) -- **D** : **shift** : **offset** : -- Str -- - - Offset the plot symbol or line locations by the given amounts dx/dy. - [`-D`](http://gmt.soest.hawaii.edu/doc/latest/plot.html#d) -- **E** : **error** : **error_bars** : -- Str -- - - Draw symmetrical error bars. - [`-E`](http://gmt.soest.hawaii.edu/doc/latest/plot.html#e) -- **F** : **conn** : **connection** : -- Str -- - - Alter the way points are connected - [`-F`](http://gmt.soest.hawaii.edu/doc/latest/plot.html#f) -- **G** : **fill** : **markerfacecolor** : -- Str -- - - Select color or pattern for filling of symbols or polygons. BUT WARN: the alias 'fill' will set the - color of polygons OR symbols but not the two together. If your plot has polygons and symbols, use - 'fill' for the polygons and 'markerfacecolor' for filling the symbols. Same applyies for W bellow - [`-G`](http://gmt.soest.hawaii.edu/doc/latest/plot.html#g) -- **I** : **intens** : -- Str or number -- - - Use the supplied intens value (in the [-1 1] range) to modulate the fill color by simulating - shading illumination. - [`-I`](http://gmt.soest.hawaii.edu/doc/latest/plot.html#i) -- **L** : **close** : -- Str -- - - Force closed polygons. - [`-L`](http://gmt.soest.hawaii.edu/doc/latest/plot.html#l) -- **N** : **noclip** : **no_clip** : -- Str or [] -- - - Do NOT clip symbols that fall outside map border - [`-N`](http://gmt.soest.hawaii.edu/doc/latest/plot.html#n) -- $(GMT.opt_P) -- **S** : **symbol** : -- Str -- - - Plot symbols (including vectors, pie slices, fronts, decorated or quoted lines). - [`-S`](http://gmt.soest.hawaii.edu/doc/latest/plot.html#s) - - Alternatively select a sub-set of symbols using the aliases: **marker** or **shape**and values: - - + **-**, **x_dash** - + **+**, **plus** - + **a**, *, **star** - + **c**, **circle** - + **d**, **diamond** - + **g**, **octagon** - + **h**, **hexagon** - + **i**, **v**, **inverted_tri** - + **n**, **pentagon** - + **p**, **.**, **point** - + **r**, **rectangle** - + **s**, **square** - + **t**, **^**, **triangle** - + **x**, **cross** - + **y**, **y_dash** - - and select their sizes with the **markersize** or **size** keyword [default is 7p]. - The marker size can be a scalar or a vector with same size numeber of rows of data. Units are - points unless specified otherwise with (for example for cm) *par=(PROJ_LENGTH_UNIT="c")* -- **W** : **pen** : **markeredgecolor** : -- Str -- - - Set pen attributes for lines or the outline of symbols - [`-W`](http://gmt.soest.hawaii.edu/doc/latest/plot.html#w) - WARNING: the pen attributes will set the pen of polygons OR symbols but not the two together. - If your plot has polygons and symbols, use **W** or **line_attribs** for the polygons and - **markeredgecolor** for outline of symbols. Similar to S above. -- $(GMT.opt_U) -- $(GMT.opt_V) -- $(GMT.opt_X) -- $(GMT.opt_Y) -- **axis** : **aspect** : -- Str -- - When equal to "equal" makes a square plot. -- $(GMT.opt_a) -- $(GMT.opt_bi) -- $(GMT.opt_di) -- $(GMT.opt_e) -- $(GMT.opt_f) -- $(GMT.opt_g) -- $(GMT.opt_h) -- $(GMT.opt_i) -- $(GMT.opt_p) -- $(GMT.opt_t) -- $(GMT.opt_swap_xy) -""" -function psxy(cmd0::String="", arg1=[]; caller="", K=false, O=false, first=true, kwargs...) - if (isempty(cmd0) && isa(arg1, AbstractArray) && length(arg1) != 2 && - (size(arg1,2) == 1 || size(arg1,1) == 1)) # y only - arg1 = hcat(1:length(arg1), arg1) - end - common_plot_xyz(cmd0, arg1, caller, K, O, first, false, kwargs...) -end - -# --------------------------------------------------------------------------------------------------- -function psxyz(cmd0::String="", arg1=[]; caller="", K=false, O=false, first=true, kwargs...) - common_plot_xyz(cmd0, arg1, caller, K, O, first, true, kwargs...) -end +const psxy = plot +const psxy! = plot! +const psxyz = plot3d +const psxyz! = plot3d! # --------------------------------------------------------------------------------------------------- -function common_plot_xyz(cmd0, arg1, caller, K, O, first, is3D, kwargs...) +function common_plot_xyz(cmd0, arg1, caller, first, is3D, kwargs...) arg2 = [] # May be needed if GMTcpt type is sent in via C N_args = isempty_(arg1) ? 0 : 1 @@ -124,14 +14,9 @@ function common_plot_xyz(cmd0, arg1, caller, K, O, first, is3D, kwargs...) else gmt_proggy = "psxy" end - ((isempty(cmd0) && isempty_(arg1)) || occursin(" -", cmd0)) && return monolitic(gmt_proggy, cmd0, arg1) + ((cmd0 == "" && isempty_(arg1)) || occursin(" -", cmd0)) && return monolitic(gmt_proggy, cmd0, arg1) - if (isa(arg1, Array{GMT.GMTdataset,1})) # Shitty consequence of arg1 being the output of a prev cmd - arg1 = arg1[1] - end - - cmd = "" - sub_module = "" # Will change to "scatter", etc... if called by sub-modules + cmd = ""; sub_module = "" # Will change to "scatter", etc... if called by sub-modules if (caller != "") if (occursin(" -", caller)) # some sub-modues use this piggy-backed call if ((ind = findfirst("|", caller)) !== nothing) # A mixed case with "caler|partiall_command" @@ -179,7 +64,7 @@ function common_plot_xyz(cmd0, arg1, caller, K, O, first, is3D, kwargs...) opt_UVXY = parse_UVXY("", d) # Need it separate to not risk to double include it. # If a file name sent in, read it and compute a tight -R if this was not provided - #if (opt_R == "" && sub_module == "bar") opt_R = "///0" end # Make sure y_min = 0 + if (opt_R == "" && sub_module == "bar") opt_R = "///0" end # Make sure y_min = 0 cmd, arg1, opt_R, opt_i = read_data(d, cmd0, cmd, arg1, opt_R, opt_i, opt_bi, opt_di, is3D) if (is3D && isempty(opt_JZ) && length(collect(eachmatch(r"/", opt_R))) == 5) @@ -259,7 +144,7 @@ function common_plot_xyz(cmd0, arg1, caller, K, O, first, is3D, kwargs...) else opt_ML = " -W" * arg2str(d[:markerline]) end - if (!isempty(opt_Wmarker)) + if (opt_Wmarker != "") opt_Wmarker = "" @warn("markerline overrides markeredgecolor") end @@ -306,7 +191,7 @@ function common_plot_xyz(cmd0, arg1, caller, K, O, first, is3D, kwargs...) cmd = [finish_PS(d, cmd * opt_UVXY, output, K, O)] end - put_in_legend_bag(d, cmd) + put_in_legend_bag(d, cmd, arg1) r = finish_PS_module(d, cmd, "", output, fname_ext, opt_T, K, gmt_proggy, arg1, arg2) if (got_pattern) gmt("destroy") end # Apparently patterns are screweing the session @@ -503,7 +388,7 @@ function parse_bar_cmd(d::Dict, key::Symbol, cmd::String, optS::String) end # --------------------------------------------------------------------------------------------------- -# --------------------------------------------------------------------------------------------------- +#= --------------------------------------------------------------------------------------------------- psxy(arg1; caller="", K=false, O=false, first=true, kw...) = psxy("", arg1; caller=caller, K=K, O=O, first=first, kw...) psxy!(arg1; caller="", K=true, O=true, first=false, kw...) = @@ -517,3 +402,4 @@ psxyz!(cmd0::String="", arg1=[]; caller="", K=true, O=true, first=false, kw...) psxyz(cmd0, arg1; caller=caller, K=K, O=O, first=first, kw...) psxyz!(arg1=[]; caller="", K=true, O=true, first=false, kw...) = psxyz("", arg1; caller=caller, K=K, O=O, first=first, kw...) +=# \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index d1bfc654db..c6a3aed3d4 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -98,9 +98,9 @@ if (got_it) # Otherwise go straight to end d=Dict(:L => (pen=(lw=10,lc=:red),) ); @test GMT.add_opt("", "", d, [:L], (pen=("+p",GMT.add_opt_pen),) ) == "+p10,red" r = psxy([0 0; 1 1.1], L=(pen=(10,:red),bot=true), Vd=:cmd); - @test r[1:48] == " -JX12c/8c -Baf -BWSen -R0/1/0/1.2 -L+p10,red+yb" + @test startswith(r," -JX12c/8c -Baf -BWSen -R1/2/0/1 -L+p10,red+yb") r = psxy([0 0; 1 1.1], L=(pen=(lw=10,cline=true),bot=true), Vd=:cmd); - @test r[1:47] == " -JX12c/8c -Baf -BWSen -R0/1/0/1.2 -L+p10+cl+yb" + @test startswith(r," -JX12c/8c -Baf -BWSen -R1/2/0/1 -L+p10+cl+yb") psxy!([0 0; 1 1.1], Vd=:cmd); psxy!("", [0 0; 1 1.1], Vd=:cmd); @@ -340,6 +340,7 @@ if (got_it) # Otherwise go straight to end # PLOT plot(collect(1:10),rand(10), lw=1, lc="blue", fmt=:ps, marker="circle", markeredgecolor=0, size=0.2, markerfacecolor="red", title="Bla Bla", x_label="Spoons", y_label="Forks", savefig="lixo") + plot(mat2ds(hcat(collect(1:6), GMT.fakedata(6,6)), color=[:red, :green, :blue, :yellow]), leg=true, label="Bla") plot("",hcat(collect(1:10)[:],rand(10,1))) plot!("",hcat(collect(1:10)[:],rand(10,1)), Vd=:cmd) plot(hcat(collect(1:10)[:],rand(10,1)), Vd=:cmd) @@ -348,8 +349,8 @@ if (got_it) # Otherwise go straight to end plot(1:10,rand(10), S=(symb=:c,size=7,unit=:point), color=:rainbow, zcolor=rand(10)) plot(1:10,rand(10)*3, S="c7p", color=:rainbow, Vd=:cmd) plot(1:10,rand(10)*3, S="c7p", color=:rainbow, zcolor=rand(10)*3) - plot3d(rand(5,5,3), marker=:cube) - plot3d!(rand(5,5,3), marker=:cube, Vd=:cmd) + plot3d(rand(5,3), marker=:cube) + plot3d!(rand(5,3), marker=:cube, Vd=:cmd) plot3d(1:10, rand(10), rand(10), Vd=:cmd) plot3d!(1:10, rand(10), rand(10), Vd=:cmd) @@ -377,7 +378,7 @@ if (got_it) # Otherwise go straight to end # SCATTER sizevec = [s for s = 1:10] ./ 10; scatter(1:10, 1:10, markersize = sizevec, axis=:equal, B=:a, marker=:square, fill=:green) - scatter(rand(10), leg=:bottomrigh, fill=:red) # leg wong on purpose + scatter(rand(10), leg=:bottomrigh, fill=:red) # leg wrong on purpose scatter(1:10,rand(10)*3, S="c7p", color=:rainbow, zcolor=rand(10)*3, show=1, Vd=:cmd) scatter(rand(50),rand(50), markersize=rand(50), zcolor=rand(50), aspect=:equal, alpha=50, Vd=:cmd) scatter(1:10, rand(10), fill=:red, B=:a) @@ -572,8 +573,16 @@ if (got_it) # Otherwise go straight to end G3 = G1 - G2; G3 = G1 * G2; G3 = G1 / G2; + G2 = GMT.mat2grid(rand(Float32,5,5)) + @test_throws ErrorException("The two grids have not the same size, so they cannot be added.") G1 + G2; + @test_throws ErrorException("The two grids have not the same size, so they cannot be subtracted.") G1 - G2; + @test_throws ErrorException("The two grids have not the same size, so they cannot be multiplied.") G1 * G2; + @test_throws ErrorException("The two grids have not the same size, so they cannot be divided.") G1 / G2; + GMT.get_datatype([]); GMT.get_datatype(Float32(8)); + GMT.get_datatype(UInt64(8)); + GMT.get_datatype(Int64(8)); GMT.get_datatype(UInt32(8)); GMT.get_datatype(Int32(8)); GMT.get_datatype(UInt16(8));