Ejemplo n.º 1
0
def main(config_file, config_prefix, population, gid, template_paths, dataset_prefix, results_path, results_file_id, results_namespace_id, v_init):

    if results_file_id is None:
        results_file_id = uuid.uuid4()
    if results_namespace_id is None:
        results_namespace_id = 'Cell Clamp Results'
    comm = MPI.COMM_WORLD
    np.seterr(all='raise')
    verbose = True
    params = dict(locals())
    env = Env(**params)
    configure_hoc_env(env)
    io_utils.mkout(env, env.results_file_path)
    env.cell_selection = {}

    attr_dict = {}
    attr_dict[gid] = {}
    attr_dict[gid].update(measure_passive(gid, population, v_init, env))
    attr_dict[gid].update(measure_ap(gid, population, v_init, env))
    attr_dict[gid].update(measure_ap_rate(gid, population, v_init, env))
    attr_dict[gid].update(measure_fi(gid, population, v_init, env))

    pprint.pprint(attr_dict)

    if results_path is not None:
        append_cell_attributes(env.results_file_path, population, attr_dict,
                               namespace=env.results_namespace_id,
                               comm=env.comm, io_size=env.io_size)
Ejemplo n.º 2
0
def init_env():
    """

    """
    context.env = Env(comm=context.comm,
                      results_file_id=context.results_file_id,
                      **context.kwargs)
Ejemplo n.º 3
0
def main(template_path, forest_path, synapses_path, config_path):

    comm = MPI.COMM_WORLD
    rank = comm.Get_rank()

    env = Env(comm=comm, config_file=config_path, template_paths=template_path)

    h('objref nil, pc, tlog, Vlog, spikelog')
    h.load_file("nrngui.hoc")
    h.xopen("./tests/rn.hoc")
    h.xopen(template_path + '/BasketCell.hoc')

    pop_name = "BC"
    gid = 1039000
    (trees_dict, _) = read_tree_selection(forest_path,
                                          pop_name, [gid],
                                          comm=env.comm)
    synapses_dict = read_cell_attribute_selection(synapses_path,
                                                  pop_name, [gid],
                                                  "Synapse Attributes",
                                                  comm=env.comm)

    (_, tree) = next(trees_dict)
    (_, synapses) = next(synapses_dict)

    v_init = -60

    template_class = getattr(h, "BasketCell")

    ap_test(template_class, tree, v_init)
    passive_test(template_class, tree, v_init)
    ap_rate_test(template_class, tree, v_init)
    fi_test(template_class, tree, v_init)
    gap_junction_test(env, template_class, tree, v_init)
    synapse_test(template_class, gid, tree, synapses, v_init, env)
Ejemplo n.º 4
0
def main(config, config_prefix, gid, population, input_file, output_file,
         dry_run, verbose):

    utils.config_logging(verbose)
    logger = utils.get_script_logger(os.path.basename(__file__))

    h.load_file("nrngui.hoc")
    h.load_file("import3d.hoc")

    env = Env(config_file=config, config_prefix=config_prefix)
    swc_type_defs = env.SWC_Types

    if not os.path.isfile(output_file):
        io_utils.make_h5types(env, output_file)

    (forest_pop_ranges, _) = read_population_ranges(output_file)
    (forest_population_start,
     forest_population_count) = forest_pop_ranges[population]

    h.load_file(input_file)
    if verbose:
        h.topology()
    tree_dict = export_swc_dict()

    trees_dict = {0: tree_dict}

    logger.info(pprint.pformat(trees_dict))

    if not dry_run:
        append_cell_trees(output_file, population, trees_dict)
Ejemplo n.º 5
0
def main(arena_id, cell_selection_path, config_file, template_paths, hoc_lib_path, dataset_prefix, config_prefix,
         results_path, results_id, node_rank_file, io_size, recording_fraction, recording_profile, coredat, trajectory_id, tstop, v_init,
         stimulus_onset, max_walltime_hours, checkpoint_clear_data, checkpoint_interval, results_write_time,
         spike_input_path, spike_input_namespace, spike_input_attr, dt, ldbal, lptbal, cleanup, profile_memory, write_selection,
         verbose, debug, dry_run):

    profile_time = False


    comm = MPI.COMM_WORLD
    np.seterr(all='raise')
    params = dict(locals())

    env = Env(**params)

    if profile_time:
        from dentate.network import init, run
        import cProfile
        cProfile.runctx('init(env)', None, locals(), filename='dentate_profile_init')
        if not dry_run:
            cProfile.runctx('run(env)', None, locals(), filename='dentate_profile_run')
    else:
        network.init(env)
        if not dry_run:
            network.run(env)
