Пример #1
0
Файл: nodes.py Проект: MFSY/snap
    def load_population_data(self, population):
        """Load node properties from SONATA Nodes.

        Args:
            population (str): a population name .

        Returns:
            pandas.DataFrame with node properties (zero-based index).
        """
        nodes = self.storage.open_population(population)
        categoricals = nodes.enumeration_names

        node_count = nodes.size
        result = pd.DataFrame(index=np.arange(node_count))

        _all = libsonata.Selection([(0, node_count)])
        for attr in sorted(nodes.attribute_names):
            if attr in categoricals:
                enumeration = np.asarray(nodes.get_enumeration(attr, _all))
                values = np.asarray(nodes.enumeration_values(attr))
                # if the size of `values` is large enough compared to `enumeration`, not using
                # categorical reduces the memory usage.
                if values.shape[0] < 0.5 * enumeration.shape[0]:
                    result[attr] = pd.Categorical.from_codes(enumeration,
                                                             categories=values)
                else:
                    result[attr] = values[enumeration]
            else:
                result[attr] = nodes.get_attribute(attr, _all)
        for attr in sorted(
                utils.add_dynamic_prefix(nodes.dynamics_attribute_names)):
            result[attr] = nodes.get_dynamics_attribute(
                attr.split(DYNAMICS_PREFIX)[1], _all)
        return result
Пример #2
0
    def properties(self, edge_ids, properties):
        """
        Edge properties as pandas DataFrame.

        Args:
            edge_ids: array-like of edge IDs
            properties: edge property name | list of edge property names

        Returns:
            Pandas Series indexed by edge IDs if `properties` is scalar;
            Pandas DataFrame indexed by edge IDs if `properties` is list.
        """
        selection = libsonata.Selection(edge_ids)
        return self._get(selection, properties)
Пример #3
0
def _load_population(h5_filepath, csv_filepath, population):
    """
    Load node properties from SONATA Nodes.

    Returns:
        pandas.DataFrame with node properties (zero-based index).
    """
    nodes = libsonata.NodePopulation(h5_filepath, csv_filepath or '', population)

    node_count = nodes.size
    result = pd.DataFrame(index=np.arange(node_count))

    _all = libsonata.Selection([(0, node_count)])
    for prop in sorted(nodes.attribute_names):
        result[prop] = nodes.get_attribute(prop, _all)

    return result
Пример #4
0
    def properties(self, edge_ids, properties):
        """Edge properties as pandas DataFrame.

        Args:
            edge_ids (array-like): array-like of edge IDs
            properties (str/list): an edge property name or a list of edge property names

        Returns:
            pandas.Series/pandas.DataFrame:
                A pandas Series indexed by edge IDs if ``properties`` is scalar.
                A pandas DataFrame indexed by edge IDs if ``properties`` is list.

        Notes:
            The EdgePopulation.property_names function will give you all the usable properties
            for the `properties` argument.
        """
        selection = libsonata.Selection(edge_ids)
        return self._get(selection, properties)