Exemple #1
0
def save_unit_spike_trains(units, stimulus_list, c_add_unit_figures, c_add_retina_figure,
        by='angle'):
    print("Creating bar unit spike trains")
    if by == 'angle':
        get_solid = glia.compose(
            glia.f_create_experiments(stimulus_list),
            glia.f_has_stimulus_type(["BAR"]),
            partial(sorted, key=lambda e: e["stimulus"]["angle"]),
        )
        nplots = get_nplots(stimulus_list,by)
        response = glia.apply_pipeline(get_solid,units)
        result = glia.plot_units(plot_spike_trains_by_angle,response, nplots=nplots,
            ncols=3,ax_xsize=10, ax_ysize=5,
            figure_title="Unit spike train by BAR angle")
    elif by == 'width':
        get_solid = glia.compose(
            glia.f_create_experiments(stimulus_list),
            glia.f_has_stimulus_type(["BAR"]),
            partial(sorted, key=lambda e: e["stimulus"]["width"]),
        )
        nplots = get_nplots(stimulus_list,by)
        response = glia.apply_pipeline(get_solid,units)
        result = glia.plot_units(plot_spike_trains_by_trial,response, nplots=nplots,
            ncols=3,ax_xsize=10, ax_ysize=5,
            figure_title="Unit spike train by BAR angle")


    # nplots = len(speed_widths)
    c_add_unit_figures(result)
    glia.close_figs([fig for the_id,fig in result])
Exemple #2
0
def save_acuity_chart(units, stimulus_list, c_unit_fig, c_add_retina_figure,
                      prepend, append):
    "Compare SOLID light wedge to BAR response in corresponding ascending width."

    print("Creating acuity chart v3.")
    get_solids = glia.compose(
        glia.f_create_experiments(stimulus_list,
                                  prepend_start_time=prepend,
                                  append_lifespan=append),
        glia.f_has_stimulus_type(["SOLID"]),
    )
    solids = glia.apply_pipeline(get_solids, units, progress=True)

    # offset to avoid diamond pixel artifacts
    get_bars_by_speed = glia.compose(
        glia.f_create_experiments(stimulus_list),
        glia.f_has_stimulus_type(["BAR"]),
        partial(sorted, key=lambda x: x["stimulus"]["angle"]),
        partial(sorted, key=lambda x: x["stimulus"]["width"]),
        partial(glia.group_by, key=lambda x: x["stimulus"]["speed"]))
    bars_by_speed = glia.apply_pipeline(get_bars_by_speed,
                                        units,
                                        progress=True)

    speeds = list(glia.get_unit(bars_by_speed)[1].keys())

    for speed in sorted(speeds):
        print("Plotting acuity for speed {}".format(speed))
        plot_function = partial(plot_acuity_v3,
                                prepend=prepend,
                                append=append,
                                speed=speed)
        filename = "acuity-{}".format(speed)
        result = glia.plot_units(
            plot_function,
            partial(c_unit_fig, filename),
            solids,
            bars_by_speed,
            nplots=1,
            ncols=1,
            ax_xsize=5,
            ax_ysize=15,
            figure_title="Bars with speed {}".format(speed))

        plot_function = partial(plot_dissimilarity,
                                prepend=prepend,
                                append=append,
                                speed=speed)
        filename = "dissimilarity-{}".format(speed)
        result = glia.plot_units(
            plot_function,
            partial(c_unit_fig, filename),
            solids,
            bars_by_speed,
            nplots=1,
            ncols=1,
            ax_xsize=7,
            ax_ysize=7,
            figure_title="Dissimilarity matrix for bars with speed {}".format(
                speed))
Exemple #3
0
def save_acuity_direction(units, stimulus_list, c_unit_fig,
                          c_add_retina_figure):
    "Make one direction plot per speed"
    get_direction = glia.compose(
        glia.f_create_experiments(stimulus_list),
        glia.f_has_stimulus_type(["BAR"]),
        partial(filter, lambda x: x["stimulus"]["barColor"] == "white"),
        partial(sorted, key=lambda e: e["stimulus"]["angle"]),
        partial(glia.group_by,
                key=lambda x: x["stimulus"]["speed"],
                value=lambda x: x))

    response = glia.apply_pipeline(get_direction, units, progress=True)

    speeds = list(glia.get_unit(response)[1].keys())
    nspeeds = len(speeds)

    for speed in sorted(speeds):
        print("Plotting DS for speed {}".format(speed))
        plot_function = partial(plot_unit_response_for_speed, speed=speed)
        filename = "direction-{}".format(speed)
        glia.plot_units(
            plot_function,
            partial(c_unit_fig, filename),
            response,
            subplot_kw={"projection": "polar"},
            ax_xsize=7,
            ax_ysize=7,
            figure_title="Units spike train for speed {}".format(speed),
            transpose=True)
