autoemx.config.schema_models.segmentation module
Particle segmentations of the frames of a sample (SampleLedger.segmentations), and the result of one segmentation
of one frame (FrameRecord.segmentations).
Like quantifications, each segmentation has an id: segmenting frames again (with another model or threshold) adds results with a new id to the frames, and never replaces earlier ones, so that the statistics of different segmentations can be compared and one chosen.
- class autoemx.config.schema_models.segmentation.SegmentationConfig(*, segmentation_id: int, label: str = '', autoemx_version: str = '1.8.0', datetime: str = <factory>, source: Literal['acquisition', 'reanalysis']='acquisition', par_segmentation_model: str, par_brightness_thresh: int, min_par_pixels: int, model_params: Dict[str, ~typing.Any]=<factory>)[source]
Bases:
BaseModelSettings of a particle segmentation of the frames of a sample: segmentation model, brightness threshold (used by the threshold model), minimum number of pixels of a particle for its area to be measured, and options of the model (
PowderMeasurementConfig.par_segmentation_params, e.g. the SAM2 checkpoint).sourcetells whether frames were segmented with it during an acquisition, or again afterwards from their saved images.- segmentation_id: int
- label: str
- autoemx_version: str
- datetime: str
- source: Literal['acquisition', 'reanalysis']
- par_segmentation_model: str
- par_brightness_thresh: int
- min_par_pixels: int
- model_params: Dict[str, Any]
- model_config = {'extra': 'forbid'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- default_label() SegmentationConfig[source]
- settings() Dict[str, Any][source]
The segmentation settings (not the id, version, date, source or label); the brightness threshold only for the threshold model, the only one using it.
- fingerprint() str[source]
Identity of the settings: a segmentation with the same settings is reused, not added again.
- classmethod from_powder_meas_cfg(cfg: PowderMeasurementConfig, segmentation_id: int, source: str = 'acquisition') SegmentationConfig[source]
Segmentation with the settings of a measurement.
- autoemx.config.schema_models.segmentation.segmentation_label(model: str, threshold: int, min_par_pixels: int, model_params: Dict[str, Any] | None = None) str[source]
Readable name of segmentation settings, e.g. ‘threshold_bright · 100 · 80 px’, or ‘SAM2 · 80 px · checkpoint=sam2.1-hiera-small’ (model options, values shortened to their last path part).
- class autoemx.config.schema_models.segmentation.FrameSegmentation(*, segmentation_id: int, d_range_um: ~typing.Tuple[float, float], particle_areas_um2: ~typing.List[float] = <factory>, particle_edge_corrections: ~typing.List[float] = <factory>, particle_marks_px: ~typing.List[~typing.Tuple[int, int, int]] = <factory>)[source]
Bases:
BaseModelParticles found in a frame by one segmentation (
segmentation_id): area, frame-edge correction and mark (x, y and radius in pixels, on the frame image) of each particle valid for the statistics: ind_range_um(the diameters searched in the frame, from the smallest with at leastmin_par_pixelspixels) and not touching the frame edge. Particleiof the frame is identified by(frame_id, i).- segmentation_id: int
- d_range_um: Tuple[float, float]
- particle_areas_um2: List[float]
- particle_edge_corrections: List[float]
- particle_marks_px: List[Tuple[int, int, int]]
- model_config = {'extra': 'forbid'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- validate_particles() FrameSegmentation[source]
- property n_particles: int