コード例 #1
0
def run_analyses(spike_data_in, synced_spatial_data, opto_analysis=False):
    snippet_data = PostSorting.load_snippet_data.get_snippets(
        spike_data_in, prm, random_snippets=False)
    spike_data = PostSorting.load_snippet_data.get_snippets(
        spike_data_in, prm, random_snippets=True)
    spike_data_spatial = PostSorting.open_field_spatial_firing.process_spatial_firing(
        spike_data, synced_spatial_data)
    spike_data_spatial = PostSorting.speed.calculate_speed_score(
        synced_spatial_data, spike_data_spatial, 250, prm.get_sampling_rate())
    hd_histogram, spatial_firing = PostSorting.open_field_head_direction.process_hd_data(
        spike_data_spatial, synced_spatial_data, prm)
    position_heat_map, spatial_firing = PostSorting.open_field_firing_maps.make_firing_field_maps(
        synced_spatial_data, spike_data_spatial, prm)
    spatial_firing = PostSorting.open_field_grid_cells.process_grid_data(
        spatial_firing)
    spatial_firing = PostSorting.open_field_firing_fields.analyze_firing_fields(
        spatial_firing, synced_spatial_data, prm)
    if opto_analysis:
        PostSorting.open_field_light_data.process_spikes_around_light(
            spike_data_spatial, prm)

    save_data_frames(spatial_firing,
                     synced_spatial_data,
                     snippet_data=snippet_data)
    save_data_for_plots(position_heat_map, hd_histogram, prm)
    make_plots(synced_spatial_data, spatial_firing, position_heat_map,
               hd_histogram, prm)
    return synced_spatial_data, spatial_firing
コード例 #2
0
def process_data(analysis_path):
    organize_data(analysis_path)
    for name in glob.glob(analysis_path + '*'):
        if os.path.isdir(name):
            if os.path.exists(name + '/spatial_firing.pkl'):
                print(name)
                prm.set_file_path(name)
                prm.set_output_path(name)
                position = pd.read_pickle(name + '/position.pkl')
                # process position data - add hd etc
                spatial_firing = pd.read_pickle(name + '/spatial_firing.pkl')

                hd = [item for sublist in spatial_firing.hd[0] for item in sublist]
                spatial_firing['hd'] = [np.array(hd) - 180]
                #if len(spatial_firing.hd) == 1:
                 #   spatial_firing['hd'] = np.array(spatial_firing.hd)
                spatial_firing['position_x_pixels'] = spatial_firing.position_x
                spatial_firing['position_y_pixels'] = spatial_firing.position_y

                prm.set_sampling_rate(1000000)  # this is to make the histograms similar to the real data
                hd_histogram, spatial_firing = PostSorting.open_field_head_direction.process_hd_data(spatial_firing, position, prm)

                # if 'firing_maps' not in spatial_firing:
                position_heat_map, spatial_firing = get_rate_maps(position, spatial_firing)

                spatial_firing = PostSorting.open_field_grid_cells.process_grid_data(spatial_firing)
                spatial_firing = PostSorting.open_field_firing_fields.analyze_firing_fields(spatial_firing, position, prm)
                spatial_firing.to_pickle(name + '/spatial_firing.pkl')
                make_plots(position, spatial_firing, position_heat_map, hd_histogram, prm)
コード例 #3
0
def post_process_recording(recording_to_process,
                           session_type,
                           sorter_name='MountainSort'):
    create_folders_for_output(recording_to_process)
    initialize_parameters(recording_to_process)
    prm.set_sorter_name('/' + sorter_name)
    prm.set_output_path(recording_to_process + prm.get_sorter_name())

    #Process position
    print('process position')
    raw_position_data, processed_position_data = process_position_data(
        recording_to_process, prm)
    print('process file properties')

    #save data
    if os.path.exists(prm.get_output_path() + '/DataFrames') is False:
        os.makedirs(prm.get_output_path() + '/DataFrames')
    # raw_position_data.to_pickle(prm.get_output_path() + '/DataFrames/raw_position_data.pkl')
    # processed_position_data.to_pickle(prm.get_output_path() + '/DataFrames/processed_position_data.pkl')
    # processed_position_data = pd.read_pickle(prm.get_output_path() + '/DataFrames/processed_position_data.pkl')

    #Process firing
    spike_data, bad_clusters = process_firing_properties(
        recording_to_process, session_type, prm)

    if len(
            spike_data
    ) == 0:  # this means that there are no good clusters and the analysis will not run
        save_data_frames(prm, spike_data, raw_position_data,
                         processed_position_data, bad_clusters)
        return

    spike_data = PostSorting.load_snippet_data.get_snippets(spike_data, prm)
    spike_data = PostSorting.vr_spatial_firing.process_spatial_firing(
        spike_data, raw_position_data)
    #spike_data = PostSorting.vr_firing_rate_maps.make_firing_field_maps_for_trial_types(spike_data, raw_position_data, processed_position_data)
    spike_data = PostSorting.vr_firing_rate_maps.make_firing_field_maps_all(
        spike_data, raw_position_data, processed_position_data)
    spike_data = PostSorting.vr_FiringMaps_InTime.control_convolution_in_time(
        spike_data, raw_position_data)
    #spike_data = PostSorting.vr_firing_maps_copy.make_firing_field_maps(raw_position_data, spike_data, prm)

    save_data_frames(prm, spike_data, raw_position_data,
                     processed_position_data, bad_clusters)
    make_plots(spike_data, raw_position_data, processed_position_data)
    gc.collect()
コード例 #4
0
def call_stable_functions(recording_to_process, session_type, analysis_type):
    # process opto data -this has to be done before splitting the session into recording and opto-tagging parts
    opto_on, opto_off, opto_is_found = process_light_stimulation(
        recording_to_process, prm)
    # process spatial data
    spatial_data, position_was_found = process_position_data(
        recording_to_process, session_type, prm)
    if position_was_found:
        synced_spatial_data = sync_data(recording_to_process, prm,
                                        spatial_data)
        # analyze spike data
        spike_data = PostSorting.load_firing_data.create_firing_data_frame(
            recording_to_process, session_type, prm)
        spike_data = PostSorting.temporal_firing.add_temporal_firing_properties_to_df(
            spike_data, prm)
        if analysis_type is 'default':
            spike_data, bad_clusters = PostSorting.curation.curate_data(
                spike_data, prm)
            if len(
                    spike_data
            ) == 0:  # this means that there are no good clusters and the analysis will not run
                save_data_frames(spike_data,
                                 synced_spatial_data,
                                 bad_clusters=bad_clusters)
                return
        spike_data = PostSorting.load_snippet_data.get_snippets(
            spike_data, prm)
        spike_data_spatial = PostSorting.open_field_spatial_firing.process_spatial_firing(
            spike_data, synced_spatial_data)
        if opto_is_found:
            PostSorting.open_field_light_data.process_spikes_around_light(
                spike_data_spatial, prm)
        spike_data_spatial = PostSorting.speed.calculate_speed_score(
            synced_spatial_data, spike_data_spatial, 250,
            prm.get_sampling_rate())
        hd_histogram, spatial_firing = PostSorting.open_field_head_direction.process_hd_data(
            spike_data_spatial, synced_spatial_data, prm)
        position_heat_map, spatial_firing = PostSorting.open_field_firing_maps.make_firing_field_maps(
            synced_spatial_data, spike_data_spatial, prm)
        spatial_firing = PostSorting.open_field_grid_cells.process_grid_data(
            spatial_firing)
        spatial_firing = PostSorting.open_field_firing_fields.analyze_firing_fields(
            spatial_firing, synced_spatial_data, prm)
        save_data_frames(spatial_firing, synced_spatial_data)
        make_plots(synced_spatial_data, spatial_firing, position_heat_map,
                   hd_histogram, prm)
