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
Exemple #2
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)
Exemple #3
0
    else:
        warnings.warn('No trigger events to plot in clusters!')

    ax.set_xlabel('time [{}]'.format(events.times.dimensionality.string))
    ax.set_ylabel('x-pixel')
    ax.set_zlabel('y-pixel')
    ax.view_init(45, -75)
    return ax, cmap


if __name__ == '__main__':
    CLI = argparse.ArgumentParser()
    CLI.add_argument("--output",    nargs='?', type=str)
    CLI.add_argument("--data",      nargs='?', type=str)
    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 = block.filter(name='wavefronts', objects="Event")[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)

    ax, cmap = plot_clustering(evts)

    save_plot(args.output)
Exemple #4
0
    CLI.add_argument("--plot_tstop",
                     nargs='?',
                     type=none_or_float,
                     default=10,
                     help="stop time in seconds")
    CLI.add_argument("--plot_channels",
                     nargs='+',
                     type=none_or_int,
                     default=None,
                     help="list of channels to plot")
    args, unknown = CLI.parse_known_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
    # slice signals
    asig = time_slice(asig, args.plot_tstart, args.plot_tstop)

    # get transition events
    event = block.filter(name='transitions', objects="Event")[0]
    event = event.time_slice(args.plot_tstart, args.plot_tstop)

    for channel in args.plot_channels:
        plot_trigger_times(asig=asig, event=event, channel=channel)
        output_path = os.path.join(
            args.output,
            args.filename.replace('_channel0', f'_channel{channel}'))
        save_plot(output_path)
                     nargs='?',
                     type=none_or_float,
                     default=10,
                     help="stop time in seconds")
    args, unknown = CLI.parse_known_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 = args.img_dir / args.img_name.replace(
                '_channel0', f'_channel{channel}')
            save_plot(output_path)
Exemple #6
0
                     help="path of output figure")
    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)

    ax = plot_traces(asig, channels)
    save_plot(args.output)
Exemple #7
0
    args, unknown = CLI.parse_known_args()

    # Load data with Neo IO or custom loading routine
    block = load_neo(args.data)
    # If there is no Neo IO for the data type available,
    # the data must be loaded conventioally and added to a newly constructed
    # Neo block. For building a Neo objects, have a look into the documentation
    # https://neo.readthedocs.io/

    # In case the dataset is imagaging data and therefore stored as an
    # ImageSequence object, it needs to be transformed into an AnalogSignal
    # object. To do this use the function imagesequences_to_analogsignals in utils/neo.py

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

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

    # Add metadata from ANNOTIATION dict
    asig.annotations.update(parse_string2dict(args.annotations))
    asig.annotations.update(spatial_scale=args.spatial_scale * pq.mm)
    asig.annotations.update(orientation_top=args.orientation_top)
    asig.annotations.update(orientation_right=args.orientation_right)

    # Add metadata from ARRAY_ANNOTIATION dict
    asig.array_annotations.update(parse_string2dict(args.array_annotations))

    # Do custom metadata processing from KWARGS dict (optional)
    # kwargs = parse_string2dict(args.kwargs)
    # ... do something

    # Add description to the Neo object
Exemple #8
0
    CLI.add_argument("--original_data", nargs='?', type=str, required=True,
                     help="path to input data in neo format")
    CLI.add_argument("--processed_data", nargs='?', type=str, required=True,
                     help="path to input data in neo format")
    CLI.add_argument("--img_dir",  nargs='?', type=str, required=True,
                     help="path of output figure directory")
    CLI.add_argument("--img_name", nargs='?', type=str,
                     default='processed_trace_channel0.png',
                     help='example filename for channel 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=int, default=0,
                     help="channel to plot")
    args = CLI.parse_args()

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

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

    for channel in args.channels:
        plot_traces(orig_asig, proc_asig, channel)
        output_path = os.path.join(args.img_dir,
                                   args.img_name.replace('_channel0', f'_channel{channel}'))
        save_plot(output_path)