Skip to content

Commit

Permalink
reduced printout and bugfix with naming viewers
Browse files Browse the repository at this point in the history
  • Loading branch information
RainerHeintzmann committed May 7, 2024
1 parent d14e220 commit 96491f3
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 39 deletions.
12 changes: 6 additions & 6 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "View5D"
uuid = "90d841e0-6953-4e90-9f3a-43681da8e949"
authors = ["rheintzmann <[email protected]>"]
version = "0.4.5"
version = "0.5"

[deps]
AxisArrays = "39de3d68-74b9-583c-8d2d-e117c070f3a9"
Expand All @@ -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"
Expand Down
9 changes: 7 additions & 2 deletions src/rois.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down
43 changes: 22 additions & 21 deletions src/shorthands.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

"""
Expand Down Expand Up @@ -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

"""
Expand All @@ -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

"""
Expand All @@ -235,15 +236,15 @@ rand(5, 4, 7, 1, 2) = in_view5d
```
"""
macro ve(exs...)
do_start(exs; mystarter=ve)
do_start(exs; mystarter=ve)
end

"""
@vp expressions
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

"""
Expand All @@ -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

"""
Expand All @@ -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:
Expand Down
11 changes: 7 additions & 4 deletions src/viewer_core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
11 changes: 5 additions & 6 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -50,15 +49,15 @@ 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
@vp data3; # new phase viewer
@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
Expand Down

2 comments on commit 96491f3

@RainerHeintzmann
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/106323

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.0 -m "<description of version>" 96491f3a41476e91d91fa034c54b36bfb4aa1a6e
git push origin v0.5.0

Please sign in to comment.