Exemplo n.º 1
0
def run(test, N):
    res = dict()
    print("Running nixio14/h5py")
    nf = nixio14.File.open(tmpfile,
                           mode=nixio14.FileMode.Overwrite,
                           backend="h5py")
    times = test.runtest(nf, N)
    res["nixio14/h5py"] = times
    nf.close()

    print("Running nixio14/hdf5")
    nf = nixio14.File.open(tmpfile,
                           mode=nixio14.FileMode.Overwrite,
                           backend="hdf5")
    times = test.runtest(nf, N)
    res["nixio14/hdf5"] = times
    nf.close()

    print("Running nixionew")
    nf = nixionew.File.open(tmpfile, mode=nixionew.FileMode.Overwrite)
    times = test.runtest(nf, N)
    res["nixionew"] = times
    nf.close()

    print("Running nix(C++)")
    times = test.runtest_nix(N)
    res["nix(C++)"] = times

    print("Running h5py")
    hf = h5py.File(tmpfile, mode="w")
    times = test.runtest_h5py(hf, N)
    res["h5py"] = times
    hf.close()

    print("Running neo/nixio14")
    neo.io.nixio.nix = nixio14
    io = neo.NixIO(tmpfile, mode="ow")
    times = test.runtest_neo(io, N)
    res["neo/nixio14"] = times
    io.close()

    print("Running neo/nixionew")
    neo.io.nixio.nix = nixionew
    io = neo.NixIO(tmpfile, mode="ow")
    times = test.runtest_neo(io, N)
    res["neo/nixionew"] = times
    io.close()

    return res
Exemplo n.º 2
0
def print_neo(nixfname):
    with neo.NixIO(nixfname) as io:
        neoblocks = io.read_all_blocks()

    for blk in neoblocks:
        printdepth(blk.annotations)
        for seg in blk.segments:
            printdepth(seg.annotations, 1)
            for child in seg.children:
                printdepth(child.annotations, 2)
        for chx in blk.channel_indexes:
            printdepth(chx.annotations, 1)
            for child in chx.children:
                printdepth(child.annotations, 2)
Exemplo n.º 3
0

if __name__ == '__main__':

    CLI = argparse.ArgumentParser()
    CLI.add_argument("--waves", nargs='?', type=str)
    CLI.add_argument("--output", nargs='?', type=str)
    CLI.add_argument("--contour", nargs='?', type=str)
    CLI.add_argument("--min_pixelfrac", nargs='?', type=float)
    CLI.add_argument("--max_fiterror", nargs='?', type=float)
    CLI.add_argument("--max_rotation", nargs='?', type=float)
    CLI.add_argument("--min_frames", nargs='?', type=float)

    args = CLI.parse_args()

    with neo.NixIO(args.waves) as io:
        seg = io.read_block().segments[0]
        up_trains = seg.spiketrains
        images = seg.analogsignals[0]

    # for every frame, create list of pixels which show a up transition
    up_coords = up_pixel_per_frame(up_trains, images.times)

    # linear fit through UP pixels;
    # select for minimum number of pixels, maximal fit error,
    # and maximal rotation of the wavefront direction
    pixel_num = (~np.isnan(images[0])).sum()
    waves = detect_waves(up_coords,
                         min_pixel=args.min_pixelfrac * pixel_num,
                         max_fiterror=args.max_fiterror,
                         max_rotation=args.max_rotation)
Exemplo n.º 4
0
def none_or_int(value):
    if value == 'None':
        return None
    return int(value)


if __name__ == '__main__':
    CLI = argparse.ArgumentParser()
    CLI.add_argument("--data", nargs='?', type=str)
    CLI.add_argument("--output", nargs='?', type=str)
    CLI.add_argument("--tstart", nargs='?', type=float)
    CLI.add_argument("--tstop", nargs='?', type=float)
    CLI.add_argument("--channel", nargs='+', type=none_or_int)
    args = CLI.parse_args()

    with neo.NixIO(args.data) as io:
        asig = io.read_block().segments[0].analogsignals

    check_analogsignal_shape(asig)
    asig = asig[0]

    dim_t, channel_num = asig.shape

    for i, channel in enumerate(args.channel):
        if channel is None:
            args.channel[i] = random.randint(0, channel_num)

    asig = asig.time_slice(args.tstart * pq.s, args.tstop * pq.s)

    sns.set(style='ticks', palette="deep", context="notebook")
    fig, ax = plt.subplots()
Exemplo n.º 5
0
if __name__ == '__main__':
    CLI = argparse.ArgumentParser()
    CLI.add_argument("--output", nargs='?', type=str)
    CLI.add_argument("--logMUA", nargs='?', type=str)
    CLI.add_argument("--data", nargs='?', type=str)
    CLI.add_argument("--UD_states", nargs='?', type=str)
    CLI.add_argument("--format", nargs='?', type=str, default='eps')
    CLI.add_argument("--t_start", nargs='?', type=float, default=0)
    CLI.add_argument("--t_stop", nargs='?', type=float, default=0)
    CLI.add_argument("--channel", nargs='?', type=int, default=0)
    CLI.add_argument("--show_figure", nargs='?', type=int, default=0)

    args = CLI.parse_args()

    with neo.NixIO(args.data) as io:
        data_segment = io.read_block().segments[0]
    with neo.NixIO(args.logMUA) as io:
        logMUA_segment = io.read_block().segments[0]
    state_vector = np.load(file=args.UD_states)

    plot_signal_traces(logMUA=logMUA_segment.analogsignals[args.channel],
                       data=data_segment.analogsignals[args.channel],
                       state_vector=state_vector[args.channel],
                       t_start=args.t_start * pq.s,
                       t_stop=args.t_stop * pq.s)

    data_dir = os.path.dirname(args.output)
    if not os.path.exists(data_dir):
        os.makedirs(data_dir)
    plt.savefig(fname=args.output, format=args.format)
Exemplo n.º 6
0
    print(
        indent,
        "We want to select the interesting part of the image (Figure 1).\n We have implemented this search using the function 'measure.find_contours' of the scikit-image package: image processing in Python, https://scikit-image.org"
    )
    print(
        indent,
        "In order to do so, we need you to input the Contour_Limit parameter.")
    print(
        indent,
        "Visit http://scikit-image.org/docs/0.8.0/api/skimage.measure.find_contours.html for more information."
    )

    print(indent, "Finding contours...")

    # Load image
    with neo.NixIO(args.image_file) as io:
        img_block = io.read_block()
        img_frame = img_block.segments[0].analogsignals[0][args.contour_frame]
        del img_block

    # Calculate image contour
    contour = find_contour(image=img_frame, contour_limit=args.contour_limit)
    print(indent, "Mask has been found!")

    contour = close_contour(contour, num=100)

    mask = contour2mask(contour=contour,
                        dim_x=img_frame.shape[0],
                        dim_y=img_frame.shape[1])

    # Save contour, mask and example image
    CLI.add_argument("--output", nargs='?', type=str, required=True)
    CLI.add_argument("--channels", nargs='+', type=int, default=[1, 97])
    CLI.add_argument("--t_start", nargs='?', type=float, default=0)
    CLI.add_argument("--t_stop", nargs='?', type=float, default=10)
    CLI.add_argument("--grid_size", nargs='+', type=int, default=[10, 10])
    args = CLI.parse_args()

    block = load_block(session_path=os.path.splitext(args.data)[0],
                       odml_dir=os.path.dirname(args.odml),
                       channels=args.channels,
                       t_start=args.t_start,
                       t_stop=args.t_stop)

    asig = merge_analogsingals(block.segments[0].analogsignals)
    x_coords, y_coords = channel2coords(
        asig.array_annotations['connector_aligned_id'], args.grid_size)
    asig.array_annotations['x_coords'] = x_coords
    asig.array_annotations['y_coords'] = y_coords
    asig.annotations['spatial_scale'] = block.annotations['electrodes_pitch']
    asig.name = 'Raw Signal'

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

    # remove neo elements for compability
    del block.annotations['subject_birthday']
    block.channel_indexes = []

    # save data as nix
    with neo.NixIO(args.output) as nio:
        nio.write_block(block)
Exemplo n.º 8
0
        return signal_out
    elif isinstance(signal, pq.quantity.Quantity):
        return X * signal.units
    elif isinstance(signal, np.ndarray):
        return X


if __name__ == '__main__':
    CLI = argparse.ArgumentParser()
    CLI.add_argument("--data", nargs='?', type=str)
    CLI.add_argument("--output", nargs='?', type=str)
    CLI.add_argument("--order", nargs='?', type=int)
    args = CLI.parse_args()

    # load images
    with neo.NixIO(args.data) as io:
        block = io.read_block()

    check_analogsignal_shape(block.segments[0].analogsignals)
    remove_annotations([block] + block.segments +
                       block.segments[0].analogsignals)

    asig = detrending(block.segments[0].analogsignals[0], args.order)

    # save processed data
    asig.name += ""
    asig.description += "Detrended by order {} ({}). "\
                        .format(args.order, os.path.basename(__file__))
    block.segments[0].analogsignals[0] = asig

    with neo.NixIO(args.output) as io:
Exemplo n.º 9
0
    return None


