Skip to content

Configuration

USC uses YAML files for all pipeline parameters. The configuration system provides:

  • Typed values through build_config, for clients that hold values rather than a file (Grasshopper through the daemon).
  • YAML loading of a flat mapping of settings; an analysis_period: mapping with Ladybug AnalysisPeriod.to_dict() keys is expanded into the six period fields. Relative paths are resolved against the YAML file's folder.
  • Overrides (-o key=value on the CLI, or a mapping in Python) that replace top-level values from the file.
  • Pydantic v2 validation with value ranges, type coercion, rejection of unknown keys, and one error message listing every problem. Both entry points raise ConfigError, whose errors list gives the field and message of each problem.
  • Chain files: a YAML with a criteria: list is loaded by load_chain into a ChainConfig (see Criteria); load_config refuses it and is_chain_file(path) tells the two apart.
  • Manifest schemas for the preprocessing and thresholding stages, so a later stage can be re-run from an earlier run's output.

See also: Configuration guide for the user-facing parameter reference.

Config loader

urbansolarcarver.load_config

Load a YAML config, apply overrides, and validate it into a user_config.

Overrides come from the CLI (key=value strings), the daemon, or Grasshopper. :func:build_config validates already-typed values (no YAML involved) and raises a structured :class:~urbansolarcarver.errors.ConfigError. The schema itself lives in :mod:pydantic_schemas.

parse_override_value(raw)

Convert a key=value override's value into a Python value.

"true"/"false" become bool and "null"/"none" None (case-insensitive); JSON lists and objects are parsed ([45,40,35]), then int, then float; anything else stays a string. "inf" and "nan" stay strings so the schema reports them clearly.

parse_override_value("true") True parse_override_value("3.5") 3.5 parse_override_value("foofoo") 'foofoo'

parse_overrides(overrides)

The settings named by overrides: key=value strings or a mapping.

String values are parsed by :func:parse_override_value. An analysis_period mapping is expanded into the six flat period fields, so the result can replace the values of a YAML file or of a mode's starting values field by field.

Raises:

Type Description
ConfigError

For an item without = or an analysis_period that is not a valid period (errors holds one entry whose field is None).

build_config(values, base_folder=None)

Validate values into a user_config.

Parameters:

Name Type Description Default
values Mapping[str, Any]

Config settings by name, already typed (what a YAML file or a client such as Grasshopper holds). An analysis_period mapping is expanded into the six flat period fields.

required
base_folder Path | str | None

When given, relative values of the path settings (meshes, EPW, out_dir, simulated weights) are resolved against it; otherwise they are kept as written.

None

Raises:

Type Description
ConfigError

On any invalid value. errors lists each problem with the field it concerns (None for checks that involve several fields).

build_config_from_mode_starting_values(values, base_folder=None)

Validate values on top of the starting values of the mode they name.

This is how a client without a YAML file gets a complete config: the mode's starting_values (see :mod:mode_registry) fill every setting values leaves out, and every setting values gives wins. The mode name may be an alias (tilted-plane). An analysis_period mapping in values is expanded first, so it replaces the starting period field by field. base_folder resolves relative paths as in :func:build_config.

Raises:

Type Description
ConfigError

When values has no mode (the error is on field mode), and for every problem :func:build_config reports, an unknown mode included.

read_yaml_mapping(path)

The top-level mapping of the YAML file at path (empty for an empty file).

Raises:

Type Description
FileNotFoundError

If path does not exist.

ConfigError

On malformed YAML or a top level that is not a mapping.

load_config(path, overrides=None)

Load the YAML at path, apply overrides, and validate.

Parameters:

Name Type Description Default
path str

YAML config file. Relative paths inside it (meshes, EPW, out_dir, simulated weights) are resolved against the file's folder.

required
overrides list[str] | Mapping[str, Any] | None

Top-level config keys that replace the YAML's values: "key=value" strings (values parsed by :func:parse_override_value) or a mapping. They win over the YAML, including over its analysis_period block. Relative paths in overrides are left as given (relative to the current directory).