コード例 #5
0
def run_analyses(spike_data_in, synced_spatial_data):
    spike_data = PostSorting.load_snippet_data.get_snippets(spike_data_in, prm)
    spike_data_spatial = PostSorting.open_field_spatial_firing.process_spatial_firing(
        spike_data, synced_spatial_data)
    spike_data_spatial = PostSorting.speed.calculate_speed_score(
        synced_spatial_data, spike_data_spatial, 250, prm.get_sampling_rate())
    hd_histogram, spatial_firing = PostSorting.open_field_head_direction.process_hd_data(
        spike_data_spatial, synced_spatial_data, prm)
    position_heat_map, spatial_firing = PostSorting.open_field_firing_maps.make_firing_field_maps(
        synced_spatial_data, spike_data_spatial, prm)
    spatial_firing = PostSorting.open_field_grid_cells.process_grid_data(
        spatial_firing)
    spatial_firing = PostSorting.open_field_firing_fields.analyze_firing_fields(
        spatial_firing, synced_spatial_data, prm)
    save_data_frames(spatial_firing, synced_spatial_data)
    make_plots(synced_spatial_data, spatial_firing, position_heat_map,
               hd_histogram, prm)
    return synced_spatial_data, spatial_firing
コード例 #6
0
def process_data(folder_to_search_in):
    prm.set_sampling_rate(
        48000)  # this is according to Sargolini et al. (2006)
    prm.set_pixel_ratio(
        100
    )  # this is because the data is already in cm so there's no need to convert
    prm.set_sorter_name('Manual')
    # prm.set_is_stable(True)  # todo: this needs to be removed - R analysis won't run for now
    for name in glob.glob(folder_to_search_in + '/*.mat'):
        if os.path.exists(name):
            if 'POS' in name:
                print('I found this:' + name)
                position_data_matlab = loadmat(name)
                position_data = get_position_data_frame(position_data_matlab)
                session_id = name.split('\\')[-1].split('_')[0]
                if position_data is not False:
                    try:
                        firing_data = pd.DataFrame()
                        create_folder_structure(name, session_id, prm)
                        firing_data = fill_firing_data_frame(
                            position_data, firing_data, name,
                            folder_to_search_in, session_id)
                        hd_histogram, spatial_firing = PostSorting.open_field_head_direction.process_hd_data(
                            firing_data, position_data, prm)
                        position_heat_map, spatial_firing = get_rate_maps(
                            position_data, firing_data)
                        spatial_firing = PostSorting.open_field_grid_cells.process_grid_data(
                            spatial_firing)
                        spatial_firing = PostSorting.open_field_firing_fields.analyze_firing_fields(
                            spatial_firing, position_data, prm)
                        save_data_frames(spatial_firing, position_data)
                        make_plots(position_data, spatial_firing,
                                   position_heat_map, hd_histogram, prm)
                    except Exception as ex:
                        print('I failed to analyze this cell.')
                        print(ex)
                        exc_type, exc_value, exc_traceback = sys.exc_info()
                        traceback.print_tb(exc_traceback)

    print('Processing finished.')
コード例 #7
0
def main():
    print('-------------------------------------------------------------')
    print('-------------------------------------------------------------')

    prm = PostSorting.parameters.Parameters()
    prm.set_pixel_ratio(440)
    prm.set_sampling_rate(30000)
    path_to_recordings = '/M5_2018-03-06_15-34-44_of'
    path_to_recordings = '/recordings/test_figures'
    prm.set_output_path(path_to_recordings + '/MountainSort/')

    position_data = pd.read_pickle(path_to_recordings +
                                   '/MountainSort/DataFrames/position.pkl')
    spatial_firing = pd.read_pickle(
        path_to_recordings + '/MountainSort/DataFrames/spatial_firing.pkl')
    position_heat_map = np.load(
        path_to_recordings + '/MountainSort/DataFrames/position_heat_map.npy')
    hd_histogram = np.load(path_to_recordings +
                           '/MountainSort/DataFrames/hd_histogram.npy')

    make_plots(position_data, spatial_firing, position_heat_map, hd_histogram,
               prm)