Skip to content
This repository has been archived by the owner on Oct 23, 2022. It is now read-only.

Commit

Permalink
fix assert error in choosecluster (#360)
Browse files Browse the repository at this point in the history
* incorrect assert error in choosecluster
Fixes #359

* added unit test for choosecluster

* fixed generate_clusters() test

* Added hardcoded glasses to be used for examples to eliminate dependency on downloaded glasses. This was fragile and caused tests to sometimes fail.

* changed Example_ to Examples_ in various places.

* systems.jl in test suite has almost, but not quite, exact duplicate of otherexamples.jl. Which had the old SCHOTT glasses. Fixed to use hardcoded glasses.

* found a few more places that were using SCHOTT in tests that had to be replaced with locally defined glasses.

* incorrect assert error in choosecluster
Fixes #359

removed redefinition of Examples_N_BK7
  • Loading branch information
BrianGun authored Feb 7, 2022
1 parent 9997b5f commit 4f8986e
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/Examples/other_examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

export cooketriplet, doubleconvexlensonly


#Hardcode these glass types so this code will work even if it is not possible to download the glasses at build time.
const Examples_N_BK7 = GlassCat.Glass("$(@__MODULE__).Examples_N_BK7", 2, 1.03961212, 0.00600069867, 0.231792344, 0.0200179144, 1.01046945, 103.560653, 0.0, 0.0, NaN, NaN, 0.3, 2.5, 1.86e-6, 1.31e-8, -1.37e-11, 4.34e-7, 6.27e-10, 0.17, 20.0, -0.0009, 2.3, 1.0, 7.1, 1.0, 1, 1.0, [(0.3, 0.05, 25.0), (0.31, 0.25, 25.0), (0.32, 0.52, 25.0), (0.334, 0.78, 25.0), (0.35, 0.92, 25.0), (0.365, 0.971, 25.0), (0.37, 0.977, 25.0), (0.38, 0.983, 25.0), (0.39, 0.989, 25.0), (0.4, 0.992, 25.0), (0.405, 0.993, 25.0), (0.42, 0.993, 25.0), (0.436, 0.992, 25.0), (0.46, 0.993, 25.0), (0.5, 0.994, 25.0), (0.546, 0.996, 25.0), (0.58, 0.995, 25.0), (0.62, 0.994, 25.0), (0.66, 0.994, 25.0), (0.7, 0.996, 25.0), (1.06, 0.997, 25.0), (1.53, 0.98, 25.0), (1.97, 0.84, 25.0), (2.325, 0.56, 25.0), (2.5, 0.36, 25.0)], 1.5168, 2.3, 0.0, 0, 64.17, 0, 2.51, 0.0)

Expand All @@ -14,7 +15,6 @@ const Examples_N_SF2 = GlassCat.Glass("$(@__MODULE__).Examples_N_SF2", 2, 1.4734

const Examples_N_SF14 = GlassCat.Glass("$(@__MODULE__).Examples_N_SF14", 2, 1.69022361, 0.0130512113, 0.288870052, 0.061369188, 1.7045187, 149.517689, 0.0, 0.0, NaN, NaN, 0.365, 2.5, -5.56e-6, 7.09e-9, -1.09e-11, 9.85e-7, 1.39e-9, 0.287, 20.0, 0.013, 1.0, 2.2, 9.41, 1.0, 1, 1.0, [(0.365, 0.004, 25.0), (0.37, 0.04, 25.0), (0.38, 0.33, 25.0), (0.39, 0.61, 25.0), (0.4, 0.75, 25.0), (0.405, 0.79, 25.0), (0.42, 0.87, 25.0), (0.436, 0.91, 25.0), (0.46, 0.938, 25.0), (0.5, 0.964, 25.0), (0.546, 0.983, 25.0), (0.58, 0.987, 25.0), (0.62, 0.987, 25.0), (0.66, 0.987, 25.0), (0.7, 0.985, 25.0), (1.06, 0.998, 25.0), (1.53, 0.98, 25.0), (1.97, 0.88, 25.0), (2.325, 0.64, 25.0), (2.5, 0.57, 25.0)], 1.76182, 1.0, 0.0, 0, 26.53, 0, 3.118, 0.0)


"""
hemisphere()
Expand Down Expand Up @@ -83,6 +83,8 @@ function convexplano(::Type{T} = Float64) where {T<:Real}
)
end



function doubleconvex(frontradius::T, rearradius::T) where {T<:Real}
AxisymmetricOpticalSystem{T}(
DataFrame(
Expand All @@ -91,6 +93,7 @@ function doubleconvex(frontradius::T, rearradius::T) where {T<:Real}
# OptimizeRadius = [false, true, true, false],
Thickness = [convert(T, Inf64), convert(T, 10.0), convert(T, 57.8), missing],
# OptimizeThickness = [false, false, false, false],

Material = [Air, Examples_N_BK7, Air, missing],
SemiDiameter = [convert(T, Inf64), convert(T, 9.0), convert(T, 9.0), convert(T, 15.0)]
)
Expand Down
2 changes: 1 addition & 1 deletion src/RepeatingStructures/Multilens/Analysis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ function choosecluster(pupildiameter::Unitful.Length, lensletdiameter::Unitful.L
end

maxcluster = clusters[clusterindex](ratio*scale)
@assert Repeat.euclideandiameter(maxcluster) <= ustrip(mm,pupildiameter)
@assert isapprox(Repeat.euclideandiameter(maxcluster), ustrip(mm,pupildiameter))

scaledlensletdiameter = lensletdiameter*ratio
return (cluster = maxcluster, lensletdiameter = scaledlensletdiameter, packingdistance = pupildiameter * ustrip(mm, lensletdiameter))
Expand Down
12 changes: 12 additions & 0 deletions test/TestData/TestData.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ using Images
using Base: @.
using LinearAlgebra

#define glasses locally rather than relying on GlassCat. These tests used to rely on downloaded glasses which made the tests brittle.
#If a glass didn't download the test would fail.

const Examples_N_BK7 = GlassCat.Glass(GlassCat.GlassID(GlassCat.AGF, 885), 2, 1.03961212, 0.00600069867, 0.231792344, 0.0200179144, 1.01046945, 103.560653, 0.0, 0.0, NaN, NaN, 0.3, 2.5, 1.86e-6, 1.31e-8, -1.37e-11, 4.34e-7, 6.27e-10, 0.17, 20.0, -0.0009, 2.3, 1.0, 7.1, 1.0, 1, 1.0, [(0.3, 0.05, 25.0), (0.31, 0.25, 25.0), (0.32, 0.52, 25.0), (0.334, 0.78, 25.0), (0.35, 0.92, 25.0), (0.365, 0.971, 25.0), (0.37, 0.977, 25.0), (0.38, 0.983, 25.0), (0.39, 0.989, 25.0), (0.4, 0.992, 25.0), (0.405, 0.993, 25.0), (0.42, 0.993, 25.0), (0.436, 0.992, 25.0), (0.46, 0.993, 25.0), (0.5, 0.994, 25.0), (0.546, 0.996, 25.0), (0.58, 0.995, 25.0), (0.62, 0.994, 25.0), (0.66, 0.994, 25.0), (0.7, 0.996, 25.0), (1.06, 0.997, 25.0), (1.53, 0.98, 25.0), (1.97, 0.84, 25.0), (2.325, 0.56, 25.0), (2.5, 0.36, 25.0)], 1.5168, 2.3, 0.0, 0, 64.17, 0, 2.51, 0.0)

const Examples_N_SK16 =GlassCat.Glass(GlassCat.GlassID(GlassCat.AGF, 828), 2, 1.34317774, 0.00704687339, 0.241144399, 0.0229005, 0.994317969, 92.7508526, 0.0, 0.0, NaN, NaN, 0.31, 2.5, -2.37e-8, 1.32e-8, -1.29e-11, 4.09e-7, 5.17e-10, 0.17, 20.0, -0.0011, 3.2, 1.4, 6.3, 4.0, 1, 53.3, [(0.31, 0.02, 25.0), (0.32, 0.11, 25.0), (0.334, 0.4, 25.0), (0.35, 0.7, 25.0), (0.365, 0.86, 25.0), (0.37, 0.89, 25.0), (0.38, 0.93, 25.0), (0.39, 0.956, 25.0), (0.4, 0.97, 25.0), (0.405, 0.974, 25.0), (0.42, 0.979, 25.0), (0.436, 0.981, 25.0), (0.46, 0.984, 25.0), (0.5, 0.991, 25.0), (0.546, 0.994, 25.0), (0.58, 0.994, 25.0), (0.62, 0.993, 25.0), (0.66, 0.994, 25.0), (0.7, 0.996, 25.0), (1.06, 0.995, 25.0), (1.53, 0.973, 25.0), (1.97, 0.88, 25.0), (2.325, 0.54, 25.0), (2.5, 0.26, 25.0)], 1.62041, 3.3, 4.0, 0, 60.32, 0, 3.58, 0.0)


const Examples_N_SF2 = GlassCat.Glass(GlassCat.GlassID(GlassCat.AGF, 815), 2, 1.47343127, 0.0109019098, 0.163681849, 0.0585683687, 1.36920899, 127.404933, 0.0, 0.0, NaN, NaN, 0.365, 2.5, 3.1e-6, 1.75e-8, 6.62e-11, 7.51e-7, 8.99e-10, 0.277, 20.0, 0.0081, 1.0, 1.4, 6.68, 1.0, 1, 1.0, [(0.365, 0.007, 25.0), (0.37, 0.06, 25.0), (0.38, 0.4, 25.0), (0.39, 0.68, 25.0), (0.4, 0.83, 25.0), (0.405, 0.865, 25.0), (0.42, 0.926, 25.0), (0.436, 0.949, 25.0), (0.46, 0.961, 25.0), (0.5, 0.975, 25.0), (0.546, 0.986, 25.0), (0.58, 0.987, 25.0), (0.62, 0.984, 25.0), (0.66, 0.984, 25.0), (0.7, 0.987, 25.0), (1.06, 0.997, 25.0), (1.53, 0.984, 25.0), (1.97, 0.93, 25.0), (2.325, 0.76, 25.0), (2.5, 0.67, 25.0)], 1.64769, 1.2, 0.0, 0, 33.82, 0, 2.718, 0.0)

const Examples_N_SF14 = GlassCat.Glass(GlassCat.GlassID(GlassCat.AGF, 896), 2, 1.69022361, 0.0130512113, 0.288870052, 0.061369188, 1.7045187, 149.517689, 0.0, 0.0, NaN, NaN, 0.365, 2.5, -5.56e-6, 7.09e-9, -1.09e-11, 9.85e-7, 1.39e-9, 0.287, 20.0, 0.013, 1.0, 2.2, 9.41, 1.0, 1, 1.0, [(0.365, 0.004, 25.0), (0.37, 0.04, 25.0), (0.38, 0.33, 25.0), (0.39, 0.61, 25.0), (0.4, 0.75, 25.0), (0.405, 0.79, 25.0), (0.42, 0.87, 25.0), (0.436, 0.91, 25.0), (0.46, 0.938, 25.0), (0.5, 0.964, 25.0), (0.546, 0.983, 25.0), (0.58, 0.987, 25.0), (0.62, 0.987, 25.0), (0.66, 0.987, 25.0), (0.7, 0.985, 25.0), (1.06, 0.998, 25.0), (1.53, 0.98, 25.0), (1.97, 0.88, 25.0), (2.325, 0.64, 25.0), (2.5, 0.57, 25.0)], 1.76182, 1.0, 0.0, 0, 26.53, 0, 3.118, 0.0)

include("curves.jl")
include("surfaces.jl")
include("lenses.jl")
Expand Down
2 changes: 2 additions & 0 deletions test/TestData/other.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ reflectivethingrating(period, orders) = ThinGratingInterface(SVector(0.0, 1.0, 0
function multiHOE()
rect = Rectangle(5.0, 5.0, SVector(0.0, 0.0, 1.0), SVector(0.0, 0.0, 0.0))
inbeam = SVector(0.0, 0.0, -1.0), CollimatedBeam

int1 = HologramInterface(SVector(-5.0, 0.0, -20.0), ConvergingBeam, SVector(0.0, -1.0, -1.0), CollimatedBeam, 0.55, 100.0, OpticSim.GlassCat.Air, OpticSim.Examples.Examples_N_BK7, OpticSim.GlassCat.Air, OpticSim.GlassCat.Air, OpticSim.GlassCat.Air, 0.05, false)
int2 = HologramInterface(SVector(5.0, 0.0, -20.0), ConvergingBeam, SVector(0.0, 1.0, -1.0), CollimatedBeam, 0.55, 100.0, OpticSim.GlassCat.Air, OpticSim.Examples.Examples_N_BK7, OpticSim.GlassCat.Air, OpticSim.GlassCat.Air, OpticSim.GlassCat.Air, 0.05, false)

mint = MultiHologramInterface(int1, int2)
obj = MultiHologramSurface(rect, mint)
sys = CSGOpticalSystem(LensAssembly(obj), Rectangle(50.0, 50.0, SVector(0.0, 0.0, 1.0), SVector(0.0, 0.0, -20.0), interface = opaqueinterface()))
Expand Down
3 changes: 3 additions & 0 deletions test/TestData/systems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# See LICENSE in the project root for full license information.


#TODO this is redundant. Many of these systems are already defined in Examples.otherexamples.jl. We should only have one copy

function cooketriplet(::Type{T} = Float64) where {T<:Real}
return AxisymmetricOpticalSystem{T}(
DataFrame(
SurfaceType = ["Object", "Standard", "Standard", "Standard", "Stop", "Standard", "Standard", "Image"],
Radius = [Inf, 26.777, 66.604, -35.571, 35.571, 35.571, -26.777, Inf],
Thickness = [Inf, 4.0, 2.0, 4.0, 2.0, 4.0, 44.748, missing],

Material = [Air, OpticSim.Examples.Examples_N_SK16, Air, OpticSim.Examples.Examples_N_SF2, Air, OpticSim.Examples.Examples_N_SK16, Air, missing],
SemiDiameter = [Inf, 8.580, 7.513, 7.054, 6.033, 7.003, 7.506, 15.0]
)
Expand Down
19 changes: 19 additions & 0 deletions test/testsets/Repeat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,23 @@
@test all(coords .== 0)
@test tileindex == index
end

#verify that choosecluster assertion doesn't fire incorrectly
using Unitful,Unitful.DefaultSymbols
function generate_clusters()
freq = Vector{Int64}(undef,0)
subdivs = Vector{Tuple{Int64,Int64}}(undef,0)
areas = Vector(undef,0)

try
for cycles in 15:30
OpticSim.Repeat.Multilens.system_properties(15mm,(10mm,9mm),(100°,70°),3.5mm,.1,cycles)
end
catch err #if any errors then failure
return false
end
return true
end

@test generate_clusters() #shouldn't get assertion failures for any of the frequencies between 15:30
end

0 comments on commit 4f8986e

Please sign in to comment.