1
- import pathlib
2
1
import datetime
3
- import datajoint as dj
2
+ import pathlib
4
3
import typing as T
4
+ from uuid import UUID
5
5
6
- from element_interface .utils import insert1_skip_full_duplicates
6
+ import datajoint as dj
7
+ from element_interface .utils import dict_to_uuid
7
8
8
9
schema = dj .schema ()
9
10
@@ -102,9 +103,9 @@ class UnitLevelReport(dj.Computed):
102
103
def make (self , key ):
103
104
104
105
from .plotting .unit_level import (
105
- plot_waveform ,
106
106
plot_auto_correlogram ,
107
107
plot_depth_waveforms ,
108
+ plot_waveform ,
108
109
)
109
110
110
111
sampling_rate = (ephys .EphysRecording & key ).fetch1 (
@@ -145,9 +146,14 @@ class QualityMetricCutoffs(dj.Lookup):
145
146
amplitude_cutoff_maximum=null : float # Defualt null, no cutoff applied
146
147
presence_ratio_minimum=null : float # Defualt null, no cutoff applied
147
148
isi_violations_maximum=null : float # Defualt null, no cutoff applied
149
+ cutoffs_hash: uuid
150
+ unique index (cutoffs_hash)
148
151
"""
149
152
150
- contents = [(0 , None , None , None ), (1 , 0.1 , 0.9 , 0.5 )]
153
+ contents = [
154
+ (0 , None , None , None , UUID ("5d835de1-e1af-1871-d81f-d12a9702ff5f" )),
155
+ (1 , 0.1 , 0.9 , 0.5 , UUID ("f74ccd77-0b3a-2bf8-0bfd-ec9713b5dca8" )),
156
+ ]
151
157
152
158
@classmethod
153
159
def insert_new_cutoffs (
@@ -157,18 +163,38 @@ def insert_new_cutoffs(
157
163
presence_ratio_minimum : float = None ,
158
164
isi_violations_maximum : float = None ,
159
165
):
160
- if not cutoffs_id :
166
+ if cutoffs_id is None :
161
167
cutoffs_id = (dj .U ().aggr (cls , n = "max(cutoffs_id)" ).fetch1 ("n" ) or 0 ) + 1
162
168
163
- insert1_skip_full_duplicates ( # depends on element-interface/pull/43
164
- cls ,
165
- dict (
166
- cutoffs_id = cutoffs_id ,
167
- amplitude_cutoff_maximum = amplitude_cutoff_maximum ,
168
- presence_ratio_minimum = presence_ratio_minimum ,
169
- isi_violations_maximum = isi_violations_maximum ,
170
- ),
171
- )
169
+ param_dict = {
170
+ "amplitude_cutoff_maximum" : amplitude_cutoff_maximum ,
171
+ "presence_ratio_minimum" : presence_ratio_minimum ,
172
+ "isi_violations_maximum" : isi_violations_maximum ,
173
+ }
174
+ param_hash = dict_to_uuid (param_dict )
175
+ param_query = cls & {"cutoffs_hash" : param_hash }
176
+
177
+ if param_query : # If the specified cutoff set already exists
178
+ existing_paramset_idx = param_query .fetch1 ("cutoffs_id" )
179
+ if (
180
+ existing_paramset_idx == cutoffs_id
181
+ ): # If the existing set has the same id: job done
182
+ return
183
+ # If not same name: human err, adding the same set with different name
184
+ else :
185
+ raise dj .DataJointError (
186
+ f"The specified param-set already exists"
187
+ f" - with paramset_idx: { existing_paramset_idx } "
188
+ )
189
+ else :
190
+ if {"cutoffs_id" : cutoffs_id } in cls .proj ():
191
+ raise dj .DataJointError (
192
+ f"The specified cuttoffs_id { cutoffs_id } already exists,"
193
+ f" please pick a different one."
194
+ )
195
+ cls .insert1 (
196
+ {"cutoffs_id" : cutoffs_id , ** param_dict , "cutoffs_hash" : param_hash }
197
+ )
172
198
173
199
174
200
@schema
0 commit comments