From 0e438eed03ab1b8e91b69146a687f25fb8999724 Mon Sep 17 00:00:00 2001 From: Peter Yoachim Date: Tue, 2 Apr 2024 17:06:19 -0700 Subject: [PATCH 1/3] fix future warning --- rubin_sim/maf/batches/science_radar_batch.py | 2 +- rubin_sim/maf/run_comparison/gather_summaries.py | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/rubin_sim/maf/batches/science_radar_batch.py b/rubin_sim/maf/batches/science_radar_batch.py index 6865ae401..8ac40867b 100644 --- a/rubin_sim/maf/batches/science_radar_batch.py +++ b/rubin_sim/maf/batches/science_radar_batch.py @@ -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) diff --git a/rubin_sim/maf/run_comparison/gather_summaries.py b/rubin_sim/maf/run_comparison/gather_summaries.py index d20198246..ec89137c4 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 From 6e1bd7a7174ada7372860f91d272e5ce2125f0c1 Mon Sep 17 00:00:00 2001 From: Peter Yoachim Date: Wed, 3 Apr 2024 16:22:26 -0700 Subject: [PATCH 2/3] revert XRB metric to previous default value --- rubin_sim/maf/maf_contrib/xrb_metrics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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, From f78b626b45c43d752d8229a6e00d29cfb8284323 Mon Sep 17 00:00:00 2001 From: Peter Yoachim Date: Thu, 4 Apr 2024 13:59:01 -0700 Subject: [PATCH 3/3] fix if periodic star does not have enough data points to fit --- rubin_sim/maf/batches/science_radar_batch.py | 2 +- .../periodic_star_modulation_metric.py | 32 +++++++++++-------- .../maf/run_comparison/gather_summaries.py | 2 +- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/rubin_sim/maf/batches/science_radar_batch.py b/rubin_sim/maf/batches/science_radar_batch.py index 8ac40867b..6865ae401 100644 --- a/rubin_sim/maf/batches/science_radar_batch.py +++ b/rubin_sim/maf/batches/science_radar_batch.py @@ -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) 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/run_comparison/gather_summaries.py b/rubin_sim/maf/run_comparison/gather_summaries.py index ec89137c4..027d61a44 100755 --- a/rubin_sim/maf/run_comparison/gather_summaries.py +++ b/rubin_sim/maf/run_comparison/gather_summaries.py @@ -72,7 +72,7 @@ def combine_result_dbs(run_dirs, dbfilename="resultsDb_sqlite.db"): index=[row_name], ) - # Can have duplicate columns if MAF was run multiple times. + # Can have duplicate columns if MAF was run multiple times. # Remove duplicates: # https://stackoverflow.com/questions/14984119/ # python-pandas-remove-duplicate-columns