Commit bfe62d6a authored by snuverink_j's avatar snuverink_j
Browse files

Merge branch '99-update-lossparser-after-update' into 'master'

Resolve "Update LossParser after update"

Closes #99

See merge request OPAL/pyOPALTools!74
parents 2df8b69c f3dd606c
......@@ -31,19 +31,22 @@ class LossParser(BaseParser):
**1. Clean**
line = "# Element STQ1 x (mm), y (mm), z (mm), px ( ), py ( ), pz ( ), id, turn, time (ns)"
(OPAL version <= 2.4)
line = "# Element STQ1 x (m), y (m), z (m), px ( ), py ( ), pz ( ), id, turn, time (ns)"
(OPAL version >= 2.6)
line = "# x (m), y (m), z (m), px ( ), py ( ), pz ( ), id, turn, time (s)"
gets
line = " x (mm), y (mm), z (mm), px ( ), py ( ), pz ( ), id, turn, time (ns)"
line = " x (m), y (m), z (m), px ( ), py ( ), pz ( ), id, turn, time (s)"
**2. no commas**
line = " x (mm), y (mm), z (mm), px ( ), py ( ), pz ( ), id, turn, time (ns)"
line = " x (m), y (m), z (m), px ( ), py ( ), pz ( ), id, turn, time (s)"
gets
line = " x (mm) y (mm) z (mm) px ( ) py ( ) pz ( ) id turn time (ns)"
line = " x (m) y (m) z (m) px ( ) py ( ) pz ( ) id turn time (s)"
"""
line = ''
......@@ -52,8 +55,10 @@ class LossParser(BaseParser):
with open(filename) as f:
line = f.readline()
# 1. step
# 1. step (OPAL version <= 2.4)
line = re.sub(r"# Element (\S+)", ' ', line)
# 1. step (OPAL version >= 2.6)
line = re.sub(r"# ", ' ', line)
# 2. step
line = re.sub(r',', ' ', line)
......
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Test to read loss files"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### OPAL versions <= 2.4 "
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"\tLoss dataset.\n",
"\n",
"\tSize: 10 x 20\n",
"\n",
"\tAvailable variables (10) :\n",
"\n",
"\telement \t\n",
"\tid \t\n",
"\tpx \t\n",
"\tpy \t\n",
"\tpz \t\n",
"\ttime \tns\n",
"\tturn \t\n",
"\tx \tmm\n",
"\ty \tmm\n",
"\tz \tmm\n",
"\n"
]
}
],
"source": [
"from opal import load_dataset\n",
"\n",
"ds = load_dataset('./loss/', fname='STQ1.loss')\n",
"\n",
"print( ds )"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([3.19454, 3.21438, 3.22708, 3.23298, 3.25034, 3.26718, 3.27135,\n",
" 3.28587, 3.30447, 3.30977, 3.32193, 3.34001, 3.34574, 3.35734,\n",
" 3.3751 , 3.38031, 3.39277, 3.41013, 3.4132 , 3.42791])"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ds.getData('x')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### OPAL versions >= 2.6 "
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"\tLoss dataset.\n",
"\n",
"\tSize: 10 x 20\n",
"\n",
"\tAvailable variables (10) :\n",
"\n",
"\telement \t\n",
"\tid \t\n",
"\tpx \t\n",
"\tpy \t\n",
"\tpz \t\n",
"\ttime \tns\n",
"\tturn \t\n",
"\tx \tmm\n",
"\ty \tmm\n",
"\tz \tmm\n",
"\n"
]
}
],
"source": [
"from opal import load_dataset\n",
"\n",
"ds = load_dataset('./loss/', fname='STQ1-2.6.loss')\n",
"\n",
"print( ds )"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([3.19454, 3.21438, 3.22708, 3.23298, 3.25034, 3.26718, 3.27135,\n",
" 3.28587, 3.30447, 3.30977, 3.32193, 3.34001, 3.34574, 3.35734,\n",
" 3.3751 , 3.38031, 3.39277, 3.41013, 3.4132 , 3.42791])"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ds.getData('x')"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "pyOPALTools",
"language": "python",
"name": "pyopaltools"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
# x (m), y (m), z (m), px ( ), py ( ), pz ( ), id, turn, time (s)
STQ1 3.19454 -0.855974 -5.36191e-45 0.230594 0.718158 2.61788e-46 0 70 8249.8
STQ1 3.21438 -0.86129 -6.6129e-45 0.231112 0.723141 -5.25233e-46 0 71 8368.24
STQ1 3.22708 -0.864692 -6.0357e-45 0.229112 0.728921 -1.15336e-45 0 72 8486.72
STQ1 3.23298 -0.866273 -3.70922e-45 0.230876 0.733492 -1.44919e-45 0 73 8605.15
STQ1 3.25034 -0.870925 -3.85996e-46 0.232702 0.738023 -1.34932e-45 0 74 8723.57
STQ1 3.26718 -0.875437 2.95596e-45 0.230492 0.743812 -8.67266e-46 0 75 8842.06
STQ1 3.27135 -0.876556 5.60223e-45 0.23105 0.748733 -1.31988e-46 0 76 8960.52
STQ1 3.28587 -0.880446 6.59739e-45 0.233903 0.752924 6.58777e-46 0 77 9078.93
STQ1 3.30447 -0.88543 5.70809e-45 0.231835 0.758625 1.26919e-45 0 78 9197.41
STQ1 3.30977 -0.886851 3.05757e-45 0.231761 0.763709 1.48841e-45 0 79 9315.87
STQ1 3.32193 -0.890108 -6.03966e-46 0.234308 0.767975 1.24973e-45 0 80 9434.29
STQ1 3.34001 -0.894953 -4.01345e-45 0.232894 0.773434 6.08776e-46 0 81 9552.76
STQ1 3.34574 -0.896488 -6.23617e-45 0.232381 0.778616 -2.40751e-46 0 82 9671.23
STQ1 3.35734 -0.899598 -6.37204e-45 0.235155 0.782794 -1.01443e-45 0 83 9789.64
STQ1 3.3751 -0.904356 -4.56834e-45 0.233403 0.788306 -1.46722e-45 0 84 9908.11
STQ1 3.38031 -0.905752 -1.37092e-45 0.233227 0.793346 -1.44961e-45 0 85 10026.6
STQ1 3.39277 -0.90909 2.25366e-45 0.235856 0.797547 -1.00074e-45 0 86 10145
STQ1 3.41013 -0.913743 5.15544e-45 0.233547 0.803182 -2.23212e-46 0 87 10263.5
STQ1 3.4132 -0.914565 6.53991e-45 0.233928 0.80802 6.43043e-46 0 88 10381.9
STQ1 3.42791 -0.918505 5.6797e-45 0.236227 0.812289 1.31811e-45 0 89 10500.3
# Element STQ1 x (mm), y (mm), z (mm), px ( ), py ( ), pz ( ), id, turn, time (ns)
# Element STQ1 x (m), y (m), z (m), px ( ), py ( ), pz ( ), id, turn, time (ns)
STQ1 3.19454 -0.855974 -5.36191e-45 0.230594 0.718158 2.61788e-46 0 70 8249.8
STQ1 3.21438 -0.86129 -6.6129e-45 0.231112 0.723141 -5.25233e-46 0 71 8368.24
STQ1 3.22708 -0.864692 -6.0357e-45 0.229112 0.728921 -1.15336e-45 0 72 8486.72
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment