<commit_before>import math
import numpy as np

from .utils.io import saveswc
from collections import Counter
from random import gauss
from random import random
from random import randrange
from scipy.spatial.distance import cdist


class SWC(object):
    def __init__(self, soma=None):
        self._data = np.zeros((1, 8))
        if soma:
            self._data[0, :] = np.asarray(
                [
                    0,
                    1,
                    soma.centroid[0],
                    soma.centroid[1],
                    soma.centroid[2],
                    soma.radius,
                    -1,
                    1,
                ]
            )

    def add(self, swc_nodes):
        np.vstack((self._data, swc_nodes))

    def add_branch(self, branch, pidx=None, random_color=True):
        """
        Add a branch to swc.
        Note: This swc is special with N X 8 shape. The 8-th column is the online confidence
        """
        if random_color:
            rand_node_type = randrange(256)

        new_branch = np.zeros((len(branch.pts), 8))
        id_start = 1 if self._data.shape[0] == 1 else self._data[:, 0].max() + 1

        for i in range(len(branch.pts)):
            p, r, c = branch.pts[i], branch.radius[i], branch.conf[i]
            id = id_start + i
            # 3 for basal dendrite; 4 for apical dendrite;
            # However now we cannot differentiate them automatically
            nodetype = 3

            if i == len(branch.pts) - 1:  # The end of this branch<commit_msg>fix: randrange occasionally produced "real" dendrite types<commit_after>import math
import numpy as np

from .utils.io import saveswc
from collections import Counter
from random import gauss
from random import random
from random import randrange
from scipy.spatial.distance import cdist


class SWC(object):
    def __init__(self, soma=None):
        self._data = np.zeros((1, 8))
        if soma:
            self._data[0, :] = np.asarray(
                [
                    0,
                    1,
                    soma.centroid[0],
                    soma.centroid[1],
                    soma.centroid[2],
                    soma.radius,
                    -1,
                    1,
                ]
            )

    def add(self, swc_nodes):
        np.vstack((self._data, swc_nodes))

    def add_branch(self, branch, pidx=None, random_color=True):
        """
        Add a branch to swc.
        Note: This swc is special with N X 8 shape. The 8-th column is the online confidence
        """
        if random_color:
            rand_node_type = randrange(6, 257)

        new_branch = np.zeros((len(branch.pts), 8))
        id_start = 1 if self._data.shape[0] == 1 else self._data[:, 0].max() + 1

        for i in range(len(branch.pts)):
            p, r, c = branch.pts[i], branch.radius[i], branch.conf[i]
            id = id_start + i
            # 3 for basal dendrite; 4 for apical dendrite;
            # However now we cannot differentiate them automatically
            nodetype = 3

            if i == len(branch.pts) - 1:  # The end of this branch
{'fraction_non_alphanumeric': 0.09615384615384616, 'fraction_numerical': 0.016346153846153847, 'mean_word_length': 1.5965058236272878, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4178956', 'n_tokens_mistral': 968, 'n_tokens_neox': 891, 'n_words': 282}