Skip to content

Simulation Requirements

ReqPopHasAttr #

Checks if population(s) contains the attribute(s) (parameters or variables)

Source code in src/CompNeuroPy/simulation_requirements.py
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class ReqPopHasAttr:
    """
    Checks if population(s) contains the attribute(s) (parameters or variables)
    """

    def __init__(self, pop, attr):
        """
        Args:
            pop (str or list of strings):
                population name(s)
            attr (str or list of strings):
                attribute name(s)
        """
        self.pop_name_list = pop
        self.attr_name_list = attr
        ### convert single strings into list
        if not (isinstance(pop, list)):
            self.pop_name_list = [pop]
        if not (isinstance(attr, list)):
            self.attr_name_list = [attr]

    def run(self):
        """
        Checks if population(s) contains the attribute(s) (parameters or variables)

        Raises:
            ValueError: if population(s) does not contain the attribute(s)
        """
        for attr_name in self.attr_name_list:
            for pop_name in self.pop_name_list:
                pop: Population = get_population(pop_name)
                if not (attr_name in pop.attributes):
                    raise ValueError(
                        "Population "
                        + pop_name
                        + " does not contain attribute "
                        + attr_name
                        + "!\n"
                    )

__init__(pop, attr) #

Parameters:

Name Type Description Default
pop str or list of strings

population name(s)

required
attr str or list of strings

attribute name(s)

required
Source code in src/CompNeuroPy/simulation_requirements.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
def __init__(self, pop, attr):
    """
    Args:
        pop (str or list of strings):
            population name(s)
        attr (str or list of strings):
            attribute name(s)
    """
    self.pop_name_list = pop
    self.attr_name_list = attr
    ### convert single strings into list
    if not (isinstance(pop, list)):
        self.pop_name_list = [pop]
    if not (isinstance(attr, list)):
        self.attr_name_list = [attr]

run() #

Checks if population(s) contains the attribute(s) (parameters or variables)

Raises:

Type Description
ValueError

if population(s) does not contain the attribute(s)

Source code in src/CompNeuroPy/simulation_requirements.py
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
def run(self):
    """
    Checks if population(s) contains the attribute(s) (parameters or variables)

    Raises:
        ValueError: if population(s) does not contain the attribute(s)
    """
    for attr_name in self.attr_name_list:
        for pop_name in self.pop_name_list:
            pop: Population = get_population(pop_name)
            if not (attr_name in pop.attributes):
                raise ValueError(
                    "Population "
                    + pop_name
                    + " does not contain attribute "
                    + attr_name
                    + "!\n"
                )