Skip to content

Commit 0b46eb8

Browse files
committed
Add stubs for loading cameraGeom inside PipelineTasks.
1 parent b5d7751 commit 0b46eb8

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

python/lsst/obs/base/_camera_loaders.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
from lsst.afw.cameraGeom import Camera, CameraBuilder, Detector, DetectorBuilder
3535
from lsst.daf.butler import Butler, DataId, DatasetRef, DatasetType
36+
from lsst.pipe.base import ButlerQuantumContext
3637

3738

3839
class CameraBuilderUpdater(ABC):
@@ -400,3 +401,99 @@ def update_detectors(
400401
def finish(self) -> Camera:
401402
"""Finish updating and return the updated `Camera`."""
402403
return self.builder.finish()
404+
405+
406+
def load_detector_for_quantum(
407+
self,
408+
arg: Union[str, int, DatasetRef, Detector, DetectorBuilder],
409+
/,
410+
butlerQC: ButlerQuantumContext,
411+
camera: Union[DatasetRef, Camera, CameraBuilder, None] = None,
412+
**kwargs: Union[bool, DatasetRef, DetectorBuilderUpdater],
413+
) -> Detector:
414+
"""A variant of `Instrument.load_detector` for use inside
415+
`PipelineTask.runQuantum`.
416+
417+
Parameters
418+
----------
419+
arg : `str`, `int`, `DatasetRef`, `Detector`, `DetectorBuilder`
420+
If a `DatasetRef`, `Detector`, or `DetectorBuilder`, an object that
421+
can be used or loaded to provide the detector directly (``camera``
422+
will be ignored).
423+
If an `int` or `str`, a detector identifier to use with ``camera``.
424+
butlerQC : `ButlerQuantumContext`
425+
Butler client proxy to read from.
426+
camera : `DatasetRef`, `Camera`, `CameraBuilder`, optional
427+
Used to obtain a `Camera` or `CameraBuilder` as a way to get a
428+
`DetectorBuilder`. If a `Camera` is given, the detector is
429+
extracted and then a `Detector.rebuild` is called, instead of
430+
rebuilding the full camera. Required (unlike
431+
`Instrument.load_detector`) if the first argument is a `str` or `int`.
432+
**kwargs
433+
Named updates to apply to the detector. Keys are typically those in
434+
`Instrument.detector_calibrations`, but are only used here in error
435+
messages. Values are one of the following:
436+
437+
- `False`: do not update this dataset (same as not passing a key).
438+
- `DatasetRef`: load with `ButlerQuantumContext.get` (must be a
439+
resolved reference).
440+
- `DetectorBuilderUpdater`: just apply this calibration directly.
441+
442+
Returns
443+
-------
444+
detector : `Detector`
445+
The loaded detector object.
446+
447+
Notes
448+
-----
449+
This function only applies the updates given as keyword arguments, while
450+
the `Instrument.load_detector` method attempts to apply all updates
451+
potentially used by that instrument.
452+
"""
453+
# Implementing this by delegating to DetectorLoader is tricky because
454+
# ButlerQuantumContext doesn't expose its underlying butler. Hopefully we
455+
# can resolve this while the rest of the RFC is worked out.
456+
raise NotImplementedError("TODO")
457+
458+
459+
def load_camera_for_quantum(
460+
self,
461+
butlerQC: ButlerQuantumContext,
462+
camera: Union[DatasetRef, Camera, CameraBuilder],
463+
**kwargs: Union[
464+
bool, DatasetRef, CameraBuilderUpdater, Iterable[DatasetRef], Iterable[DetectorBuilderUpdater]
465+
],
466+
) -> Camera:
467+
"""
468+
Parameters
469+
----------
470+
butler : `Butler`
471+
Butler client to read from. If not initialized with the desired
472+
collection search path, the ``collections`` argument must be
473+
provided.
474+
camera : `DatasetRef`, `Camera`, `CameraBuilder`, optional
475+
A `CameraBuilder`, a `Camera` to rebuild into one, or a butler
476+
reference that can be used to load a `Camera`.
477+
**kwargs
478+
Named updates to apply to the camera or its detectors, depending on
479+
whether the key is in `Instrument.detector_calibrations` or
480+
`Instrument.camera_calibrations` (for the instrument identified by
481+
``butlerQC.quantum.dataId``):
482+
483+
- `False`: do not use this calibration (same as no key).
484+
- `DatasetRef`: a `CameraBuilderUpdater` dataset to load and apply.
485+
- `CameraBuilderUpdater`: a full-camera update to apply directly.
486+
- `Iterable` [ `DatasetRef` ]: per-detector `DetectorBuilderUpdater`
487+
datasets to load and apply.
488+
- `Iterable` [ `DetectorBuilderUpdater` ]: per-detector updates to
489+
apply directly.
490+
491+
Returns
492+
-------
493+
camera : `Camera`
494+
The updated camera.
495+
"""
496+
# Implementing this by delegating to DetectorLoader is tricky because
497+
# ButlerQuantumContext doesn't expose its underlying butler. Hopefully we
498+
# can resolve this while the rest of the RFC is worked out.
499+
raise NotImplementedError("TODO")

0 commit comments

Comments
 (0)