API reference¶
Classes:
| Name | Description |
|---|---|
Device |
Base class for devices. |
PDevice |
Minimal required protocol for a recognizable device in Redsun. |
Device
¶
Base class for devices.
Users may subclass from this device and implement their own configuration properties and methods.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the device. Serves as a unique identifier for the object created from it. |
required |
kwargs
|
Any
|
Additional keyword arguments for device subclasses. |
{}
|
Methods:
| Name | Description |
|---|---|
describe_configuration |
Provide a description of the device configuration. |
read_configuration |
Provide a description of the device configuration. |
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the device, serving as a unique identifier. |
parent |
None
|
Parent of the device. Always returns None for compliance with |
Source code in src/sunflare/device/_base.py
describe_configuration
abstractmethod
¶
Provide a description of the device configuration.
Subclasses should override this method to provide their own configuration description compatible with the Bluesky event model.
Returns:
| Type | Description |
|---|---|
dict[str, Descriptor]
|
A dictionary with the description of each field of the device configuration. |
Source code in src/sunflare/device/_base.py
read_configuration
abstractmethod
¶
Provide a description of the device configuration.
Subclasses should override this method to provide their own configuration reading compatible with the Bluesky event model.
Returns:
| Type | Description |
|---|---|
dict[str, Reading[Any]]
|
A dictionary with the reading of each field of the device configuration. |
Source code in src/sunflare/device/_base.py
Classes:
| Name | Description |
|---|---|
PPresenter |
Presenter protocol class. |
Presenter |
Presenter base class. |
PPresenter
¶
Bases: Protocol
Presenter protocol class.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Identity key of the presenter. |
devices |
Mapping[str, Device]
|
Reference to the devices used in the presenter. |
Notes
Access to the virtual container is optional and should be acquired
by implementing :class:~sunflare.virtual.IsProvider or
:class:~sunflare.virtual.IsInjectable.
Source code in src/sunflare/presenter/_base.py
Presenter
¶
Bases: PPresenter, ABC
Presenter base class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Identity key of the presenter. Passed as positional-only argument. |
required |
devices
|
Mapping[str, Device]
|
Reference to the devices used in the presenter. |
required |
kwargs
|
Any
|
Additional keyword arguments for presenter subclasses. |
{}
|
Source code in src/sunflare/presenter/_base.py
Classes:
| Name | Description |
|---|---|
RedSunConfig |
Base configuration schema for Redsun applications. |
VirtualContainer |
Data exchange and dependency injection layer. |
HasShutdown |
Protocol marking your class as capable of shutting down. |
IsInjectable |
Protocol marking a class as injectable with dependencies from the container. |
IsProvider |
Protocol marking a class as a provider of dependencies. |
Attributes:
| Name | Type | Description |
|---|---|---|
CallbackType |
TypeAlias
|
Type alias for document callback functions. |
SignalCache |
TypeAlias
|
Cache type for storing signal instances registered from component classes. |
CallbackType
module-attribute
¶
Type alias for document callback functions.
SignalCache
module-attribute
¶
Cache type for storing signal instances registered from component classes.
RedSunConfig
¶
Bases: TypedDict
Base configuration schema for Redsun applications.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema_version
|
Required[float]
|
An enumeration. |
required |
frontend
|
Required[str]
|
An enumeration. |
required |
session
|
NotRequired[str]
|
An enumeration. |
required |
metadata
|
NotRequired[dict[str, Any]]
|
An enumeration. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
schema_version |
Required[float]
|
Plugin schema version. |
frontend |
Required[str]
|
Frontend toolkit identifier (e.g. |
session |
NotRequired[str]
|
Session display name. If not provided, default is |
metadata |
NotRequired[dict[str, Any]]
|
Additional session-specific metadata to include in the configuration. |
Source code in src/sunflare/virtual/_config.py
VirtualContainer
¶
Bases: DynamicContainer, Loggable
Data exchange and dependency injection layer.
VirtualContainer is a [DynamicContainer][dependency_injector.containers.DynamicContainer]
that also acts as a runtime signal bus and data sharing layer for an application.
Methods:
| Name | Description |
|---|---|
register_signals |
Register the signals of an object in the virtual container. |
register_callbacks |
Register one or more document callbacks in the virtual container. |
Attributes:
| Name | Type | Description |
|---|---|---|
schema_version |
float
|
The plugin schema version specified in the configuration. |
frontend |
str
|
The frontend toolkit identifier specified in the configuration. |
session |
str
|
The session display name specified in the configuration. |
metadata |
dict[str, object]
|
The session metadata specified in the configuration. |
callbacks |
dict[str, CallbackType]
|
The currently registered document callbacks. |
signals |
dict[str, SignalCache]
|
The currently registered signals. |
Source code in src/sunflare/virtual/_container.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 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 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 | |
schema_version
property
¶
The plugin schema version specified in the configuration.
metadata
property
¶
The session metadata specified in the configuration.
callbacks
property
¶
The currently registered document callbacks.
register_signals
¶
register_signals(
owner: HasName,
name: str | None = None,
only: Iterable[str] | None = None,
) -> None
Register the signals of an object in the virtual container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
owner
|
HasName
|
The instance whose class's signals are to be cached.
Must provide a |
required |
name
|
str | None
|
An optional name to use as the key for caching the signals.
If not provided, the |
None
|
only
|
Iterable[str]
|
A list of signal names to cache. If not provided, all signals in the class will be cached automatically by inspecting the class attributes. |
None
|
Notes
This method inspects the attributes of the owner's class to find
psygnal.Signal descriptors. For each such descriptor, it
retrieves the psygnal.SignalInstance from the owner using
the descriptor protocol and stores it in the registry.
Source code in src/sunflare/virtual/_container.py
register_callbacks
¶
register_callbacks(
owner: HasName,
name: str | None = None,
callback_map: dict[str, CallbackType] | None = None,
) -> None
Register one or more document callbacks in the virtual container.
Accepts any object that is a valid CallbackType and exposes a
name attribute used as the registry key. Two forms are supported:
- A [DocumentRouter][event_model.DocumentRouter] subclass instance;
- Any other object that implements
__call__(self, name, doc)with the correct two-parameter signature.
When callback_map is provided the owner itself is not registered; instead each entry in the mapping is validated and registered independently under its own key, allowing a single owner to expose multiple callbacks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
owner
|
HasName
|
The component registering callbacks. Must expose a |
required |
name
|
str | None
|
Override for the registry key used when registering owner
directly. Ignored when callback_map is provided.
Defaults to |
None
|
callback_map
|
dict[str, CallbackType] | None
|
Optional mapping of registry key to callback object. When supplied, each value is validated and registered under its corresponding key; name is ignored. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If a callback is not callable or its signature is incompatible
with |
Source code in src/sunflare/virtual/_container.py
HasShutdown
¶
IsInjectable
¶
Bases: Protocol
Protocol marking a class as injectable with dependencies from the container.
Methods:
| Name | Description |
|---|---|
inject_dependencies |
Inject dependencies from the container. |
Source code in src/sunflare/virtual/_protocols.py
inject_dependencies
abstractmethod
¶
IsProvider
¶
Bases: Protocol
Protocol marking a class as a provider of dependencies.
Methods:
| Name | Description |
|---|---|
register_providers |
Register providers in the virtual container. |
Source code in src/sunflare/virtual/_protocols.py
register_providers
abstractmethod
¶
Modules:
| Name | Description |
|---|---|
qt |
|
Classes:
| Name | Description |
|---|---|
PView |
Minimal protocol a view component should implement. |
View |
Base view class. |
ViewPosition |
Supported view positions. |
PView
¶
Bases: Protocol
Minimal protocol a view component should implement.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Identity key of the view. |
Notes
Access to the virtual container is optional and should be acquired
by implementing :class:~sunflare.virtual.IsInjectable.
Source code in src/sunflare/view/_base.py
view_position
abstractmethod
property
¶
Position of the view component in the main view of the UI.
View
¶
Base view class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Identity key of the view. Passed as positional-only argument. |
required |
kwargs
|
``Any``
|
Additional keyword arguments for view subclasses. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
view_position |
ViewPosition
|
Position of the view component in the main view of the UI. |
Source code in src/sunflare/view/_base.py
view_position
abstractmethod
property
¶
Position of the view component in the main view of the UI.
ViewPosition
¶
Supported view positions.
Used to define the position of a view component in the main view of the UI.
Warning
These values are based on how Qt manages dock widgets. They may change in the future.
Attributes:
| Name | Type | Description |
|---|---|---|
CENTER |
str
|
Center view position. |
LEFT |
str
|
Left view position. |
RIGHT |
str
|
Right view position. |
TOP |
str
|
Top view position. |
BOTTOM |
str
|
Bottom view position. |
Source code in src/sunflare/view/__init__.py
Classes:
| Name | Description |
|---|---|
Loggable |
Mixin class that adds a logger to a class instance with extra contextual information. |
Classes:
| Name | Description |
|---|---|
Status |
Track the status of a potentially-lengthy action like moving or triggering. |
RunEngine |
The Run Engine execute messages and emits Documents. |
Status
¶
Bases: Status
Track the status of a potentially-lengthy action like moving or triggering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
float | None
|
The amount of time to wait before marking the Status as failed. If
|
None
|
settle_time
|
float | None
|
The amount of time to wait between the caller specifying that the status has completed to running callbacks. Default is 0. |
0
|
Notes
Theory of operation:
This employs two threading.Event objects, one thread that runs for
(timeout + settle_time) seconds, and one thread that runs for
settle_time seconds (if settle_time is nonzero).
At init time, a timeout and settle_time are specified. A thread
is started, on which user callbacks, registered after init time via
add_callback, will eventually be run. The thread waits on an
Event be set or (timeout + settle_time) seconds to pass, whichever
happens first.
If (timeout + settle_time) expires and the Event has not
been set, an internal Exception is set to StatusTimeoutError, and a
second Event is set, marking the Status as done and failed. The
callbacks are run.
If a callback is registered after the Status is done, it will be run immediately.
If the first Event is set before (timeout + settle_time) expires, then the second Event is set and no internal Exception is set, marking the Status as done and successful. The callbacks are run.
There are two methods that directly set the first Event. One,
set_exception, sets it directly after setting the internal
Exception. The other, set_finished, starts a
threading.Timer that will set it after a delay (the settle_time).
One of these methods may be called, and at most once. If one is called
twice or if both are called, InvalidState is raised. If they are
called too late to prevent a StatusTimeoutError, they are ignored
but one call is still allowed. Thus, an external callback, e.g. pyepics,
may reports success or failure after the Status object has expired, but
to no effect because the callbacks have already been called and the
program has moved on.
Methods:
| Name | Description |
|---|---|
set_exception |
Mark as finished but failed with the given Exception. |
set_finished |
Mark as finished successfully. |
exception |
Return the exception raised by the action. |
wait |
Block until the action completes. |
add_callback |
Register a callback to be called once when the Status finishes. |
Attributes:
| Name | Type | Description |
|---|---|---|
timeout |
float | None
|
The timeout for this action. |
settle_time |
float
|
A delay between when |
done |
bool
|
Boolean indicating whether associated operation has completed. |
success |
bool
|
Boolean indicating whether associated operation has completed. |
callbacks |
deque[Callable[[Status], None]]
|
Callbacks to be run when the status is marked as finished. |
Source code in src/sunflare/engine/_status.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 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 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 258 259 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 353 354 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 | |
timeout
property
¶
The timeout for this action.
This is set when the Status is created, and it cannot be changed.
settle_time
property
¶
A delay between when set_finished is when the Status is done.
This is set when the Status is created, and it cannot be changed.
done
property
¶
Boolean indicating whether associated operation has completed.
This is set to True at init time or by calling
set_finished, set_exception.
Once True, it can never become False.
success
property
¶
Boolean indicating whether associated operation has completed.
This is set to True at init time or by calling
set_finished, set_exception
. Once True, it can never become False.
callbacks
property
¶
Callbacks to be run when the status is marked as finished.
set_exception
¶
Mark as finished but failed with the given Exception.
This method should generally not be called by the recipient of this Status object, but only by the object that created and returned it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exc
|
BaseException
|
The exception that caused the failure. |
required |
Source code in src/sunflare/engine/_status.py
set_finished
¶
Mark as finished successfully.
This method should generally not be called by the recipient of this Status object, but only by the object that created and returned it.
Source code in src/sunflare/engine/_status.py
exception
¶
Return the exception raised by the action.
If the action has completed successfully, return None. If it has
finished in error, return the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
float | None
|
If None (default) wait indefinitely until the status finishes. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Exception |
BaseException | None
|
The exception raised by the action. If the action has completed
successfully, return |
Raises:
| Type | Description |
|---|---|
WaitTimeoutError
|
If the status has not completed within |
Source code in src/sunflare/engine/_status.py
wait
¶
Block until the action completes.
When the action has finished succesfully, return None. If the
action has failed, raise the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
float | None
|
If |
None
|
Raises:
| Type | Description |
|---|---|
WaitTimeoutError
|
If the status has not completed within |
StatusTimeoutError
|
If the status has failed because the timeout that it was initialized with has expired. |
Exception
|
This is |
Source code in src/sunflare/engine/_status.py
add_callback
¶
Register a callback to be called once when the Status finishes.
The callback will be called exactly once. If the Status is finished before a callback is added, it will be called immediately. This is threadsafe. The callback will be called regardless of success of failure. The callback has access to this status object, so it can distinguish success or failure by inspecting the object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
callback
|
Callable[[Status], None]
|
required |
Source code in src/sunflare/engine/_status.py
RunEngine
¶
Bases: RunEngine
The Run Engine execute messages and emits Documents.
This is a wrapper for the bluesky.run_engine.RunEngine class that
allows execution without blocking the main thread.
The main difference is that the __call__ method
is executed in a separate thread,
and it returns a concurrent.futures.Future object
representing the result of the plan execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
md
|
dict[str, Any]
|
The default is a standard Python dictionary, but fancier
objects can be used to store long-term history and persist
it between sessions. The standard configuration
instantiates a Run Engine with historydict.HistoryDict, a
simple interface to a sqlite file. Any object supporting
|
None
|
loop
|
AbstractEventLoop | None
|
An asyncio event loop to be used for executing plans. If not provided,
the RunEngine will create a new event loop using |
None
|
preprocessors
|
list
|
Generator functions that take in a plan (generator instance) and
modify its messages on the way out. Suitable examples include
the functions in the module |
None
|
md_validator
|
Callable[dict[str, Any], None]
|
a function that raises and prevents starting a run if it deems the metadata to be invalid or incomplete Function should raise if md is invalid. What that means is completely up to the user. The function's return value is ignored. |
None
|
md_normalizer
|
Callable[dict[str, Any], dict[str, Any]]
|
a function that, similar to md_validator, raises and prevents starting a run if it deems the metadata to be invalid or incomplete. If it succeeds, it returns the normalized/transformed version of the original metadata. Function should raise if md is invalid. What that means is completely up to the user. Expected return: normalized metadata |
None
|
scan_id_source
|
Callable[dict[str, Any], int | Awaitable[int]]
|
a (possibly async) function that will be used to calculate scan_id. Default is to increment scan_id by 1 each time. However you could pass in a customized function to get a scan_id from any source. Expected return: updated scan_id value |
default_scan_id_source
|
call_returns_result
|
bool
|
A flag that controls the return value of |
True
|
Attributes:
| Name | Type | Description |
|---|---|---|
md |
Direct access to the dict-like persistent storage described above |
|
record_interruptions |
False by default. Set to True to generate an extra event stream that records any interruptions (pauses, suspensions). |
|
state |
{'idle', 'running', 'paused'} |
|
suspenders |
Read-only collection of |
|
preprocessors |
list
|
Generator functions that take in a plan (generator instance) and
modify its messages on the way out. Suitable examples include
the functions in the module |
msg_hook |
Callable that receives all messages before they are processed
(useful for logging or other development purposes); expected
signature is |
|
state_hook |
Callable with signature |
|
waiting_hook |
Callable with signature |
|
ignore_callback_exceptions |
Boolean, False by default. |
|
call_returns_result |
Boolean, False by default. If False, RunEngine will return uuid list after running a plan. If True, RunEngine will return a RunEngineResult object that contains the plan result, error status, and uuid list. |
|
loop |
asyncio event loop
|
e.g., |
max_depth |
Maximum stack depth; set this to prevent users from calling the RunEngine inside a function (which can result in unexpected behavior and breaks introspection tools). Default is None. For built-in Python interpreter, set to 2. For IPython, set to 11 (tested on IPython 5.1.0; other versions may vary). |
|
pause_msg |
str
|
The message printed when a run is interrupted. This message
includes instructions of changing the state of the RunEngine.
It is set to |
commands |
The list of commands available to Msg. |
Methods:
| Name | Description |
|---|---|
resume |
Resume the paused plan in a separate thread. |
Source code in src/sunflare/engine/_wrapper.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 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 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 258 259 260 261 262 263 264 265 | |
resume
¶
Resume the paused plan in a separate thread.
If the plan has been paused, the initial
future returned by __call__ will be set as completed.
With this method, the plan is resumed in a separate thread, and a new future is returned.
Returns:
| Type | Description |
|---|---|
``Future[RunEngineResult | tuple[str, ...]]``
|
Future object representing the result of the resumed plan. |
Source code in src/sunflare/engine/_wrapper.py
Storage infrastructure for sunflare devices.
This subpackage provides the dependency-free primitives for storage:
Writer— abstract base class for storage backendsFrameSink— device-facing handle for pushing framesSourceInfo— per-device frame metadataPathInfo— storage path and configuration for one deviceFilenameProvider— protocol for filename callablesPathProvider— protocol for path-info callablesStaticFilenameProvider,UUIDFilenameProvider,AutoIncrementFilenameProvider— concrete filename strategiesStaticPathProvider— concrete path providerStorageProxy— protocol implemented by all storage backendsStorageDescriptor— descriptor for declaringstorageon a deviceHasStorage— protocol for devices that have opted in to storage
Concrete backend classes (e.g. ZarrWriter) are internal
implementation details and are not exported from this package.
The application container is responsible for selecting and instantiating
the correct backend based on the session configuration.
Devices that require storage declare it explicitly in their class body:
from sunflare.storage import StorageDescriptor
class MyDetector(Device):
storage = StorageDescriptor()
Classes:
| Name | Description |
|---|---|
FrameSink |
Device-facing handle for pushing frames to a storage backend. |
SourceInfo |
Metadata for a registered data source. |
Writer |
Abstract base class for data writers. |
AutoIncrementFilenameProvider |
Returns a numerically incrementing filename on each call. |
FilenameProvider |
Callable that produces a filename (without extension) for a device. |
PathInfo |
Where and how a storage backend should write data for one device. |
PathProvider |
Callable that produces |
StaticFilenameProvider |
Always returns the same filename. |
StaticPathProvider |
Provides |
UUIDFilenameProvider |
Returns a fresh UUID4 string on every call. |
HasStorage |
Protocol for devices that have opted in to storage. |
StorageDescriptor |
Descriptor that manages the |
StorageProxy |
Protocol that devices use to interact with a storage backend. |
FrameSink
¶
Device-facing handle for pushing frames to a storage backend.
Returned by Writer.prepare.
Devices write frames by calling write;
the sink routes each frame to the correct array inside the shared
Writer and updates the frame counter atomically.
Calling close is equivalent to calling
Writer.complete for this source — it
signals that no more frames will arrive and triggers backend finalisation
once all active sinks have been closed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
writer
|
Writer
|
The shared writer that owns this sink. |
required |
name
|
str
|
Source name this sink is bound to. |
required |
Methods:
| Name | Description |
|---|---|
write |
Push frame to the storage backend. |
close |
Signal that no more frames will be written from this sink. |
Source code in src/sunflare/storage/_base.py
write
¶
Push frame to the storage backend.
Thread-safe; multiple sinks may call write concurrently.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame
|
NDArray[generic]
|
Array data to write. dtype and shape must match the source
registration from |
required |
Source code in src/sunflare/storage/_base.py
close
¶
Signal that no more frames will be written from this sink.
Delegates to Writer.complete.
The backend is finalised once all active sinks have called close.
Source code in src/sunflare/storage/_base.py
SourceInfo
dataclass
¶
Metadata for a registered data source.
Attributes:
| Name | Type | Description |
|---|
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
An enumeration. |
required |
dtype
|
dtype[generic]
|
An enumeration. |
required |
shape
|
tuple[int, ...]
|
An enumeration. |
required |
data_key
|
str
|
An enumeration. |
required |
mimetype
|
str
|
An enumeration. |
'application/octet-stream'
|
frames_written
|
int
|
An enumeration. |
0
|
collection_counter
|
int
|
An enumeration. |
0
|
stream_resource_uid
|
str
|
|
'df3cf11f-1711-461f-bc52-3f5d6d7b787f'
|
extra
|
dict[str, Any]
|
dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2) |
<class 'dict'>
|
Source code in src/sunflare/storage/_base.py
Writer
¶
Abstract base class for data writers.
This interface loosely follows the Bluesky Flyable protocol while
remaining generic — methods do not need to return a Status object;
that is left to the device that owns the writer.
A single Writer instance is shared by all devices in a session.
Each device registers itself as a source via
update_source and obtains
a dedicated FrameSink via
prepare.
Call order per acquisition:
update_source(name, dtype, shape)— register the deviceprepare(name, capacity)— returns aFrameSinkkickoff()— opens the backendsink.write(frame)— push frames (thread-safe)sink.close()— signals completion (callscomplete)
Subclasses must implement:
mimetype— MIME type string for this backendprepare— source-specific setup; must callsuper().prepare()kickoff— open the backend; must callsuper().kickoff()_write_frame— write one frame to the backend_finalize— close the backend when all sources are complete
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Unique name for this writer instance (used for logging). |
required |
Methods:
| Name | Description |
|---|---|
update_source |
Register or update a data source. |
clear_source |
Remove a registered data source. |
get_indices_written |
Return the number of frames written for a source. |
reset_collection_state |
Reset the collection counter for a new acquisition. |
kickoff |
Open the storage backend for a new acquisition. |
prepare |
Prepare storage for a specific source and return a frame sink. |
complete |
Mark acquisition complete for name. |
collect_stream_docs |
Yield |
Attributes:
| Name | Type | Description |
|---|---|---|
is_open |
bool
|
Return whether the writer is currently open. |
name |
str
|
Return the name of this writer. |
mimetype |
str
|
Return the MIME type string for this backend. |
sources |
MappingProxyType[str, SourceInfo]
|
Return a read-only view of the registered data sources. |
Source code in src/sunflare/storage/_base.py
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 258 259 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 353 354 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 443 444 445 | |
sources
property
¶
Return a read-only view of the registered data sources.
update_source
¶
update_source(
name: str,
dtype: dtype[generic],
shape: tuple[int, ...],
extra: dict[str, Any] | None = None,
) -> None
Register or update a data source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Source name (typically the device name). |
required |
dtype
|
dtype[generic]
|
NumPy data type of the frames. |
required |
shape
|
tuple[int, ...]
|
Shape of individual frames. |
required |
extra
|
dict[str, Any] | None
|
Optional backend-specific metadata forwarded to
|
None
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the writer is currently open. |
Source code in src/sunflare/storage/_base.py
clear_source
¶
Remove a registered data source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Source name to remove. |
required |
raise_if_missing
|
bool
|
If |
False
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the writer is currently open. |
KeyError
|
If raise_if_missing is |
Source code in src/sunflare/storage/_base.py
get_indices_written
¶
Return the number of frames written for a source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
Source name. If |
None
|
Raises:
| Type | Description |
|---|---|
KeyError
|
If name is not registered. |
Source code in src/sunflare/storage/_base.py
reset_collection_state
¶
Reset the collection counter for a new acquisition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Source name to reset. |
required |
Source code in src/sunflare/storage/_base.py
kickoff
abstractmethod
¶
Open the storage backend for a new acquisition.
Subclasses must call super().kickoff() to set
is_open.
Subsequent calls while already open must be no-ops.
Source code in src/sunflare/storage/_base.py
prepare
abstractmethod
¶
Prepare storage for a specific source and return a frame sink.
Called once per device per acquisition. Resets per-source counters
and returns a FrameSink bound to name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Source name. |
required |
capacity
|
int
|
Maximum frames to accept ( |
0
|
Returns:
| Type | Description |
|---|---|
FrameSink
|
Bound sink; call |
Raises:
| Type | Description |
|---|---|
KeyError
|
If name has not been registered via
|
Source code in src/sunflare/storage/_base.py
complete
¶
Mark acquisition complete for name.
Called automatically by FrameSink.close.
The backend is finalised once all active sinks have called close.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Source name. |
required |
Source code in src/sunflare/storage/_base.py
collect_stream_docs
¶
Yield StreamResource and StreamDatum documents for name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Source name. |
required |
indices_written
|
int
|
Number of frames to report in this call. |
required |
Yields:
| Type | Description |
|---|---|
StreamAsset
|
Tuples of |
Raises:
| Type | Description |
|---|---|
KeyError
|
If name is not registered. |
Source code in src/sunflare/storage/_base.py
AutoIncrementFilenameProvider
¶
Returns a numerically incrementing filename on each call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base
|
str
|
Optional base prefix for the filename. |
''
|
max_digits
|
int
|
Zero-padding width for the counter. |
5
|
start
|
int
|
Initial counter value. |
0
|
step
|
int
|
Increment per call. |
1
|
delimiter
|
str
|
Separator between base and counter. |
'_'
|
Source code in src/sunflare/storage/_path.py
FilenameProvider
¶
Bases: Protocol
Callable that produces a filename (without extension) for a device.
Source code in src/sunflare/storage/_path.py
PathInfo
dataclass
¶
Where and how a storage backend should write data for one device.
Attributes:
| Name | Type | Description |
|---|
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
store_uri
|
str
|
An enumeration. |
required |
array_key
|
str
|
An enumeration. |
required |
capacity
|
int
|
An enumeration. |
0
|
mimetype_hint
|
str
|
An enumeration. |
'application/x-zarr'
|
extra
|
dict[str, Any]
|
dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2) |
<class 'dict'>
|
Source code in src/sunflare/storage/_path.py
PathProvider
¶
Bases: Protocol
Callable that produces PathInfo for a device.
Source code in src/sunflare/storage/_path.py
StaticFilenameProvider
¶
Always returns the same filename.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
The filename string to return on every call. |
required |
Source code in src/sunflare/storage/_path.py
StaticPathProvider
¶
Provides PathInfo rooted at a fixed base URI.
Composes a FilenameProvider
(for the array key / filename) with a fixed base_uri (for the store location).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename_provider
|
FilenameProvider
|
Callable that returns a filename for each device. |
required |
base_uri
|
str
|
Base URI for the store root (e.g. |
required |
mimetype_hint
|
str
|
MIME type hint forwarded to |
'application/x-zarr'
|
capacity
|
int
|
Default frame capacity forwarded to |
0
|
Source code in src/sunflare/storage/_path.py
UUIDFilenameProvider
¶
Returns a fresh UUID4 string on every call.
Each call produces a new UUID, so files from different acquisitions are never overwritten.
Source code in src/sunflare/storage/_path.py
HasStorage
¶
StorageDescriptor
¶
Descriptor that manages the storage slot on a device.
The private attribute name is derived from the descriptor's own name
at class-creation time via __set_name__ (e.g. a class attribute
named storage produces a backing attribute _storage). Reading
and writing go through object.__getattribute__ and
object.__setattr__ rather than __dict__ access, so the descriptor
works correctly on classes that define __slots__ as long as the
backing slot is declared.
This descriptor is public so users can reference it explicitly in custom device classes:
from sunflare.device import Device
from sunflare.storage import StorageDescriptor
class MyDevice(Device):
storage = StorageDescriptor()
Source code in src/sunflare/storage/_proxy.py
StorageProxy
¶
Bases: Protocol
Protocol that devices use to interact with a storage backend.
Writer instances implement this protocol,
so device code remains independent of the concrete backend.
Devices access the backend via their storage attribute, which is
None when no backend has been configured for the session.
Methods:
| Name | Description |
|---|---|
update_source |
Register or update a data source on the backend. |
prepare |
Prepare the backend for name and return a |
kickoff |
Open the storage backend. |
complete |
Signal that name has finished writing. |
get_indices_written |
Return the number of frames written for name. |
collect_stream_docs |
Yield Bluesky stream documents for name. |