s6.schema package

Submodules

s6.schema.calibration module

Calibration Pydantic models for camera calibration configuration.

class s6.schema.calibration.CalibrationConfig(*, R: CameraCalibration, L: CameraCalibration, B: CameraCalibration, RGBL: CameraCalibration, RGBR: CameraCalibration, board: List[List[float]])

Bases: BaseModel

Calibration configuration mapping camera identifiers to their parameters.

B: CameraCalibration
L: CameraCalibration
R: CameraCalibration
RGBL: CameraCalibration
RGBR: CameraCalibration
board: List[List[float]]
cameras() Dict[str, CameraCalibration | List[List[float]]]
static load_default() CalibrationConfig

Load the CalibrationConfig from the default JSON configuration file.

class s6.schema.calibration.CameraCalibration(*, extrinsic: List[List[float]], intrinsic: List[List[float]], distortion: List[float], resolution: Tuple[int, int])

Bases: BaseModel

Calibration parameters for a single camera.

classmethod check_extrinsic(v: Any) Any
classmethod check_intrinsic(v: Any) Any
classmethod check_resolution(v: Any) Any
distortion: List[float]
extrinsic: List[List[float]]
classmethod flatten_and_check_distortion(v: Any) Any
intrinsic: List[List[float]]
resolution: Tuple[int, int]

s6.schema.connection module

Pydantic model for connection configuration.

class s6.schema.connection.ConnectionConfig(*, stream_server: str, robotic: HostConfig = None, camera_controller: HostConfig = None)

Bases: BaseModel

camera_controller: HostConfig
static load_default() ConnectionConfig

Load the ConnectionConfig from the default JSON configuration file.

robotic: HostConfig
stream_server: str
classmethod validate_stream_server(v)
class s6.schema.connection.DBConfig(*, mongodb_uri: MongoDsn = None, mongodb_database: str = None, fileserver_url: HttpUrl = None, default_collection: str = None)

Bases: BaseModel

Configuration for connection settings, including MongoDB and file server endpoints.

default_collection: str
fileserver_url: HttpUrl
mongodb_database: str
mongodb_uri: MongoDsn
classmethod validate_default_collection(v)
classmethod validate_mongodb_database(v)
class s6.schema.connection.HostConfig(*, host: str, port: int)

Bases: BaseModel

Host and port configuration model.

host: str
port: int
classmethod validate_host(v)
classmethod validate_port(v)

s6.schema.data module

Pydantic models for instrument tracking rendered dataset frames.

Represents schema of entries written by instrument_render_v3.py and read by convert.py.

class s6.schema.data.CameraFrame(*, image_path: str, targets: List[CameraTarget], depth_map_path: str | None = None)

Bases: BaseModel

depth_map_path: str | None
image_path: str
targets: List[CameraTarget]
class s6.schema.data.CameraTarget(*, mesh_name: str, projections: List[Projection])

Bases: BaseModel

mesh_name: str
projections: List[Projection]
class s6.schema.data.InstrumentTrackingFrame(*, world: World, uuid: UUID, cameras: Dict[str, CameraFrame])

Bases: BaseModel

class Config

Bases: object

allow_population_by_field_name = True
extra = 'ignore'
validate_all = True
cameras: Dict[str, CameraFrame]
to_yolo(camera_name: str, class_to_id: Dict[str, int], image_size: Tuple[int, int], box_ratio: float = 0.1) YoloFrame

Convert this frame to YOLO format for the given camera.

uuid: UUID
world: World
class s6.schema.data.Projection(*, vertex: str, uv: ConstrainedListValue[float], box_xyxy: ConstrainedListValue[float] | None = None)

Bases: BaseModel

box_xyxy: ConstrainedListValue[float] | None
uv: ConstrainedListValue[float]
vertex: str
class s6.schema.data.World(*, targets: List[WorldTarget])

Bases: BaseModel

targets: List[WorldTarget]
class s6.schema.data.WorldTarget(*, mesh_name: str, vertices: List[str], positions: List[ConstrainedListValue[float]])

Bases: BaseModel

mesh_name: str
positions: List[ConstrainedListValue[float]]
vertices: List[str]
class s6.schema.data.YoloBox(*, class_id: int, x_center: float, y_center: float, width: float, height: float)

