Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pykat
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sean Leavey
pykat
Commits
fde8c507
Commit
fde8c507
authored
Mar 4, 2014
by
Daniel Brown
Browse files
Options
Downloads
Patches
Plain Diff
removing similarly named objects before adding a new one
parent
b89b6d0a
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
pykat/commands.py
+22
-20
22 additions, 20 deletions
pykat/commands.py
pykat/finesse.py
+8
-0
8 additions, 0 deletions
pykat/finesse.py
with
30 additions
and
20 deletions
pykat/commands.py
+
22
−
20
View file @
fde8c507
...
@@ -15,9 +15,12 @@ from collections import namedtuple
...
@@ -15,9 +15,12 @@ from collections import namedtuple
from
pykat.utilities.optics.gaussian_beams
import
gauss_param
from
pykat.utilities.optics.gaussian_beams
import
gauss_param
class
Command
(
object
):
class
Command
(
object
):
__metaclass__
=
abc
.
ABCMeta
tag
=
None
def
__init__
(
self
,
name
):
__removed
=
False
self
.
tag
=
None
self
.
__removed
=
False
self
.
__name
=
name
def
getFinesseText
(
self
):
def
getFinesseText
(
self
):
"""
Base class for individual finesse optical components
"""
"""
Base class for individual finesse optical components
"""
...
@@ -37,28 +40,30 @@ class Command(object):
...
@@ -37,28 +40,30 @@ class Command(object):
self
.
_kat
.
remove
(
self
)
self
.
_kat
.
remove
(
self
)
self
.
__removed
=
True
self
.
__removed
=
True
@property
def
name
(
self
):
return
self
.
__name
@property
@property
def
removed
(
self
):
return
self
.
__removed
def
removed
(
self
):
return
self
.
__removed
class
cavity
(
Command
):
class
cavity
(
Command
):
def
__init__
(
self
,
name
,
c1
,
n1
,
c2
,
n2
):
def
__init__
(
self
,
name
,
c1
,
n1
,
c2
,
n2
):
super
(
Command
,
self
)
.
__init__
()
Command
.
__init__
(
self
,
axis_type
)
self
.
__name
=
name
self
.
__c1
=
c1
self
.
__c1
=
c1
self
.
__c2
=
c2
self
.
__c2
=
c2
self
.
__n1
=
n1
self
.
__n1
=
n1
self
.
__n2
=
n2
self
.
__n2
=
n2
def
getFinesseText
(
self
):
def
getFinesseText
(
self
):
return
'
cav {0} {1} {2} {3} {4}
'
.
format
(
self
.
__
name
,
self
.
__c1
,
self
.
__n1
,
self
.
__c2
,
self
.
__n2
);
return
'
cav {0} {1} {2} {3} {4}
'
.
format
(
self
.
name
,
self
.
__c1
,
self
.
__n1
,
self
.
__c2
,
self
.
__n2
);
class
gauss
(
object
):
class
gauss
(
object
):
@staticmethod
@staticmethod
def
parseFinesseText
(
text
,
kat
):
def
parseFinesseText
(
text
,
kat
):
values
=
text
.
split
()
values
=
text
.
split
()
if
not
values
[
0
].
startswith
(
"
gauss
"
)
or
(
len
(
values
)
!=
6
and
len
(
values
)
!=
8
):
if
not
values
[
0
].
startswith
(
"
gauss
"
)
or
(
len
(
values
)
!=
6
and
len
(
values
)
!=
8
):
raise
exceptions
.
RuntimeError
(
"'
{0}
'
not a valid Finesse gauss command
"
.
format
(
text
))
raise
pkex
.
BasePyKatException
(
"'
{0}
'
not a valid Finesse gauss command
"
.
format
(
text
))
name
=
values
[
1
]
name
=
values
[
1
]
component
=
values
[
2
]
component
=
values
[
2
]
...
@@ -94,7 +99,7 @@ class tf(Command):
...
@@ -94,7 +99,7 @@ class tf(Command):
fQ
=
namedtuple
(
'
fQ
'
,
[
'
f
'
,
'
Q
'
])
fQ
=
namedtuple
(
'
fQ
'
,
[
'
f
'
,
'
Q
'
])
def
__init__
(
self
,
name
,
poles
,
zeros
):
def
__init__
(
self
,
name
,
poles
,
zeros
):
super
(
Command
,
self
)
.
__init__
()
Command
.
__init__
(
self
,
axis_type
)
pass
pass
class
xaxis
(
Command
):
class
xaxis
(
Command
):
...
@@ -103,9 +108,6 @@ class xaxis(Command):
...
@@ -103,9 +108,6 @@ class xaxis(Command):
and interface to the xaxis command in FINESSE.
and interface to the xaxis command in FINESSE.
"""
"""
@property
def
name
(
self
):
return
self
.
_axis_type
def
__init__
(
self
,
scale
,
limits
,
param
,
steps
,
comp
=
None
,
axis_type
=
"
xaxis
"
):
def
__init__
(
self
,
scale
,
limits
,
param
,
steps
,
comp
=
None
,
axis_type
=
"
xaxis
"
):
"""
"""
Typical usage:
Typical usage:
...
@@ -116,7 +118,7 @@ class xaxis(Command):
...
@@ -116,7 +118,7 @@ class xaxis(Command):
steps is the number of points to compute between upper and lower limits.
steps is the number of points to compute between upper and lower limits.
"""
"""
super
(
Command
,
self
)
.
__init__
()
Command
.
__init__
(
self
,
axis_type
)
self
.
_axis_type
=
axis_type
self
.
_axis_type
=
axis_type
...
@@ -129,20 +131,20 @@ class xaxis(Command):
...
@@ -129,20 +131,20 @@ class xaxis(Command):
scale
=
Scale
.
logarithmic
scale
=
Scale
.
logarithmic
elif
isinstance
(
scale
,
str
):
elif
isinstance
(
scale
,
str
):
# else we have a string but not a recognisable one
# else we have a string but not a recognisable one
raise
exceptions
.
ValueError
(
"
scale argument
'
{0}
'
is not valid, must be
'
lin
'
or
'
log
'"
.
format
(
scale
))
raise
pkex
.
BasePyKatException
(
"
scale argument
'
{0}
'
is not valid, must be
'
lin
'
or
'
log
'"
.
format
(
scale
))
if
scale
!=
Scale
.
linear
and
scale
!=
Scale
.
logarithmic
:
if
scale
!=
Scale
.
linear
and
scale
!=
Scale
.
logarithmic
:
raise
exceptions
.
ValueError
(
"
scale is not Scale.linear or Scale.logarithmic
"
)
raise
pkex
.
BasePyKatException
(
"
scale is not Scale.linear or Scale.logarithmic
"
)
self
.
scale
=
scale
self
.
scale
=
scale
if
numpy
.
size
(
limits
)
!=
2
:
if
numpy
.
size
(
limits
)
!=
2
:
raise
exceptions
.
ValueError
(
"
limits input should be a 2x1 vector of limits for the xaxis
"
)
raise
pkex
.
BasePyKatException
(
"
limits input should be a 2x1 vector of limits for the xaxis
"
)
self
.
limits
=
numpy
.
array
(
SIfloat
(
limits
)).
astype
(
float
)
self
.
limits
=
numpy
.
array
(
SIfloat
(
limits
)).
astype
(
float
)
if
steps
<=
0
:
if
steps
<=
0
:
raise
exceptions
.
ValueError
(
"
steps value should be > 0
"
)
raise
pkex
.
BasePyKatException
(
"
steps value should be > 0
"
)
self
.
steps
=
int
(
steps
)
self
.
steps
=
int
(
steps
)
...
@@ -173,14 +175,14 @@ class xaxis(Command):
...
@@ -173,14 +175,14 @@ class xaxis(Command):
values
=
text
.
split
()
values
=
text
.
split
()
if
values
[
0
]
!=
"
xaxis
"
and
values
[
0
]
!=
"
xaxis*
"
:
if
values
[
0
]
!=
"
xaxis
"
and
values
[
0
]
!=
"
xaxis*
"
:
raise
exceptions
.
RuntimeError
(
"'
{0}
'
not a valid Finesse xaxis command
"
.
format
(
text
))
raise
pkex
.
BasePyKatException
(
"'
{0}
'
not a valid Finesse xaxis command
"
.
format
(
text
))
axis_type
=
values
[
0
]
axis_type
=
values
[
0
]
values
.
pop
(
0
)
# remove initial value
values
.
pop
(
0
)
# remove initial value
if
len
(
values
)
!=
6
:
if
len
(
values
)
!=
6
:
raise
exceptions
.
RuntimeError
(
"
xaxis Finesse code format incorrect
'
{0}
'"
.
format
(
text
))
raise
pkex
.
BasePyKatException
(
"
xaxis Finesse code format incorrect
'
{0}
'"
.
format
(
text
))
return
xaxis
(
values
[
2
],
[
values
[
3
],
values
[
4
]],
values
[
1
],
values
[
5
],
comp
=
values
[
0
],
axis_type
=
axis_type
)
return
xaxis
(
values
[
2
],
[
values
[
3
],
values
[
4
]],
values
[
1
],
values
[
5
],
comp
=
values
[
0
],
axis_type
=
axis_type
)
...
@@ -204,13 +206,13 @@ class x2axis(xaxis):
...
@@ -204,13 +206,13 @@ class x2axis(xaxis):
values
=
text
.
split
()
values
=
text
.
split
()
if
values
[
0
]
!=
"
x2axis
"
and
values
[
0
]
!=
"
x2axis*
"
:
if
values
[
0
]
!=
"
x2axis
"
and
values
[
0
]
!=
"
x2axis*
"
:
raise
exceptions
.
RuntimeError
(
"'
{0}
'
not a valid Finesse xaxis command
"
.
format
(
text
))
raise
pkex
.
BasePyKatException
(
"'
{0}
'
not a valid Finesse xaxis command
"
.
format
(
text
))
axis_type
=
values
[
0
]
axis_type
=
values
[
0
]
values
.
pop
(
0
)
# remove initial value
values
.
pop
(
0
)
# remove initial value
if
len
(
values
)
!=
6
:
if
len
(
values
)
!=
6
:
raise
exceptions
.
RuntimeError
(
"
xaxis Finesse code format incorrect
'
{0}
'"
.
format
(
text
))
raise
pkex
.
BasePyKatException
(
"
xaxis Finesse code format incorrect
'
{0}
'"
.
format
(
text
))
return
x2axis
(
values
[
2
],
[
values
[
3
],
values
[
4
]],
values
[
1
],
values
[
5
],
comp
=
values
[
0
])
return
x2axis
(
values
[
2
],
[
values
[
3
],
values
[
4
]],
values
[
1
],
values
[
5
],
comp
=
values
[
0
])
This diff is collapsed.
Click to expand it.
pykat/finesse.py
+
8
−
0
View file @
fde8c507
...
@@ -549,8 +549,13 @@ class kat(object):
...
@@ -549,8 +549,13 @@ class kat(object):
self
.
__blocks
[
self
.
__currentTag
].
contents
.
append
(
line
)
self
.
__blocks
[
self
.
__currentTag
].
contents
.
append
(
line
)
if
obj
!=
None
and
not
isinstance
(
obj
,
str
):
if
obj
!=
None
and
not
isinstance
(
obj
,
str
):
if
self
.
hasNamedObject
(
obj
.
name
):
getattr
(
self
,
obj
.
name
).
remove
()
print
"
Removed existing object
'
{0}
'
of type {1} to add new object
"
.
format
(
obj
.
name
,
obj
.
__class__
)
self
.
add
(
obj
)
self
.
add
(
obj
)
# now process all the varous gauss/attr etc. commands which require
# now process all the varous gauss/attr etc. commands which require
# components to exist first before they can be processed
# components to exist first before they can be processed
for
line
in
after_process
:
for
line
in
after_process
:
...
@@ -835,6 +840,9 @@ class kat(object):
...
@@ -835,6 +840,9 @@ class kat(object):
import
gc
import
gc
print
gc
.
get_referrers
(
obj
)
print
gc
.
get_referrers
(
obj
)
def
hasNamedObject
(
self
,
name
):
return
name
in
self
.
__components
or
name
in
self
.
__detectors
or
name
in
self
.
__commands
def
add
(
self
,
obj
):
def
add
(
self
,
obj
):
try
:
try
:
obj
.
tag
=
self
.
__currentTag
obj
.
tag
=
self
.
__currentTag
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment