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¶
Base class for curated projections over a |
|
A self-contained view that owns its component instances. |
|
An |
Module Contents¶
- class cfx.views.ConfigView(config)[source]¶
Base class for curated projections over a
Configinstance.Subclass
ConfigViewand declareAliasattributes 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:
- config
Config The config instance to bind to. All alias paths are resolved relative to this object.
- config
- to_dict()[source]¶
Return a plain dict of the aliased fields and their current values.
- Returns:
- d
dict Mapping of alias name to current value for every declared
Alias.
- d
- classmethod from_dict(d, config)[source]¶
Bind config and apply values from d through the view’s aliases.
- Parameters:
- d
dict Alias names and replacement values.
- config
Config The config instance to bind and write into.
- d
- Returns:
- view
ConfigView A bound view with d values applied.
- view
- class cfx.views.AliasedView[source]¶
Bases:
ConfigViewA self-contained view that owns its component instances.
Subclass
AliasedViewand passcomponents=to auto-generateAliasdescriptors for every field in each component. By default each alias is prefixed with the component’sconfid: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 (useNonefor a flat, unprefixed namespace):class CalibView(AliasedView, components=[PSFConfig, PhotoConfig], aliases=["psf", None]): pass
Name conflicts among auto-generated aliases raise
ValueErrorat class-definition time.Unlike
ConfigView, anAliasedViewis constructed with no arguments — it creates and owns a fresh instance of each component.- classmethod from_dict(d)[source]¶
Create a fresh view and apply field values from d.
- Parameters:
- d
dict Alias names and replacement values.
- d
- Returns:
- view
AliasedView A new view with d values applied.
- view
- class cfx.views.FlatView[source]¶
Bases:
AliasedViewAn
AliasedViewwith no component prefix.Every component field is exposed directly by its own name. A
ValueErroris 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