Ejemplo n.º 6
0
def config_controller():
    """

    """
    utils.config_logging(context.verbose)
    context.logger = utils.get_script_logger(os.path.basename(__file__))

    # TODO: I don't think the controller needs this
    if 'results_file_id' not in context():
        context.results_file_id = 'DG_optimize_network_subworlds_%s_%s' % \
                             (context.interface.worker_id, datetime.datetime.today().strftime('%Y%m%d_%H%M'))

    try:
        context.env = Env(comm=context.controller_comm,
                          results_file_id=context.results_file_id,
                          **context.kwargs)
    except Exception as err:
        context.logger.exception(err)
        raise err

    param_bounds, param_names, param_initial_dict, param_tuples, opt_targets = \
        optimization_params(context.env, context.target_populations, context.param_config_name)

    context.param_names = param_names
    context.bounds = [param_bounds[key] for key in param_names]
    context.x0 = param_initial_dict
    context.target_val = opt_targets
    context.target_range = opt_targets
    context.param_tuples = param_tuples
    # These kwargs will be sent from the controller to each worker context
    context.kwargs['param_tuples'] = param_tuples
Ejemplo n.º 7
0
def config_controller():
    """

    """
    utils.config_logging(context.verbose)
    context.logger = utils.get_script_logger(os.path.basename(__file__))

    try:
        context.env = Env(comm=context.controller_comm, **context.kwargs)
    except Exception as err:
        context.logger.exception(err)
        raise err

    opt_param_config = optimization_params(
        context.env.netclamp_config.optimize_parameters,
        context.target_populations, context.param_config_name)
    param_bounds = opt_param_config.param_bounds
    param_names = opt_param_config.param_bounds
    param_initial_dict = opt_param_config.param_initial_dict
    param_tuples = opt_param_config.param_tuples
    opt_targets = opt_param_config.opt_targets

    context.param_names = param_names
    context.bounds = [param_bounds[key] for key in param_names]
    context.x0 = param_initial_dict
    context.target_val = opt_targets
    context.target_range = opt_targets
    context.param_tuples = param_tuples
    # These kwargs will be sent from the controller to each worker context
    context.kwargs['param_tuples'] = param_tuples
Ejemplo n.º 8
0
def main(template_path, forest_path, synapses_path, connections_path, config_path):
    
    comm = MPI.COMM_WORLD
    rank = comm.Get_rank()

    env = Env(comm=comm, config_file=config_path, template_paths=template_path)

    h('objref nil, pc, tlog, Vlog, spikelog')
    h.load_file("nrngui.hoc")
    h.xopen ("./tests/rn.hoc")
    h.xopen(template_path+'/HICAPCell.hoc')
    
    pop_name = "HCC"
    gid = 1043250
    (trees_dict,_) = read_tree_selection (forest_path, pop_name, [gid], comm=env.comm)

    (_, tree) = next(trees_dict)
    v_init = -67
    
    template_class = getattr(h, "HICAPCell")

    passive_test(template_class, tree, v_init)
    ap_test(template_class, tree, v_init)
    ap_rate_test(template_class, tree, v_init)
    fi_test(template_class, tree, v_init)

    if synapses_path and connections_path:
        synapses_iter = read_cell_attribute_selection (synapses_path, pop_name, [gid],
                                                       "Synapse Attributes", comm=env.comm)
        (_, synapses_dict) = next(synapses_iter)
        connections = read_graph_selection(file_name=connections_path, selection=[gid],
                                            namespaces=['Synapses', 'Connections'], comm=env.comm)

        synapse_test(template_class, gid, tree, synapses_dict, connections, v_init, env)
Ejemplo n.º 9
0
def init_network():
    """

    """
    np.seterr(all='raise')
    context.env = Env(comm=context.comm, results_file_id=context.results_file_id, **context.kwargs)
    network.init(context.env)
Ejemplo n.º 10
0
def main(config, config_prefix, connectivity_path, coords_path, output_path,
         vertex_metrics_namespace, distances_namespace, destination, sources,
         bin_size, verbose):

    utils.config_logging(verbose)
    logger = utils.get_script_logger(script_name)

    env = Env(config_file=config, config_prefix=config_prefix)

    layer_extents = env.geometry['Parametric Surface']['Layer Extents']
    (extent_u, extent_v, extent_l) = geometry.get_total_extents(layer_extents)

    extents = geometry.measure_distance_extents(env)

    comm = MPI.COMM_WORLD

    graph_dict = graph.spatial_bin_graph(connectivity_path,
                                         coords_path,
                                         distances_namespace,
                                         destination,
                                         sources,
                                         extents,
                                         bin_size=bin_size,
                                         comm=comm)

    if comm.rank == 0:
        graph.save_spatial_bin_graph(output_path, graph_dict)

    comm.barrier()
