trace_reader Module
This module defines a TraceReader for Spyral
Event
dataclass
Simple dataclass wrapping the event data
Attributes:
Name | Type | Description |
---|---|---|
id |
int
|
The event id number |
get |
GetEvent | None
|
Optional GET trace data |
frib |
FribEvent | None
|
Optional FRIBDAQ trace data |
original_run |
int
|
The original run number. In the case of merger data this is the same as the current run. In the case of harmonizer data this is the run number before harmonization. |
original_event |
int
|
The original event number. In the case of merger data this is the same as the current event. In the case of harmonizer data this is the event number before harmonization. |
Source code in src/spyral/trace/trace_reader.py
HarmonizerReader
A TraceReader for the current (0.1) harmonizer data
Attributes:
Name | Type | Description |
---|---|---|
file |
File
|
The hdf5 file |
run_number |
int
|
The run_number |
version |
str
|
The version string |
min_event |
int
|
The first event number |
max_event |
int
|
The last event number |
Source code in src/spyral/trace/trace_reader.py
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 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 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 |
|
MergerCurrentReader
A TraceReader for the current (1.0) libattpc_merger data
Attributes:
Name | Type | Description |
---|---|---|
file |
File
|
The hdf5 file |
run_number |
int
|
The run_number |
version |
str
|
The version string |
min_event |
int
|
The first event number |
max_event |
int
|
The last event number |
Source code in src/spyral/trace/trace_reader.py
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 |
|
MergerLegacyReader
A TraceReader for legacy (un-versioned) attpc_merger data
Attributes:
Name | Type | Description |
---|---|---|
file |
File
|
The hdf5 file |
run_number |
int
|
The run_number |
min_event |
int
|
The first event number |
max_event |
int
|
The last event number |
Source code in src/spyral/trace/trace_reader.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 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 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 |
|
TraceReader
Bases: Protocol
Protocol defining a reader for trace data
As the attpc_merger and its friends have evolved, the format of trace files has evolved as well. We define this Protocol, which will be implemented for each supported trace format.
As this is a protocol, do not instantiate it directly.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file |
File
|
The hdf5 file to read traces from |
required |
run_number |
int
|
The trace run number |
required |
Methods:
Name | Description |
---|---|
event_range |
Get the event range as an iterator for use in a loop |
__len |
The length of the file in events |
read_event |
Read a specific event |
read_raw_get_event |
Read a specific GET event and return the raw data array |
read_raw_frib_event |
Read a specific FRIB event and return the raw data array |
read_scalers |
Read the scalers, if they exist |
Source code in src/spyral/trace/trace_reader.py
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 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
|
__len__()
The length of the file in events
Returns:
Type | Description |
---|---|
int
|
The number of events in the file |
event_range()
Get the event range as an iterator for use in a loop
Returns:
Type | Description |
---|---|
Iterable[int]
|
A range of event numbers to iterate over |
first_event()
last_event()
read_event(event_id, get_params, frib_params, rng)
Read a specific event
Read all of the data for a specific AT-TPC event and collect it into a unified structure (Event).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
event_id |
int
|
The event to read |
required |
get_params |
GetParameters
|
The GET electronics signal analysis parameters |
required |
frib_params |
FribParameters
|
The FRIBDAQ signal analysis parameters |
required |
rng |
Generator
|
A random number generator |
required |
Returns:
Type | Description |
---|---|
Event
|
A unified AT-TPC event structure |
Source code in src/spyral/trace/trace_reader.py
read_raw_frib_event(event_id)
Read a specific FRIB event and return the raw data array
Read the raw data from a specific FRIBDAQ event and returns the underlying data. In general, the data matrix format is preserved between different overarching file formats, but this cannot be guaranteed, so use with caution.
Main intent is for use with exploratory notebooks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
event_id |
int
|
The event to read |
required |
Returns:
Type | Description |
---|---|
ndarray | None
|
The raw FRIB data matrix, or None if that FRIB event does not exist |
Source code in src/spyral/trace/trace_reader.py
read_raw_get_event(event_id)
Read a specific GET event and return the raw data array
Read the raw data from a specific GET event and returns the underlying data. In general, the data matrix format is preserved between different overarching file formats, but this cannot be guaranteed, so use with caution.
Main intent is for use with exploratory notebooks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
event_id |
int
|
The event to read |
required |
Returns:
Type | Description |
---|---|
ndarray | None
|
The raw GET data matrix, or None if it does not exist |
Source code in src/spyral/trace/trace_reader.py
read_scalers()
Read the scalers, if they exist
Read the scaler data into an FribScaler container. Some formats do not contain scalers at all (i.e. harmonizer), so this may return None.
Returns:
Type | Description |
---|---|
FribScalers | None
|
The scaler container or None if scalers do not exist |
Source code in src/spyral/trace/trace_reader.py
TraceVersion
Bases: Enum
Enum indicating what version the traces are formatted to
This is used to handle format versions from different Trace producing tools (attpc_merger, harmonizer) Much easier to programmatically handle version enums over version strings. Probably a little over-optimizing at the moment, but if more versions get made, this should allow us to be more flexible.
Attributes:
Name | Type | Description |
---|---|---|
MERGER_1_0 |
int
|
The 1.0 output libattpc_merger format |
HARMONIZER_0_1 |
int
|
The 0.1.0 harmonizer output |
INVALID |
int
|
An illegal format |
Source code in src/spyral/trace/trace_reader.py
create_reader(path, run_number)
Create a TraceReader
This function detects the appropriate implementation and instantiates it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Path
|
Path to the trace file |
required |
run_number |
int
|
The run number of the trace file |
required |
Returns:
Type | Description |
---|---|
TraceReader | None
|
A specific implementation of the TraceReader protocol, or None if no appropriate implementation was found. |
Source code in src/spyral/trace/trace_reader.py
version_string_to_enum(version)
Converts a version string to a TraceVersion
Much easier to programmatically handle version enums over version strings. Probably a little over-optimizing at the moment, but if more versions get made, this should allow us to be more flexible.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
version |
str
|
The version string |
required |
Returns:
Name | Type | Description |
---|---|---|
TraceVersion |
TraceVersion
|
The version enum |