Commit c6424dc8 authored by yuedong0607's avatar yuedong0607
Browse files

Refactor versioned instrument data package and fix optional SLS references

parent ce112596
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -19,6 +19,12 @@ data_set: "csst-msc-c11-1000sqdeg-wide-v1"
project_cycle: 9
run_counter: 1

# Versioned detector definitions used by Chip and the readout simulation steps
instrument_data:
  release: legacy-v1
  release_directory: null
  detector_overrides: {}

# Run options
run_option:
  # Output catalog only?
+6 −0
Original line number Diff line number Diff line
@@ -17,6 +17,12 @@ run_name: "testRun0"
project_cycle: 9
run_counter: 1

# Versioned detector definitions used by Chip and the readout simulation steps
instrument_data:
  release: legacy-v1
  release_directory: null
  detector_overrides: {}

# Run options
run_option:
  # Output catalog only?
+70 −0
Original line number Diff line number Diff line
# CSST instrument detector model

This package is the authoritative interface between version-controlled
instrument data and the main simulator. Simulation steps must consume a
`ResolvedDetector` from `InstrumentRepository`; they must not parse YAML or
duplicate channel geometry.

## Catalog ownership

| Catalog | Owns | Changes when |
|---|---|---|
| `detector_types.yaml` | Active size, pitch, detector technology, nominal electronics | A detector design changes |
| `readout_modes.yaml` | Channel boxes, transforms, per-channel scans, raw placement and output order | A controller/readout mode changes |
| `calibration_profiles.yaml` | Dated electronics, defects, exposure recipes and calibration references | A calibration release changes |
| `focal_plane.yaml` | Installed detector IDs, type/mode/profile references, placement, filter and survey role | The focal-plane build changes |

Instrument releases are immutable directories under `releases/`. Add a new
directory for a new release; do not silently rewrite a release already used for
production.
`legacy-v1` preserves the values formerly stored in the simulator's legacy
`chip_definition.json` file.

## Runtime API

```python
from csst_msc_instrument import InstrumentRepository

instrument = InstrumentRepository.load_builtin("legacy-v1")
detector = instrument.detector("01")

for channel in detector.iter_channels():
    print(channel.id, channel.detector_bbox, channel.raw_shape)
```

`Chip` loads the built-in release by default. An overall simulation config can
select another checked-out release directory or override a detector's
mode/profile:

```yaml
instrument_data:
  release: legacy-v1
  release_directory: null
  detector_overrides:
    "01":
      readout_mode: science_16ch_legacy
      calibration_profile: science_nominal_v1
```

## Versioned reference files

Each directory under `releases/` is a self-contained instrument release. Its
schema-validated YAML lives under `definitions/`; throughput curves, distortion
models, calibration arrays, and slitless-spectroscopy files live under
`reference_files/`. Consumers use a release-bound `InstrumentRepository` and
its `reference_path()` or `materialized_reference_path()` methods, so custom
release directories never fall back to files from a different built-in release.

## Validation and schemas

Unknown keys are rejected and cross-catalog validation checks references,
channel coverage/non-overlap, raw mosaic bounds, and calibration channel IDs.

```bash
python -m csst_msc_instrument validate --release legacy-v1
python -m csst_msc_instrument emit-schema \
  csst_msc_instrument/schemas/1.0
```

The checked-in schemas are generated from the same Pydantic models. CI should
regenerate them and fail if the schema directory changes.
+33 −0
Original line number Diff line number Diff line
from .models import BBox, ChannelGeometry, DetectorType, Electronics, ReadoutMode
from .references import (
    DEFAULT_RELEASE,
    ReferenceGroup,
    materialized_reference_path,
    reference,
    reference_path,
)
from .repository import (
    InstrumentRepository,
    ResolvedChannel,
    ResolvedDetector,
    get_builtin_repository,
)
from .schema import emit_schemas

__all__ = [
    "BBox",
    "ChannelGeometry",
    "DEFAULT_RELEASE",
    "DetectorType",
    "Electronics",
    "InstrumentRepository",
    "ReadoutMode",
    "ReferenceGroup",
    "ResolvedChannel",
    "ResolvedDetector",
    "emit_schemas",
    "get_builtin_repository",
    "materialized_reference_path",
    "reference",
    "reference_path",
]
 No newline at end of file
+34 −0
Original line number Diff line number Diff line
from __future__ import annotations

import argparse

from .references import DEFAULT_RELEASE
from .repository import InstrumentRepository
from .schema import emit_schemas


def main() -> None:
    parser = argparse.ArgumentParser(description="Manage CSST instrument releases")
    subparsers = parser.add_subparsers(dest="command", required=True)

    validate = subparsers.add_parser("validate", help="validate instrument catalogs")
    validate.add_argument("directory", nargs="?")
    validate.add_argument("--release", default=DEFAULT_RELEASE)

    emit = subparsers.add_parser("emit-schema", help="regenerate JSON Schemas")
    emit.add_argument("output_directory")

    args = parser.parse_args()
    if args.command == "validate":
        if args.directory:
            repository = InstrumentRepository.load(args.directory)
        else:
            repository = InstrumentRepository.load_builtin(args.release)
        detector_count = len(tuple(repository.iter_detectors()))
        print(f"validated {detector_count} detectors")
    else:
        emit_schemas(args.output_directory)


if __name__ == "__main__":
    main()
Loading