Bases: BaseModel

A single YOLO bounding box entry.

class_id: int
height: float
width: float
x_center: float
y_center: float
class s6.schema.data.YoloFrame(*, image_path: str, boxes: List[YoloBox])

Bases: BaseModel

YOLO annotation for a single image.

boxes: List[YoloBox]
image_path: str

s6.schema.light_calibration module

class s6.schema.light_calibration.LightCalibrationConfig(*, L: SamplingRegion, R: SamplingRegion, B: SamplingRegion, pin_mapping: Dict[Literal['L', 'R', 'B'], int])

Bases: BaseModel

B: SamplingRegion
L: SamplingRegion
R: SamplingRegion
static load_default()
pin_mapping: Dict[Literal['L', 'R', 'B'], int]
save_default()
class s6.schema.light_calibration.SamplingRegion(*, y: float, x: float, w: float, h: float, normalised: bool = False, intensity_target: int = 200)

Bases: BoundingBox2D

h: float
intensity_target: int
normalised: bool
sample(image: ndarray)
w: float
x: float
y: float

s6.schema.primitives module

Lightweight geometry and data primitives used across Sense Core.

This module defines small pydantic models and vector utilities commonly exchanged between pipeline stages, visualization, and telemetry layers.

Coordinate conventions

  • Pixel coordinates are represented as (x, y) in Vector2D instances.

  • BoundingBox2D stores fields in image-slice order (y, x, w, h) to match NumPy row/column indexing; helper methods clarify conversions.

  • Methods operating on image arrays assume NumPy’s HxW(xC) memory layout.

class s6.schema.primitives.BoundingBox2D(*, y: float, x: float, w: float, h: float, normalised: bool = False)

Bases: BaseModel

Axis-aligned rectangle in image coordinates.

y, x

Top-left corner in pixel coordinates (row y, column x).

Type:

float

w, h

Width and height in pixels.

Type:

float

normalised

If True, fields are normalised relative to image size.

Type:

bool

property center: Vector2D

Center point of the box as a Vector2D.

crop_image(image: ndarray)

Return the region of image covered by this box.

Parameters:

image (np.ndarray) – Source image array (H x W x C or H x W).

Returns:

A view/slice of image bounded by the box.

Return type:

np.ndarray

crop_points(points: List[Tuple[float, float]] | List[Vector2D] | ndarray) List[Tuple[float, float]] | List[Vector2D] | ndarray

Convert points from image coordinates to this box’s local coordinates.

For each point:
  • If provided as a tuple (y, x) or as a numpy array (assumed order [y, x]), the cropped coordinate is (y - self.y, x - self.x).

  • If provided as a Vector2D (with fields x and y), the cropped coordinate is Vector2D(x = original.x - self.x, y = original.y - self.y).

classmethod from_center_radius(cx: float, cy: float, radius: float, normalised: bool = False) BoundingBox2D

Create a square box centered at (cx, cy) with side 2*radius.

Parameters:
  • cx (float) – Center coordinates in pixels.

  • cy (float) – Center coordinates in pixels.

  • radius (float) – Half of the side length in pixels.

  • normalised (bool, optional) – Whether the returned coordinates are normalised.

Returns:

The constructed bounding box.

Return type:

BoundingBox2D

classmethod from_vector_radius(center: Vector2D, radius: float, normalised: bool = False) BoundingBox2D

Create a square box centered at center with side 2*radius.

Parameters:
  • center (Vector2D) – Center coordinate.

  • radius (float) – Half of the side length in pixels.

  • normalised (bool, optional) – Whether the returned coordinates are normalised.

Returns:

The constructed bounding box.

Return type:

BoundingBox2D

h: float
normalised: bool
uncrop_points(points: List[Tuple[float, float]] | List[Vector2D] | ndarray) List[Tuple[float, float]] | List[Vector2D] | ndarray

Convert points from this box’s local coordinates back to image space.

For each point:
  • If provided as a tuple (y, x) or as a numpy array (assumed order [y, x]), the original coordinate is (y + self.y, x + self.x).

  • If provided as a Vector2D (with fields x and y), the original coordinate is Vector2D(x = original.x + self.x, y = original.y + self.y).

