Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
ess-python-tools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
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
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ESS Beam Physics
ess-python-tools
Commits
859dc898
Commit
859dc898
authored
8 years ago
by
Yngve Levinsen
Browse files
Options
Downloads
Patches
Plain Diff
fix for viewing plt files while simulation is still running
replaced xrange -> range (py3 compatibility)
parent
83793df1
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ess/TraceWin.py
+23
-13
23 additions, 13 deletions
ess/TraceWin.py
with
23 additions
and
13 deletions
ess/TraceWin.py
+
23
−
13
View file @
859dc898
...
...
@@ -261,6 +261,7 @@ class plt:
# Thanks Emma!
import
numpy
from
builtins
import
range
fin
=
open
(
self
.
filename
,
'
r
'
)
...
...
@@ -295,6 +296,9 @@ class plt:
i
=
0
while
i
<
self
.
Ne
:
SubHeader
=
numpy
.
fromfile
(
fin
,
dtype
=
SubHeader_type
,
count
=
1
)
# unfinished files need this fix (simulation still running)
if
not
SubHeader
[
'
Nelp
'
]:
break
i
=
SubHeader
[
'
Nelp
'
][
0
]
self
.
Nelp
.
append
(
i
)
...
...
@@ -304,7 +308,7 @@ class plt:
data
=
{}
for
key
in
[
'
Zgen
'
,
'
phase0
'
,
'
wgen
'
]:
data
[
key
]
=
SubHeader
[
key
][
0
]
for
j
in
x
range
(
7
):
for
j
in
range
(
7
):
c
=
self
.
_columns
[
j
]
data
[
c
]
=
Table
[:,
j
]
# convert x,y from cm to m
...
...
@@ -370,12 +374,13 @@ class plt:
(NOT necessarily reference)
'''
import
numpy
from
builtins
import
range
if
not
hasattr
(
self
,
'
avg
'
):
self
.
calc_avg
()
self
.
gamma
=
[]
self
.
beta
=
[]
for
i
,
j
in
zip
(
self
.
Nelp
,
x
range
(
len
(
self
.
Nelp
))):
for
i
,
j
in
zip
(
self
.
Nelp
,
range
(
len
(
self
.
Nelp
))):
Eavg
=
self
.
avg
[
'
E
'
][
j
]
self
.
gamma
.
append
((
self
.
mc2
+
Eavg
)
/
self
.
mc2
)
self
.
beta
.
append
(
numpy
.
sqrt
(
1.
-
1.
/
self
.
gamma
[
-
1
]
**
2
))
...
...
@@ -421,6 +426,7 @@ class plt:
'''
import
numpy
from
builtins
import
range
if
not
hasattr
(
self
,
'
avg
'
):
self
.
calc_avg
()
...
...
@@ -428,7 +434,7 @@ class plt:
vals
=
self
.
_columns
[:
-
1
]
self
.
sigma
=
[]
for
j
in
x
range
(
len
(
self
.
Nelp
)):
for
j
in
range
(
len
(
self
.
Nelp
)):
i
=
self
.
Nelp
[
j
]
data
=
self
[
i
]
...
...
@@ -443,6 +449,7 @@ class plt:
'''
import
numpy
from
builtins
import
range
if
not
hasattr
(
self
,
'
sigma
'
):
self
.
calc_sigma
()
...
...
@@ -451,7 +458,7 @@ class plt:
self
.
std
=
{}
for
j
in
x
range
(
len
(
vals
)):
for
j
in
range
(
len
(
vals
)):
v
=
vals
[
j
]
self
.
std
[
v
]
=
numpy
.
sqrt
(
self
.
sigma
[:,
j
,
j
])
...
...
@@ -462,6 +469,7 @@ class plt:
'''
import
numpy
from
builtins
import
range
if
not
hasattr
(
self
,
'
sigma
'
):
self
.
calc_sigma
()
...
...
@@ -469,23 +477,23 @@ class plt:
self
.
calc_rel
()
self
.
twiss_eps
=
[]
for
j
in
x
range
(
len
(
self
.
Nelp
)):
for
j
in
range
(
len
(
self
.
Nelp
)):
self
.
twiss_eps
.
append
([
numpy
.
sqrt
(
numpy
.
linalg
.
det
(
self
.
sigma
[
j
][
i
:
i
+
2
][:,
i
:
i
+
2
]))
for
i
in
(
0
,
2
,
4
)])
self
.
twiss_eps
=
numpy
.
array
(
self
.
twiss_eps
)
# Calculate normalized emittance:
# TODO: this is NOT correct normalization for longitudinal
self
.
twiss_eps_normed
=
self
.
twiss_eps
.
copy
()
for
i
in
x
range
(
3
):
for
i
in
range
(
3
):
self
.
twiss_eps_normed
[:,
i
]
*=
self
.
gamma
*
self
.
beta
# Calculate beta:
# This is a factor 10 different from what TraceWin plots
self
.
twiss_beta
=
[[
self
.
sigma
[
j
][
i
][
i
]
/
self
.
twiss_eps
[
j
,
i
/
2
]
for
i
in
(
0
,
2
,
4
)]
for
j
in
x
range
(
len
(
self
.
Nelp
))]
self
.
twiss_beta
=
[[
self
.
sigma
[
j
][
i
][
i
]
/
self
.
twiss_eps
[
j
,
i
/
2
]
for
i
in
(
0
,
2
,
4
)]
for
j
in
range
(
len
(
self
.
Nelp
))]
self
.
twiss_beta
=
numpy
.
array
(
self
.
twiss_beta
)
# Calculate alpha:
self
.
twiss_alpha
=
[[
-
self
.
sigma
[
j
][
i
][
i
+
1
]
/
self
.
twiss_eps
[
j
,
i
/
2
]
for
i
in
(
0
,
2
,
4
)]
for
j
in
x
range
(
len
(
self
.
Nelp
))]
self
.
twiss_alpha
=
[[
-
self
.
sigma
[
j
][
i
][
i
+
1
]
/
self
.
twiss_eps
[
j
,
i
/
2
]
for
i
in
(
0
,
2
,
4
)]
for
j
in
range
(
len
(
self
.
Nelp
))]
self
.
twiss_alpha
=
numpy
.
array
(
self
.
twiss_alpha
)
...
...
@@ -643,6 +651,7 @@ class density_file:
def
_getFullContent
(
self
):
import
numpy
from
builtins
import
range
#self._getHeader()
# no need to read the header again:
...
...
@@ -685,7 +694,7 @@ class density_file:
self
.
Np
[
self
.
i
]
=
numpy
.
fromfile
(
self
.
fin
,
dtype
=
numpy
.
int64
,
count
=
1
)[
0
]
if
self
.
Np
[
self
.
i
]:
for
i
in
x
range
(
self
.
Nrun
):
for
i
in
range
(
self
.
Nrun
):
self
.
lost
[
self
.
i
,
i
]
=
numpy
.
fromfile
(
self
.
fin
,
dtype
=
numpy
.
int64
,
count
=
1
)[
0
]
self
.
powlost
[
self
.
i
,
i
]
=
numpy
.
fromfile
(
self
.
fin
,
dtype
=
numpy
.
float32
,
count
=
1
)[
0
]
self
.
lost2
[
self
.
i
]
=
numpy
.
fromfile
(
self
.
fin
,
dtype
=
numpy
.
int64
,
count
=
1
)[
0
]
...
...
@@ -953,6 +962,7 @@ class remote_data_merger:
'''
import
numpy
as
np
from
builtins
import
range
h1
=
[]
h2
=
[]
...
...
@@ -978,17 +988,17 @@ class remote_data_merger:
d3
.
append
(
thisdata
[
11
])
# fix d1:
for
i
in
x
range
(
len
(
d1
)):
for
j
in
x
range
(
len
(
d1
[
0
])):
for
i
in
range
(
len
(
d1
)):
for
j
in
range
(
len
(
d1
[
0
])):
d1
[
i
][
j
]
=
float
(
d1
[
i
][
j
])
d1
=
np
.
array
(
d1
)
means
=
d1
.
mean
(
axis
=
0
)
stds
=
d1
.
std
(
axis
=
0
)
d1
=
[]
for
i
in
x
range
(
len
(
stds
)):
for
i
in
range
(
len
(
stds
)):
if
stds
[
i
]
/
means
[
i
]
<
1e-10
:
stds
[
i
]
=
0.0
for
i
in
x
range
(
len
(
stds
)):
for
i
in
range
(
len
(
stds
)):
# some small std are removed..
if
stds
[
i
]
/
means
[
i
]
>
1e-8
:
d1
.
append
(
'
%f(%f)
'
%
(
means
[
i
],
stds
[
i
]))
...
...
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