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
bd378f92
Commit
bd378f92
authored
Dec 09, 2013
by
Andreas Freise
Browse files
Merge branch 'master' of gitmaster.atlas.aei.uni-hannover.de:pykat/pykat
parents
5a5c246a
2fecc0f6
Changes
9
Hide whitespace changes
Inline
Side-by-side
bin/test_aperture.py
View file @
bd378f92
...
...
@@ -28,7 +28,6 @@ for tem in maxtem:
r
=
kat
.
run
()
pl
.
plot
(
r
.
x
/
1e-3
,
r
.
y
,
label
=
"maxtem={0}"
.
format
(
tem
))
pl
.
ylabel
(
"Reflected Power [W]"
)
pl
.
xlabel
(
"Mirror aperture [mm]"
)
pl
.
legend
()
...
...
bin/test_pykat_gui.py
View file @
bd378f92
...
...
@@ -6,12 +6,13 @@ from pykat.detectors import *
from
pykat.components
import
*
from
pykat.commands
import
*
from
pykat.structs
import
*
#from pykat.plotting import *
import
numpy
as
np
import
pylab
as
pl
code
=
"""
l l1 1 0 0 n1
#l l1 1 0 0 n1
s s1 1 n3 n4
"""
kat
=
finesse
.
kat
(
kat_code
=
code
)
...
...
pykat/components.py
View file @
bd378f92
...
...
@@ -32,21 +32,21 @@ class NodeGaussSetter(object):
@
q
.
setter
def
q
(
self
,
value
):
self
.
__node
.
setGauss
(
self
.
__comp
,
value
)
self
.
__node
.
setGauss
(
self
.
__comp
,
complex
(
value
)
)
@
property
def
qx
(
self
):
return
self
.
__node
.
qx
@
qx
.
setter
def
qx
(
self
,
value
):
self
.
__node
.
setGauss
(
self
.
__comp
,
value
)
self
.
__node
.
setGauss
(
self
.
__comp
,
complex
(
value
)
)
@
property
def
qy
(
self
):
return
self
.
__node
.
qy
@
qy
.
setter
def
qy
(
self
,
value
):
self
.
__node
.
setGauss
(
self
.
__comp
,
self
.
qx
,
value
)
self
.
__node
.
setGauss
(
self
.
__comp
,
self
.
qx
,
complex
(
value
)
)
class
Component
(
object
)
:
def
__init__
(
self
,
name
):
...
...
@@ -94,8 +94,8 @@ class Component(object) :
# now we have a list of which to remove
for
key
in
key_rm
:
ns
=
self
.
__dict__
[
key
]
de
t
attr
(
self
,
'__nodesetter_'
+
ns
.
_
node
.
name
)
delattr
(
self
,
ns
.
_
node
.
name
)
de
l
attr
(
self
,
'__nodesetter_'
+
ns
.
node
.
name
)
delattr
(
self
.
__class__
,
ns
.
node
.
name
)
for
node
in
self
.
nodes
:
if
type
(
node
)
!=
pykat
.
node_network
.
DumpNode
:
...
...
@@ -313,22 +313,7 @@ class space(Component):
if
self
.
_QItem
==
None
:
self
.
_QItem
=
pykat
.
gui
.
graphics
.
SpaceQGraphicsItem
(
self
)
return
self
.
_QItem
# def changeNode(self, node_old, node_new):
# '''
# Called when a space's node has been connected
# to another components node
# '''
# node_new.connect(self)
# node_old.disconnect(self)
# if self._nodes[0] == node_old:
# self._nodes[0] = node_new
# if self._nodes[1] == node_old:
# self._nodes[1] = node_newf
return
self
.
_QItem
class
laser
(
Component
):
def
__init__
(
self
,
name
,
node
,
P
=
1
,
f_offset
=
0
,
phase
=
0
):
...
...
pykat/finesse.py
View file @
bd378f92
...
...
@@ -42,6 +42,9 @@ from pykat.components import Component
from
pykat.commands
import
Command
,
xaxis
from
pykat.gui.gui
import
pyKatGUI
from
PyQt4.QtCore
import
QCoreApplication
from
PyQt4.QtGui
import
QApplication
NO_GUI
=
False
NO_BLOCK
=
"NO_BLOCK"
...
...
@@ -474,12 +477,20 @@ class kat(object):
if
NO_GUI
:
print
"No PyQt4 module was installed so cannot open a GUI"
else
:
self
.
app
=
QCoreApplication
.
instance
()
created
=
False
if
self
.
app
==
None
:
created
=
True
self
.
app
=
QApplication
([
""
])
if
self
.
pykatgui
==
None
:
#self.app = QtGui.QApplication([""])
self
.
pykatgui
=
pyKatGUI
(
self
)
self
.
pykatgui
.
main
()
else
:
self
.
pykatgui
.
show
()
if
created
:
self
.
app
.
exec_
()
def
getComponents
(
self
):
return
self
.
__components
.
values
()
...
...
pykat/gui/graphics.py
View file @
bd378f92
...
...
@@ -8,6 +8,7 @@ Created on Fri Feb 01 09:13:03 2013
from
PyQt4.QtGui
import
*
from
PyQt4.Qt
import
*
from
PyQt4
import
QtSvg
from
PyQt4.QtSvg
import
QGraphicsSvgItem
import
pykat.components
import
exceptions
...
...
@@ -56,16 +57,16 @@ class SpaceQGraphicsItem(QGraphicsLineItem):
@
property
def
space
(
self
):
return
self
.
__space
def
refresh
(
self
):
nodes
=
self
.
__space
.
getN
odes
()
def
refresh
(
self
):
nodes
=
self
.
__space
.
n
odes
conn
=
nodes
[
0
].
amIConnected
(
self
.
__space
)
x1
=
0
y1
=
0
x2
=
0
y2
=
0
if
conn
[
0
]:
if
conn
[
1
]
!=
None
:
if
self
.
__n1
is
not
None
:
...
...
@@ -178,7 +179,7 @@ class ComponentQGraphicsItem(QtSvg.QGraphicsSvgItem):
def
itemChange
(
self
,
change
,
value
):
# if the item is moved then update any spaces attached to it
if
change
==
QGraphicsItem
.
ItemPositionHasChanged
:
nodes
=
self
.
__component
.
getN
odes
()
nodes
=
self
.
__component
.
n
odes
for
n
in
nodes
:
conn
=
n
.
amIConnected
(
self
.
__component
)
...
...
@@ -187,4 +188,4 @@ class ComponentQGraphicsItem(QtSvg.QGraphicsSvgItem):
conn
[
1
].
getQGraphicsItem
().
refresh
()
return
QGraphicsSvgItem
.
itemChange
(
self
,
change
,
value
)
\ No newline at end of file
pykat/gui/gui.py
View file @
bd378f92
...
...
@@ -5,7 +5,7 @@ Created on Tue Jan 29 11:35:48 2013
@author: Daniel
"""
from
pykat.components
import
Component
from
pykat.components
import
Component
,
space
from
pykat.detectors
import
Detector
from
PyQt4
import
QtGui
,
QtCore
...
...
@@ -16,11 +16,11 @@ import qt_gui
import
functools
class
pyKatGUI
(
QtGui
.
QMainWindow
,
qt_gui
.
Ui_MainWindow
):
def
__init__
(
self
,
kat
,
parent
=
None
):
def
__init__
(
self
,
kat
,
parent
=
None
):
super
(
pyKatGUI
,
self
).
__init__
(
parent
)
self
.
setupUi
(
self
)
self
.
graphicsView
=
pyKatGraphicsView
(
self
.
centralwidget
)
self
.
graphicsView
=
pyKatGraphicsView
(
self
.
centralwidget
,
kat
)
self
.
graphicsView
.
setObjectName
(
"graphicsView"
)
self
.
graphicsView
.
setViewportUpdateMode
(
QGraphicsView
.
FullViewportUpdate
)
self
.
graphicsView
.
viewport
().
setMouseTracking
(
True
)
...
...
@@ -41,8 +41,11 @@ class pyKatGUI(QtGui.QMainWindow, qt_gui.Ui_MainWindow):
self
.
actionExport_to_SVG
.
triggered
.
connect
(
lambda
:
self
.
exportToSVG
())
self
.
actionClose
.
triggered
.
connect
(
lambda
:
self
.
close
)
self
.
kat
=
kat
self
.
_
kat
=
kat
@
property
def
kat
(
self
):
return
self
.
_kat
def
main
(
self
):
self
.
show
()
...
...
@@ -52,7 +55,6 @@ class pyKatGUI(QtGui.QMainWindow, qt_gui.Ui_MainWindow):
return
self
.
__scene
def
addComponentsToScene
(
self
):
for
c
in
self
.
kat
.
getComponents
():
self
.
addComponentToScene
(
c
)
...
...
@@ -120,7 +122,27 @@ class pyKatGUI(QtGui.QMainWindow, qt_gui.Ui_MainWindow):
self
.
kat
.
add
(
l
)
self
.
addComponentToScene
(
l
,
x
,
y
)
def
disconnect
(
self
,
node
):
comps
=
self
.
kat
.
nodes
.
getNodeComponents
(
node
)
spaces
=
[
c
for
c
in
comps
if
isinstance
(
c
,
space
)]
if
len
(
spaces
)
>
0
:
dis_comp
=
spaces
[
0
]
else
:
dis_comp
=
comps
[
0
]
new_node_name
=
self
.
kat
.
getNewNodeNames
(
"n"
,
1
)
new_node
=
self
.
kat
.
nodes
.
createNode
(
new_node_name
[
0
])
self
.
kat
.
nodes
.
replaceNode
(
dis_comp
,
node
,
new_node
)
# refresh all the graphics that might be affected
for
c
in
node
.
components
+
new_node
.
components
:
if
c
!=
None
:
c
.
getQGraphicsItem
().
refresh
()
class
pyKatGraphicsScene
(
QGraphicsScene
):
def
drawBackground
(
self
,
painter
,
rect
):
size
=
10
...
...
@@ -149,9 +171,9 @@ class pyKatGraphicsScene(QGraphicsScene):
painter
.
drawLine
(
y
,
rect
.
top
(),
y
,
rect
.
bottom
())
class
pyKatGraphicsView
(
QGraphicsView
):
def
__init__
(
self
,
val
):
QGraphicsView
.
__init__
(
self
,
val
)
def
__init__
(
self
,
val
,
kat
):
QGraphicsView
.
__init__
(
self
,
val
)
self
.
_kat
=
kat
self
.
__selected_item
=
None
self
.
__prev_pt
=
None
self
.
setMouseTracking
(
True
)
...
...
@@ -189,8 +211,11 @@ class pyKatGraphicsView(QGraphicsView):
menu
.
addAction
(
"Delete"
)
if
isinstance
(
item
,
NodeQGraphicItem
):
menu
.
addSeparator
()
menu
.
addAction
(
"Disconnect"
)
comps
=
self
.
_kat
.
nodes
.
getNodeComponents
(
item
.
node
)
if
(
comps
.
count
(
None
)
==
0
):
action
=
menu
.
addAction
(
"Disconnect"
)
action
.
triggered
.
connect
(
functools
.
partial
(
gui
.
disconnect
,
item
.
node
))
menu
.
popup
(
ev
.
globalPos
());
...
...
@@ -244,8 +269,7 @@ class pyKatGraphicsView(QGraphicsView):
# connect space of node dragged to the component node
# the space node that has been dragged gets deleted and we
# replace it with the components
space
.
changeNode
(
node_s
,
node_c
)
node_s
.
remove
()
# now remove from node network completly
self
.
_kat
.
nodes
.
replaceNode
(
space
,
node_s
,
node_c
)
# then refresh the graphical items
qspace
.
refresh
()
...
...
pykat/node_network.py
View file @
bd378f92
...
...
@@ -9,6 +9,7 @@ import pykat.gui.graphics
import
pykat.exceptions
as
pkex
from
pykat.components
import
Component
from
pykat.detectors
import
Detector
from
pykat.utilities.optics.gaussian_beams
import
gauss_param
class
NodeNetwork
(
object
):
def
__init__
(
self
,
kat
):
...
...
@@ -47,17 +48,54 @@ class NodeNetwork(object):
change_callback
()
def
replaceNode
(
self
,
comp
,
node_old
,
node_new
):
if
node_new
.
components
.
count
(
None
)
==
0
:
raise
pkex
.
BasePyKatException
(
"New node already connected to two components"
)
if
comp
not
in
node_old
.
components
:
raise
pkex
.
BasePyKatException
(
"Old node not attached to component"
)
if
comp
in
node_new
.
components
:
raise
pkex
.
BasePyKatException
(
"New node already attached to component"
)
# add component to new node component list
new_node_comps
=
list
(
node_new
.
components
)
new_node_comps
[
new_node_comps
.
index
(
None
)]
=
comp
self
.
__nodeComponents
[
node_new
.
id
]
=
tuple
(
new_node_comps
)
# remove component from old node list
old_node_comps
=
list
(
node_old
.
components
)
old_node_comps
[
old_node_comps
.
index
(
comp
)]
=
None
self
.
__nodeComponents
[
node_old
.
id
]
=
tuple
(
old_node_comps
)
comp_nodes
=
list
(
comp
.
nodes
)
comp_nodes
[
comp_nodes
.
index
(
node_old
)]
=
node_new
self
.
__componentNodes
[
comp
.
id
]
=
tuple
(
comp_nodes
)
# if old node is no longer connected to anything then delete it
if
node_old
.
components
.
count
(
None
)
==
2
:
self
.
removeNode
(
node_old
)
self
.
__componentCallback
[
comp
.
id
]()
def
connectNodeToComp
(
self
,
node
,
comp
,
do_callback
=
True
):
if
node
.
id
in
self
.
__nodeComponents
:
comps
=
self
.
__nodeComponents
[
node
.
id
]
else
:
comps
=
(
)
comps
=
(
None
,)
*
2
if
len
(
comps
)
>=
2
:
if
len
(
comps
)
>=
2
and
comps
[
0
]
!=
None
and
comps
[
1
]
!=
None
:
raise
pkex
.
BasePyKatException
(
"Node is already connected to 2 components"
)
l
=
list
(
comps
)
l
.
append
(
comp
)
if
l
[
0
]
==
None
:
l
[
0
]
=
comp
elif
l
[
1
]
==
None
:
l
[
1
]
=
comp
else
:
raise
pkex
.
BasePyKatException
(
"Connected to two coponents already"
)
self
.
__nodeComponents
[
node
.
id
]
=
tuple
(
l
)
...
...
@@ -76,6 +114,7 @@ class NodeNetwork(object):
self
.
__node_id
+=
1
self
.
__add_node_attr
(
n
)
# add node as a member of this object, e.g. kat.nodes.n
self
.
__nodes
[
node_name
]
=
n
self
.
__nodeComponents
[
n
.
id
]
=
(
None
,
None
)
return
n
def
removeNode
(
self
,
node
):
...
...
@@ -133,8 +172,11 @@ class NodeNetwork(object):
print
"node: {0} connected:{1} {2}->{3} {4}"
.
format
(
n
.
name
,
n
.
isConnected
(),
comp1
,
comp2
,
detectors
)
def
getComponentNodes
(
self
,
comp
):
return
self
.
__componentNodes
[
comp
.
id
]
def
getNodeComponents
(
self
,
node
):
return
self
.
__nodeComponents
[
node
.
id
]
def
getComponentNodes
(
self
,
comp
):
return
self
.
__componentNodes
[
comp
.
id
]
def
getNodeComponents
(
self
,
node
):
return
self
.
__nodeComponents
[
node
.
id
]
def
__add_node_attr
(
self
,
node
):
...
...
@@ -152,8 +194,8 @@ class NodeNetwork(object):
raise
exceptions
.
ValueError
(
"Argument is not of type Node"
)
name
=
node
.
name
de
t
attr
(
self
.
__class__
,
'__node_'
+
name
)
delattr
(
self
,
name
)
de
l
attr
(
self
,
'__node_'
+
name
)
delattr
(
self
.
__class__
,
name
)
def
__get_node_attr
(
self
,
name
):
return
getattr
(
self
,
'__node_'
+
name
)
...
...
@@ -200,11 +242,11 @@ class Node(object):
self
.
__q_comp
=
component
if
len
(
args
)
==
1
:
self
.
__q_x
=
args
[
0
]
self
.
__q_y
=
args
[
0
]
self
.
__q_x
=
gauss_param
(
q
=
args
[
0
]
)
self
.
__q_y
=
gauss_param
(
q
=
args
[
0
]
)
elif
len
(
args
)
==
2
:
self
.
__q_x
=
args
[
0
]
self
.
__q_y
=
args
[
1
]
self
.
__q_x
=
gauss_param
(
q
=
args
[
0
]
)
self
.
__q_y
=
gauss_param
(
q
=
args
[
1
]
)
else
:
raise
pkex
.
BasePyKatException
(
"Must specify either 1 Gaussian beam parameter or 2 for astigmatic beams"
)
...
...
@@ -222,7 +264,7 @@ class Node(object):
return
rtn
def
isConnected
(
self
):
if
(
self
.
components
[
0
]
is
not
None
)
and
(
self
.
self
.
components
[
1
]
is
not
None
):
if
(
self
.
components
[
0
]
is
not
None
)
and
(
self
.
components
[
1
]
is
not
None
):
return
True
else
:
return
False
...
...
@@ -256,7 +298,7 @@ class Node(object):
if
comps
[
1
]
==
None
:
ix
=
-
1
else
:
ix
=
comps
[
1
].
getN
odes
()
.
index
(
self
)
ix
=
comps
[
1
].
n
odes
.
index
(
self
)
return
[
True
,
comps
[
1
],
ix
]
...
...
@@ -264,7 +306,7 @@ class Node(object):
if
comps
[
0
]
==
None
:
ix
=
-
1
else
:
ix
=
comps
[
0
].
getN
odes
()
.
index
(
self
)
ix
=
comps
[
0
].
n
odes
.
index
(
self
)
return
[
True
,
comps
[
0
],
ix
]
else
:
...
...
pykat/parser.py
deleted
100644 → 0
View file @
5a5c246a
import
os
import
exceptions
import
numpy
as
np
from
pykat.node_network
import
NodeNetwork
from
pykat.detectors
import
Detector
from
pykat.components
import
Component
from
pykat.commands
import
Command
,
xaxis
components
=
np
.
array
([
'm'
,
'm1'
,
'm2'
,
'l'
,
's'
,
'bs'
,
'bs1'
,
'bs2'
,
'pd'
,
'pd*'
])
commands
=
np
.
array
([
'attr'
,
'tem'
,
'tem*'
,
'gauss'
,
'gauss*'
,
'gauss**'
,
'cav'
,
'conf'
])
# some commands we ignore, we do the plotting with pyhton
# so don't need
ignore
=
[
'gnuterm'
]
def
parse_kat_file
(
kat_filename
):
kat_cmps
=
[]
# holds the components found in kat file
kat_cmds
=
[]
# holds the commands found in kat file
katfile
=
open
(
kat_filename
,
'r'
)
for
line
in
katfile
.
readlines
():
arg
=
line
.
split
(
' '
)[
0
]
# c
if
(
components
==
arg
).
any
():
kat_cmps
.
append
()
elif
(
commands
==
arg
).
any
():
print
""
def
parse_m
(
line
):
return
line
\ No newline at end of file
pykat/utilities/optics/gaussian_beams.py
View file @
bd378f92
...
...
@@ -14,6 +14,7 @@ class gauss_param(object):
q = gauss_param(w0=w0, z=z)
q = gauss_param(z=z, zr=zr)
q = gauss_param(wz=wz, rc=rc)
q = gauss_param(q=a) # where a is a complex number
or change default wavelength and refractive index with:
...
...
@@ -27,6 +28,13 @@ class gauss_param(object):
if
len
(
args
)
==
1
:
self
.
__q
=
args
[
0
]
elif
len
(
kwargs
)
==
1
:
if
"q"
in
kwargs
:
self
.
__q
=
complex
(
kwargs
[
"q"
])
else
:
raise
pkex
.
BasePyKatException
(
"Must specify: z and w0 or z and zr or rc and wz, to define the beam parameter"
)
elif
len
(
kwargs
)
==
2
:
if
"w0"
in
kwargs
and
"z"
in
kwargs
:
...
...
Write
Preview
Supports
Markdown
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