From eb683ec845ce36210f09ec02731f0ecf3bddc609 Mon Sep 17 00:00:00 2001 From: BrianGun Date: Thu, 29 Apr 2021 17:18:33 -0700 Subject: [PATCH 01/17] Draw glass map Fixes #163 got basic scatter plot done but there are weird values in the NIKON glass catalog that are messing things up. --- src/GlassCat/GlassCat.jl | 2 ++ src/GlassCat/utilities.jl | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/GlassCat/GlassCat.jl b/src/GlassCat/GlassCat.jl index c5bcc8a30..b2be8a3e8 100644 --- a/src/GlassCat/GlassCat.jl +++ b/src/GlassCat/GlassCat.jl @@ -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") diff --git a/src/GlassCat/utilities.jl b/src/GlassCat/utilities.jl index ee646e62a..3ff366229 100644 --- a/src/GlassCat/utilities.jl +++ b/src/GlassCat/utilities.jl @@ -318,3 +318,24 @@ function plot_indices(glass::AbstractGlass; polyfit::Bool = false, fiterror::Boo gui(p) end + + +""" Draw a scatter plot of index vs dispersion at wavelength λ """ +function drawglassmap(glasscatalog::Module; λ = 550nm) + wavelength = Float64(ustrip(uconvert(u"μm", λ))) + indices = Vector{Float64}(undef,0) + dispersions = Vector{Float64}(undef,0) + glassnames = Vector{Symbol}(undef,0) + + for name in names(glasscatalog) + glass = eval(:($glasscatalog.$name)) + if typeof(glass) !== Module + f(x) = index(glass,x) + push!(indices,index(glass,wavelength)) + g = x -> ForwardDiff.derivative(f, x); + push!(dispersions, g(wavelength)) + end + end + scatter(indices,dispersions) + return indices +end \ No newline at end of file From 42884145639d4f0f58f265124db94dc1961e4cfb Mon Sep 17 00:00:00 2001 From: BrianGun Date: Thu, 29 Apr 2021 19:01:56 -0700 Subject: [PATCH 02/17] glassmap drawing is working. Could be improved to show popup menu of glasses that have nearly identical [index,dispersion] points so the names don't overlap. Still need to figure out how to get markers not to draw in scatter plot. Setting markershape = :none doesn't work. --- src/GlassCat/utilities.jl | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/GlassCat/utilities.jl b/src/GlassCat/utilities.jl index 3ff366229..bd1911135 100644 --- a/src/GlassCat/utilities.jl +++ b/src/GlassCat/utilities.jl @@ -320,22 +320,26 @@ function plot_indices(glass::AbstractGlass; polyfit::Bool = false, fiterror::Boo end -""" Draw a scatter plot of index vs dispersion at wavelength λ """ -function drawglassmap(glasscatalog::Module; λ = 550nm) +""" 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.""" +function drawglassmap(glasscatalog::Module; λ = 550nm, glassfontsize = 3, showprefixglasses = false) wavelength = Float64(ustrip(uconvert(u"μm", λ))) indices = Vector{Float64}(undef,0) dispersions = Vector{Float64}(undef,0) - glassnames = Vector{Symbol}(undef,0) + glassnames = Vector{String}(undef,0) for name in names(glasscatalog) glass = eval(:($glasscatalog.$name)) - if typeof(glass) !== Module + glassstring = String(name) + hasprefix = occursin("_",glassstring) + + if typeof(glass) !== Module && index(glass,wavelength) > 0 && index(glass,wavelength) < 3 && (showprefixglasses ? true : !hasprefix) f(x) = index(glass,x) push!(indices,index(glass,wavelength)) g = x -> ForwardDiff.derivative(f, x); - push!(dispersions, g(wavelength)) + push!(dispersions, -g(wavelength)) + push!(glassnames,String(name)) end end - scatter(indices,dispersions) - return indices + 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, markershape = :none) end \ No newline at end of file From 26ff724fa7518fd78d428e646c6815a14157d5a3 Mon Sep 17 00:00:00 2001 From: BrianGun Date: Thu, 29 Apr 2021 17:18:33 -0700 Subject: [PATCH 03/17] Draw glass map Fixes #163 got basic scatter plot done but there are weird values in the NIKON glass catalog that are messing things up. --- src/GlassCat/GlassCat.jl | 2 ++ src/GlassCat/utilities.jl | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/GlassCat/GlassCat.jl b/src/GlassCat/GlassCat.jl index c5bcc8a30..b2be8a3e8 100644 --- a/src/GlassCat/GlassCat.jl +++ b/src/GlassCat/GlassCat.jl @@ -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") diff --git a/src/GlassCat/utilities.jl b/src/GlassCat/utilities.jl index ee646e62a..3ff366229 100644 --- a/src/GlassCat/utilities.jl +++ b/src/GlassCat/utilities.jl @@ -318,3 +318,24 @@ function plot_indices(glass::AbstractGlass; polyfit::Bool = false, fiterror::Boo gui(p) end + + +""" Draw a scatter plot of index vs dispersion at wavelength λ """ +function drawglassmap(glasscatalog::Module; λ = 550nm) + wavelength = Float64(ustrip(uconvert(u"μm", λ))) + indices = Vector{Float64}(undef,0) + dispersions = Vector{Float64}(undef,0) + glassnames = Vector{Symbol}(undef,0) + + for name in names(glasscatalog) + glass = eval(:($glasscatalog.$name)) + if typeof(glass) !== Module + f(x) = index(glass,x) + push!(indices,index(glass,wavelength)) + g = x -> ForwardDiff.derivative(f, x); + push!(dispersions, g(wavelength)) + end + end + scatter(indices,dispersions) + return indices +end \ No newline at end of file From b7f2e3169eccf263ce0e505d3636acf4d1900d6a Mon Sep 17 00:00:00 2001 From: BrianGun Date: Thu, 29 Apr 2021 19:01:56 -0700 Subject: [PATCH 04/17] glassmap drawing is working Could be improved to show popup menu of glasses that have nearly identical [index,dispersion] points so the names don't overlap. Still need to figure out how to get markers not to draw in scatter plot. Setting markershape = :none doesn't work. --- src/GlassCat/utilities.jl | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/GlassCat/utilities.jl b/src/GlassCat/utilities.jl index 3ff366229..bd1911135 100644 --- a/src/GlassCat/utilities.jl +++ b/src/GlassCat/utilities.jl @@ -320,22 +320,26 @@ function plot_indices(glass::AbstractGlass; polyfit::Bool = false, fiterror::Boo end -""" Draw a scatter plot of index vs dispersion at wavelength λ """ -function drawglassmap(glasscatalog::Module; λ = 550nm) +""" 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.""" +function drawglassmap(glasscatalog::Module; λ = 550nm, glassfontsize = 3, showprefixglasses = false) wavelength = Float64(ustrip(uconvert(u"μm", λ))) indices = Vector{Float64}(undef,0) dispersions = Vector{Float64}(undef,0) - glassnames = Vector{Symbol}(undef,0) + glassnames = Vector{String}(undef,0) for name in names(glasscatalog) glass = eval(:($glasscatalog.$name)) - if typeof(glass) !== Module + glassstring = String(name) + hasprefix = occursin("_",glassstring) + + if typeof(glass) !== Module && index(glass,wavelength) > 0 && index(glass,wavelength) < 3 && (showprefixglasses ? true : !hasprefix) f(x) = index(glass,x) push!(indices,index(glass,wavelength)) g = x -> ForwardDiff.derivative(f, x); - push!(dispersions, g(wavelength)) + push!(dispersions, -g(wavelength)) + push!(glassnames,String(name)) end end - scatter(indices,dispersions) - return indices + 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, markershape = :none) end \ No newline at end of file From a8db36cfb2ed2f96544da20e060c23ccc8f4aa93 Mon Sep 17 00:00:00 2001 From: Alfred Wong Date: Fri, 30 Apr 2021 10:20:30 +0100 Subject: [PATCH 05/17] clean up * whitespace * export glasscatmap * format docstring * typed function signature * u"nm" -> nm * chained comparisons and simplified boolean expression --- src/GlassCat/GlassCat.jl | 2 +- src/GlassCat/utilities.jl | 26 +++++++++++++++++--------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/GlassCat/GlassCat.jl b/src/GlassCat/GlassCat.jl index b2be8a3e8..7e34494cc 100644 --- a/src/GlassCat/GlassCat.jl +++ b/src/GlassCat/GlassCat.jl @@ -40,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, glasscatmap # include utility functions for maintaining the AGF source list include("sources.jl") diff --git a/src/GlassCat/utilities.jl b/src/GlassCat/utilities.jl index bd1911135..d79734680 100644 --- a/src/GlassCat/utilities.jl +++ b/src/GlassCat/utilities.jl @@ -319,10 +319,17 @@ 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 λ. -""" 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.""" -function drawglassmap(glasscatalog::Module; λ = 550nm, glassfontsize = 3, showprefixglasses = false) - wavelength = Float64(ustrip(uconvert(u"μm", λ))) +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. +""" +function drawglassmap(glasscatalog::Module; λ::Length = 550nm, glassfontsize::Integer = 3, showprefixglasses::Bool = false) + wavelength = Float64(ustrip(uconvert(μm, λ))) indices = Vector{Float64}(undef,0) dispersions = Vector{Float64}(undef,0) glassnames = Vector{String}(undef,0) @@ -330,16 +337,17 @@ function drawglassmap(glasscatalog::Module; λ = 550nm, glassfontsize = 3, showp for name in names(glasscatalog) glass = eval(:($glasscatalog.$name)) glassstring = String(name) - hasprefix = occursin("_",glassstring) - - if typeof(glass) !== Module && index(glass,wavelength) > 0 && index(glass,wavelength) < 3 && (showprefixglasses ? true : !hasprefix) + hasprefix = occursin("_", glassstring) + + if !(glass isa Module) && 0 < index(glass, wavelength) < 3 && (!hasprefix || showprefixglasses) f(x) = index(glass,x) push!(indices,index(glass,wavelength)) g = x -> ForwardDiff.derivative(f, x); push!(dispersions, -g(wavelength)) - push!(glassnames,String(name)) + push!(glassnames, String(name)) 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, markershape = :none) -end \ No newline at end of file + scatter(dispersions,indices, xaxis = "dispersion", yaxis = "index", series_annotations = series_annotations, markersize = .001, legends = :none, markershape = :none) +end From 97b0e837df72acc300d1106533259c47d84c7542 Mon Sep 17 00:00:00 2001 From: BrianGun Date: Fri, 30 Apr 2021 12:02:03 -0700 Subject: [PATCH 06/17] changed export to export drawglassmap instead of glasscatmap, which is an old name for the function. --- src/GlassCat/GlassCat.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GlassCat/GlassCat.jl b/src/GlassCat/GlassCat.jl index 7e34494cc..a387c3b37 100644 --- a/src/GlassCat/GlassCat.jl +++ b/src/GlassCat/GlassCat.jl @@ -40,7 +40,7 @@ include("search.jl") export glasscatalogs, glassnames, findglass include("utilities.jl") -export plot_indices, index, polyfit_indices, absairindex, absorption, glasscatmap +export plot_indices, index, polyfit_indices, absairindex, absorption, drawglassmap # include utility functions for maintaining the AGF source list include("sources.jl") From 6f756e31044049064583e9d5445d90ef28399ae8 Mon Sep 17 00:00:00 2001 From: BrianGun Date: Fri, 30 Apr 2021 12:10:12 -0700 Subject: [PATCH 07/17] Draw glass map Fixes #163 added title to glass catalog map --- src/GlassCat/utilities.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GlassCat/utilities.jl b/src/GlassCat/utilities.jl index 53f8c4633..4a8a70246 100644 --- a/src/GlassCat/utilities.jl +++ b/src/GlassCat/utilities.jl @@ -349,5 +349,5 @@ function drawglassmap(glasscatalog::Module; λ::Length = 550nm, glassfontsize::I 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, markershape = :none) + scatter(dispersions,indices, xaxis = "dispersion", yaxis = "index", series_annotations = series_annotations, markersize = .001, legends = :none, markershape = :none, title = "$NIKON Glass Catalog") end From c23c634ea5d79952cd3cbf90fd9190a42924d676 Mon Sep 17 00:00:00 2001 From: BrianGun Date: Fri, 30 Apr 2021 12:15:51 -0700 Subject: [PATCH 08/17] mode to documentation for drawglassmap --- src/GlassCat/utilities.jl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/GlassCat/utilities.jl b/src/GlassCat/utilities.jl index 4a8a70246..af36144cf 100644 --- a/src/GlassCat/utilities.jl +++ b/src/GlassCat/utilities.jl @@ -328,8 +328,10 @@ 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 as high as 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) +function drawglassmap(glasscatalog::Module; λ::Length = 550nm, glassfontsize::Integer = 3, showprefixglasses::Bool = false, maximumindex = 3.0) wavelength = Float64(ustrip(uconvert(μm, λ))) indices = Vector{Float64}(undef,0) dispersions = Vector{Float64}(undef,0) @@ -340,7 +342,7 @@ function drawglassmap(glasscatalog::Module; λ::Length = 550nm, glassfontsize::I glassstring = String(name) hasprefix = occursin("_",glassstring) - if typeof(glass) !== Module && index(glass,wavelength) > 0 && index(glass,wavelength) < 3 && (showprefixglasses ? true : !hasprefix) + if typeof(glass) !== Module && index(glass,wavelength) > 1.0 && index(glass,wavelength) < maximumindex && (showprefixglasses ? true : !hasprefix) f(x) = index(glass,x) push!(indices,index(glass,wavelength)) g = x -> ForwardDiff.derivative(f, x); @@ -349,5 +351,5 @@ function drawglassmap(glasscatalog::Module; λ::Length = 550nm, glassfontsize::I 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, markershape = :none, title = "$NIKON Glass Catalog") + scatter(dispersions,indices, xaxis = "dispersion", yaxis = "index", series_annotations = series_annotations, markersize = .001, legends = :none, markershape = :none, title = "$glasscatalog Glass Catalog") end From f52af5833b697a75194cb3527332b2bbbe5907de Mon Sep 17 00:00:00 2001 From: BrianGun Date: Fri, 30 Apr 2021 16:04:34 -0700 Subject: [PATCH 09/17] changed sign on dispersion to make it mathematically correct. --- src/GlassCat/utilities.jl | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/GlassCat/utilities.jl b/src/GlassCat/utilities.jl index af36144cf..58e419a15 100644 --- a/src/GlassCat/utilities.jl +++ b/src/GlassCat/utilities.jl @@ -329,9 +329,9 @@ 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 as high as 6. To filter out these glasses set maximumindex to a reasonable value such as 3.0. +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. 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, maximumindex = 3.0) +function drawglassmap(glasscatalog::Module; λ::Length = 550nm, glassfontsize::Integer = 3, showprefixglasses::Bool = false, minimumindex = 1.0, maximumindex = 3.0) wavelength = Float64(ustrip(uconvert(μm, λ))) indices = Vector{Float64}(undef,0) dispersions = Vector{Float64}(undef,0) @@ -341,13 +341,17 @@ function drawglassmap(glasscatalog::Module; λ::Length = 550nm, glassfontsize::I glass = eval(:($glasscatalog.$name)) glassstring = String(name) hasprefix = occursin("_",glassstring) - - if typeof(glass) !== Module && index(glass,wavelength) > 1.0 && index(glass,wavelength) < maximumindex && (showprefixglasses ? true : !hasprefix) + + if typeof(glass) !== Module && index(glass,wavelength) > minimumindex && index(glass,wavelength) < maximumindex f(x) = index(glass,x) - push!(indices,index(glass,wavelength)) g = x -> ForwardDiff.derivative(f, x); - push!(dispersions, -g(wavelength)) - push!(glassnames,String(name)) + dispersion = g(wavelength) + + if 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). + 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))) From f28d9a2616ad0c4b0feef200fb667ed60557d740 Mon Sep 17 00:00:00 2001 From: BrianGun Date: Fri, 30 Apr 2021 16:21:32 -0700 Subject: [PATCH 10/17] added bounds on min and max dispersion, shortened argument names --- src/GlassCat/utilities.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/GlassCat/utilities.jl b/src/GlassCat/utilities.jl index 58e419a15..18757bf75 100644 --- a/src/GlassCat/utilities.jl +++ b/src/GlassCat/utilities.jl @@ -329,9 +329,9 @@ 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. To filter out these glasses set maximumindex to a reasonable value such as 3.0. +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, minimumindex = 1.0, maximumindex = 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) @@ -341,13 +341,13 @@ function drawglassmap(glasscatalog::Module; λ::Length = 550nm, glassfontsize::I glass = eval(:($glasscatalog.$name)) glassstring = String(name) hasprefix = occursin("_",glassstring) - - if typeof(glass) !== Module && index(glass,wavelength) > minimumindex && index(glass,wavelength) < maximumindex + + if typeof(glass) !== Module && (minindex <= index(glass,wavelength) <= maxindex) f(x) = index(glass,x) g = x -> ForwardDiff.derivative(f, x); dispersion = g(wavelength) - if 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). + 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). push!(indices,index(glass,wavelength)) push!(dispersions, dispersion) push!(glassnames,String(name)) From cda6f9ff7008ee9d0756964269230d089bc417ca Mon Sep 17 00:00:00 2001 From: BrianGun Date: Fri, 30 Apr 2021 16:22:23 -0700 Subject: [PATCH 11/17] changed title of plot --- src/GlassCat/utilities.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GlassCat/utilities.jl b/src/GlassCat/utilities.jl index 18757bf75..206df3ba8 100644 --- a/src/GlassCat/utilities.jl +++ b/src/GlassCat/utilities.jl @@ -355,5 +355,5 @@ function drawglassmap(glasscatalog::Module; λ::Length = 550nm, glassfontsize::I 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, markershape = :none, title = "$glasscatalog Glass Catalog") + scatter(dispersions,indices, xaxis = "dispersion", yaxis = "index", series_annotations = series_annotations, markersize = .001, legends = :none, markershape = :none, title = "Glass Catalog: $glasscatalog") end From 4f9ae669df8c82072bd9ca32b89ce59963938fb5 Mon Sep 17 00:00:00 2001 From: BrianGun Date: Fri, 30 Apr 2021 17:17:17 -0700 Subject: [PATCH 12/17] Draw glass map Fixes #163 set markeraplha = 0 so the marker shapes don't show up in the glassmap plot. --- src/GlassCat/utilities.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GlassCat/utilities.jl b/src/GlassCat/utilities.jl index 206df3ba8..a40a5fa50 100644 --- a/src/GlassCat/utilities.jl +++ b/src/GlassCat/utilities.jl @@ -355,5 +355,5 @@ function drawglassmap(glasscatalog::Module; λ::Length = 550nm, glassfontsize::I 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, markershape = :none, title = "Glass Catalog: $glasscatalog") + scatter(dispersions,indices, xaxis = "dispersion", yaxis = "index", series_annotations = series_annotations, markersize = .001, legends = :none, markeralpha = 0.0, markershape = :none, title = "Glass Catalog: $glasscatalog") end From 42787793a93534c340ea77e494fedfbbc1a347e6 Mon Sep 17 00:00:00 2001 From: Alfred Wong Date: Tue, 4 May 2021 09:45:39 +0100 Subject: [PATCH 13/17] add drawglassmap to docs --- docs/src/glasscat.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/src/glasscat.md b/docs/src/glasscat.md index 435554756..631c0964a 100644 --- a/docs/src/glasscat.md +++ b/docs/src/glasscat.md @@ -113,6 +113,7 @@ OpticSim.GlassCat.glassforid ```@docs OpticSim.GlassCat.polyfit_indices OpticSim.GlassCat.plot_indices +OpticSim.GlassCat.drawglassmap ``` --- From 79d0465d3478dbc65eb7db56bfda3490c91c5865 Mon Sep 17 00:00:00 2001 From: Alfred Wong Date: Tue, 4 May 2021 10:12:22 +0100 Subject: [PATCH 14/17] formatting --- src/GlassCat/utilities.jl | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/GlassCat/utilities.jl b/src/GlassCat/utilities.jl index a40a5fa50..539c56913 100644 --- a/src/GlassCat/utilities.jl +++ b/src/GlassCat/utilities.jl @@ -329,7 +329,9 @@ 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. +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, λ))) @@ -340,20 +342,24 @@ function drawglassmap(glasscatalog::Module; λ::Length = 550nm, glassfontsize::I for name in names(glasscatalog) glass = eval(:($glasscatalog.$name)) glassstring = String(name) - hasprefix = occursin("_",glassstring) + hasprefix = occursin("_", glassstring) - if typeof(glass) !== Module && (minindex <= index(glass,wavelength) <= maxindex) + 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). - push!(indices,index(glass,wavelength)) + # don't show glasses that have an _ in the name. This prevents cluttering the map with many glasses of + # similar (index, dispersion). + if (mindispersion <= dispersion <= maxdispersion) && (showprefixglasses ? true : !hasprefix) + push!(indices, index(glass, wavelength)) push!(dispersions, dispersion) - push!(glassnames,String(name)) + 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") + + font = Plots.font(family = "Sans", pointsize = glassfontsize, color = RGB(0.0,0.0,.4)) + series_annotations = Plots.series_annotations(glassnames, font) + scatter(dispersions, indices, xaxis = "dispersion", yaxis = "index", series_annotations = series_annotations, markersize = .001, legends = :none, markeralpha = 0.0, markershape = :none, title = "Glass Catalog: $glasscatalog") end From 0a80b7951a19cd8fa3db099ee183db5f35865fcf Mon Sep 17 00:00:00 2001 From: Alfred Wong Date: Tue, 4 May 2021 10:17:06 +0100 Subject: [PATCH 15/17] remove ternary expression and unecessary(?) scatter args --- src/GlassCat/utilities.jl | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/GlassCat/utilities.jl b/src/GlassCat/utilities.jl index 539c56913..c0574b97a 100644 --- a/src/GlassCat/utilities.jl +++ b/src/GlassCat/utilities.jl @@ -351,7 +351,7 @@ function drawglassmap(glasscatalog::Module; λ::Length = 550nm, glassfontsize::I # don't show glasses that have an _ in the name. This prevents cluttering the map with many glasses of # similar (index, dispersion). - if (mindispersion <= dispersion <= maxdispersion) && (showprefixglasses ? true : !hasprefix) + if (mindispersion <= dispersion <= maxdispersion) && (showprefixglasses || !hasprefix) push!(indices, index(glass, wavelength)) push!(dispersions, dispersion) push!(glassnames, String(name)) @@ -361,5 +361,13 @@ function drawglassmap(glasscatalog::Module; λ::Length = 550nm, glassfontsize::I font = Plots.font(family = "Sans", pointsize = glassfontsize, color = RGB(0.0,0.0,.4)) series_annotations = Plots.series_annotations(glassnames, font) - scatter(dispersions, indices, xaxis = "dispersion", yaxis = "index", series_annotations = series_annotations, markersize = .001, legends = :none, markeralpha = 0.0, markershape = :none, title = "Glass Catalog: $glasscatalog") + scatter( + dispersions, + indices; + series_annotations, + markeralpha = 0.0, + legends = :none, + xaxis = "dispersion", + yaxis = "index", + title = "Glass Catalog: $glasscatalog") end From 2d3dec96501f99c7b7a3bae2a0aff1c269c07edb Mon Sep 17 00:00:00 2001 From: Alfred Wong Date: Tue, 4 May 2021 12:13:55 +0100 Subject: [PATCH 16/17] escape underscores in docstring --- src/GlassCat/utilities.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/GlassCat/utilities.jl b/src/GlassCat/utilities.jl index c0574b97a..a1dab7b53 100644 --- a/src/GlassCat/utilities.jl +++ b/src/GlassCat/utilities.jl @@ -326,8 +326,8 @@ end 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. +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 From 7b35f82998c032bc8b5bf540173de22831e8005e Mon Sep 17 00:00:00 2001 From: BrianGun Date: Wed, 5 May 2021 14:05:30 -0700 Subject: [PATCH 17/17] Draw glass map Fixes #163 added comment explaining markeraplha = 0 argument to scatter. --- src/GlassCat/utilities.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GlassCat/utilities.jl b/src/GlassCat/utilities.jl index a1dab7b53..d76596147 100644 --- a/src/GlassCat/utilities.jl +++ b/src/GlassCat/utilities.jl @@ -369,5 +369,5 @@ function drawglassmap(glasscatalog::Module; λ::Length = 550nm, glassfontsize::I legends = :none, xaxis = "dispersion", yaxis = "index", - title = "Glass Catalog: $glasscatalog") + title = "Glass Catalog: $glasscatalog") #should use markershape = :none to prevent markers from being drawn but this option doesn't work. Used markeralpha = 0 so the markers are invisible. A hack which works. end