Skip to content

Commit

Permalink
Add method.
Browse files Browse the repository at this point in the history
  • Loading branch information
tymorrow committed Nov 14, 2023
1 parent 78ec3af commit 4c4727f
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion riid/data/sampleset.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,9 @@ def _check_target_level(self, target_level,

def all_spectra_sum_to_one(self, rtol: float = 0.0, atol: float = 1e-4) -> bool:
"""Checks if all spectra are normalized to sum to one."""
return np.all(np.isclose(self.spectra.sum(axis=1).values, 1, rtol=rtol, atol=atol))
spectra_counts = self.spectra.sum(axis=1).values
all_sum_to_one = np.all(np.isclose(spectra_counts, 1, rtol=rtol, atol=atol))
return all_sum_to_one

def as_ecal(self, new_offset: float, new_gain: float,
new_quadratic: float, new_cubic: float,
Expand Down Expand Up @@ -581,6 +583,28 @@ def as_ecal(self, new_offset: float, new_gain: float,
new_ss.info[ecal_cols] = new_ecal
return new_ss

def check_seeds(self):
"""Checks health of all spectra and info assuming they are seeds.
Invalidate states for which we currently check:
- Spectra do not sum to 1
- 100% dead time
Raises:
AssertionError: when any check fails
"""
live_times = self.info.live_time.values
real_times = self.info.real_time.values
dead_time_props = (1.0 - live_times / real_times)
dead_time_props = np.nan_to_num(dead_time_props, nan=1.0)
dead = dead_time_props >= 1.0
all_spectra_are_alive = not np.any(dead)
assert all_spectra_are_alive

all_spectra_sum_to_one = self.all_spectra_sum_to_one()
assert all_spectra_sum_to_one

def clip_negatives(self, min_value: float = 0):
"""Clip spectrum values to some minimum value.
Expand Down

0 comments on commit 4c4727f

Please sign in to comment.