w: float
x: float
y: float
class s6.schema.primitives.Circle2D(*, x: float, y: float, r: float)

Bases: Vector2D

2D circle parameterized by center (x, y) and radius r.

r: float
x: float
y: float
class s6.schema.primitives.ComponentStat(*, y: float, x: float, w: float, h: float, normalised: bool = False, area: float)

Bases: BoundingBox2D

Bounding box with connected-component area statistic.

area: float
static from_tuple(*args)

Construct from an OpenCV-style tuple (x, y, w, h, area).

h: float
normalised: bool
w: float
x: float
y: float
class s6.schema.primitives.TrackingTarget

Bases: object

Simple container describing a tracked region in an image.

bounding_box: BoundingBox2D
input_image: ndarray
class s6.schema.primitives.Vector2D(*, x: float, y: float)

Bases: BaseModel

2D vector/point with convenience math and conversion helpers.

Supports basic arithmetic (+, -, *, /), dot product, magnitude/normalization, and conversion to/from NumPy and Torch tensors.

clone()

Return a shallow copy of this vector.

dot(other)

Dot product with another Vector2D.

static from_numpy(array)

Create from a NumPy array-like (x, y).

static from_torch(tensor) Vector2D

Create from a Torch tensor of shape (2,) or (2, 1).

magnitude()

Euclidean length sqrt(x^2 + y^2).

normalize()

Return a unit-length vector in the same direction.

Raises:

ValueError – If this vector has zero length.

numpy()

Return a NumPy array of shape (2,) with dtype float32.

to_torch(dtype=torch.float32, device=None)

Return a Torch tensor tensor([x, y]) with the given dtype/device.

tolist()

Return [x, y] list representation.

x: float
y: float
class s6.schema.primitives.Vector3D(*, x: float, y: float, z: float)

Bases: BaseModel

3D vector/point with arithmetic and conversion helpers.

Provides vector math (add/subtract, scalar mul/div, dot/cross) and conversions to/from NumPy arrays and Torch tensors.

clone()

Return a shallow copy of this vector.

cross(other)

Cross product with another Vector3D (right-handed).

dot(other)

Dot product with another Vector3D.

static from_numpy(array)

Create from a NumPy sequence (x, y, z).

static from_torch(tensor) Vector3D

Create from a Torch tensor of shape (3,) or (3, 1).

property magnitude

Euclidean length sqrt(x^2 + y^2 + z^2).

normalize()

Return a unit-length vector in the same direction.

Raises:

ValueError – If this vector has zero length.

numpy()

Return a NumPy array of shape (3,) with dtype float32.

to_torch(dtype=torch.float32, device=None)

Return a Torch tensor tensor([x, y, z]) with the given dtype/device.

tolist()

Return [x, y, z] list representation.

x: float
y: float
z: float
classmethod zero() Vector3D

Convenience constructor for the zero vector (0, 0, 0).

s6.schema.pipeline_config module

Typed configuration for the Sense Core tracking pipeline.

This module defines Pydantic models that capture the configuration keys consumed by pipeline stages. Using typed objects enables attribute access with validation and sensible defaults, avoiding brittle nested‑dict lookups. The layout mirrors the structure of configs/pipeline.config.{yaml|yml|json}.

Key concepts

  • Sub‑configs group related parameters (e.g., tracking, tip).

  • Validators coerce common YAML/JSON forms (e.g., lists → tuples) and enforce ranges so problems are caught at load time.

class s6.schema.pipeline_config.BoundaryConfig(*, smoothing_window: ConstrainedIntValue = 3, max_radius_change_frac: ConstrainedFloatValue = 0.05, max_center_change_frac: ConstrainedFloatValue = 0.05, default_center: Tuple[float, float] = (640.0, 480.0), default_radius: ConstrainedFloatValue = 600.0)

Bases: BaseModel

Outer boundary detection/smoothing configuration.

smoothing_window

Window size (frames) for temporal smoothing (>= 1).

Type:

int

max_radius_change_frac

Max relative change in detected radius per frame (>= 0).

Type:

float

max_center_change_frac

Max relative change in detected centre per frame (>= 0).

Type:

float

default_center

Fallback boundary centre (x, y) in pixels.

Type:

tuple[float, float]

