Skip to content

Commit fc989bc

Browse files
deploy: a5a75ef
0 parents  commit fc989bc

File tree

88 files changed

+8459
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+8459
-0
lines changed

.buildinfo

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Sphinx build info version 1
2+
# This file records the configuration used when building these files. When it is not found, a full rebuild will be done.
3+
config: 1749b51d68cc11fb1e3d0436644db4e7
4+
tags: 645f666f9bcd5a90fca523b33c5a78b7

.nojekyll

Whitespace-only changes.

_images/betas.png

83.9 KB
Loading

_sources/authorship.rst.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
==========
2+
Authorship
3+
==========
4+
5+
The following people have contributed to pymad8:
6+
7+
* Stewart Boogert
8+
* Andrey Abramov
9+
* Laurie Nevay
10+
* Will Parker
11+
* William Shields
12+
* Jochem Snuverink
13+
* Stuart Walker
14+
* Marin Deniaud

_sources/convert.rst.txt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
=================
2+
Converting Models
3+
=================
4+
5+
pymad8 provdies converters to allow BDSIM models to prepared from optical
6+
descriptions in MAD8.
7+
8+
For conversion of MAD8 to BDSIM GMAD format, please see the pybdsim documentation
9+
`<http://www.pp.rhul.ac.uk/bdsim/pybdsim/convert.html#mad8-twiss-2-gmad>`_.
10+
11+
Mad8 output required
12+
--------------------
13+
14+
Listed here are the MAD8 lines required to generate various output files.
15+
16+
To make the Twiss and Rmat outputs : ::
17+
18+
use, LINE
19+
twiss, beta0=LINE.B0, save, couple, tape=TWISS_LINE rtape=RMAT_LINE
20+
21+
To make the Chrom output : ::
22+
23+
use, LINE
24+
twiss, beta0=LINE.B0, save, chrom, tape=CHROM_LINE
25+
26+
To make the Envelope output : ::
27+
28+
use, LINE
29+
envel, sigma0=LINE.SIGMA0, save, tape=ENVEL_LINE
30+
31+
To make the Survey output : ::
32+
33+
use, LINE
34+
survey, tape=SURVEY_LINE
35+

_sources/data.rst.txt

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
================================
2+
MAD8 File Loading & Manipulation
3+
================================
4+
5+
MAD8 outputs Twiss information in their own file format.
6+
pymad8 includes a class called Output for the purpose of loading and manipulating this data.
7+
8+
The MAD8 format is described in the manual available from `the mad8 website <http://mad8.web.cern.ch>`_.
9+
The format is roughly described as a text file.
10+
The MAD8 files contain first a few lines that indicate when the file was generated and other general informations.
11+
After this, each segment of 5 lines typically represents the values of the lattice for a particular element with each new segment containing the values at a subsequent element in the lattice.
12+
13+
Output Class Features
14+
---------------------
15+
16+
* Loading different types of MAD8 files.
17+
* Get a particular column.
18+
* Get a particular row.
19+
* Get elements of a particular type.
20+
* Get a numerical index from the name of the element.
21+
* Find the curvilinear S coordinate of an element by name.
22+
* Find the name of the nearest element at a given S coordinate.
23+
* Plot an optics diagram.
24+
* Calculate a beam size given the Twiss parameters, dispersion and emittance.
25+
* Make a slice of the initial lattice
26+
27+
Loading
28+
-------
29+
30+
MAD8 files can be of different types.
31+
Twiss files are the main ones but we can also load Rmat files, Chrom files, Envelope files or Survey files
32+
33+
A file may be loading by constructing an Output instance from a file name :
34+
35+
>>> import pymad8
36+
>>> t = pymad8.Output("myTwissFile")
37+
>>> r = pymad8.Output("myRmatFile", "rmat")
38+
>>> c = pymad8.Output("myChromFile", "chrom")
39+
>>> e = pymad8.Output("myEnvelopeFile", "envel")
40+
>>> s = pymad8.Output("mySurveyFile", "survey")
41+
42+
.. note:: The import will be assumed from now on in examples.
43+
44+
Querying
45+
--------
46+
47+
The Output class can be used to query the data in various ways.
48+
49+
Basic Information
50+
*****************
51+
52+
* All data is stored in the **data** object inside the class
53+
* The number of elements is stored in **nrec**.
54+
* The file name is stored in **filename**.
55+
* The file type is stored in **filetype**.
56+
* A dict of each element type and corresponding properties is stored in **keys_dict**
57+
* The names of columns common to all file types is stored in **colnames_common**.
58+
59+
The **data** object is a pandas dataframe that can be displayed as follow :
60+
61+
>>> t = pymad8.Output("myTwissFile")
62+
>>> t.data
63+
64+
Indexing and Slicing
65+
********************
66+
67+
The information stored in the dataframe is accessible using regular pandas syntax : ::
68+
69+
t.data.iloc[3] # 4th element in sequence (Pandas.Series returned)
70+
t.data.iloc[3: 10] # 4th to 11th elements (Pandas.Dataframe returned)
71+
t.data.iloc[[3, 5, 10]] # 4th, 6th and 11th elements (Dataframe)
72+
t.data['S'] # column named exactly S (Series)
73+
t.data[['S', 'L']] # columns named exactly S and L (Dataframe)
74+
t.data['S'][3] # value of the 4th element in the column S
75+
t.data[t.data['NAME'] == 'INITIAL'] # Row of the element with this exact name (Dataframe)
76+
77+
But you can also find information about elements usind built-in functions.
78+
79+
To get index for example ::
80+
81+
t.getIndexByNames('INITIAL') # can have a list of names as input
82+
t.getIndexByTypes('QUAD') # can have a list of types as input
83+
t.getIndexByValues(key='S', minValue=200) # indices of elements with S value above 200
84+
t.getIndexByNearestS(150) # index of element with S value closest to 150
85+
86+
The results are returned in the form of one value or a list of values, depending on the input given.
87+
In the case of the getIndex function, we get either an integer or a list of integers
88+
89+
.. note:: Similar functions are avaliable to find names and types of lattice elements
90+
91+
Rows and Columns
92+
****************
93+
94+
A row of data is an entry for a particular element. The Output class is conceptually a list of
95+
elements. Each element is represented by a row in the pandas dataframe that has a key for each column.
96+
The list of acceptable keys (i.e. names of columns) can be found in the member named 'colums' : ::
97+
98+
t.data.columns #prints out list of column names
99+
100+
A specific row or set of rows can be accessed using similar functions as those previously shown : ::
101+
102+
t.getRowsByIndex(3) # can have a list of indices as input
103+
t.getRowsByNames('INITIAL') # can have a list of names as input
104+
t.getRowsByTypes('QUAD') # can have a list of types as input
105+
t.getRowsByValues(key='S', minValue=200) # rows of elements with S value above 200
106+
t.getRowByNearestS(150) # row of element with S value closest to 150
107+
108+
The results are return either in the form of a dataframe or serie (which is equivalent to a dataframe with only one row), depending on the input given.
109+
110+
A specific column or set of columns can be accessed using its keys (i.e. its names) : ::
111+
112+
t.getColumnsByKeys(['S','L'])
113+
114+
Beam Sizes
115+
----------
116+
117+
For convenience the beam size is calculated from the Beta amplitude functions, the emittance, dispersion and enegy spread using `calcBeamSize()`.
118+
The emittance is defined by 'EmitX' and 'EmitY' and the energy spread by 'Esprd'.
119+
Those three parameters aren't provided by MAD8 and must be manualy given to the function : ::
120+
121+
EmitX = 3e-11
122+
EmitY = 3e-11
123+
Esprd = 1e-6
124+
t.calcBeamSize(EmitX, EmitY, Esprd)
125+
126+
In this function, the beam sizes are calculated according to :
127+
128+
.. math::
129+
130+
\sigma_x &= \sqrt{ \beta_x \epsilon_x + D(S)^2 \frac{\sigma_{E}^{2}}{E_{0}^{2}}} \\
131+
\sigma_y &= \sqrt{ \beta_y \epsilon_y + D(S)^2 \frac{\sigma_{E}^{2}}{E_{0}^{2}}}
132+