None

Raises:

Type Description
FileNotFoundError

If path does not exist.

ConfigError

On malformed YAML, a file that lists criteria: (use :func:~urbansolarcarver.chain_config.load_chain), an override string without =, or invalid values (a ValueError listing all validation errors in one message).

urbansolarcarver.build_config(values, base_folder=None)

Validate values into a user_config.

Parameters:

Name Type Description Default
values Mapping[str, Any]

Config settings by name, already typed (what a YAML file or a client such as Grasshopper holds). An analysis_period mapping is expanded into the six flat period fields.

required
base_folder Path | str | None

When given, relative values of the path settings (meshes, EPW, out_dir, simulated weights) are resolved against it; otherwise they are kept as written.

None

Raises:

Type Description
ConfigError

On any invalid value. errors lists each problem with the field it concerns (None for checks that involve several fields).

Chain config

Shared settings are at the top level of a chain file and each criterion's own settings are listed under criteria:. load_chain(path, overrides) returns a ChainConfig: criteria is a tuple of Criterion(id, name, config) with one validated config per criterion, and shared is the last criterion's config. A criterion's id (default: its position from 1) names its output folder, so it is 1 to 40 letters, digits, _ or -, unique ignoring case and not a Windows device name (CON, NUL, COM1, ...). A shared setting inside a criterion, or a criterion setting at the top level or in -o overrides, is an error that names the setting; chain_config.CRITERION_KEYS lists the criterion settings.

urbansolarcarver.chain_config

The criteria: form of a config: several criteria carved in sequence on one voxel grid.

