Skip to content

Config

optari.config.config

OptariConfig: dataclass schema for the user's ~/.optari/config/config.json.

AnalysisConfig dataclass

AnalysisConfig(histogram_bins)

Settings for the analysis dock.

AnnotationConfig dataclass

AnnotationConfig(roi_colors=list(), roi_features=dict(), show_track_id=True, roi_label_size=8)

ROI annotation display settings: colors, measured features, and shape labels.

ExportConfig dataclass

ExportConfig(font_size, cbar_width, padding)

Layout settings for exported figures: font size, colorbar width, and padding.

GeneralConfig dataclass

GeneralConfig(LOG_LEVEL, GUI_LOG_LEVEL, DEFAULT_PA_LAYER, PA_FALLBACK_SCALE, DEFAULT_US_LAYER, US_FALLBACK_SCALE, DEFAULT_FRAME_INDEX, DEFAULT_CHANNEL_INDEX, DEFAULT_PLAYBACK_FPS, OPERATOR, ANALYSIS_ID, LAYER_COLOR_MAPS=dict(), DEFAULT_VISIBLE_DOCKS=dict())

App-wide defaults: logging, default layers/scales/frame/channel, operator identity, layer colors, dock visibility.

OptariConfig dataclass

OptariConfig(schema_version, general, annotation, analysis, segmentation, export)

Top-level config, loaded once at startup into the module-level settings.

Mirrors ~/.optari/config/config.json: one section per settings category.

load_from_user_dir classmethod

load_from_user_dir()

Loads the user's config.json and safely parses it into the dataclasses.

Source code in src/optari/config/config.py
85
86
87
88
89
90
91
92
93
94
95
96
97
98
@classmethod
def load_from_user_dir(cls) -> "OptariConfig":
    """Loads the user's config.json and safely parses it into the dataclasses."""
    config_path = get_user_config_file()
    data = json.loads(config_path.read_text())

    schema_version = data.get("schema_version")

    if schema_version != CONFIG_SCHEMA_VERSION:
        archive_config_dir(config_path.parent)
        config_path = get_user_config_file()
        data = json.loads(config_path.read_text())

    return _config_from_dict(data)

SegmentationConfig dataclass

SegmentationConfig(default_model)

Default segmentation model to preselect in the Segmentation dock.

read_user_config_dict

read_user_config_dict()

Return the raw contents of the user's config.json.

Source code in src/optari/config/config.py
112
113
114
def read_user_config_dict() -> dict:
    """Return the raw contents of the user's config.json."""
    return json.loads(get_user_config_file().read_text(encoding="utf-8"))

write_user_config_dict

write_user_config_dict(data)

Validate data against the config dataclasses and write it atomically.

Source code in src/optari/config/config.py
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
def write_user_config_dict(data: dict) -> Path:
    """Validate *data* against the config dataclasses and write it atomically."""
    if data.get("schema_version") != CONFIG_SCHEMA_VERSION:
        # A mismatch makes the loader archive the whole user directory on next launch.
        raise ValueError(
            f"Refusing to write config with schema_version {data.get('schema_version')!r}; "
            f"expected {CONFIG_SCHEMA_VERSION}."
        )

    # Constructing the sections also works as validation: the loader is intolerant of missing or
    # unknown keys, so anything it would reject never reaches disk.
    _config_from_dict(data)

    path = get_user_config_file()
    with atomic_destination(path) as temporary:
        temporary.write_text(
            json.dumps(data, indent=4, ensure_ascii=False) + "\n",
            encoding="utf-8",
        )
    return path