_sources/index.rst.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
pymad8 documentation
2+
====================
3+
4+
pymad8 is a Python package to aid in the preparation, running and validation
5+
of BDSIM models.
6+
7+
.. toctree::
8+
:maxdepth: 2
9+
10+
licence
11+
authorship
12+
installation
13+
data
14+
plot
15+
convert
16+
simulation
17+
support
18+
moduledocs
19+
version_history
20+
21+
Indices and tables
22+
==================
23+
24+
* :ref:`genindex`
25+
* :ref:`modindex`
26+
* :ref:`search`

_sources/installation.rst.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
============
2+
Installation
3+
============
4+
5+
6+
Packages requirements
7+
---------------------
8+
9+
* numpy
10+
* matplotlib
11+
* pylab
12+
* pandas
13+
* fortranformat
14+
15+
pymad8 is developed for Python 3 but should be Python 2 compatible.
16+
17+
Installation
18+
------------
19+
20+
21+
To install pymad8, simply run ``make install`` from the root pymad8
22+
directory.::
23+
24+
cd /my/path/to/repositories/
25+
git clone http://bitbucket.org/jairhul/pymad8
26+
cd pymad8
27+
make install
28+
29+
Alternatively, run ``make develop`` from the same directory to ensure
30+
that any local changes are picked up.

_sources/licence.rst.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
====================
2+
Licence & Disclaimer
3+
====================
4+
5+
pymad8 Copyright (C) Royal Holloway, University of London 2024.
6+
7+
pymad8 is free software: you can redistribute it and/or modify
8+
it under the terms of the GNU General Public License as published
9+
by the Free Software Foundation version 3 of the License.
10+
11+
pymad8 is distributed in the hope that it will be useful, but
12+
WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with pymad8. If not, see <http://www.gnu.org/licenses/>.

_sources/moduledocs.rst.txt

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
===============
2+
Module Contents
3+
===============
4+
5+
This documentation is automatically generated by scanning all the source code. Parts
6+
may be incomplete.
7+
8+
.. automodule:: pymad8
9+
10+
pymad8.Input module
11+
-----------------------
12+
13+
.. automodule:: pymad8.Input
14+
:members:
15+
:undoc-members:
16+
:show-inheritance:
17+
18+
pymad8.Output module
19+
-----------------------
20+
21+
.. automodule:: pymad8.Output
22+
:members:
23+
:undoc-members:
24+
:show-inheritance:
25+
26+
pymad8.Plot module
27+
------------------
28+
29+
.. automodule:: pymad8.Plot
30+
:members:
31+
:undoc-members:
32+
:show-inheritance:
33+
34+
pymad8.Sim module
35+
-----------------
36+
37+
.. automodule:: pymad8.Sim
38+
:members:
39+
:undoc-members:
40+
:show-inheritance:
41+
42+
pymad8.Track module
43+
-------------------
44+
45+
.. automodule:: pymad8.Track
46+
:members:
47+
:undoc-members:
48+
:show-inheritance:
49+
50+
pymad8.Visualisation module
51+
---------------------------
52+
53+
.. automodule:: pymad8.Visualisation
54+
:members:
55+
:undoc-members:
56+
:show-inheritance:

0 commit comments

Comments
 (0)