Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/GMT.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/grdimage.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
46 changes: 22 additions & 24 deletions src/montage.jl
Original file line number Diff line number Diff line change
@@ -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.

# ------------------------------------------------------------------------------------------
"""
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions src/statplots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Binary file added test/assets/cameraman.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/assets/peppers.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions test/test_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading