pyccapt.control.core package

Submodules

pyccapt.control.core.baking_loging module

pyccapt.control.core.baking_loging.animate(i)[source]

Animation function for plotting.

pyccapt.control.core.baking_loging.daq_tc()[source]

This function performs DAQ operations related to temperature measurement and control.

pyccapt.control.core.baking_loging.plot_baking(df, window=0)[source]

Plot baking data.

pyccapt.control.core.baking_loging.read()[source]

This function reads data from sensors and logs it.

pyccapt.control.core.com_ports module

pyccapt.control.core.com_ports.list_com_ports()[source]

List all available COM ports on the system.

Parameters:

None

Returns:

A list of available COM ports.

Return type:

list

pyccapt.control.core.control_data_tool module

pyccapt.control.core.control_data_tool.concatenate_datasets(hdf5_file_path_1, hdf_file_path_2, index_2)[source]

Concatenate datasets in nested HDF5 groups.

pyccapt.control.core.control_data_tool.copy_npy_to_hdf_surface_concept(path, hdf5_file_name)[source]

copy npy data to hdf5 file for surface concept TDC

Parameters:
  • path – path to the npy files

  • hdf5_file_name – name of the hdf5 file

Returns:

None

pyccapt.control.core.control_data_tool.correct_surface_concept_old_data(hdf5_file_path)[source]

correct surface concept old data

Parameters:

hdf5_file_path – path to the hdf5 file

Returns:

None

pyccapt.control.core.control_data_tool.crop_dataset_to_new_file(original_path, new_path, num_of_samples)[source]

Crop dataset and save to a new file.

Parameters:
  • original_path – Path to the original dataset.

  • new_path – Path to save the cropped dataset.

  • num_of_samples – Number of samples to keep.

Returns:

None

pyccapt.control.core.control_data_tool.load_and_copy_chunks_to_hdf(path, hdf5_file_path, chunk_id)[source]
pyccapt.control.core.control_data_tool.rename_subcategory(hdf5_file_path, old_name, new_name)[source]

rename subcategory

Parameters:
  • hdf5_file_path – path to the hdf5 file

  • old_name – old name of the subcategory

  • new_name – new name of the subcategory

Returns:

None

pyccapt.control.core.experiment_statistics module

pyccapt.control.core.experiment_statistics.save_statistics_apt(variables, conf)[source]

Save setup parameters and run statistics in a text file.

Parameters:
  • variables (object) – An object containing experiment variables.

  • conf (dict) – A dictionary containing the configuration file parameters.

Returns:

None

pyccapt.control.core.hdf5_creator module

pyccapt.control.core.hdf5_creator.hdf_creator(variables, conf, time_counter, time_ex)[source]

Save experiment data to an HDF5 file.

Parameters:
  • variables (object) – An object containing experiment variables.

  • conf (dict) – A dictionary containing configuration settings.

  • time_counter (list) – A list of time counter data.

  • time_ex (list) – A list of timestamp of iteration.

Returns:

None

pyccapt.control.core.loggi module

Application and per-experiment logging for the pyccapt control package.

There are two layers:

  1. Application logging — configured once at GUI startup via setup_application_logging(). This installs:

    • A rotating per-day file handler under <project_root>/files/logs/gui/gui_<YYYY-MM-DD>.log. Files rotate at 5 MiB, with 10 backups kept. The intent is that this log captures everything the operator needs to diagnose what happened in a given day, without growing without bound.

    • A console handler that mirrors records to stderr at INFO level (so the operator still sees the same kind of output that print was producing before).

    • logging.captureWarnings(True) so Python warnings land in the log.

    • A sys.excepthook replacement so otherwise-uncaught exceptions are written to the log with a full traceback before propagating.

    • An optional sys.stdout / sys.stderr mirror: every print call in the GUI process is duplicated into the log without losing console output.

  2. Per-experiment logging — logger_creator() returns a logger whose own dedicated file lives in the experiment’s meta_data folder (<exp>/meta_data/apt.log by default). Because the per-experiment logger inherits from the root logger configured in step 1, every experiment record is also captured in the daily GUI log, giving a single chronological view across multiple experiments while keeping each experiment’s own folder self-contained for archival.

Both functions are idempotent: calling them multiple times will not produce duplicate handlers or duplicate log lines.

pyccapt.control.core.loggi.log_configuration_snapshot(logger: Logger, conf: dict[str, Any], variables: Any | None = None) None[source]

Log a stable subset of config keys so we can compare runs after the fact.

This is informational only and never raises.

pyccapt.control.core.loggi.logger_creator(script_name: str, variables: Any, log_name: str, path: PathLike[str] | str) Logger[source]

Create or fetch a per-experiment logger writing to <path>/<log_name>.

This signature matches the historical API and is used by apt_exp_control.py to attach a dedicated log file to each experiment’s meta_data folder.

