From ec4bf6cbe653362217b67f3cd46fea1ca0afd563 Mon Sep 17 00:00:00 2001 From: Pim Nelissen Date: Thu, 23 Apr 2026 16:02:29 +0200 Subject: [PATCH 1/5] add NaIR detector (isotropic) --- src/pg_rad/data/detectors.csv | 3 ++- src/pg_rad/data/field_efficiencies/LU_NaIR.csv | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 src/pg_rad/data/field_efficiencies/LU_NaIR.csv diff --git a/src/pg_rad/data/detectors.csv b/src/pg_rad/data/detectors.csv index f5ae726..081a17d 100644 --- a/src/pg_rad/data/detectors.csv +++ b/src/pg_rad/data/detectors.csv @@ -1,4 +1,5 @@ name,type,is_isotropic dummy,NaI,true LU_NaI_3inch,NaI,true -LU_HPGe_90,HPGe,false \ No newline at end of file +LU_HPGe_90,HPGe,false +LU_NaIR,NaI,true \ No newline at end of file diff --git a/src/pg_rad/data/field_efficiencies/LU_NaIR.csv b/src/pg_rad/data/field_efficiencies/LU_NaIR.csv new file mode 100644 index 0000000..f5bbea2 --- /dev/null +++ b/src/pg_rad/data/field_efficiencies/LU_NaIR.csv @@ -0,0 +1,3 @@ +energy_keV,field_efficiency_m2 +0,0 +662,0.0216 \ No newline at end of file From 2dd6ab6beb08a9532db0347e782293dae75076e3 Mon Sep 17 00:00:00 2001 From: Pim Nelissen Date: Thu, 23 Apr 2026 16:05:20 +0200 Subject: [PATCH 2/5] add angular dependence NaIR --- .../data/angular_efficiencies/LU_NaIR.csv | 38 +++++++++++++++++++ src/pg_rad/data/detectors.csv | 2 +- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 src/pg_rad/data/angular_efficiencies/LU_NaIR.csv diff --git a/src/pg_rad/data/angular_efficiencies/LU_NaIR.csv b/src/pg_rad/data/angular_efficiencies/LU_NaIR.csv new file mode 100644 index 0000000..25eb2eb --- /dev/null +++ b/src/pg_rad/data/angular_efficiencies/LU_NaIR.csv @@ -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 \ No newline at end of file diff --git a/src/pg_rad/data/detectors.csv b/src/pg_rad/data/detectors.csv index 081a17d..47662df 100644 --- a/src/pg_rad/data/detectors.csv +++ b/src/pg_rad/data/detectors.csv @@ -2,4 +2,4 @@ name,type,is_isotropic dummy,NaI,true LU_NaI_3inch,NaI,true LU_HPGe_90,HPGe,false -LU_NaIR,NaI,true \ No newline at end of file +LU_NaIR,NaI,false \ No newline at end of file From 372082f19b08ae7259516a65d12d19aab2dcff5d Mon Sep 17 00:00:00 2001 From: Pim Nelissen Date: Sun, 3 May 2026 15:58:38 +0200 Subject: [PATCH 3/5] add bounds_check optional flag (default false) --- src/pg_rad/landscape/builder.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pg_rad/landscape/builder.py b/src/pg_rad/landscape/builder.py index 78ef1cf..2ea096e 100644 --- a/src/pg_rad/landscape/builder.py +++ b/src/pg_rad/landscape/builder.py @@ -107,7 +107,8 @@ class LandscapeBuilder: def set_point_sources( self, - *sources: AbsolutePointSourceSpec | RelativePointSourceSpec + *sources: AbsolutePointSourceSpec | RelativePointSourceSpec, + bounds_check: bool = False ): """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 # the path is centered in the y direction. - if not ( + if bounds_check and not ( (0 <= pos[0] <= self._size[0]) and (-0.5 * self._size[1] <= pos[1] <= 0.5 * self._size[1]) ): From 40b09971ff3b4b50415de4a30acb9f67a8f8ed1a Mon Sep 17 00:00:00 2001 From: Pim Nelissen Date: Sun, 3 May 2026 17:29:53 +0200 Subject: [PATCH 4/5] pass global seed onto fluence and background --- src/pg_rad/background/background.py | 5 +++-- src/pg_rad/inputparser/parser.py | 2 +- src/pg_rad/main.py | 7 +++++++ src/pg_rad/physics/fluence.py | 9 ++++++--- src/pg_rad/plotting/result_plotter.py | 1 + src/pg_rad/simulator/engine.py | 6 ++++-- src/pg_rad/simulator/outputs.py | 1 + 7 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/pg_rad/background/background.py b/src/pg_rad/background/background.py index a7cfa5c..facbadf 100644 --- a/src/pg_rad/background/background.py +++ b/src/pg_rad/background/background.py @@ -11,7 +11,8 @@ def generate_background( cps_array: np.ndarray, detector: Detector, energy_keV: float, - lam_inp: int | None = None + lam_inp: int | None = None, + seed: int | None = None ) -> np.ndarray: """ @@ -23,7 +24,7 @@ def generate_background( else: lam = lam_inp - rng = np.random.default_rng() + rng = np.random.default_rng(seed=seed) return rng.poisson(lam=lam, size=cps_array.shape) diff --git a/src/pg_rad/inputparser/parser.py b/src/pg_rad/inputparser/parser.py index aea77e7..159a69f 100644 --- a/src/pg_rad/inputparser/parser.py +++ b/src/pg_rad/inputparser/parser.py @@ -125,7 +125,7 @@ class ConfigParser: ) if ( - seed is not None or + seed is not None and (isinstance(seed, int) and seed <= 0) ): raise InvalidConfigValueError( diff --git a/src/pg_rad/main.py b/src/pg_rad/main.py index f83be0f..7fb3725 100644 --- a/src/pg_rad/main.py +++ b/src/pg_rad/main.py @@ -2,6 +2,7 @@ import argparse import logging import sys +from numpy.random import SeedSequence from pandas.errors import ParserError from pg_rad.exceptions.exceptions import ( @@ -77,12 +78,18 @@ def main(): gamma_energy_keV: 661 detector: LU_NaI_3inch + + options: + seed: 1234 """ elif args.config: input_config = args.config try: 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) output = SimulationEngine( landscape=landscape, diff --git a/src/pg_rad/physics/fluence.py b/src/pg_rad/physics/fluence.py index 7bc04dc..ae37b3b 100644 --- a/src/pg_rad/physics/fluence.py +++ b/src/pg_rad/physics/fluence.py @@ -109,7 +109,8 @@ def calculate_counts_along_path( detector: "Detector", velocity: float, 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]: """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: 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: bkg = bkg_cps_input else: bkg = generate_background( 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 diff --git a/src/pg_rad/plotting/result_plotter.py b/src/pg_rad/plotting/result_plotter.py index ad595f2..5a76e42 100644 --- a/src/pg_rad/plotting/result_plotter.py +++ b/src/pg_rad/plotting/result_plotter.py @@ -116,6 +116,7 @@ class ResultPlotter: ["Air density (kg/m^3)", round(self.landscape.air_density, 3)], ["Total path length (m)", round(self.landscape.path.length, 3)], ["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)] ] diff --git a/src/pg_rad/simulator/engine.py b/src/pg_rad/simulator/engine.py index c37cc8d..634ff64 100644 --- a/src/pg_rad/simulator/engine.py +++ b/src/pg_rad/simulator/engine.py @@ -48,7 +48,8 @@ class SimulationEngine: self.landscape, self.detector, 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, cps, int_counts, - mean_bkg_counts + mean_bkg_counts, + self.sim_spec.seed ) def _calculate_point_source_distance_to_path(self) -> List[SourceOutput]: diff --git a/src/pg_rad/simulator/outputs.py b/src/pg_rad/simulator/outputs.py index 7ec364b..1822ebe 100644 --- a/src/pg_rad/simulator/outputs.py +++ b/src/pg_rad/simulator/outputs.py @@ -12,6 +12,7 @@ class CountRateOutput: cps: List[float] integrated_counts: List[float] mean_bkg_cps: List[float] + seed: int @dataclass From 54ae0c4c0d719ca04a81371f79cee60ce14cc1a7 Mon Sep 17 00:00:00 2001 From: Pim Nelissen Date: Sun, 3 May 2026 17:38:09 +0200 Subject: [PATCH 5/5] fix #61 --- src/pg_rad/main.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/pg_rad/main.py b/src/pg_rad/main.py index 7fb3725..b74fb4e 100644 --- a/src/pg_rad/main.py +++ b/src/pg_rad/main.py @@ -84,7 +84,11 @@ def main(): """ elif args.config: input_config = args.config - + else: + logger.warning( + "No input provided. Try --example or --config path/to/config.yml. " + ) + sys.exit(1) try: cp = ConfigParser(input_config).parse() if cp.options.seed is None: