Add detector architecture + isotropic detectors

This commit is contained in:
Pim Nelissen
2026-03-03 09:48:20 +01:00
parent 41a8ca95b3
commit c98000dfd8
10 changed files with 179 additions and 13 deletions

View File

@ -17,7 +17,8 @@ from .specs import (
SourceSpec,
AbsolutePointSourceSpec,
RelativePointSourceSpec,
SimulationSpec,
DetectorSpec,
SimulationSpec
)
@ -31,7 +32,8 @@ class ConfigParser:
"acquisition_time",
"path",
"sources",
"options",
"detector",
"options"
}
def __init__(self, config_source: str):
@ -49,6 +51,7 @@ class ConfigParser:
options = self._parse_options()
path = self._parse_path()
sources = self._parse_point_sources()
detector = self._parse_detector()
return SimulationSpec(
metadata=metadata,
@ -56,6 +59,7 @@ class ConfigParser:
options=options,
path=path,
point_sources=sources,
detector=detector
)
def _load_yaml(self, config_source: str) -> Dict[str, Any]:
@ -285,6 +289,34 @@ class ConfigParser:
return specs
def _parse_detector(self) -> DetectorSpec:
det_dict = self.config.get("detector", {})
required = {"name", "is_isotropic"}
missing = required - det_dict.keys()
if missing:
raise MissingConfigKeyError(missing)
name = det_dict.get("name")
is_isotropic = det_dict.get("is_isotropic")
eff = det_dict.get("efficiency")
default_detectors = defaults.DETECTOR_EFFICIENCIES
if eff is None and name in default_detectors.keys():
eff = default_detectors[name]
elif eff is not None:
pass
else:
raise ValueError(
f"The detector {name} is not in the library, and no "
"efficiency was defined. Either specify detector efficiency "
"or choose one from the following list: "
f"{default_detectors.keys()}"
)
return DetectorSpec(name=name, eff=eff, is_isotropic=is_isotropic)
def _warn_unknown_keys(self, section: str, provided: set, allowed: set):
unknown = provided - allowed
if unknown:

View File

@ -63,6 +63,13 @@ class RelativePointSourceSpec(SourceSpec):
z: float
@dataclass
class DetectorSpec:
name: str
eff: float | None
is_isotropic: bool
@dataclass
class SimulationSpec:
metadata: MetadataSpec
@ -70,3 +77,4 @@ class SimulationSpec:
options: SimulationOptionsSpec
path: PathSpec
point_sources: list[SourceSpec]
detector: DetectorSpec