from pykat import finesse # import the whole pykat.finesse package
from pykat.commands import * # import all packages in pykat.commands
import numpy as np # for basic math/sci/array functions
import matplotlib.pyplot as plt # for plotting
import scipy # for analysing the plots
# tell the notebook to automatically show plots inline below each cell
%matplotlib inline
# use pykat's plotting style. change dpi to change plot sizes on your screen
pykat.init_pykat_plotting(dpi=90)
basecode = """
l laser 0.005 0 n0 # Laser (Power = 5 mW, wavelength offset = 0)
s s1 0.5 n0 nc1
## The cavity ##
m m1 0.99 0.01 0 nc1 nc2 # Mirror (R = 0.99, T = 0.01, phi = 0)
s sL 1 nc2 nc3 # Space (Length = 1 m)
m m2 0.99 0.01 0.01 nc3 nc4 # Mirror (R = 0.99, T = 0.01, phi = 0)
fsig signal1 m2 phase 1000 0
"""
#initialise Finesse with a new empty kat object
basekat = finesse.kat()
#tell Finesse to talk less
basekat.verbose = False
#parse the Finesse code into PyKat
basekat.parse(basecode)
kat1 = deepcopy(basekat)
newcode1 = """
# pd1 tran $fs nc4
pd1 tran 0 nc4
xaxis signal1 f log 100 100k 1000
put tran f1 $x1
yaxis abs:deg
"""
kat1.parse(newcode1)
out1 = kat1.run()
out1.plot()
kat2 = deepcopy(basekat)
newcode2 = """
pd tran nc4
xaxis m2 phi lin -10 10 1000
yaxis abs
"""
kat2.parse(newcode2)
out2 = kat2.run()
out2.plot()