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
6538c18a
Commit
6538c18a
authored
6 years ago
by
Yngve Levinsen
Browse files
Options
Downloads
Patches
Plain Diff
removing * imports
parent
54342089
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/lib_tw.py
+18
-19
18 additions, 19 deletions
ess/lib_tw.py
with
18 additions
and
19 deletions
ess/lib_tw.py
+
18
−
19
View file @
6538c18a
...
...
@@ -11,8 +11,7 @@ from __future__ import print_function
#---- Lib
from
numpy
import
*
from
numpy.linalg
import
det
import
numpy
from
struct
import
pack
from
itertools
import
chain
...
...
@@ -431,7 +430,7 @@ class PARTRAN:
lin
=
lin
.
split
()
if
flag
==
1
:
data
.
append
(
map
(
float
,
lin
))
if
'
##
'
in
lin
[
0
]:
flag
=
1
data
=
array
(
data
).
transpose
()
data
=
numpy
.
array
(
data
).
transpose
()
# Instances
self
.
s
=
data
[
idx_s
]
...
...
@@ -450,7 +449,7 @@ class PARTRAN:
# Additional instances
self
.
gamma
=
data
[
idx_gamma
]
+
1.0
self
.
beta
=
sqrt
(
1.0
-
1.0
/
self
.
gamma
**
2
)
self
.
beta
=
numpy
.
sqrt
(
1.0
-
1.0
/
self
.
gamma
**
2
)
self
.
z
=-
self
.
phs
*
self
.
beta
*
(
c
/
freq
*
1e5
)
/
360.0
self
.
betx
=
self
.
sigx
**
2
/
self
.
epsx
*
self
.
beta
*
self
.
gamma
self
.
bety
=
self
.
sigy
**
2
/
self
.
epsy
*
self
.
beta
*
self
.
gamma
...
...
@@ -507,7 +506,7 @@ class DST:
mass
=
fromfile
(
file
,
dtype
=
float64
,
count
=
1
)[
0
]
# Adjust units
gamma
=
1.0
+
x
[
5
]
/
mass
;
beta
=
sqrt
(
1
-
1
/
gamma
**
2
)
gamma
=
1.0
+
x
[
5
]
/
mass
;
beta
=
numpy
.
sqrt
(
1
-
1
/
gamma
**
2
)
if
unit_x
==
'
mm
'
:
x
[
0
]
=
x
[
0
]
*
1e1
;
x
[
2
]
=
x
[
2
]
*
1e1
if
unit_px
==
'
mrad
'
:
x
[
1
]
=
x
[
1
]
*
1e3
;
x
[
3
]
=
x
[
3
]
*
1e3
if
unit_z
==
'
deg
'
:
x
[
4
]
=
x
[
4
]
*
180
/
pi
...
...
@@ -632,12 +631,12 @@ class DENSITY:
#-- Take care ave and rms
cent_ave
=
cent_ave
/
Nrun
;
cent_rms
=
sqrt
(
cent_rms
/
Nrun
)
sig_ave
=
sig_ave
/
Nrun
;
sig_rms
=
sqrt
(
sig_rms
/
Nrun
)
eps_ave
=
eps_ave
/
Nrun
;
eps_rms
=
sqrt
(
eps_rms
/
Nrun
)
cent_ave
=
cent_ave
/
Nrun
;
cent_rms
=
numpy
.
sqrt
(
cent_rms
/
Nrun
)
sig_ave
=
sig_ave
/
Nrun
;
sig_rms
=
numpy
.
sqrt
(
sig_rms
/
Nrun
)
eps_ave
=
eps_ave
/
Nrun
;
eps_rms
=
numpy
.
sqrt
(
eps_rms
/
Nrun
)
if
Nptcl
[
0
]
>
0
:
loss_num_ave
=
1.0
*
array
(
loss_num_ave
)
/
Nrun
;
loss_num_rms
=
sqrt
(
1.0
*
array
(
loss_num_rms
)
/
Nrun
)
loss_pow_ave
=
array
(
loss_pow_ave
)
/
Nrun
;
loss_pow_rms
=
sqrt
(
array
(
loss_pow_rms
)
/
Nrun
)
loss_num_ave
=
1.0
*
numpy
.
array
(
loss_num_ave
)
/
Nrun
;
loss_num_rms
=
numpy
.
sqrt
(
1.0
*
numpy
.
array
(
loss_num_rms
)
/
Nrun
)
loss_pow_ave
=
numpy
.
array
(
loss_pow_ave
)
/
Nrun
;
loss_pow_rms
=
numpy
.
sqrt
(
numpy
.
array
(
loss_pow_rms
)
/
Nrun
)
#-- Change units, m => mm, pi-m-rad => pi-mm-mrad
...
...
@@ -652,15 +651,15 @@ class DENSITY:
#-- Define std (around to avoid sqrt(-eps))
if
Nrun
>
1
:
cent_std
=
sqrt
(
around
(
cent_rms
**
2
-
cent_ave
**
2
,
12
))
sig_std
=
sqrt
(
around
(
sig_rms
**
2
-
sig_ave
**
2
,
12
))
eps_std
=
sqrt
(
around
(
eps_rms
**
2
-
eps_ave
**
2
,
12
))
cent_std
=
numpy
.
sqrt
(
around
(
cent_rms
**
2
-
cent_ave
**
2
,
12
))
sig_std
=
numpy
.
sqrt
(
around
(
sig_rms
**
2
-
sig_ave
**
2
,
12
))
eps_std
=
numpy
.
sqrt
(
around
(
eps_rms
**
2
-
eps_ave
**
2
,
12
))
cent_std
=
nan_to_num
(
cent_std
)
# Replace nan with 0
sig_std
=
nan_to_num
(
sig_std
)
# Replace nan with 0
eps_std
=
nan_to_num
(
eps_std
)
# Replace nan with 0
if
Nptcl
[
0
]
>
0
:
loss_num_std
=
sqrt
(
around
(
loss_num_rms
**
2
-
loss_num_ave
**
2
,
16
))
loss_pow_std
=
sqrt
(
around
(
loss_pow_rms
**
2
-
loss_pow_ave
**
2
,
16
))
loss_num_std
=
numpy
.
sqrt
(
around
(
loss_num_rms
**
2
-
loss_num_ave
**
2
,
16
))
loss_pow_std
=
numpy
.
sqrt
(
around
(
loss_pow_rms
**
2
-
loss_pow_ave
**
2
,
16
))
loss_num_std
=
nan_to_num
(
loss_num_std
)
# Replace nan with 0
loss_pow_std
=
nan_to_num
(
loss_pow_std
)
# Replace nan with 0
...
...
@@ -836,9 +835,9 @@ def x2twiss(x):
2015.07.30
'''
x
=
[
x_i
-
mean
(
x_i
)
for
x_i
in
array
(
x
).
transpose
()]
x
=
[
x_i
-
mean
(
x_i
)
for
x_i
in
numpy
.
array
(
x
).
transpose
()]
sig
=
[[
mean
(
x_i
*
x_k
)
for
x_k
in
x
]
for
x_i
in
x
]
eps
=
[
sqrt
(
det
(
array
(
sig
)[
i
:
i
+
2
][:,
i
:
i
+
2
]))
for
i
in
(
0
,
2
,
4
)]
eps
=
[
numpy
.
sqrt
(
numpy
.
linalg
.
det
(
numpy
.
array
(
sig
)[
i
:
i
+
2
][:,
i
:
i
+
2
]))
for
i
in
(
0
,
2
,
4
)]
bet
=
[
sig
[
i
][
i
]
/
eps
[
i
/
2
]
for
i
in
(
0
,
2
,
4
)]
alf
=
[
-
sig
[
i
][
i
+
1
]
/
eps
[
i
/
2
]
for
i
in
(
0
,
2
,
4
)]
gam
=
[
sig
[
i
+
1
][
i
+
1
]
/
eps
[
i
/
2
]
for
i
in
(
0
,
2
,
4
)]
...
...
@@ -886,7 +885,7 @@ def loss_elem2den(s,loss,file_name_dt='',dlt_dt=5e-6):
try
:
# DTL cell and DT lengths
with
open
(
file_name_dt
)
as
file
:
L_cell
,
L_dt
=
array
([
map
(
float
,
lin
.
split
())
for
lin
in
file
.
readlines
()]).
transpose
()[:
2
]
L_cell
,
L_dt
=
numpy
.
array
([
map
(
float
,
lin
.
split
())
for
lin
in
file
.
readlines
()]).
transpose
()[:
2
]
# Replace cell lengths with DT lengths
Ndt
=
0
for
i
in
range
(
len
(
L
)):
...
...
@@ -923,7 +922,7 @@ def loss_elem2den(s,loss,file_name_dt='',dlt_dt=5e-6):
try
:
# Read DTL cell and DT lengths
with
open
(
file_name_dt
)
as
file
:
l_cell
,
l_dt
=
array
([
map
(
float
,
lin
.
split
())
for
lin
in
file
.
readlines
()]).
transpose
()[:
2
]
l_cell
,
l_dt
=
numpy
.
array
([
map
(
float
,
lin
.
split
())
for
lin
in
file
.
readlines
()]).
transpose
()[:
2
]
# Replace cell lengths with DT lengths
Ndt
=
0
for
i
in
range
(
len
(
l
)):
...
...
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