Ejemplo n.º 11
0
def init_env():
    """

    """
    context.env = Env(comm=context.comm, results_file_id=context.results_file_id, **context.init_params)
    configure_hoc_env(context.env)
    context.gid = int(context.init_params['gid'])
    context.population = context.init_params['population']
    context.target_val = {}
Ejemplo n.º 12
0
def main(config, config_prefix, coords_path, distances_namespace, population, graph_type, bin_size, verbose):

    utils.config_logging(verbose)

    env = Env(config_file=config, config_prefix=config_prefix)

    soma_distances = read_cell_attributes(coords_path, population, namespace=distances_namespace)

    plot.plot_positions (env, population, soma_distances, bin_size=bin_size, graph_type=graph_type, saveFig=True)
Ejemplo n.º 13
0
def main(gid, pop_name, config_file, template_paths, hoc_lib_path, dataset_prefix, config_prefix, mech_file,
         load_edges, load_weights, correct_for_spines, verbose):
    """

    :param gid: int
    :param pop_name: str
    :param config_file: str; model configuration file name
    :param template_paths: str; colon-separated list of paths to directories containing hoc cell templates
    :param hoc_lib_path: str; path to directory containing required hoc libraries
    :param dataset_prefix: str; path to directory containing required neuroh5 data files
    :param config_prefix: str; path to directory containing network and cell mechanism config files
    :param mech_file: str; cell mechanism config file name
    :param load_edges: bool; whether to attempt to load connections from a neuroh5 file
    :param load_weights: bool; whether to attempt to load connections from a neuroh5 file
    :param correct_for_spines: bool
    :param verbose: bool
    """
    utils.config_logging(verbose)
    logger = utils.get_script_logger(os.path.basename(__file__))

    comm = MPI.COMM_WORLD
    np.seterr(all='raise')
    env = Env(comm=comm, config_file=config_file, template_paths=template_paths, hoc_lib_path=hoc_lib_path,
              dataset_prefix=dataset_prefix, config_prefix=config_prefix, verbose=verbose)
    configure_hoc_env(env)

    mech_file_path = config_prefix + '/' + mech_file
    template_name = env.celltypes[pop_name]['template']
    if template_name.lower() == 'izhikevich':
        cell = make_izhikevich_cell(env, pop_name=pop_name, gid=gid,
                                    load_synapses=True, load_connections=True,
                                    load_edges=load_edges, load_weights=load_weights,
                                    mech_file_path=mech_file_path)
    elif template_name.lower() == 'pr_nrn':
        cell = make_PR_cell(env, pop_name=pop_name, gid=gid,
                            load_synapses=True, load_connections=True,
                            load_edges=load_edges, load_weights=load_weights,
                            mech_file_path=mech_file_path)
    else:
        cell = make_biophys_cell(env, pop_name=pop_name, gid=gid,
                                 load_synapses=True, load_connections=True,
                                 load_edges=load_edges, load_weights=load_weights,
                                 mech_file_path=mech_file_path)
    context.update(locals())

    init_biophysics(cell, reset_cable=True, correct_cm=correct_for_spines, correct_g_pas=correct_for_spines,
                    env=env, verbose=verbose)

    init_syn_mech_attrs(cell, env)
    config_biophys_cell_syns(env, gid, pop_name, insert=True, insert_netcons=True, insert_vecstims=True,
                             verbose=verbose)

    if verbose:
        for sec in list(cell.hoc_cell.all if hasattr(cell, 'hoc_cell') else cell.all):
            h.psection(sec=sec)
        report_topology(cell, env)
Ejemplo n.º 14
0
def main(gid, pop_name, config_file, template_paths, hoc_lib_path,
         dataset_prefix, config_prefix, mech_file, load_edges, load_weights,
         correct_for_spines, verbose):
    """

    :param gid: int
    :param pop_name: str
    :param config_file: str; model configuration file name
    :param template_paths: str; colon-separated list of paths to directories containing hoc cell templates
    :param hoc_lib_path: str; path to directory containing required hoc libraries
    :param dataset_prefix: str; path to directory containing required neuroh5 data files
    :param config_prefix: str; path to directory containing network and cell mechanism config files
    :param mech_file: str; cell mechanism config file name
    :param load_edges: bool; whether to attempt to load connections from a neuroh5 file
    :param load_weights: bool; whether to attempt to load connections from a neuroh5 file
    :param correct_for_spines: bool
    :param verbose: bool
    """
    comm = MPI.COMM_WORLD
    np.seterr(all='raise')
    env = Env(comm=comm,
              config_file=config_file,
              template_paths=template_paths,
              hoc_lib_path=hoc_lib_path,
              dataset_prefix=dataset_prefix,
              config_prefix=config_prefix,
              verbose=verbose)
    configure_hoc_env(env)

    mech_file_path = config_prefix + '/' + mech_file
    cell = get_biophys_cell(env,
                            pop_name=pop_name,
                            gid=gid,
                            load_edges=load_edges,
                            load_weights=load_weights,
                            mech_file_path=mech_file_path)
    context.update(locals())

    init_biophysics(cell,
                    reset_cable=True,
                    correct_cm=correct_for_spines,
                    correct_g_pas=correct_for_spines,
                    env=env,
                    verbose=verbose)
    init_syn_mech_attrs(cell, env)
    config_biophys_cell_syns(env,
                             gid,
                             pop_name,
                             insert=True,
                             insert_netcons=True,
                             insert_vecstims=True,
                             verbose=verbose)

    if verbose:
        report_topology(cell, env)
