dj_mixin.py
SpyglassMixin
¶
Bases: CautiousDeleteMixin, ExportMixin, HelperMixin, PopulateMixin, RestrictByMixin
Mixin for Spyglass DataJoint tables.
Provides methods for fetching NWBFile objects and checking user permission prior to deleting. As a mixin class, all Spyglass tables can inherit custom methods from a central location.
Methods:
| Name | Description |
|---|---|
fetch_nwb |
Fetch NWBFile object from relevant table. Uses either a foreign key to a NWBFile table (including AnalysisNwbfile) or a _nwb_table attribute to determine which table to use. |
cautious_delete |
Check user permissions before deleting table rows. Permission is granted
to users listed as admin in LabMember table or to users on a team with
with the Session experimenter(s). If the table where the delete is
executed cannot be linked to a Session, a warning is logged and the
delete continues. If the Session has no experimenter, or if the user is
not on a team with the Session experimenter(s), a PermissionError is
raised. |
Source code in src/spyglass/utils/dj_mixin.py
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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
__init__(*args, **kwargs)
¶
Initialize SpyglassMixin.
Checks that schema prefix is in SHARED_MODULES. Validates that table doesn't have multiple AnalysisNwbfile foreign keys.
Source code in src/spyglass/utils/dj_mixin.py
get_params_blob_from_key(key, default='default')
¶
Get params blob from table using key, assuming 1 primary key.
Defaults to 'default' if no entry is found.
TODO: Split SpyglassMixin to SpyglassParamsMixin.
Source code in src/spyglass/utils/dj_mixin.py
analysis_table
property
¶
Return the AnalysisNwbfile table linked to this table, if any.
SpyglassMixinPart
¶
Bases: SpyglassMixin, Part
A part table for Spyglass Group tables. Assists in propagating delete calls from upstream tables to downstream tables.
Source code in src/spyglass/utils/dj_mixin.py
delete(*args, **kwargs)
¶
Delete master and part entries.
Source code in src/spyglass/utils/dj_mixin.py
SpyglassAnalysis
¶
Bases: SpyglassMixin, AnalysisMixin
Mixin for custom AnalysisNwbfile tables.
Provides automatic definition enforcement, schema validation, and registry integration for team-specific AnalysisNwbfile tables. This mixin enables transaction lock isolation by allowing teams to create their own analysis file tables in separate schemas.
Usage: Users should import the pre-configured table from custom_nwbfile. By default, it uses database.user as the prefix:
from spyglass.common.custom_nwbfile import AnalysisNwbfile
# Schema "{username}_nwbfile" is created automatically
# Uses database.user as prefix (or custom database.prefix if set)
See Also: spyglass.common.custom_nwbfile for the pre-configured table. docs/src/ForDevelopers/CustomAnalysisFiles.md for comprehensive guide.
Source code in src/spyglass/utils/dj_mixin.py
__init__(*args, **kwargs)
¶
Initialize SpyglassAnalysis.
Enforces ...
- Database conforms to {prefix}_nwbfile naming convention, one '_'
- Table conforms to AnalysisNwbfile class name
- Exact definition match for common AnalysisNwbfile table
- Not a part table (part tables cannot be AnalysisNwbfile)
- Inserts into AnalysisRegistry on declaration
Source code in src/spyglass/utils/dj_mixin.py
SpyglassIngestion
¶
Bases: SpyglassMixin, IngestionMixin
Mixin for Spyglass ingestion tables.
Provides additional methods and properties to automate population of table entries from raw NWB files.