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',)
load_electromagnetic_fields(field_maps, cython, loadable=('.edz',))[source]

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?

Parameters:
Return type:

None

_geom_to_field_map_type(geom)[source]

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

Parameters:

geom (int)

Return type:

dict[str, str]

_get_filemaps_extensions(field_map_type)[source]

Get the proper file extensions for every field map.

Parameters:

field_map_type (dict[str, str]) – Dictionary which keys are in FIELD_TYPES 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_filemap_extensions(field_type, field_geometry)[source]

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_field_nature(second_word_field_type)[source]

Give first letter of the file extension.

Parameters:

second_word_field_type (Literal["electric", "magnetic"]) – This is the second word in a FIELD_TYPES entry.

Returns:

first_character – First character in the file extension.

Return type:

Literal[“e”, “b”]

_get_type(first_word_field_type)[source]

Give second letter of the file extension.

Parameters:

first_word_field_type (Literal["static", "RF"]) – The first word in a FIELD_TYPES entry.

Returns:

second_character – Second character in the file extension.

Return type:

Literal[“s”, “d”]

_get_field_components(first_words_field_geometry)[source]

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

Parameters:

first_words_field_geometry (Literal['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]

load_field_map_file(field_map, loadable)[source]

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.

Parameters:
Return type:

tuple[Callable[[float], float], int, int] | None

is_a_valid_1d_electric_field(n_z, zmax, f_z, cavity_length, tol=1e-06, **validity_check_kwargs)[source]

Assert that the electric field that we loaded is valid.

Parameters:
Return type:

bool

rescale(f_z, norm, tol=1e-06)[source]

Rescale the array if it was given scaled.

Parameters:
Return type:

ndarray

output_data_in_tw_fashion(linac)[source]

Mimick TW’s Data tab.

Return type:

DataFrame