if __name__ == '__main__':
    CLI = argparse.ArgumentParser()
    CLI.add_argument("--output", nargs='?', type=str)
    CLI.add_argument("--logMUA_estimate", nargs='?', type=str)
    CLI.add_argument("--state_vector", nargs='?', type=str)
    CLI.add_argument("--slope_window", nargs='?', type=int, default=50)
    CLI.add_argument("--show_figure", nargs='?', type=int, default=0)
    CLI.add_argument("--format", nargs='?', type=str)
    CLI.add_argument("--channel", nargs='?', type=int, default=1)

    args = CLI.parse_args()

    with neo.NixIO(args.logMUA_estimate) as io:
        logMUA_segment = io.read_block().segments[0]

    state_vectors = np.load(file=args.state_vector)

    plot_avg_transisitons(logMUA=logMUA_segment.analogsignals[args.channel -
                                                              1],
                          state_vector=state_vectors[args.channel - 1],
                          slope_window=args.slope_window)

    if args.show_figure:
        plt.show()

    data_dir = os.path.dirname(args.output)
    if not os.path.exists(data_dir):
        os.makedirs(data_dir)
Exemplo n.º 10
0
        return None
    return str(value)


if __name__ == '__main__':

    CLI = argparse.ArgumentParser()
    CLI.add_argument("--image_file", nargs='?', type=str)
    CLI.add_argument("--background", nargs='?', type=none_or_str)
    CLI.add_argument("--mask", nargs='?', type=none_or_str)
    CLI.add_argument("--macro_pixel_dim", nargs='?', type=none_or_int)
    CLI.add_argument("--normalize_by", nargs='?', type=none_or_str)
    CLI.add_argument("--output", nargs='?', type=str)
    args = CLI.parse_args()

    with neo.NixIO(args.image_file) as io:
        images = io.read_block().segments[0].analogsignals[0]

    if args.background is not None:
        images = substract_background(images, np.load(args.background))

    if args.normalize_by is not None and args.normalize_by != 'None':
        images = normalize(images, args.normalize_by)
    else:
        args.normlize_by = None

    if args.mask is not None:
        images = apply_mask(images, np.load(args.mask))

    if args.macro_pixel_dim is not None and args.macro_pixel_dim != 'None':
        images = spatial_smoothing(images, args.macro_pixel_dim)
from pathlib import Path

import importlib
import sys

sys.path.append('/home/chebrol/tools/vision4action/')
# sys.path.append('/users/essink/projects/vision4action/vision4action')
# sys.path.append('/home/ito/toolbox/vision4action')
import v4a
from v4a.plot import plotting_functions, plotting_utils

nix_file = '/home/chebrol/nix_folder/y180306-land-001_small.nix'
# nix_file = '/projects/v4a-curation/test_all_sessions/y180306-land-001/y180306-land-001_small.nix'
# nix_file = '/home/ito/datasets/marseille/congloue/data/Vision4Action/DataV4A/y180306-land-001/y180306-land-001_small.nix'

with neo.NixIO(nix_file, 'ro') as io:
    blocks = io.read_all_blocks()

# Analysis parameters

pre = -200 * pq.ms
post = 1500 * pq.ms

# areas to analyze
block_id = 0 # motor
# block_id = 1 # visual
seg_id = 1
anasig_id = 3
epoch_id = 2

Exemplo n.º 12
0
if __name__ == '__main__':
    CLI = argparse.ArgumentParser()
    CLI.add_argument("--out_state_vector", nargs='?', type=str)
    CLI.add_argument("--out_nix_file", nargs='?', type=str)
    CLI.add_argument("--logMUA_estimate", nargs='?', type=str)
    CLI.add_argument("--min_state_duration", nargs='?', type=int, default=2)
    CLI.add_argument("--remove_down_first",
                     nargs='?',
                     type=str2bool,
                     default=True)
    CLI.add_argument("--fixed_threshold", nargs='?', type=int, default=0)
    CLI.add_argument("--sigma_threshold", nargs='?', type=int, default=0)
    CLI.add_argument("--show_plots", nargs='?', type=int, default=0)
    args = CLI.parse_args()

    with neo.NixIO(args.logMUA_estimate) as io:
        logMUA_block = io.read_block()

    remove_duplicate_properties(logMUA_block.segments[0].analogsignals)
    remove_duplicate_properties([logMUA_block, logMUA_block.segments[0]])

    logMUA_signals = logMUA_block.segments[0].analogsignals

    state_vectors, up_trains, down_trains = create_all_state_vectors(
        logMUA_signals,
        min_state_duration=args.min_state_duration,
        remove_down_first=args.remove_down_first,
        fixed_threshold=args.fixed_threshold,
        sigma_threshold=args.sigma_threshold,
        plot=args.show_plots)
