Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jagot/sellmeier.jl
https://github.com/jagot/sellmeier.jl
Last synced: 6 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/jagot/sellmeier.jl
- Owner: jagot
- License: other
- Created: 2016-03-31T14:51:10.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2018-10-08T19:05:45.000Z (over 6 years ago)
- Last Synced: 2024-11-15T18:34:54.898Z (2 months ago)
- Language: Julia
- Size: 74.2 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.org
- License: LICENSE.md
Awesome Lists containing this project
README
#+TITLE: Sellmeier.jl
#+AUTHOR: Stefanos Carlström
#+EMAIL: [email protected][[https://travis-ci.org/jagot/Sellmeier.jl][https://travis-ci.org/jagot/Sellmeier.jl.svg?branch=master]]
[[https://coveralls.io/github/jagot/Sellmeier.jl?branch=master][https://coveralls.io/repos/github/jagot/Sellmeier.jl/badge.svg?branch=master]]
[[http://codecov.io/gh/jagot/Sellmeier.jl][http://codecov.io/gh/jagot/Sellmeier.jl/branch/master/graph/badge.svg]]#+PROPERTY: header-args:julia :session *julia-README*
Small library for the [[https://en.wikipedia.org/wiki/Sellmeier_equation][Sellmeier equation]], used to model the refractive
index of transparent media, as a function of wavelength.This is a [[https://github.com/jagot/LiterateOrg.jl][LiterateOrg.jl]] project. The documentation is found [[file:src/Sellmeier.org][within the code]].
* Usage
It is very simple to calculate the refractive index of e.g. BK7
glass at a specific wavelength, or a specific frequency:
#+BEGIN_SRC julia :exports both :results verbatim
using Sellmeier
using UnitfulBK7(800u"nm"), BK7(2u"THz")
#+END_SRC#+RESULTS:
: (1.5107762314198745, 1.812885348989345)It is equally easy to evaluate the refractive index over a range of
wavelengths:
#+BEGIN_SRC julia :exports code
λ = linspace(200u"nm",6.0u"μm", 1000)
n = [BK7.(λ) SiO2.(λ)]
#+END_SRC#+RESULTS:
#+BEGIN_SRC julia :exports none
using PyPlot
PyPlot.svg(true)function savefig_f(filename)
mkpath(dirname(filename))
savefig(filename, transparent=true)
filename
endno_units(x::Quantity, u) = x/u |> NoUnits
#+END_SRC#+RESULTS:
: no_units (generic function with 1 method)#+BEGIN_SRC julia :exports results :results file
figure("BK7 & SiO2")
clf()
plot(no_units.(λ, u"nm"), n)
xlabel(L"$\lambda$ [nm]")
ylabel(L"$n(\lambda)$")
legend(["BK7", L"SiO$_2$"])
title("Refractive index")
tight_layout()
savefig_f("figures/refractive-index.svg")
#+END_SRC#+RESULTS:
[[file:figures/refractive-index.svg]]** Dispersion through glass
#+BEGIN_SRC julia :exports code
λ = 500.0u"nm"
f₀ = u"c"/λ |> u"THz"
ω₀ = 2π*f₀
τ = 6.2u"fs" # Pulse duration, intensity FWHM
γ = τ^2/8log(2)f = linspace(0,30,2000)*f₀
ω = 2π*fÊ = exp.(-(ω-ω₀).^2*γ)
# We propagate the pulse through 200 μm of BK7. We also remove
# dispersion at the central frequency, to keep the pulse centred in
# the time window.
Ê′ = Ê.*dispersion(BK7, 200u"μm", f, f₀)
#+END_SRC#+RESULTS:
#+BEGIN_SRC julia :exports results :results file
time_domain(spectrum) = real(fftshift(ifft(spectrum)*√(length(spectrum))))E = time_domain(Ê)
E′ = time_domain(Ê′)
using DSPt = fftshift(fftfreq(length(f), ustrip(1.0/(f[2]-f[1]) .|> u"s")))*u"s"
t_ax = no_units.(t, u"fs")
f_ax = no_units.(ω, (2π*u"THz"))
sel = f_ax .< 2500figure("pulse")
clf()
subplot(311)
plot(t_ax, E)
plot(t_ax, E′)
xlabel(L"$t$ [fs]")
ylabel(L"$E(t)$ [arb.u.]")
gca()[:xaxis][:tick_top]()
gca()[:xaxis][:set_label_position]("top")
margins(0,0.1)
subplot(312)
plot(f_ax[sel], abs2.(Ê[sel]))
plot(f_ax[sel], abs2.(Ê′[sel]))
ylabel(L"$|\hat{E}(f)|^2$ [arb.u.]")
margins(0,0.1)
ax = gca()[:twinx]()
ax[:plot](f_ax[sel], BK7.(f)[sel], "k--")
ylabel(L"n(f)")
margins(0,0.1)
gca()[:set_xticklabels]([])
subplot(313)
plot(f_ax[sel], unwrap(angle.(Ê[sel])))
plot(f_ax[sel], unwrap(angle.(Ê′[sel])))
xlabel(L"$f$ [THz]")
ylabel(L"$\arg\{\hat{E}(f)\}$ [rad]")
margins(0,0.1)
tight_layout()
savefig_f("figures/dispersed-pulse.svg")
#+END_SRC#+RESULTS:
[[file:figures/dispersed-pulse.svg]]