mirror of
https://github.com/pim-n/pg-rad
synced 2026-06-17 15:59:35 +02:00
pass global seed onto fluence and background
This commit is contained in:
@ -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)
|
||||
|
||||
|
||||
|
||||
@ -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(
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)]
|
||||
]
|
||||
|
||||
|
||||
@ -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]:
|
||||
|
||||
@ -12,6 +12,7 @@ class CountRateOutput:
|
||||
cps: List[float]
|
||||
integrated_counts: List[float]
|
||||
mean_bkg_cps: List[float]
|
||||
seed: int
|
||||
|
||||
|
||||
@dataclass
|
||||
|
||||
Reference in New Issue
Block a user