Esempio n. 1
0
def stimulus_list():
    return glia.load_stimulus(
        "tests/data/160615/E1_R1_DAD_55min_contrastgratings.stimulus")
Esempio n. 2
0
def stimulus_list():
    return glia.load_stimulus("tests/data/160615/E1_R1_DAD_55min_contrastgratings.stimulus")
Esempio n. 3
0
def analyze(ctx, filename, trigger, threshold, eyecandy, ignore_extra=False,
        fix_missing=False, window_height=None, window_width=None, output=None, notebook=None,
        calibration=None, distance=None):
    """Analyze data recorded with eyecandy.
    """
    ctx.obj = {}
    data_directory, data_name = os.path.split(filename)
    name, extension = os.path.splitext(data_name)
    analog_file = os.path.join(data_directory, name +'.analog')
    stimulus_file = os.path.join(data_directory, name + ".stimulus")

    spyking_regex = re.compile('.*\.result.hdf5$')
    if extension == ".txt":
        ctx.obj["units"] = glia.read_plexon_txt_file(filename,filename)
    elif re.match(spyking_regex, filename):
        ctx.obj["units"] = glia.read_spyking_results(filename)
    else:
        raise ValueError('could not read {}. Is it a plexon or spyking circus file?')

    if not notebook:
        notebooks = glob(os.path.join(data_directory, '*.yml')) + \
            glob(os.path.join(data_directory, '*.yaml'))
        if len(notebooks)==0:
            raise ValueError("no lab notebooks (.yml) were found. Either add to directory," \
                "or specify file path with -n.")
        notebook=notebooks[0]

    lab_notebook = glia.open_lab_notebook(notebook)
    experiment_protocol = glia.get_experiment_protocol(lab_notebook, name)
    flicker_version = experiment_protocol["flickerVersion"]

    try:
        ctx.obj["stimulus_list"] = glia.load_stimulus(stimulus_file)
    except OSError:
        print("No .stimulus file found. Attempting to create from .analog file.".format(trigger))
        if flicker_version==0.3:
            ctx.obj["stimulus_list"] = glia.create_stimulus_list_v0_4(
                analog_file, stimulus_file, notebook, name, eyecandy, ignore_extra,
                calibration, distance)

        elif trigger == "legacy":
            ctx.obj["stimulus_list"] = glia.legacy_create_stimulus_list_from_flicker(
                analog_file, stimulus_file, notebook, name, eyecandy, ignore_extra, threshold, window_height, window_width)
        elif trigger == "flicker":
            ctx.obj["stimulus_list"] = glia.create_stimulus_list_from_flicker(
                analog_file, stimulus_file, notebook, name, eyecandy, ignore_extra, threshold, fix_missing, window_height, window_width)
        elif trigger == "fix":
            ctx.obj["stimulus_list"] = glia.alternate_create_stimulus_list_from_flicker(
                analog_file, stimulus_file, notebook, name, eyecandy, ignore_extra, threshold, window_height, window_width,
                fix_missing=True)
        elif trigger == "detect-solid":
            ctx.obj["stimulus_list"] = glia.create_stimulus_list_from_SOLID(
                analog_file, stimulus_file, notebook, name, eyecandy, ignore_extra, threshold, window_height, window_width)
        elif trigger == "ttl":
            raise ValueError('not implemented')
        else:
            raise ValueError("invalid trigger: {}".format(trigger))

    # prepare_output
    plot_directory = os.path.join(data_directory, name+"-plots")
    try:
        os.makedirs(plot_directory)
        os.chmod(plot_directory, 0o777)
    except OSError as exception:
        if exception.errno != errno.EEXIST:
            raise
    if output == "pdf":
        ctx.obj["retina_pdf"] = PdfPages(glia.plot_pdf_path(plot_directory, "retina"))
        ctx.obj["unit_pdfs"] = glia.open_pdfs(plot_directory, list(ctx.obj["units"].keys()), Unit.name_lookup())
        # c connotes 'continuation'
        ctx.obj["c_add_unit_figures"] = partial(glia.add_to_unit_pdfs,
            unit_pdfs=ctx.obj["unit_pdfs"])
        ctx.obj["c_add_retina_figure"] = lambda x: ctx.obj["retina_pdf"].savefig(x)
        
    elif output == "png":
        raise ValueError("not implemented")