Ejemplo n.º 1
0
    def save_all_files(self):
        output_files_list = []
        list_of_all_files = self.get_list_of_all_files()
        for file in list_of_all_files:
            file_path, file_name = os.path.split(file)
            if os.path.split(file_path)[1] == '.temp':
                temp_path = file_path
                temp_file = os.path.join(temp_path, file_name)
            else:
                temp_path = os.path.join(file_path, '.temp')
                temp_file = os.path.join(temp_path, file_name)
                output_files_list.append(temp_file)
                if not os.path.exists(temp_path):
                    os.mkdir(temp_path)
                    ctypes.windll.kernel32.SetFileAttributesW(temp_path,
                                                              2)  # hidden dir
                    self.temp_dirs.append(
                        temp_path
                    )  # for deletion of temp dir on closing of GUI
            output = ''
            xdata, ydata = trlfs.load_data(file)
            for i, x_value in enumerate(xdata):
                output += str(x_value) + '\t' + str(ydata[i]) + '\n'
            with open(temp_file, 'w+') as o:
                o.write(output)

        abs_path = filedialog.askdirectory(initialdir=self.get_data_dir())
        for temp_file in output_files_list:
            _, temp_filename = os.path.split(temp_file)
            abs_out_path = os.path.join(abs_path, temp_filename)
            shutil.copyfile(temp_file, abs_out_path)
Ejemplo n.º 2
0
 def data_plotter(self):
     self.selected_item_indexes = lister.curselection()
     for item_index in self.selected_item_indexes:
         file_name = lister.get(item_index)
         file = data_files.get_file_from_file_name(file_name)
         xdata, ydata = trlfs.load_data(file)
         self.ax2.plot(xdata, ydata, label=file_name)
         if len(self.selected_item_indexes) <= 10:
             ax.legend()
Ejemplo n.º 3
0
 def integrate_data(self):
     button_excitation_wavelengths['state'] = 'normal'
     self.integral_xdata = []
     self.integral_ydata = []
     line1_x_value = None
     line2_x_value = None
     if integration_lines.get_range() is not None:
         line1_x_value, line2_x_value = integration_lines.get_range()
     selected_item_indexes = lister.curselection()
     for i, item_index in enumerate(selected_item_indexes):
         file_name = lister.get(item_index)
         file = self.get_file_from_file_name(file_name)
         stripped_file_name = os.path.split(file)[1].split('.')[0]
         try:
             if stripped_file_name.split('_')[-1] == 'corr':
                 first_value = int(stripped_file_name.split('_')[-3])
                 if first_value > 30000:  # which means it is excitation data
                     xvalue = float(stripped_file_name.split('_')[-3]) / 100
                 else:  # which means it is lifetime data
                     xvalue = int(stripped_file_name.split('_')[-3])
             else:
                 first_value = int(stripped_file_name.split('_')[-1])
                 if first_value > 30000:  # which means it is excitation data
                     xvalue = float(stripped_file_name.split('_')[-1]) / 100
                 else:  # which means it is lifetime data
                     xvalue = int(stripped_file_name.split('_')[-1])
         except:
             xvalue = i + 1
         self.integral_xdata.append(xvalue)
         if background.background_corr_data == []:
             xdata, ydata = trlfs.load_data(file)
         else:
             xdata, ydata = background.background_corr_data[i]
         if line1_x_value != None:
             for j, value in enumerate(
                     xdata):  # find xdata value closest to line1 x value
                 if value >= line1_x_value:
                     lower_value = j
                     break
             for k, value in enumerate(
                     xdata):  # find xdata value closest to line2 x value
                 if value >= line2_x_value:
                     upper_value = k
                     break
         else:  # choose whole range
             lower_value = 0
             upper_value = -1
         interpolate_function = interpolate.interp1d(
             xdata[lower_value:upper_value], ydata[lower_value:upper_value])
         integral_of_file = integrate.quad(interpolate_function,
                                           xdata[lower_value],
                                           xdata[upper_value - 1],
                                           limit=50)[0]
         self.integral_ydata.append(integral_of_file)
     integral_plotter(self.integral_xdata, self.integral_ydata)
Ejemplo n.º 4
0
def plot_all(file_list):
    ax.cla()
    integration_lines.lines = []
    lister.delete(0, tk.END)
    for file in file_list:
        _, file_name = os.path.split(file)
        lister.insert(tk.END, file_name)
        xdata, ydata = trlfs.load_data(file)
        ax.plot(xdata, ydata, linewidth=1, label=file_name.split('.')[0])
    if len(file_list) <= 10:
        ax.legend()
    canvas.draw()
