Skip to content

Commit 4402567

Browse files
authored
Merge pull request #216 from ttngu207/main_external-storage
Use `external-storage` to manage spike-sorting result files
2 parents 3761c61 + 269f3f2 commit 4402567

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

element_array_ephys/spike_sorting/si_spike_sorting.py

Lines changed: 76 additions & 0 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

@@ -333,6 +377,17 @@ def _sorting_analyzer_compute():
333377
"do_si_export": do_si_export and has_units,
334378
}
335379
)
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+
)
336391

337392
# Once finished, insert this `key` into ephys.Clustering
338393
ephys.Clustering.insert1(
@@ -351,6 +406,14 @@ class SIExport(dj.Computed):
351406
execution_duration: float
352407
"""
353408

409+
class File(dj.Part):
410+
definition = """
411+
-> master
412+
file_name: varchar(255)
413+
---
414+
file: filepath@ephys-processed
415+
"""
416+
354417
@property
355418
def key_source(self):
356419
return PostProcessing & "do_si_export = 1"
@@ -413,3 +476,16 @@ def _export_report():
413476
/ 3600,
414477
}
415478
)
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)