Ejemplo n.º 15
0
def main(config_path, template_paths, forest_path, synapses_path):

    comm = MPI.COMM_WORLD
    rank = comm.Get_rank()
    env = Env(comm=comm,
              config_file=config_path,
              template_paths=template_paths)

    neuron_utils.configure_hoc_env(env)

    h.pc = h.ParallelContext()

    v_init = -65.0
    popName = "MC"
    gid = 1000000

    env.load_cell_template(popName)

    (trees, _) = read_tree_selection(forest_path, popName, [gid], comm=comm)
    if synapses_path is not None:
        synapses_iter = read_cell_attribute_selection (synapses_path, popName, [gid], \
                                                       "Synapse Attributes", comm=comm)
    else:
        synapses_iter = None

    gid, tree = next(trees)
    if synapses_iter is not None:
        (_, synapses) = next(synapses_iter)
    else:
        synapses = None

    if 'mech_file' in env.celltypes[popName]:
        mech_file_path = env.config_prefix + '/' + env.celltypes[popName][
            'mech_file']
    else:
        mech_file_path = None

    template_class = getattr(h, "MossyCell")

    if (synapses is not None):
        synapse_test(template_class, mech_file_path, gid, tree, synapses,
                     v_init, env)
Ejemplo n.º 16
0
def main(config, template_path, prototype_gid, prototype_path, forest_path, population, io_size, verbose):
    """

    :param config:
    :param template_path:
    :param prototype_gid:
    :param prototype_path:
    :param forest_path:
    :param population:
    :param io_size:
    """

    utils.config_logging(verbose)
    logger = utils.get_script_logger(script_name)
        
    comm = MPI.COMM_WORLD
    rank = comm.rank
    
    env = Env(comm=MPI.COMM_WORLD, config_file=config, template_paths=template_path)
    configure_hoc_env(env)
    
    if io_size == -1:
        io_size = comm.size
    if rank == 0:
        logger.info('%i ranks have been allocated' % comm.size)
    
    layers = env.layers
    layer_idx_dict = { layers[layer_name]: layer_name 
                       for layer_name in ['GCL', 'IML', 'MML', 'OML', 'Hilus'] }

    (tree_iter, _) = read_tree_selection(prototype_path, population, selection=[prototype_gid])
    (_, prototype_morph_dict) = next(tree_iter)
    prototype_x = prototype_morph_dict['x']
    prototype_y = prototype_morph_dict['y']
    prototype_z = prototype_morph_dict['z']
    prototype_xyz = (prototype_x, prototype_y, prototype_z)

    (pop_ranges, _) = read_population_ranges(forest_path, comm=comm)
    start_time = time.time()

    (population_start, _) = pop_ranges[population]
    template_class = load_cell_template(env, population, bcast_template=True)
    for gid, morph_dict in NeuroH5TreeGen(forest_path, population, io_size=io_size, cache_size=1, comm=comm, topology=True):
#    trees, _ = scatter_read_trees(forest_path, population, io_size=io_size, comm=comm, topology=True)
 #   for gid, morph_dict in trees:
        if gid is not None:
            logger.info('Rank %i gid: %i' % (rank, gid))
            secnodes_dict = morph_dict['section_topology']['nodes']
            vx = morph_dict['x']
            vy = morph_dict['y']
            vz = morph_dict['z']
            if compare_points((vx,vy,vz), prototype_xyz):
                logger.info('Possible match: gid %i' % gid)
    MPI.Finalize()
