Skip to content

surgery.py

activate(surgery_schema_name, subject_schema_name=None, *, create_schema=True, create_tables=True, linking_module=True)

Activate this schema.

Parameters:

Name Type Description Default
schema_name str

schema name on the database server to activate the subject element

required
create_schema bool

when True (default), create schema in the database if it does not yet exist.

True
create_tables bool

when True (default), create tables in the database if they do not yet exist.

True
linking_module bool

a module name or a module containing the

True
required dependencies to activate the `subject` element
required

Dependencies:

Upstream tables

User: the who conducted a particular surgery/implantation

Source code in element_animal/surgery.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
def activate(
    surgery_schema_name: str,
    subject_schema_name: str = None,
    *,
    create_schema: bool = True,
    create_tables: bool = True,
    linking_module: bool = True,
):
    """Activate this schema.

    Args:
        schema_name (str): schema name on the database server to activate the
                        `subject` element
        create_schema (bool): when True (default), create schema in the
                            database if it does not yet exist.
        create_tables (bool): when True (default), create tables in the
                            database if they do not yet exist.
        linking_module (bool): a module name or a module containing the
        required dependencies to activate the `subject` element:

    Dependencies:
    Upstream tables:
        User: the who conducted a particular surgery/implantation
    """

    if isinstance(linking_module, str):
        linking_module = importlib.import_module(linking_module)
    assert inspect.ismodule(
        linking_module
    ), "The argument 'linking_module' must be a module's name or a module"

    global _linking_module
    _linking_module = linking_module

    subject.activate(
        subject_schema_name,
        create_schema=create_schema,
        create_tables=create_tables,
        linking_module=linking_module,
    )
    schema.activate(
        surgery_schema_name,
        create_schema=create_schema,
        create_tables=create_tables,
        add_objects=linking_module.__dict__,
    )

CoordinateReference

Bases: dj.Lookup

Coordinate reference system

Attributes:

Name Type Description
reference varchar(60)

Reference system (e.g., bregma, lambda, etc.)

Source code in element_animal/surgery.py
61
62
63
64
65
66
67
68
69
70
71
72
73
74
@schema
class CoordinateReference(dj.Lookup):
    """Coordinate reference system

    Attributes:
        reference ( varchar(60) ): Reference system (e.g., bregma, lambda, etc.)
    """

    definition = """
    reference   : varchar(32)
    """
    contents = zip(
        ["bregma", "lambda", "dura", "skull_surface", "sagittal_suture", "sinus"]
    )

BrainRegion

Bases: dj.Manual

Brain region of a given surgery

Attributes:

Name Type Description
region_acronym varchar(32) )

Brain region shorthand

region_name varchar(128) )

Brain region full name

Source code in element_animal/surgery.py
77
78
79
80
81
82
83
84
85
86
87
88
89
90
@schema
class BrainRegion(dj.Manual):
    """Brain region of a given surgery

    Attributes:
        region_acronym ( varchar(32) ) : Brain region shorthand
        region_name ( varchar(128) ) : Brain region full name
    """

    definition = """
    region_acronym : varchar(32)   # Brain region shorthand
    ---
    region_name    : varchar(256)  # Brain region full name
    """

Hemisphere

Bases: dj.Lookup

Brain region hemisphere

Attributes:

Name Type Description
hemisphere varchar(8)

Brain region hemisphere (e.g., left, right, middle)

Source code in element_animal/surgery.py
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
@schema
class Hemisphere(dj.Lookup):
    """Brain region hemisphere

    Attributes:
        hemisphere ( varchar(8) ): Brain region hemisphere (e.g., left, right, middle)
    """

    definition = """
    hemisphere: varchar(8) # Brain region hemisphere
    """

    contents = zip(["left", "right", "middle"])

ImplantationType

Bases: dj.Lookup

Type of implantation

Attributes:

Name Type Description
implant_type varchar(16)

Short name for type of implanted device

implant_description varchar(32)

Full description for implanted device

Source code in element_animal/surgery.py
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
@schema
class ImplantationType(dj.Lookup):
    """Type of implantation

    Attributes:
        implant_type ( varchar(16) ): Short name for type of implanted device
        implant_description ( varchar(32) ): Full description for implanted device
    """

    definition = """
    implant_type        : varchar(16) # Short name for type of implanted device
    ---
    implant_description : varchar(32) # Full description for implanted device
    """

    contents = (
        ("ephys", "electophysiology"),
        ("fiber", "fiber photometry"),
        ("opto", "optogenetic perturbation"),
    )

Implantation

Bases: dj.Manual

Implantation of a device

Attributes:

Name Type Description
Session foreign key

Session primary key

location_id int

ID of of brain location

ap float

In mm, Anterior/posterior; Anterior Positive

ap_reference projected attribute

Coordinate reference

ml float

In mm, medial axis; Right Positive

ml_reference projected attribute

Coordinate reference

dv float

In mm, dorso-ventral axis. Ventral negative

dv_reference projected attribute

Coordinate reference

theta float, nullable

Elevation in degrees. Rotation about ml-axis [0, 180] relative to z-axis

phi float, nullable

Azimuth in degrees. Rotations about dv-axis [0, 360] relative to x-axis

beta float, nullable

Rotation about shank in degrees. Rotation about the shank [-180, 180]. Clockwise is increasing. 0 is the probe-front facing anterior

Source code in element_animal/surgery.py
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
@schema
class Implantation(dj.Manual):
    """Implantation of a device

    Attributes:
        Session (foreign key): Session primary key
        location_id (int): ID of of brain location
        ap ( float ): In mm, Anterior/posterior; Anterior Positive
        ap_reference (projected attribute): Coordinate reference
        ml ( float ): In mm, medial axis; Right Positive
        ml_reference (projected attribute): Coordinate reference
        dv ( float ): In mm, dorso-ventral axis. Ventral negative
        dv_reference (projected attribute): Coordinate reference
        theta ( float, nullable ): Elevation in degrees.
            Rotation about ml-axis [0, 180] relative to z-axis
        phi ( float, nullable ): Azimuth in degrees.
            Rotations about dv-axis [0, 360] relative to x-axis
        beta ( float, nullable ): Rotation about shank in degrees.
            Rotation about the shank [-180, 180]. Clockwise is increasing.
            0 is the probe-front facing anterior
    """

    definition = """
    -> subject.Subject
    implant_date        : datetime       # surgery date
    -> ImplantationType
    -> BrainRegion.proj(target_region='region_acronym')
    -> Hemisphere.proj(target_hemisphere='hemisphere')
    ---
    -> User.proj(surgeon='user')         # surgeon
    implant_comment=''  : varchar(1024) # Comments about the implant
    """

    class Coordinate(dj.Part):
        definition = """
        -> master
        ---
        ap=null       : float  # (mm) anterior-posterior; ref is 0
        -> [nullable] CoordinateReference.proj(ap_ref='reference')
        ml=null       : float  # (mm) medial axis; ref is 0
        -> [nullable] CoordinateReference.proj(ml_ref='reference')
        dv=null       : float  # (mm) dorso-ventral axis; ventral negative
        -> [nullable] CoordinateReference.proj(dv_ref='reference')
        theta=null    : float  # (deg) rot about ml-axis [0, 180] wrt z
        phi=null      : float  # (deg) rot about dv-axis [0, 360] wrt x
        beta=null     : float  # (deg) rot about shank [-180, 180] wrt anterior
        """