default_radius

Fallback boundary radius in pixels (> 0).

Type:

float

default_center: Tuple[float, float]
default_radius: float
max_center_change_frac: float
max_radius_change_frac: float
smoothing_window: int
class s6.schema.pipeline_config.DetectionConfig(*, components_area_thresholds: Tuple[int, int] = (600, 5000), fallback_margin_frac: ConstrainedFloatValue = 0.05)

Bases: BaseModel

Coarse component detection parameters.

components_area_thresholds

Minimum/maximum connected‑component areas used for filtering.

Type:

tuple[int, int]

fallback_margin_frac

Margin added around fallback ROIs as a fraction of image size (0.00.5).

Type:

float

components_area_thresholds: Tuple[int, int]
fallback_margin_frac: float
class s6.schema.pipeline_config.ExportConfig(*, preview_size: Tuple[int, int] = (320, 240), preview_format: str = '.jpg')

Bases: BaseModel

Export/telemetry configuration.

preview_size

Size of preview images as (width, height) in pixels.

Type:

tuple[int, int]

preview_format

File extension for previews (e.g., ".jpg").

Type:

str

preview_format: str
preview_size: Tuple[int, int]
class s6.schema.pipeline_config.PipelineConfig(*, tracking: TrackingConfig = None, solver: SolverConfig = None, detection: DetectionConfig = None, refine: RefineConfig = None, boundary: BoundaryConfig = None, tip: TipConfig = None, export: ExportConfig = None)

Bases: BaseModel

Root pipeline configuration container.

tracking

Per‑frame search/ROI configuration.

Type:

TrackingConfig

solver

Geometry/solver parameters.

Type:

SolverConfig

detection

Coarse component detection thresholds.

Type:

DetectionConfig

refine

Local refinement parameters.

Type:

RefineConfig

boundary

Outer boundary defaults and smoothing.

Type:

BoundaryConfig

tip

Tip ROI/tracking/refinement parameters.

Type:

TipConfig

export

Preview/telemetry export options.

Type:

ExportConfig

Examples

Minimal JSON compatible with load_default():

{
  "solver": { "instrument_length": 0.135 },
  "tracking": { "enable_prediction": false, "search_radius_px": 150 }
}
boundary: BoundaryConfig
detection: DetectionConfig
export: ExportConfig
static load_default() PipelineConfig

Load from default config path, preferring YAML when available.

Search order: - configs/pipeline.config.yaml - configs/pipeline.config.yml - configs/pipeline.config.json

Returns:

Parsed configuration object.

Return type:

PipelineConfig

Notes

YAML requires PyYAML; if unavailable or no YAML exists, JSON is used as a fallback.

refine: RefineConfig
solver: SolverConfig
tip: TipConfig
tracking: TrackingConfig
class s6.schema.pipeline_config.RefineConfig(*, zoom_factor: ConstrainedFloatValue = 4.5, patch_size: Tuple[int, int] = (128, 128))

Bases: BaseModel

Local refinement (patch warp) configuration.

zoom_factor

Relative zoom used when warping patches for refinement (> 0).

Type:

float

patch_size

Patch size as (width, height) in pixels (both > 0).

Type:

tuple[int, int]

patch_size: Tuple[int, int]
zoom_factor: float
class s6.schema.pipeline_config.SolverConfig(*, instrument_length: ConstrainedFloatValue = 0.135)

Bases: BaseModel

Configuration for geometric solver behaviour.

instrument_length

Instrument total length in meters (> 0).

Type:

float

instrument_length: float
class s6.schema.pipeline_config.TipConfig(*, boundary_margin_px: ConstrainedIntValue = 0, tracking_box_radius_px: ConstrainedIntValue = 80, tracking_box_next_radius_px: ConstrainedIntValue = 100, refine_area_thresholds: Tuple[int, int] = (20, 1200), suppression_radius_px: ConstrainedIntValue = 30)

Bases: BaseModel

Tip detection settings for ROI and refinement.

boundary_margin_px

Margin (pixels) used to keep ROIs within the outer boundary.

Type:

int

tracking_box_radius_px

Pixel radius for the primary tip tracking box (>= 1).

Type:

int

tracking_box_next_radius_px

