Beispiel #1
0
def time_correct(in_dir_name, dir_params, main_dir):
    '''
    Spectrums/Images time adjusted in TimeSort function above are loaded in
    and the data is maintained. The file name is split and the first file
    captured is set to 0, the following files within the directory are given
    a time stamp respective to the zero file (a time step). This is useful
    for later processing.
    Args:
        in_dir_name: <string> directory name containind time adjusted
                     spectrum files
        dir_params: <array> directories are given a name equivalent to the
                    individual file names, the dir_params function splits
                    the directory name into an array that can be used to find
                    the correct spectrum files.
        main_dir: <string> current working directory
    '''
    file_string = '_'.join(dir_params[0:2])
    print(' ')
    print(dir_params)
    data_files = io.extract_files(dir_name=in_dir_name,
                                  file_string=file_string)

    zero_file_name = data_files[0]
    zero_time_stamp = (zero_file_name.split('_')[::-1])[0]

    for index, selected_file in enumerate(data_files):
        file = os.path.join(in_dir_name, selected_file)
        data = np.load(file)

        file_name = io.get_filename(file)
        split_file = file_name.split('_')[::-1]
        time_correction = int(
            float(split_file[0]) - float(zero_time_stamp[0:-4]))

        out_dir_name = '_'.join(dir_params[0:-1]) + '_TimeCorrected'
        out_dir = os.path.join(main_dir, out_dir_name)
        io.check_dir_exists(out_dir)

        joined = []
        joined.append(file_string)
        joined.append(str(time_correction))
        new_file_name = '_'.join(joined)

        io.array_save(array_name=data,
                      file_name=new_file_name,
                      dir_name=out_dir)

        io.update_progress(index / len(data_files))
                    writer.writerow([time_stamp] + [peak] + [peak_shift])
                    io.update_progress(index / len(data_files))

            shutil.copy(outfile_name, results_dir)
            os.remove(outfile_name)

            dir_params = dprep.solute_finder(solute_dir)
            data_files = io.extract_files(dir_name=results_dir,
                                          file_string='_'.join(dir_params) +
                                          '_Peaks.csv')

            print(f'\nFiles to be processed: {data_files}')

            for index, selected_file in enumerate(data_files):
                file = os.path.join(results_dir, selected_file)
                file_name = io.get_filename(file)

                bg_file_string = [
                    '1M_Salt_Background',
                    '_'.join(dir_params[0:2]) + '_Background',
                    '1M_Salt_Paper_Background',
                    '_'.join(dir_params[0:2]) + '_Background',
                    f'{sensor}_Background', 'DI_Background', 'IPA_Background'
                ]

                bg_file = os.path.join(bg_dir, 'Background_Peaks.csv')
                names, bg_peak, bg_peak_shift = np.genfromtxt(bg_file,
                                                              delimiter='\t',
                                                              dtype=(str),
                                                              unpack=True)