diff --git a/rubin_sim/maf/maf_contrib/periodic_star_modulation_metric.py b/rubin_sim/maf/maf_contrib/periodic_star_modulation_metric.py index b3c18d6ba..af92e052a 100644 --- a/rubin_sim/maf/maf_contrib/periodic_star_modulation_metric.py +++ b/rubin_sim/maf/maf_contrib/periodic_star_modulation_metric.py @@ -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 diff --git a/rubin_sim/maf/maf_contrib/xrb_metrics.py b/rubin_sim/maf/maf_contrib/xrb_metrics.py index 80428497f..c4786137f 100644 --- a/rubin_sim/maf/maf_contrib/xrb_metrics.py +++ b/rubin_sim/maf/maf_contrib/xrb_metrics.py @@ -290,7 +290,7 @@ def __init__( night_col="night", pts_needed=2, pts_early=2, - t_early=2, + t_early=7, mjd0=None, output_lc=False, badval=-666, diff --git a/rubin_sim/maf/run_comparison/gather_summaries.py b/rubin_sim/maf/run_comparison/gather_summaries.py index d20198246..027d61a44 100755 --- a/rubin_sim/maf/run_comparison/gather_summaries.py +++ b/rubin_sim/maf/run_comparison/gather_summaries.py @@ -36,9 +36,9 @@ def combine_result_dbs(run_dirs, dbfilename="resultsDb_sqlite.db"): run_names.append(dirname_to_runname(dname)) # querry to grab all the summary stats - sql_q = "SELECT metrics.metric_name, metrics.metric_info_label, " - sql_q += "metrics.slicer_name, summarystats.summary_name, " - sql_q += "summarystats.summary_value " + sql_q = "SELECT summarystats.summary_value, " + sql_q += "metrics.metric_name, metrics.metric_info_label, " + sql_q += "metrics.slicer_name, summarystats.summary_name " sql_q += "FROM summarystats INNER JOIN metrics ON metrics.metric_id=summarystats.metric_id" rows = [] @@ -71,6 +71,13 @@ def combine_result_dbs(run_dirs, dbfilename="resultsDb_sqlite.db"): columns=col_names, index=[row_name], ) + + # Can have duplicate columns if MAF was run multiple times. + # Remove duplicates: + # https://stackoverflow.com/questions/14984119/ + # python-pandas-remove-duplicate-columns + row = row.loc[:, ~row.columns.duplicated()].copy() + rows.append(row) # Create final large DataFrame to hold everything all_cols = np.unique(np.concatenate([r.columns.values for r in rows])) @@ -83,7 +90,8 @@ def combine_result_dbs(run_dirs, dbfilename="resultsDb_sqlite.db"): # Put each row into the final DataFrame for row_name, row in zip(run_names, rows): - result_df.loc[row_name][row.columns] = np.ravel(row.values) + result_df.loc[row_name, row.columns] = np.ravel(row.values) + return result_df