def fit_correlation(path, mess_array, scan_array, mess_date, maxtau, A_start = [3, 10000, 1, 10], flag_write = False, flag_plot = True, debug = False): """ croc.LaserCorrelation.fit_correlation This method imports the correlation data and fits it two a double exponential. CHANGELOG: 20120223/RB: collected some scripts into this function INPUT: - path (string): the path to the correlation data. Note that this is the same as the path_output in the import_and_process function. - mess_array (array): the base file names, for example 'correlation_T300' - scan_array (array): array with the file-endings, for example ['_NR1_1.bin', '_NR1_2.bin', ...] - mess_date (int): the day of the measurement yyyymmdd - pixel (int): the pixel that should be used - maxtau (int): to determine the correct name for the file of the correlation data - A_start (array, 4 elements): starting guess for the fit of the correlation data - flag_write (BOOL, False): If True, will write a file with the fitting data - flag_plot (BOOL, True): If False, it will not plot the result. - debug (BOOL, False): If true, it will only calculate 1 correlation, not all of them. OUTPUT: - a plot of the correlation data using both methods and the corresponding fits. - a text file with the fitting data """ if debug: i_len = 1 j_len = 1 else: i_len = len(mess_array) j_len = len(scan_array) string = "" for i in range(i_len): for j in range(j_len): if flag_plot: plt.figure() for k in range(2): if k == 0: sort = "fft" else: sort = "jan_" + str(maxtau) c = Resources.IOMethods.import_data_correlation(path, mess_array, i, scan_array, j, mess_date, sort = sort) c = c[:1000] x = numpy.arange(len(c)) A = A_start A_final = M.fit(x, c, E.double_exp, A) if flag_plot: plt.plot(c, ".") plt.plot(E.double_exp(A_final, x)) plt.title(mess_array[i] + scan_array[j]) s_m = mess_array[i] s_s = scan_array[j] s_p = sort s_a = str(numpy.round(A_final[0],2)) s_t1 = str(numpy.round(A_final[1],1)) s_b = str(numpy.round(A_final[2],2)) s_t2 = str(numpy.round(A_final[3],1)) temp_string = "{0:5} {1:6} {2:8} {3:5} {4:7} {5:5} {6:7}".format(s_m, s_s, s_p, s_a, s_t1, s_b, s_t2) print(temp_string) string += temp_string if flag_plot: plt.show() if flag_write: FILE = open(path + "corr_fitting.txt", "w") FILE.write(string) FILE.close()