Browse Source

Combiner update

compton 4 years ago
parent
commit
9b03e509e1
1 changed files with 6 additions and 6 deletions
  1. 6 6
      src/compton_combiner.py

+ 6 - 6
src/compton_combiner.py

@@ -295,7 +295,7 @@ def calculate_point(comb_df: pd.DataFrame, runs_df: pd.DataFrame, compton_df: pd
             'first_run': comb_df.run_first.min(),
             'last_run': comb_df.run_last.max(), 
             'mean_energy': res_df.e_mean.mean(), 
-            'mean_energy_stat_err': np.sqrt(1/np.sum(1/(res_df.e_std)**2)), #res_df.e_std.mean()/np.sqrt(len(res_df)), 
+            'mean_energy_stat_err': np.sqrt(1/np.sum(1/(res_df.e_std)**2)),
             'mean_energy_sys_err': np.abs(comb_df.iloc[0].at['elabel'] - res_df.e_mean.mean()), 
             'mean_spread': res_df.spread_mean.mean(),
             'mean_spread_stat_err':np.sqrt(1/np.sum(1/(res_df.spread_std)**2)),
@@ -383,20 +383,20 @@ def process_combined(combined_df: pd.DataFrame, runs_df: pd.DataFrame, compton_d
             total_error = np.sqrt(res_dict["mean_energy_stat_err"]**2 + res_dict["mean_energy_sys_err"]**2)
             half_timedelta = (plt_table.compton_stop - plt_table.compton_start)/2 
             time = plt_table.compton_start + half_timedelta
-            dlt0 = timedelta(days=1)
+            dlt0, total_time = timedelta(days=1), plt_table.compton_stop.max() - plt_table.compton_stop.min()
+            timelim = [plt_table.compton_stop.min() - 0.05*total_time, plt_table.compton_stop.max() + 0.05*total_time]
             
             fig, ax = plt.subplots(1, 1, dpi=120, tight_layout=True)
             ax.errorbar(time, plt_table.e_mean, xerr=half_timedelta, yerr=plt_table.e_std, fmt='.')
             ax.axhline(res_dict['mean_energy'], color='black', zorder=3, label='Mean')
-            ax.fill_between([plt_table.compton_stop.min(), plt_table.compton_stop.max()], 
+            ax.fill_between(timelim, 
                             [res_dict['mean_energy'] - total_error]*2, 
                             [res_dict['mean_energy'] + total_error]*2, color='green', zorder=1, alpha=0.4)
             ax.tick_params(axis='x', labelrotation=45)
             ax.xaxis.set_major_locator(locator)
             ax.xaxis.set_major_formatter(formatter)
-            ax.set(title=f'{res_dict["energy_point"]}, E = {res_dict["mean_energy"]:.3f} ± {res_dict["mean_energy_stat_err"]:.3f} ± {res_dict["mean_energy_sys_err"]:.3f} MeV', xlabel='Time, NSK', ylabel='Energy, [MeV]', 
-                   xlim=[plt_table.compton_stop.min(), plt_table.compton_stop.max()])
-            plt.savefig(f'{pics_folder}/{res_dict["first_run"]}_{res_dict["energy_point"]}.png')
+            ax.set(title=f'{res_dict["energy_point"]}, E = {res_dict["mean_energy"]:.3f} ± {res_dict["mean_energy_stat_err"]:.3f} ± {res_dict["mean_energy_sys_err"]:.3f} MeV', xlabel='Time, NSK', ylabel='Energy, [MeV]', xlim=timelim)
+            plt.savefig(f'{pics_folder}/{res_dict["first_run"]}_{res_dict["energy_point"]}.png', transparent=True)
             plt.close()
     
     return result_df