def run():
    data_folder = r"\\allen\programs\braintv\workgroups\nc-ophys\Jun\raw_data_rabies_project" \
                  r"\180404-M360495-2p\2p_movie\reorged"

    curr_folder = os.path.dirname(os.path.realpath(__file__))
    os.chdir(curr_folder)

    mc.motion_correction(input_folder=data_folder,
                         input_path_identifier='.tif',
                         process_num=6,
                         output_folder=os.path.join(data_folder, 'corrected'),
                         anchor_frame_ind_chunk=10,
                         anchor_frame_ind_projection=0,
                         iteration_chunk=10,
                         iteration_projection=10,
                         max_offset_chunk=(40., 40.),
                         max_offset_projection=(40., 40.),
                         align_func=mc.phase_correlation,
                         preprocessing_type=0,
                         fill_value=0.)

    offsets_path = os.path.join(data_folder, 'corrected', 'correction_offsets.hdf5')
    fns = [f for f in os.listdir(data_folder) if f[-4:] == '.tif']
    fns.sort()
    f_paths = [os.path.join(data_folder, f) for f in fns]
    print('\nfile paths:')
    print('\n'.join(f_paths))

    mc.apply_correction_offsets(offsets_path=offsets_path,
                                path_pairs=zip(f_paths, f_paths),
                                output_folder=os.path.join(data_folder, 'corrected'),
                                process_num=6,
                                fill_value=0.,
                                avi_downsample_rate=10,
                                is_equalizing_histogram=True)
def run():
    data_folder = r"\\allen\programs\braintv\workgroups\nc-ophys\Jun\raw_data_rabies_project" \
                  r"\180104-M361012-2p\FOV1_injection_site_00001"
    ref_ch_n = 'red'
    apply_ch_ns = ['green', 'red']

    curr_folder = os.path.dirname(os.path.realpath(__file__))
    os.chdir(curr_folder)

    ref_data_folder = os.path.join(data_folder, ref_ch_n)

    mc.motion_correction(input_folder=ref_data_folder,
                         input_path_identifier='.tif',
                         process_num=3,
                         output_folder=os.path.join(ref_data_folder,
                                                    'corrected'),
                         anchor_frame_ind_chunk=10,
                         anchor_frame_ind_projection=0,
                         iteration_chunk=10,
                         iteration_projection=10,
                         max_offset_chunk=(20., 20.),
                         max_offset_projection=(20., 20.),
                         align_func=mc.phase_correlation,
                         preprocessing_type=0,
                         fill_value=0.)

    offsets_path = os.path.join(ref_data_folder, 'corrected',
                                'correction_offsets.hdf5')
    ref_fns = [f for f in os.listdir(ref_data_folder) if f[-4:] == '.tif']
    ref_fns.sort()
    ref_paths = [os.path.join(ref_data_folder, f) for f in ref_fns]
    print('\nreference paths:')
    print('\n'.join(ref_paths))

    for apply_ch_i, apply_ch_n in enumerate(apply_ch_ns):
        apply_data_folder = os.path.join(data_folder, apply_ch_n)
        apply_fns = [
            f for f in os.listdir(apply_data_folder) if f[-4:] == '.tif'
        ]
        apply_fns.sort()
        apply_paths = [os.path.join(apply_data_folder, f) for f in apply_fns]
        print('\napply paths:')
        print('\n'.join(apply_paths))

        mc.apply_correction_offsets(offsets_path=offsets_path,
                                    path_pairs=zip(ref_paths, apply_paths),
                                    output_folder=os.path.join(
                                        apply_data_folder, 'corrected'),
                                    process_num=3,
                                    fill_value=0.,
                                    avi_downsample_rate=20,
                                    is_equalizing_histogram=False)
示例#3
0
def correct(data_folder):

    ref_ch_n = 'red'
    apply_ch_ns = ['green', 'red']

    curr_folder = os.path.dirname(os.path.realpath(__file__))
    os.chdir(curr_folder)

    ref_data_folder = os.path.join(data_folder, ref_ch_n)

    mc.motion_correction(input_folder=ref_data_folder,
                         input_path_identifier='.tif',
                         process_num=6,
                         output_folder=os.path.join(ref_data_folder,
                                                    'corrected'),
                         anchor_frame_ind_chunk=10,
                         anchor_frame_ind_projection=0,
                         iteration_chunk=10,
                         iteration_projection=10,
                         max_offset_chunk=(100., 100.),
                         max_offset_projection=(100., 100.),
                         align_func=mc.phase_correlation,
                         preprocessing_type=6,
                         fill_value=0.)

    offsets_path = os.path.join(ref_data_folder, 'corrected',
                                'correction_offsets.hdf5')
    ref_fns = [f for f in os.listdir(ref_data_folder) if f[-4:] == '.tif']
    ref_fns.sort()
    ref_paths = [os.path.join(ref_data_folder, f) for f in ref_fns]
    print('\nreference paths:')
    print('\n'.join(ref_paths))

    for apply_ch_i, apply_ch_n in enumerate(apply_ch_ns):
        apply_data_folder = os.path.join(data_folder, apply_ch_n)
        apply_fns = [
            f for f in os.listdir(apply_data_folder) if f[-4:] == '.tif'
        ]
        apply_fns.sort()
        apply_paths = [os.path.join(apply_data_folder, f) for f in apply_fns]
        print('\napply paths:')
        print('\n'.join(apply_paths))

        mc.apply_correction_offsets(offsets_path=offsets_path,
                                    path_pairs=zip(ref_paths, apply_paths),
                                    output_folder=os.path.join(
                                        apply_data_folder, 'corrected'),
                                    process_num=6,
                                    fill_value=0.,
                                    avi_downsample_rate=10,
                                    is_equalizing_histogram=False)
