field_map_loaders module

Define functions to load field maps.

warn_norm(path, norm)[source]

Raise this warning only once.

https://stackoverflow.com/questions/31953272/logging-print-message-only-once

Parameters:
load_field_1d(path)[source]

Load a 1D field.

Parameters:

path (Path) – The path to the file to load.

Return type:

tuple[int, float, float, ndarray, int]

Returns:

  • n_z – Number of steps in the array.

  • zmax – z position of the filemap end.

  • norm – Electric field normalisation factor. It is different from k_e (6th argument of the FIELD_MAP command). Electric fields are normalised by k_e/norm, hence norm should be unity by default.

  • f_z – Array holding field. If electric, will be in \(\mathrm{MV/m}\).

  • n_cell – Number of cells in the cavity.

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

load_field_3d(path)[source]

Load a 3D field.

Parameters:

path (Path) – The path to the file to load.

Return type:

tuple[int, float, int, float, float, int, float, float, float, ndarray]

Returns:

  • n_z – Number of steps along the z-axis.

  • zmax – Maximum z position.

  • n_x – Number of steps along the x-axis.

  • xmin – Minimum x position.

  • xmax – Maximum x position.

  • n_y – Number of steps along the y-axis.

  • ymin – Minimum y position.

  • ymax – Maximum y position.

  • norm – Field normalization factor.

  • field_values – 3D array holding field values. If electric, will be in \(\mathrm{MV/m}\).

is_a_valid_3d_field(zmax, n_x, n_y, n_z, field, cavity_length, tol=1e-06, **validity_check_kwargs)[source]

Assert that the 3D field we loaded is valid.

Parameters:
  • n_x (int) – Number of steps along the three axis.

  • n_y (int) – Number of steps along the three axis.

  • n_z (int) – Number of steps along the three axis.

  • zmax (float) – Maximum z position.

  • field (ndarray) – 3D array holding field values.

  • cavity_length (float) – Expected length along the z-axis.

  • tol (float, default: 1e-06) – Tolerance for length comparisons, by default 1e-6.

Return type:

bool

Returns:

Whether the field is valid.

get_number_of_cells(f_z)[source]

Count number of times the array of z-electric field changes sign.

See SO.

Parameters:

f_z (Collection[float])

Return type:

int

field_values_on_axis(field_values, n_x, n_y)[source]

Give only values at x=y=0.

For now, we just hope that the n_x/2 and n_y/2 axis correspond to the axis.

Parameters:
Return type:

ndarray

FIELD_MAP_LOADERS = {'.edz': <function load_field_1d at 0x7318fb4fdc60>}