resonance.api.data.catalog¶
resonance.api.data.catalog
¶
Catalog(db_path)
¶
Read-only catalog over a per-beamtime SQLite database.
The catalog reads from a .db SQLite file and an adjacent .zarr
directory store that holds detector image arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db_path
|
Path
|
Path to the beamtime SQLite database file. The Zarr store is
expected at |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
_conn |
Connection
|
Read-only connection to the database. |
_db_path |
Path
|
Resolved path passed at construction time. |
_zarr_path |
Path
|
Path to the adjacent Zarr store directory. |
Source code in src/resonance/api/data/catalog.py
recent(n=10)
¶
Return the n most recently started runs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Maximum number of runs to return. Defaults to 10. |
10
|
Returns:
| Type | Description |
|---|---|
list[RunSummary]
|
Run summaries ordered newest-first. |
Source code in src/resonance/api/data/catalog.py
by_sample(name)
¶
Return all runs associated with a sample by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Exact sample name as stored in the |
required |
Returns:
| Type | Description |
|---|---|
list[RunSummary]
|
Run summaries for the given sample, ordered newest-first. |
Source code in src/resonance/api/data/catalog.py
__getitem__(uid)
¶
Return the full Run object for the given UID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uid
|
str
|
Hex UUID of the run. |
required |
Returns:
| Type | Description |
|---|---|
Run
|
Fully-featured run accessor backed by the open connection. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If no run with the given UID exists in the database. |
Source code in src/resonance/api/data/catalog.py
Run(conn, row, zarr_path)
¶
Full accessor for a single run, including scalar event data and sample metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection
|
Active connection to the beamtime database. |
required |
row
|
dict[str, Any]
|
Deserialized row from the |
required |
zarr_path
|
Path
|
Path to the adjacent Zarr store directory. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
_conn |
Connection
|
Shared database connection from the parent Catalog. |
_row |
dict[str, Any]
|
Raw column values for this run. |
_zarr_path |
Path
|
Path to the Zarr store for detector images. |
Source code in src/resonance/api/data/catalog.py
uid
property
¶
str: Hex UUID of the run.
plan_name
property
¶
str: Name of the scan plan.
time_start
property
¶
float: Unix timestamp of run start.
time_stop
property
¶
float or None: Unix timestamp of run stop.
exit_status
property
¶
str or None: Final run status, e.g. 'success', 'failed'.
num_events
property
¶
int: Total number of events recorded in the primary stream.
sample
property
¶
Return the associated sample metadata, or None if not set.
Returns:
| Type | Description |
|---|---|
SampleMetadata or None
|
Populated from the |
table(stream='primary')
¶
Load scalar event data from a named stream as a DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stream
|
str
|
Name of the stream to load. Defaults to "primary". |
'primary'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Columns are |
Source code in src/resonance/api/data/catalog.py
images(field='detector_image')
¶
Return a lazy accessor for detector images in this run.
Images are not loaded until explicitly indexed. Each frame is stored as a slice of a Zarr array on the filesystem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
str
|
The image field name to load (default: "detector_image"). |
'detector_image'
|
Returns:
| Type | Description |
|---|---|
LazyImageSequence
|
Lazy accessor with length equal to the number of images in this run. |
Notes
Returns an empty LazyImageSequence if no images are stored for the given field or if the Zarr store does not exist.
Source code in src/resonance/api/data/catalog.py
LazyImageSequence(conn, refs, zarr_store_path)
¶
Lazy accessor for detector images referenced via Zarr.
Images are not loaded until explicitly indexed. Each image is stored as a frame in a Zarr array on the filesystem; this class holds the reference metadata and defers loading.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection
|
Active connection to the beamtime database. |
required |
refs
|
list[dict[str, Any]]
|
List of deserialized rows from the |
required |
zarr_store_path
|
Path
|
Path to the Zarr store directory containing detector arrays. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
_conn |
Connection
|
Shared database connection from the parent Catalog. |
_refs |
list[dict[str, Any]]
|
Image reference metadata, one entry per frame. |
_zarr_store_path |
Path
|
Path to the Zarr store directory. |
Source code in src/resonance/api/data/catalog.py
shape
property
¶
tuple[int, int, int]: (n_frames, shape_x, shape_y).
__getitem__(idx)
¶
Load one or more detector images from the Zarr store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
idx
|
int or slice
|
Frame index or slice. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
A single (shape_x, shape_y) array for int index, or a stacked (n, shape_x, shape_y) array for slice index. |
Raises:
| Type | Description |
|---|---|
IndexError
|
If idx is out of range. |
TypeError
|
If idx is not int or slice. |