tracewin_utils.electromagnetic_fields module

Define functions to handle TraceWin electromagnetic fields.

Note

Last compatibility check: TraceWin v2.22.1.0

Todo

some functions are not used anymore I guess…

Todo

Better handling of the module import

FIELD_GEOMETRIES = {0: 'no field', 1: '1D: F(z)', 2: 'not available', 3: 'not available', 4: '2D cylindrical static or RF electric field', 5: '2D cylindrical static or RF magnetic field', 6: '2D cartesian field', 7: '3D cartesian field', 8: '3D cylindrical field', 9: '1D: G(z)'}
FIELD_TYPES = ('static electric field', 'static magnetic field', 'RF electric field', 'RF magnetic field', '3D aperture map')
LOADABLE = ('.edz',)
_geom_to_field_map_type(geom: int) dict[str, str]

Determine the field map type from TraceWin’s geom parameter.

Examples

geom == 100 will lead to {'RF electric field': '1D: F(z)', 'static magnetic field': 'no field', 'static electric field': 'no field'}

geom == 7700 will lead to {'RF magnetic field': '3D cartesian field', 'RF electric field': '3D cartesian field', 'static magnetic field': 'no field', 'static electric field': 'no field'}

Note that every key associated with a 'no field' or 'not available' value will be removed from the dictionary before returning.

Notes

Last compatibility check: TraceWin v2.22.1.0

_get_field_components(first_words_field_geometry: str) list[str]

Give last letter of the extension of every file to load.

Parameters:

first_words_field_geometry ({'1D:', '2D cylindrical', '2D cartesian', '3D cartesian', '3D cylindrical'}) – Beginning of a FIELD_GEOMETRIES value.

Returns:

third_characters – Last extension character of every file to load.

Return type:

list[str]

_get_field_nature(second_word_field_type: str) str

Give first letter of the file extension.

Parameters:

second_word_field_type ({'electric', 'magnetic'}) – This is the second word in a FIELD_TYPE entry.

Returns:

first_character – First character in the file extension.

Return type:

{‘e’, ‘b’}

_get_filemap_extensions(field_type: str, field_geometry: str) list[str]

Get the proper file extensions for the file map under study.

Parameters:
  • field_type (str) – Type of the field/aperture. Allowed values are in FIELD_TYPES.

  • field_geometry (str) – Name of the geometry of the field, as in TraceWin. Allowed values are values of FIELD_GEOMETRIES.

Returns:

extensions – Extension without ‘.’ of every file to load.

Return type:

list[str]

_get_filemaps_extensions(field_map_type: dict[str, str]) dict[str, list[str]]

Get the proper file extensions for every field map.

Parameters:

field_map_type (dict[str, str]) – Dictionary which keys are in FIELD_TYPE and values are values of FIELD_GEOMETRIES.

Returns:

extensions – Dictionary with the same keys as input. The values are lists containing all the extensions of the files to load, without a ‘.’.

Return type:

dict[str, list[str]]

_get_type(first_word_field_type: str) str

Give second letter of the file extension.

Parameters:

first_word_field_type ({'static', 'RF'}) – The first word in a FIELD_TYPE entry.

Returns:

second_character – Second character in the file extension.

Return type:

{‘s’, ‘d’}

_is_a_valid_electric_field(n_z: int, zmax: float, f_z: ndarray, cavity_length: float, tol: float = 1e-06) bool

Assert that the electric field that we loaded is valid.

_load_electromagnetic_fields_for_cython(field_maps: list[FieldMap], loadable: Sequence[str]) None

Load one electric field per section.

_load_field_map_file(field_map: FieldMap, loadable: Collection[str]) tuple[Callable[[float | ndarray], float | ndarray] | None, int | None, int | None]

Go across the field map file names and load the first recognized.

For now, only .edz files (1D electric RF) are implemented. This will be a problem with Envelope1D, but TraceWin does not care.

_rescale(f_z: ndarray, norm: float, tol: float = 1e-06) ndarray

Rescale the array if it was given scaled.

load_electromagnetic_fields(field_maps: Collection[FieldMap], cython: bool, loadable: Collection[str] = ('.edz',)) None

Load field map files into the FieldMap objects.

As for now, only 1D RF electric field are handled by Envelope1D. With TraceWin, every field is supported.

Todo

I think that this should be a method right? Different FieldMap objects -> different loading func?

output_data_in_tw_fashion(linac) DataFrame

Mimick TW’s Data tab.