Ejemplo n.º 17
0
def main(config, config_prefix, resolution, resample, alpha_radius, graph_type,
         verbose):

    utils.config_logging(verbose)
    logger = utils.get_script_logger(script_name)

    env = Env(config_file=config, config_prefix=config_prefix)

    layers = env.layers
    rotate = env.geometry['Parametric Surface']['Rotation']
    min_u = float('inf')
    max_u = 0.0
    min_v = float('inf')
    max_v = 0.0
    min_l = float('inf')
    max_l = 0.0
    for layer in list(layers.keys()):
        min_extent = env.geometry['Parametric Surface']['Minimum Extent'][
            layer]
        max_extent = env.geometry['Parametric Surface']['Maximum Extent'][
            layer]
        min_u = min(min_extent[0], min_u)
        max_u = max(max_extent[0], max_u)
        min_v = min(min_extent[1], min_v)
        max_v = max(max_extent[1], max_v)
        min_l = min(min_extent[2], min_l)
        max_l = max(max_extent[2], max_l)

    logger.info('Creating volume: min_l = %f max_l = %f...' % (min_l, max_l))
    ip_volume = make_volume((min_u, max_u), \
                            (min_v, max_v), \
                            (min_l, max_l), \
                            resolution=resolution, \
                            rotate=rotate)
    logger.info('Computing volume distances...')

    vol_dist = get_volume_distances(ip_volume,
                                    res=resample,
                                    alpha_radius=alpha_radius)
    (obs_uv, dist_u, dist_v) = vol_dist

    dist_dict = {}
    for i in range(0, len(dist_u)):
        dist_dict[i] = { 'U Distance': np.asarray([dist_u[i]], dtype=np.float32), \
                         'V Distance': np.asarray([dist_v[i]], dtype=np.float32) }

    plot.plot_positions(env,
                        "DG Volume",
                        dist_dict,
                        verbose=verbose,
                        saveFig=True,
                        graphType=graph_type)
def init_network_clamp():
    """

    """
    np.seterr(all='raise')
    if context.env is None:
        context.env = Env(comm=context.comm,
                          results_file_id=context.results_file_id,
                          **context.init_params)
        configure_hoc_env(env)

    context.gid = int(context.init_params['gid'])
    context.population = context.init_params['population']
    context.target_val = {}
    network_clamp.init(
        context.env,
        context.init_params['population'],
        set([context.gid]),
        arena_id=context.init_params['arena_id'],
        trajectory_id=context.init_params['trajectory_id'],
        n_trials=int(context.init_params['n_trials']),
        spike_events_path=context.init_params.get('spike_events_path', None),
        spike_events_namespace=context.init_params.get(
            'spike_events_namespace', None),
        spike_train_attr_name=context.init_params.get('spike_train_attr_name',
                                                      None),
        input_features_path=context.init_params.get('input_features_path',
                                                    None),
        input_features_namespaces=context.init_params.get(
            'input_features_namespaces', None),
        t_min=0.,
        t_max=context.init_params['tstop'])

    context.equilibration_duration = float(
        context.env.stimulus_config['Equilibration Duration'])

    state_variable = 'v'
    context.recording_profile = {
        'label': 'optimize_network_clamp.state.%s' % state_variable,
        'dt': 0.1,
        'section quantity': {
            state_variable: {
                'swc types': ['soma']
            }
        }
    }
    context.state_recs_dict = {}
    context.state_recs_dict[context.gid] = cells.record_cell(
        context.env,
        context.population,
        context.gid,
        recording_profile=context.recording_profile)
Ejemplo n.º 19
0
def main(config, config_prefix, connectivity_path, coords_path,
         distances_namespace, target_gid, destination, source, extent_type,
         direction, normed, bin_size, font_size, save_format, verbose):

    utils.config_logging(verbose)
    logger = utils.get_script_logger(os.path.basename(script_name))

    env = Env(config_file=config, config_prefix=config_prefix)

    plot.plot_single_vertex_dist (env, connectivity_path, coords_path, distances_namespace, \
                                  target_gid, destination, source, direction=direction, \
                                  normed=normed, extent_type=extent_type, bin_size=bin_size, \
                                  fontSize=font_size, saveFig=True, figFormat=save_format)
Ejemplo n.º 20
0
def init_network():
    """

    """
    np.seterr(all='raise')
    context.comm.barrier()
    context.env = Env(comm=context.comm,
                      results_file_id=context.results_file_id,
                      **context.kwargs)
    network.init(context.env)
    if context.debug:
        raise RuntimeError('config_worker: after network.init')
    context.comm.barrier()
