flame_utils.io package
Submodules
flame_utils.io.lattice module
FLAME lattice operations.
- flame_utils.io.lattice.generate_latfile(machine, latfile=None, state=None, original=None, out=None, start=None, end=None)[source]
Generate lattice file for the usage of FLAME code.
- Parameters
- machine :
FLAME machine object.
- latfile :
File name for generated lattice file.
- original :
File name for original lattice file to keep user comments and indents. (optional)
- state :
BeamState object, accept FLAME internal State object also. (optional)
- out :
New stream paramter, file stream. (optional)
- start :
Start element (id or name) of generated lattice. (optional)
- end :
End element (id or name) of generated lattice. (optional)
- Returns
- filenamestr
None if failed to generate lattice file, or the out file name.
Notes
If latfile and out are not defined, will print all output to screen;
If latfile and out are all defined, out stream is preferred;
For other cases, choose one that is defined.
If start is defined, user should define state also.
If user define start only, the initial beam state is the same as the machine.
Parameter out can also be
StringIO
, and get string bygetvalue()
.To get element configuration only by
m.conf(i)
method, wherem
isflame.Machine
object,i
is element index, when some re-configuring operation is done,m.conf(i)
will be update, butm.conf()["elements"]
remains with the initial values.
Examples
>>> from flame import Machine >>> latfile = 'test.lat' >>> m = Machine(open(latfile)) >>> outfile1 = generate_latfile(m, latfile='out1.lat') >>> m.reconfigure(80, {'theta_x': 0.1}) >>> outfile2 = generate_latfile(m, latfile='out2.lat') >>> # recommand new way >>> fout = open('out.lat', 'w') >>> generate_latfile(m, out=fout)
flame_utils.io.output module
Output from FLAME.
- flame_utils.io.output.convert_results(res, **kws)[source]
Convert all beam states of results generated by
run()
method to beBeamState
object.- Parameters
- reslist of tuple
List of propagation results.
- Returns
- list of tuple
Tuple of
(r, s)
, wherer
is list of results at each monitor points,s
isBeamState
object after the last monitor point.
- flame_utils.io.output.collect_data(result, *args, **kws)[source]
Collect data of interest from propagation results.
- Parameters
- result :
Propagation results with
BeamState
object.- args :
Names of attribute, separated by comma.
- Returns
- dict
Dict of
{k1:v1, k2,v2...}
, keys are from keyword parameters.
See also
BeamState
FLAME beam state class for
MomentMatrix
simulation type.
Notes
Set the data of interest with
k=True
as input will return the definedk
value.Invalid attribute names will be ignored.
Examples
>>> # get x0 and y0 array >>> collect_data(r, x0=True, y0=True) >>> # which is equivalent as: >>> collect_data(r, 'x0', 'y0') >>> # or: >>> collect_data(r, 'x0', y0=True)
Module contents
- flame_utils.io.generate_latfile(machine, latfile=None, state=None, original=None, out=None, start=None, end=None)[source]
Generate lattice file for the usage of FLAME code.
- Parameters
- machine :
FLAME machine object.
- latfile :
File name for generated lattice file.
- original :
File name for original lattice file to keep user comments and indents. (optional)
- state :
BeamState object, accept FLAME internal State object also. (optional)
- out :
New stream paramter, file stream. (optional)
- start :
Start element (id or name) of generated lattice. (optional)
- end :
End element (id or name) of generated lattice. (optional)
- Returns
- filenamestr
None if failed to generate lattice file, or the out file name.
Notes
If latfile and out are not defined, will print all output to screen;
If latfile and out are all defined, out stream is preferred;
For other cases, choose one that is defined.
If start is defined, user should define state also.
If user define start only, the initial beam state is the same as the machine.
Parameter out can also be
StringIO
, and get string bygetvalue()
.To get element configuration only by
m.conf(i)
method, wherem
isflame.Machine
object,i
is element index, when some re-configuring operation is done,m.conf(i)
will be update, butm.conf()["elements"]
remains with the initial values.
Examples
>>> from flame import Machine >>> latfile = 'test.lat' >>> m = Machine(open(latfile)) >>> outfile1 = generate_latfile(m, latfile='out1.lat') >>> m.reconfigure(80, {'theta_x': 0.1}) >>> outfile2 = generate_latfile(m, latfile='out2.lat') >>> # recommand new way >>> fout = open('out.lat', 'w') >>> generate_latfile(m, out=fout)
- flame_utils.io.convert_results(res, **kws)[source]
Convert all beam states of results generated by
run()
method to beBeamState
object.- Parameters
- reslist of tuple
List of propagation results.
- Returns
- list of tuple
Tuple of
(r, s)
, wherer
is list of results at each monitor points,s
isBeamState
object after the last monitor point.
- flame_utils.io.collect_data(result, *args, **kws)[source]
Collect data of interest from propagation results.
- Parameters
- result :
Propagation results with
BeamState
object.- args :
Names of attribute, separated by comma.
- Returns
- dict
Dict of
{k1:v1, k2,v2...}
, keys are from keyword parameters.
See also
BeamState
FLAME beam state class for
MomentMatrix
simulation type.
Notes
Set the data of interest with
k=True
as input will return the definedk
value.Invalid attribute names will be ignored.
Examples
>>> # get x0 and y0 array >>> collect_data(r, x0=True, y0=True) >>> # which is equivalent as: >>> collect_data(r, 'x0', 'y0') >>> # or: >>> collect_data(r, 'x0', y0=True)