def plot_logMUA_estimation(asig, logMUA_asig, highpass_freq, lowpass_freq,
                           t_start, t_stop, channel):
    asig = time_slice(asig, t_start, t_stop)
    logMUA_asig = time_slice(logMUA_asig, t_start, t_stop)
    filt_asig = butter(asig, highpass_freq=highpass_freq,
                               lowpass_freq=lowpass_freq)

    sns.set(style='ticks', palette="deep", context="notebook")
    fig, ax = plt.subplots()

    ax.plot(asig.times,
            zscore(asig.as_array()[:,channel]),
            label='original signal')

    ax.plot(filt_asig.times,
            zscore(filt_asig.as_array()[:,channel]) + 10,
            label=f'signal [{highpass_freq}-{lowpass_freq}]',
            alpha=0.5)

    ax.plot(logMUA_asig.times,
            zscore(logMUA_asig.as_array()[:,channel]) + 20,
            label='logMUA')

    ax.set_title('Channel {}'.format(channel))
    ax.set_xlabel('time [{}]'.format(asig.times.units.dimensionality.string))
    ax.set_yticklabels([])
    plt.legend()
    return ax
    CLI.add_argument("--time_slice",
                     nargs='?',
                     type=none_or_float,
                     default=None,
                     help="length of time_slice in seconds.")
    args = CLI.parse_args()

    block = load_neo(args.data)

    evts = [ev for ev in block.segments[0].events
            if ev.name == 'Wavefronts'][0]

    if args.time_slice is not None:
        asig = block.segments[0].analogsignals[0]
        t_stop = asig.t_start.rescale('s') + args.time_slice * pq.s
        evts = time_slice(evts, t_start=asig.t_start, t_stop=t_stop)

    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    N = len(np.unique(evts.labels))
    cmap = sns.husl_palette(N - 1, h=.5, l=.6)
    cmap = random.sample([c for c in cmap], N - 1)
    cmap = ListedColormap(['k'] + cmap)

    ax.scatter(evts.times,
               evts.array_annotations['x_coords'],
               evts.array_annotations['y_coords'],
               c=[int(label) for label in evts.labels],
               cmap=cmap,
               s=2)
Example #3
0
    try:
        block = load_neo(args.data, try_signal_grouping=True)
    except Exception as e:
        print(e)
        block = load_neo(args.data, try_signal_grouping=True)

    asigs = block.segments[0].analogsignals

    if len(asigs) > 1:
        print(f'Merging {len(asigs)} AnalogSignals into one.')
        asig = merge_analogsingals(asigs)
    else:
        asig = asigs[0]

    asig = time_slice(asig, args.t_start, args.t_stop)

    # add metadata
    kwargs = parse_string2dict(args.kwargs)

    channels = asig.array_annotations[kwargs['ELECTRODE_ANNOTATION_NAME']]

    coords = np.array([
        kwargs['NAME2COORDS'][str(channel)] for channel in channels.astype(int)
    ])
    asig.array_annotations.update(x_coords=coords[:, 0])
    asig.array_annotations.update(y_coords=coords[:, 1])

    # locations = []
    # for channel in channels:
    #     locations.append([loc for loc in kwargs['ELECTRODE_LOCATION'].keys()
Example #4
0
                     help="start time in seconds")
    CLI.add_argument("--t_stop",
                     nargs='?',
                     type=float,
                     default=10,
                     help="stop time in seconds")
    CLI.add_argument("--channel",
                     nargs='?',
                     type=int,
                     default=0,
                     help="channel to plot")
    args = CLI.parse_args()

    orig_asig = load_neo(args.original_data, 'analogsignal', lazy=True)
    orig_asig = time_slice(orig_asig,
                           t_start=args.t_start,
                           t_stop=args.t_stop,
                           lazy=True,
                           channel_indexes=args.channel)

    proc_asig = load_neo(args.processed_data, 'analogsignal', lazy=True)
    proc_asig = time_slice(proc_asig,
                           t_start=args.t_start,
                           t_stop=args.t_stop,
                           lazy=True,
                           channel_indexes=args.channel)

    plot_traces(orig_asig, proc_asig, args.channel)

    save_plot(args.output)