Exemple #4
0
def f_create_experiments_test(unit, stimulus_list):
	spike_train = unit.spike_train
	create = glia.f_create_experiments(stimulus_list)
	experiments = create(spike_train)
	for e in experiments:
		time = e["stimulus"]["lifespan"]/120
		spikes = e["spikes"]
		number_of_spikes = len(spikes)
		assert time==number_of_spikes
		assert spikes[0] <= 1
def simulated_test(units, stimulus_list):
    # assert len(next(iter(units.values())).spike_train)==2200

    test_pipeline = glia.compose(glia.f_create_experiments(stimulus_list),
                                 glia.f_has_stimulus_type(["GRATING"]),
                                 glia.f_group_by_stimulus(),
                                 glia.f_calculate_firing_rate_by_stimulus())

    firing_rates = glia.apply_pipeline(test_pipeline, units, progress=True)
    for stimulus, rates in next(iter(firing_rates.values())).items():
        for rate in rates:
            assert np.isclose(rate, 60, 1)
Exemple #6
0
def save_unit_spike_trains(units, stimulus_list, c_add_unit_figures, c_add_retina_figure, prepend, append):
    print("Creating solid unit spike trains")
    
    get_solid = glia.compose(
        glia.f_create_experiments(stimulus_list,prepend_start_time=prepend,append_lifespan=append),
        glia.f_has_stimulus_type(["SOLID"]),
    )
    response = glia.apply_pipeline(get_solid,units)
    plot_function = partial(plot_spike_trains,prepend_start_time=prepend,append_lifespan=append)
    result = glia.plot_units(plot_function,response,ncols=1,ax_xsize=10, ax_ysize=5)
    c_add_unit_figures(result)
    glia.close_figs([fig for the_id,fig in result])
Exemple #7
0
def save_integrity_chart(units, stimulus_list, c_unit_fig, c_add_retina_figure):
    print("Creating integrity chart")

    get_solid = glia.compose(
        glia.f_create_experiments(stimulus_list,prepend_start_time=1,append_lifespan=2),
        glia.f_has_stimulus_type(["SOLID"]),
        filter_lifespan
    )
    response = glia.apply_pipeline(get_solid,units, progress=True)
    plot_function = partial(plot_spike_trains,prepend_start_time=1,append_lifespan=2)
    glia.plot_units(plot_function,c_unit_fig,response,ncols=1,ax_xsize=10, ax_ysize=5,
                             figure_title="Integrity Test (5 Minute Spacing)")
Exemple #8
0
def save_unit_spike_trains(units, stimulus_list, c_unit_fig, c_add_retina_figure, prepend, append):
    print("Creating solid unit spike trains")

    get_solid = glia.compose(
        glia.f_create_experiments(stimulus_list,prepend_start_time=prepend,append_lifespan=append),
        glia.f_has_stimulus_type(["SOLID"]),
    )
    response = glia.apply_pipeline(get_solid,units, progress=True)
    plot_function = partial(plot_spike_trains,prepend_start_time=prepend,append_lifespan=append)
    result = glia.plot_units(plot_function,response,ncols=1,ax_xsize=10, ax_ysize=5)
    c_unit_fig(result)
    glia.close_figs([fig for the_id,fig in result])
Exemple #9
0
def save_unit_spike_trains(units,
                           stimulus_list,
                           c_add_unit_figures,
                           c_add_retina_figure,
                           by='angle'):
    print("Creating bar unit spike trains")
    if by == 'angle':
        get_solid = glia.compose(
            glia.f_create_experiments(stimulus_list),
            glia.f_has_stimulus_type(["BAR"]),
            partial(sorted, key=lambda e: e["stimulus"]["angle"]),
        )
        nplots = get_nplots(stimulus_list, by)
        response = glia.apply_pipeline(get_solid, units, progress=True)
        result = glia.plot_units(plot_spike_trains_by_angle,
                                 response,
                                 nplots=nplots,
                                 ncols=3,
                                 ax_xsize=10,
                                 ax_ysize=5,
                                 figure_title="Unit spike train by BAR angle")
    elif by == 'width':
        get_solid = glia.compose(
            glia.f_create_experiments(stimulus_list),
            glia.f_has_stimulus_type(["BAR"]),
            partial(sorted, key=lambda e: e["stimulus"]["width"]),
        )
        nplots = get_nplots(stimulus_list, by)
        response = glia.apply_pipeline(get_solid, units, progress=True)
        result = glia.plot_units(plot_spike_trains_by_trial,
                                 response,
                                 nplots=nplots,
                                 ncols=3,
                                 ax_xsize=10,
                                 ax_ysize=5,
                                 figure_title="Unit spike train by BAR angle")

    # nplots = len(speed_widths)
    c_add_unit_figures(result)
    glia.close_figs([fig for the_id, fig in result])
