Skip to content

Commit 4f6c301

Browse files
committed
Remove interface 42 dependence
1 parent eed1eee commit 4f6c301

File tree

1 file changed

+41
-15
lines changed

1 file changed

+41
-15
lines changed

element_array_ephys/ephys_report.py

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import pathlib
21
import datetime
3-
import datajoint as dj
2+
import pathlib
43
import typing as T
4+
from uuid import UUID
55

6-
from element_interface.utils import insert1_skip_full_duplicates
6+
import datajoint as dj
7+
from element_interface.utils import dict_to_uuid
78

89
schema = dj.schema()
910

@@ -102,9 +103,9 @@ class UnitLevelReport(dj.Computed):
102103
def make(self, key):
103104

104105
from .plotting.unit_level import (
105-
plot_waveform,
106106
plot_auto_correlogram,
107107
plot_depth_waveforms,
108+
plot_waveform,
108109
)
109110

110111
sampling_rate = (ephys.EphysRecording & key).fetch1(
@@ -145,9 +146,14 @@ class QualityMetricCutoffs(dj.Lookup):
145146
amplitude_cutoff_maximum=null : float # Defualt null, no cutoff applied
146147
presence_ratio_minimum=null : float # Defualt null, no cutoff applied
147148
isi_violations_maximum=null : float # Defualt null, no cutoff applied
149+
cutoffs_hash: uuid
150+
unique index (cutoffs_hash)
148151
"""
149152

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+
]
151157

152158
@classmethod
153159
def insert_new_cutoffs(
@@ -157,18 +163,38 @@ def insert_new_cutoffs(
157163
presence_ratio_minimum: float = None,
158164
isi_violations_maximum: float = None,
159165
):
160-
if not cutoffs_id:
166+
if cutoffs_id is None:
161167
cutoffs_id = (dj.U().aggr(cls, n="max(cutoffs_id)").fetch1("n") or 0) + 1
162168

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+
)
172198

173199

174200
@schema

0 commit comments

Comments
 (0)