Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
spm returns np array when it fails, spm bounds and ftol were changed
Browse files Browse the repository at this point in the history
  • Loading branch information
ignacioreyes committed Jun 1, 2021
1 parent c9256a6 commit 082dd71
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions lc_classifier/features/extractors/sn_parametric_model_computer.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def fit(self, times, targets, obs_errors):
[A_bounds[1], t0_bounds[1], gamma_bounds[1], beta_bounds[1], trise_bounds[1], tfall_bounds[1]]],
ftol=A_guess / 3.)
except (ValueError, RuntimeError, OptimizeWarning):
pout = [np.nan, np.nan, np.nan, np.nan, np.nan, np.nan]
pout = np.array([np.nan, np.nan, np.nan, np.nan, np.nan, np.nan])

self.parameters = pout
predictions = model_inference(
Expand Down Expand Up @@ -122,11 +122,11 @@ def fit(self, times, fluxpsf, obs_errors):
argmax_fluxpsf = np.argmax(fluxpsf)
max_fluxpsf = fluxpsf[argmax_fluxpsf]
A_bounds = [max_fluxpsf / 3.0, max_fluxpsf * 3.0]
t0_bounds = [-50.0, 50.0]
t0_bounds = [-50.0, 70.0]
gamma_bounds = [1.0, 100.0]
beta_bounds = [0.0, 1.0]
trise_bounds = [1.0, 100.0]
tfall_bounds = [1.0, 100.0]
tfall_bounds = [1.0, 180.0]

# Parameter guess
A_guess = np.clip(1.2 * max_fluxpsf, A_bounds[0], A_bounds[1])
Expand All @@ -150,10 +150,12 @@ def fit(self, times, fluxpsf, obs_errors):
sigma=5+obs_errors,
bounds=[[A_bounds[0], t0_bounds[0], gamma_bounds[0], beta_bounds[0], trise_bounds[0], tfall_bounds[0]],
[A_bounds[1], t0_bounds[1], gamma_bounds[1], beta_bounds[1], trise_bounds[1], tfall_bounds[1]]],
ftol=0.01
ftol=1e-8,
# verbose=2
)
except (ValueError, RuntimeError, OptimizeWarning):
try:
logging.info('First fit of SPM failed. Attempting second fit.')
pout, pcov = curve_fit(
f=model_inference,
xdata=times,
Expand All @@ -162,9 +164,12 @@ def fit(self, times, fluxpsf, obs_errors):
sigma=5+obs_errors,
bounds=[[A_bounds[0], t0_bounds[0], gamma_bounds[0], beta_bounds[0], trise_bounds[0], tfall_bounds[0]],
[A_bounds[1], t0_bounds[1], gamma_bounds[1], beta_bounds[1], trise_bounds[1], tfall_bounds[1]]],
ftol=0.1)
ftol=0.1,
# verbose=2
)
except (ValueError, RuntimeError, OptimizeWarning):
pout = [np.nan, np.nan, np.nan, np.nan, np.nan, np.nan]
logging.info('Two fits of SPM failed. Returning NaN.')
pout = np.array([np.nan, np.nan, np.nan, np.nan, np.nan, np.nan])

self.parameters = pout
predictions = model_inference(
Expand Down

0 comments on commit 082dd71

Please sign in to comment.