def correct_single_step(param):

    folder_ref, anchor_frame_ind_chunk, iteration_chunk, max_offset_chunk, preprocessing_type, fill_value,\
        is_apply, avi_downsample_rate, is_equalizing_histogram= param

    step_n = os.path.split(folder_ref)[1]
    print('\nStart correcting step {} ...'.format(step_n))

    mov_ref_n = [f for f in os.listdir(folder_ref) if f[-4:] == '.tif' and step_n in f]
    if len(mov_ref_n) != 1:
        warn('step {}: number of green movie does not equal 1.'.format(step_n))
        return

    mov_paths, _ = mc.motion_correction(input_folder=folder_ref,
                                        input_path_identifier='.tif',
                                        process_num=1,
                                        output_folder=folder_ref,
                                        anchor_frame_ind_chunk=anchor_frame_ind_chunk,
                                        anchor_frame_ind_projection=0,
                                        iteration_chunk=iteration_chunk,
                                        iteration_projection=10,
                                        max_offset_chunk=max_offset_chunk,
                                        max_offset_projection=(30., 30.),
                                        align_func=mc.phase_correlation,
                                        preprocessing_type=preprocessing_type,
                                        fill_value=fill_value)

    if is_apply:

        offsets_path = os.path.join(folder_ref, 'correction_offsets.hdf5')
        offsets_f = h5py.File(offsets_path)
        ref_path = offsets_f['file_0000'].attrs['path']
        offsets_f.close()

        movie_path = mov_paths[0]

        mc.apply_correction_offsets(offsets_path=offsets_path,
                                    path_pairs=[[ref_path, movie_path]],
                                    output_folder=folder_ref,
                                    process_num=1,
                                    fill_value=fill_value,
                                    avi_downsample_rate=avi_downsample_rate,
                                    is_equalizing_histogram=is_equalizing_histogram)
示例#5
0
def run():

    data_folder = r"\\allen\programs\braintv\workgroups\nc-ophys\Jun\raw_data_rabies_project" \
                  r"\180328-M360495-deepscope\04\04_"

    curr_folder = os.path.dirname(os.path.realpath(__file__))
    os.chdir(curr_folder)

    plane_ns = [p for p in os.listdir(data_folder) if os.path.isdir(os.path.join(data_folder, p))]
    plane_ns.sort()
    print('planes:')
    print('\n'.join(plane_ns))

    for plane_n in plane_ns:
        print('\nprocessing plane: {}'.format(plane_n))
        plane_folder = os.path.join(data_folder, plane_n)
        f_paths, _ = mc.motion_correction(input_folder=plane_folder,
                                          input_path_identifier='.tif',
                                          process_num=3,
                                          output_folder=os.path.join(plane_folder, 'corrected'),
                                          anchor_frame_ind_chunk=10,
                                          anchor_frame_ind_projection=0,
                                          iteration_chunk=10,
                                          iteration_projection=10,
                                          max_offset_chunk=(50., 50.),
                                          max_offset_projection=(50., 50.),
                                          align_func=mc.phase_correlation,
                                          preprocessing_type=0,
                                          fill_value=0.)

        offsets_path = os.path.join(plane_folder, 'corrected', 'correction_offsets.hdf5')

        mc.apply_correction_offsets(offsets_path=offsets_path,
                                    path_pairs=zip(f_paths, f_paths),
                                    output_folder=os.path.join(plane_folder, 'corrected'),
                                    process_num=3,
                                    fill_value=0.,
                                    avi_downsample_rate=20,
                                    is_equalizing_histogram=True)
示例#6
0
avi_downsample_rate = 20

sub_folder_ns = [f for f in os.listdir(data_folder) if os.path.isdir(os.path.join(data_folder, f))]
sub_folder_ns.sort()
print('\n'.join(sub_folder_ns))

for sub_folder_n in sub_folder_ns:

    sub_folder = os.path.join(data_folder, sub_folder_n)

    f_paths, _ = mc.motion_correction(input_folder=sub_folder,
                                      input_path_identifier=input_path_identifier,
                                      process_num=process_num,
                                      output_folder=sub_folder,
                                      anchor_frame_ind_chunk=anchor_frame_ind_chunk,
                                      anchor_frame_ind_projection=anchor_frame_ind_projection,
                                      iteration_chunk=iteration_chunk,
                                      iteration_projection=iteration_projection,
                                      max_offset_chunk=max_offset_chunk,
                                      max_offset_projection=max_offset_projection,
                                      align_func=align_func,
                                      fill_value=fill_value)

    print('\n'.join(f_paths))

    offsets_path = os.path.join(sub_folder, 'correction_offsets.hdf5')
    path_pairs = zip(f_paths, f_paths)
    mc.apply_correction_offsets(offsets_path=offsets_path,
                                path_pairs=path_pairs,
                                process_num=process_num,
                                fill_value=fill_value,
                                output_folder=sub_folder,