Ejemplo n.º 21
0
def main(config, stimulus_id, template_path, coords_path, output_path,
         distances_namespace, io_size, chunk_size, value_chunk_size,
         cache_size, write_size, verbose, dry_run):
    """

    :param config:
    :param coords_path:
    :param distances_namespace:
    :param io_size:
    :param chunk_size:
    :param value_chunk_size:
    :param cache_size:
    :param write_size:
    :param dry_run:
    """
    comm = MPI.COMM_WORLD
    rank = comm.rank

    env = Env(comm=comm, config_file=config, template_paths=template_path)
    if io_size == -1:
        io_size = comm.size
    if rank == 0:
        logger.info('%i ranks have been allocated' % comm.size)

    if (not dry_run) and (rank == 0):
        if not os.path.isfile(output_path):
            input_file = h5py.File(coords_path, 'r')
            output_file = h5py.File(output_path, 'w')
            input_file.copy('/H5Types', output_file)
            input_file.close()
            output_file.close()
    comm.barrier()
    population_ranges = read_population_ranges(coords_path, comm)[0]
    context.update(locals())

    gid_normed_distances = assign_cells_to_normalized_position(
    )  # Assign normalized u,v coordinates
    gid_module_assignments = assign_cells_to_module(
        gid_normed_distances, p_width=0.75, displace=0.0
    )  # Determine which module a cell is in based on normalized u position
    total_num_fields, gid_attributes = determine_cell_participation(
        gid_module_assignments
    )  # Determine if a cell is 1) active and; 2) how many fields?
    cell_attributes = build_cell_attributes(
        gid_attributes, gid_normed_distances, total_num_fields
    )  # Determine additional cell properties (lambda, field_width, orientation, jitter, and rate map. This will also build the data structure ({<pop>: {<cell type>: <cells>}}) containing all cells.

    if not dry_run and rank == 0:
        save_to_h5(cell_attributes)
Ejemplo n.º 22
0
def main(config, coords_path, coords_namespace, resample, resolution, populations, projection_depth, io_size, chunk_size, value_chunk_size, cache_size, verbose):

    utils.config_logging(verbose)
    logger = utils.get_script_logger(script_name)
    
    comm = MPI.COMM_WORLD
    rank = comm.rank

    env = Env(comm=comm, config_file=config)

    soma_coords = {}

    if rank == 0:
        logger.info('Reading population coordinates...')

    rotate = env.geometry['Parametric Surface']['Rotation']
    min_l = float('inf')
    max_l = 0.0
    population_ranges = read_population_ranges(coords_path)[0]
    population_extents = {}
    for population in population_ranges:
        min_extent = env.geometry['Cell Layers']['Minimum Extent'][population]
        max_extent = env.geometry['Cell Layers']['Maximum Extent'][population]
        min_l = min(min_extent[2], min_l)
        max_l = max(max_extent[2], max_l)
        population_extents[population] = (min_extent, max_extent)
        
    for population in populations:
        coords = bcast_cell_attributes(coords_path, population, 0, \
                                       namespace=coords_namespace)

        soma_coords[population] = { k: (v['U Coordinate'][0], v['V Coordinate'][0], v['L Coordinate'][0]) for (k,v) in coords }
        del coords
        gc.collect()
    
    output_path = coords_path
    soma_coords = icp_transform(comm, soma_coords, projection_depth, population_extents, \
                                populations=populations, rotate=rotate, verbose=verbose)
    
    for population in populations:

        if rank == 0:
            logger.info('Writing transformed coordinates for population %s...' % population)

        append_cell_attributes(output_path, population, soma_coords[population],
                               namespace='Soma Projections', comm=comm,
                               io_size=io_size, chunk_size=chunk_size,
                               value_chunk_size=value_chunk_size, cache_size=cache_size)
Ejemplo n.º 23
0
def main(config_file, template_paths, hoc_lib_path, dataset_prefix,
         config_prefix, results_path, results_id, input_path, input_namespace,
         target_cell, tstop, v_init, stimulus_onset, max_walltime_hours,
         results_write_time, dt, ldbal, lptbal, verbose, dry_run):
    """
    :param config_file: str; model configuration file name
    :param template_paths: str; colon-separated list of paths to directories containing hoc cell templates
    :param hoc_lib_path: str; path to directory containing required hoc libraries
    :param dataset_prefix: str; path to directory containing required neuroh5 data files
    :param config_prefix: str; path to directory containing network and cell mechanism config files
    :param results_path: str; path to directory to export output files
    :param results_id: str; label for neuroh5 namespaces to write spike and voltage trace data
    :param tstop: int; physical time to simulate (ms)
    :param v_init: float; initialization membrane potential (mV)
    :param stimulus_onset: float; starting time of stimulus (ms)
    :param max_walltime_hours: float; maximum wall time (hours)
    :param results_write_time: float; time to write out results at end of simulation
    :param dt: float; simulation time step
    :param verbose: bool; print verbose diagnostic messages while constructing the network
    :param dry_run: bool; whether to actually execute simulation after building network
    """
    comm = MPI.COMM_WORLD
    np.seterr(all='raise')
    vrecord_fraction = 1.0
    env = Env(comm,
              config_file,
              template_paths,
              hoc_lib_path,
              dataset_prefix,
              config_prefix,
              results_path,
              results_id,
              vrecord_fraction,
              target_cell,
              tstop,
              v_init,
              stimulus_onset,
              max_walltime_hours,
              results_write_time,
              dt,
              cell_selection=target_cell,
              spike_input_path=input_path,
              spike_input_ns=input_namespace,
              verbose=verbose)
    network.init(env)
    if not dry_run:
        network.run(env)
