예제 #1
0
def load_config(config):
    if isinstance(config, string_types):
        return ConfigDict.from_json(config)
    elif isinstance(config, dict):
        return ConfigDict.from_dict(config)
    else:
        raise Exception('Could not convert {} (type "{}") to json.'.format(config, type(config)))
예제 #2
0
def load_spikes_file(config_file=None, spikes_file=None):
    if spikes_file is not None:
        return SpikeTrains.load(spikes_file)

    elif config_file is not None:
        config = ConfigDict.from_json(config_file)
        return SpikeTrains.load(config.spikes_file)
예제 #3
0
    def from_config(cls, conf, **properties):
        """Generates a graph structure from a json config file or dictionary.

        :param conf: name of json config file, or a dictionary with config parameters
        :param properties: optional properties.
        :return: A graph object of type cls
        """
        network = cls(**properties)

        # The simulation run script should create a config-dict since it's likely to vary based on the simulator engine,
        # however in the case the user doesn't we will try a generic conversion from dict/json to ConfigDict
        if isinstance(conf, ConfigDict):
            config = conf
        else:
            try:
                config = ConfigDict.load(conf)
            except Exception as e:
                network.io.log_exception('Could not convert {} (type "{}") to json.'.format(conf, type(conf)))

        if not config.with_networks:
            network.io.log_exception('Could not find any network files. Unable to build network.')

        # TODO: These are simulator specific
        network.spike_threshold = config.spike_threshold
        network.dL = config.dL

        # load components
        for name, value in config.components.items():
            network.add_component(name, value)

        # load nodes
        gid_map = config.gid_mappings
        node_adaptor = network.get_node_adaptor('sonata')
        for node_dict in config.nodes:
            nodes = sonata_reader.load_nodes(node_dict['nodes_file'], node_dict['node_types_file'], gid_map,
                                             adaptor=node_adaptor)
            for node_pop in nodes:
                network.add_nodes(node_pop)

        # TODO: Raise a warning if more than one internal population and no gids (node_id collision)

        # load edges
        edge_adaptor = network.get_edge_adaptor('sonata')
        for edge_dict in config.edges:
            if not edge_dict.get('enabled', True):
                continue

            edges = sonata_reader.load_edges(edge_dict['edges_file'], edge_dict['edge_types_file'],
                                             adaptor=edge_adaptor)
            for edge_pop in edges:
                network.add_edges(edge_pop)

        # Add nodeset section
        network.add_node_set('all', NodeSetAll(network))
        for ns_name, ns_filter in config.node_sets.items():
            network.add_node_set(ns_name, NodeSet(ns_filter, network))

        return network
예제 #4
0
def load_reports(config_file):
    cfg = ConfigDict.from_json(config_file)
    reports = []
    for report_name, report in cfg.reports.items():
        if report['module'] not in ['membrane_report', 'multimeter_report']:
            continue
        report_file = report[
            'file_name'] if 'file_name' in report else '{}.h5'.format(
                report_name)
        report_file = report_file if os.path.isabs(
            report_file) else os.path.join(cfg.output_dir, report_file)
        reports.append(CompartmentReport(report_file, 'r'))

    return reports