def compute_initial_figure(self): self.fig.clear() ax1 = self.fig.add_subplot(2, 1, 1) ax1.set_title(self.title, loc='left') ax1.set_xlabel(self.xlabel) ax1.set_ylabel(self.ylabel) ax1.plot(self.x_IN_A, self.y_IN_A, color='#004466', linewidth=1) try: ax1.plot(self.x_IN_B, self.y_IN_B, color='#018BCF', linewidth=1) except: pass ax1.set_xlim([self.x_IN_A[0], self.x_IN_A[::-1][0]]) ax1.legend(['Sensor A', 'Sensor B']) prairie.style(ax1) # print(self.x1) ax2 = self.fig.add_subplot(2, 1, 2) ax2.set_title(self.title, loc='left') ax2.set_xlabel(self.xlabel) ax2.set_ylabel(self.ylabel) ax2.plot(self.x_OUT_A, self.y_OUT_A, color='#6E160E', linewidth=1) try: ax2.plot(self.x_OUT_B, self.y_OUT_B, color='#CF2A1B', linewidth=1) except: pass ax2.set_xlim([self.x_OUT_A[0], self.x_OUT_A[::-1][0]]) ax2.legend(['Sensor A', 'Sensor B']) prairie.style(ax2) self.fig.tight_layout()
def simulation_of_beam_width_measurements_error(reference_fit_parameters_file, fit_parameters_file, save=False, saving_name=None, position_random_error=15e-6, theoretical_curve=False): fig = plt.figure(figsize=(8, 2.5)) prairie.use() ax = fig.add_subplot(111) legend = [] for center in np.arange(0, 1, 1): r = [] sigmas = [] means = [] sig = 150 * np.logspace(-6, -4, 20) for beam_sigma in tqdm(sig): r = simulate_wire_profile_measurements(reference_fit_parameters_file, fit_parameters_file, center, beam_sigma, position_random_error=position_random_error) sigmas.append(r[1]/np.sqrt(2)) means.append(r[0]) sigmas = np.asarray(sigmas) means = np.asarray(means) legend.append('center: ' + str(center) + ' mm') Error = 100 * sigmas / means Error = 100 * sigmas/sig scan_speed = 133 * 150e-3 cycle_period = 20e-6 pps = sig / scan_speed / cycle_period ax.loglog(pps, Error, '.-') if theoretical_curve is True: SNR_x = sig/sigmas theor_curve = 100 * 0.4/(SNR_x*np.sqrt(pps)) ax.loglog(pps, theor_curve, '-') legend.append('Theoretical curve') # ax.set_title('Simulation of beam width measurements error (BWS LabProto2 ' + fit_parameters_file + ')', loc='left') ax.set_title('Relative random error on beam size measurements', loc='left') ax.set_xlabel('Points per sigma') ax.set_ylabel('Error (%)') ax.legend(legend) prairie.style(ax, ticks=None) plt.tight_layout() if save is True: plt.show(block=False) if saving_name is not None: plt.savefig(saving_name + '.png', format='png', dpi=DPI) plt.close('all') else: print('saving_name is None - Figure not saved') else: plt.show(block=True)
def compute_initial_figure(self): ax1 = self.fig.add_subplot(2, 1, 1) ax1.set_title('Position error and time compensation - IN', loc='left') ax1.set_xlabel('Angular position (rad)') ax1.set_ylabel('Position error (rad)') ax1.plot(self.positions_IN, self.time_IN) prairie.style(ax1) # print(self.positions_IN) ax2 = self.fig.add_subplot(2, 1, 2) ax2.set_title('Position error and time compensation - OUT', loc='left') ax2.set_xlabel('Angular position (rad)') ax2.set_ylabel('Position error (rad)') ax2.plot(self.positions_OUT, self.time_OUT) prairie.style(ax2) self.fig.tight_layout()
def compute_initial_figure(self): self.fig.clear() day_max = 31 legends = [] ax1 = self.fig.add_subplot(2, 1, 1) ax2 = self.fig.add_subplot(2, 1, 2) labels = [] dates = [] colors = [] mu = [] sigma = [] ranges_0 = [] ranges_1 = [] for folder in self.folders: if os.path.exists(folder + '/calibration_results.mat'): date = float( folder.split('/')[::-1][0].split('__')[1].split('_')[2]) plot_legend = folder.split('/')[::-1][0].split('__')[1].split('_')[1] + '/' + \ folder.split('/')[::-1][0].split('__')[1].split('_')[2] color = int( folder.split('/')[::-1][0].split('__')[1].split('_')[2]) if int( folder.split('/')[::-1][0].split('__')[2].split('_') [0]) <= 12: plot_legend += ' a.m.' else: plot_legend += ' p.m.' date += 0.5 color += 0.5 labels.append(plot_legend) data = sio.loadmat(folder + '/calibration_results.mat', struct_as_record=False, squeeze_me=True) dates.append(2 * date) acolor = np.zeros(3) acolor[1] = (day_max - color) / day_max acolor[2] = 0.75 acolor[0] = 0.2 colors.append(acolor) if self.in_or_out is 'IN': residuals = np.asarray(data['residuals_IN_origin']) range_0 = 1e3 * (np.mean(residuals) - 4 * np.std(residuals)) ranges_0.append(range_0) range_1 = 1e3 * (np.mean(residuals) + 4 * np.std(residuals)) ranges_1.append(range_1) ax1.plot(data['laser_position_IN'], 1e3 * data['residuals_IN_origin'], '.', color=acolor) m = dt.make_histogram(1e3 * data['residuals_IN_origin'], [range_0, range_1], 'um', axe=ax2, color=acolor) elif self.in_or_out is 'OUT': residuals = np.asarray(data['residuals_OUT_origin']) range_0 = 1e3 * (np.mean(residuals) - 4 * np.std(residuals)) ranges_0.append(range_0) range_1 = 1e3 * (np.mean(residuals) + 4 * np.std(residuals)) ranges_1.append(range_1) ax1.plot(data['laser_position_OUT'], 1e3 * data['residuals_OUT_origin'], '.', color=acolor) m = dt.make_histogram(1e3 * data['residuals_OUT_origin'], [range_0, range_1], 'um', axe=ax2, color=acolor) mu.append(m) if len(ranges_0) > 0: ax1.set_ylim( [np.min(np.asarray(ranges_0)), np.max(np.asarray(ranges_1))]) ax2.set_xlim( [np.min(np.asarray(ranges_0)), np.max(np.asarray(ranges_1))]) else: ax1.set_ylim([-100, 100]) ax1.set_xlim([-60, 60]) if len(self.folders) > 1: texts = ax2.get_legend().get_texts() for text in texts: legends.append(text._text) legends = np.asarray([ label + ' ' + legend for label, legend in zip(labels, legends) ]) ax2.legend(legends, bbox_to_anchor=(1.05, 1.90), loc=2, borderpad=1) prairie.style(ax1) prairie.style(ax2) ax1.set_title('Wire position error overs scans', loc='left') ax1.set_ylabel('Error (\u03BCm)') ax1.set_xlabel('Laser position (mm)') ax2.set_title('Wire position error histogram', loc='left') ax2.set_ylabel('Occurence') ax2.set_xlabel('Error (\u03BCm)') prairie.style(ax1) prairie.style(ax2) self.fig.tight_layout() self.fig.subplots_adjust(right=0.7)
def compute_initial_figure(self): self.fig.clear() prairie.use() ax1 = self.fig.add_subplot(2, 1, 1) ax3 = self.fig.add_subplot(2, 1, 2) residuals_IN = [] residuals_OUT = [] laser_position_IN = [] laser_position_OUT = [] for folder in self.folders: if os.path.exists(folder + '/calibration_results.mat'): color = int( folder.split('/')[::-1][0].split('__')[1].split('_')[2]) if int( folder.split('/')[::-1][0].split('__')[2].split('_') [0]) >= 12: color += 0.5 data = sio.loadmat(folder + '/' + 'calibration_results.mat', struct_as_record=False, squeeze_me=True) residuals_IN.append(data['residuals_IN_origin_mean']) residuals_OUT.append(data['residuals_OUT_origin_mean']) laser_position_IN.append(data['laser_position_IN_mean']) laser_position_OUT.append(data['laser_position_OUT_mean']) if len(self.folders) > 1: M = [] for residuals, laser_position in zip(residuals_IN, laser_position_IN): ax1.plot( laser_position, utils.butter_lowpass_filter(residuals, 1 / 101, 1 / 10) - np.mean(residuals), alpha=0.2, linewidth=2, label='_nolegend_') M.append(residuals) M = np.asarray(M) M = np.mean(M, 0) ax1.plot(laser_position, utils.butter_lowpass_filter(M, 1 / 101, 1 / 10), color='k', linewidth=2.5, label='Mean residual profile') ax1.set_xlabel('Laser position (mm)') ax1.set_ylabel('Residual error (\u03BCm)') ax1.legend() prairie.style(ax1) M = [] for residuals, laser_position in zip(residuals_OUT, laser_position_OUT): ax3.plot( laser_position, utils.butter_lowpass_filter(residuals, 1 / 101, 1 / 10) - np.mean(residuals), alpha=0.2, linewidth=2, label='_nolegend_') M.append(residuals) M = np.asarray(M) M = np.mean(M, 0) ax3.plot(laser_position, utils.butter_lowpass_filter(M, 1 / 101, 1 / 10), color='k', linewidth=2.5, label='Mean residual profile') ax3.set_xlabel('Laser position (mm)') ax3.set_ylabel('Residual error (\u03BCm)') ax3.legend() prairie.style(ax3)
def compute_initial_figure(self): self.fig.clear() prairie.use() ax1 = self.fig.add_subplot(2, 1, 1) ax3 = self.fig.add_subplot(2, 1, 2) residuals_IN = np.empty(1) residuals_OUT = np.empty(1) laser_position_IN = np.empty(1) laser_position_OUT = np.empty(1) for folder in self.folders: if os.path.exists(folder + '/calibration_results.mat'): color = int( folder.split('/')[::-1][0].split('__')[1].split('_')[2]) if int( folder.split('/')[::-1][0].split('__')[2].split('_') [0]) >= 12: color += 0.5 data = sio.loadmat(folder + '/' + 'calibration_results.mat', struct_as_record=False, squeeze_me=True) residuals_IN = np.concatenate( (residuals_IN, data['residuals_IN_origin']), axis=0) residuals_OUT = np.concatenate( (residuals_OUT, data['residuals_OUT_origin']), axis=0) laser_position_IN = np.concatenate( (laser_position_IN, data['laser_position_IN']), axis=0) laser_position_OUT = np.concatenate( (laser_position_OUT, data['laser_position_OUT']), axis=0) ax1.plot(data['laser_position_IN'], 1e3 * data['residuals_IN_origin'], '.') ax3.plot(data['laser_position_OUT'], 1e3 * data['residuals_OUT_origin'], '.') if len(self.folders) > 1: laser_position_IN_mean = [] residuals_IN_mean = [] laser_position_OUT_mean = [] residuals_OUT_mean = [] for laser_position in laser_position_IN: residuals_IN_mean.append( np.mean(residuals_IN[np.where( laser_position_IN == laser_position)])) laser_position_IN_mean.append(laser_position) for laser_position in laser_position_OUT: residuals_OUT_mean.append( np.mean(residuals_OUT[np.where( laser_position_OUT == laser_position)])) laser_position_OUT_mean.append(laser_position) ax1.set_ylim([-100, 100]) ax3.set_ylim([-100, 100]) prairie.style(ax1) prairie.style(ax3) ax1.set_title('Wire position error overs scans - IN', loc='left') ax1.set_ylabel('Error (\u03BCm)') ax1.set_xlabel('Laser position (mm)') ax1.legend([ '\u03C3 ' + "{:3.3f}".format(np.std(1e3 * residuals_IN) / np.sqrt(2)) + ' ' + '\u03BC ' + "{:3.3f}".format(np.mean(1e3 * residuals_IN)) + ' (\u03BCm)' ]) ax3.set_title('Wire position error overs scans - OUT', loc='left') ax3.set_ylabel('Error (\u03BCm)') ax3.set_xlabel('Laser position (mm)') ax3.legend([ '\u03C3 ' + "{:3.3f}".format(np.std(1e3 * residuals_OUT) / np.sqrt(2)) + ' ' + '\u03BC ' + "{:3.3f}".format(np.mean(1e3 * residuals_OUT)) + ' (\u03BCm)' ]) self.fig.tight_layout()
def compute_initial_figure(self): self.fig.clear() color_IN = '#018BCF' color_OUT = '#CF2A1B' black = [0.3, 0.3, 0.3] parameter_file = utils.resource_path('data/parameters.cfg') if len(self.x_IN_A) == 200: ax1 = self.fig.add_subplot(2, 2, 1) ax1.plot(self.t1, self.x_IN_A, linewidth=0.5) prairie.style(ax1) ax2 = self.fig.add_subplot(2, 2, 2) ax2.plot(self.t1, self.y_IN_A, linewidth=0.5) prairie.style(ax2) ax3 = self.fig.add_subplot(2, 2, 3) ax3.plot(self.t2, self.x_OUT_A, linewidth=0.5) prairie.style(ax3) ax4 = self.fig.add_subplot(2, 2, 4) ax4.plot(self.t2, self.y_OUT_A, linewidth=0.5) prairie.style(ax4) self.fig.tight_layout() else: P = ops.process_position(self.x_IN_A, parameter_file, self.t1[0], return_processing=True) ax1 = self.fig.add_subplot(3, 2, 1) ax1.axhspan(0, P[8], color='black', alpha=0.05) ax1.plot(1e-3 * P[0], P[1], linewidth=0.5) ax1.plot(1e-3 * P[2], P[3], '.', markersize=2) ax1.plot(1e-3 * P[4], P[5], '.', markersize=2) ax1.plot(1e-3 * P[6], P[7], '-', linewidth=0.5, color=black) ax1.set_title('OPS processing SA - IN', loc='left') ax1.set_xlabel('Time (s)') ax1.set_ylabel('Normalized amplitude') ax1.legend(['OPS data', 'Maxs', 'Mins', 'Threshold']) prairie.style(ax1) P = ops.process_position(self.y_IN_A, parameter_file, self.t1[0], return_processing=True) ax2 = self.fig.add_subplot(3, 2, 3) ax2.axhspan(0, P[8], color='black', alpha=0.05) ax2.plot(1e-3 * P[0], P[1], linewidth=0.5) ax2.plot(1e-3 * P[2], P[3], '.', markersize=2) ax2.plot(1e-3 * P[4], P[5], '.', markersize=2) ax2.plot(1e-3 * P[6], P[7], '-', linewidth=0.5, color=black) ax2.set_title('OPS processing SB - IN', loc='left') ax2.set_xlabel('Time (s)') ax2.set_ylabel('Normalized amplitude') prairie.style(ax2) P = ops.process_position(self.x_OUT_A, parameter_file, self.t2[0], return_processing=True) ax3 = self.fig.add_subplot(3, 2, 2) ax3.axhspan(0, P[8], color='black', alpha=0.05) ax3.plot(1e-3 * P[0], P[1], linewidth=0.5) ax3.plot(1e-3 * P[2], P[3], '.', markersize=2) ax3.plot(1e-3 * P[4], P[5], '.', markersize=2) ax3.plot(1e-3 * P[6], P[7], '-', linewidth=0.5, color=black) ax3.set_title('OPS processing SA - OUT', loc='left') ax3.set_xlabel('Time (s)') ax3.set_ylabel('Normalized amplitude') prairie.style(ax3) P = ops.process_position(self.y_OUT_A, parameter_file, self.t2[0], return_processing=True) ax4 = self.fig.add_subplot(3, 2, 4) ax4.axhspan(0, P[8], color='black', alpha=0.05) ax4.plot(1e-3 * P[0], P[1], linewidth=0.5) ax4.plot(1e-3 * P[2], P[3], '.', markersize=2) ax4.plot(1e-3 * P[4], P[5], '.', markersize=2) ax4.plot(1e-3 * P[6], P[7], '-', linewidth=0.5, color=black) ax4.set_title('OPS processing SB - OUT', loc='left') ax4.set_xlabel('Time (s)') ax4.set_ylabel('Normalized amplitude') prairie.style(ax4) occ_IN = ops.find_occlusions(self.pd1, IN=True, StartTime=self.t1[0], return_processing=True) occ_OUT = ops.find_occlusions(self.pd2, IN=False, StartTime=self.t2[0], return_processing=True) ax5 = self.fig.add_subplot(3, 2, 5) ax5.set_title('Processing PH - IN', loc='left') ax5.set_xlabel('Time (s)') ax5.set_ylabel('a.u.') ax5.plot(self.t1, self.pd1, linewidth=1) ax5.plot(occ_IN[0], occ_IN[1], '.', markersize=3, color=black) ax5.legend(['PD data', 'Detected occlusions']) prairie.style(ax5) ax6 = self.fig.add_subplot(3, 2, 6) ax6.set_title('Processing PH - OUT', loc='left') ax6.set_xlabel('Time (s)') ax6.set_ylabel('a.u.') ax6.plot(self.t2, self.pd2, linewidth=1) ax6.plot(occ_OUT[0], occ_OUT[1], '.', markersize=3, color=black) prairie.style(ax6) self.fig.tight_layout()
def compute_initial_figure(self): parameter_file = utils.resource_path('data/parameters.cfg') config = configparser.RawConfigParser() config.read(parameter_file) rdcp = eval( config.get('OPS processing parameters', 'relative_distance_correction_prameters')) self.fig.clear() color_A = '#018BCF' color_B = self.color = '#CF2A1B' time_SA = self.x_IN_A time_SB = self.x_OUT_A offset = 0 ax1 = self.fig.add_subplot(2, 1, 1) ax1.axhspan(rdcp[1], rdcp[0], color='black', alpha=0.1) for i in np.arange(0, time_SA.shape[0] - 1): distances_A = np.diff(time_SA[i])[offset:time_SA[i].size - 1 - offset] rel_distances_A = np.divide(distances_A[1::], distances_A[0:distances_A.size - 1]) distances_B = np.diff(time_SB[i])[offset:time_SB[i].size - 1 - offset] rel_distances_B = np.divide(distances_B[1::], distances_B[0:distances_B.size - 1]) ax1.plot(1e3 * time_SA[i][offset:time_SA[i].size - 2 - offset], rel_distances_A, '.', color=color_A) ax1.plot(1e3 * time_SB[i][offset:time_SB[i].size - 2 - offset], rel_distances_B, '.', color=color_B) ax1.set_xlabel('Time (' + '\u03BC' + 's)') ax1.set_ylabel('Relative distance') ax1.set_title('RDS plot - IN', loc='left') red_patch = mpatches.Patch(color=color_A, label='Sensor A') blue_patch = mpatches.Patch(color=color_B, label='Sensor B') ax1.legend(handles=[blue_patch, red_patch]) prairie.style(ax1) time_SA = self.y_IN_A time_SB = self.y_OUT_A ax2 = self.fig.add_subplot(2, 1, 2) ax2.axhspan(rdcp[1], rdcp[0], color='black', alpha=0.1) for i in np.arange(0, time_SA.shape[0] - 1): distances_A = np.diff(time_SA[i])[offset:time_SA[i].size - 1 - offset] rel_distances_A = np.divide(distances_A[1::], distances_A[0:distances_A.size - 1]) distances_B = np.diff(time_SB[i])[offset:time_SB[i].size - 1 - offset] rel_distances_B = np.divide(distances_B[1::], distances_B[0:distances_B.size - 1]) ax2.plot(1e3 * time_SA[i][offset:time_SA[i].size - 2 - offset], rel_distances_A, '.', color=color_A) ax2.plot(1e3 * time_SB[i][offset:time_SB[i].size - 2 - offset], rel_distances_B, '.', color=color_B) ax2.set_xlabel('Time (' + '\u03BC' + 's)') ax2.set_ylabel('Relative distance') ax2.set_title('RDS plot - OUT', loc='left') red_patch = mpatches.Patch(color=color_A, label='Sensor A') blue_patch = mpatches.Patch(color=color_B, label='Sensor B') ax2.legend(handles=[blue_patch, red_patch]) prairie.style(ax2) self.fig.tight_layout()
def compute_initial_figure(self): self.fig.clear() if self.in_or_out is 'IN': self.color = '#018BCF' elif self.in_or_out is 'OUT': self.color = '#CF2A1B' eccentricity = self.y_IN_A angular_position_SA = self.x_IN_A off = 50 ref_ecc = eccentricity[0][:] ref_ecc = ref_ecc[off:ref_ecc.size - off] ref_pos = angular_position_SA[0][:] ref_pos = ref_pos[off:ref_pos.size - off] ecc_all = [] def theor_ecc(x, a, b, c): return a * np.sin(x + b) + c popt, pcov = curve_fit(theor_ecc, ref_pos, ref_ecc, bounds=([-100, -100, -100], [100, 100, 100])) for ecc, pos in zip(eccentricity, angular_position_SA): ecc = ecc[off:ecc.size - off] pos = pos[off:pos.size - off] ecc = utils.resample(np.array([pos, ecc]), np.array([ref_pos, ref_ecc])) ecc_all.append(ecc[1]) [ref_ecc, ref_pos] = [eccentricity[0], angular_position_SA[0]] deff = [] residuals_mean = [] ax1 = self.fig.add_subplot(2, 1, 1) ax1.plot(ref_pos, theor_ecc(ref_pos, popt[0], popt[1], popt[2]), linewidth=0.5, color='black') for ecc, pos in zip(eccentricity, angular_position_SA): ecc = ecc[off:ecc.size - off] pos = pos[off:pos.size - off] ax1.plot(pos, ecc, linewidth=1) ax1.set_title('Position error and eccentricity', loc='left') ax1.set_xlabel('Angular position (rad)') ax1.set_ylabel('Position error (rad)') prairie.style(ax1) ax2 = self.fig.add_subplot(2, 2, 3) for ecc, pos in zip(eccentricity, angular_position_SA): ecc = ecc[off:ecc.size - off] pos = pos[off:pos.size - off] residuals = ecc - theor_ecc(pos, popt[0], popt[1], popt[2]) ax2.plot(pos, residuals, linewidth=0.5) residuals_mean.append(np.mean(residuals)) ax2.set_title('Position error after compensation', loc='left') ax2.set_xlabel('Angular position (rad)') ax2.set_ylabel('Position error (\u03BCrad)') prairie.style(ax2) ax3 = self.fig.add_subplot(4, 2, 4) dt.make_histogram(1e6 * np.asarray(residuals_mean), [-10, 10], '\u03BC' + 'rad', ax3) ax3.set_title('Error histogram (' + str(len(eccentricity)) + ' traces)', loc='left') ax3.set_ylabel('Occurrence') ax3.set_xlabel('Position error (\u03BCrad)') prairie.style(ax3) self.fig.tight_layout()
def simulate_wire_profile_measurements(reference_fit_parameters_file, fit_parameters_file, gauss_beam_position=0, gauss_beam_sigma=0, diagnostic=False, save=False, saving_name=None, position_random_error=15e-6): ########################## # Loading files and data # ########################## param_file = sio.loadmat(fit_parameters_file + '/calibration_results.mat', struct_as_record=False, squeeze_me=True) fit_parameters = param_file['f_parameters_IN'] param_file = sio.loadmat(reference_fit_parameters_file, struct_as_record=False, squeeze_me=True) reference_fit_parameters = param_file['f_parameters_IN'] parameter_file = utils.resource_path('data/parameters.cfg') config = configparser.RawConfigParser() config.read(parameter_file) measurement_sigma = position_random_error # gauss_beam_position = eval(config.get('Beam characteristics', 'gauss_beam_position')) # gauss_beam_sigma = eval(config.get('Beam characteristics', 'gauss_beam_sigma')) scan_speed = eval(config.get('Simulation', 'scan_speed')) cycle_period = eval(config.get('Simulation', 'cycle_period')) point_per_sigma = gauss_beam_sigma / scan_speed / cycle_period ############################# # Sigma and Mean extraction # ############################# if diagnostic is True : fig = plt.figure(figsize=(8, 2.5)) prairie.use() ax = fig.add_subplot(111) sigmas = [] extended_std = 15 * gauss_beam_sigma beam_offset_center = utils.theoretical_laser_position( utils.inverse_theoretical_laser_position(gauss_beam_position, *reference_fit_parameters), *fit_parameters) ideal_beam_measurement_positions = np.arange(gauss_beam_position - extended_std / 2, gauss_beam_position + extended_std / 2, gauss_beam_sigma / point_per_sigma) disk_measurement_positions = utils.inverse_theoretical_laser_position(ideal_beam_measurement_positions, *reference_fit_parameters) beam_measurement_positions = utils.theoretical_laser_position(disk_measurement_positions, *fit_parameters) def gauss(x, a, mu, sigma): return a * np.exp(-(x - mu) ** 2 / (2 * sigma ** 2)) for i in np.arange(0, 1000, 1): sim_measured_positions = [] sim_amplitudes = [] for mu in beam_measurement_positions: sim_pos = mu + np.random.normal(0, measurement_sigma) sim_measured_positions.append(sim_pos) sim_amp = gauss(mu, 1, beam_offset_center, gauss_beam_sigma) sim_amplitudes.append(sim_amp) x = sim_measured_positions y = sim_amplitudes parameters, trash = curve_fit(gauss, x, y, p0=[2, beam_offset_center, gauss_beam_sigma]) if diagnostic is True: arange = np.arange(beam_measurement_positions[0], beam_measurement_positions[::-1][0], (beam_measurement_positions[1]-beam_measurement_positions[0])/100) ax.plot(1e3*arange, gauss(arange, *parameters), linewidth=0.2) ax.plot(1e3*np.asarray(x), y, '.k', markersize=4) scan_speed = 133 * 150e-3 cycle_period = 20e-6 pps = gauss_beam_sigma / scan_speed / cycle_period ax.set_title('Beam profile simulation' + ' [ \u03C3:' + "{:3.0f}".format(1e6*gauss_beam_sigma) + '\u03BCm ' + '\u03BC:' + "{:3.0f}".format(1e6*gauss_beam_position) + ' \u03BCm ] - 1000 profiles\n' + "{:3.2f}".format(pps) + ' points per sigma', loc='left') ax.set_xlabel('Transverse dimension (mm)') ax.set_ylabel('Secondary shower intensity (a.u)') ax.legend(['Beam gaussian fits', 'Measurement points']) sigmas.append(parameters[2]) if diagnostic is True: prairie.style(ax) plt.tight_layout() if save is True: plt.show(block=False) if saving_name is not None: plt.savefig(saving_name + '.png', format='png', dpi=DPI) plt.close('all') else: print('saving_name is None - Figure not saved') else: plt.show(block=True) return [np.mean(sigmas), np.std(sigmas), beam_offset_center]
def Beam_width_error_over_different_calibration_curves(reference_fit_parameters_file, folders, save=False, saving_name=None, position_random_error=15e-6): fig = plt.figure(figsize=(8, 2.5)) prairie.use() ax = fig.add_subplot(111) legend = [] sigmas = [] means = [] i = 0 center = [] beam_width = 150e-6 scan_speed = 133 * 150e-3 cycle_period = 20e-6 pps = beam_width / scan_speed / cycle_period for folder in tqdm(folders): r = simulate_wire_profile_measurements(reference_fit_parameters_file, folder, 0, beam_width, position_random_error=position_random_error) sigmas.append(r[1]) means.append(r[0]) center.append(r[2]) # ax.plot(i, 100*r[1]/r[0], '.') i += 1 sigmas = np.asarray(sigmas) means = np.asarray(means) Error = 100 * sigmas / means Error = np.asarray(Error) ax.plot(np.asarray(Error), '.', color='k') ax.set_ylabel('beam width error (%)') ax.set_xlabel('Calibrations #') ax.set_ylim([np.mean(Error) - 6*np.std(Error), np.mean(Error) + 6*np.std(Error)]) ax.set_title('Beam width error over different calibration curves \n (' + "{:3.2f}".format(pps) + ' points per sigma'')', loc='left') # ax.set_ylim([0.5, 1.5]) prairie.style(ax) # # scan_speed = 133 * 150e-3 # cycle_period = 20e-6 # # pps = sig / scan_speed / cycle_period # # ax.loglog(pps, Error, '.-') # # ax.set_title('Simulation of beam width measurements error (BWS LabProto2)', loc='left') # ax.set_xlabel('Points per sigma') # ax.set_ylabel('Error (%)') # ax.legend(legend) # prairie.apply(ax, ticks=None) plt.tight_layout() if save is True: plt.show(block=False) if saving_name is not None: plt.savefig(saving_name + '.png', format='png', dpi=DPI) plt.close('all') else: print('saving_name is None - Figure not saved') else: plt.show(block=True)
def compute_initial_figure(self): self.fig.clear() laser_position = self.y_IN_A occlusion_position = self.x_IN_A if self.in_or_out is 'IN': self.color = '#018BCF' elif self.in_or_out is 'OUT': self.color = '#CF2A1B' occlusion_position = np.pi / 2 - occlusion_position parameter_file = utils.resource_path('data/parameters.cfg') config = configparser.RawConfigParser() config.read(parameter_file) positions_for_fit = eval( config.get('OPS processing parameters', 'positions_for_fit')) positions_for_analysis = eval( config.get('OPS processing parameters', 'positions_for_analysis')) tank_center = eval( config.get('OPS processing parameters', 'offset_center')) self.idxs = np.argsort(laser_position) occlusion_position = occlusion_position[self.idxs] laser_position = laser_position[self.idxs] self.focus = np.where(self.idxs == self.focus)[0] laser_position = -laser_position + tank_center self.y_IN_A = laser_position self.x_IN_A = occlusion_position unique_laser_position = np.unique(laser_position) occlusion_position_mean = [] for laser_pos in unique_laser_position: occlusion_position_mean.append( np.mean(occlusion_position[np.where( laser_position == laser_pos)[0]])) off1 = [ int(positions_for_fit[0] / 100 * unique_laser_position.size), int(positions_for_fit[1] / 100 * unique_laser_position.size) ] occlusion_position_mean = np.asarray(occlusion_position_mean) popt, pcov = curve_fit(utils.theoretical_laser_position, occlusion_position_mean[off1[0]:off1[1]], unique_laser_position[off1[0]:off1[1]], bounds=([-5, 80, 100], [5, 500, 500])) theorical_laser_position_mean = utils.theoretical_laser_position( occlusion_position_mean, popt[0], popt[1], popt[2]) theoretical_laser_position = utils.theoretical_laser_position( occlusion_position, popt[0], popt[1], popt[2]) param = popt off2 = [ int(positions_for_analysis[0] / 100 * laser_position.size), int(positions_for_analysis[1] / 100 * laser_position.size) ] laser_position = laser_position[off2[0]:off2[1]] theoretical_laser_position = theoretical_laser_position[ off2[0]:off2[1]] occlusion_position = occlusion_position[off2[0]:off2[1]] residuals = laser_position - theoretical_laser_position plt.figure(figsize=(6.5, 7.5)) prairie.use() ax2 = self.fig.add_subplot(2, 2, 4) residuals = residuals[off2[0]:off2[1]] dt.make_histogram(1e3 * residuals, [-300, 300], '\u03BCm', axe=ax2, color=self.color) ax2.set_title('Wire position error histogram', loc='left') ax2.set_xlabel('Wire position error (\u03BCm)') ax2.set_ylabel('Occurrence') prairie.style(ax2) ax3 = self.fig.add_subplot(2, 2, 3) ax3.plot(laser_position, 1e3 * residuals, '.', color=self.color, markersize=1.5) ax3.set_ylim([-300, 300]) ax3.set_title('Wire position error', loc='left') ax3.set_ylabel('Wire position error (\u03BCm)') ax3.set_xlabel('Laser position (mm)') prairie.style(ax3) equation = "{:3.2f}".format(param[1]) + '-' + "{:3.2f}".format( param[2]) + '*' + 'cos(\u03C0-x+' + "{:3.2f}".format( param[0]) + ')' legend = 'Theoretical Wire position: ' + equation self.ax1 = self.fig.add_subplot(2, 1, 1) self.ax1.plot(occlusion_position_mean, theorical_laser_position_mean, linewidth=0.5, color='black') self.ax1.plot(occlusion_position, laser_position, '.', color=self.color, markersize=4) self.foc_marker, = self.ax1.plot(occlusion_position[self.focus], laser_position[self.focus], 'o', color=self.color, fillstyle='none', markersize=10) self.ax1.legend([legend, 'Measured positions']) # ax1.set_title(folder_name + ' ' + in_or_out + '\n\n\n Theoretical wire positions vs. measured positions', # loc='left') self.ax1.set_title('Theoretical wire positions vs. measured positions', loc='left') self.ax1.set_xlabel('Angular position at laser crossing (rad)') self.ax1.set_ylabel('Laser position (mm)') prairie.style(self.ax1) # ax4 = plt.subplot2grid((3, 2), (2, 0), colspan=2) # ax4.plot(1e3 * residuals, '.', color=color, markersize=1.5) # ax4.plot(1e3 * residuals, color=color, linewidth=0.5) # ax4.set_title('Wire position error over scans', loc='left') # ax4.set_ylabel('Wire position error (\u03BCm)') # ax4.set_xlabel('Scan #') # prairie.apply(ax4) # # plt.tight_layout() # ax1 = self.fig.add_subplot(2, 1, 1) # ax1.set_title('Position error and eccentricity compensation - IN', loc='left') # ax1.set_xlabel('Angular position (rad)') # ax1.set_ylabel('Position error (rad)') # ax1.plot(self.x1, self.y1) # ax1.set_xlim([self.x1[0], self.x1[::-1][0]]) # prairie.apply(ax1) # # print(self.x1) # # ax2 = self.fig.add_subplot(2, 1, 2) # ax2.set_title('Position error and eccentricity compensation - OUT', loc='left') # ax2.set_xlabel('Angular position (rad)') # ax2.set_ylabel('Position error (rad)') # ax2.plot(self.x2, self.y2) # ax2.set_xlim([self.x2[0], self.x2[::-1][0]]) # prairie.apply(ax2) self.fig.tight_layout()