Skip to content

Commit 8c365f7

Browse files
committed
Include nearly all seed info post-synthesis.
1 parent 64758c0 commit 8c365f7

File tree

3 files changed

+26
-60
lines changed

3 files changed

+26
-60
lines changed

riid/data/synthetic/base.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
_get_utc_timestamp)
1515

1616

17+
IGNORED_INFO_COLS = ["snr", "live_time", "real_time", "total_counts", "timestamp"]
18+
19+
1720
class Synthesizer():
1821
"""Base class for synthesizers."""
1922

@@ -159,12 +162,9 @@ def _get_minimal_ss(spectra, sources, live_times, snrs, total_counts=None) -> Sa
159162
ss.spectra_state = SpectraState.Counts
160163
ss.spectra = pd.DataFrame(spectra)
161164
ss.sources = sources
162-
ss.info.description = np.full(n_samples, "") # Ensures the length of info equal n_samples
163165
ss.info.snr = snrs
164166
ss.info.total_counts = total_counts if total_counts is not None else spectra.sum(axis=1)
165167
ss.info.live_time = live_times
166-
ss.info.occupancy_flag = 0
167-
ss.info.tag = " " # TODO: test if this can be an empty string
168168

169169
return ss
170170

@@ -259,3 +259,17 @@ def get_samples_per_seed(columns: pd.MultiIndex, min_samples_per_seed: int, bala
259259
total_samples_expected = sum([x * y for x, y in zip(occurences, samples_per_level_value)])
260260

261261
return lv_to_samples_per_seed, total_samples_expected
262+
263+
264+
def set_ss_info_from_seed_info(ss: SampleSet, info: pd.Series, timestamp: str,
265+
ignored_cols=IGNORED_INFO_COLS):
266+
if ss is None:
267+
return
268+
269+
info_indices_to_set = info.index.difference(ignored_cols)
270+
info_to_set = info[info_indices_to_set]
271+
for c, v in info_to_set.items():
272+
ss.info[c] = v
273+
274+
ss.info.real_time = ss.info.live_time / (1 - info.dead_time_prop)
275+
ss.info.timestamp = timestamp

riid/data/synthetic/passby.py

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
from numpy.random import Generator
1313

1414
from riid import SampleSet
15-
from riid.data.synthetic.base import Synthesizer, get_distribution_values
15+
from riid.data.synthetic.base import (Synthesizer, get_distribution_values,
16+
set_ss_info_from_seed_info)
1617

1718

1819
class PassbySynthesizer(Synthesizer):
@@ -282,45 +283,16 @@ def generate(self, fg_seeds_ss: SampleSet, bg_seeds_ss: SampleSet,
282283
fg_sources, bg_sources)
283284
args.append(pb_args)
284285

285-
# TODO: follow prevents periodic progress reports
286+
# TODO: the following prevents periodic progress reports
286287
passbys = []
287288
for a in args:
288289
f, fwhm, snr, dwell_time, fg_pmf, bg_pmf, fg_sources, bg_sources = a
289290
fg_passby_ss, gross_passby_ss = self._generate_single_passby(
290291
fwhm, snr, dwell_time, fg_pmf, bg_pmf, fg_sources, bg_sources
291292
)
292-
live_times = None
293-
if fg_passby_ss is not None:
294-
live_times = fg_passby_ss.info.live_time
295-
elif gross_passby_ss is not None:
296-
live_times = gross_passby_ss.info.live_time
297-
else:
298-
live_times = 1.0
299-
300-
fg_seed_ecal = fg_seeds_ss.ecal[f]
301293
fg_seed_info = fg_seeds_ss.info.iloc[f]
302-
batch_rt_targets = live_times * (1 - fg_seed_info.dead_time_prop)
303-
fg_seed_distance_cm = fg_seed_info.distance_cm
304-
fg_seed_dead_time_prop = fg_seed_info.dead_time_prop
305-
fg_seed_ad = fg_seed_info.areal_density
306-
fg_seed_an = fg_seed_info.atomic_number
307-
fg_seed_neutron_counts = fg_seed_info.neutron_counts
308-
309-
def _set_remaining_info(ss):
310-
if ss is None:
311-
return
312-
ss: SampleSet = ss
313-
ss.ecal = fg_seed_ecal
314-
ss.info.real_time = batch_rt_targets
315-
ss.info.distance_cm = fg_seed_distance_cm
316-
ss.info.dead_time_prop = fg_seed_dead_time_prop
317-
ss.info.areal_density = fg_seed_ad
318-
ss.info.atomic_number = fg_seed_an
319-
ss.info.neutron_counts = fg_seed_neutron_counts
320-
ss.info.timestamp = self._synthesis_start_dt
321-
322-
_set_remaining_info(fg_passby_ss)
323-
_set_remaining_info(gross_passby_ss)
294+
set_ss_info_from_seed_info(fg_passby_ss, fg_seed_info, self._synthesis_start_dt)
295+
set_ss_info_from_seed_info(gross_passby_ss, fg_seed_info, self._synthesis_start_dt)
324296

325297
passbys.append((fg_passby_ss, gross_passby_ss))
326298

riid/data/synthetic/static.py

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
from numpy.random import Generator
1212

1313
from riid import SampleSet, SpectraState, SpectraType
14-
from riid.data.synthetic.base import Synthesizer, get_distribution_values
14+
from riid.data.synthetic.base import (Synthesizer, get_distribution_values,
15+
set_ss_info_from_seed_info)
1516

1617

1718
class StaticSynthesizer(Synthesizer):
@@ -190,30 +191,9 @@ def _get_synthetic_samples(self, fg_seeds_ss: SampleSet, bg_seeds_ss: SampleSet,
190191
batch_snr_targets
191192
)
192193

193-
fg_seed_ecal = fg_seeds_ss.ecal[f]
194194
fg_seed_info = fg_seeds_ss.info.iloc[f]
195-
batch_rt_targets = batch_lt_targets / (1 - fg_seed_info.dead_time_prop)
196-
fg_seed_distance_cm = fg_seed_info.distance_cm
197-
fg_seed_dead_time_prop = fg_seed_info.dead_time_prop
198-
fg_seed_ad = fg_seed_info.areal_density
199-
fg_seed_an = fg_seed_info.atomic_number
200-
fg_seed_neutron_counts = fg_seed_info.neutron_counts
201-
202-
def _set_remaining_info(ss):
203-
if ss is None:
204-
return
205-
ss: SampleSet = ss
206-
ss.ecal = fg_seed_ecal
207-
ss.info.real_time = batch_rt_targets
208-
ss.info.distance_cm = fg_seed_distance_cm
209-
ss.info.dead_time_prop = fg_seed_dead_time_prop
210-
ss.info.areal_density = fg_seed_ad
211-
ss.info.atomic_number = fg_seed_an
212-
ss.info.neutron_counts = fg_seed_neutron_counts
213-
ss.info.timestamp = self._synthesis_start_dt
214-
215-
_set_remaining_info(fg_batch_ss)
216-
_set_remaining_info(gross_batch_ss)
195+
set_ss_info_from_seed_info(fg_batch_ss, fg_seed_info, self._synthesis_start_dt)
196+
set_ss_info_from_seed_info(gross_batch_ss, fg_seed_info, self._synthesis_start_dt)
217197

218198
fg_ss_batches.append(fg_batch_ss)
219199
gross_ss_batches.append(gross_batch_ss)

0 commit comments

Comments
 (0)