Exemplo n.º 1
0
def plot_spike_trains_by_trial(axis_gen, data):
    "ignores angle, assumes data is sorted by width"
    # we will use a different axis for each speed_width & repetition
    axes = {}
    for d in data:
        stimulus = d["stimulus"]
        spike_train = d['spikes']
        speed_width = (stimulus["speed"], stimulus["width"])

        try:
            ax, trial = axes[speed_width]
            axes[speed_width] = (ax, trial + 1)
        except:
            ax = next(axis_gen)
            if speed_width not in axes:
                axes[speed_width] = None
            trial = 0
            axes[speed_width] = (ax, trial)

        if spike_train.size > 0:
            glia.draw_spikes(ax, spike_train, ymin=trial + 0.3, ymax=trial + 1)
    for speed_width, tup in axes.items():
        ax, trial = tup
        ax.set_title("Speed: {}, Width: {}".format(speed_width[0],
                                                   speed_width[1]))
        ax.set_xlabel("Time (s)")
        ax.set_xlim([0, stimulus['lifespan']])
        # trial is now the count
        ax.set_ylim([0, trial])
        ax.set_ylabel("Trial #")
Exemplo n.º 2
0
Arquivo: solid.py Projeto: tbenst/glia
def plot_spike_trains(axis_gen,data,prepend_start_time=1,append_lifespan=1):
    ax = next(axis_gen)
    trial = 0
    for v in data:
        # print(type(v))
        stimulus, spike_train = (v["stimulus"], v["spikes"])
        lifespan = stimulus['lifespan'] / 120
        if lifespan > 10:
            print("skipping stimulus longer than 10 seconds")
            continue
        if spike_train.size>0:
            glia.draw_spikes(ax, spike_train, ymin=trial+0.3,ymax=trial+1)
        
        stimulus_end = prepend_start_time + lifespan
        duration = stimulus_end + append_lifespan
        ax.fill([0,prepend_start_time,prepend_start_time,0],
                [trial,trial,trial+1,trial+1],
                facecolor="gray", edgecolor="none", alpha=0.1)
        ax.fill([stimulus_end,duration,duration,stimulus_end],
                [trial,trial,trial+1,trial+1],
                facecolor="gray", edgecolor="none", alpha=0.1)
        trial += 1
        
    ax.set_title("Unit spike train per SOLID")
    ax.set_xlabel("time (s)")
    ax.set_ylabel("trials")
Exemplo n.º 3
0
Arquivo: bar.py Projeto: tbenst/glia
def plot_spike_trains_by_trial(axis_gen,data):
    "ignores angle, assumes data is sorted by width"
    # we will use a different axis for each speed_width & repetition
    axes = {}
    for d in data:
        stimulus = d["stimulus"]
        spike_train = d['spikes']
        speed_width = (stimulus["speed"], stimulus["width"])

        try:
            ax,trial = axes[speed_width]
            axes[speed_width] = (ax, trial+1)
        except:
            ax = next(axis_gen)
            if speed_width not in axes:
                axes[speed_width] = None
            trial = 0
            axes[speed_width] = (ax,trial)

        if spike_train.size>0:
            glia.draw_spikes(ax, spike_train, ymin=trial+0.3,ymax=trial+1)        
    for speed_width, tup in axes.items():
        ax, trial = tup
        ax.set_title("Speed: {}, Width: {}".format(
            speed_width[0],speed_width[1]))
        ax.set_xlabel("Time (s)")
        ax.set_xlim([0,stimulus['lifespan']/120])
        # trial is now the count
        ax.set_ylim([0,trial])
        ax.set_ylabel("Trial #")
Exemplo n.º 4
0
def plot_spike_trains_vFail(fig, axis_gen, data):
    # remove this function asap
    ax = next(axis_gen)

    trial = 0
    # forgot to change group id, so iterate triplets
    for i in range(0, len(data)-1, 3):
        # x offset for row
        offset = 0

        for v in data[i:i+3]:
            stimulus, spike_train = (v["stimulus"], v["spikes"])
            lifespan = stimulus['lifespan']
            end_time = lifespan + offset
            if lifespan > 20:
                logger.warning("skipping stimulus longer than 20 seconds")
                continue
            if spike_train.size>0:
                glia.draw_spikes(ax, spike_train+offset, ymin=trial+0.3,
                    ymax=trial+1)

            ax.fill([offset,end_time,end_time,offset],
                    [trial,trial,trial+1,trial+1],
                    facecolor=stimulus["backgroundColor"], edgecolor="none", alpha=0.1)
            offset = end_time
        trial += 1


    ax.set_title("Unit spike train per SOLID group")
    ax.set_xlabel("time (s)")
    ax.set_ylabel("trials")
