@@ -34,14 +34,17 @@ julia> viz(G, zsize=6, facades=(TESTSDIR*"assets/cenora_base.jpg", TESTSDIR*"bun
3434See also: [`grdimage`](@ref), [`grdview`](@ref)
3535"""
3636function imshow (arg1, x:: AbstractVector{Float64} = Float64[], y:: AbstractVector{Float64} = Float64[]; kw... )
37+ _imshow (arg1, x, y, KW (kw))
38+ end
39+ function _imshow (@nospecialize (arg1), x:: AbstractVector{Float64} , y:: AbstractVector{Float64} , d:: Dict{Symbol,Any} )
3740 # Take a 2D array of floats and turn it into a GMTgrid or if input is a string assume it's a file name
3841 # In this later case try to figure if it's a grid or an image and act accordingly.
3942
40- see = ((val = find_in_kwargs (kw, [ :show ])[ 2 ]) === nothing ) ? true : (val != 0 ) # No explicit 'show' keyword means show=true
43+ see = (! haskey (d, :show )) ? true : (d[ :show ] != 0 ) # No explicit 'show' keyword means show=true
4144
42- function isplot3 (kw )
45+ function _isplot3 (d :: Dict )
4346 _call_plot3 = false
44- opt_p = find_in_kwargs (kw , [:p :view :perspective ])[1 ]
47+ opt_p = find_in_dict (d , [:p :view :perspective ], false )[1 ]
4548 (isa (opt_p, String) && contains (opt_p, ' /' )) && (_call_plot3 = true )
4649 ((isa (opt_p, Tuple) || isa (opt_p, VMr)) && length (opt_p) > 1 ) && (_call_plot3 = true )
4750 return _call_plot3
@@ -60,10 +63,9 @@ function imshow(arg1, x::AbstractVector{Float64}=Float64[], y::AbstractVector{Fl
6063 ext = lowercase (ext)
6164 (ext == " .jpg" || ext == " .tif" || ext == " .tiff" || ext == " .png" || ext == " .bmp" || ext == " .gif" ) && (is_image = true )
6265 ! is_image && (Gg = arg1)
63- # snif_GI_set_CTRLlimits(arg1) # Set CTRL.limits to be eventually used by J=:guess
6466 end
6567 elseif (isa (arg1, Array{UInt8}) || isa (arg1, Array{UInt16,3 }) || isa (arg1, Array{Bool}) || isa (arg1, BitMatrix))
66- Gi = isa (arg1, BitMatrix) ? mat2img (collect (arg1); kw ... ) : mat2img (arg1; kw ... )
68+ Gi = isa (arg1, BitMatrix) ? mat2img (collect (arg1); d ... ) : mat2img (arg1; d ... )
6769 call_img = true
6870 elseif (isa (arg1, GDtype) || isa (arg1, GMTfv) || isa (arg1, Vector{GMTfv}) || (isa (arg1, AbstractVecOrMat{<: Real }) && size (arg1,2 ) <= 4 ) || (isa (arg1, Gdal. AbstractDataset) || isa (arg1, Gdal. AbstractGeometry)))
6971 (isa (arg1, Gdal. AbstractDataset) || isa (arg1, Gdal. AbstractGeometry)) && (arg1 = gd2gmt (arg1))
@@ -82,13 +84,15 @@ function imshow(arg1, x::AbstractVector{Float64}=Float64[], y::AbstractVector{Fl
8284 call_plot3 = ((isa (arg1, GMTdataset) && arg1. geom == wkbPolygonZM) ||
8385 (isa (arg1, Vector{<: GMTdataset }) && arg1[1 ]. geom == wkbPolygonZM) ||
8486 isFV3D) ? true : false # Should evolve into a fun that detects the several plot3d cases.
85- ! call_plot3 && (call_plot3 = isplot3 (kw))
86- return (call_plot3) ? plot3d (arg1; show= see, kw... ) : plot (arg1; show= see, kw... )
87+ ! call_plot3 && (call_plot3 = _isplot3 (d))
88+ d[:show ] = see
89+ return (call_plot3) ? plot3d (arg1; d... ) : plot (arg1; d... )
8790 elseif (isa (arg1, GMTcpt))
88- return (find_in_kwargs (kw , [:D :pos :position ])[1 ] === nothing ) ?
89- psscale (arg1; show= true , D= " x0/0+w7+h" , kw ... ) : psscale (arg1; show= true , kw ... )
91+ return (find_in_dict (d , [:D :pos :position ], false )[1 ] === nothing ) ?
92+ psscale (arg1; show= true , D= " x0/0+w7+h" , d ... ) : psscale (arg1; show= true , d ... )
9093 elseif (isdataframe (arg1) || isODE (arg1))
91- return isplot3 (kw) ? plot3 (arg1; show= see, kw... ) : plot (arg1; show= see, kw... )
94+ d[:show ] = see
95+ return _isplot3 (d) ? plot3 (arg1; d... ) : plot (arg1; d... )
9296 else
9397 Gg = mat2grid (arg1, x, y, reg= 1 ) # For displaying, pixel registration is more appropriate
9498 call_grd = true
@@ -98,17 +102,18 @@ function imshow(arg1, x::AbstractVector{Float64}=Float64[], y::AbstractVector{Fl
98102 call_grd && snif_GI_set_CTRLlimits (Gg)
99103
100104 if (is_image)
101- grdimage (arg1; show= see, kw ... )
105+ grdimage (arg1; show= see, d ... )
102106 else
103- if (isa (Gg, String)) # Guess also if call grdview or grdimage
104- if (get (kw, :JZ , 0 ) != 0 || get (kw, :Jz , 0 ) != 0 || get (kw, :zscale , 0 ) != 0 || get (kw, :zsize , 0 ) != 0 )
105- (get (kw, :Q , " " ) == " " && get (kw, :surf , " " ) == " " && get (kw, :surftype , " " ) == " " ) && (kw = (kw... , Q= " s" ))
106- grdview (arg1; show= see, kw... ) # String when fname is @xxxx
107+ if (isa (Gg, String)) # Guess also if call grdview or grdimage
108+ d[:show ] = see
109+ if (get (d, :JZ , 0 ) != 0 || get (d, :Jz , 0 ) != 0 || get (d, :zscale , 0 ) != 0 || get (d, :zsize , 0 ) != 0 )
110+ (get (d, :Q , " " ) == " " && get (d, :surf , " " ) == " " && get (d, :surftype , " " ) == " " ) && (d[:Q ] = " s" )
111+ grdview (arg1; d... ) # String when fname is @xxxx
107112 else
108- grdimage (arg1; show = see, kw ... )
113+ grdimage (arg1; d ... )
109114 end
110115 else
111- imshow (call_img ? Gi : Gg; kw ... ) # Call the specialized method
116+ _imshow_GI (call_img ? Gi : Gg, d ) # Call the specialized method directly
112117 end
113118 end
114119end
@@ -122,12 +127,14 @@ end
122127# - `T, no_interp, tiles`: -T option for grdview
123128# - `facades, cubeplot`: Call cubeplot.
124129function imshow (arg1:: GItype ; kw... )
125- # Here the default is to show, but if a 'show' was used let it rule
126- d = KW (kw)
130+ _imshow_GI (arg1, KW (kw))
131+ end
132+ function _imshow_GI (arg1:: GItype , d:: Dict{Symbol,Any} )
127133 see:: Bool = (! haskey (d, :show )) ? true : (d[:show ] != 0 ) # No explicit 'show' keyword means show=true
128134
129- if (isa (arg1, GMTimage) && (size (arg1, 3 ) <= 3 || arg1. layout[4 ] == ' A' )) # Rest of the work is done in grdiamge
130- return grdimage (" " , arg1; show= see, kw... )
135+ if (isa (arg1, GMTimage) && (size (arg1, 3 ) <= 3 || arg1. layout[4 ] == ' A' )) # Rest of the work is done in grdimage
136+ d[:show ] = see
137+ return grdimage_helper (wrapGrids (" " , arg1), nothing , nothing , true , false , d)
131138 end
132139
133140 if ((cont_opts = find_in_dict (d, [:contour ])[1 ]) != = nothing )
@@ -138,7 +145,7 @@ function imshow(arg1::GItype; kw...)
138145 have_tilles:: Bool = ((til = find_in_dict (d, [:T :no_interp :tiles ])[1 ]) != = nothing )
139146 (! have_tilles && opt_p != " " && ! contains (opt_p, ' /' )) && (flat = true ) # If only 'azimuth' and no 'elev'
140147 flat:: Bool = (find_in_dict (d, [:flat ])[1 ] != = nothing ) # If true, force the use of grdimage
141- docube = is_in_kwargs (kw , [:facades :cubeplot ])
148+ docube = is_in_dict (d , [:facades :cubeplot ]) != = nothing
142149 (flat && docube) && (flat = false )
143150
144151 if (! docube && (flat || (opt_p == " " && ! have_tilles)))
@@ -232,15 +239,16 @@ end
232239
233240# Simple method to show CPTs. (May grow)
234241# Ex: imshow(C, xlabel="Bla", ylabel="Blu"), or imshow(:gray)
235- imshow (arg1:: Symbol ; horizontal:: Bool = false , kw... ) = imshow (makecpt (arg1); horizontal= horizontal, kw... )
242+ imshow (arg1:: Symbol ; horizontal:: Bool = false , kw... ) = imshow (makecpt (arg1); horizontal= horizontal, kw... )
236243function imshow (arg1:: GMTcpt ; horizontal:: Bool = false , kw... )
237- see:: Bool = (! haskey (kw, :show )) ? true : kw[:show ] # No explicit 'show' keyword means show=true
238- horizontal ? psscale (arg1; D= " x8c/1c+w12c/0.5c+jTC+h" , show= see, kw... ) : psscale (arg1; J= " X15/0" , D= " x8c/1c+w12c/0.5c+jBC" , show= see, kw... )
244+ d = KW (kw)
245+ see:: Bool = (! haskey (d, :show )) ? true : (d[:show ] != 0 )
246+ horizontal ? psscale (arg1; D= " x8c/1c+w12c/0.5c+jTC+h" , show= see, d... ) : psscale (arg1; J= " X15/0" , D= " x8c/1c+w12c/0.5c+jBC" , show= see, d... )
239247end
240248
241249function imshow (arg1:: Gdal.AbstractDataset ; kw... )
242250 (Gdal. GDALGetRasterCount (arg1. ptr) == 0 ) && return plot (gd2gmt (arg1), show= 1 )
243- imshow (gd2gmt (arg1); kw ... )
251+ _imshow_GI (gd2gmt (arg1), KW (kw) )
244252end
245253
246254imshow (x:: AbstractVector{Float64} , y:: AbstractVector{Float64} , f:: Function ; kw... ) = imshow (mat2grid (f, x, y); kw... )
0 commit comments