MattNolanLab / in_vivo_ephys_openephys

Analysis for in vivo electrophysiology recordings saved in open ephys format.
GNU General Public License v3.0
0 stars 0 forks source link

[BUG] Splitting bug #293

Closed klaragerlei closed 3 years ago

klaragerlei commented 3 years ago

Describe the bug It looks like there's still an issue with splitting the firing times mda file after sorting. The first recording isn't split back and has extra spikes. It mainly affects the spike histogram and avg firing rates.

I know that this recording should be around 20-30 minutes, but it's 80 on the plot: image

I also made combined plots of the histograms for multiple recordings and it's clear that the second (sleep) recording is part of the first (open field) one: image

It is clear from the splitting function why this is happening (first one isn't split back here at all). I remember having and fixing this error so I'm a bit concerned about not pushing some changes and I will investigate further.

split_firing_times_sorting_output(recording_to_sort: str, sorter_name: str, stitch_points: list): tags = control_sorting_analysis.get_tags_parameter_file(recording_to_sort) paired_recordings = control_sorting_analysis.check_for_paired(tags)

this are the firing times of the sorted clusters

firing_times_path = recording_to_sort + '/Electrophysiology/' + sorter_name + '/firings.mda'
if os.path.exists(firing_times_path):
    firing_info = mdaio.readmda(firing_times_path)

    for stitch_index, recording in enumerate(paired_recordings):
        first_half_of_local_path = '/'.join(recording_to_sort.split('/')[:-1])
        second_half = '/' + recording.split('/')[-1]
        paired_path_local = first_half_of_local_path + second_half
        sorting_output_folder = make_sorting_output_folder_for_paired_recording(paired_path_local, sorter_name)
        # split firing times file based on stitch point
        after_previous_stitch = firing_info[1] > stitch_points[stitch_index]
        before_next_stitch = firing_info[1] <= stitch_points[stitch_index + 1]
        in_recording = after_previous_stitch & before_next_stitch
        indices_in_recording = np.where(in_recording == 1)[0]
        firing_times_recording = firing_info[:, indices_in_recording]
        firing_times_recording[1] -= stitch_points[stitch_index]  # shift so they start at 0
        mdaio.writemda32(firing_times_recording, sorting_output_folder + '/firings.mda')
klaragerlei commented 3 years ago

addressed in https://github.com/MattNolanLab/in_vivo_ephys_openephys/pull/294

klaragerlei commented 3 years ago

fixed and merged