striqt.sensor¶
Sweep execution against a bound sensor, and readers for sweep specs and calibration data.
iterate_sweep
¶
iterate_sweep(
resources: Resources[SS, SP, SC, SA, PS, PC],
*,
always_yield: bool = False,
yield_values: bool = True,
loop: bool = False,
captures: Iterable[SC] | None = None,
**replace: Unpack[
AnyResources[SS, SP, SC, SA, PS, PC]
],
) -> Generator[Dataset | DelayedDataset | None]
run the iterate of resources['runner'] over resources.
Parameters:
-
resources(Resources[SS, SP, SC, SA, PS, PC]) –the open resources of
open_resources -
always_yield(bool, default:False) –with
yield_valuesFalse, True yields None at every step and False yields nothing -
yield_values(bool, default:True) –True yields the sink result of every step
-
loop(bool, default:False) –True cycles through the captures from the first after the last
-
captures(Iterable[SC] | None, default:None) –the captures to acquire in place of the loop expansion of the sweep, finite or endless; None acquires the expansion
-
**replace(Unpack[AnyResources[SS, SP, SC, SA, PS, PC]], default:{}) –entries that replace those of
resourcesfor this run
Yields:
-
Generator[Dataset | DelayedDataset | None]–the return value of
sink.appendfor each delivered acquisition, or None -
Generator[Dataset | DelayedDataset | None]–at the steps before the first sink write. With
yield_valuesFalse, None at -
Generator[Dataset | DelayedDataset | None]–every step or nothing as
always_yieldselects. The iteration never ends -
Generator[Dataset | DelayedDataset | None]–when
loopis True orcapturesis endless.
Raises:
-
ValueError–if
capturesis given withloopTrue, or if the runner rejectscaptures
open_resources
¶
open_resources(
spec: ActionSpec[SS, SP, SA],
spec_path: str | Path | None = None,
*,
test_only: bool = False,
on_source_opened: SourceOpenCallback | None = None,
on_analyzed: AnalyzedCallback | None = None,
on_sink_cached: CachedCallback | None = None,
select_analysis: AnalysisSelector | None = None,
) -> ConnectionManager[SS, SP, SC, SA, PS, PC]
open the sensor hardware and software contexts needed to run spec.
The source, peripherals, sink, calibration file, and log file open concurrently
for the sweep of the action runner built from spec. The compute warmup runs
in the calling thread. The returned ConnectionManager yields the open
Resources on entry and closes every resource on exit. An exception from a hook
ends the run. Progress is logged at INFO on the sweep logger.
Parameters:
-
spec(ActionSpec[SS, SP, SA]) –the action spec
-
spec_path(str | Path | None, default:None) –the file from which
specwas read, or None; the process working directory becomes the directory of the file, and the{spec_path}path field is set -
test_only(bool, default:False) –if True, open
NoPeripheralsin place of the peripherals and skip the compute warmup -
on_source_opened(SourceOpenCallback | None, default:None) –hook run once with
(sweep, source_id)in a worker thread after the source opens and before the first capture -
on_analyzed(AnalyzedCallback | None, default:None) –hook run in the analysis thread with the
DelayedDatasetof each acquisition, before the sink receives the dataset; theextra_dataof the dataset lacks the peripheral entries -
on_sink_cached(CachedCallback | None, default:None) –hook run in the analysis thread with
(resources, cache, capture, result, **kwargs)each time a measurement fills aKwArgCache -
select_analysis(AnalysisSelector | None, default:None) –hook run in the analysis thread with
(capture, analysis)before each analysis, returning the group to evaluate in place of the adjustedanalysis; a sink that allocates a store from the full group rejects the narrowed result
Raises:
-
TypeError–if no action runner is registered for the type of
spec -
KeyError–if no sensor binding is registered for the type of
spec -
ExceptionGroup–if more than one resource fails to open; a single failure raises that exception
open_store
¶
open_store(
spec: ZarrSink,
*,
format_path: PathFormatter | None = None,
force=False,
) -> ZarrStore
open a new zarr store at spec.path for writing.
A zip store is opened at a .zarr.zip path when spec.path ends in .zip
or spec.store is 'zip'. Otherwise a directory store is opened at a
.zarr path. Missing parent directories are created.
Parameters:
-
spec(ZarrSink) –the sink block with the
pathandstoretype -
format_path(PathFormatter | None, default:None) –expands the
{fields}ofspec.path; None leaves the path as is -
force–if True, a store already at the path is removed; if False, an occupied path is rejected
Raises:
-
ValueError–if
spec.pathis None -
FileExistsError–if a non-empty store is at the path and
forceis False
read_calibration
¶
read_calibration(
path: str | Path | None,
format_path: PathFormatter | None = None,
) -> Dataset | None
read the Y-factor corrections dataset at path into memory.
The dataset is loaded and the file handle is closed before return. Repeated calls with equal arguments return the cached dataset.
Parameters:
-
path(str | Path | None) –the netCDF file written by
save_calibration, or None -
format_path(PathFormatter | None, default:None) –the formatter of the
{field}templates inpath, or None to openpathas written
Returns:
-
Dataset | None–the loaded
Dataset, or None whenpathis None
Raises:
-
FileNotFoundError–if the formatted path does not exist
read_json_spec
¶
read_json_spec(
path: str | Path,
*,
type: type[ActionSpec] | None = None,
output_path: Optional[str] = None,
store_backend: Optional[str] = None,
) -> ActionSpec
decode the action spec in the json file at path.
The file has the schema of a yaml spec without !include directives. The
extensions block of the file is imported before decoding. A relative
extensions.import_path is resolved against the directory of the file.
Parameters:
-
path(str | Path) –the json file
-
type(type[ActionSpec] | None, default:None) –the action spec type to decode into, or None to select the type bound under the
sensor_bindingtag -
output_path(Optional[str], default:None) –replaces
sink.pathin the returned spec when given -
store_backend(Optional[str], default:None) –replaces
sink.storeof aSweepspec when given
Returns:
-
ActionSpec–an instance of
type, or of the bound class whentypeis None
Raises:
-
ValidationError–if the file does not validate as the spec class, or if the tag names no registered binding
-
TypeError–if
store_backendis given and thesinkof the spec is not aZarrSink -
FileNotFoundError–if
extensions.import_pathdoes not exist
read_yaml_spec
¶
read_yaml_spec(
path: str | Path,
*,
type: type[ActionSpec] | None = None,
output_path: Optional[str] = None,
store_backend: Optional[str] = None,
) -> ActionSpec
decode the action spec in the yaml file at path.
The extensions block of the file is imported before decoding. A relative
extensions.import_path is resolved against the directory of the file.
Parameters:
-
path(str | Path) –the yaml file
-
type(type[ActionSpec] | None, default:None) –the action spec type to decode into, or None to select the type bound under the
sensor_bindingtag -
output_path(Optional[str], default:None) –replaces
sink.pathin the returned spec when given -
store_backend(Optional[str], default:None) –replaces
sink.storeof aSweepspec when given
Returns:
-
ActionSpec–an instance of
type, or of the bound class whentypeis None
Raises:
-
ValidationError–if the file does not validate as the spec class, or if the tag names no registered binding
-
TypeError–if
store_backendis given and thesinkof the spec is not aZarrSink -
FileNotFoundError–if
extensions.import_pathdoes not exist
read_zarr_spec
¶
read_zarr_spec(
path: str | Path,
*,
type: type[ActionSpec] | None = None,
output_path: Optional[str] = None,
store_backend: Optional[str] = None,
extension_root: str | Path | None = None,
) -> ActionSpec
decode the sweep spec saved in the attrs of the zarr store at path.
The extensions block of the attrs is imported before decoding. Only the attrs
that name fields of the sweep class, the sensor_binding tag, and
mock_source are read. An extensions.sink attr is dropped with a
DeprecationWarning.
Parameters:
-
path(str | Path) –the zarr store, a
.zarrdirectory or.zarr.ziparchive -
type(type[ActionSpec] | None, default:None) –the sweep class to decode against, or None to select the class bound under the saved
sensor_bindingtag; a savedmock_sourceattr selects the mock class of that binding instead -
output_path(Optional[str], default:None) –replaces
sink.pathin the returned spec when given -
store_backend(Optional[str], default:None) –replaces
sink.storeof aSweepspec when given -
extension_root(str | Path | None, default:None) –the directory against which a relative
extensions.import_pathis resolved, or None for the directory of the store
Returns:
-
ActionSpec–an instance of
type, or of the bound sweep class whentypeis None
Raises:
-
ValidationError–if the attrs do not validate as the sweep class, or if the tag names no registered binding
-
TypeError–if
store_backendis given and thesinkof the spec is not aZarrSink -
FileNotFoundError–if
extensions.import_pathorextension_rootdoes not exist