Exemplo n.º 13
0
if __name__ == '__main__':

    CLI = argparse.ArgumentParser()
    CLI.add_argument("--logMUA", nargs='?', type=str)
    CLI.add_argument("--frame_folder", nargs='?', type=str)
    CLI.add_argument("--frame_name", nargs='?', type=str)
    CLI.add_argument("--frame_format", nargs='?', type=str)
    CLI.add_argument("--vid_format", nargs='?', type=str, default='mp4')
    CLI.add_argument("--pixel_size", nargs='?', type=float)
    CLI.add_argument("--t_start", nargs='?', type=float)
    CLI.add_argument("--t_stop", nargs='?', type=float)

    args = CLI.parse_args()

    with neo.NixIO(args.logMUA) as io:
        logMUA = io.read_block().segments[0].analogsignals

    frame_start = int(args.t_start * logMUA[0].sampling_rate.rescale('1/s'))
    frame_stop = int(args.t_stop * logMUA[0].sampling_rate.rescale('1/s'))
    times = logMUA[0].times[frame_start:frame_stop]

    shape = [
        len(times), logMUA[0].annotations['grid_size'][0],
        logMUA[0].annotations['grid_size'][1]
    ]
    logMUA_array = np.zeros(shape)
    for asig in logMUA:
        x, y = asig.annotations['coordinates']
        logMUA_array[frame_start:frame_stop,x,y] = \
                            np.squeeze(asig.as_array()[frame_start:frame_stop])
Exemplo n.º 14
0
    if value == 'None':
        return None
    return int(value)


if __name__ == '__main__':
    CLI = argparse.ArgumentParser()
    CLI.add_argument("--output", nargs='?', type=str)
    CLI.add_argument("--data", nargs='?', type=str)
    CLI.add_argument("--MUA_data", nargs='?', type=str)
    CLI.add_argument("--tstart", nargs='?', type=float)
    CLI.add_argument("--tstop", nargs='?', type=float)
    CLI.add_argument("--channel", nargs='?', type=none_or_int)
    args = CLI.parse_args()

    with neo.NixIO(args.data) as io:
        asig = io.read_block().segments[0].analogsignals[0]
    with neo.NixIO(args.MUA_data) as io:
        MUA_asig = io.read_block().segments[0].analogsignals[0]

    dim_t, channel_num = asig.shape

    if args.channel is None:
        args.channel = random.randint(0, channel_num)

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

    asig = zscore(asig.time_slice(args.tstart * pq.s, args.tstop * pq.s))
    ax.plot(asig.times,
            asig.as_array()[:, args.channel],
Exemplo n.º 15
0
import elephant as el
import scipy

if __name__ == '__main__':

    CLI = argparse.ArgumentParser()
    CLI.add_argument("--signal", nargs='?', type=str)
    CLI.add_argument("--y", nargs='?', type=int)
    CLI.add_argument("--x", nargs='?', type=int)
    CLI.add_argument("--output", nargs='?', type=str)
    CLI.add_argument("--highcut", nargs='?', type=float)
    CLI.add_argument("--lowcut", nargs='?', type=float)

    args = CLI.parse_args()

    with neo.NixIO(args.signal) as io:
        seg = io.read_block().segments[0]
        up_transitions = seg.spiketrains
        signal = seg.analogsignals[0]

    filt_signal = el.signal_processing.butter(signal.as_array()[:, args.x,
                                                                args.y],
                                              highpass_freq=args.lowcut,
                                              lowpass_freq=args.highcut,
                                              order=2,
                                              fs=signal.sampling_rate)

    hilbert_signal = el.signal_processing.hilbert(signal)

    pixel_pos = signal.shape[2] * args.x + args.y
Exemplo n.º 16
0

if __name__ == '__main__':
    CLI = argparse.ArgumentParser()
    CLI.add_argument("--image_file", nargs='?', type=str)
    CLI.add_argument("--out_signal", nargs='?', type=str)
    CLI.add_argument("--transition_phase", nargs='?', type=float)
    # CLI.add_argument("--lowcut", nargs='?', type=float)
    # CLI.add_argument("--highcut", nargs='?', type=float)
    # CLI.add_argument("--order", nargs='?', type=int)
    # CLI.add_argument("--minima_threshold", nargs='?', type=float)
    # CLI.add_argument("--minima_windowsize", nargs='?', type=int)

    args = CLI.parse_args()

    with neo.NixIO(args.image_file) as io:
        img_block = io.read_block()

    remove_duplicate_properties([img_block, img_block.segments[0]] +
                                img_block.segments[0].analogsignals)

    images = img_block.segments[0].analogsignals[0]

    # # Filter the signal
    # filt_signals = filter_signals(images, lowcut=args.lowcut,
    #                               highcut=args.highcut, order=args.order)

    up_trains = UP_detection(
        images.as_array(),
        times=images.times,
        t_start=images.t_start,