Behaviours:

  • Inherits from the root logger, so the same records also appear in the GUI session log configured by setup_application_logging().

  • Has its own dedicated file handler in the experiment folder.

  • Is idempotent: a duplicate file handler is not created on repeat calls.

  • Always returns a working logger object. If the file handler cannot be attached (permissions, missing folder, etc.) the returned logger still accepts .info / .warning / .exception calls — they just won’t be persisted to the experiment file. This avoids cascading AttributeError: 'NoneType' object has no attribute 'info' failures later in the experiment hot path.

Parameters:
  • script_name – Logger name. Conventional value is "apt".

  • variables – Shared variables namespace (currently unused, kept for backwards compatibility with the previous signature).

  • log_name – File name (e.g. "apt.log").

  • path – Directory in which to create the file. Created if missing.

Returns:

A configured logging.Logger.

pyccapt.control.core.loggi.setup_application_logging(project_root: PathLike[str] | str, *, console_level: int = 20, file_level: int = 10, mirror_stdio: bool = True) Logger[source]

Configure the root logger for the running pyccapt process.

Parameters:
  • project_root – Project root directory (the folder that contains config.toml and files/). The GUI log file is created under <project_root>/files/logs/gui/.

  • console_level – Verbosity for the console mirror. The file always records file_level and below regardless of console level.

  • file_level – Verbosity for the rotating file. Defaults to DEBUG so the log file always contains the most detail available.

  • mirror_stdio – When True (the default), print output is also recorded in the log. Console output is preserved.

Returns:

The pyccapt.gui logger. Returning a child logger here, rather than the root logger, gives downstream code a sensible default name for records that do not specify their own logger.

pyccapt.control.core.read_files module

File-loading helpers for the control package.

pyccapt.control.core.read_files.load_config_file(config_file_path: str | Path) dict[str, Any][source]

Load a control configuration file from .toml.

Parameters:

config_file_path – Absolute or relative path to the config file.

Returns:

Parsed config dictionary.

Raises:

ValueError – If file extension is unsupported.

pyccapt.control.core.read_files.normalize_control_config(config: dict[str, Any]) dict[str, Any][source]

Normalize supported control config toggle aliases to legacy values.

pyccapt.control.core.read_files.read_json_file(json_file_path: str | Path) dict[str, Any][source]

Read a JSON file and return its content as a dictionary.

Parameters:

json_file_path – Absolute or relative path to the JSON file.

Returns:

Parsed JSON content.

Raises:
pyccapt.control.core.read_files.read_toml_file(toml_file_path: str | Path) dict[str, Any][source]

Read a TOML file and return its content as a dictionary.

Parameters:

toml_file_path – Absolute or relative path to the TOML file.

Returns:

Parsed TOML content.

Raises:

pyccapt.control.core.share_variables module

Shared process-safe variables used by the control module.

Variable ownership

Every entry in Variables._OWNERSHIP lists who writes and who reads it. This is the authoritative map - if you add a new shared field, document it there too. Variables not listed are flagged as ("?",  ("?",)) so they’re easy to find with grep and audit.

Process keys (single letters keep the table narrow):
main - main GUI process (also hosts the Gates, Pumps&Vacuum,

Baking, Laser, Stage sub-windows that don’t have their own subprocess)

exp - experiment subprocess (apt_exp_control.run_experiment) tdc - TDC subprocess (tdc_surface_concept / tdc_roentdek /

tdc_surface_concept_t_*)

drs - DRS digitiser subprocess cam - camera subprocess (gui_cameras.run_camera_window) viz - visualization subprocess (gui_visualization.run_visualization_window) pump - pumps & vacuum reader thread (lives inside main) ? - ownership not yet audited

class pyccapt.control.core.share_variables.Variables(conf: Mapping[str, Any], namespace: Any)[source]

Bases: object

Expose shared experiment state through a manager-backed namespace.

The class keeps backward compatibility with existing variables.<name> access while removing thousands of lines of repetitive property code.

See module docstring for the writer / reader ownership map (_OWNERSHIP). Plot data (x_plot / y_plot / t_plot / main_v_dc_plot) is NOT on this namespace - it lives in pyccapt.control.core.shared_ring_buffer.SharedRingBuffer instances passed explicitly as arguments to subprocess targets.

clear_to(variable_name: str) None[source]

Clear a shared list attribute by replacing it with an empty list.

extend_to(variable_name: str, value: Iterable[Any]) None[source]

Extend a shared list attribute with iterable values.

snapshot() dict[str, Any][source]

Return a shallow snapshot of all currently known shared fields.

pyccapt.control.core.tof2mc_simple module

pyccapt.control.core.tof2mc_simple.tof_2_mc(t, t0, V, xDet, yDet, flightPathLength)[source]

Calculate the m/c for

Parameters:
  • t (float) – Time in ns.

  • t0 (float) – T0 correction in ns.

  • V (float) – Voltage.

  • xDet (float) – X-coordinate of the detector in cm.

  • yDet (float) – Y-coordinate of the detector in cm.

  • flightPathLength (float) – Flight path length in mm.

Returns:

Calculated m/c value.

Return type:

float

Module contents