<commit_before>## Copyright 2015-2016 <NAME> (FIAS), <NAME> (FIAS)

## This program is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 3 of the
## License, or (at your option) any later version.

## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.

## You should have received a copy of the GNU General Public License
## along with this program.  If not, see <http://www.gnu.org/licenses/>.

"""Functions for computing network clusters
"""

from __future__ import absolute_import, print_function, division

__author__ = "<NAME> (FIAS), <NAME> (FIAS)"
__copyright__ = "Copyright 2015-2016 <NAME> (FIAS), <NAME> (FIAS), GNU GPL 3"

import numpy as np
import pandas as pd
import networkx as nx
from collections import OrderedDict, namedtuple
from itertools import repeat
from six.moves import zip, range
from six import itervalues

from .descriptors import OrderedGraph
from . import components, io
from . import Network

def _consense(x):
    v = x.iat[0]
    assert ((x == v).all() or x.isnull().all())
    return v

def _haversine(coords):
    lon, lat = np.deg2rad(np.asarray(coords)).T
    a = np.sin((lat[1]-lat[0])/2.)**2 + np.cos(lat[0]) * np.cos(lat[1]) * np.sin((lon[0] - lon[1])/2.)**2
    return 6371.000 * 2 * np.arctan2( np.sqrt(a), np.sqrt(1-a) )

def aggregatebuses(network, busmap):
    columns = set(network.component_simple_descriptors[components.Bus])
    strategies = dict(x=np.mean, y=np.mean,
                     v_nom=np.max,
                      v_mag_pu_max=np.min, v_mag_pu_min=np.max)
    strategies.update(zip(columns.difference(strategies), repeat(_consense)))

    return network.buses \
            .groupby(busmap).agg(strategies) \
            .reindex_axis([f for f in network.buses.columns if f in columns], axis=1)

def aggregatelines(network, buses, interlines, line_length_factor=1.0):
<commit_msg>networkclustering: fix import ordering<commit_after>## Copyright 2015-2016 <NAME> (FIAS), <NAME> (FIAS)

## This program is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 3 of the
## License, or (at your option) any later version.

## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.

## You should have received a copy of the GNU General Public License
## along with this program.  If not, see <http://www.gnu.org/licenses/>.

"""Functions for computing network clusters
"""

from __future__ import absolute_import, print_function, division

__author__ = "<NAME> (FIAS), <NAME> (FIAS)"
__copyright__ = "Copyright 2015-2016 <NAME> (FIAS), <NAME> (FIAS), GNU GPL 3"

import numpy as np
import pandas as pd
import networkx as nx
from collections import OrderedDict, namedtuple
from itertools import repeat
from six.moves import zip, range
from six import itervalues

from .descriptors import OrderedGraph
from .components import Network

from . import components, io

def _consense(x):
    v = x.iat[0]
    assert ((x == v).all() or x.isnull().all())
    return v

def _haversine(coords):
    lon, lat = np.deg2rad(np.asarray(coords)).T
    a = np.sin((lat[1]-lat[0])/2.)**2 + np.cos(lat[0]) * np.cos(lat[1]) * np.sin((lon[0] - lon[1])/2.)**2
    return 6371.000 * 2 * np.arctan2( np.sqrt(a), np.sqrt(1-a) )

def aggregatebuses(network, busmap):
    columns = set(network.component_simple_descriptors[components.Bus])
    strategies = dict(x=np.mean, y=np.mean,
                     v_nom=np.max,
                      v_mag_pu_max=np.min, v_mag_pu_min=np.max)
    strategies.update(zip(columns.difference(strategies), repeat(_consense)))

    return network.buses \
            .groupby(busmap).agg(strategies) \
            .reindex_axis([f for f in network.buses.columns if f in columns], axis=1)

def aggregatelines(network, buses, interlines, line_length_factor=1.0):

{'fraction_non_alphanumeric': 0.11711919005982513, 'fraction_numerical': 0.019788311090658078, 'mean_word_length': 3.8897637795275593, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '487067', 'n_tokens_mistral': 1408, 'n_tokens_neox': 1358, 'n_words': 468}