segrails.config

Segrails library configuration.

Reads all parameters from environment variables at instantiation time. A .env file is loaded automatically when the module is imported (requires python-dotenv).

To pick up changes to .env: instantiate a new SegrailsConfig(). To override specific values without env vars: use SegrailsConfig.from_yaml(yaml_path) or pass keyword arguments: SegrailsConfig(model_name=”my-model”).

Environment variables:
Model:

SEGRAILS_MODEL_NAME Model name (default: “segrails-unet”). SEGRAILS_MODEL_VERSION Model version (default: “latest”). SEGRAILS_WEIGHTS_SOURCE Weights URI (azure://… or https://…).

Storage:

DS_WEIGHTS_CONTAINER Azure Blob container name (default: “weights”). DS_WEIGHTS_PREFIX Container prefix (default: “segrails”). DS_API_BASE_URL APIM base URL. When set and SEGRAILS_WEIGHTS_SOURCE is absent,

weights_source is derived as {DS_API_BASE_URL}/{SEGRAILS_ENV}/weights/ {DS_WEIGHTS_PREFIX}/{SEGRAILS_MODEL_NAME}.

Processing:

SEGRAILS_RASTER_RESOLUTION Raster resolution in m/px (default: 0.06). SEGRAILS_RASTER_ABOVE_GROUND_FILTER Remove ground points before rasterization (default: true). SEGRAILS_RASTER_NOISE_OUTLIER Remove statistical noise outliers before rasterization (default: false). SEGRAILS_POSTPROCESS_DEBUG Save debug PNG visualisations after postprocessing (default: false).

Cache:

SEGRAILS_CACHE_DIR Local cache directory (default: ~/.cache/segrails). SEGRAILS_CACHE_TTL_SECONDS Cache TTL in seconds (default: 86400).

Monitoring:

MLFLOW_TRACKING_URI MLflow tracking URI (disabled if absent). AZURE_TABLES_CONNECTION_STRING Azure Storage connection string for Table tracking. AZURE_TABLES_ACCOUNT_URL Azure Storage table endpoint URL (used with DefaultAzureCredential). AZURE_TABLES_TABLE_NAME Azure Table name (default: “SegrailsInferences”).

Environment:

SEGRAILS_ENV Target environment: dev / test / beta / prod (default: “dev”).

Example

>>> config = SegrailsConfig()
>>> config.env
'dev'
>>> config = SegrailsConfig.from_yaml("segrails.yml")
>>> config.model_name
'U-Net-segrails'

Classes

SegrailsConfig

Immutable configuration for the Segrails library.

Module Contents

class segrails.config.SegrailsConfig

Immutable configuration for the Segrails library.

All fields are read from environment variables at instantiation time. A .env file is loaded automatically if python-dotenv is installed.

To override values: use from_yaml(yaml_path) for file-based config, or pass keyword arguments directly: SegrailsConfig(model_name=”my-model”).

Example

>>> import os
>>> os.environ["SEGRAILS_ENV"] = "prod"
>>> config = SegrailsConfig()
>>> config.env
'prod'
>>> config = SegrailsConfig.from_yaml("segrails.yml")
>>> config.model_name
'U-Net-segrails'
model_name: str
model_version: str
weights_source: str
weights_container: str
weights_prefix: str
api_base_url: str
api_weights_endpoint: str = 'weights'
raster_resolution: float
raster_above_ground_filter: bool
raster_noise_outlier: bool
inference_image_size: tuple[int, int] = (512, 512)
model_encoder: str
model_classes: int
model_mean: tuple[float, float, float] = (93.8652, 72.2728, 14.3507)
model_std: tuple[float, float, float] = (72.8819, 76.9462, 25.7942)
detection_area_min: float
detection_area_max: float
detection_distance_min: float
detection_distance_max: float
detection_dilation_size: float
detection_canny_low: float
detection_canny_high: float
detection_hough_threshold: float
detection_hough_min_line: float
detection_hough_max_gap: float
detection_origin_distance: float
detection_box_splits: int
detection_iou_threshold: float
postprocess_debug: bool
cache_dir: str
cache_ttl_seconds: int | None
mlflow_tracking_uri: str
azure_tables_connection_string: str
azure_tables_account_url: str
azure_tables_table_name: str
env: str
classmethod from_yaml(path: str | pathlib.Path) SegrailsConfig

Load configuration from a YAML file with environment variable overrides.

YAML values serve as base defaults. Environment variables always take priority and override the corresponding YAML values.

Parameters:

path – Path to the YAML configuration file (see segrails.yml.example).

Returns:

Merged configuration (YAML base + env var overrides).

Return type:

SegrailsConfig

Raises:
  • FileNotFoundError – If the YAML file does not exist.

  • ValueError – If the YAML file is invalid or malformed.

Example

>>> config = SegrailsConfig.from_yaml("segrails.yml")
>>> config.model_name
'U-Net-segrails'