Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/GMT.jl
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,7 @@ using .Laszip
@compile_workload begin
G_API[] = GMT_Create_Session("GMT", 2, GMT_SESSION_BITFLAGS)
#GMT.parse_B(Dict{Symbol, Any}(:frame => (annot=10, title="Ai Ai"), :grid => (pen=2, x=10, y=20)), "", " -Baf -BWSen");
#GMT.parse_R(Dict{Symbol, Any}(:xlim => (1,2), :ylim => (3,4), :zlim => (5,6)), "");
#GMT.parse_J(Dict{Symbol, Any}(:J => "X", :scale => "1:10"), "");
#GMT.parse_opt_S(Dict{String, Any}(), mat2ds(rand(4,2)));
#GMT.build_opt_J(:X5);
GMT.theme("dark")
GMT.theme_modern()
mat2ds([9 8; 9 8], x=[0 7], pen=["5p,black", "4p,white,20p_20p"], multi=true)
Expand All @@ -389,6 +386,7 @@ using .Laszip
gmtwrite(t, [0.0 0; 1 1])
gmtread(t)
gmtread(TESTSDIR * "assets/burro_cenora.jpg")
coast(R=:g, proj=:guess, W=(level=1, pen=(2, :green)), savefig=tempname()*".ps")
rm(t)
D = mat2ds(rand(3, 3), colnames=["Time", "b", "c"])
D.attrib = Dict("Timecol" => "1")
Expand All @@ -413,7 +411,6 @@ using .Laszip
grdsample(Glix, inc=0.5)
grdtrend(Glix, model=3)
grdtrack(Glix, [1 1])
coast(R=:g, proj=:guess, W=(level=1, pen=(2, :green)), savefig=tempname()*".ps")
rescale(mat2img(rand(UInt16, 16,16,3)))
plot(rand(5, 2))
bar(1:5, (20, 35, 30, 35, 27), width=0.5, color=:lightblue, limits=(0.5,5.5,0,40))
Expand All @@ -426,13 +423,13 @@ using .Laszip
#ecdfplot!(randn(50), fmt=:ps);
#cornerplot(randn(50,3), scatter=true, fmt=:ps);
#marginalhist(randn(1000,2), par=(PS_MEDIA="A2",), fmt=:ps); rm("GMTplot.ps")
#feather([0.0 0 2.0; 0.0 30 2; 0.0 60 2], rtheta=true, aspect="1:1", arrow=(len=0.5, shape=0.5,), fmt=:ps);
feather([0.0 0 2.0; 0.0 30 2; 0.0 60 2], rtheta=true, aspect="1:1", arrow=(len=0.5, shape=0.5,), fmt=:ps);
#orbits(mat2ds(rand(10,3)));
#pca(rand(Float32, 24, 4));
#pca(mat2img(rand(UInt8, 64,64,4)));
#kmeans(rand(100,3), 3, maxiter=10);
#rm(joinpath(tempdir(), "GMTjl_custom_p_x.txt")) # This one gets created before username is set.
#arrows([0 8.2 0 6], limits=(-2,4,0,9), arrow=(len=2,stop=1,shape=0.5,fill=:red), axis=:a, pen="6p");
arrows([0 8.2 0 6], limits=(-2,4,0,9), arrow=(len=2,stop=1,shape=0.5,fill=:red), axis=:a, pen="6p");
GMT.doc_source_links("psbasemap"; silent=true)
theme()

Expand Down
5 changes: 3 additions & 2 deletions src/gmt2kml.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ gmt2kml(arg1; kw...) = gmt2kml_helper("", arg1; kw...)
# ---------------------------------------------------------------------------------------------------
function gmt2kml_helper(cmd0::String, arg1; kw...)
d = init_module(false, kw...)[1]
gmt2kml_helper(cmd0, arg1, d)
gmt2kml_helper(wrapDatasets(cmd0, arg1), d)
end
function gmt2kml_helper(cmd0::String, arg1, d::Dict{Symbol, Any})
function gmt2kml_helper(w::wrapDatasets, d::Dict{Symbol, Any})
cmd0, arg1 = unwrapDatasets(w::wrapDatasets)

