Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
finesse
pykat
Commits
bccb041c
Commit
bccb041c
authored
Nov 27, 2013
by
Daniel Brown
Browse files
adding in more gui fixes and another example
parent
64810bc8
Changes
8
Hide whitespace changes
Inline
Side-by-side
bin/test_aperture.py
View file @
bccb041c
...
...
@@ -17,10 +17,10 @@ xaxis m1 r_ap lin 0.1e-3 2e-3 10
kat
=
finesse
.
kat
(
kat_code
=
code
)
maxtem
=
np
.
arange
(
0
,
1
,
2
)
maxtem
=
np
.
arange
(
0
,
3
,
2
)
for
tem
in
maxtem
:
print
"Calculating maxtem "
,
tem
,
"..."
print
"Calculating maxtem "
,
tem
,
"..."
kat
.
maxtem
=
tem
r
=
kat
.
run
()
pl
.
plot
(
r
.
x
/
1e-3
,
r
.
y
,
label
=
"maxtem={0}"
.
format
(
tem
))
...
...
bin/test_plot.py
View file @
bccb041c
...
...
@@ -20,9 +20,9 @@ kat = finesse.kat(kat_code=code)
kat
.
add
(
cavity
(
'cav1'
,
'm1'
,
'n3'
,
'm2'
,
'n4'
))
kat
.
add
(
photodiode
(
'pd_cav'
,
'n4'
))
kat
.
add
(
photodiode
(
'pd_ref'
,
'n2'
))
kat
.
add
(
photodiode
(
'pd_trs'
,
'n5'
))
kat
.
add
(
photodiode
(
'pd_cav'
,
'n4'
,[]
))
kat
.
add
(
photodiode
(
'pd_ref'
,
'n2'
,[]
))
kat
.
add
(
photodiode
(
'pd_trs'
,
'n5'
,[]
))
kat
.
add
(
xaxis
(
"lin"
,
[
0
,
360
],
kat
.
m2
,
kat
.
m2
.
phi
,
100
))
...
...
bin/test_pykat_gui.py
View file @
bccb041c
...
...
@@ -16,7 +16,6 @@ l l1 1 0 0 n1
kat
=
finesse
.
kat
(
kat_code
=
code
)
kat
.
openGUI
()
bin/test_rad_pressure.py
0 → 100644
View file @
bccb041c
from
pykat
import
finesse
from
pykat.detectors
import
*
from
pykat.components
import
*
from
pykat.commands
import
*
from
pykat.structs
import
*
import
numpy
as
np
import
pylab
as
pl
code
=
"""
l l1 1 0 n1
m m1 0.99 0.01 0 n1 n2
s cav1 1200 n2 n3
m m2 0.99 0.01 -0.1 n3 n4
#attr m1 m 1# mech sus1
attr m2 m 1# mech sus1
fsig sig l1 amp 1 0 4
#ad car_refl 0 n1
ad up_refl 0 n1
ad low_refl 0 n1
#qd refl_A 0 0 n1
#qd refl_Q 0 90 n1
#qd tran_A 0 0 n4
#qd tran_Q 0 90 n4
put up_refl f $x1
put low_refl f $mx1
xaxis sig f log 1 10000 1000
yaxis log re:im
"""
kat
=
finesse
.
kat
(
kat_code
=
code
)
run
=
kat
.
run
(
printout
=
0
,
printerr
=
0
)
# using real and imag part compute the complex value of the upper and lower sidebands
a_up
=
run
.
y
[:,
0
]
+
run
.
y
[:,
1
]
*
1j
a_lo
=
run
.
y
[:,
2
]
+
run
.
y
[:,
3
]
*-
1j
pl
.
figure
()
pl
.
loglog
(
run
.
x
,
np
.
abs
(
a_up
+
a_lo
),
run
.
x
,
np
.
abs
((
a_up
-
a_lo
)
/
(
1j
)))
pl
.
xlabel
(
run
.
xlabel
)
pl
.
show
()
pl
.
figure
()
pl
.
loglog
(
run
.
x
,
np
.
abs
(
a_up
),
run
.
x
,
np
.
abs
(
a_lo
))
pl
.
xlabel
(
run
.
xlabel
)
pl
.
show
()
\ No newline at end of file
pykat/detectors.py
View file @
bccb041c
...
...
@@ -8,7 +8,6 @@ import exceptions
import
pykat.gui.resources
from
pykat.utils
import
*
from
pykat.gui.graphics
import
*
from
pykat.node_network
import
*
...
...
@@ -40,8 +39,8 @@ class Detector(object) :
def
getQGraphicsItem
(
self
):
return
None
def
getNode
(
self
):
return
self
.
_
_
node
;
def
getNode
s
(
self
):
return
[
self
.
_node
]
def
__getname
(
self
):
return
self
.
__name
...
...
@@ -49,6 +48,22 @@ class Detector(object) :
name
=
property
(
__getname
)
class
photodiode
(
Detector
):
class
demodulation
:
def
__init__
(
self
,
f
,
phase
):
self
.
frequency
=
f
self
.
phase
=
phase
def
__init__
(
self
,
name
,
node
,
demods
):
Detector
.
__init__
(
self
,
name
,
node
)
self
.
_num_demods
=
len
(
demods
)
for
d
in
demods
:
if
not
isinstance
(
d
,
photodiode
.
demodulation
):
raise
ValueError
(
"demods array has something other than a demodulation in it"
)
self
.
_demods
.
append
(
d
)
@
staticmethod
def
parseFinesseText
(
text
):
raise
NotImplementedError
(
"This function is not implemented"
)
...
...
@@ -71,7 +86,7 @@ class photodiode(Detector):
def
getQGraphicsItem
(
self
):
if
self
.
_svgItem
==
None
:
self
.
_svgItem
=
ComponentQGraphicsItem
(
":/resources/photodiode_red.svg"
,
self
,[(
-
20
,
0
,
self
.
node
)])
self
.
_svgItem
=
ComponentQGraphicsItem
(
":/resources/photodiode_red.svg"
,
self
,[(
-
5
,
11
,
self
.
_
node
)])
return
self
.
_svgItem
\ No newline at end of file
pykat/finesse.py
View file @
bccb041c
...
...
@@ -134,8 +134,23 @@ class kat(object):
parseCommands
(
f
.
readlines
())
def
parseCommands
(
self
,
commands
):
blockComment
=
False
for
line
in
commands
.
split
(
"
\n
"
):
if
len
(
line
.
strip
())
>
0
:
if
len
(
line
.
strip
())
>=
2
:
line
=
line
.
strip
()
# don't read comment lines
if
line
[
0
]
==
"#"
or
line
[
0
]
==
"%"
:
continue
# check if block comment is being used
if
not
blockComment
and
line
[
0
:
2
]
==
"/*"
:
blockComment
=
True
continue
elif
blockComment
and
line
[
0
:
2
]
==
"*/"
:
blockComment
=
False
continue
first
=
line
.
split
(
" "
,
1
)[
0
]
if
(
first
==
"m"
):
...
...
@@ -316,10 +331,18 @@ class kat(object):
hdr
=
outfile
.
readline
().
replace
(
'%'
,
''
).
replace
(
'
\n
'
,
''
).
split
(
','
)
data
=
np
.
loadtxt
(
filename
,
comments
=
'%'
)
rows
,
cols
=
data
.
shape
shape_len
=
len
(
data
.
shape
)
x
=
data
[:,
0
]
y
=
data
[:,
1
:
cols
].
squeeze
()
if
shape_len
>
1
:
rows
,
cols
=
data
.
shape
x
=
data
[:,
0
]
y
=
data
[:,
1
:
cols
].
squeeze
()
else
:
rows
=
1
cols
=
data
.
shape
[
0
]
x
=
data
[
0
]
y
=
data
[
1
:
cols
].
squeeze
()
return
[
x
,
y
,
hdr
]
...
...
@@ -386,21 +409,32 @@ class kat(object):
def
hasComponent
(
self
,
name
):
return
(
name
in
self
.
__components
)
def
getNewComponentName
(
self
,
prefix
):
'''
Returns a name for a component which hasn't already been added.
Returns [prefix] + number, where number is greater than 1. e.g.
if m1 exists getNewName('m') will return 'm2'
'''
def
_newName
(
self
,
container
,
prefix
):
n
=
1
name
=
"{0}{1}"
.
format
(
prefix
,
n
)
while
name
in
self
.
__components
:
while
name
in
container
:
n
+=
1
name
=
"{0}{1}"
.
format
(
prefix
,
n
)
return
name
def
getNewComponentName
(
self
,
prefix
):
'''
Returns a name for a component which hasn't already been added.
Returns [prefix] + number, where number is greater than 1. e.g.
if m1 exists getNewName('m') will return 'm2'
'''
return
self
.
_newName
(
self
.
__components
,
prefix
)
def
getNewDetectorName
(
self
,
prefix
):
'''
Returns a name for a component which hasn't already been added.
Returns [prefix] + number, where number is greater than 1. e.g.
if m1 exists getNewName('m') will return 'm2'
'''
return
self
.
_newName
(
self
.
__detectors
,
prefix
)
def
getNewNodeNames
(
self
,
prefix
,
N
=
1
):
'''
Returns a list of names for N number of nodes which haven't already been added.
...
...
pykat/gui/graphics.py
View file @
bccb041c
...
...
@@ -10,7 +10,7 @@ from PyQt4.Qt import *
import
pykat.components
import
exceptions
nsize
=
8
nsize
=
10
class
NodeQGraphicItem
(
QGraphicsRectItem
):
...
...
pykat/gui/gui.py
View file @
bccb041c
...
...
@@ -119,6 +119,14 @@ class pyKatGUI(QtGui.QMainWindow, qt_gui.Ui_MainWindow):
self
.
kat
.
add
(
l
)
self
.
addComponentToScene
(
l
,
x
,
y
)
def
addPhotodiode
(
self
,
x
,
y
):
name
=
self
.
kat
.
getNewDetectorName
(
'pd'
)
n
=
self
.
kat
.
getNewNodeNames
(
'n'
,
1
)
l
=
pykat
.
detectors
.
photodiode
(
name
,
n
[
0
],
[])
self
.
kat
.
add
(
l
)
self
.
addComponentToScene
(
l
,
x
,
y
)
class
pyKatGraphicsScene
(
QGraphicsScene
):
def
drawBackground
(
self
,
painter
,
rect
):
...
...
@@ -159,7 +167,7 @@ class pyKatGraphicsView(QGraphicsView):
def
contextMenuEvent
(
self
,
ev
):
pt
=
self
.
mapToScene
(
ev
.
pos
())
gui
=
self
.
parentWidget
().
parent
()
# get the main gui window
menu
=
QMenu
(
self
)
...
...
@@ -174,8 +182,8 @@ class pyKatGraphicsView(QGraphicsView):
action
=
addmenu
.
addAction
(
"Laser"
)
action
.
triggered
.
connect
(
functools
.
partial
(
gui
.
addLaser
,
pt
.
x
(),
pt
.
y
()))
addmenu
.
addAction
(
"
Beamsplitter
"
)
a
ddmenu
.
addAction
(
"Photodiode"
)
action
=
addmenu
.
addAction
(
"
Photodiode
"
)
a
ction
.
triggered
.
connect
(
functools
.
partial
(
gui
.
addPhotodiode
,
pt
.
x
(),
pt
.
y
())
)
item
=
self
.
scene
().
itemAt
(
pt
.
x
(),
pt
.
y
())
...
...
@@ -189,6 +197,7 @@ class pyKatGraphicsView(QGraphicsView):
if
isinstance
(
item
,
NodeQGraphicItem
):
menu
.
addSeparator
()
menu
.
addAction
(
"Disconnect"
)
menu
.
popup
(
ev
.
globalPos
());
...
...
@@ -248,7 +257,8 @@ class pyKatGraphicsView(QGraphicsView):
# then refresh the graphical items
qspace
.
refresh
()
qcomp
.
refresh
()
self
.
setCursor
(
QCursor
(
Qt
.
ArrowCursor
))
if
self
.
__marked
is
not
None
:
self
.
__marked
.
marked
=
False
...
...
@@ -256,8 +266,7 @@ class pyKatGraphicsView(QGraphicsView):
self
.
__marked
=
None
self
.
__selected_item
=
None
self
.
setCursor
(
QCursor
(
Qt
.
ArrowCursor
))
def
mouseMoveEvent
(
self
,
ev
):
if
self
.
__selected_item
!=
None
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment