How to use the allensdk.core.json_utilities function in allensdk

To help you get started, we’ve selected a few allensdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AllenInstitute / biophys_optimize / biophys_optimize / scripts / run_optimize.py View on Github external
def main():
    module = ags.ArgSchemaParser(schema_type=OptimizeParameters)

    preprocess_results = ju.read(module.args["paths"]["preprocess_results"])
    passive_results = ju.read(module.args["paths"]["passive_results"])
    fit_style_data = ju.read(module.args["paths"]["fit_style"])

    results = optimize(hoc_files=module.args["paths"]["hoc_files"],
                       compiled_mod_library=module.args["paths"]["compiled_mod_library"],
                       morphology_path=module.args["paths"]["swc"],
                       preprocess_results=preprocess_results,
                       passive_results=passive_results,
                       fit_type=module.args["fit_type"],
                       fit_style_data=fit_style_data,
                       seed=module.args["seed"],
                       ngen=module.args["ngen"],
                       mu=module.args["mu"],
                       storage_directory = module.args["paths"]["storage_directory"],
                       starting_population = module.args["paths"].get("starting_population",None))
github AllenInstitute / biophys_optimize / biophys_optimize / scripts / run_consolidate_passive_fitting.py View on Github external
def main():
    module = ags.ArgSchemaParser(schema_type=ConsolidateParameters)

    preprocess_results = ju.read(module.args["paths"]["preprocess_results"])
    is_spiny = preprocess_results["is_spiny"]
    info = ju.read(module.args["paths"]["passive_info"])

    if info["should_run"]:
        fit_1_path = module.args["paths"]["passive_fit_1"]
        fit_1 = ju.read(fit_1_path)

        fit_2_path = module.args["paths"]["passive_fit_2"]
        fit_2 = ju.read(fit_2_path)

        fit_3_path = module.args["paths"]["passive_fit_elec"]
        fit_3 = ju.read(fit_3_path)

        ra, cm1, cm2 = cpf.compare_runs(preprocess_results, fit_1, fit_2, fit_3)
    else:
        ra = 100.
github AllenInstitute / biophys_optimize / biophys_optimize / scripts / run_model_selection.py View on Github external
swc_path = module.args["paths"]["swc"]
    fit_style_paths = module.args["paths"]["fit_styles"]
    best_fit_json_path = module.args["paths"]["best_fit_json_path"]
    passive = ju.read(module.args["paths"]["passive_results"])
    preprocess = ju.read(module.args["paths"]["preprocess_results"])


    fits = module.args["paths"]["fits"]
    fit_results = ms.fit_info(fits)
    best_fit = ms.select_model(fit_results, module.args["paths"], passive, preprocess["v_baseline"],
                               module.args["noise_1_sweeps"], module.args["noise_2_sweeps"])
    if best_fit is None:
        raise Exception("Failed to find acceptable optimized model")

    logging.info("building fit data")
    fit_style_data = ju.read(module.args["paths"]["fit_styles"][best_fit["fit_type"]])
    fit_data = ms.build_fit_data(best_fit["params"], passive, preprocess, fit_style_data)

    logging.info("writing fit data: %s", best_fit_json_path)
    ju.write(best_fit_json_path, fit_data)

    output = {
        "paths": {
            "fit_json": best_fit_json_path,
        }
    }

    logging.info("writing output json: %s", module.args["output_json"])
    ju.write(module.args["output_json"], output)
github AllenInstitute / biophys_optimize / biophys_optimize / scripts / run_preprocessing.py View on Github external
fit_types = preprocess.FitStyle.get_fit_types(
        has_apical=has_apical,
        is_spiny=is_spiny,
        width=target_info.at["width", "mean"])

    stage_1_tasks = [{"fit_type": fit_type, "seed": seed}
        for seed in random_seeds
        for fit_type in fit_types]

    stage_2_tasks = [{"fit_type": preprocess.FitStyle.map_stage_2(fit_type), "seed": seed}
        for seed in random_seeds
        for fit_type in fit_types]

    preprocess_results_path = os.path.join(
        paths["storage_directory"], "preprocess_results.json")
    ju.write(preprocess_results_path, {
        "is_spiny": is_spiny,
        "has_apical": has_apical,
        "junction_potential": junction_potential,
        "max_stim_test_na": max_i,
        "v_baseline": v_baseline,
        "stimulus": {
            "amplitude": 1e-3 * stim_amp, # to nA
            "delay": 1e3,
            "duration": 1e3 * stim_dur, # to ms
        },
        "target_features": target_info.to_dict(orient="index"),
        "sweeps": sweeps,
        "sweeps_to_fit": [s.sweep_number for s in sweep_set_to_fit.sweeps],
    })

    paths.update({
github AllenInstitute / biophys_optimize / biophys_optimize / scripts / run_optimize.py View on Github external
results = optimize(hoc_files=module.args["paths"]["hoc_files"],
                       compiled_mod_library=module.args["paths"]["compiled_mod_library"],
                       morphology_path=module.args["paths"]["swc"],
                       preprocess_results=preprocess_results,
                       passive_results=passive_results,
                       fit_type=module.args["fit_type"],
                       fit_style_data=fit_style_data,
                       seed=module.args["seed"],
                       ngen=module.args["ngen"],
                       mu=module.args["mu"],
                       storage_directory = module.args["paths"]["storage_directory"],
                       starting_population = module.args["paths"].get("starting_population",None))

    logging.info("Writing optimization output")
    ju.write(module.args["output_json"], results)
github AllenInstitute / biophys_optimize / biophys_optimize / scripts / run_passive_fitting.py View on Github external
npf.initialize_neuron(swc_path, paths["fit"])

    if passive_fit_type == npf.PASSIVE_FIT_1:
        results = npf.passive_fit_1(up_data, down_data,
            info["fit_window_start"], info["fit_window_end"])
    elif passive_fit_type == npf.PASSIVE_FIT_2:
        results = npf.passive_fit_2(up_data, down_data,
            info["fit_window_start"], info["fit_window_end"])
    elif passive_fit_type == npf.PASSIVE_FIT_ELEC:
        results = npf.passive_fit_elec(up_data, down_data,
            info["fit_window_start"], info["fit_window_end"],
            info["bridge"], info["electrode_cap"])
    else:
        raise Exception("unknown passive fit type: %s" % passive_fit_type)

    ju.write(results_file, results)
    ju.write(output_json, { "paths": { passive_fit_type: results_file } })
github AllenInstitute / biophys_optimize / biophys_optimize / scripts / hack_optimize_input.py View on Github external
import argparse, os
import allensdk.core.json_utilities as ju
from pkg_resources import resource_filename
import biophys_optimize

parser = argparse.ArgumentParser(description='hack in paths that strategy will do - passive')
parser.add_argument('input', type=str)
parser.add_argument('output', type=str)
parser.add_argument('--fit_type_index', default=0)
parser.add_argument("--stage_key", default="stage_1_task_list")
parser.add_argument('--mu', default=10, type=int)
parser.add_argument('--ngen', default=5, type=int)
parser.add_argument('--sp', default=None, type=str)
args = parser.parse_args()

data = ju.read(args.input)
fit_type_index = args.fit_type_index
stage_key = args.stage_key
fit_type = data[stage_key][fit_type_index]["fit_type"]
seed = data[stage_key][fit_type_index]["seed"]

boph_name = biophys_optimize.__name__

output = {
  "paths": {
    "swc": data["paths"]["swc"],
    "storage_directory": data["paths"]["storage_directory"],
    "preprocess_results": data["paths"]["preprocess_results"],
    "passive_results": os.path.join(data["paths"]["storage_directory"], "passive_results.json"),
    "fit_style": resource_filename(boph_name, "fit_styles/%s_fit_style.json" % fit_type),
    "compiled_mod_library": resource_filename(boph_name, "x86_64/.libs/libnrnmech.so"),
    "hoc_files": [ "stdgui.hoc", "import3d.hoc", resource_filename(boph_name, "cell.hoc") ]
github AllenInstitute / biophys_optimize / biophys_optimize / scripts / hack_consolidate_passive_strategy.py View on Github external
#!/usr/bin/env python

import argparse
import os.path
import allensdk.core.json_utilities as ju
import biophys_optimize.neuron_passive_fit as npf

parser = argparse.ArgumentParser(description='hack in paths that strategy will do - passive')
parser.add_argument('preprocess_out', type=str)
parser.add_argument('fit_1_out', type=str)
parser.add_argument('fit_2_out', type=str)
parser.add_argument('fit_elec_out', type=str)
parser.add_argument('output', type=str)
args = parser.parse_args()

data = ju.read(args.preprocess_out)
fit_1 = ju.read(args.fit_1_out)
fit_2 = ju.read(args.fit_2_out)
fit_3 = ju.read(args.fit_elec_out)

out_data = {
    "paths": {
        "passive_info": data["paths"]["passive_info"],
        "preprocess_results": data["paths"]["preprocess_results"],
        "passive_fit_1": fit_1["paths"][npf.PASSIVE_FIT_1],
        "passive_fit_2": fit_2["paths"][npf.PASSIVE_FIT_2],
        "passive_fit_elec": fit_3["paths"][npf.PASSIVE_FIT_ELEC],
        "passive_results": os.path.join(data["paths"]["storage_directory"], "passive_results.json")
        }
}

ju.write(args.output, out_data)
github AllenInstitute / biophys_optimize / biophys_optimize / scripts / run_consolidate_passive_fitting.py View on Github external
def main():
    module = ags.ArgSchemaParser(schema_type=ConsolidateParameters)

    preprocess_results = ju.read(module.args["paths"]["preprocess_results"])
    is_spiny = preprocess_results["is_spiny"]
    info = ju.read(module.args["paths"]["passive_info"])

    if info["should_run"]:
        fit_1_path = module.args["paths"]["passive_fit_1"]
        fit_1 = ju.read(fit_1_path)

        fit_2_path = module.args["paths"]["passive_fit_2"]
        fit_2 = ju.read(fit_2_path)

        fit_3_path = module.args["paths"]["passive_fit_elec"]
        fit_3 = ju.read(fit_3_path)

        ra, cm1, cm2 = cpf.compare_runs(preprocess_results, fit_1, fit_2, fit_3)
    else:
        ra = 100.
        cm1 = 1.
        if is_spiny:
github AllenInstitute / biophys_optimize / biophys_optimize / scripts / run_preprocessing.py View on Github external
"""Main sequence of pre-processing and passive fitting"""

    # Extract Sweep objects (from IPFX package) from NWB file
    nwb_path = paths["nwb"] # nwb - neurodata without borders (ephys data)
    nwb_data = create_nwb_reader(nwb_path)
    core_1_lsq, c1_start, c1_end = sweeps_from_nwb(
        nwb_data, sweeps["core_1_long_squares"])
    core_2_lsq, c2_start, c2_end = sweeps_from_nwb(
        nwb_data, sweeps["core_2_long_squares"])

    # Choose sweeps to train the model
    sweep_set_to_fit, start, end = preprocess.select_core_1_or_core_2_sweeps(
        core_1_lsq, c1_start, c1_end,
        core_2_lsq, c2_start, c2_end)
    if len(sweep_set_to_fit.sweeps) == 0:
        ju.write(output_json, { 'error': "No usable sweeps found" })
        return


    # Calculate the target features from the training sweeps
    step_analysis = StepAnalysis(start, end)
    step_analysis.analyze(sweep_set_to_fit)
    target_info = preprocess.target_features(
        step_analysis.sweep_features(),
        step_analysis.spikes_data())

    stim_amp = step_analysis.sweep_features()["stim_amp"].values[0]
    stim_dur = end - start
    v_baseline = target_info.at["v_baseline", "mean"]

    # Determine maximum current used for depolarization block checks
    # during optimization