Pixel radius for the next‑frame tracking box (>= 1).

Type:

int

refine_area_thresholds

Min/max areas (in pixels) for candidate regions in refinement.

Type:

tuple[int, int]

suppression_radius_px

Non‑maximum suppression radius in pixels (>= 0).

Type:

int

boundary_margin_px: int
refine_area_thresholds: Tuple[int, int]
suppression_radius_px: int
tracking_box_next_radius_px: int
tracking_box_radius_px: int
class s6.schema.pipeline_config.TrackingConfig(*, enable_prediction: bool = True, search_radius_px: ConstrainedIntValue = 150, trajectory_maxlen: ConstrainedIntValue = 20, search_radius_m: ConstrainedFloatValue = 0.05)

Bases: BaseModel

Per‑frame tracking/search configuration.

enable_prediction

If True, center the 2D search ROI around the predicted 3D endpoint projected into the image when available.

Type:

bool

search_radius_px

Pixel radius for the fallback 2D search region when prediction or valid depth is unavailable (>= 1).

Type:

int

trajectory_maxlen

Maximum trajectory length kept for smoothing/visualisation (>= 1).

Type:

int

search_radius_m

3D search sphere radius in meters used to adapt the 2D ROI size according to depth via camera projection (> 0).

Type:

float

enable_prediction: bool
search_radius_m: float
search_radius_px: int
trajectory_maxlen: int

s6.schema.robotic module

Robotic configuration models (stepper axes and waypoints).

These Pydantic models capture the configuration for the external stepper axes controller used by Sense Core’s robotic utilities. The schema is intended to match the structure of configs/robotic.config.json and provide attribute access, validation, and documentation for fields.

Key concepts

  • Each axis is configured with motor/drive parameters and an initial position in controller units.

  • Waypoints store named sets of target positions per axis.

class s6.schema.robotic.AxisConfig(*, Axis: AxisParams, current_position: int)

Bases: BaseModel

Configuration for a single axis.

Axis

Motor/driver parameters and defaults for the axis.

Type:

AxisParams

current_position

Initial position in controller units (e.g., steps).

Type:

int

Axis: AxisParams
current_position: int
class s6.schema.robotic.AxisParams(*, address: int, distance_per_revolution: float, step_per_revolution: int, nominal_speed: int, nominal_acceleration: int, persist: bool)

Bases: BaseModel

Parameters for initializing a motorized axis.

address

Controller/bus address for the axis.

Type:

int

distance_per_revolution

Linear travel per full motor revolution, in your mechanism’s linear units (e.g., millimetres per revolution).

Type:

float

step_per_revolution

Microsteps per motor revolution as configured on the driver.

Type:

int

nominal_speed

Nominal move speed in controller units.

Type:

int

nominal_acceleration

Nominal acceleration in controller units.

Type:

int

persist

If True, persist parameters to the controller’s storage when supported.

Type:

bool

address: int
distance_per_revolution: float
nominal_acceleration: int
nominal_speed: int
persist: bool
step_per_revolution: int
class s6.schema.robotic.RoboticConfig(*, Axes: Dict[str, AxisConfig], waypoints: List[Waypoint] = None)

Bases: BaseModel

Root configuration for robotic stepper axes and waypoints.

Axes

Axis configurations keyed by axis name.

Type:

dict[str, AxisConfig]

waypoints

Named sets of target positions for coordinated moves.

Type:

list[Waypoint]

Axes: Dict[str, AxisConfig]
get_axes() Dict[str, AxisConfig]

Return the axis configurations keyed by name.

Returns:

Mapping of axis name to configuration.

Return type:

dict[str, AxisConfig]

get_waypoints() List[Waypoint]

Return the list of named waypoints.

Returns:

Configured waypoints in the order provided.

Return type:

list[Waypoint]

static load_default() RoboticConfig

Load configuration from configs/robotic.config.json.

Returns:

Parsed configuration object.

Return type:

RoboticConfig

save_default(*, indent: int = 4) None

Write configuration to configs/robotic.config.json.

Parameters:

indent (int, optional) – Indentation level for pretty‑printed JSON (default 4).

waypoints: List[Waypoint]
class s6.schema.robotic.Waypoint(*, name: str, positions: Dict[str, int])

