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
e39191c1
Commit
e39191c1
authored
10 years ago
by
Yngve Levinsen
Browse files
Options
Downloads
Patches
Plain Diff
added density reader
this is VERY buggy, as there are some data written to file which are NOT DOCUMENTED
parent
fa71894b
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
+153
-0
153 additions, 0 deletions
ess/TraceWin.py
with
153 additions
and
0 deletions
ess/TraceWin.py
+
153
−
0
View file @
e39191c1
...
...
@@ -53,3 +53,156 @@ class dst:
if
key
in
self
.
_columns
:
i
=
self
.
_columns
.
index
(
key
)
return
self
.
_data
[:,
i
]
class
density_file
:
'''
Simple class to read a TraceWin density file
into a pythonized object
'''
def
__init__
(
self
,
filename
):
import
numpy
self
.
filename
=
filename
self
.
fin
=
file
(
self
.
filename
,
'
r
'
)
# first we simply count how many elements we have:
counter
=
0
while
True
:
try
:
self
.
_skipAndCount
()
counter
+=
1
except
IndexError
:
# EOF reached..
break
print
counter
self
.
fin
.
seek
(
0
)
# set up the arrays..
self
.
i
=
0
# z position [m] :
self
.
z
=
numpy
.
zeros
(
counter
)
# current [mA] :
self
.
ib
=
numpy
.
zeros
(
counter
)
# number of lost particles:
self
.
Np
=
numpy
.
zeros
(
counter
)
self
.
Xouv
=
numpy
.
zeros
(
counter
)
self
.
Youv
=
numpy
.
zeros
(
counter
)
self
.
_max
=
numpy
.
zeros
((
counter
,
7
))
self
.
_min
=
numpy
.
zeros
((
counter
,
7
))
self
.
lost
=
numpy
.
zeros
((
counter
,
self
.
Nrun
))
self
.
powlost
=
numpy
.
zeros
((
counter
,
self
.
Nrun
))
while
self
.
i
<
counter
:
self
.
_getFullContent
()
self
.
i
+=
1
def
_getHeader
(
self
):
import
numpy
# header..
version
=
numpy
.
fromfile
(
self
.
fin
,
dtype
=
numpy
.
int16
,
count
=
1
)[
0
]
year
=
numpy
.
fromfile
(
self
.
fin
,
dtype
=
numpy
.
int16
,
count
=
1
)[
0
]
# there is much more data written, but it is undocumented. Our trick to get back "on line":
shift
=
0
while
year
!=
2011
or
version
!=
8
:
shift
+=
1
version
=
year
year
=
numpy
.
fromfile
(
self
.
fin
,
dtype
=
numpy
.
int16
,
count
=
1
)[
0
]
if
shift
:
raise
ValueError
(
"
ERROR, shifted
"
+
str
(
shift
*
2
)
+
"
bytes
"
)
self
.
vlong
=
numpy
.
fromfile
(
self
.
fin
,
dtype
=
numpy
.
int16
,
count
=
1
)[
0
]
self
.
Nrun
=
numpy
.
fromfile
(
self
.
fin
,
dtype
=
numpy
.
int32
,
count
=
1
)[
0
]
self
.
version
=
version
self
.
year
=
year
def
_skipAndCount
(
self
):
import
numpy
self
.
_getHeader
()
numpy
.
fromfile
(
self
.
fin
,
dtype
=
numpy
.
int16
,
count
=
8344
/
2
)
numpy
.
fromfile
(
self
.
fin
,
dtype
=
numpy
.
int16
,
count
=
6788
/
2
)
def
_getFullContent
(
self
):
import
numpy
#self._getHeader()
# no need to read the header again:
numpy
.
fromfile
(
self
.
fin
,
dtype
=
numpy
.
int16
,
count
=
5
)
nelp
=
numpy
.
fromfile
(
self
.
fin
,
dtype
=
numpy
.
int32
,
count
=
1
)[
0
]
self
.
ib
[
self
.
i
]
=
numpy
.
fromfile
(
self
.
fin
,
dtype
=
numpy
.
float32
,
count
=
1
)[
0
]
self
.
z
[
self
.
i
]
=
numpy
.
fromfile
(
self
.
fin
,
dtype
=
numpy
.
float32
,
count
=
1
)[
0
]
# Aperture
self
.
Xouv
[
self
.
i
]
=
numpy
.
fromfile
(
self
.
fin
,
dtype
=
numpy
.
float32
,
count
=
1
)[
0
]
self
.
Youv
[
self
.
i
]
=
numpy
.
fromfile
(
self
.
fin
,
dtype
=
numpy
.
float32
,
count
=
1
)[
0
]
step
=
numpy
.
fromfile
(
self
.
fin
,
dtype
=
numpy
.
int32
,
count
=
1
)[
0
]
n
=
7
# x [m], y[m], Phase [deg], Energy [MeV], R[m], Z[m], dp/p
moy
=
numpy
.
fromfile
(
self
.
fin
,
dtype
=
numpy
.
float32
,
count
=
n
)
moy2
=
numpy
.
fromfile
(
self
.
fin
,
dtype
=
numpy
.
float32
,
count
=
n
)
self
.
_max
[
self
.
i
]
=
numpy
.
fromfile
(
self
.
fin
,
dtype
=
numpy
.
float32
,
count
=
n
)[:]
self
.
_min
[
self
.
i
]
=
numpy
.
fromfile
(
self
.
fin
,
dtype
=
numpy
.
float32
,
count
=
n
)[:]
if
self
.
version
>=
5
:
rms
=
numpy
.
fromfile
(
self
.
fin
,
dtype
=
numpy
.
float32
,
count
=
n
)
rms_size2
=
numpy
.
fromfile
(
self
.
fin
,
dtype
=
numpy
.
float32
,
count
=
n
)
if
self
.
version
>=
6
:
min_pos_moy
=
numpy
.
fromfile
(
self
.
fin
,
dtype
=
numpy
.
float32
,
count
=
n
)
max_pos_moy
=
numpy
.
fromfile
(
self
.
fin
,
dtype
=
numpy
.
float32
,
count
=
n
)
if
self
.
version
>=
7
:
rms_emit
=
numpy
.
fromfile
(
self
.
fin
,
dtype
=
numpy
.
float32
,
count
=
n
)
rms_emit2
=
numpy
.
fromfile
(
self
.
fin
,
dtype
=
numpy
.
float32
,
count
=
n
)
self
.
Np
[
self
.
i
]
=
numpy
.
fromfile
(
self
.
fin
,
dtype
=
numpy
.
int64
,
count
=
1
)[
0
]
#print self.i, self.Np[self.i] # Nrun, nelp, ib, self.z[self.i], Np
if
self
.
Np
[
self
.
i
]:
powlost
=
numpy
.
zeros
(
self
.
Nrun
)
for
i
in
xrange
(
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
]
lost2
=
numpy
.
fromfile
(
self
.
fin
,
dtype
=
numpy
.
int64
,
count
=
1
)[
0
]
Minlost
=
numpy
.
fromfile
(
self
.
fin
,
dtype
=
numpy
.
int64
,
count
=
1
)[
0
]
Maxlost
=
numpy
.
fromfile
(
self
.
fin
,
dtype
=
numpy
.
int64
,
count
=
1
)[
0
]
powlost2
=
numpy
.
fromfile
(
self
.
fin
,
dtype
=
numpy
.
float64
,
count
=
1
)[
0
]
Minpowlost
=
numpy
.
fromfile
(
self
.
fin
,
dtype
=
numpy
.
float32
,
count
=
1
)[
0
]
Maxpowlost
=
numpy
.
fromfile
(
self
.
fin
,
dtype
=
numpy
.
float32
,
count
=
1
)[
0
]
if
self
.
vlong
==
1
:
tab
=
numpy
.
fromfile
(
self
.
fin
,
dtype
=
numpy
.
uint64
,
count
=
n
)
else
:
tab
=
numpy
.
fromfile
(
self
.
fin
,
dtype
=
numpy
.
uint32
,
count
=
n
)
if
self
.
ib
[
self
.
i
]
>
0
:
tabp
=
[]
for
j
in
xrange
(
n
):
tabp
.
append
(
numpy
.
fromfile
(
self
.
fin
,
dtype
=
numpy
.
uint32
,
count
=
step
))
# skip jibberish
if
self
.
Np
[
self
.
i
]:
numpy
.
fromfile
(
self
.
fin
,
dtype
=
numpy
.
int16
,
count
=
2352
/
2
)
if
self
.
Nrun
==
100
:
numpy
.
fromfile
(
self
.
fin
,
dtype
=
numpy
.
int16
,
count
=
5572
/
2
)
else
:
numpy
.
fromfile
(
self
.
fin
,
dtype
=
numpy
.
int16
,
count
=
8032
/
2
)
if
self
.
Nrun
==
100
:
numpy
.
fromfile
(
self
.
fin
,
dtype
=
numpy
.
int16
,
count
=
6788
/
2
)
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