Skip to content

Commit

Permalink
Move parse_astra_phase_file from LUME-Astra into here. Better species…
Browse files Browse the repository at this point in the history
… handling.
  • Loading branch information
ChristopherMayes committed Nov 30, 2021
1 parent 900c2d7 commit a434dd8
Show file tree
Hide file tree
Showing 2 changed files with 399 additions and 49 deletions.
102 changes: 58 additions & 44 deletions examples/write_examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -128,23 +128,37 @@
"name": "stdout",
"output_type": "stream",
"text": [
" -1.289814080985e-05 1.712192978919e-05 0.000000000000e+00 -9.245284702413e-01 -3.316650265292e+00 2.210558337183e+02 1.819664001274e-05 0.000000000000e+00 1 -1\n",
" -1.184861337727e-03 -2.101371437059e-03 0.000000000000e+00 -3.047044656318e+02 -3.039342419008e+02 -1.005645891013e+02 -9.745607002167e-04 1.000000000000e-06 1 -1\n",
" -5.181307340245e-04 -2.178353405029e-03 0.000000000000e+00 5.525456229648e+02 2.416723877028e+02 -6.554342847563e+01 1.280843753434e-03 1.000000000000e-06 1 -1\n",
" -1.773501610902e-03 2.864979597813e-03 0.000000000000e+00 -2.226004747820e+02 9.450238076106e+00 -1.055085411491e+02 3.835366744569e-04 1.000000000000e-06 1 -1\n",
" 1.686555815999e-03 -2.401048305081e-04 0.000000000000e+00 -1.891692499417e+02 4.859547751754e+01 3.339263495319e+02 1.902998338336e-03 1.000000000000e-06 1 -1\n",
" -7.779454935491e-04 -6.800063114796e-04 0.000000000000e+00 6.716138938638e+01 -2.064173000222e+02 -1.405963302134e+02 1.779005092730e-04 1.000000000000e-06 1 -1\n",
" -2.593702199590e-03 -2.301030494125e-03 0.000000000000e+00 -1.455653402031e+01 2.074634953296e+02 -1.397453142110e+02 1.368567098305e-03 1.000000000000e-06 1 -1\n",
" 1.997801509161e-03 2.648416193086e-03 0.000000000000e+00 -2.124047726665e+00 -6.792723569247e+01 6.931081537770e+01 2.616497721112e-04 1.000000000000e-06 1 -1\n",
" 1.999741847023e-03 -6.945690451493e-04 0.000000000000e+00 -9.991142908925e+01 -9.189412445573e+01 2.259539675809e+02 -8.681109991004e-04 1.000000000000e-06 1 -1\n",
" -7.033822974359e-04 -5.677746866954e-04 0.000000000000e+00 7.520962264129e+02 3.125940718167e+02 -1.451032665210e+02 4.315191990002e-04 1.000000000000e-06 1 -1\n"
" -1.289814080985e-05 1.712192978919e-05 0.000000000000e+00 -9.245284702413e-01 -3.316650265292e+00 2.210558337183e+02 1.819664001274e-05 0.000000000000e+00 1 5\n",
" -1.184861337727e-03 -2.101371437059e-03 0.000000000000e+00 -3.047044656318e+02 -3.039342419008e+02 -1.005645891013e+02 -9.745607002167e-04 1.000000000000e-06 1 5\n",
" -5.181307340245e-04 -2.178353405029e-03 0.000000000000e+00 5.525456229648e+02 2.416723877028e+02 -6.554342847563e+01 1.280843753434e-03 1.000000000000e-06 1 5\n",
" -1.773501610902e-03 2.864979597813e-03 0.000000000000e+00 -2.226004747820e+02 9.450238076106e+00 -1.055085411491e+02 3.835366744569e-04 1.000000000000e-06 1 5\n",
" 1.686555815999e-03 -2.401048305081e-04 0.000000000000e+00 -1.891692499417e+02 4.859547751754e+01 3.339263495319e+02 1.902998338336e-03 1.000000000000e-06 1 5\n",
" -7.779454935491e-04 -6.800063114796e-04 0.000000000000e+00 6.716138938638e+01 -2.064173000222e+02 -1.405963302134e+02 1.779005092730e-04 1.000000000000e-06 1 5\n",
" -2.593702199590e-03 -2.301030494125e-03 0.000000000000e+00 -1.455653402031e+01 2.074634953296e+02 -1.397453142110e+02 1.368567098305e-03 1.000000000000e-06 1 5\n",
" 1.997801509161e-03 2.648416193086e-03 0.000000000000e+00 -2.124047726665e+00 -6.792723569247e+01 6.931081537770e+01 2.616497721112e-04 1.000000000000e-06 1 5\n",
" 1.999741847023e-03 -6.945690451493e-04 0.000000000000e+00 -9.991142908925e+01 -9.189412445573e+01 2.259539675809e+02 -8.681109991004e-04 1.000000000000e-06 1 5\n",
" -7.033822974359e-04 -5.677746866954e-04 0.000000000000e+00 7.520962264129e+02 3.125940718167e+02 -1.451032665210e+02 4.315191990002e-04 1.000000000000e-06 1 5\n"
]
}
],
"source": [
"!head astra_particles.txt"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"# Check the readback\n",
"from pmd_beamphysics.interfaces.astra import parse_astra_phase_file\n",
"import numpy as np\n",
"P1 = ParticleGroup(data=parse_astra_phase_file('astra_particles.txt'))\n",
"for k in ['x', 'px', 'y', 'py', 'z', 'pz']:\n",
" assert np.allclose(P[k], P1[k])"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -154,7 +168,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -163,7 +177,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 12,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -196,7 +210,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 13,
"metadata": {},
"outputs": [
{
Expand All @@ -213,7 +227,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 14,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -256,7 +270,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 15,
"metadata": {},
"outputs": [
{
Expand All @@ -273,7 +287,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 16,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -306,7 +320,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 17,
"metadata": {},
"outputs": [
{
Expand All @@ -323,7 +337,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 18,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -355,15 +369,15 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 19,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"writing 10000 particles to gpt_particles.txt\n",
"ASCII particles written. Convert to GDF using: asci2df -o particles.gdf gpt_particles.txt\n"
"ASCII particles written. Convert to GDF using: asci2gdf -o particles.gdf gpt_particles.txt\n"
]
}
],
Expand All @@ -374,7 +388,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 20,
"metadata": {},
"outputs": [
{
Expand All @@ -392,7 +406,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 21,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -425,7 +439,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -435,7 +449,7 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 23,
"metadata": {},
"outputs": [
{
Expand All @@ -447,7 +461,7 @@
" 'Flagimg': 0}"
]
},
"execution_count": 22,
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -459,7 +473,7 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 24,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -492,7 +506,7 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 25,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -502,7 +516,7 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 26,
"metadata": {},
"outputs": [
{
Expand All @@ -519,7 +533,7 @@
"'litrack.zd'"
]
},
"execution_count": 25,
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -531,7 +545,7 @@
},
{
"cell_type": "code",
"execution_count": 26,
"execution_count": 27,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -574,7 +588,7 @@
},
{
"cell_type": "code",
"execution_count": 27,
"execution_count": 28,
"metadata": {},
"outputs": [
{
Expand All @@ -591,7 +605,7 @@
},
{
"cell_type": "code",
"execution_count": 28,
"execution_count": 29,
"metadata": {},
"outputs": [
{
Expand All @@ -605,10 +619,10 @@
{
"data": {
"text/plain": [
"<ParticleGroup with 10000 particles at 0x16458bbb0>"
"<ParticleGroup with 10000 particles at 0x1116bb130>"
]
},
"execution_count": 28,
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -622,7 +636,7 @@
},
{
"cell_type": "code",
"execution_count": 29,
"execution_count": 30,
"metadata": {},
"outputs": [
{
Expand All @@ -631,7 +645,7 @@
"['BEGINNING']"
]
},
"execution_count": 29,
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -650,7 +664,7 @@
},
{
"cell_type": "code",
"execution_count": 30,
"execution_count": 31,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -663,7 +677,7 @@
},
{
"cell_type": "code",
"execution_count": 31,
"execution_count": 32,
"metadata": {},
"outputs": [
{
Expand All @@ -689,7 +703,7 @@
},
{
"cell_type": "code",
"execution_count": 32,
"execution_count": 33,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -700,7 +714,7 @@
},
{
"cell_type": "code",
"execution_count": 33,
"execution_count": 34,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -733,7 +747,7 @@
},
{
"cell_type": "code",
"execution_count": 34,
"execution_count": 35,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -742,7 +756,7 @@
},
{
"cell_type": "code",
"execution_count": 35,
"execution_count": 36,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -751,7 +765,7 @@
},
{
"cell_type": "code",
"execution_count": 36,
"execution_count": 37,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -760,7 +774,7 @@
},
{
"cell_type": "code",
"execution_count": 37,
"execution_count": 38,
"metadata": {},
"outputs": [],
"source": [
Expand Down
Loading

0 comments on commit a434dd8

Please sign in to comment.