%run pykat_notebook_defaults.py
pykat.init_pykat_plotting()
This is the first introduction notebook for the simulation sessions this week. This week we aim to introduce you to modelling gravitational wave detectors with Finesse. By the end of the week we hope to have taught you how to produce your own quantum noise limited sensitivity for a gravitational wave detector.
These sessions together will cover the following material:
Important reference material:
The topics of the first session today are:
You should have received instructions on how to install Python, Pykat, Finesse and these notebook files already. If these did not install correctly we will find out today and can hopefully fix that.
We are going to use the Python programming language, executed in the Jupyter notebooks. We have no time to study either of these in detail during the SIM sessions. I have provided some basic introduction and links for more information below.
Python is a powerful programming language which is particularly useful for fast development and scripting. We will use only a very small subset of Python's functionality. In particular, we will do simple mathematical operations (using the package Numpy), some simple string operations and we will plot output data.
I recommend that you do not try to learn Python in general right now, but search the web for a solution for each particular task. A good starting point, for example, is the A Crash Course in Python for Scientists.
More info can be found in:
These cells are just text, fomatted using Markdown: http://daringfireball.net/projects/markdown/syntax
Code cells are the main element in the Jupyter notebook. When you press 'shift+enter' the content of the cell will be evaluated as Python code and an output cell is created to display the result, see the simple examples below.
# Adding numbers
a=5
b=10
print(a+b)
# Joining strings together
one='red '
two='car'
print(one+two)
# Outputting sentences
r = 2
area = np.pi * r*r
print("This is a good way to present results: The area is {0:.1f} km^2".format(area))
You can use HTML commands and Latex commands (for example: $\Delta L = L_X - L_Y$) in the markdown cells. You can also generate HTML text with code, for example to highlight certain data:
a=5.512;
h=HTML('<b>This is bold: {0}</b>'.format(a));
display(h)
For any optical simulation it is very useful to prepare a sketch of the optical layout. We typically use Inkscape and the ComponentLibrary to prepare such sketches as Scalable Vector Graphics (svg files). Such files can be loaded into notebooks as shown below.
HTML('<img src="michelson01.svg" width=400 height=400/>')
Python provides a number of powerful plotting packages. We will be using inline plots based on the 'matplotlib' package. Examples and documentation can be found online, for example a notebook with good plotting examples, or this extensive lecture on plotting. A simple example is shown below.
x=np.linspace(1, 100, 10) # this creates a data vector with 10 elements
print("x = {0}".format(x))
y = x*x
plt.plot(x, y)
plt.title('A simple function')
plt.xlabel('x [some units]')
plt.ylabel('y [some other units]')
Important: If your plots are looking too big or too small then you will need to change the DPI setting to suit your monitor. At the top of this page is a line of code that looks like pykat.init_pykat_plotting(dpi=90)
, either increase of decrease this to find a scaling that suits you.
Finesse is an interferometer simulation software, developed for the design and commissioning of laser-interferometric gravitational wave detectors. As such it is optimised for modelling the main interferometers of LIGO, Virgo, GEO etc, but it is also a simple and versatile tool to learn basic laser optics. Examples and an extensive manual for Finesse can be found on the Finesse page.
PyKat is a Python wrapper for the interferometer simulation Finesse. This allows us to run Finesse from an Jupyter notebook. The main advantage of using Finesse in this way is that Python offers the ability to do post-processing of the Finesse output very easily in the notebook.
You should have a read of this notebook:
It should be used as a reference on how to use Pykat throughout this school.
Here we construct a simple Finesse model of a laser beam shining on a mirror. In this simulation we just vary the input laser power and see how much is reflected and transmitted. To measure the laser power we put two photodiodes on reflection and transmission at the mirror.
kat = finesse.kat()
kat.verbose = False
code = """
l laser1 1.0 0 n1
s s1 0 n1 n2
pd Prefl n2
pd Ptran n3
m m1 0.9 0.1 0 n2 n3
xaxis laser1 P lin 0 1 10
yaxis abs
"""
kat.parseCommands(code)
out1 = kat.run()
The data can be plotted in multiple ways. If quickly want to see the results we suggest using the builtin plotting command for the output:
# Plotting the results of an output can be done using the builtin command
fig = out1.plot()
This will produce a plot using all the detectors enabled in the model. It should be noted that the yaxis units is [au] because multiple quantities can be shown at the same time. For example, a beam's power in Watts can be plotted along with the size of a beam. Thus to infer the units of a trace you must look at what type of detector has been used.
The builtin plotting function has many options that can be set to customise the plot. For more examples on using this please see the notebook on plotting.
However, if you would rather make a plot yourself you can always just use matplotlib commands as per usual:
plt.plot(out1.x, out1["Prefl"], label="Refl")
plt.plot(out1.x, out1["Ptran"], label="Tran")
plt.xlim(out1.x.min(), out1.x.max())
plt.ylabel("Power [W]")
plt.xlabel("Laser power [W]")
plt.legend()
The out
object returned by run()
command is an important one as it contains all the results from the simulation. It is important to remember that when Finesse outputs some results it is just an array of numbers: the number of steps in the simulation set with the xaxis
and the outputted value of each of the detectors you have added.
You can see the raw outputs with:
print(out1.x) # show the xaxis values
print(out1.y)
As you can see, they are quite long and not easily readable. Here we just have one detector, however, if we have more we would have more columns of data. To find out which column is which you need to look at the out.ylabels
array:
print(out1.ylabels)
However, the recommended method for accessing the values of a particular detector is by using the detector's name as shown here:
out1["Prefl"]
In each notebook we will provide some tasks for you to complete. You should make a local copy of this notebook that you will edit. In each task section you should add your code you write to compelte the task. After the sessions we will have a show and tell from some students about how they did each task.
The following sections provide some simple tasks to get you back up and running with Finesse and Pykat. The aim here is not to full understand the simulation but to just get something running.
You should help each other, work in groups, organise yourselves and don't forget to ask for help if needed!
Don't worry about understanding any physics here, this example is just about getting something running correctly before we proceed.
(a) Copy the Finesse code for radiation pressure effects from the Finesse pages
(b) Load this into a kat
object as shown about and run it
model = finesse.kat()
model.parseCommands("""
# optical setup: laser, space and mirror:
l l1 1 0 n1
s s1 1 n1 n2
m m1 1 0 0 n2 n3
# define transfer function with pole at 10Hz and Q factor 1000
tf pendulum 1 0 p 10 1000
# apply transfer function to mirror as force->motion
attr m1 mass 1 zmech pendulum
# measuring the mirror longitudinal motion
xd m1_z m1 z
# generate amplitude modulation at the laser
fsig sig1 l1 amp 1 0
xaxis sig1 f log 1 100 400
yaxis log abs:deg
""")
out = kat.run()
Take the output generated when running the kat
object made in task 1 and plot all the outputs.
fig = out.plot()