Skip to content

Commit

Permalink
fix if periodic star does not have enough data points to fit
Browse files Browse the repository at this point in the history
  • Loading branch information
yoachim committed Apr 4, 2024
1 parent 6e1bd7a commit 38dcbe8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion rubin_sim/maf/batches/science_radar_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,7 @@ def science_radar_batch(
summary_metrics=summaryStats,
info_label=f"dm {dM} interval {time_interval} RRc Year 1-2",
)
#bundleList.append(bundle)
bundleList.append(bundle)

# PulsatingStarRecovery metric (to be added; Marcella)

Expand Down
32 changes: 18 additions & 14 deletions rubin_sim/maf/maf_contrib/periodic_star_modulation_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,20 +187,24 @@ def run(self, data_slice, slice_point=None):
noise = np.random.randn(true_lc.size) * dmag
# Suppress warnings about failing on covariance
fit_obj = PeriodicStar(t_subrun["filter"])
with warnings.catch_warnings():
warnings.simplefilter("ignore")
# If it fails to converge,
# save values that should fail later
try:
parm_vals, pcov = curve_fit(
fit_obj,
t_subrun["time"],
true_lc + noise,
p0=true_params,
sigma=dmag,
)
except RuntimeError:
parm_vals = true_params * 0 + np.inf
# check if we have enough points
if np.size(true_params) >= np.size(fit_obj):
parm_vals = true_params * 0 + np.inf
else:
with warnings.catch_warnings():
warnings.simplefilter("ignore")
# If it fails to converge,
# save values that should fail later
try:
parm_vals, pcov = curve_fit(
fit_obj,
t_subrun["time"],
true_lc + noise,
p0=true_params,
sigma=dmag,
)
except RuntimeError:
parm_vals = true_params * 0 + np.inf
fits[i, :] = parm_vals

# Throw out any magnitude fits if there are no
Expand Down

0 comments on commit 38dcbe8

Please sign in to comment.