Skip to content

Commit 5d0a652

Browse files
authored
Rework a bit the makecpt method that uses grids in input. (#1935)
* Simploify and always call makecpt either with equalize or not. * Test also with 1.12 * Rework a bit the makecpt method that uses grids in input. (shelter it from multi-recompiles)
1 parent 05a9818 commit 5d0a652

3 files changed

Lines changed: 17 additions & 16 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
#- '1.7' # Leave this line unchanged. '1' will automatically expand to the latest stable 1.x release of Julia.
2929
- '~1.10.0-0'
3030
#- '~1.11.0-0'
31-
#- '~1.12.0-0'
31+
- '~1.12.0-0'
3232
#- '~1.13.0-0'
3333
- 'nightly'
3434
os:

src/blendimg.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,8 @@ function lelandshade(G::GMTgrid; detail=1.0, contrast=2.0, uint16=false, intensi
343343
if (cmap != "")
344344
cpt = cmap
345345
isa(cpt, GMTcpt) && (CURRENT_CPT[] = cpt)
346-
elseif (equalize == 0)
347-
cpt = makecpt(G; C=_cpt, Vd=-1, kw...) # The 'nothing' branch will pick G's cpt
348346
else
349-
cpt = (equalize == 1) ? grd2cpt(G, C=_cpt, kw...) : grd2cpt(G, T="$equalize", C=_cpt, Vd=-1, kw...)
347+
cpt = (equalize == 0) ? makecpt(G, C=_cpt, kw...) : makecpt(G, C=_cpt, equalize=equalize, kw...)
350348
end
351349
color = gdaldem(G, "color-relief"; color=cpt, kw...)
352350
blendimg!(I1, Ihill, transparency=transparency)

src/makecpt.jl

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,25 +89,28 @@ function makecpt(w::wrapDatasets, d::Dict)::Union{String, GMTcpt}
8989
return r
9090
end
9191

92+
function makecpt(G::GMTgrid; kw...) # A version that works on grids.
93+
d = KW(kw...)
94+
have_equalize = (is_in_kwargs(kw, [:equalize]) && d[:equalize] == 1) # Because equalize=true escapes detection in parse_opt_range
95+
opt_T = parse_opt_range(d, "")[1]
96+
!isempty(opt_T) && (d[:T] = opt_T)
97+
makecpt(G::GMTgrid, have_equalize || !isempty(opt_T), d)
98+
end
9299

93-
function makecpt(G::GMTgrid; equalize=false, kw...) # A version that works on grids.
100+
function makecpt(G::GMTgrid, have_equalize, d) # A version that works on grids.
94101
# equalize = true uses default grd2cpt. equalize=n uses grd2cpt -Tn
95102
# The kw... are those of makecpt or grd2cpt depending on 'equalize'.
96103

97-
val, symb = find_in_kwargs(kw, CPTaliases)
104+
val = find_in_dict(d, CPTaliases)[1]
98105
cpt = (val === nothing) ? ((G.cpt != "") ? G.cpt : :turbo) : nothing
99-
d = Dict{Symbol, Any}()
100-
if (equalize == 0 && symb != Symbol() && val === nothing && cpt !== nothing)
101-
# It means kw have a -C, but it can be a C=nothing. Remove the duplicate that was in kw.
102-
d = KW(kw...); delete!(d, symb) # This confusion is due to the crazziness possible in lelandshade()
103-
end
104-
if (equalize == 0)
105-
t = isempty(d) ? kw : d
106+
d[:C] = cpt
107+
if (!have_equalize)
106108
range::Vector{Float64} = G.range
107109
loc_eps = 0.0004
108-
makecpt(; T=@sprintf("%.12g/%.12g/256+n", range[5] - loc_eps*abs(range[5]), range[6] + loc_eps*abs(range[6])), C=cpt, t...)
110+
d[:T] = @sprintf("%.12g/%.12g/256+n", range[5] - loc_eps*abs(range[5]), range[6] + loc_eps*abs(range[6]))
111+
makecpt(wrapDatasets("", nothing), d)
109112
else
110-
(equalize == 1) ? grd2cpt(G, C=cpt, kw...) : grd2cpt(G, T="$equalize", C=cpt, kw...)
113+
grd2cpt_helper(wrapGrids("", G), d)
111114
end
112115
end
113116

@@ -138,7 +141,7 @@ end
138141

139142
# -------------------------------------------------------------------------------------------
140143
function parse_opt_range(d::Dict, cmd::String, opt::String="")::Tuple{String, Vector{Float64}}
141-
symbs = [:T :range :inc :bin]
144+
symbs = [:T :range :inc :bin :equalize]
142145
(SHOW_KWARGS[]) && return print_kwarg_opts(symbs, "Tuple | Array | String | Number"), Float64[] # Just print the options
143146
Tvec::Vector{Float64} = Float64[]
144147
if ((val = find_in_dict(d, symbs)[1]) !== nothing)

0 commit comments

Comments
 (0)