Merge branch 'dev' of github.com:pim-n/pg-rad into dev

This commit is contained in:
Pim Nelissen
2026-05-03 17:46:50 +02:00
11 changed files with 74 additions and 12 deletions

View File

@ -11,7 +11,8 @@ def generate_background(
cps_array: np.ndarray, cps_array: np.ndarray,
detector: Detector, detector: Detector,
energy_keV: float, energy_keV: float,
lam_inp: int | None = None lam_inp: int | None = None,
seed: int | None = None
) -> np.ndarray: ) -> np.ndarray:
""" """
@ -23,7 +24,7 @@ def generate_background(
else: else:
lam = lam_inp lam = lam_inp
rng = np.random.default_rng() rng = np.random.default_rng(seed=seed)
return rng.poisson(lam=lam, size=cps_array.shape) return rng.poisson(lam=lam, size=cps_array.shape)

View File

@ -0,0 +1,38 @@
angle,662
0,0.027
10,0.162
20,0.346
30,0.517
40,0.662
50,0.794
60,0.882
70,0.947
80,0.995
90,1.000
100,0.970
110,0.895
120,0.778
130,0.649
140,0.546
150,0.477
160,0.387
170,0.267
180,0.205
-180,0.205
-170,0.266
-160,0.385
-150,0.527
-140,0.671
-130,0.764
-120,0.838
-110,0.763
-100,0.838
-90,0.903
-80,0.904
-70,0.898
-60,0.862
-50,0.717
-40,0.337
-30,0.154
-20,0.253
-10,0.125
1 angle 662
2 0 0.027
3 10 0.162
4 20 0.346
5 30 0.517
6 40 0.662
7 50 0.794
8 60 0.882
9 70 0.947
10 80 0.995
11 90 1.000
12 100 0.970
13 110 0.895
14 120 0.778
15 130 0.649
16 140 0.546
17 150 0.477
18 160 0.387
19 170 0.267
20 180 0.205
21 -180 0.205
22 -170 0.266
23 -160 0.385
24 -150 0.527
25 -140 0.671
26 -130 0.764
27 -120 0.838
28 -110 0.763
29 -100 0.838
30 -90 0.903
31 -80 0.904
32 -70 0.898
33 -60 0.862
34 -50 0.717
35 -40 0.337
36 -30 0.154
37 -20 0.253
38 -10 0.125

View File

@ -1,4 +1,5 @@
name,type,is_isotropic name,type,is_isotropic
dummy,NaI,true dummy,NaI,true
LU_NaI_3inch,NaI,true LU_NaI_3inch,NaI,true
LU_HPGe_90,HPGe,false LU_HPGe_90,HPGe,false
LU_NaIR,NaI,false
1 name type is_isotropic
2 dummy NaI true
3 LU_NaI_3inch NaI true
4 LU_HPGe_90 HPGe false
5 LU_NaIR NaI false

View File

@ -0,0 +1,3 @@
energy_keV,field_efficiency_m2
0,0
662,0.0216
1 energy_keV field_efficiency_m2
2 0 0
3 662 0.0216

View File

@ -125,7 +125,7 @@ class ConfigParser:
) )
if ( if (
seed is not None or seed is not None and
(isinstance(seed, int) and seed <= 0) (isinstance(seed, int) and seed <= 0)
): ):
raise InvalidConfigValueError( raise InvalidConfigValueError(

View File

@ -107,7 +107,8 @@ class LandscapeBuilder:
def set_point_sources( def set_point_sources(
self, self,
*sources: AbsolutePointSourceSpec | RelativePointSourceSpec *sources: AbsolutePointSourceSpec | RelativePointSourceSpec,
bounds_check: bool = False
): ):
"""Add one or more point sources to the world. """Add one or more point sources to the world.
@ -148,7 +149,7 @@ class LandscapeBuilder:
# we dont support -x values, but negative y values are possible as # we dont support -x values, but negative y values are possible as
# the path is centered in the y direction. # the path is centered in the y direction.
if not ( if bounds_check and not (
(0 <= pos[0] <= self._size[0]) and (0 <= pos[0] <= self._size[0]) and
(-0.5 * self._size[1] <= pos[1] <= 0.5 * self._size[1]) (-0.5 * self._size[1] <= pos[1] <= 0.5 * self._size[1])
): ):

View File

@ -2,6 +2,7 @@ import argparse
import logging import logging
import sys import sys
from numpy.random import SeedSequence
from pandas.errors import ParserError from pandas.errors import ParserError
from pg_rad.exceptions.exceptions import ( from pg_rad.exceptions.exceptions import (
@ -77,12 +78,22 @@ def main():
gamma_energy_keV: 661 gamma_energy_keV: 661
detector: LU_NaI_3inch detector: LU_NaI_3inch
options:
seed: 1234
""" """
elif args.config: elif args.config:
input_config = args.config input_config = args.config
else:
logger.warning(
"No input provided. Try --example or --config path/to/config.yml. "
)
sys.exit(1)
try: try:
cp = ConfigParser(input_config).parse() cp = ConfigParser(input_config).parse()
if cp.options.seed is None:
entr = SeedSequence().entropy
cp.options.seed = int(str(entr)[:6])
landscape = LandscapeDirector.build_from_config(cp) landscape = LandscapeDirector.build_from_config(cp)
output = SimulationEngine( output = SimulationEngine(
landscape=landscape, landscape=landscape,

View File

@ -109,7 +109,8 @@ def calculate_counts_along_path(
detector: "Detector", detector: "Detector",
velocity: float, velocity: float,
points_per_segment: int = 10, points_per_segment: int = 10,
bkg_cps_input: int | None = None bkg_cps_input: int | None = None,
seed: int | None = None
) -> Tuple[np.ndarray, np.ndarray]: ) -> Tuple[np.ndarray, np.ndarray]:
"""Compute the counts recorded in each acquisition period in the landscape. """Compute the counts recorded in each acquisition period in the landscape.
@ -152,14 +153,16 @@ def calculate_counts_along_path(
if bkg_cps_input is None: if bkg_cps_input is None:
bkg = generate_background( bkg = generate_background(
cps, detector, landscape.point_sources[0].isotope.E cps, detector, landscape.point_sources[0].isotope.E,
seed=seed
) )
elif bkg_cps_input == 0: elif bkg_cps_input == 0:
bkg = bkg_cps_input bkg = bkg_cps_input
else: else:
bkg = generate_background( bkg = generate_background(
cps, detector, landscape.point_sources[0].isotope.E, cps, detector, landscape.point_sources[0].isotope.E,
lam_inp=bkg_cps_input lam_inp=bkg_cps_input,
seed=seed
) )
cps_with_bg = cps + bkg cps_with_bg = cps + bkg

View File

@ -116,6 +116,7 @@ class ResultPlotter:
["Air density (kg/m^3)", round(self.landscape.air_density, 3)], ["Air density (kg/m^3)", round(self.landscape.air_density, 3)],
["Total path length (m)", round(self.landscape.path.length, 3)], ["Total path length (m)", round(self.landscape.path.length, 3)],
["Readout points", len(self.count_rate_res.integrated_counts)], ["Readout points", len(self.count_rate_res.integrated_counts)],
["Seed", self.count_rate_res.seed],
["Mean background cps", round(self.count_rate_res.mean_bkg_cps, 3)] ["Mean background cps", round(self.count_rate_res.mean_bkg_cps, 3)]
] ]

View File

@ -48,7 +48,8 @@ class SimulationEngine:
self.landscape, self.landscape,
self.detector, self.detector,
velocity=self.runtime_spec.speed, velocity=self.runtime_spec.speed,
bkg_cps_input=self.sim_spec.bkg_cps bkg_cps_input=self.sim_spec.bkg_cps,
seed=self.sim_spec.seed
) )
) )
@ -59,7 +60,8 @@ class SimulationEngine:
sub_points, sub_points,
cps, cps,
int_counts, int_counts,
mean_bkg_counts mean_bkg_counts,
self.sim_spec.seed
) )
def _calculate_point_source_distance_to_path(self) -> List[SourceOutput]: def _calculate_point_source_distance_to_path(self) -> List[SourceOutput]:

View File

@ -12,6 +12,7 @@ class CountRateOutput:
cps: List[float] cps: List[float]
integrated_counts: List[float] integrated_counts: List[float]
mean_bkg_cps: List[float] mean_bkg_cps: List[float]
seed: int
@dataclass @dataclass