A chain file sets the shared settings once at the top level (meshes, voxel size, weather file, output folder, exporting and massing) and lists the settings of each criterion under criteria: (mode, test surface, how the voxels are decided, the mode's own parameters, its analysis period). :func:load_chain turns it into one validated user_config per criterion, so everything downstream reads ordinary configs.

ChainConfig(criteria, shared) dataclass

A chain of criteria. shared is the last criterion's config: exporting and massing read their settings from it, and those are all shared keys, equal in every criterion.

Criterion(id, name, config) dataclass

One criterion of a chain: its id (also its folder name), its display name and its validated config.

load_chain(path, overrides=None)

Load the chain file at path, apply overrides, and validate each criterion.

Each criterion's config is the shared settings plus its own, without the weather file when its mode does not read one. A criterion's id (default: its position from 1) names its output folder; its name (default: its mode) is for display.

Parameters:

Name Type Description Default
path str

YAML file with a criteria: list. Relative paths in it (top level and criteria) are resolved against the file's folder.

required
overrides list[str] | Mapping[str, Any] | None

Top-level settings that replace the YAML's: "key=value" strings or a mapping, as for :func:~urbansolarcarver.load_config.load_config. Shared settings only: a criterion setting in the overrides is refused.

None

Raises:

Type Description
FileNotFoundError

If path does not exist.

ConfigError

On malformed YAML, a file without criteria, a shared setting inside a criterion, a criterion setting at the top level, an id that is repeated, unsafe as a folder name or reserved by Windows, or an invalid criterion (the message starts criterion <id> (<name>):).

is_chain_file(path)

Whether the YAML at path is a mapping with a criteria key. A missing or malformed file is not a chain file; loading it reports the problem.

Mode starting values

mode_registry.MODES holds one ModeSpec per carving mode. Its starting_values are the settings that differ from the schema defaults and fill a new config for the mode: the analysis period of time-based, irradiance and benefit, tilted_plane_angle_deg: 45 for tilted_plane and carve_fraction: 0.35 for radiative_cooling. A client with no YAML file (Grasshopper through the daemon's run command) gets its config from these values plus its overrides. The schema defaults and validation rules are unchanged, so a CLI config without carve_fraction keeps 0.7 in every mode and time-based still requires an analysis period. The files in configs/ repeat the starting values as commented examples. ModeSpec.description is the text the Grasshopper mode component shows, MODE_ALIASES lists the accepted spellings (time_based, tilted-plane, ...) and canonical_mode_name(name) maps a name to the canonical one.

Schemas

urbansolarcarver.pydantic_schemas

Pydantic schemas for YAML configuration validation and stage manifests.

Defines :class:UserConfig (the pipeline configuration model, imported elsewhere as user_config), :class:ThresholdSpec (the normalized threshold setting), the four stage manifest schemas (:class:PreprocessingManifest, :class:ThresholdingManifest, :class:ExportingManifest, :class:MassingManifest) and the project-specific warning class :class:UrbanSolarCarverWarning.

The config schemas use extra='forbid' so that typos in YAML keys are caught at load time rather than silently ignored. The manifest schemas use Pydantic's default and ignore unknown keys.

ThresholdSpec

Bases: BaseModel

Canonical thresholding strategy: how per-voxel scores become a mask.

Every accepted config spelling of threshold (a bare number, a strategy name, or a mapping) is normalized into this one shape at load time, so downstream stages never re-interpret raw user input.

Methods:

Name Description
* ``carve_fraction``: carve the highest-scoring voxels that together

hold value (0-1) of the total score mass.

* ``headtail``: head/tail breaks
* ``cutoff``: carve voxels scoring strictly above ``value``; for

time-based this is the tolerated shading in m²·h.

SiteRules

Bases: BaseModel

Develop's rules of one drawn site while they are set per site (design/develop-workspace.md); each empty: no limit.

DevelopmentSite

Bases: BaseModel

A drawn site's outline in plan, in the input files' coordinates, for Develop's rules per site (written by the service).

UserConfig

Bases: BaseModel

resolved_threshold()

The thresholding strategy this config applies; see :func:resolve_threshold.

PreprocessingManifest

Bases: BaseModel

Manifest written by preprocessing, read by thresholding and exporting.

ThresholdingManifest

Bases: BaseModel

Manifest written by thresholding, read by exporting and massing.

ExportingManifest

Bases: BaseModel

Manifest written by exporting.

MassingManifest

Bases: BaseModel

Manifest written by massing.

schema_from_json(cls, text)

Deserialize a JSON string into a Pydantic model instance.

schema_to_json(model, *, indent=2)

Serialize a Pydantic model to a JSON string.

threshold_reads_carve_fraction(threshold)

Whether a threshold, in any spelling the config accepts, takes its value from carve_fraction.

It does when unset (in a weighted mode) or when it names the carve_fraction method without a value. A spelling the schema refuses reads nothing here; validation reports it.

resolve_threshold(mode, threshold, carve_fraction)

The complete thresholding strategy for mode.

threshold is the config's field as written: None takes the mode default (carve_fraction with the carve_fraction value for the weighted modes, cutoff 0 for the violation-count modes), and carve_fraction without a value takes carve_fraction. Raises ValueError for a method the mode cannot use: violation-count scores take only a cutoff, and tilted_plane only cutoff 0.

resolve_max_slope_deg(mode, max_slope_deg)

The slope limit thresholding applies for mode, or None when it is off.

An explicit max_slope_deg applies as given (90 = off). Unset, it is 75 degrees for the weighted modes, whose per-voxel score cutoffs can leave cliffs and spires, and off for the violation-count modes (time-based, tilted_plane), whose results follow the rays exactly.

resolve_grid_step(grid_step, voxel_size)

The sample spacing on the test surfaces, in meters: grid_step as given, or half the voxel size when it is unset.

Measured on the district example (Solar usefulness, 1 m voxels), half the voxel size keeps the kept voxels within about 1 % of a 0.25 m reference at about twice the time of a spacing of one voxel (2 %).

expand_analysis_period(data)

Expand an analysis_period mapping into the six flat period fields.

Canonical form uses Ladybug's AnalysisPeriod.to_dict() keys (st_month ... end_hour), so a Ladybug period can be pasted or passed directly; start_month-style keys work as well. Returns a new dict. Raises ValueError if analysis_period is not a mapping, has an unknown key, or disagrees with a flat period field in the same dict.