diff --git a/src/GMT.jl b/src/GMT.jl index 30c7c9899..c7b43474d 100644 --- a/src/GMT.jl +++ b/src/GMT.jl @@ -152,7 +152,7 @@ export mbimport, mbgetdata, mbsvplist, mblevitus, blendimg!, lonlat2xy, xy2lonlat, df2ds, mat2ds, mat2grid, mat2img, slicecube, cubeslice, linspace, logspace, fileparts, - fields, flipud, fliplr, flipdim, flipdim!, grdinterpolate, pow, tic, toc, theme, tern2cart, geodetic2enu, cpt4dcw, + tests, fields, flipud, fliplr, flipdim, flipdim!, grdinterpolate, pow, tic, toc, theme, tern2cart, geodetic2enu, cpt4dcw, getregion, getattribs, getattrib, getres, gd2gmt, gmt2gd, gdalread, gdalshade, gdalwrite, gadm, xyzw2cube, coastlinesproj, graticules, orbits, orbits!, plotgrid!, leepacific, worldrectangular, worldrectgrid, togglemask, @@ -424,6 +424,7 @@ using .Laszip D[:Time]; D["Time", "b"]; #plot(rand(5,2), marker=:point, lc=:red, ls=:dot, lw=1) grdimage(rand(Float32,32,32), R="0/32/0/32"); + grdimage(tests("coins")) I = mat2img(rand(UInt8, 32, 32, 3), clim=:zscale); grdimage(I, V=:q); grdview(rand(Float32,32,32), Vd=2); diff --git a/src/grdimage.jl b/src/grdimage.jl index 2a1e80258..ffa0c89a7 100644 --- a/src/grdimage.jl +++ b/src/grdimage.jl @@ -72,7 +72,7 @@ function grdimage(cmd0::String="", arg1=nothing, arg2=nothing, arg3=nothing; fir (haskey(d, :stretch) || haskey(d, :histo_bounds)) && delete!(d, [:histo_bounds, :stretch]) end - invokelatest(_grdimage, cmd0, arg1, arg2, arg3, O, K, d) + _grdimage(cmd0, arg1, arg2, arg3, O, K, d) end function _grdimage(cmd0::String, arg1, arg2, arg3, O::Bool, K::Bool, d::Dict) diff --git a/src/montage.jl b/src/montage.jl index bc42dca81..29f1d7f35 100644 --- a/src/montage.jl +++ b/src/montage.jl @@ -1,7 +1,6 @@ export montage -# This file was initially created by Claude and still needs lots of cleanings. - +# This file was initially created by Claude and still needs to be worked on. # ------------------------------------------------------------------------------------------ """ @@ -21,7 +20,6 @@ Display multiple images arranged in a grid using GMT's subplot. - `frame`: Frame setting for panels. Default: :none - `indices`: Vector of indices selecting which images to display. - `show`: Display the result. Default: true. -- `savefig`: Filename to save the montage. ### Example ```julia @@ -36,40 +34,39 @@ montage(imgs, grid=(2,3), titles=["A","B","C","D","E","F"], panels_size=5) montage(rand(UInt8, 64, 64, 9), grid=(3,3), margin="0.2c") ``` """ -function montage(images; grid=nothing, panels_size=nothing, margin="0.0c", - title=nothing, titles=nothing, frame=nothing, indices=nothing, - show::Bool=true, noR::Bool=false, kw...) +function montage(images; grid=nothing, panels_size=nothing, margin="-0.23c", + title=nothing, titles=nothing, frame=nothing, indices=nothing, + show::Bool=true, noR::Bool=false, kw...) (indices !== nothing) && (images = images[indices]) # Apply indices selection ((n = length(images)) == 0) && error("No images to display") nrows, ncols = _montage_grid_size(n, grid) # Calculate grid dimensions - subplot_kw = KW(kw) - subplot_kw[:grid] = (nrows, ncols) - subplot_kw[:margin] = margin - subplot_kw[:frame] = frame - (frame === nothing) && (subplot_kw[:D] = true) # No frames around panels - (title !== nothing) && (subplot_kw[:title] = title) - subplot_kw[:Vd] = 1 - - if panels_size !== nothing - subplot_kw[:panels_size] = panels_size - else # Auto size based on grid - ps = max(3, min(8, 18 / max(nrows, ncols))) - subplot_kw[:panels_size] = ps - end + d = KW(kw) + d[:grid] = (nrows, ncols) + d[:margin] = margin + (frame == "0") ? (d[:par] = (MAP_FRAME_PEN="0",); d[:frame] = frame) : + ((frame !== nothing) && (d[:B] ="0"; d[:par] = (:MAP_FRAME_PEN,parse_pen(frame)))) + + (frame === nothing) && (d[:D] = true) # No frames around panels + (title !== nothing) && (d[:title] = title) + + ps = (panels_size !== nothing) ? panels_size : max(3, min(8, 18 / max(nrows, ncols))) + d[:panels_size] = ps + Vd = get(d, :Vd, 0) # Get the Vd option that will be consumed by subplot\ - subplot("", false, subplot_kw) # Create subplot (since we already have the Dict pass it directly) + subplot("", false, d) # Create subplot (since we already have the Dict pass it directly) d = CTRL.pocket_d[1] # Fetch options not consumed by subplot. # Plot each ... input - k = 0 + d[:J] = "x?" + k = 0; n_inputs = length(images) for row in 1:nrows for col in 1:ncols - k += 1 + ((k += 1) > n_inputs) && break panel_title = (titles !== nothing && k <= length(titles)) ? titles[k] : nothing opt_R = isa(images[k], GItype) ? (noR ? "" : getR(images[k])) : "" - viz(images[k], panel=(row, col), title=panel_title, R=(opt_R !== "" ? opt_R : nothing), Vd=1, show=false, d...) + viz(images[k]; panel=(row, col), title=panel_title, R=(opt_R !== "" ? opt_R : nothing), Vd=Vd, show=false, d...) end end subplot(show ? :show : :end) # End subplot @@ -78,6 +75,7 @@ function montage(images; grid=nothing, panels_size=nothing, margin="0.0c", end # Calculate grid dimensions +# ---------------------------------------------------------------------------------------------------------- function _montage_grid_size(n, size) if size === nothing || all(x -> x === nothing || x == 0 || (isa(x, AbstractFloat) && isnan(x)), size) ncols = ceil(Int, sqrt(n)) diff --git a/src/statplots.jl b/src/statplots.jl index 453f5d91f..da1a56b72 100644 --- a/src/statplots.jl +++ b/src/statplots.jl @@ -1327,7 +1327,7 @@ function cornerplot(arg1; first::Bool=true, kwargs...) d[:Vd] = Vd d[:grid] = "$(ndims)x$(ndims)" - r = subplot(; d...) + r = subplot("", false, d) d = CTRL.pocket_d[1] # Get back what was not consumemd in subplot (Vd >= 0) && (d[:Vd] = Vd) # Restore this in case (Vd == 2) && return r # Almost useless but at least wont error @@ -1472,7 +1472,7 @@ function marginalhist(arg1::Union{GDtype, Matrix{<:Real}}; first=true, kwargs... CTRL.figsize[1] = W # Set figsize needed to compute hexagons size doDensity = (find_in_dict(d, [:density :Density])[1] !== nothing) # For now, no control on the density computing params - r = subplot(; d...) + r = subplot("", false, d) d = CTRL.pocket_d[1] # Get back what was not consumemd in subplot (Vd >= 0) && (d[:Vd] = Vd) # Restore this in case (Vd == 2) && return r # Almost useless but at least wont error diff --git a/src/utils.jl b/src/utils.jl index 954191928..3e6d1cc43 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -991,6 +991,31 @@ function fileparts(fn::String) return pato, fname, ext end +# --------------------------------------------------------------------------------------------------- +""" + tests(fname::String, subdir::String="assets") -> String + +Return the full path of a test file `fname` under `TESTSDIR/subdir`. +If `fname` has no extension, search for a matching file in the subdirectory. +If no match is found, issue a warning and return `""`. +""" +function tests(fname::String, subdir::String="assets") + dir = joinpath(TESTSDIR, subdir) + ext = fileparts(fname)[3] + if ext !== "" + fullpath = joinpath(dir, fname) + isfile(fullpath) && return fullpath + else + # Search for files whose basename (without extension) matches fname + isdir(dir) || (@warn("Directory $dir not found"); return "") + for f in readdir(dir) + splitext(f)[1] == fname && return joinpath(dir, f) + end + end + @warn("File \"$fname\" not found in $dir") + return "" +end + # --------------------------------------------------------------------------------------------------- """ I = eye(n=3) returns an n-by-n identity matrix with ones on the main diagonal and zeros elsewhere. diff --git a/test/assets/cameraman.png b/test/assets/cameraman.png new file mode 100644 index 000000000..0568435b3 Binary files /dev/null and b/test/assets/cameraman.png differ diff --git a/test/assets/peppers.jpg b/test/assets/peppers.jpg new file mode 100644 index 000000000..e974742cb Binary files /dev/null and b/test/assets/peppers.jpg differ diff --git a/test/test_utils.jl b/test/test_utils.jl index 9e2e82d5c..cd36a985b 100644 --- a/test/test_utils.jl +++ b/test/test_utils.jl @@ -42,4 +42,15 @@ @test !bissextile(100) @test bissextile(-4) + + println(" TESTS function") + # With extension - must find the file and return a non-empty path + @test tests("cameraman.png") == joinpath(TESTSDIR, "assets", "cameraman.png") + # Without extension - must find a matching file in assets/ + @test tests("cameraman") == joinpath(TESTSDIR, "assets", "cameraman.png") + # Non-existent file - must warn and return "" + @test (@test_logs (:warn,) tests("nao_existe_xpto.dat")) == "" + # Non-existent file without extension + @test (@test_logs (:warn,) tests("nao_existe_xpto")) == "" + end