Exemplo n.º 1
0
def peak_shift(file, zero_file):
    '''
    Reads in the wavelength, intensity and file name parameters from
    an in-file and the sensor file. Then uses the FindPeaks function to
    determine the x coordinates of a resonant peak within both files. Using
    this it calculates a peak shift. Outputs the time, peak and peak shift
    values.
    Args:
        file: <string> file path to image
        zero_file: <string> file path to sensor background image
    '''
    wavelength, intensity, file_name = io.array_in(file=file)
    wav_zero, int_zero, zero_file_name = io.array_in(file=zero_file)

    file_peak = peaks(x=wavelength,
                      y=intensity,
                      distance=300,
                      width=20,
                      xmin=730,
                      xmax=810)

    zero_peak = peaks(x=wav_zero,
                      y=int_zero,
                      distance=300,
                      width=20,
                      xmin=740,
                      xmax=800)

    time_stamp = (file_name.split('_')[::-1])[0]

    if len(file_peak) == 0:
        peak = None
        peak_shift = None
    else:
        peak = float(file_peak[0])
        peak_shift = float(file_peak[0]) - float(zero_peak[0])

    return time_stamp, peak, peak_shift
Exemplo n.º 2
0
main_dir = io.config_dir_path()

exp_settings = io.exp_in(main_dir)
print(f'Experiment Settings:\n {exp_settings}\n')

for hs_img in exp_settings['hs_imgs']:
    img_dir = os.path.join(main_dir, hs_img)
    if not os.path.isdir(img_dir):
        continue
    corrected_img_dir = os.path.join(img_dir, 'corrected_imgs')

    data_files = io.extract_files(dir_name=corrected_img_dir,
                                  file_string='corrected_img_')
    print(len(data_files))

    data_cube = []

    print('\nBuilding data cube...')
    for index, file in enumerate(data_files):
        file_path = os.path.join(corrected_img_dir, file)
        corrected_img, file_name = io.array_in(file_path, mode='r')
        data_cube.append(corrected_img)

        io.update_progress(index / len(data_files))

    print('\nSaving data cube...approximately 1min per 100 imgs')
    io.array_out(array_name=data_cube,
                 file_name=f'{hs_img}_datacube',
                 dir_name=main_dir)
Exemplo n.º 3
0
            io.array_out(array_name=norm_img,
                         file_name=f'corrected_{file_name}',
                         dir_name=os.path.join(img_dir, 'corrected_imgs'))

            io.update_progress(index / len(data_files))

    if datacube:
        data_files = io.extract_files(dir_name=corrected_img_dir,
                                      file_string='corrected_img_')

        data_cube = []
        print(f'\nBuilding data cube for {hs_img}...')
        for index, file in enumerate(data_files):
            file_path = os.path.join(corrected_img_dir, file)

            corrected_img, file_name = io.array_in(file_path, mode='r')
            data_cube.append(corrected_img)

            io.update_progress(index / len(data_files))

        print('\nSaving data cube...approximately 1min per 100 images')
        io.array_out(array_name=data_cube,
                     file_name=f'{hs_img}_datacube',
                     dir_name=root)

    if fsr:
        rows, cols = dp.find_img_size(dir_name=corrected_img_dir,
                                      file_string='corrected_img_')

        data_cube = os.path.join(root, f'{hs_img}_datacube.npy')
        data_cube, file_name = io.array_in(file_path=data_cube, mode='r')