Exemple #10
0
def simulated_test(units, stimulus_list):
	assert len(next(iter(units.values())).spike_train)==2200

	test_pipeline = glia.compose(
	    glia.f_create_experiments(stimulus_list),
	    glia.f_has_stimulus_type(["GRATING"]),
	    glia.f_group_by_stimulus(),
	    glia.f_calculate_firing_rate_by_stimulus()
	)

	firing_rates = glia.apply_pipeline(test_pipeline, units)
	for stimulus,rates in next(iter(firing_rates.values())).items():
		for rate in rates:
			assert rate==1
Exemple #11
0
def save_unit_psth(units, stimulus_list, c_add_unit_figures, c_add_retina_figure, prepend, append):
    print("Creating solid unit PSTH")

    get_psth = glia.compose(
        glia.f_create_experiments(stimulus_list,prepend_start_time=prepend,append_lifespan=append),
        glia.f_has_stimulus_type(["SOLID"]),
        glia.f_group_by_stimulus(),
        glia.concatenate_by_stimulus
    )
    psth = glia.apply_pipeline(get_psth,units)
    plot_function = partial(plot_psth,prepend_start_time=prepend,append_lifespan=append)
    result = glia.plot_units(partial(plot_function,bin_width=0.01),psth,ax_xsize=10, ax_ysize=5)
    c_add_unit_figures(result)
    glia.close_figs([fig for the_id,fig in result])
Exemple #12
0
def save_unit_psth(units, stimulus_list, c_unit_fig, c_add_retina_figure, prepend, append):
    print("Creating solid unit PSTH")

    get_psth = glia.compose(
        glia.f_create_experiments(stimulus_list,prepend_start_time=prepend,append_lifespan=append),
        glia.f_has_stimulus_type(["SOLID"]),
        glia.f_group_by_stimulus(),
        glia.concatenate_by_stimulus
    )
    psth = glia.apply_pipeline(get_psth,units, progress=True)
    plot_function = partial(plot_psth,prepend_start_time=prepend,append_lifespan=append)
    result = glia.plot_units(partial(plot_function,bin_width=0.01),psth,ax_xsize=10, ax_ysize=5)
    c_unit_fig(result)
    glia.close_figs([fig for the_id,fig in result])
Exemple #13
0
def save_raster(units, stimulus_list, c_unit_fig, c_add_retina_figure,
        sort_by=glia.group_lifespan):
    print("Creating spike train raster plot")
    
    get_solid = glia.compose(
        glia.f_create_experiments(stimulus_list),
        partial(glia.group_by,
            key=lambda x: x["stimulus"]["metadata"]["group"]),
        glia.group_dict_to_list,
        partial(sorted,key=sort_by)
    )
    response = glia.apply_pipeline(get_solid,units, progress=True)
    glia.plot_units(glia.raster_group,c_unit_fig,response,nplots=1,
        ncols=1,ax_xsize=15, ax_ysize=10)
Exemple #14
0
def save_unit_wedges_v2(units, stimulus_list, c_unit_fig, c_add_retina_figure):
    print("Creating solid unit wedges")

    get_solid = glia.compose(
        glia.f_create_experiments(stimulus_list),
        glia.f_has_stimulus_type(["SOLID","WAIT"]),
        partial(glia.group_by,
            key=lambda x: x["stimulus"]["metadata"]["group"]),
        glia.group_dict_to_list,
        partial(sorted,key=lambda x: get_lifespan(x[1]))
    )
    response = glia.apply_pipeline(get_solid,units, progress=True)

    glia.plot_units(plot_spike_train_triplet,c_unit_fig,response,nplots=1,
        ncols=1,ax_xsize=10, ax_ysize=5)
