This repository has been archived by the owner on Oct 23, 2022. It is now read-only.
/
search.jl
121 lines (108 loc) · 2.92 KB
/
search.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# MIT license
# Copyright (c) Microsoft Corporation. All rights reserved.
# See LICENSE in the project root for full license information.
"""
glasscatalogs()
Returns the complete list of glass catalogs available from GlassCat.
## Example
```julia-repl
julia> glasscatalogs()
41-element Array{Any,1}:
OpticSim.GlassCat.AMTIR
OpticSim.GlassCat.ANGSTROMLINK
OpticSim.GlassCat.APEL
OpticSim.GlassCat.ARCHER
OpticSim.GlassCat.ARTON
OpticSim.GlassCat.AUER_LIGHTING
OpticSim.GlassCat.BIREFRINGENT
⋮
```
"""
glasscatalogs() = _child_modules(GlassCat)
"""
glassnames(catalog::Module)
Returns the glass names available from a given catalog.
# Example
```julia-repl
julia> glassnames(GlassCat.CARGILLE)
3-element Array{Any,1}:
"OG0607"
"OG0608"
"OG081160"
```
"""
function glassnames(catalog::Module)
glass_names = names(catalog, all = true, imported = false)
glasses = []
for glass_name in glass_names
glass_name_str = string(glass_name)
if !occursin("#", glass_name_str) && glass_name_str != "eval" && glass_name_str != "include" && glass_name != nameof(catalog)
push!(glasses, glass_name)
end
end
return glasses
end
"""
glassnames()
Returns the glass names available from all catalogs.
# Example
```julia-repl
julia> glassnames()
6-element Array{Pair{Module,Array{Any,1}},1}:
OpticSim.GlassCat.CARGILLE => ["OG0607", "OG0608", "OG081160"]
OpticSim.GlassCat.HOYA => ["BAC4", "BACD11" … "TAFD65"]
OpticSim.GlassCat.NIKON => ["BAF10", "BAF11" … "_7054"]
OpticSim.GlassCat.OHARA => ["L_BAL35", "L_BAL35P" … "S_TIM8"]
OpticSim.GlassCat.SCHOTT => ["AF32ECO", "BAFN6" … "SFL6"]
OpticSim.GlassCat.SUMITA => ["BAF1", "BAF10" … "ZNSF8"]
```
"""
glassnames() = [m => glassnames(m) for m in _child_modules(GlassCat)]
"""
findglass(condition::Function) -> Vector{Glass}
Returns the list of glasses which satisfy `condition` where `condition::(Glass -> Bool)`.
# Example
```julia-repl
julia> findglass(x -> (x.Nd > 2.3 && x.λmin < 0.5 && x.λmax > 0.9))
8-element Array{GlassCat.Glass,1}:
BIREFRINGENT.TEO2_E
BIREFRINGENT.PBMOO4
BIREFRINGENT.LINBO3
INFRARED.CLEARTRAN_OLD
INFRARED.CLEARTRAN
INFRARED.SRTIO3
INFRARED.ZNS_BROAD
INFRARED.ZNS_VIS
```
"""
function findglass(condition::Function)
# TODO - make the condition easier to specify (accessor functions for fields?)
out = Vector{Glass}(undef, 0)
for g in AGF_GLASSES
if condition(g)
push!(out, g)
end
end
for g in OTHER_GLASSES
if condition(g)
push!(out, g)
end
end
return out
end
function _child_modules(m::Module)
ns = names(m, imported = false, all = true)
ms = []
for n in ns
if n != nameof(m)
try
x = Core.eval(m, n)
if x isa Module
push!(ms, x)
end
catch
end
end
end
return ms
end