tracker, force_gap=gap, force_streaker_offset=streaker_offset) #tracker.quad_wake = False sim_screens = fprop_dict['sim_screens'] #self.plot_streaker_calib() meas_screens = self.get_meas_screens() offsets = self.offsets rms_sim = np.zeros(len(offsets)) centroid_sim = rms_sim.copy() for n_proj, (_meas_screen, sim_screen, offset) in enumerate(zip(meas_screens, sim_screens, offsets)): color = ms.colorprog(n_proj, offsets) _meas_screen.plot_standard(sp_proj, label='%.2f mm' % (offset * 1e3), color=color) sim_screen.plot_standard(sp_proj, color=color, ls='--') centroid_sim[n_proj] = sim_screen.mean() rms_sim[n_proj] = sim_screen.rms() opt_values[gap_ctr] += _meas_screen.compare(sim_screen) nonzero = offsets != 0 distance_arr = gap / 2. - np.abs(self.offsets - streaker_offset) xx_plot = distance_arr[nonzero] * 1e6 sort = np.argsort(xx_plot) xx_plot = xx_plot[sort] xx_plot -= xx_plot.min()
sp.tick_params(axis='y', labelsize=fs_label) for sp in bpm_sp_dict2.values(): sp.set_xlim(-5, 5) sp.set_ylim(-0.2, 0.2) offset_arr = np.array(offset_list) * 1e3 ms.figure('Summary') subplot = ms.subplot_factory(1, 1) sp = subplot(1, title='Summary', xlabel='Gap', ylabel='Structure offset fit [$\mu$m]') labelled_ctrs = set() for gap, offset, bpm, bpm_ctr in zip(gap_list, offset_arr, bpm_plot_list, bpm_plot_ctr_list): if bpm_ctr not in labelled_ctrs: label = bpm labelled_ctrs.add(bpm_ctr) else: label = None sp.scatter(gap, offset, color=ms.colorprog(bpm_ctr, bpm_list), label=label) sp.axhline(offset_arr.mean(), color='black', ls='--') sp.legend() ms.saveall('/tmp/offset_for_paper', ending='.pdf') plt.show()
sp_ctr = 1 sp_screen = subplot(sp_ctr, title='Measured projections', xlabel='x (mm)', ylabel='Intensity (arb. units)') sp_ctr += 1 sp_profile = subplot(sp_ctr, title='Reconstructed profiles', xlabel='x (mm)', ylabel='I (kA)') sp_ctr += 1 rms_list = [] for ctr, output_dict in enumerate(output_dicts): color = ms.colorprog(ctr, output_dicts) gauss_dict = output_dict['gauss_dict'] gauss_dict['meas_screen'].plot_standard(sp_screen) profile = gauss_dict['reconstructed_profile'] rms_list.append(profile.rms()) profile.plot_standard(sp_profile, center='Mean', label='%.1f fs' % (rms_list[-1] * 1e15)) rms_index = np.argsort(rms_list)[len(rms_list) // 2] gauss_dict = output_dicts[rms_index]['gauss_dict'] gauss_dict['meas_screen'].plot_standard(sp_screen, color='red', lw=3) profile = gauss_dict['reconstructed_profile'] label = '%.1f fs' % (rms_list[rms_index] * 1e15)
for gap_ctr, gap in enumerate(gap_arr): sc.gap0 = gap sc.fit() streaker_offset = sc.fit_dicts_gap_order['centroid'][sc.fit_gap][sc.fit_order]['streaker_offset'] offset_list, gauss_dicts = sc.reconstruct_current(tracker, gauss_kwargs, plot_details=False) distance_arr = gap/2. - np.abs(offset_list) sc.plot_reconstruction(blmeas_profile=blmeas_profile, figsize=(20, 12)) ms.plt.suptitle('%.3f' % (gap*1e3)) print('%i out of %i done' % (gap_ctr+1, len(gap_arr))) rms_arr = np.array([x['reconstructed_profile'].rms() for x in gauss_dicts]) all_rms_arr[gap_ctr] = rms_arr d_arr2 = distance_arr - distance_arr.min() sort = np.argsort(d_arr2) _label = '%.3f' % (gap*1e3) #sp_centroid.plot(d_arr2, centroid_arr, label=_label) sp_rms.plot(d_arr2[sort]*1e6, rms_arr[sort]*1e15, label=_label, marker='.', color=ms.colorprog(gap_ctr, gap_arr)) fit = np.polyfit(d_arr2[sort], rms_arr[sort], 1)[0] lin_fit[gap_ctr] = fit sp_overview.errorbar(gap_arr*1e3, all_rms_arr.mean(axis=-1)*1e15, yerr=all_rms_arr.std(axis=-1)*1e15) sp_std.plot(gap_arr*1e3, all_rms_arr.std(axis=-1)/all_rms_arr.mean(axis=-1), marker='.') sp_fit.plot(gap_arr*1e3, lin_fit*1e15/1e6, marker='.') sp_rms.legend() ms.saveall('./album061/%s_file_%i' % (method, file_index), empty_suptitle=False) if not args.noshow: ms.show()