Skip to content

Commit

Permalink
Merge c355a0f into f614d70
Browse files Browse the repository at this point in the history
  • Loading branch information
joa-quim committed Dec 25, 2018
2 parents f614d70 + c355a0f commit f0db4a1
Show file tree
Hide file tree
Showing 9 changed files with 237 additions and 351 deletions.
6 changes: 3 additions & 3 deletions src/GMT.jl
Expand Up @@ -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,
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand Down
21 changes: 6 additions & 15 deletions src/blocks.jl
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand All @@ -98,29 +95,23 @@ 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
if (GMTver < 6 && occursin("-A", cmd))
@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
Expand Down
16 changes: 8 additions & 8 deletions src/common_docs.jl
Expand Up @@ -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 --
Expand Down Expand Up @@ -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)"
Expand All @@ -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)"
Expand Down
82 changes: 56 additions & 26 deletions src/common_options.jl
Expand Up @@ -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

# ---------------------------------------------------------------------------------------------------
Expand All @@ -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

# ---------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

# --------------------------------------------------------------------------------------------------
Expand All @@ -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],
Expand All @@ -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
Expand Down

0 comments on commit f0db4a1

Please sign in to comment.