Ejemplo n.º 5
0
 def init_line(self):
     self.lines = []
     # Make default lines first
     file = data_files.get_list_of_all_files()[0]
     xdata, _ = trlfs.load_data(file)
     center_x_value_index = int(len(xdata) / 2)
     x_value_line1 = xdata[center_x_value_index] - 5
     x_value_line2 = xdata[center_x_value_index] + 5
     left_line = self.ax.axvline(x_value_line1)
     right_line = self.ax.axvline(x_value_line2)
     self.lines.append(left_line)
     self.lines.append(right_line)
     self.canvas.draw()
Ejemplo n.º 6
0
def short_cut_re_plotter(event, ax):
    ax.cla()
    integration_lines.lines = []
    integration_lines.x1 = None
    integration_lines.x2 = None
    selected_item_indexes = lister.curselection()
    for selected_item_index in selected_item_indexes:
        file_name = lister.get(selected_item_index)
        file = data_files.get_file_from_file_name(file_name)
        xdata, ydata = trlfs.load_data(file)
        ax.plot(xdata, ydata, label=file_name)
    if len(selected_item_indexes) <= 10:
        ax.legend()
    canvas.draw()
Ejemplo n.º 7
0
 def bg_correct_all(self):
     self.disconnect()
     dots_xdata = self.bg_corr_line.dots_xdata
     dots_ydata = self.bg_corr_line.dots_ydata
     bg_functions = {
     }  # dict of functions, valid below the according x_value, i.e. the key
     for i, dot_xdata in enumerate(dots_xdata):
         if i > 0:
             slope = (dots_ydata[i] - dots_ydata[i - 1]) / (
                 dots_xdata[i] - dots_xdata[i - 1])
             y_intercept = dots_ydata[i - 1] - slope * dots_xdata[i - 1]
             bg_functions[dot_xdata] = [slope, y_intercept]
     function_delimiters = list(
         bg_functions.keys()
     )  # list of the x_values of the dots, first bg function valid until first value etc.
     self.list_of_all_files = data_files.get_list_of_all_files()
     for file in self.list_of_all_files:
         _, file_name = os.path.split(file)
         xdata, ydata = trlfs.load_data(file)
         corrected_ydata = []
         range_of_points = list(range(0, len(function_delimiters)))
         for i, x_value in enumerate(xdata):
             for j in range_of_points:  # step through function_delimiters and find corresponding bg function
                 if x_value <= function_delimiters[j]:
                     slope, y_intercept = bg_functions[
                         function_delimiters[j]]
                     corrected_ydata.append(ydata[i] - (slope * xdata[i] +
                                                        y_intercept))
                     break
                 elif x_value > function_delimiters[-1]:
                     slope, y_intercept = bg_functions[
                         function_delimiters[-1]]
                     corrected_ydata.append(ydata[i] - (slope * xdata[i] +
                                                        y_intercept))
                     break
                 else:
                     j += 1
         self.background_corr_data.append([xdata, corrected_ydata])
     ax.cla()
     for i, xy_data in enumerate(self.background_corr_data):
         file_name = list(data_files.get_list_of_all_file_names())[i]
         ax.plot(xy_data[0], xy_data[1], label=file_name.split('.')[0])
     self.correction_window.destroy()
     self.save_bg_corr_data()
     if len(self.background_corr_data) <= 10:
         ax.legend()
     canvas.draw()
Ejemplo n.º 8
0
 def save_integration_data(self):
     first_file_name = lister.get(0)
     if integration_lines.get_range() is not None:
         line1_x_value, line2_x_value = integration_lines.get_range()
     else:
         file = data_files.get_file_from_file_name(first_file_name)
         xdata, _ = trlfs.load_data(file)
         line1_x_value = xdata[0]
         line2_x_value = xdata[-1]
     out_file_name = os.path.split(first_file_name)[1].split('.')[0]
     if out_file_name.split('_')[0] != out_file_name:
         temp_out_file_name = ''
         for i in range(len(out_file_name.split('_')) - 1):
             temp_out_file_name += out_file_name.split('_')[i]
         out_file_name = temp_out_file_name
     output = self.integral_output_maker()
     init_file_name = f'{out_file_name} integration from {int(line1_x_value*100)/100} - {int(line2_x_value*100)/100}'
     save_file = filedialog.asksaveasfilename(
         initialdir=self.get_data_dir(),
         initialfile=init_file_name,
         defaultextension='.txt',
         filetypes=[('Text file', '*.txt'), ('Others', ('*.asc', '*dat'))])
     with open(str(save_file), 'w+') as o:
         o.write(str(output))
Ejemplo n.º 9
0
 def init_data_range(self):
     first_data_file = data_files.get_list_of_files_from_indexes(
         self.item_indexes[0])[0]
     self.xdata, self.ydata = trlfs.load_data(first_data_file)