Skip to content

Commit

Permalink
set the values in np.clip() from [-100,100] to [-10,10] to help with …
Browse files Browse the repository at this point in the history
…numerical issues with large logsfr_ratio jumps that were causing the returned SFHs to contain nans
  • Loading branch information
davidjsetton committed Dec 12, 2023
1 parent 6583fd0 commit 364d0c0
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions prospect/models/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def logsfr_ratios_to_masses(logmass=None, logsfr_ratios=None, agebins=None,
time.
"""
nbins = agebins.shape[0]
sratios = 10**np.clip(logsfr_ratios, -100, 100) # numerical issues...
sratios = 10**np.clip(logsfr_ratios, -10, 10) # numerical issues...
dt = (10**agebins[:, 1] - 10**agebins[:, 0])
coeffs = np.array([ (1. / np.prod(sratios[:i])) * (np.prod(dt[1: i+1]) / np.prod(dt[: i]))
for i in range(nbins)])
Expand All @@ -209,8 +209,8 @@ def logsfr_ratios_to_sfrs(logmass=None, logsfr_ratios=None, agebins=None, **extr
def logsfr_ratios_to_masses_flex(logmass=None, logsfr_ratios=None,
logsfr_ratio_young=None, logsfr_ratio_old=None,
**extras):
logsfr_ratio_young = np.clip(logsfr_ratio_young, -100, 100)
logsfr_ratio_old = np.clip(logsfr_ratio_old, -100, 100)
logsfr_ratio_young = np.clip(logsfr_ratio_young, -10, 10)
logsfr_ratio_old = np.clip(logsfr_ratio_old, -10, 10)

abins = logsfr_ratios_to_agebins(logsfr_ratios=logsfr_ratios, **extras)

Expand All @@ -236,7 +236,7 @@ def logsfr_ratios_to_agebins(logsfr_ratios=None, agebins=None, **extras):
"""

# numerical stability
logsfr_ratios = np.clip(logsfr_ratios, -100, 100)
logsfr_ratios = np.clip(logsfr_ratios, -10, 10)

# calculate delta(t) for oldest, youngest bins (fixed)
lower_time = (10**agebins[0, 1] - 10**agebins[0, 0])
Expand Down

0 comments on commit 364d0c0

Please sign in to comment.