<commit_before>from __future__ import division

import collections
import importlib

import networkx as nx
import numpy as np
PI = np.pi


def divceil(x, y):
    return (x+y-1)//y


class AmUtils(object):
    inds = collections.OrderedDict(
            [('a{}'.format(i+1), i+1) for i in range(6)])
    am_names = inds.keys()

    @classmethod
    def name_to_ind(cls, name):
        try:
            return cls.inds[name]
        except KeyError:
            print('"{}" is not a valid alpha process name'.format(name))
            raise

    @classmethod
    def ind_to_name(cls, index):
        try:
            return cls.am_names[index-1]
        except KeyError:
            print('"{}" is not a valid alpha process index'.format(index))
            raise

    @staticmethod
    def am_name(am_num):
        return 'Am{}'.format(am_num)

    @staticmethod
    def get_ampos_from_cart(i, lamina):
        cartid = i % len(lamina.cartridges)
        cartridge = lamina.cartridges[cartid]
        return cartridge.sphere_pos


class Cartridge(object):
    def __init__(self, element):
        '''
            element: ArrayElement object
        '''
        elev, azim = element.dima, element.dimb
        self._elev = elev
        self._azim = azim
        self.element = element

        self.neurons = collections.OrderedDict()
        self.synapses = []

    def add_neuron(self, neuron):
        if neuron.name not in self.neurons:
            self.neurons[neuron.name] = neuron

    def replace_am(self, name, am):
        ''' make alpha process 'name' a dummy neuron and
            connect it to its parent amacrine cell 'am'
        '''
        self.neurons[name].make_dummy()
        self.neurons[name].parent = am


    def get_neighborid(self, neighbor_dr):
        return self.element.get_neighborid(neighbor_dr)

    def is_neighbor_dummy(self, neighbor_num):
        return self.element.neighbors[neighbor_num].is_dummy

    @property
    def is_dummy(self):
        return self.element.is_dummy

    @property
    def sphere_pos(self):
        return self._elev, self._azim

    @property
    def gid(self):
        return self.element.gid


class NonColumn(object):
    def __init__(self, gid, elev, azim, params):
        self._gid = gid
        self._elev = elev
        self._azim = azim
        self.neuron = Neuron(params)

    @property
    def sphere_pos(self):
        return self._elev, self._azim

    @property
    def gid(self):
        return self._gid

    @property
    def selector(self):
        # assumes there is only one type of non columnar neuron
        # which is the amacrine cell
        return '/lam/am/{}'.format(self._gid)


class LaminaArray(object):
    def __init__(self, hex_array, config):
        self.hex_array = hex_array

        modelname = config['Lamina']['model']
        try:
            self.model = importlib.import_module('vision_models.{}'
                                                 .format(modelname))
        except ImportError:
            self.model = importlib.import_module('lamina.vision_models.{}'
                                                 .format(modelname))

        self._set_elements()
        self._update_neurons()

        relative_am = config['Lamina']['relative_am']
        if relative_am == 'half':
            self.n_amacrine = hex_array.num_elements//2
        elif relative_am == 'equal':
            self.n_amacrine = hex_array.num_elements
        else:
            self.n_amacrine = config['Lamina']['n_amacrine']

        # Have at least one Am cell
        self.n_amacrine = max(1, self.n_amacrine)

        self._connect_composition_II()
        self._connect_composition_I(config)

        self._generate_graph()

    def _set_elements(self):
        self._cartridges = [Cartridge(el) for el in self.hex_array.elements]
<commit_msg>one more change needed for the previous commit<commit_after>from __future__ import division

import collections
import importlib

import networkx as nx
import numpy as np
PI = np.pi


def divceil(x, y):
    return (x+y-1)//y


class AmUtils(object):
    inds = collections.OrderedDict(
            [('a{}'.format(i+1), i+1) for i in range(6)])
    am_names = inds.keys()

    @classmethod
    def name_to_ind(cls, name):
        try:
            return cls.inds[name]
        except KeyError:
            print('"{}" is not a valid alpha process name'.format(name))
            raise

    @classmethod
    def ind_to_name(cls, index):
        try:
            return cls.am_names[index-1]
        except KeyError:
            print('"{}" is not a valid alpha process index'.format(index))
            raise

    @staticmethod
    def am_name(am_num):
        return 'Am{}'.format(am_num)

    @staticmethod
    def get_ampos_from_cart(i, lamina):
        cartid = i % len(lamina.cartridges)
        cartridge = lamina.cartridges[cartid]
        return cartridge.sphere_pos


class Cartridge(object):
    def __init__(self, element):
        '''
            element: ArrayElement object
        '''
        elev, azim = element.dima, element.dimb
        self._elev = elev
        self._azim = azim
        self.element = element

        self.neurons = collections.OrderedDict()
        self.synapses = []

    def add_neuron(self, neuron):
        if neuron.name not in self.neurons:
            self.neurons[neuron.name] = neuron

    def replace_am(self, name, am):
        ''' make alpha process 'name' a dummy neuron and
            connect it to its parent amacrine cell 'am'
        '''
        self.neurons[name].make_dummy()
        self.neurons[name].parent = am


    def get_neighborid(self, neighbor_dr):
        return self.element.get_neighborid(neighbor_dr)

    def is_neighbor_dummy(self, neighbor_num):
        return self.element.neighbors[neighbor_num].is_dummy

    @property
    def is_dummy(self):
        return self.element.is_dummy

    @property
    def sphere_pos(self):
        return self._elev, self._azim

    @property
    def gid(self):
        return self.element.gid


class NonColumn(object):
    def __init__(self, gid, elev, azim, params):
        self._gid = gid
        self._elev = elev
        self._azim = azim
        self.neuron = Neuron(params)

    @property
    def sphere_pos(self):
        return self._elev, self._azim

    @property
    def gid(self):
        return self._gid

    @property
    def selector(self):
        # assumes there is only one type of non columnar neuron
        # which is the amacrine cell
        return '/lam/am/{}'.format(self._gid)


class LaminaArray(object):
    def __init__(self, hex_array, config):
        self.hex_array = hex_array

        modelname = config['Lamina']['model']
        
        self.model = importlib.import_module('lamina.vision_models.{}'
                                                 .format(modelname))

        self._set_elements()
        self._update_neurons()

        relative_am = config['Lamina']['relative_am']
        if relative_am == 'half':
            self.n_amacrine = hex_array.num_elements//2
        elif relative_am == 'equal':
            self.n_amacrine = hex_array.num_elements
        else:
            self.n_amacrine = config['Lamina']['n_amacrine']

        # Have at least one Am cell
        self.n_amacrine = max(1, self.n_amacrine)

        self._connect_composition_II()
        self._connect_composition_I(config)

        self._generate_graph()

    def _set_elements(self):
        self._cartridges = [Cartridge(el) for el in self.hex_array.elements]

{'fraction_non_alphanumeric': 0.10063643595863166, 'fraction_numerical': 0.0018562715460090163, 'mean_word_length': 2.1494780793319417, '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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '300030', 'n_tokens_mistral': 2384, 'n_tokens_neox': 2249, 'n_words': 541}