Ejemplo n.º 24
0
def main(config_file, population, gid, template_paths, dataset_prefix,
         config_prefix, load_synapses, syn_types, syn_sources,
         syn_source_threshold, font_size, bgcolor, colormap, verbose):

    utils.config_logging(verbose)
    logger = utils.get_script_logger(script_name)

    params = dict(locals())
    env = Env(**params)
    configure_hoc_env(env)

    ## Determine if a mechanism configuration file exists for this cell type
    if 'mech_file_path' in env.celltypes[population]:
        mech_file_path = env.celltypes[population]['mech_file_path']
    else:
        mech_file_path = None

    logger.info('loading cell %i' % gid)

    load_weights = False
    biophys_cell = get_biophys_cell(env,
                                    population,
                                    gid,
                                    load_synapses=load_synapses,
                                    load_weights=load_weights,
                                    load_edges=load_synapses,
                                    mech_file_path=mech_file_path)

    if len(syn_types) == 0:
        syn_types = None
    else:
        syn_types = list(syn_types)
    if len(syn_sources) == 0:
        syn_sources = None
    else:
        syn_sources = list(syn_sources)

    plot.plot_biophys_cell_tree(env,
                                biophys_cell,
                                saveFig=True,
                                syn_source_threshold=syn_source_threshold,
                                synapse_filters={
                                    'syn_types': syn_types,
                                    'sources': syn_sources
                                },
                                bgcolor=bgcolor,
                                colormap=colormap)
Ejemplo n.º 25
0
def init_context():

    if 'env' not in context():
        context.env = Env(**context.kwargs)

    local_random = random.Random()
    local_random.seed(context.local_seed)

    feature_type_random = np.random.RandomState(context.local_seed)
    field_random = np.random.RandomState(context.local_seed)
    field_probabilities = None

    input_params = context.env.input_config

    nmodules = input_params['Number Modules']
    field_width_x1 = input_params['Field Width']['x1']
    field_width_x2 = input_params['Field Width']['x2']
    min_field_width = input_params['Field Width']['min']
    resolution = input_params['Spatial Resolution']
    peak_rate = input_params['Peak Rate']

    modules = np.arange(nmodules)
    grid_orientation = [
        local_random.uniform(0, np.pi / 3.) for i in xrange(nmodules)
    ]
    field_width_params = [field_width_x1, field_width_x2]
    field_width = lambda x: min_field_width + field_width_params[0] * (np.exp(
        x / field_width_params[1]) - 1.)
    max_field_width = field_width(1.)
    module_width = field_width(float(context.module) / np.max(modules))

    arena = context.env.input_config['Arena'][context.arena_id]

    mesh = generate_spatial_mesh(scale_factor=1.,
                                 arena=arena,
                                 resolution=resolution)
    nx, ny = mesh[0].shape[0], mesh[0].shape[1]

    grid_cells, place_cells = {}, {}
    place_gid_start = None
    context.update(locals())
    context.update(input_params)
    context.grid_cells, context.place_gid_start = _build_cells(
        context.num_grid, 'grid', context.module)
    _calculate_rate_maps(context.grid_cells, context)
Ejemplo n.º 26
0
def main(config, coords_path, coords_namespace, distances_namespace,
         populations, verbose):

    utils.config_logging(verbose)
    logger = utils.get_script_logger(__file__)

    comm = MPI.COMM_WORLD
    rank = comm.rank

    env = Env(comm=comm, config_file=config)
    output_path = coords_path

    soma_coords = {}
    soma_distances = {}

    if rank == 0:
        logger.info('Reading population coordinates and distances...')

    for population in populations:

        coords = bcast_cell_attributes(coords_path,
                                       population,
                                       0,
                                       namespace=coords_namespace,
                                       comm=comm)
        soma_coords[population] = {
            k:
            (v['U Coordinate'][0], v['V Coordinate'][0], v['L Coordinate'][0])
            for (k, v) in coords
        }
        del coords
        gc.collect()

        distances = bcast_cell_attributes(coords_path,
                                          population,
                                          0,
                                          namespace=distances_namespace,
                                          comm=comm)
        soma_distances = {
            k: (v['U Distance'][0], v['V Distance'][0])
            for (k, v) in distances
        }
        del distances
        gc.collect()
