Skip to content

Commit 8c748e0

Browse files
authored
Fix things in stereonet. (savefig and show were not working correctly) (#1824)
* Move the makecpt_raw from makecpt.jl to common_options.jl Do this so makecpt can be accessed from a future GMTcore package. * Fix things in stereonet. (savefig and show were not working correctly)
1 parent d342502 commit 8c748e0

4 files changed

Lines changed: 32 additions & 21 deletions

File tree

src/GMT.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ using GMT.Laszip
375375
#include("ImageFeatures/ImageFeatures.jl")
376376
#using GMT.ImageFeatures
377377

378-
@compile_workload let
378+
@compile_workload begin
379379
G_API[1] = GMT_Create_Session("GMT", 2, GMT_SESSION_BITFLAGS)
380380
#GMT.parse_B(Dict{Symbol, Any}(:frame => (annot=10, title="Ai Ai"), :grid => (pen=2, x=10, y=20)), "", " -Baf -BWSen");
381381
#GMT.parse_R(Dict{Symbol, Any}(:xlim => (1,2), :ylim => (3,4), :zlim => (5,6)), "");

src/common_options.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2802,6 +2802,18 @@ function get_cpt_set_R(d::Dict, cmd0::String, cmd::String, opt_R::String, got_fn
28022802
return cmd, N_used, arg1, arg2, arg3
28032803
end
28042804

2805+
# 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"
2806+
function makecpt_raw(cmd::String, arg1=nothing)::GMTcpt
2807+
# Raw version that already knows what the command is and has no input data.
2808+
(IamModern[1] && !contains(cmd, " -H")) && (cmd *= " -H")
2809+
!startswith(cmd, "makecpt ") && (cmd = "makecpt " * cmd)
2810+
_r = gmt_GMTcpt(cmd, arg1)
2811+
r::GMTcpt = (_r !== nothing) ? _r : GMTcpt() # _r === nothing when we save CPT on disk.
2812+
(contains(cmd, " -N") && !isempty(r)) && (r.bfn = ones(3,3)) # Cannot remove the bfn like in plain GMT so make it all whites
2813+
CURRENT_CPT[1] = r
2814+
return r
2815+
end
2816+
28052817
#=
28062818
function get_colorbar_pos(anchor)
28072819
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_
41914203
if (haskey(d, :show) && d[:show] != 0)
41924204
if ((isdefined(Main, :IJulia) && Main.IJulia.inited) || (isdefined(Main, :VSCodeServer) && get(ENV, "DISPLAY_IN_VSC", "") != "no"))
41934205
#https://stackoverflow.com/questions/70620607/how-can-i-programmatically-check-that-i-am-running-code-in-a-notebook-in-julia
4194-
(fname == "") ? display(MIME"image/png"(), read(out)) : @warn("In Jupyter you can only visualize png files. File $fname was saved in disk though.")
4206+
(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.")
41954207
elseif (isPluto)
41964208
retPluto = true
41974209
elseif (!isFranklin[1]) # !isFranklin is true when building the docs and there we don't want displays.

src/makecpt.jl

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ Make static color palette tables (CPTs). The second form accepts a name of one o
99
- **A** | **alpha** | **transparency** :: [Type => Str]
1010
1111
Sets a constant level of transparency (0-100) for all color slices.
12-
- $(opt_C)
12+
- **C** | **color** | **colormap** | **cmap** | **colorscale** :: [Type => Str]
13+
14+
Give a CPT name or specify -Ccolor1,color2[,color3,...] to build a linear continuous CPT from those
15+
colors automatically.
1316
- **D** | **bg** | **background** :: [Type => Str | []] `Arg = [i|o]`
1417
1518
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}
8588
return r
8689
end
8790

88-
function makecpt_raw(cmd::String, arg1=nothing)::GMTcpt
89-
# Raw version that already knows what the command is and has no input data.
90-
(IamModern[1] && !contains(cmd, " -H")) && (cmd *= " -H")
91-
!startswith(cmd, "makecpt ") && (cmd = "makecpt " * cmd)
92-
_r = gmt_GMTcpt(cmd, arg1)
93-
r::GMTcpt = (_r !== nothing) ? _r : GMTcpt() # _r === nothing when we save CPT on disk.
94-
(contains(cmd, " -N") && !isempty(r)) && (r.bfn = ones(3,3)) # Cannot remove the bfn like in plain GMT so make it all whites
95-
CURRENT_CPT[1] = r
96-
return r
97-
end
9891

9992
function makecpt(G::GMTgrid; equalize=false, kw...) # A version that works on grids.
10093
# equalize = true uses default grd2cpt. equalize=n uses grd2cpt -Tn

src/plot.jl

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,8 @@ function bar(f::Function, range_x=nothing; first=true, kw...)
493493
end
494494
bar!(f::Function, rang=nothing; kw...) = bar(f, rang; first=false, kw...)
495495

496-
bar(arg1, arg2; first=true, kw...) = common_plot_xyz("", cat_2_arg2(arg1, arg2, true), "bar", first, false; kw...)
497-
bar!(arg1, arg2; kw...) = common_plot_xyz("", cat_2_arg2(arg1, arg2, true), "bar", false, false; kw...)
496+
bar(arg1, arg2; first=true, kw...) = common_plot_xyz("", cat_2_arg2(arg1, Float64.(arg2), true), "bar", first, false; kw...)
497+
bar!(arg1, arg2; kw...) = common_plot_xyz("", cat_2_arg2(arg1, Float64.(arg2), true), "bar", false, false; kw...)
498498
bar(arg; kw...) = bar("", arg; kw...)
499499
bar!(arg; kw...) = common_plot_xyz("", cat_1_arg(arg, true), "bar", false, false; kw...)
500500
# ------------------------------------------------------------------------------------------------------
@@ -2251,38 +2251,44 @@ Plot a stereonet map in either Schmidt or Wulff projection.
22512251
and line & marker settings (see ``plots`` manual for details on them).
22522252
22532253
In case the produced figure is still not satisfactory, you can make one by yourself.
2254-
For that use the `Dv, Dp = _stereonet(mat)` function to get the fault planes and poles. A good place
2254+
For that use the `Dv, Dp = stereonet_data(mat)` function to get the fault planes and poles. A good place
22552255
to start is the `stereonet` function itself. Type ``@edit GMT.stereonet([0 0])`` to see the code.
22562256
22572257
### Example
22582258
```julia
2259-
stereonet([90 30; 180 45; 270 60; 0 15; 30 45; 120 48; 225 27; 350 80])
2259+
stereonet([90 30; 180 45; 270 60; 0 15; 30 45; 120 48; 225 27; 350 80], show=true)
22602260
```
22612261
"""
22622262
function stereonet(mat::AbstractArray{T,2}; first=true, schmidt=true, wulff=false, kw...) where T<:Real
22632263
d = KW(kw)
2264-
show = (find_in_dict(d, [:show])[1] !== nothing) ? false : true # DEfault is 'true'.
2264+
_stereonet(mat, first, schmidt, wulff, d)
2265+
end
2266+
function _stereonet(mat::AbstractArray{T,2}, first::Bool, schmidt::Bool, wulff::Bool, d) where T<:Real
2267+
show = ((val = find_in_dict(d, [:show])[1]) !== nothing && val != 0)
2268+
savefig = find_in_dict(d, [:savefig :figname :name])[1];
2269+
Vd = get(d, :Vd, 0)
22652270
wulff && (schmidt = false) # Wulff stereonet
22662271

2267-
Dv, Dp = _stereonet(mat)
2272+
Dv, Dp = stereonet_data(mat)
22682273
prj = schmidt ? :laea : (name=:stereo, center=[0,0])# "S0/0/15c"
22692274
(is_in_dict(d, [:lc :linecolor]) === nothing) && (d[:lc] = "red")
22702275
(is_in_dict(d, [:lt :linethickness]) === nothing) && (d[:lt] = 0.5)
22712276
d[:par] = (MAP_GRID_PEN_PRIMARY="0.25,gray", MAP_GRID_PEN_SECONDARY="0.25,black")
22722277
d[:B], d[:R], d[:J] = "pg5 sg20", :d, prj
22732278
common_plot_xyz("", Dv, "plot", first, false, d) # Plot the fault planes
2279+
(Vd != 0) && (d[:Vd] = Vd)
22742280

22752281
(is_in_dict(d, [:marker :Marker :shape]) === nothing) && (d[:marker] = "circ")
22762282
(is_in_dict(d, [:mec :markeredgecolor :MarkerEdgeColor]) === nothing) && (d[:mec] = "0.0p,black")
22772283
(is_in_dict(d, [:mc :markercolor]) === nothing) && (d[:mc] = "blue")
22782284
(is_in_dict(d, [:ms :markersize :MarkerSize :size]) === nothing) && (d[:ms] = "3p")
22792285
common_plot_xyz("", Dp, "stereonet", false, false, d) # Plot the poles
2280-
basemap!(J="P" * CTRL.pocket_J[2] * "+a", B="a15", show=show)
2286+
basemap!(J="P" * CTRL.pocket_J[2] * "+a", B="a15", show=show, savefig=savefig)
22812287
end
22822288
stereonet!(mat::AbstractArray{T,2}; schmidt=true, wulff=false, kw...) where T<:Real =
22832289
stereonet(mat; first=false, schmidt=schmidt, wulff=wulff, kw...)
22842290

2285-
function _stereonet(mat::AbstractArray{T,2}) where T<:Real
2291+
function stereonet_data(mat::AbstractArray{T,2}) where T<:Real
22862292
# This function computes the fault planes and the poles. Returns a vector of GMTdataset
22872293
# with the fault planes and a GMTdataset with the poles.
22882294
@assert size(mat,2) >= 2 "Input matrix must have at least two columns: azimuth and plunge"

0 commit comments

Comments
 (0)