cfx.views

View classes for projecting Config trees into custom namespaces.

A view binds to one or more Config instances and exposes a curated or auto-generated subset of their fields under new names. Reads and writes delegate through to the underlying config — views carry no field data of their own.

Public API

ConfigView

Base class for hand-written curated projections.

AliasedView

Auto-generates prefixed aliases for every field in each component.

FlatView

Like AliasedView but with no prefix — raises on name conflicts.

Classes

ConfigView

Base class for curated projections over a Config instance.

AliasedView

A self-contained view that owns its component instances.

FlatView

An AliasedView with no component prefix.

Module Contents

class cfx.views.ConfigView(config)[source]

Base class for curated projections over a Config instance.

Subclass ConfigView and declare Alias attributes to expose a selected subset of fields from one or more configs under names that suit the consumer’s context. All reads and writes delegate to the bound config — the view itself holds no values:

class CalibSummaryView(ConfigView):
    psf_kernel = Alias(PSFFittingConfig.kernel_estimate)
    zero_point = Alias(PhotometryConfig.zero_point)

view = CalibSummaryView(pipeline.calibration)
view.psf_kernel           # reads pipeline.calibration.psf_fitting...
view.psf_kernel = 3.5     # writes through

Views can span multiple sub-configs by binding to a common parent:

class PipelineSummaryView(ConfigView):
    psf_kernel = Alias(CalibrationConfig.psf_fitting.kernel_estimate)
    threshold  = Alias(DetectionConfig.threshold)

view = PipelineSummaryView(pipeline_cfg)
Parameters:
configConfig

The config instance to bind to. All alias paths are resolved relative to this object.

classmethod __init_subclass__(**kwargs)[source]
to_dict()[source]

Return a plain dict of the aliased fields and their current values.

Returns:
ddict

Mapping of alias name to current value for every declared Alias.

classmethod from_dict(d, config)[source]

Bind config and apply values from d through the view’s aliases.

Parameters:
ddict

Alias names and replacement values.

configConfig

The config instance to bind and write into.

Returns:
viewConfigView

A bound view with d values applied.

__repr__()[source]
class cfx.views.AliasedView[source]

Bases: ConfigView

A self-contained view that owns its component instances.

Subclass AliasedView and pass components= to auto-generate Alias descriptors for every field in each component. By default each alias is prefixed with the component’s confid:

class CalibView(AliasedView, components=[PSFConfig, PhotoConfig]):
    pass

v = CalibView()
v.psf_kernel = 3.5   # writes through to v.psf.kernel_estimate

Supply aliases= to override the prefix for each component (use None for a flat, unprefixed namespace):

class CalibView(AliasedView,
                components=[PSFConfig, PhotoConfig],
                aliases=["psf", None]):
    pass

Name conflicts among auto-generated aliases raise ValueError at class-definition time.

Unlike ConfigView, an AliasedView is constructed with no arguments — it creates and owns a fresh instance of each component.

classmethod __init_subclass__(components=None, aliases=None, **kwargs)[source]
classmethod from_dict(d)[source]

Create a fresh view and apply field values from d.

Parameters:
ddict

Alias names and replacement values.

Returns:
viewAliasedView

A new view with d values applied.

class cfx.views.FlatView[source]

Bases: AliasedView

An AliasedView with no component prefix.

Every component field is exposed directly by its own name. A ValueError is raised at class-definition time if two components share a field name:

class InstrumentView(
        FlatView,
        components=[
            CameraConfig,
            FilterConfig,
        ]):
    pass

v = InstrumentView()
v.gain = 2.0   # writes through to v.camera.gain
classmethod __init_subclass__(components=None, **kwargs)[source]