예제 #1
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))
예제 #2
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)
예제 #3
0
def save_unit_response_by_angle(units, stimulus_list, c_unit_fig,
                                c_add_retina_figure):
    print("Calculating DSI & OSI")
    bar_firing_rate, bar_dsi, bar_osi = get_fr_dsi_osi(units, stimulus_list)

    print("plotting unit response by angle")
    analytics = glia.by_speed_width_then_angle(
        glia.get_unit(bar_firing_rate)[1])
    nplots = len(list(analytics.keys()))
    del analytics

    if nplots > 1:
        ncols = 3
    else:
        ncols = 1

    result = glia.plot_units(plot_unit_response_by_angle,
                             partial(c_unit_fig, "angle"),
                             bar_firing_rate,
                             bar_dsi,
                             bar_osi,
                             nplots=nplots,
                             subplot_kw={"projection": "polar"},
                             ax_xsize=4,
                             ax_ysize=5,
                             ncols=3)
    # c_unit_fig(result)
    # glia.close_figs([fig for the_id,fig in result])

    print("plotting unit DSI/OSI table")
    result = glia.plot_units(plot_unit_dsi_osi_table,
                             partial(c_unit_fig, "selectivity_table"),
                             bar_firing_rate,
                             bar_dsi,
                             bar_osi,
                             ax_xsize=16,
                             ax_ysize=3)
    # c_unit_fig(result)
    # glia.close_figs([fig for the_id,fig in result])

    fig_population, ax = plt.subplots(2, 1)
    print("plotting population by DSI & OSI")
    plot_population_dsi_osi(fig_population, ax, (bar_dsi, bar_osi))
    c_add_retina_figure("DSI_OSI", fig_population)
    plt.close(fig_population)
예제 #4
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)
예제 #5
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))
예제 #6
0
파일: bar.py 프로젝트: tbenst/glia
def save_unit_response_by_angle(units, stimulus_list, c_add_unit_figures, c_add_retina_figure):
    print("Calculating DSI & OSI")
    bar_firing_rate, bar_dsi, bar_osi = get_fr_dsi_osi(units, stimulus_list)

    print("plotting unit response by angle")
    analytics = glia.by_speed_width_then_angle(glia.get_unit(bar_firing_rate)[1])
    nplots = len(list(analytics.keys()))
    del analytics

    if nplots>1:
        ncols=3
    else:
        ncols=1

    result = glia.plot_units(plot_unit_response_by_angle,
        bar_firing_rate,bar_dsi,bar_osi,
        nplots=nplots, subplot_kw={"projection": "polar"},
        ax_xsize=4, ax_ysize=5, ncols=3)
    c_add_unit_figures(result)
    glia.close_figs([fig for the_id,fig in result])


    print("plotting unit DSI/OSI table")
    result = glia.plot_units(plot_unit_dsi_osi_table,
        bar_firing_rate,bar_dsi,bar_osi,
        ax_xsize=6, ax_ysize=4)
    c_add_unit_figures(result)
    glia.close_figs([fig for the_id,fig in result])



    fig_population,ax = plt.subplots(2,1)
    print("plotting population by DSI & OSI")
    plot_population_dsi_osi(ax, (bar_dsi, bar_osi))
    c_add_retina_figure(fig_population)
    plt.close(fig_population)
예제 #7
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])