From c65a7fed71a881d3e06dfe4a3a8da312e20c905d Mon Sep 17 00:00:00 2001 From: Joaquim Date: Tue, 30 Sep 2025 23:28:45 +0100 Subject: [PATCH 1/2] Move the makecpt_raw from makecpt.jl to common_options.jl Do this so makecpt can be accessed from a future GMTcore package. --- src/common_options.jl | 14 +++++++++++++- src/makecpt.jl | 15 ++++----------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/common_options.jl b/src/common_options.jl index 7892a7b4c..88cb9c1b3 100644 --- a/src/common_options.jl +++ b/src/common_options.jl @@ -2802,6 +2802,18 @@ function get_cpt_set_R(d::Dict, cmd0::String, cmd::String, opt_R::String, got_fn return cmd, N_used, arg1, arg2, arg3 end +# This function is a mini makecpt. Put it here so that we can call it from a future GMTcore module that will split from "modules" +function makecpt_raw(cmd::String, arg1=nothing)::GMTcpt + # Raw version that already knows what the command is and has no input data. + (IamModern[1] && !contains(cmd, " -H")) && (cmd *= " -H") + !startswith(cmd, "makecpt ") && (cmd = "makecpt " * cmd) + _r = gmt_GMTcpt(cmd, arg1) + r::GMTcpt = (_r !== nothing) ? _r : GMTcpt() # _r === nothing when we save CPT on disk. + (contains(cmd, " -N") && !isempty(r)) && (r.bfn = ones(3,3)) # Cannot remove the bfn like in plain GMT so make it all whites + CURRENT_CPT[1] = r + return r +end + #= function get_colorbar_pos(anchor) hack_modern_session(GMT.CTRL.pocket_R[1], GMT.CTRL.pocket_J[1] * GMT.CTRL.pocket_J[3], " -Baf -Bza", fullremove=true) # Start a modern session @@ -4191,7 +4203,7 @@ function showfig(d::Dict{Symbol, Any}, fname_ps::String, fname_ext::String, opt_ if (haskey(d, :show) && d[:show] != 0) if ((isdefined(Main, :IJulia) && Main.IJulia.inited) || (isdefined(Main, :VSCodeServer) && get(ENV, "DISPLAY_IN_VSC", "") != "no")) #https://stackoverflow.com/questions/70620607/how-can-i-programmatically-check-that-i-am-running-code-in-a-notebook-in-julia - (fname == "") ? display(MIME"image/png"(), read(out)) : @warn("In Jupyter you can only visualize png files. File $fname was saved in disk though.") + (fname == "" || endswith(fname, ".png")) ? display(MIME"image/png"(), read(out)) : @warn("In Jupyter you can only visualize png files. File $fname was saved in disk though.") elseif (isPluto) retPluto = true elseif (!isFranklin[1]) # !isFranklin is true when building the docs and there we don't want displays. diff --git a/src/makecpt.jl b/src/makecpt.jl index 3abba7cc8..5c0902c16 100644 --- a/src/makecpt.jl +++ b/src/makecpt.jl @@ -9,7 +9,10 @@ Make static color palette tables (CPTs). The second form accepts a name of one o - **A** | **alpha** | **transparency** :: [Type => Str] Sets a constant level of transparency (0-100) for all color slices. -- $(opt_C) +- **C** | **color** | **colormap** | **cmap** | **colorscale** :: [Type => Str] + + Give a CPT name or specify -Ccolor1,color2[,color3,...] to build a linear continuous CPT from those + colors automatically. - **D** | **bg** | **background** :: [Type => Str | []] `Arg = [i|o]` Select the back- and foreground colors to match the colors for lowest and highest @@ -85,16 +88,6 @@ function makecpt(cmd0::String, arg1, d::Dict)::Union{String, GMTcpt} return r end -function makecpt_raw(cmd::String, arg1=nothing)::GMTcpt - # Raw version that already knows what the command is and has no input data. - (IamModern[1] && !contains(cmd, " -H")) && (cmd *= " -H") - !startswith(cmd, "makecpt ") && (cmd = "makecpt " * cmd) - _r = gmt_GMTcpt(cmd, arg1) - r::GMTcpt = (_r !== nothing) ? _r : GMTcpt() # _r === nothing when we save CPT on disk. - (contains(cmd, " -N") && !isempty(r)) && (r.bfn = ones(3,3)) # Cannot remove the bfn like in plain GMT so make it all whites - CURRENT_CPT[1] = r - return r -end function makecpt(G::GMTgrid; equalize=false, kw...) # A version that works on grids. # equalize = true uses default grd2cpt. equalize=n uses grd2cpt -Tn From 65e2facd664f53bd234a78633288f850bac55dbb Mon Sep 17 00:00:00 2001 From: Joaquim Date: Tue, 30 Sep 2025 23:29:54 +0100 Subject: [PATCH 2/2] Fix things in stereonet. (savefig and show were not working correctly) --- src/GMT.jl | 2 +- src/plot.jl | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/GMT.jl b/src/GMT.jl index 4e2429828..bd6dd79ce 100644 --- a/src/GMT.jl +++ b/src/GMT.jl @@ -375,7 +375,7 @@ using GMT.Laszip #include("ImageFeatures/ImageFeatures.jl") #using GMT.ImageFeatures -@compile_workload let +@compile_workload begin G_API[1] = 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)), ""); diff --git a/src/plot.jl b/src/plot.jl index bb061ff2b..60b86299a 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -493,8 +493,8 @@ function bar(f::Function, range_x=nothing; first=true, kw...) end bar!(f::Function, rang=nothing; kw...) = bar(f, rang; first=false, kw...) -bar(arg1, arg2; first=true, kw...) = common_plot_xyz("", cat_2_arg2(arg1, arg2, true), "bar", first, false; kw...) -bar!(arg1, arg2; kw...) = common_plot_xyz("", cat_2_arg2(arg1, arg2, true), "bar", false, false; kw...) +bar(arg1, arg2; first=true, kw...) = common_plot_xyz("", cat_2_arg2(arg1, Float64.(arg2), true), "bar", first, false; kw...) +bar!(arg1, arg2; kw...) = common_plot_xyz("", cat_2_arg2(arg1, Float64.(arg2), true), "bar", false, false; kw...) bar(arg; kw...) = bar("", arg; kw...) bar!(arg; kw...) = common_plot_xyz("", cat_1_arg(arg, true), "bar", false, false; kw...) # ------------------------------------------------------------------------------------------------------ @@ -2251,38 +2251,44 @@ Plot a stereonet map in either Schmidt or Wulff projection. and line & marker settings (see ``plots`` manual for details on them). In case the produced figure is still not satisfactory, you can make one by yourself. -For that use the `Dv, Dp = _stereonet(mat)` function to get the fault planes and poles. A good place +For that use the `Dv, Dp = stereonet_data(mat)` function to get the fault planes and poles. A good place to start is the `stereonet` function itself. Type ``@edit GMT.stereonet([0 0])`` to see the code. ### Example ```julia -stereonet([90 30; 180 45; 270 60; 0 15; 30 45; 120 48; 225 27; 350 80]) +stereonet([90 30; 180 45; 270 60; 0 15; 30 45; 120 48; 225 27; 350 80], show=true) ``` """ function stereonet(mat::AbstractArray{T,2}; first=true, schmidt=true, wulff=false, kw...) where T<:Real d = KW(kw) - show = (find_in_dict(d, [:show])[1] !== nothing) ? false : true # DEfault is 'true'. + _stereonet(mat, first, schmidt, wulff, d) +end +function _stereonet(mat::AbstractArray{T,2}, first::Bool, schmidt::Bool, wulff::Bool, d) where T<:Real + show = ((val = find_in_dict(d, [:show])[1]) !== nothing && val != 0) + savefig = find_in_dict(d, [:savefig :figname :name])[1]; + Vd = get(d, :Vd, 0) wulff && (schmidt = false) # Wulff stereonet - Dv, Dp = _stereonet(mat) + Dv, Dp = stereonet_data(mat) prj = schmidt ? :laea : (name=:stereo, center=[0,0])# "S0/0/15c" (is_in_dict(d, [:lc :linecolor]) === nothing) && (d[:lc] = "red") (is_in_dict(d, [:lt :linethickness]) === nothing) && (d[:lt] = 0.5) d[:par] = (MAP_GRID_PEN_PRIMARY="0.25,gray", MAP_GRID_PEN_SECONDARY="0.25,black") d[:B], d[:R], d[:J] = "pg5 sg20", :d, prj common_plot_xyz("", Dv, "plot", first, false, d) # Plot the fault planes + (Vd != 0) && (d[:Vd] = Vd) (is_in_dict(d, [:marker :Marker :shape]) === nothing) && (d[:marker] = "circ") (is_in_dict(d, [:mec :markeredgecolor :MarkerEdgeColor]) === nothing) && (d[:mec] = "0.0p,black") (is_in_dict(d, [:mc :markercolor]) === nothing) && (d[:mc] = "blue") (is_in_dict(d, [:ms :markersize :MarkerSize :size]) === nothing) && (d[:ms] = "3p") common_plot_xyz("", Dp, "stereonet", false, false, d) # Plot the poles - basemap!(J="P" * CTRL.pocket_J[2] * "+a", B="a15", show=show) + basemap!(J="P" * CTRL.pocket_J[2] * "+a", B="a15", show=show, savefig=savefig) end stereonet!(mat::AbstractArray{T,2}; schmidt=true, wulff=false, kw...) where T<:Real = stereonet(mat; first=false, schmidt=schmidt, wulff=wulff, kw...) -function _stereonet(mat::AbstractArray{T,2}) where T<:Real +function stereonet_data(mat::AbstractArray{T,2}) where T<:Real # This function computes the fault planes and the poles. Returns a vector of GMTdataset # with the fault planes and a GMTdataset with the poles. @assert size(mat,2) >= 2 "Input matrix must have at least two columns: azimuth and plunge"