Skip to content

Commit 180fbc6

Browse files
committed
feat: add File part table for external storage
1 parent 40dc3c0 commit 180fbc6

1 file changed

Lines changed: 82 additions & 2 deletions

File tree

element_array_ephys/spike_sorting/si_spike_sorting.py

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ class PreProcessing(dj.Imported):
6161
execution_duration: float # execution duration in hours
6262
"""
6363

64+
class File(dj.Part):
65+
definition = """
66+
-> master
67+
file_name: varchar(255)
68+
---
69+
file: filepath@ephys-processed
70+
"""
71+
6472
@property
6573
def key_source(self):
6674
return (
@@ -176,6 +184,14 @@ def make(self, key):
176184
/ 3600,
177185
}
178186
)
187+
# Insert result files
188+
self.File.insert(
189+
[
190+
{**key, "file_name": f.relative_to(recording_dir).as_posix(), "file": f}
191+
for f in recording_dir.rglob("*")
192+
if f.is_file()
193+
]
194+
)
179195

180196

181197
@schema
@@ -189,6 +205,14 @@ class SIClustering(dj.Imported):
189205
execution_duration: float # execution duration in hours
190206
"""
191207

208+
class File(dj.Part):
209+
definition = """
210+
-> master
211+
file_name: varchar(255)
212+
---
213+
file: filepath@ephys-processed
214+
"""
215+
192216
def make(self, key):
193217
execution_time = datetime.utcnow()
194218

@@ -239,6 +263,18 @@ def _run_sorter():
239263
/ 3600,
240264
}
241265
)
266+
# Insert result files
267+
self.File.insert(
268+
[
269+
{
270+
**key,
271+
"file_name": f.relative_to(sorting_output_dir).as_posix(),
272+
"file": f,
273+
}
274+
for f in sorting_output_dir.rglob("*")
275+
if f.is_file()
276+
]
277+
)
242278

243279

244280
@schema
@@ -253,6 +289,14 @@ class PostProcessing(dj.Imported):
253289
do_si_export=0: bool # whether to export to phy
254290
"""
255291

292+
class File(dj.Part):
293+
definition = """
294+
-> master
295+
file_name: varchar(255)
296+
---
297+
file: filepath@ephys-processed
298+
"""
299+
256300
def make(self, key):
257301
execution_time = datetime.utcnow()
258302

@@ -290,7 +334,9 @@ def make(self, key):
290334
def _sorting_analyzer_compute():
291335
if not has_units:
292336
log.info("No units found in sorting object. Skipping sorting analyzer.")
293-
analyzer_output_dir.mkdir(parents=True, exist_ok=True) # create empty directory anyway, for consistency
337+
analyzer_output_dir.mkdir(
338+
parents=True, exist_ok=True
339+
) # create empty directory anyway, for consistency
294340
return
295341

296342
# Sorting Analyzer
@@ -316,7 +362,9 @@ def _sorting_analyzer_compute():
316362

317363
_sorting_analyzer_compute()
318364

319-
do_si_export = postprocessing_params.get("export_to_phy", False) or postprocessing_params.get("export_report", False)
365+
do_si_export = postprocessing_params.get(
366+
"export_to_phy", False
367+
) or postprocessing_params.get("export_report", False)
320368

321369
self.insert1(
322370
{
@@ -329,6 +377,17 @@ def _sorting_analyzer_compute():
329377
"do_si_export": do_si_export and has_units,
330378
}
331379
)
380+
self.File.insert(
381+
[
382+
{
383+
**key,
384+
"file_name": f.relative_to(analyzer_output_dir).as_posix(),
385+
"file": f,
386+
}
387+
for f in analyzer_output_dir.rglob("*")
388+
if f.is_file()
389+
]
390+
)
332391

333392
# Once finished, insert this `key` into ephys.Clustering
334393
ephys.Clustering.insert1(
@@ -347,6 +406,14 @@ class SIExport(dj.Computed):
347406
execution_duration: float
348407
"""
349408

409+
class File(dj.Part):
410+
definition = """
411+
-> master
412+
file_name: varchar(255)
413+
---
414+
file: filepath@ephys-processed
415+
"""
416+
350417
@property
351418
def key_source(self):
352419
return PostProcessing & "do_si_export = 1"
@@ -409,3 +476,16 @@ def _export_report():
409476
/ 3600,
410477
}
411478
)
479+
# Insert result files
480+
for report_dirname in ("spikeinterface_report", "phy"):
481+
self.File.insert(
482+
[
483+
{
484+
**key,
485+
"file_name": f.relative_to(analyzer_output_dir).as_posix(),
486+
"file": f,
487+
}
488+
for f in (analyzer_output_dir / report_dirname).rglob("*")
489+
if f.is_file()
490+
]
491+
)

0 commit comments

Comments
 (0)