Exemplo n.º 5
0
def plot_spike_train_triplet(fig, axis_gen, data):
    #
    ax = next(axis_gen)
    trial = 0
    # hardcoded 2 must correspond to pivot
    longest_group = max(map(lambda x: get_lifespan(x[1]),
        data)) + 2
    for group in data:
        # x offset for row
        offset = 0
        for i,v in enumerate(group):
            stimulus, spike_train = (v["stimulus"], v["spikes"])
            lifespan = stimulus['lifespan']

            if i==0:
                # only show last second before middle stimuli
                pivot = lifespan-1
                if pivot<0:
                    logger.error("first stimuli is too short--must be >1s")
                    pivot = 0
                spike_train = spike_train[spike_train>pivot] - pivot
                end_time = 1
            elif i==1:
                end_time = lifespan + offset
            elif i==2:
                # only show last second before middle stimuli
                spike_train = spike_train[spike_train<1]
                end_time = 1 + offset

            if lifespan > 20:
                logger.warning("skipping stimulus longer than 20 seconds")
                continue
            if spike_train.size>0:
                glia.draw_spikes(ax, spike_train+offset, ymin=trial+0.3,
                    ymax=trial+1)

            ax.fill([offset,end_time,end_time,offset],
                    [trial,trial,trial+1,trial+1],
                    facecolor=stimulus["backgroundColor"],
                    edgecolor="none", alpha=0.1)
            offset = end_time

        if offset<longest_group:
            ax.fill([offset,longest_group,longest_group,offset],
                    [trial,trial,trial+1,trial+1],
                    facecolor="black",
                    edgecolor="none", alpha=1)

        trial += 1


    ax.set_title("Unit spike train per SOLID group")
    ax.set_xlabel("time (s)")
    ax.set_ylabel("trials")
    ax.set_xlim((0,longest_group))
    ax.set_ylim((0,trial))
Exemplo n.º 6
0
def plot_spike_trains_by_angle(axis_gen, data):
    "assumes data is sorted by angle"
    # we will use a different axis for each speed_width & repetition
    axes = {}
    y = 0
    trial = 0
    current_angle = None
    for d in data:
        stimulus = d["stimulus"]
        spike_train = d['spikes']
        speed_width = (stimulus["speed"], stimulus["width"])
        angle = stimulus["angle"]

        if angle != current_angle:
            trial = 0
            y += 1
            current_angle = angle
        else:
            # same angle, next trial
            trial += 1

        try:
            ax = axes[speed_width][trial][0]
        except:
            ax = next(axis_gen)
            if speed_width not in axes:
                axes[speed_width] = {}
            axes[speed_width][trial] = (ax, stimulus["lifespan"])

        if spike_train.size > 0:
            glia.draw_spikes(ax, spike_train, ymin=y + 0.3, ymax=y + 1)

    for speed_width, trial in axes.items():
        for trial, v in trial.items():
            ax, duration = v
            ax.set_title("Trial: {}, Speed: {}, Width: {}".format(
                trial + 1, speed_width[0], speed_width[1]))
            ax.set_xlabel("Time (s)")
            ax.set_xlim([0, duration])
            ax.set_ylabel("Bar Angle")
            ax.set_yticks(np.linspace(0, y + 1, 9))
            ax.set_yticklabels([
                0, "45°", "90°", "135°", "180°", "225°", "270°", "315°", "360°"
            ])
Exemplo n.º 7
0
Arquivo: bar.py Projeto: tbenst/glia
def plot_spike_trains_by_angle(axis_gen,data):
    "assumes data is sorted by angle"
    # we will use a different axis for each speed_width & repetition
    axes = {}
    y = 0
    trial = 0
    current_angle = None
    for d in data:
        stimulus = d["stimulus"]
        spike_train = d['spikes']
        speed_width = (stimulus["speed"], stimulus["width"])
        angle = stimulus["angle"]

        if angle!=current_angle:
            trial = 0
            y += 1
            current_angle = angle
        else:
            # same angle, next trial
            trial+=1

        try:
            ax = axes[speed_width][trial][0]
        except:
            ax = next(axis_gen)
            if speed_width not in axes:
                axes[speed_width] = {}
            axes[speed_width][trial] = (ax,stimulus["lifespan"]/120)

        if spike_train.size>0:
            glia.draw_spikes(ax, spike_train, ymin=y+0.3,ymax=y+1)

    for speed_width, trial in axes.items():
        for trial, v in trial.items():
            ax, duration = v
            ax.set_title("Trial: {}, Speed: {}, Width: {}".format(
                trial+1,speed_width[0], speed_width[1]))
            ax.set_xlabel("Time (s)")
            ax.set_xlim([0,duration])
            ax.set_ylabel("Bar Angle")
            ax.set_yticks(np.linspace(0,y+1,9))
            ax.set_yticklabels([0,"45°","90°","135°","180°","225°","270°","315°","360°"])
