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

Add glass map #164

Merged
merged 21 commits into from
May 6, 2021
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/GlassCat/GlassCat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ using Unitful
using StaticArrays
using Base: @.
import Unitful: Length, Temperature, Quantity, Units
using Unitful.DefaultSymbols
using Pkg
using ForwardDiff

include("constants.jl")

Expand All @@ -38,7 +40,7 @@ include("search.jl")
export glasscatalogs, glassnames, findglass

include("utilities.jl")
export plot_indices, index, polyfit_indices, absairindex, absorption
export plot_indices, index, polyfit_indices, absairindex, absorption, drawglassmap

# include utility functions for maintaining the AGF source list
include("sources.jl")
Expand Down
39 changes: 39 additions & 0 deletions src/GlassCat/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,42 @@ function plot_indices(glass::AbstractGlass; polyfit::Bool = false, fiterror::Boo

gui(p)
end


"""
drawglassmap(glasscatalog::Module; λ::Length = 550nm, glassfontsize::Integer = 3, showprefixglasses::Bool = false)

Draw a scatter plot of index vs dispersion (the derivative of index with respect to wavelength). Both index and
dispersion are computed at wavelength λ.

If showprefixglasses is true then glasses with names like F_BAK7 will be displayed. Otherwise glasses that have a
leading letter prefix followed by an underscore, such as F_, will not be displayed.

The index formulas for some glasses may give incorrect results if λ is outside the valid range for that glass. This can give anomalous results, such as indices less than zero or greater than 6. To filter out these glasses set maximumindex to a reasonable value such as 3.0.
"""
function drawglassmap(glasscatalog::Module; λ::Length = 550nm, glassfontsize::Integer = 3, showprefixglasses::Bool = false, minindex = 1.0, maxindex = 3.0, mindispersion = -.3, maxdispersion = 0.0)
wavelength = Float64(ustrip(uconvert(μm, λ)))
indices = Vector{Float64}(undef,0)
dispersions = Vector{Float64}(undef,0)
glassnames = Vector{String}(undef,0)

for name in names(glasscatalog)
glass = eval(:($glasscatalog.$name))
glassstring = String(name)
hasprefix = occursin("_",glassstring)
alfredclwong marked this conversation as resolved.
Show resolved Hide resolved

if typeof(glass) !== Module && (minindex <= index(glass,wavelength) <= maxindex)
f(x) = index(glass,x)
g = x -> ForwardDiff.derivative(f, x);
dispersion = g(wavelength)

if (mindispersion <= dispersion <= maxdispersion) && (showprefixglasses ? true : !hasprefix) #don't show glasses that have an _ in the name. This prevents cluttering the map with many glasses of similar (index,dispersion).
Copy link
Collaborator

Choose a reason for hiding this comment

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

I have a strong preference for the regular boolean expression (showprefixglasses || !hasprefix) as opposed to the ternary expression (showprefixglasses ? true : !hasprefix). Was there a reason for adding this back in?

push!(indices,index(glass,wavelength))
push!(dispersions, dispersion)
push!(glassnames,String(name))
end
end
end
series_annotations = Plots.series_annotations(glassnames, Plots.font(family = "Sans", pointsize = glassfontsize, color = RGB(0.0,0.0,.4)))
scatter(dispersions,indices, xaxis = "dispersion", yaxis = "index", series_annotations = series_annotations, markersize = .001, legends = :none, markeralpha = 0.0, markershape = :none, title = "Glass Catalog: $glasscatalog")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are markersize and markershape still needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no

end