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
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
Sebastian Steinlechner
pykat
Commits
d7735fbf
Commit
d7735fbf
authored
Nov 28, 2013
by
Daniel Brown
Browse files
Options
Downloads
Patches
Plain Diff
updating examples and fixing some exception errors
parent
f16e4afe
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
bin/test_aperture.py
+4
-3
4 additions, 3 deletions
bin/test_aperture.py
pykat/exceptions.py
+6
-6
6 additions, 6 deletions
pykat/exceptions.py
pykat/finesse.py
+11
-11
11 additions, 11 deletions
pykat/finesse.py
with
21 additions
and
20 deletions
bin/test_aperture.py
+
4
−
3
View file @
d7735fbf
...
@@ -15,9 +15,10 @@ pd refl n2
...
@@ -15,9 +15,10 @@ pd refl n2
xaxis m1 r_ap lin 0.1e-3 2e-3 10
xaxis m1 r_ap lin 0.1e-3 2e-3 10
"""
"""
kat
=
finesse
.
kat
(
kat_code
=
code
)
kat
=
finesse
.
kat
()
kat
.
parseCommands
(
code
)
maxtem
=
np
.
arange
(
0
,
3
,
2
)
maxtem
=
np
.
arange
(
0
,
5
,
2
)
for
tem
in
maxtem
:
for
tem
in
maxtem
:
print
"
Calculating maxtem
"
,
tem
,
"
...
"
print
"
Calculating maxtem
"
,
tem
,
"
...
"
...
...
This diff is collapsed.
Click to expand it.
pykat/exceptions.py
+
6
−
6
View file @
d7735fbf
import
exceptions
import
exceptions
class
BasePyKatException
:
class
BasePyKatException
(
Exception
)
:
def
__init__
(
self
,
msg
):
def
__init__
(
self
,
msg
):
self
.
__msg
=
msg
self
.
__msg
=
msg
def
__str__
(
self
):
def
__str__
(
self
):
return
"
PyKat Exception message:
"
,
self
.
__msg
return
self
.
__msg
class
MissingFinesseEnvVar
(
BasePyKatException
)
:
class
MissingFinesseEnvVar
(
BasePyKatException
)
:
def
__init__
(
self
):
def
__init__
(
self
):
BasePyKatEx
e
ception
.
__init__
(
"
The environment variable FINESSE_DIR was not defined
"
)
BasePyKatException
.
__init__
(
self
,
"
The environment variable FINESSE_DIR was not defined
"
)
class
MissingFinesse
(
BasePyKatException
)
:
class
MissingFinesse
(
BasePyKatException
)
:
def
__init__
(
self
):
def
__init__
(
self
):
BasePyKatEx
e
ception
.
__init__
(
"
Could not find the finesse executable
'
kat
'
in
'
{0}
'
,
"
\
BasePyKatException
.
__init__
(
self
,
"
Could not find the finesse executable
'
kat
'
in
'
{0}
'
,
"
\
"
or you do not have the permissions to run it.
"
\
"
or you do not have the permissions to run it.
"
\
.
format
(
os
.
environ
.
get
(
'
FINESSE_DIR
'
)))
.
format
(
os
.
environ
.
get
(
'
FINESSE_DIR
'
)))
...
@@ -22,5 +22,5 @@ class FinesseRunError(BasePyKatException) :
...
@@ -22,5 +22,5 @@ class FinesseRunError(BasePyKatException) :
self
.
__err
=
err
self
.
__err
=
err
self
.
__kat
=
kat
self
.
__kat
=
kat
BasePyKatEx
e
ception
.
__init__
(
"
Finesse returned an error running {1}: {0}
"
.
format
(
self
.
__err
,
self
.
__kat
))
BasePyKatException
.
__init__
(
self
,
"
Finesse returned an error running {1}: {0}
"
.
format
(
self
.
__err
,
self
.
__kat
))
This diff is collapsed.
Click to expand it.
pykat/finesse.py
+
11
−
11
View file @
d7735fbf
...
@@ -32,7 +32,7 @@ import datetime
...
@@ -32,7 +32,7 @@ import datetime
import
pickle
import
pickle
import
pykat
import
pykat
import
pykat.exceptions
as
pkex
from
pykat.exceptions
import
*
from
pykat.node_network
import
NodeNetwork
from
pykat.node_network
import
NodeNetwork
from
pykat.detectors
import
Detector
from
pykat.detectors
import
Detector
...
@@ -54,7 +54,7 @@ class katRun(object):
...
@@ -54,7 +54,7 @@ class katRun(object):
def
saveKatRun
(
self
,
run
,
filename
):
def
saveKatRun
(
self
,
run
,
filename
):
if
not
isinstance
(
run
,
katRun
):
if
not
isinstance
(
run
,
katRun
):
raise
pkex
.
BasePyKatException
(
"
run object must be a katRun type
"
)
raise
BasePyKatException
(
"
run object must be a katRun type
"
)
with
open
(
filename
,
'
w
'
)
as
outfile
:
with
open
(
filename
,
'
w
'
)
as
outfile
:
pickle
.
dump
(
run
,
outfile
,
pickle
.
HIGHEST_PROTOCOL
)
pickle
.
dump
(
run
,
outfile
,
pickle
.
HIGHEST_PROTOCOL
)
...
@@ -86,7 +86,7 @@ class kat(object):
...
@@ -86,7 +86,7 @@ class kat(object):
self
.
__time_code
=
None
self
.
__time_code
=
None
if
kat_code
!=
None
and
kat_file
!=
None
:
if
kat_code
!=
None
and
kat_file
!=
None
:
raise
pkex
.
BasePyKatException
(
"
Specify either a Kat file or some Kat code, not both.
"
)
raise
BasePyKatException
(
"
Specify either a Kat file or some Kat code, not both.
"
)
if
kat_code
!=
None
:
if
kat_code
!=
None
:
self
.
parseCommands
(
kat_code
)
self
.
parseCommands
(
kat_code
)
...
@@ -165,7 +165,7 @@ class kat(object):
...
@@ -165,7 +165,7 @@ class kat(object):
self
.
__finesse_dir
=
os
.
environ
.
get
(
'
FINESSE_DIR
'
)
self
.
__finesse_dir
=
os
.
environ
.
get
(
'
FINESSE_DIR
'
)
if
self
.
__finesse_dir
==
None
:
if
self
.
__finesse_dir
==
None
:
raise
pkex
.
MissingFinesseEnvVar
()
raise
MissingFinesseEnvVar
()
else
:
else
:
self
.
__finesse_dir
=
self
.
__katdir
self
.
__finesse_dir
=
self
.
__katdir
...
@@ -181,7 +181,7 @@ class kat(object):
...
@@ -181,7 +181,7 @@ class kat(object):
# check if kat file exists and it is executable by user
# check if kat file exists and it is executable by user
if
not
(
os
.
path
.
isfile
(
kat_exec
)
and
os
.
access
(
kat_exec
,
os
.
X_OK
)):
if
not
(
os
.
path
.
isfile
(
kat_exec
)
and
os
.
access
(
kat_exec
,
os
.
X_OK
)):
raise
pkex
.
MissingFinesse
()
raise
MissingFinesse
()
# create a kat file which we will write the script into
# create a kat file which we will write the script into
katfile
=
tempfile
.
NamedTemporaryFile
(
suffix
=
"
.kat
"
)
katfile
=
tempfile
.
NamedTemporaryFile
(
suffix
=
"
.kat
"
)
...
@@ -219,7 +219,7 @@ class kat(object):
...
@@ -219,7 +219,7 @@ class kat(object):
r
.
runDateTime
=
datetime
.
datetime
.
now
()
r
.
runDateTime
=
datetime
.
datetime
.
now
()
if
p
.
returncode
!=
0
:
if
p
.
returncode
!=
0
:
raise
pkex
.
FinesseRunError
(
err
,
katfile
.
name
)
raise
FinesseRunError
(
err
,
katfile
.
name
)
if
printout
==
1
:
print
out
if
printout
==
1
:
print
out
if
printerr
==
1
:
print
err
if
printerr
==
1
:
print
err
...
@@ -275,7 +275,7 @@ class kat(object):
...
@@ -275,7 +275,7 @@ class kat(object):
else
:
else
:
return
r
return
r
except
FinesseError
as
fe
:
except
Finesse
Run
Error
as
fe
:
print
fe
print
fe
...
@@ -284,7 +284,7 @@ class kat(object):
...
@@ -284,7 +284,7 @@ class kat(object):
if
isinstance
(
obj
,
Component
):
if
isinstance
(
obj
,
Component
):
if
obj
.
name
in
self
.
__components
:
if
obj
.
name
in
self
.
__components
:
raise
pkex
.
BasePyKatException
(
"
A component with name
'
{0}
'
has already been added
"
.
format
([
obj
.
name
]))
raise
BasePyKatException
(
"
A component with name
'
{0}
'
has already been added
"
.
format
([
obj
.
name
]))
self
.
__components
[
obj
.
name
]
=
obj
self
.
__components
[
obj
.
name
]
=
obj
self
.
__add_component
(
obj
)
self
.
__add_component
(
obj
)
...
@@ -292,7 +292,7 @@ class kat(object):
...
@@ -292,7 +292,7 @@ class kat(object):
elif
isinstance
(
obj
,
Detector
):
elif
isinstance
(
obj
,
Detector
):
if
obj
.
name
in
self
.
__detectors
:
if
obj
.
name
in
self
.
__detectors
:
raise
pkex
.
BasePyKatException
(
"
A detector
'
{0}
'
has already been added
"
.
format
(
obj
.
name
))
raise
BasePyKatException
(
"
A detector
'
{0}
'
has already been added
"
.
format
(
obj
.
name
))
self
.
__detectors
[
obj
.
name
]
=
obj
self
.
__detectors
[
obj
.
name
]
=
obj
self
.
__add_detector
(
obj
)
self
.
__add_detector
(
obj
)
...
@@ -303,11 +303,11 @@ class kat(object):
...
@@ -303,11 +303,11 @@ class kat(object):
self
.
__add_command
(
obj
)
self
.
__add_command
(
obj
)
else
:
else
:
raise
pkex
.
BasePyKatException
(
"
Object {0} could not be added
"
.
format
(
obj
))
raise
BasePyKatException
(
"
Object {0} could not be added
"
.
format
(
obj
))
obj
.
_on_kat_add
(
self
)
obj
.
_on_kat_add
(
self
)
except
pkex
.
BasePyKatException
as
ex
:
except
BasePyKatException
as
ex
:
print
ex
print
ex
def
readOutFile
(
self
,
filename
):
def
readOutFile
(
self
,
filename
):
...
...
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