Example #5
0
    print('vlock', block)
    print('seg', block.segments[0])

    block.segments[0].imagesequences.append(imageSequences)

    # change data orientation to be top=ventral, right=lateral
    imgseq = block.segments[0].imagesequences[0]
    imgseq = flip_image(imgseq, axis=-2)
    imgseq = rotate_image(imgseq, rotation=-90)
    block.segments[0].imagesequences[0] = imgseq

    # Transform into analogsignals
    block.segments[0].analogsignals = []
    block = ImageSequence2AnalogSignal(block)

    block.segments[0].analogsignals[0] = time_slice(
        block.segments[0].analogsignals[0], args.t_start, args.t_stop)

    if args.annotations is not None:
        block.segments[0].analogsignals[0].annotations.\
                                    update(parse_string2dict(args.annotations))

    block.segments[0].analogsignals[0].annotations.update(
        orientation_top=args.orientation_top)
    block.segments[0].analogsignals[0].annotations.update(
        orientation_right=args.orientation_right)

    # ToDo: add metadata
    block.name = args.data_name
    block.segments[0].name = 'Segment 1'
    block.segments[0].description = 'Loaded from mat file. '\
                                    .format(neo.__version__)
                     type=none_or_float,
                     default=10,
                     help="stop time in seconds")
    args = CLI.parse_args()

    block = load_neo(args.data)

    asig = block.segments[0].analogsignals[0]

    args.plot_tstart = asig.t_start if args.plot_tstart is None else args.plot_tstart
    args.plot_tstop = asig.t_stop if args.plot_tstop is None else args.plot_tstop

    transition_event = detect_transitions(asig, args.transition_phase)

    block.segments[0].events.append(transition_event)

    write_neo(args.output, block)

    if args.plot_channels[0] is not None:
        for channel in args.plot_channels:
            plot_hilbert_phase(asig=time_slice(asig, args.plot_tstart,
                                               args.plot_tstop),
                               event=time_slice(transition_event,
                                                args.plot_tstart,
                                                args.plot_tstop),
                               channel=int(channel))
            output_path = os.path.join(
                args.img_dir,
                args.img_name.replace('_channel0', f'_channel{channel}'))
            save_plot(output_path)
Example #7
0
    CLI.add_argument("--output",
                     nargs='?',
                     type=str,
                     required=True,
                     help="path of output file")
    CLI.add_argument("--t_start",
                     nargs='?',
                     type=float,
                     default=0,
                     help="new starting time in s")
    CLI.add_argument("--t_stop",
                     nargs='?',
                     type=float,
                     default=10,
                     help="new stopping time in s")
    args = CLI.parse_args()

    block = load_neo(args.data)

    for i, asig in enumerate(block.segments[0].analogsignals):
        block.segments[0].analogsignals[i] = time_slice(asig,
                                                        t_start=args.t_start,
                                                        t_stop=args.t_stop)

    for i, evt in enumerate(block.segments[0].events):
        block.segments[0].events[i] = time_slice(evt,
                                                 t_start=args.t_start,
                                                 t_stop=args.t_stop)

    write_neo(args.output, block)
Example #8
0
    CLI.add_argument("--output",
                     nargs='?',
                     type=str,
                     required=True,
                     help="path of output file")
    CLI.add_argument("--t_start",
                     nargs='?',
                     type=float,
                     default=0,
                     help="new starting time in s")
    CLI.add_argument("--t_stop",
                     nargs='?',
                     type=float,
                     default=10,
                     help="new stopping time in s")
    args = CLI.parse_args()

    block = load_neo(args.data)

    for i, asig in enumerate(blk.segments[0].analogsignals):
        blk.segments[0].analogsignals[i] = time_slice(asig,
                                                      t_start=t_start,
                                                      t_stop=t_stop)

    for i, evt in enumerate(blk.segments[0].events):
        blk.segments[0].events[i] = time_slice(evt,
                                               t_start=t_start,
                                               t_stop=t_stop)

    write_neo(args.output, block)
Example #9
0
    CLI.add_argument("--t_start",
                     nargs='?',
                     type=float,
                     default=0,
                     help="start time in seconds")
    CLI.add_argument("--t_stop",
                     nargs='?',
                     type=float,
                     default=10,
                     help="stop time in seconds")
    CLI.add_argument("--channels",
                     nargs='+',
                     type=none_or_int,
                     default=0,
                     help="list of channels to plot")
    args = CLI.parse_args()

    asig = load_neo(args.data, 'analogsignal', lazy=True)

    channels = parse_plot_channels(args.channels, args.data)

    asig = time_slice(asig,
                      t_start=args.t_start,
                      t_stop=args.t_stop,
                      lazy=True,
                      channel_indexes=channels)

    fig = plot_traces(asig, channels)

    save_plot(args.output)