Ejemplo n.º 27
0
def main(coords_path, io_size, chunk_size, value_chunk_size):

    utils.config_logging(verbose)
    logger = utils.get_script_logger(__file__)
    
    comm = MPI.COMM_WORLD
    rank = comm.rank

    env = Env(comm=comm, config_file=config)
    output_path = coords_path

    if io_size == -1:
        io_size = comm.size
    if rank == 0:
        logger.info('%i ranks have been allocated' % comm.size)

    source_population_ranges = read_population_ranges(coords_path)
    source_populations = list(source_population_ranges.keys())

    for population in source_populations:
        if rank == 0:
            logger.info('population: ',population)
        soma_coords = bcast_cell_attributes(0, coords_path, population,
                                            namespace='Interpolated Coordinates', comm=comm)
        #print soma_coords.keys()
        u_coords = []
        gids = []
        for gid, attrs in viewitems(soma_coords):
            u_coords.append(attrs['U Coordinate'])
            gids.append(gid)
        u_coordv = np.asarray(u_coords, dtype=np.float32)
        gidv     = np.asarray(gids, dtype=np.uint32)
        sort_idx = np.argsort(u_coordv, axis=0)
        offset   = source_population_ranges[population][0]
        sorted_coords_dict = {}
        for i in range(0,sort_idx.size):
            sorted_coords_dict[offset+i] = soma_coords[gidv[sort_idx[i][0]]]
        
        append_cell_attributes(coords_path, population, sorted_coords_dict,
                                namespace='Sorted Coordinates', io_size=io_size, chunk_size=chunk_size,
                                value_chunk_size=value_chunk_size, comm=comm)
Ejemplo n.º 28
0
def main(cell_selection_path, config_file, template_paths, hoc_lib_path,
         dataset_prefix, config_prefix, results_path, results_id,
         node_rank_file, io_size, vrecord_fraction, coredat, tstop, v_init,
         stimulus_onset, max_walltime_hours, results_write_time,
         spike_input_path, spike_input_namespace, dt, ldbal, lptbal, cleanup,
         verbose, run_test):
    """
    :param cell_selection_path: str; name of file specifying subset of cells gids to be instantiated
    :param config_file: str; model configuration file name
    :param template_paths: str; colon-separated list of paths to directories containing hoc cell templates
    :param hoc_lib_path: str; path to directory containing required hoc libraries
    :param dataset_prefix: str; path to directory containing required neuroh5 data files
    :param config_prefix: str; path to directory containing network and cell mechanism config files
    :param results_path: str; path to directory to export output files
    :param results_id: str; label for neuroh5 namespaces to write spike and voltage trace data
    :param node_rank_file: str; name of file specifying assignment of node gids to MPI ranks
    :param io_size: int; the number of MPI ranks to be used for I/O operations
    :param vrecord_fraction: float; fraction of cells to record intracellular voltage from
    :param coredat: bool; Save CoreNEURON data
    :param tstop: int; physical time to simulate (ms)
    :param v_init: float; initialization membrane potential (mV)
    :param stimulus_onset: float; starting time of stimulus (ms)
    :param max_walltime_hours: float; maximum wall time (hours)
    :param results_write_time: float; time to write out results at end of simulation
    :param spike_input_path: str; path to file for input spikes when cell selection is specified
    :param spike_input_namespace: str;
    :param dt: float; simulation time step
    :param ldbal: bool; estimate load balance based on cell complexity
    :param lptbal: bool; calculate load balance with LPT algorithm
    :param cleanup: bool; whether to delete from memory the synapse attributes metadata after specifying connections
    :param verbose: bool; print verbose diagnostic messages while constructing the network
    :param run_test: bool; whether to actually execute simulation after building network
    """
    comm = MPI.COMM_WORLD
    np.seterr(all='raise')
    params = dict(locals())
    env = Env(**params)
    network.init(env)
    if run_test:
        network.run(env, output=False)
Ejemplo n.º 29
0
def main(config, features_path, features_namespace, arena_id, include,
         font_size, verbose, save_fig):
    """
    
    :param features_path: 
    :param features_namespace: 
    :param include: 
    :param font_size: 
    :param verbose: 
    :param save_fig:  
    """
    utils.config_logging(verbose)

    env = Env(config_file=config)

    for population in include:
        plot.plot_stimulus_ratemap(env,
                                   features_path,
                                   features_namespace,
                                   population,
                                   arena_id=arena_id,
                                   fontSize=font_size,
                                   saveFig=save_fig)
def main(config, config_prefix, features_path, coords_path, features_namespace,
         arena_id, trajectory_id, distances_namespace, include, bin_size,
         from_spikes, normed, font_size, verbose, save_fig):

    utils.config_logging(verbose)

    logger = utils.get_script_logger(os.path.basename(script_name))

    env = Env(config_file=config, config_prefix=config_prefix)

    plot.plot_stimulus_spatial_rate_map(env,
                                        features_path,
                                        coords_path,
                                        arena_id,
                                        trajectory_id,
                                        features_namespace,
                                        distances_namespace,
                                        include,
                                        bin_size=bin_size,
                                        from_spikes=from_spikes,
                                        normed=normed,
                                        fontSize=font_size,
                                        saveFig=save_fig,
                                        verbose=verbose)