Bases: BaseModel

Named set of axis target positions.

name

Waypoint name (used for selection in the UI/service).

Type:

str

positions

Mapping from axis name to target position in controller units.

Type:

dict[str, int]

name: str
positions: Dict[str, int]

s6.schema.test_calibration module

class s6.schema.test_calibration.TestCalibrationConfig(methodName='runTest')

Bases: TestCase

test_invalid_config_missing_fields()
test_valid_config()
class s6.schema.test_calibration.TestCameraCalibration(methodName='runTest')

Bases: TestCase

setUp()

Hook method for setting up the test fixture before exercising it.

test_distortion_nested_list()
test_distortion_too_short()
test_extrinsic_invalid_shape()
test_intrinsic_invalid_shape()
test_resolution_invalid()
test_valid_camera_calibration()

s6.schema.test_connection module

class s6.schema.test_connection.TestConnectionConfig(methodName='runTest')

Bases: TestCase

test_default_host_configs()
test_invalid_camera_controller_config()
test_invalid_format()
test_invalid_ip_segment()
test_invalid_robotic_config()
test_invalid_type()
test_missing_stream_server()
test_parse_file_nested_configs()
test_valid_stream_server()
class s6.schema.test_connection.TestDBConfig(methodName='runTest')

Bases: TestCase

test_default_mongodb_and_fileserver()
test_invalid_database_name()
test_invalid_fileserver_url()
test_invalid_mongodb_uri()

s6.schema.test_data module

class s6.schema.test_data.TestInstrumentTrackingFrame(methodName='runTest')

Bases: TestCase

setUp()

Hook method for setting up the test fixture before exercising it.

test_invalid_projection_uv()
test_invalid_world_positions()
test_minimal_valid_frame()
test_missing_world_or_uuid()
test_parse_first_line()

s6.schema.test_light_calibration module

class s6.schema.test_light_calibration.TestLightCalibrationConfig(methodName='runTest')

Bases: TestCase

setUp()

Hook method for setting up the test fixture before exercising it.

tearDown()

Hook method for deconstructing the test fixture after testing it.

test_load_default()
test_missing_fields_validation()
test_save_default()
class s6.schema.test_light_calibration.TestSamplingRegion(methodName='runTest')

Bases: TestCase

setUp()

Hook method for setting up the test fixture before exercising it.

test_intensity_target_default()
test_sample_invalid_input()
test_sample_mean()

s6.schema.test_primitives module

class s6.schema.test_primitives.TestBoundingBox2D(methodName='runTest')

Bases: TestCase

setUp()

Hook method for setting up the test fixture before exercising it.

test_center()
test_crop_image()
test_crop_points_empty_list()
test_crop_points_invalid_list_element()
test_crop_points_invalid_type()
test_crop_points_list_tuples()
test_crop_points_list_vectors()
test_crop_points_numpy()
test_from_center_radius()
test_from_center_radius_normalised()
test_from_vector_radius()
test_uncrop_points_empty_list()
test_uncrop_points_invalid_type()
test_uncrop_points_list_tuples()
test_uncrop_points_list_vectors()
test_uncrop_points_numpy()
class s6.schema.test_primitives.TestCircle2D(methodName='runTest')

Bases: TestCase

test_attributes()
test_inherited_tolist()
class s6.schema.test_primitives.TestComponentStat(methodName='runTest')

Bases: TestCase

test_from_tuple()
class s6.schema.test_primitives.TestTrackingTarget(methodName='runTest')

Bases: TestCase

test_annotations()
class s6.schema.test_primitives.TestVector2D(methodName='runTest')

Bases: TestCase

setUp()

Hook method for setting up the test fixture before exercising it.

test_add()
test_clone()
test_dot_magnitude()
test_eq()
test_from_numpy()
test_hash()
test_invalid_operations()
test_mul()
test_neg_abs()
test_normalize()
test_numpy()
test_sub()
test_tolist()
test_torch_conversion()
test_truediv()
class s6.schema.test_primitives.TestVector3D(methodName='runTest')

Bases: TestCase

setUp()

Hook method for setting up the test fixture before exercising it.

test_add_sub_mul_div()
test_clone_tolist_numpy_from_numpy()
test_dot_cross_magnitude_normalize()
test_invalid_operations()
test_neg_abs_eq()
test_torch_conversion()

