From 96491f3a41476e91d91fa034c54b36bfb4aa1a6e Mon Sep 17 00:00:00 2001 From: RainerHeintzmann Date: Tue, 7 May 2024 11:08:46 +0200 Subject: [PATCH] reduced printout and bugfix with naming viewers --- Project.toml | 12 ++++++------ src/rois.jl | 9 +++++++-- src/shorthands.jl | 43 ++++++++++++++++++++++--------------------- src/viewer_core.jl | 11 +++++++---- test/runtests.jl | 11 +++++------ 5 files changed, 47 insertions(+), 39 deletions(-) diff --git a/Project.toml b/Project.toml index af739aa..c7956dd 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "View5D" uuid = "90d841e0-6953-4e90-9f3a-43681da8e949" authors = ["rheintzmann "] -version = "0.4.5" +version = "0.5" [deps] AxisArrays = "39de3d68-74b9-583c-8d2d-e117c070f3a9" @@ -17,12 +17,12 @@ Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" [compat] AxisArrays = "0.4.3,0.4.6" Colors = "0.12.7, 0.12.8" -ImageCore = "0.8.21, 0.9" -JavaCall = "0.7.7, 0.7.8" +ImageCore = "0.8.21, 0.9, 0.10" +JavaCall = "0.7.7, 0.7.8, 0.8" StaticArrays = "1" -Unitful = "1.7.0 - 1.12" -julia = "1, 1.6" -NDTools = "0.4, 0.5" +Unitful = "1" +julia = "1, 1.6, 1.7, 1.8, 1.9, 1.10" +NDTools = "0.4, 0.5, 0.6" [extras] JavaCall = "494afd89-becb-516b-aafa-70d2670c0337" diff --git a/src/rois.jl b/src/rois.jl index 1596df7..d5dbedf 100644 --- a/src/rois.jl +++ b/src/rois.jl @@ -57,19 +57,24 @@ The user interaction is saved in a file `coord_filename` and reloaded automatica #arguments + `data` : data to extract the regions of interest from ++ `positions`: if supplied, the positions are used instead of selecting them interactively ++ `viewer`: a pre-existing viewer to use for the user interaction + `overwrite`: boolean flag indicating weather a pre-existing file should be loaded or overwritten. + `coord_filename`: filname where to save the user-interaction to + `roi_size` : size of the region of interest to extract + `do_save`: boolean defining whether to serialize the user interaction to disk + `confirm_selected`: if true, a prompt waits for user interaction finished. ++ `verbose`: if true, the number of selected ROIs is printed #returns a tuple of the extracted ROIs and the selected positions The latter can be resupplied via the `positions` argument """ -function get_rois(data; positions=nothing, viewer=nothing, overwrite=false, confirm_selected=true, do_save=true, coord_filename="selected_coordinates.coords", roi_size=(16,16)) +function get_rois(data; positions=nothing, viewer=nothing, overwrite=false, confirm_selected=true, do_save=true, coord_filename="selected_coordinates.coords", roi_size=(16,16), verbose=false) bp = get_positions(data; positions=positions, viewer=viewer, overwrite=overwrite, confirm_selected=confirm_selected, do_save=do_save, coord_filename=coord_filename) - println("$(length(bp)) ROIs selected.") + if verbose + println("$(length(bp)) ROIs selected.") + end rois = [] for n in 1:length(bp) pos = Tuple(round.(Int,bp[n])) diff --git a/src/shorthands.jl b/src/shorthands.jl index 3a6ff69..dbc7b3f 100644 --- a/src/shorthands.jl +++ b/src/shorthands.jl @@ -114,7 +114,9 @@ created data 3 function vt(data, viewer=nothing; gamma=nothing, element=0, time=0, show_phase=false, keep_zero=false, name=nothing, title=nothing, times_linked=false) viewer = get_viewer(viewer, ignore_nothing=true); viewer = vv(data, viewer; gamma=gamma, mode=DisplAddTime, element=element, time=time, show_phase=show_phase, keep_zero=keep_zero, name=name, title=title) -set_times_linked(times_linked, viewer) +if !isnothing(viewer) + set_times_linked(times_linked, viewer) +end end """ @@ -170,27 +172,26 @@ alt_name=nothing viewer=nothing # by default the active viewer is used value = "" for ex in exs - varname = sprint(Base.show_unquoted, ex) + varname = sprint(Base.show_unquoted, ex); if isnothing(alt_name) - name = :(println($(esc(varname))*" = ", - begin local value=display_array($(esc(ex)),$(esc(varname)),$(mystarter),$(esc(viewer))) end)) + name = :(begin local value=display_array($(esc(ex)),$(esc(varname)),$(mystarter),$(esc(viewer))) end) else - name = :(println($(esc(varname))*" = ", - begin local value=display_array($(esc(ex)),$(esc(alt_name)),$(mystarter),$(esc(viewer))) end)) + name = :(begin local value=display_array($(esc(ex)),$(esc(alt_name)),$(mystarter),$(esc(viewer))) end) end - push!(blk.args, name) + if typeof(ex)==String - alt_name = ex + alt_name = ex # define this alt_name for the next round. It will generate the expression "alt_name = nothing" which has no effect. else alt_name = nothing + if typeof(ex) == Symbol # && typeof(eval(ex)) == JavaCall.JavaObject{Symbol("view5d.View5D")} + viewer=ex; # if a viewer is provided as argument, it will be used for display in the next (and future) rounds. + end end - if typeof(ex) == Symbol # && typeof(eval(ex)) == JavaCall.JavaObject{Symbol("view5d.View5D")} - viewer=ex - end + end -isempty(exs) || push!(blk.args, :value) # the second part ensures that the result of the display is the viewer -return blk # blk +isempty(exs) || push!(blk.args, :value); # the second part ensures that the result of the display is the viewer +return blk; # blk end """ @@ -212,7 +213,7 @@ julia> using Unitful, AxisArrays; @vv AxisArray(rand(10,11,12,3,4),(:x,:y,:z,:li ``` """ macro vv(exs...) -do_start(exs; mystarter=vv) + do_start(exs; mystarter=vv); end """ @@ -235,7 +236,7 @@ rand(5, 4, 7, 1, 2) = in_view5d ``` """ macro ve(exs...) -do_start(exs; mystarter=ve) + do_start(exs; mystarter=ve) end """ @@ -243,7 +244,7 @@ end a conveniance macro in its usage similar to `@show`, displaying also phase information using view5d. See `@vv` and `vp` for details. """ macro vp(exs...) -do_start(exs; mystarter=vp) + do_start(exs; mystarter=vp) end """ @@ -255,7 +256,7 @@ Note that variables of String type or expressions in strings do currently not wo ``` """ macro vt(exs...) -do_start(exs; mystarter=vt) + do_start(exs; mystarter=vt) end """ @@ -267,19 +268,19 @@ Note that variables of String type or expressions in strings do currently not wo ``` """ macro vr(exs...) -do_start(exs; mystarter=vr) + do_start(exs; mystarter=vr) end macro vep(exs...) -do_start(exs; mystarter=vep) + do_start(exs; mystarter=vep) end macro vtp(exs...) -do_start(exs; mystarter=vtp) + do_start(exs; mystarter=vtp) end macro vrp(exs...) -do_start(exs; mystarter=vrp) + do_start(exs; mystarter=vrp) end #= Missing implementations from Java: diff --git a/src/viewer_core.jl b/src/viewer_core.jl index fd20c04..cd1bcbc 100644 --- a/src/viewer_core.jl +++ b/src/viewer_core.jl @@ -930,12 +930,12 @@ function check_alive(viewer) if num_elem >= 0 return viewer else - @warn "View5D: viewer not existing." + # @warn "View5D: viewer not existing." remove_viewer(viewer) return nothing end catch - @warn "View5D: viewer not existing." + # @warn "View5D: viewer not existing." remove_viewer(viewer) return nothing end @@ -1113,8 +1113,9 @@ Arguments: + viewer: viewer to apply normalization to + element: element to apply it to + min_ratio: the minimum contrast ratio (towards zero) to require to do apply min-max rather that zero to max display normalization ++ verbose: if true, the normalization range is printed to the console """ -function optional_normalize_display(data, viewer=nothing; element=0, min_ratio=1e6) +function optional_normalize_display(data, viewer=nothing; element=0, min_ratio=1e6, verbose=false) if !(eltype(data) <: Real) data = abs.(data); end @@ -1123,7 +1124,9 @@ function optional_normalize_display(data, viewer=nothing; element=0, min_ratio=1 if ((mymax - mymin)*min_ratio < mymax) mymin = 0; end - println("display normalized to $(mymin) to $(mymax).") + if verbose + println("display normalized to $(mymin) to $(mymax).") + end set_min_max_thresh(mymin, mymax, viewer; element=element) update_panels(viewer) end diff --git a/test/runtests.jl b/test/runtests.jl index 2afe90c..1a9c9a7 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -9,17 +9,16 @@ data3 = rand(5,5,3,4,2); # more elements @testset "start viewers" begin v = @vv data1; # start the viewer @ve data2; # append along element - @vt data3; # append along time - @vt data3; # append along time + @vt "Hi there" data3 "ignor this" data3; # append along time @vr data3; # replace first w = @vv data2; - @vr v data3; # replace first + @vr "Hello" v data3; # replace first @test 6 == get_num_times(); @test 4 == get_num_elements(); sleep(0.1); hide_viewer() ; end -@testset "interaction with markers and roi extraction" begin +@testset "markers, rois" begin v = @vv data1; # start the viewer markers = empty_marker_list(2,2) markers[1][3]=1.0 @@ -50,7 +49,7 @@ data1 = rand(5,5,3,1,1) .+ 1im.*rand(5,5,3,1,1); data2 = rand(5,5,3,1,1) .+ 1im.*rand(5,5,3,1,1); data3 = rand(5,5,3,2,1) .+ 1im.*rand(5,5,3,2,1); # more elements -@testset "complex-valued display" begin +@testset "complex-vals" begin @test nothing != @vp data1; # start a new viewer in phase mode @test nothing == set_gamma(1.0); @test nothing != @vep data2; # start a new viewer in phase mode @@ -58,7 +57,7 @@ data3 = rand(5,5,3,2,1) .+ 1im.*rand(5,5,3,2,1); # more elements @vrp data3; # replace phase data end -@testset "view5d datatypes" begin +@testset "datatypes" begin @test nothing != view5d(rand(Float32,2,2,2,2,2)) # -> float @test nothing != view5d(rand(Float64,2,2,2,2,2)) # -> double @test nothing != view5d(rand(ComplexF32,2,2,2,2,2)) # > Complex