Exemple #15
0
def save_unit_kinetics(units, stimulus_list, c_unit_fig, c_add_retina_figure):
    print("Creating solid unit kinetics")

    get_solid = glia.compose(
        glia.f_create_experiments(stimulus_list),
        partial(glia.group_by,
            key=lambda x: x["stimulus"]["metadata"]["group"]),
        glia.group_dict_to_list,
        partial(sorted,key=lambda x: get_lifespan(x[2]))
    )
    response = glia.apply_pipeline(get_solid,units, progress=True)

    # glia.plot_units(plot_group_spike_train,c_unit_fig,response,nplots=1,
    #     ncols=1,ax_xsize=10, ax_ysize=5)
    glia.plot_units(glia.raster_group,c_unit_fig,response,nplots=1,
        ncols=1,ax_xsize=10, ax_ysize=5)
Exemple #16
0
def save_unit_kinetics_v1(units, stimulus_list, c_unit_fig, c_add_retina_figure):
    print("Creating solid unit kinetics")


    for i in range(5):
        s = i*150
        e = (i+1)*150
        get_solid = glia.compose(
            glia.f_create_experiments(stimulus_list),
            lambda x: x[s:e],
            partial(glia.group_by,
                key=lambda x: x["stimulus"]["metadata"]["group"]),
            glia.group_dict_to_list,
            partial(sorted,key=lambda x: get_lifespan(x[2]))
        )
        response = glia.apply_pipeline(get_solid,units, progress=True)
        c = partial(c_unit_fig,"kinetics-{}".format(i))
        glia.plot_units(glia.raster_group,c,response,nplots=1,
            ncols=1,ax_xsize=10, ax_ysize=5)
Exemple #17
0
def save_unit_wedges(units, stimulus_list, c_unit_fig, c_add_retina_figure, prepend, append):
    print("Creating solid unit wedges")

    get_solid = glia.compose(
        glia.f_create_experiments(stimulus_list,prepend_start_time=prepend,append_lifespan=append),
        glia.f_has_stimulus_type(["SOLID"]),
        partial(sorted,key=lambda x: x["stimulus"]["lifespan"])
    )
    response = glia.apply_pipeline(get_solid,units, progress=True)

    colors = set()
    for solid in glia.get_unit(response)[1]:
        colors.add(solid["stimulus"]["backgroundColor"])
    ncolors = len(colors)

    plot_function = partial(plot_spike_trains,prepend_start_time=prepend,
        append_lifespan=append)
    glia.plot_units(plot_function,c_unit_fig,response,nplots=ncolors,
        ncols=min(ncolors,5),ax_xsize=10, ax_ysize=5)
Exemple #18
0
def get_fr_dsi_osi(units, stimulus_list):

    get_bar_firing_rate = glia.compose(
        glia.f_create_experiments(stimulus_list),
        glia.f_has_stimulus_type(["BAR"]),
        glia.f_group_by_stimulus(),
        glia.f_calculate_firing_rate_by_stimulus(),
    )
    bar_firing_rate = glia.apply_pipeline(get_bar_firing_rate,
                                          units,
                                          progress=True)

    get_bar_dsi = glia.compose(glia.by_speed_width_then_angle,
                               glia.calculate_dsi_by_speed_width)
    bar_dsi = glia.apply_pipeline(get_bar_dsi, bar_firing_rate, progress=True)

    get_bar_osi = glia.compose(glia.by_speed_width_then_angle,
                               glia.calculate_osi_by_speed_width)
    bar_osi = glia.apply_pipeline(get_bar_osi, bar_firing_rate, progress=True)

    return (bar_firing_rate, bar_dsi, bar_osi)
Exemple #19
0
def save_integrity_chart_vFail(units, stimulus_list, c_unit_fig, c_add_retina_figure):
    print("Creating integrity chart")
    get_solid = glia.compose(
        glia.f_create_experiments(stimulus_list),
        glia.filter_integrity,
        partial(glia.group_by,
            key=lambda x: x["stimulus"]["metadata"]["group"]),
        glia.group_dict_to_list,
        integrity_fix_hack,
        partial(sorted,key=lambda x: x[0]["stimulus"]["stimulusIndex"])
        )

    response = glia.apply_pipeline(get_solid,units, progress=True)
    plot_function = partial(glia.raster_group)
    # c = partial(c_unit_fig,"kinetics-{}".format(i))

    glia.plot_units(plot_function,c_unit_fig,response,ncols=1,ax_xsize=10, ax_ysize=5,
                             figure_title="Integrity Test (5 Minute Spacing)")

    units_accuracy = glia.pmap(ideal_unit_classification_accuracy, response)
    c_add_retina_figure("integrity_accuracy",plot_units_accuracy(units_accuracy))
