Base Module¶
ScanAnalysis.scan_analysis.base ¶
Base classes and utilities for scan analyzers.
This module provides shared infrastructure for scan-level analyses. The core
entry point is :class:ScanAnalyzer, which handles locating scan folders,
parsing the .ini metadata, loading auxiliary data (the s-file), and exposing a
uniform run_analysis() flow that concrete analyzers implement via
_run_analysis_core().
All analyzers must inherit from :class:ScanAnalyzer and implement
_run_analysis_core().
Classes:
| Name | Description |
|---|---|
DataLengthError |
Raised when data arrays have inconsistent lengths. |
DataUnavailableWarning |
Raised when a device's data directory is missing or empty for a scan. |
ScanParameter |
Lightweight wrapper for scan parameter string with common renderings. |
ScanAnalyzer |
Base class for performing analysis on scan data. |
Functions:
| Name | Description |
|---|---|
testing_routine |
Simple dev sanity check. |
Attributes:
| Name | Type | Description |
|---|---|---|
logger |
|
Attributes¶
Classes¶
DataLengthError ¶
Bases: ValueError
Raised when data arrays have inconsistent lengths.
DataUnavailableWarning ¶
Bases: Exception
Raised when a device's data directory is missing or empty for a scan.
This is an expected condition when an analyzer is configured for a device
that was not active during a particular scan. It is caught separately from
unexpected errors so that a clean warning is logged without a traceback,
and the task queue records the state as no_data rather than failed.
ScanParameter ¶
Bases: NamedTuple
Lightweight wrapper for scan parameter string with common renderings.
Methods:
| Name | Description |
|---|---|
with_colon |
Return the raw parameter as-is (including colons). |
with_space |
Return parameter with colons replaced by spaces. |
__str__ |
Return default string form (same as |
Attributes:
| Name | Type | Description |
|---|---|---|
raw_string |
str
|
|
Attributes¶
Functions¶
with_colon ¶
with_colon()
Return the raw parameter as-is (including colons).
Source code in ScanAnalysis/scan_analysis/base.py
53 54 55 | |
with_space ¶
with_space()
Return parameter with colons replaced by spaces.
Source code in ScanAnalysis/scan_analysis/base.py
57 58 59 | |
__str__ ¶
__str__()
Return default string form (same as with_colon() or with_space() usage).
Source code in ScanAnalysis/scan_analysis/base.py
61 62 63 64 | |
ScanAnalyzer ¶
ScanAnalyzer(skip_plt_show: bool = True, device_name: Optional[str] = None, use_injected_data: bool = False, **kwargs)
Base class for performing analysis on scan data.
Responsibilities
- Resolve scan paths from a :class:
geecs_data_utils.ScanTag. - Read the scan
.inifile and extract the "Scan Parameter". - Load auxiliary s-file data (tab-delimited) into a DataFrame.
- Provide convenience helpers (e.g., label generation, s-file append).
- Define the
run_analysis()entry point that calls a subclass-provided :meth:_run_analysis_core.
Attributes:
| Name | Type | Description |
|---|---|---|
scan_directory |
Path | None
|
Path to the scan directory containing data. |
auxiliary_file_path |
Path | None
|
Path to the auxiliary s-file ( |
ini_file_path |
Path | None
|
Path to the |
scan_parameter |
str | None
|
The cleaned scan parameter label (spaces or colons depending on configuration). |
bins |
ndarray | None
|
Bin numbers from the auxiliary file. |
auxiliary_data |
DataFrame | None
|
Loaded auxiliary data (s-file) used by downstream analyses. |
Initialize the analyzer and default state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skip_plt_show
|
bool
|
If |
True
|
device_name
|
str
|
Logical device name the analyzer is associated with. Purely informational here; concrete analyzers may use it to locate files. |
None
|
use_injected_data
|
bool
|
When When Contract is intentionally tight: the base class never reaches
out to any in-memory data source itself (that would invert
the dep graph through Scanner-GUI's |
False
|
**kwargs
|
Additional analyzer-specific options (ignored by the base class). |
{}
|
Methods:
| Name | Description |
|---|---|
run_analysis |
Load inputs and dispatch to the subclass core analysis. |
cleanup |
Release per-scan memory after analysis completes. |
extract_scan_parameter_from_ini |
Extract and normalize the scan parameter label from the |
load_auxiliary_data |
Load auxiliary s-file (tab-delimited) and derive bins/scan values. |
close_or_show_plot |
Show or close figures based on |
append_to_sfile |
Append or overwrite s-file columns (merging on Shotnumber with a lock). |
generate_limited_shotnumber_labels |
Generate evenly spaced shot-number labels with an upper bound on count. |
find_scan_param_column |
Locate the column in the auxiliary DataFrame that corresponds to the scan parameter. |
find_column_for_key |
Locate an auxiliary-data column that matches a user-supplied key string. |
Source code in ScanAnalysis/scan_analysis/base.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
Attributes¶
Functions¶
run_analysis ¶
run_analysis(scan_tag: ScanTag) -> Optional[list[Union[Path, str]]]
Load inputs and dispatch to the subclass core analysis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scan_tag
|
ScanTag
|
Tag identifying the scan to analyze. |
required |
Returns:
| Type | Description |
|---|---|
list[Path | str] or None
|
Optional list of notable artifact paths/labels produced by analysis
(for experiment logs). Returns |
Source code in ScanAnalysis/scan_analysis/base.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | |
cleanup ¶
cleanup() -> None
Release per-scan memory after analysis completes.
Must be implemented by all subclasses. Called by the task runner after each analyzer finishes so that loaded data and results do not accumulate across scans. Failing to implement this will raise NotImplementedError and halt the runner — intentionally, to prevent unbounded memory growth.
Source code in ScanAnalysis/scan_analysis/base.py
178 179 180 181 182 183 184 185 186 187 | |
extract_scan_parameter_from_ini ¶
extract_scan_parameter_from_ini() -> str
Extract and normalize the scan parameter label from the .ini file.
Returns:
| Type | Description |
|---|---|
str
|
Cleaned scan parameter. By default, colons are replaced with spaces
unless |
Source code in ScanAnalysis/scan_analysis/base.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | |
load_auxiliary_data ¶
load_auxiliary_data()
Load auxiliary s-file (tab-delimited) and derive bins/scan values.
Notes
- When
use_injected_datais True, callers are expected to setself.auxiliary_datadirectly; this method does nothing. - For non-
noscancases, the per-bin mean of the scan parameter column is computed intoself.binned_param_values.
Source code in ScanAnalysis/scan_analysis/base.py
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | |
close_or_show_plot ¶
close_or_show_plot()
Show or close figures based on skip_plt_show.
Source code in ScanAnalysis/scan_analysis/base.py
313 314 315 316 317 318 | |
append_to_sfile ¶
append_to_sfile(data: DataFrame) -> None
Append or overwrite s-file columns (merging on Shotnumber with a lock).
Only accepts a DataFrame and requires an explicit Shotnumber column
(case-insensitive match is accepted and normalized).
Rows without Shotnumber are dropped with a warning.
Source code in ScanAnalysis/scan_analysis/base.py
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 | |
generate_limited_shotnumber_labels ¶
generate_limited_shotnumber_labels(max_labels: int = 20) -> np.ndarray
Generate evenly spaced shot-number labels with an upper bound on count.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_labels
|
int
|
Maximum number of labels to return. |
20
|
Returns:
| Type | Description |
|---|---|
ndarray
|
If the total number of shots is <= |
Source code in ScanAnalysis/scan_analysis/base.py
501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 | |
find_scan_param_column ¶
find_scan_param_column() -> tuple[Optional[str], Optional[str]]
Locate the column in the auxiliary DataFrame that corresponds to the scan parameter.
Returns:
| Type | Description |
|---|---|
tuple[str | None, str | None]
|
|
Notes
- Matching is performed against the part of the column name preceding
' Alias:'to tolerate aliasing in s-files.
Source code in ScanAnalysis/scan_analysis/base.py
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 | |
find_column_for_key ¶
find_column_for_key(key: str) -> Optional[str]
Locate an auxiliary-data column that matches a user-supplied key string.
Tries the key as-is, with colons replaced by spaces, and with spaces
replaced by colons, performing a substring match against the portion of
each column name that precedes any ' Alias:' suffix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
User-supplied string, e.g. |
required |
Returns:
| Type | Description |
|---|---|
str or None
|
The first matching column name (full, including any alias suffix),
or |
Source code in ScanAnalysis/scan_analysis/base.py
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 | |
Functions¶
testing_routine ¶
testing_routine()
Simple dev sanity check.
Source code in ScanAnalysis/scan_analysis/base.py
593 594 595 596 | |