Skip to content

Commit

Permalink
Add checks to decay
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexHls committed Nov 1, 2023
1 parent ac6cd34 commit 2a4c3d8
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion tardis/io/decay.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
from radioactivedecay import Nuclide, Inventory
from radioactivedecay.utils import Z_to_elem
from astropy import units as u
import logging

logger = logging.getLogger(__name__)

class IsotopeAbundances(pd.DataFrame):

class IsotopeAbundances(pd.DataFrame):
_metadata = ["time_0"]

def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -92,9 +94,18 @@ def decay(self, t):
t_second = (
u.Quantity(t, u.day).to(u.s).value - self.time_0.to(u.s).value
)
logger.info(f"Decaying abundances for {t_second} seconds")
if t_second < 0:
logger.warning(
f"Decay time {t_second} is negative. This could indicate a miss-specified input model."
f" A negative decay time can potentially lead to negative abundances."
)
decayed_inventories = [item.decay(t_second) for item in inventories]
df = IsotopeAbundances.from_inventories(decayed_inventories)
df.sort_index(inplace=True)
assert (
df.gt(0).all().all()
), "Negative abundances detected. Please make sure your input abundances are correct."
return df

def as_atoms(self):
Expand Down

0 comments on commit 2a4c3d8

Please sign in to comment.