Exemplo n.º 8
0
def plot_spike_trains(axis_gen, data):
    for d in data:
        ax = next(axis_gen)
        stimulus = d["stimulus"]
        train_list = d["train_list"]

        trial = 0
        for spike_train in train_list:
            if spike_train.size > 0:
                glia.draw_spikes(ax,
                                 spike_train,
                                 ymin=trial + 0.3,
                                 ymax=trial + 1)
            trial += 1

        ax.set_title(
            "speed={}, width={}, wavelength={}, angle={}, barColor={}".format(
                stimulus["speed"], stimulus["width"], stimulus["wavelength"],
                stimulus["angle"], stimulus["barColor"]))
        ax.set_xlabel("relative time (s)")
        ax.set_ylabel("period # (lower is earlier)")
Exemplo n.º 9
0
def plot_spike_trains(fig, axis_gen, data,prepend_start_time=1,append_lifespan=1):
    colors = set()
    for e in data:
        color = e["stimulus"]["backgroundColor"]
        colors.add(color)

    sorted_colors = sorted(list(colors),reverse=True)

    for color in sorted_colors:
        ax = next(axis_gen)
        filtered_data = list(filter(lambda x: x["stimulus"]["backgroundColor"]==color,
            data))
        trial = 0

        for v in filtered_data:
            # print(type(v))
            stimulus, spike_train = (v["stimulus"], v["spikes"])
            lifespan = stimulus['lifespan']
            if lifespan > 20:
                print("skipping stimulus longer than 20 seconds")
                continue
            if spike_train.size>0:
                glia.draw_spikes(ax, spike_train, ymin=trial+0.3,ymax=trial+1)

            stimulus_end = prepend_start_time + lifespan
            duration = stimulus_end + append_lifespan
            ax.fill([0,prepend_start_time,prepend_start_time,0],
                    [trial,trial,trial+1,trial+1],
                    facecolor="gray", edgecolor="none", alpha=0.1)
            ax.fill([stimulus_end,duration,duration,stimulus_end],
                    [trial,trial,trial+1,trial+1],
                    facecolor="gray", edgecolor="none", alpha=0.1)
            trial += 1

        ax.set_title("Unit spike train per SOLID ({})".format(color))
        ax.set_xlabel("time (s)")
        ax.set_ylabel("trials")
Exemplo n.º 10
0
def plot_acuity_v3(fig, axis_gen, data, prepend, append, speed):
    logger.debug("plot solid versus bar for speed")

    ax = next(axis_gen)
    solids, bars_by_speed = data
    bars = bars_by_speed[speed]
    max_lifespan = max(
        bars, key=lambda e: e["stimulus"]["lifespan"])["stimulus"]["lifespan"]
    lifespans = set()
    widths = set()
    angles = set()
    for e in bars:
        width = e["stimulus"]["width"]
        angle = e["stimulus"]["angle"]
        widths.add(width)
        angles.add(angle)
        # need to calculate duration of light over a particular point
        light_duration = int(np.ceil(width / speed))

        lifespans.add(light_duration)

    logger.debug("lifespans {}, widths {}".format(len(lifespans), len(widths)))
    # WARNING
    # assert len(lifespans)==len(widths)

    # keep charts aligned by row
    angle_width = []
    for w in sorted(widths):
        for a in sorted(angles):
            angle_width.append((a, w))

    bar_ymap = {aw: i for i, aw in enumerate(angle_width)}

    # used to map stimulus to proper row
    c_bar_ymap = lambda s: bar_ymap[(s["angle"], s["width"])]

    nangles = len(angles)
    nwidths = len(widths)
    ny = nangles * nwidths

    xlim = glia.axis_continuation(lambda axis: axis.set_xlim(0, max_lifespan))
    ylim = glia.axis_continuation(lambda axis: axis.set_ylim(0, ny))

    bar_text = glia.axis_continuation(
        partial(c_plot_bar,
                title="{} angles x {} widths at {} px/s".format(
                    nangles, nwidths, speed)))
    bar_continuation = glia.compose(ylim, xlim, bar_text)

    for e in bars:
        spikes = e["spikes"]
        lifespan = e["stimulus"]["lifespan"]
        angle = e["stimulus"]["angle"]
        width = e["stimulus"]["width"]
        y = bar_ymap[(angle, width)]
        glia.draw_spikes(ax, spikes, y + 0.2, y + 0.8)
        ax.fill([0, lifespan, lifespan, 0], [y, y, y + 1, y + 1],
                facecolor="gray",
                edgecolor="none",
                alpha=0.1)

    ax.yaxis.set_ticks(np.arange(0, nwidths * nangles, nangles))
    ax.yaxis.set_ticklabels(sorted(list(widths)))
    ax.set_ylabel("Bar Width in pixels (angle changes each row)")
    ax.set_xlabel("Time in seconds")