s6.schema.test_robotic module

class s6.schema.test_robotic.TestRoboticConfig(methodName='runTest')

Bases: TestCase

setUp()

Hook method for setting up the test fixture before exercising it.

test_invalid_axis_params()
test_missing_axes()
test_missing_waypoints()
test_valid_robotic_config() None
test_waypoints_invalid_type()

s6.schema.test_trace module

s6.schema.test_trace.test_ignore_extra_fields()
s6.schema.test_trace.test_invalid_phase(invalid_ph)
s6.schema.test_trace.test_invalid_pid_tid(pid, tid)
s6.schema.test_trace.test_invalid_timestamp(invalid_ts)
s6.schema.test_trace.test_readable_event_full()
s6.schema.test_trace.test_readable_event_ignore_extra_fields()
s6.schema.test_trace.test_readable_event_invalid_type(invalid_type)
s6.schema.test_trace.test_readable_event_minimal()
s6.schema.test_trace.test_readable_event_negative_depth(depth)
s6.schema.test_trace.test_readable_event_negative_time(ts)
s6.schema.test_trace.test_valid_event_defaults()
s6.schema.test_trace.test_valid_full_event()

s6.schema.trace module

Chrome Trace schema used by Sense Core profiling.

Defines lightweight Pydantic models that mirror the Chrome Trace Event format so we can serialize profiler spans to a browser‑inspectable trace (about://tracing). The TraceEvent model matches the wire format, while ReadableEvent is a friendlier record used when exporting human‑readable metrics.

Key concepts

  • Events use microsecond timestamps and have a phase: 'B' (begin) or 'E' (end).

  • Optional args carry arbitrary metadata for viewers and analysis.

class s6.schema.trace.ReadableEvent(*, event_name: str, event_type: Literal['begin', 'end'], relative_time_ms: ConstrainedFloatValue, depth: ConstrainedIntValue | None = None, metadata: Dict[str, Any] = None, full_path: str)

Bases: BaseModel

Human‑readable event record for reports.

This is a convenient representation used by s6.utils.profiler export helpers to produce tabular summaries and logs. Times are relative to process start in milliseconds and the phase is expanded to {"begin", "end"}.

event_name

Name of the event span.

Type:

str

event_type

Human‑readable phase.

Type:

{“begin”, “end”}

relative_time_ms

Time since program start, in milliseconds (non‑negative).

Type:

float

depth

Optional nesting depth for hierarchical spans.

Type:

int | None

metadata

Additional metadata excluding depth.

Type:

dict[str, Any]

full_path

Slash‑separated scope path, e.g. "stage/inner".

Type:

str

class Config

Bases: object

allow_population_by_field_name = True
extra = 'ignore'
validate_all = True
depth: int | None
event_name: str
event_type: Literal['begin', 'end']
full_path: str
metadata: Dict[str, Any]
relative_time_ms: float
class s6.schema.trace.TraceEvent(*, name: str, cat: str = 'profiling', ph: Literal['B', 'E'], ts: ConstrainedFloatValue, pid: ConstrainedIntValue = 0, tid: ConstrainedIntValue = 0, args: Dict[str, Any] | None = None)

Bases: BaseModel

Single Chrome Trace event record.

This model mirrors the Chrome Trace Event schema and is suitable for direct JSON emission to viewers compatible with the trace event profiling tool.

name

Event name shown in trace viewers.

Type:

str

cat

Category string used to group or filter events. Defaults to "profiling".

Type:

str

ph

Phase code: "B" for begin, "E" for end.

Type:

{“B”, “E”}

ts

Timestamp in microseconds since program start (non‑negative).

Type:

float

pid

Process identifier (non‑negative).

Type:

int

tid

Thread identifier (non‑negative).

Type:

int

args

Optional metadata for viewers and downstream tooling.

Type:

dict[str, Any] | None

Notes

See the Chrome trace event documentation for full schema details.

class Config

Bases: object

allow_population_by_field_name = True
extra = 'ignore'
validate_all = True
args: Dict[str, Any] | None
cat: str
name: str
ph: Literal['B', 'E']
pid: int
tid: int
ts: float

Module contents