compute_lost_power_per_meter module

Convert lost power of one or several patran1.out into lost power per meter.

Todo

Sometimes the lost power in first row is 1e-10 or something? Check this out when I see it appear again.

Todo

May be included to post-processing from within LightWin directly

compute(folderpath: Path | str, full_project: bool = False, z_min: float | None = None, z_max: float | None = None, definition: Literal['naive', 'running_mean', 'meter_per_meter'] = 'running_mean', **kwargs) None

Compute the lost power per meter for all given file(s).

Parameters:
  • path (pathlib.Path | str) – Path to a single partran1.out file, or to a full LightWin project.

  • full_project (bool, optional) – Indicate if the given path is a full project. If True, we take all the LightWin out folders in path with a name like 000000_ref or 000032 (we look for folders with 6 digits in it). In each one, we treat 1_TraceWin/partran1.out file. If False, we try to find patran1.out in path/, path/1_TraceWin (if path is not already a file). The default is False.

  • z_min (float | None, optional) – If provided, points outside of this range will be filtered out. The default is None, in which case all points are kept.

  • z_max (float | None, optional) – If provided, points outside of this range will be filtered out. The default is None, in which case all points are kept.

  • definitions (definitions_t) – How the lost power should be calculated.

_treat_single(path: Path, z_min: float | None, z_max: float | None, **kwargs: Any) Series

Load the given filepath and compute lost power in W/m.

_add_linear_losses(df: DataFrame, definition: Literal['naive', 'running_mean', 'meter_per_meter'], **kwargs: Any) None

Add a column holding linear losses in W/m.

_remove_doublons(df: DataFrame, file: Path | str | None = None) None

Remove positions that are represented twice.

_filter_in_range_only(df: DataFrame, z_min: float | None, z_max: float | None) None

Remove the points before z_min or after z_max.

_running_mean(position: Series, quantity: Series, window: float = 1.0, sigma: float = 0.5) list[float]

Provide running_mean of quantity over a length of window.

_meter_per_meter(position: Series, quantity: Series, window: float = 1.0) list[float]

Sum lost power between 0 and 1m, between 1 and 2m, etc.

_treat_full_project(paths: dict[str, Path], z_min: float | None, z_max: float | None, save_folder: Path | None = None, **kwargs: Any) DataFrame

Load several files and concatenate the lost powers.

_get_partran1_filepath(folderpath: Path) Path

Look for partran1.out in folderpath and subfolders.

get_partran1_paths(folderpath: Path, full_project: Literal[True], verbose: bool = False, **kwargs: Any) dict[str, Path]
get_partran1_paths(folderpath: Path, full_project: Literal[False], verbose: bool = False, **kwargs: Any) Path

Gather the file(s) to treat.

_check_validity(df: DataFrame) Series

Print some info to ensure consistency.

_plot_single(df: DataFrame, info: str | None, path: Path | None = None) Figure

Plot the data for validity checking.

_plot_several(df: DataFrame, path: Path | None = None) Figure

Concatenate all plots.

main()