11using FluorophoreColors
22using Test
33
4+ # interacts via @require
5+ using StructArrays
6+
47@testset " FluorophoreColors.jl" begin
58 @test isempty (detect_ambiguities (FluorophoreColors))
69
@@ -27,6 +30,7 @@ using Test
2730 @test c. channels[1 ] == c. channels[2 ] == 0.5
2831 @test convert (RGB, c) ≈ 0.5 * channels[1 ] + 0.5 * channels[2 ]
2932
33+ # Macro syntax & inferrability
3034 f_infer (i1, i2) = ColorMixture {N0f8} ((fluorophore_rgb " EGFP" , fluorophore_rgb " tdTomato" ), (i1, i2))
3135 f_noinfer (i1, i2) = ColorMixture ((fluorophore_rgb[" EGFP" ], fluorophore_rgb[" tdTomato" ]), (i1, i2))
3236 @test f_infer (1 , 0 ) == f_noinfer (1 , 0 )
@@ -38,13 +42,45 @@ using Test
3842 f_infer16 (i1, i2) = ColorMixture {N0f16} ((fluorophore_rgb " EGFP" , fluorophore_rgb " tdTomato" ), (i1, i2))
3943 @test_broken @inferred f_infer16 (1 , 0 )
4044
45+ # Inferrability from a template
4146 ctmpl = ColorMixture (channels)
4247 @test @inferred (ctmpl (1 , 0 )) === ColorMixture {N0f8} (channels, (1 , 0 ))
4348 end
4449
50+ @testset " StructArrays" begin
51+ channels = (fluorophore_rgb[" EGFP" ], fluorophore_rgb[" tdTomato" ])
52+ ctemplate = ColorMixture (channels)
53+ green, red = N0f8[0.2 , 0.4 ], N0f8[0.8 , 0.6 ]
54+ soa = StructArray {typeof(ctemplate)} ((green, red))
55+ @test soa[1 ] === ctemplate (green[1 ], red[1 ])
56+ @test soa[2 ] === ctemplate (green[2 ], red[2 ])
57+ soa[1 ] = ctemplate ((0.5 , 0.0 ))
58+ @test green[1 ] === 0.5 N0f8
59+ @test red[1 ] === 0.0 N0f8
60+
61+ # Hyperspectral
62+ cols = FluorophoreColors. Colors. distinguishable_colors (16 , [RGB (0 ,0 ,0 )]; dropseed= true )
63+ ctemplate = ColorMixture {Float32} ((cols... ,))
64+ comps = collect (reshape ((0 : 31 )/ 32f0 , 16 , 2 ))
65+ compsr = reinterpret (reshape, typeof (ctemplate), comps)
66+ soa = StructArray {typeof(ctemplate)} (comps; dims= 1 )
67+ @test soa == compsr
68+ @test size (soa) == (2 ,)
69+ @test soa[1 ] == ctemplate (ntuple (i-> (i- 1 )/ 32 , 16 ))
70+ compst = collect (transpose (comps))
71+ soa = StructArray {typeof(ctemplate)} (compst; dims= 2 )
72+ @test soa[1 ] == ctemplate (ntuple (i-> (i- 1 )/ 32 , 16 ))
73+ end
74+
4575 @testset " IO" begin
4676 channels = (fluorophore_rgb[" EGFP" ], fluorophore_rgb[" tdTomato" ])
4777 c = ColorMixture (channels, (1 , 0 ))
4878 @test sprint (show, c) == " (1.0₁, 0.0₂)"
79+
80+ # Hyperspectral
81+ cols = FluorophoreColors. Colors. distinguishable_colors (16 , [RGB (0 ,0 ,0 )]; dropseed= true )
82+ ctemplate = ColorMixture {Float32} ((cols... ,))
83+ c = ctemplate ([i/ 16 for i = 0 : 15 ]. .. )
84+ @test sprint (show, c) == " (0.0₀₁, 0.0625₀₂, 0.125₀₃, 0.1875₀₄, 0.25₀₅, 0.3125₀₆, 0.375₀₇, 0.4375₀₈, 0.5₀₉, 0.5625₁₀, 0.625₁₁, 0.6875₁₂, 0.75₁₃, 0.8125₁₄, 0.875₁₅, 0.9375₁₆)"
4985 end
5086end
0 commit comments