Exemple #20
0
def filter_units_by_accuracy(units, stimulus_list, threshold=0.8):
    ntrial = len(list(filter(
        lambda x: 'metadata' in x['stimulus'] and "label" in x['stimulus']['metadata'] and \
            x['stimulus']['metadata']['label']=='integrity',
        stimulus_list)))/3
    ntrain = int(np.ceil(ntrial/2))
    ntest = int(np.floor(ntrial/2))
    tvt = glia.TVT(ntrain,ntest,0)

    get_solid = glia.compose(
        glia.f_create_experiments(stimulus_list),
        glia.filter_integrity,
        partial(glia.group_by,
            key=lambda x: x["stimulus"]["metadata"]["group"]),
        glia.group_dict_to_list,
        glia.f_split_list(tvt)
    )

    classification_data = glia.apply_pipeline(get_solid,units, progress=True)
    units_accuracy = glia.pmap(unit_classification_accuracy,classification_data)
    filter_threshold = glia.f_filter(lambda k,x: x['on']>threshold or x['off']>threshold)
    return set(filter_threshold(units_accuracy).keys())
Exemple #21
0
def save_integrity_chart_v2(units, stimulus_list, c_unit_fig, c_add_retina_figure):
    print("Creating integrity chart")
    get_integrity= glia.compose(
        glia.f_create_experiments(stimulus_list),
        glia.filter_integrity,
        partial(glia.group_by,
            key=lambda x: x["stimulus"]["metadata"]["group"]),
        glia.group_dict_to_list,
        )
    response = glia.apply_pipeline(get_integrity,units, progress=True)
    chronological = glia.apply_pipeline(
        partial(sorted,key=lambda x: x[0]["stimulus"]["stimulusIndex"]),
        response)

    plot_function = partial(glia.raster_group)
    # c = partial(c_unit_fig,"kinetics-{}".format(i))

    glia.plot_units(plot_function,c_unit_fig,chronological,ncols=1,ax_xsize=10, ax_ysize=5,
                             figure_title="Integrity Test (5 Minute Spacing)")

    ntrial = len(glia.get_unit(response)[1])
    ntrain = int(np.ceil(ntrial/2))
    ntest = int(np.floor(ntrial/2))
    tvt = glia.TVT(ntrain,ntest,0)
    classification_data = glia.apply_pipeline(
        glia.f_split_list(tvt),
        response)

    units_accuracy = glia.pmap(unit_classification_accuracy,classification_data)
    plot_directory = os.path.join(config.plot_directory,"00-all")
    os.makedirs(plot_directory, exist_ok=True)
    with open(plot_directory + "/best_units.txt", "w") as f:
        sorted_units = sorted(units_accuracy.items(),
            key=lambda z: max(z[1]["off"],z[1]["on"]),
            reverse=True)
        for u in sorted_units:
            f.write(str(u)+"\n")
    c_add_retina_figure("integrity_accuracy",plot_units_accuracy(units_accuracy))
Exemple #22
0
def save_unit_spike_trains(units,
                           stimulus_list,
                           c_unit_fig,
                           c_add_retina_figure,
                           width=None,
                           height=None):
    print("Creating grating unit spike trains")

    get_solid = glia.compose(glia.f_create_experiments(stimulus_list),
                             glia.f_has_stimulus_type(["GRATING"]),
                             glia.f_split_by_wavelength())
    response = glia.apply_pipeline(get_solid, units, progress=True)

    nplots = len(glia.get_unit(response)[1])
    result = glia.plot_units(
        plot_spike_trains,
        response,
        nplots=nplots,
        ncols=3,
        ax_xsize=10,
        ax_ysize=5,
        figure_title="Unit spike train by GRATING waveperiod")
    c_unit_fig(result)
    glia.close_figs([fig for the_id, fig in result])
Exemple #23
0
def get_fr_dsi_osi(units, stimulus_list):

    get_bar_firing_rate = glia.compose(
        glia.f_create_experiments(stimulus_list),
        glia.f_has_stimulus_type(["BAR"]),
        glia.f_group_by_stimulus(),
        glia.f_calculate_firing_rate_by_stimulus(),
    )
    bar_firing_rate = glia.apply_pipeline(get_bar_firing_rate,units)

    get_bar_dsi = glia.compose(
        glia.by_speed_width_then_angle,
        glia.calculate_dsi_by_speed_width
    )
    bar_dsi = glia.apply_pipeline(get_bar_dsi,bar_firing_rate)

    get_bar_osi = glia.compose(
        glia.by_speed_width_then_angle,
        glia.calculate_osi_by_speed_width
    )
    bar_osi = glia.apply_pipeline(get_bar_osi,bar_firing_rate)


    return (bar_firing_rate, bar_dsi, bar_osi)