cmd, = parse_common_opts(d, "", [:R :V_params :bi :di :e :f :h :i :yx])
cmd = parse_these_opts(cmd, d, [[:A :altitude_mode], [:D :descript], [:E :extrude], [:F :feature_type], [:G :fill],
Expand Down
24 changes: 24 additions & 0 deletions src/gmt_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,30 @@ function Base.similar(bc::Broadcast.Broadcasted{Broadcast.ArrayStyle{GMTfv}}, ::
end
find4similar(FV::GMTfv, rest) = FV

# ------------------------------------------------------------------------------------
mutable struct wrapDatasets#{T<:Real, N} <: AbstractArray{T,N}
fname::String
ds::GMTdataset#{T,N}
vds::Vector{GMTdataset}
fv::GMTfv#{T}
cpt::GMTcpt
function wrapDatasets(arg1, arg2)
td, tvd, tcpt, tfv = GMTdataset(), Vector{GMTdataset}(), GMTcpt(), GMTfv()
if (arg1 !== "") new(arg1, td, tvd, tfv, tcpt)
elseif (isa(arg2, Matrix{<:Real})) new("", mat2ds(arg2), tvd, tfv, tcpt)
elseif (isa(arg2, GMTdataset)) new("", arg2, tvd, tfv, tcpt)
elseif (isa(arg2, Vector{<:GMTdataset})) new("", td, arg2, tfv, tcpt)
elseif (isa(arg2, GMTfv)) new("", td, tvd, arg2, tcpt)
elseif (isa(arg2, GMTcpt)) new("", td, tvd, tfv, arg2)
elseif (arg1 === "" && arg2 === nothing) new("", td, tvd, tfv, tcpt) # Less usual case in plot where inly kwargs are given
else error("Unknown types ($(typeof(arg1)), $(typeof(arg2))) in wrapDatasets")
end
end
end
function unwrapDatasets(w::wrapDatasets)
return w.fname, !isempty(w.ds) ? w.ds : !isempty(w.vds) ? w.vds : !isempty(w.fv) ? w.fv : !isempty(w.cpt) ? w.cpt : nothing
end

#=
Base.@kwdef struct GMTtypes
stored::String = ""
Expand Down
8 changes: 4 additions & 4 deletions src/gmtconvert.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ gmtconvert(arg1; kwargs...) = gmtconvert_helper("", arg1; kwargs...)

function gmtconvert_helper(cmd0::String, arg1; kwargs...)
d = init_module(false, kwargs...)[1] # Also checks if the user wants ONLY the HELP mode
gmtconvert_helper(cmd0, arg1, d)
gmtconvert_helper(wrapDatasets(cmd0, arg1), d)
end
# ---------------------------------------------------------------------------------------------------
function gmtconvert_helper(cmd0::String, arg1, d::Dict{Symbol,Any})
function gmtconvert_helper(w::wrapDatasets, d::Dict{Symbol,Any})
cmd0, arg1 = unwrapDatasets(w::wrapDatasets)

cmd, = parse_common_opts(d, "", [:V_params :append :a :b :bo :d :e :g :h :i :o :q :s :w :yx])
cmd, opt_f = parse_f(d, cmd) # Must have easier acces to opt_f
cmd, opt_f = parse_f(d, cmd) # Must have easier acces to opt_f

# GMT is not able to return a converted time table, so we create a temporary file if time conversions are involved
used_tmp_file = false
Expand All @@ -80,7 +81,6 @@ function gmtconvert_helper(cmd0::String, arg1, d::Dict{Symbol,Any})
cmd = parse_these_opts(cmd, d, [[:A :hcat], [:C :n_records], [:D :dump], [:E :first_last], [:F :conn_method],
[:I :invert :reverse], [:L :list_only], [:N :sort], [:Q :segments], [:S :select_hdr], [:T :suppress :skip], [:W :word2num], [:Z :transpose]])


out = common_grd(d, cmd0, cmd, "gmtconvert ", arg1) # Finish build cmd and run it
if (used_tmp_file) # Read the conversion results and clean up temporary file.
out = gmtread(fname)
Expand Down
26 changes: 24 additions & 2 deletions src/gmtinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ end
# ---------------------------------------------------------------------------------------------------
function gmtinfo_helper(cmd0::String, arg1, d::Dict{Symbol,Any})::Union{String, GMTdataset}

#=
#cmd, = parse_common_opts(d, "", [:V_params :e :f :i :o :r :w :yx])
cmd = parse_V_params(d, "")
cmd = parse_e(d, cmd)[1]
Expand All @@ -67,10 +68,31 @@ function gmtinfo_helper(cmd0::String, arg1, d::Dict{Symbol,Any})::Union{String,
cmd = add_opt(d, cmd, "I", [:I :inc :increment :spacing],
(exact=("e", nothing, 1), polyg=("b", nothing, 1), surface=("s", nothing, 1), fft=("d", nothing, 1), inc=("", arg2str, 2)); del=false, expand=true)
cmd = add_opt(d, cmd, "T", [:T :nearest_multiple], (dz="", col="+c", column="+c"))
=#

# If file name sent in, read it.
if (cmd0 != "") cmd, arg1, = read_data(d, cmd0, cmd, arg1, " ") end
cmd = gmtinfo_helper_helper(d) # Parse only options that do not depend on the (fcking Any) 'arg1'

if (cmd0 != "") cmd = cmd * " " * cmd0
elseif (eltype(arg1) == String) cmd = cmd * " " * join(arg1, ' '); arg1 = nothing # Accept also tuples/vecs of file names
end
cmd = "gmtinfo " * cmd
if (dbg_print_cmd(d, cmd) !== nothing) return cmd end
isa(arg1, Tuple) ? gmt(cmd, arg1...) : gmt(cmd, arg1)
end

function gmtinfo_helper_helper(d::Dict{Symbol,Any})::String
cmd = parse_V_params(d, "")
cmd = parse_e(d, cmd)[1]
cmd = parse_f(d, cmd)[1]
cmd = parse_i(d, cmd)[1]
cmd = parse_o(d, cmd)[1]
cmd = parse_r(d, cmd)[1]
cmd = parse_w(d, cmd)[1]
cmd = parse_swap_xy(d, cmd)[1]
(endswith(cmd, "-:")) && (cmd *= "i") # Need to be -:i not -: to not swap output too
cmd = parse_these_opts(cmd, d, [[:A :ranges], [:C :numeric :per_column], [:D :center], [:E :get_record], [:F :counts],
[:L :common_limits], [:S :for_error_bars]])
cmd = add_opt(d, cmd, "I", [:I :inc :increment :spacing],
(exact=("e", nothing, 1), polyg=("b", nothing, 1), surface=("s", nothing, 1), fft=("d", nothing, 1), inc=("", arg2str, 2)); del=false, expand=true)
add_opt(d, cmd, "T", [:T :nearest_multiple], (dz="", col="+c", column="+c"))
end
4 changes: 2 additions & 2 deletions src/psscale.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ To see the full documentation type: ``@? colorbar``
"""
function colorbar(arg1::Union{Nothing, GMTcpt}=nothing; first=true, kwargs...)
d, K, O = init_module(first==1, kwargs...) # Also checks if the user wants ONLY the HELP mode
dbg_cmd, d, cmd, arg1 = colorbar_parser(arg1, O, d)
dbg_cmd, d, cmd, arg1 = colorbar_parser(isa(arg1, Nothing) ? GMTcpt() : arg1, O, d)
(dbg_cmd !== nothing) && return dbg_cmd
r = prep_and_call_finish_PS_module(d, cmd, "", K, O, true, arg1)
(!isa(r,String)) && gmt("destroy") # Probably because of the rasters in cpt
Expand All @@ -73,7 +73,7 @@ function colorbar_parser(arg1::Union{Nothing, GMTcpt}, O::Bool, d::Dict{Symbol,

(!isempty(opt_D)) && (!contains(opt_D, "DJ") && !contains(opt_D, "Dj") && !contains(opt_D, "Dg")) && (cmd = replace(cmd, "-R " => ""))
cmd *= opt_D
cmd, arg1, = add_opt_cpt(d, cmd, CPTaliases, 'C', 0, arg1)
cmd, arg1, = add_opt_cpt(d, cmd, CPTaliases, 'C', 0, isempty(arg1) ? nothing : arg1)
if (opt_D === "" && ((val = hlp_desnany_str(d, [:triangles])) !== "")) # User asked for triangles but did not set pos
(val == "true") && (val = "tri") # Means just triangles
anc_tris = colorbar_triangles(val) # Returns anchor+triangles string
Expand Down
10 changes: 4 additions & 6 deletions src/psxy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ function common_plot_xyz(cmd0::String, arg1, caller::String, first::Bool, is3D::
d, K, O = init_module(first, kwargs...) # Also checks if the user wants ONLY the HELP mode
(cmd0 != "" && arg1 === nothing && is_in_dict(d, [:groupvar :hue]) !== nothing) && (arg1 = gmtread(cmd0); cmd0 = "")
_common_plot_xyz(cmd0, arg1, caller, O, K, is3D, d)
#invokelatest(_common_plot_xyz, cmd0, arg1, caller, O, K, is3D, d)
end
function common_plot_xyz(cmd0::String, arg1, caller::String, first::Bool, is3D::Bool, d::Dict{Symbol, Any})
(cmd0 != "" && arg1 === nothing && is_in_dict(d, [:groupvar :hue]) !== nothing) && (arg1 = gmtread(cmd0); cmd0 = "")
_common_plot_xyz(cmd0, arg1, caller, !first, true, is3D, d)
#invokelatest(_common_plot_xyz, cmd0, arg1, caller, !first, true, is3D, d)
end
function _common_plot_xyz(cmd0::String, arg1, caller::String, O::Bool, K::Bool, is3D::Bool, d::Dict{Symbol, Any})
first = !O
Expand Down Expand Up @@ -411,8 +409,8 @@ function parse_plot_callers(d::Dict{Symbol, Any}, gmt_proggy::String, caller::St
end

# ---------------------------------------------------------------------------------------------------
plt_txt_attrib!(D::GMTdataset{T,N}, d::Dict{Symbol, Any}, _cmd::Vector{String}) where {T,N} = plt_txt_attrib!([D], d, _cmd)
function plt_txt_attrib!(D::Vector{<:GMTdataset{T,N}}, d::Dict{Symbol, Any}, _cmd::Vector{String}) where {T,N}
plt_txt_attrib!(D::GMTdataset, d::Dict{Symbol, Any}, _cmd::Vector{String}) = plt_txt_attrib!([D], d, _cmd)
function plt_txt_attrib!(D::Vector{<:GMTdataset}, d::Dict{Symbol, Any}, _cmd::Vector{String})
# Plot TEXT attributed labels and serve as function barrier agains the f Any's (not sure if succeeds)
((s_val = hlp_desnany_str(d, [:labels])) === "") && return nothing

Expand Down Expand Up @@ -561,7 +559,7 @@ function check_grouping!(d, arg1)
end

# ---------------------------------------------------------------------------------------------------
function check_ribbon(d::Dict{Symbol, Any}, arg1::GMTdataset{T,N}, cmd::String, opt_W::String) where {T,N}
function check_ribbon(d::Dict{Symbol, Any}, arg1::GMTdataset, cmd::String, opt_W::String)
((val = find_in_dict(d, [:ribbon :band])[1]) === nothing) && return arg1, cmd
ec1, ec2, add_2 = helper_check_ribbon(val) # Function barrier agains Anys
(add_2) ? add2ds!(arg1, ec2; names=["Zbnd1","Zbnd2"]) : add2ds!(arg1, ec1; name="Zbnd")
Expand All @@ -570,7 +568,7 @@ function check_ribbon(d::Dict{Symbol, Any}, arg1::GMTdataset{T,N}, cmd::String,
return arg1, cmd
end

function check_ribbon(d::Dict{Symbol, Any}, arg1::Vector{<:GMTdataset{T,N}}, cmd::String, opt_W::String) where {T,N}
function check_ribbon(d::Dict{Symbol, Any}, arg1::Vector{<:GMTdataset}, cmd::String, opt_W::String)
((val = find_in_dict(d, [:ribbon :band])[1]) === nothing) && return arg1, cmd
ec1, ec2, add_2 = helper_check_ribbon(val) # Function barrier agains Anys
if (add_2)
Expand Down
7 changes: 4 additions & 3 deletions src/sample1d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,14 @@ function sample1d_helper(cmd0::String, arg1; kwargs...)
d = init_module(false, kwargs...)[1] # Also checks if the user wants ONLY the HELP mode
isa(arg1, Matrix{<:Real}) && (arg1 = mat2ds(Float64.(arg1))) # One less type to deal with
fill_nans = is_in_kwargs(d, [:fill_nans :interp_nans])
(cmd0 != "") && fill_nans && (arg1 = gmtread(cmd0))
(cmd0 != "") && fill_nans && (arg1 = gmtread(cmd0); cmd0 = "")
fill_nans && isa(arg1, Vector) && (@warn "Filling NaNs only works with GMTdatasets. For vectors you must run one by one"; return nothing)
sample1d_helper(cmd0, arg1, d)
sample1d_helper(wrapDatasets(cmd0, arg1), d)
end

# ---------------------------------------------------------------------------------------------------
function sample1d_helper(cmd0::String, arg1, d::Dict{Symbol,Any})
function sample1d_helper(w::wrapDatasets, d::Dict{Symbol,Any})
cmd0, arg1 = unwrapDatasets(w::wrapDatasets)

cmd = parse_common_opts(d, "", [:V_params :b :d :e :f :h :i :o :s :w :yx])[1]
_, opt_g = parse_g(d, "")
Expand Down
Loading