Skip to content

Commit ac0f13f

Browse files
authored
Mesoscope preprocess class (#851)
* Resolves #819 * Resolves #820 * Refector of mesoscopePreprocess incl support of ExpectedDataset obj in signature * Move suite2p imports to task methods * Process output on linux * clobber -> overwrite
1 parent 895042b commit ac0f13f

File tree

6 files changed

+471
-147
lines changed

6 files changed

+471
-147
lines changed

ibllib/oneibl/data_handlers.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,16 @@ def identifiers(self):
7979
"""tuple: the identifying parts of the dataset.
8080
8181
If no operator is applied, the identifiers are (collection, revision, name).
82-
If an operator is applied, the identifiers are two instances of an ExpectedDataset.
82+
If an operator is applied, a tuple of 3-element tuples is returned.
8383
"""
84-
return self._identifiers if self.operator is None else tuple(x.identifiers for x in self._identifiers)
84+
if self.operator is None:
85+
return self._identifiers
86+
# Flatten nested identifiers into tuple of 3-element tuples
87+
identifiers = []
88+
for x in self._identifiers:
89+
add = identifiers.extend if x.operator else identifiers.append
90+
add(x.identifiers)
91+
return tuple(identifiers)
8592

8693
@property
8794
def glob_pattern(self):
@@ -463,7 +470,6 @@ def dataset_from_name(name, datasets):
463470
list of ExpectedDataset
464471
The ExpectedDataset instances that match the given name.
465472
466-
TODO Add tests
467473
"""
468474
matches = []
469475
for dataset in datasets:
@@ -475,7 +481,7 @@ def dataset_from_name(name, datasets):
475481
return matches
476482

477483

478-
def update_collections(dataset, new_collection, substring=None):
484+
def update_collections(dataset, new_collection, substring=None, unique=None):
479485
"""
480486
Update the collection of a dataset.
481487
@@ -496,23 +502,28 @@ def update_collections(dataset, new_collection, substring=None):
496502
ExpectedDataset
497503
A copy of the dataset with the updated collection(s).
498504
499-
TODO Add tests
500505
"""
501506
after = ensure_list(new_collection)
502507
D = ExpectedDataset.input if isinstance(dataset, Input) else ExpectedDataset.output
503508
if dataset.operator is None:
504-
collection, revsion, name = dataset.identifiers
509+
collection, revision, name = dataset.identifiers
510+
if revision is not None:
511+
raise NotImplementedError
505512
if substring:
506-
after = [collection.replace(substring, x) for x in after]
507-
unique = not set(name).intersection('*[?')
513+
after = [(collection or '').replace(substring, x) or None for x in after]
514+
if unique is None:
515+
unique = [not set(name + (x or '')).intersection('*[?') for x in after]
516+
else:
517+
unique = [unique] * len(after)
508518
register = dataset.register
509-
updated = D(name, after[0], not isinstance(dataset, OptionalDataset), register, unique=unique)
519+
updated = D(name, after[0], not isinstance(dataset, OptionalDataset), register, unique=unique[0])
510520
if len(after) > 1:
511-
for folder in after[1:]:
512-
updated &= D(name, folder, not isinstance(dataset, OptionalDataset), register, unique=unique)
521+
for folder, unq in zip(after[1:], unique[1:]):
522+
updated &= D(name, folder, not isinstance(dataset, OptionalDataset), register, unique=unq)
513523
else:
514524
updated = copy(dataset)
515-
updated._identifiers = [update_collections(dd, new_collection) for dd in updated._identifiers]
525+
updated._identifiers = [update_collections(dd, new_collection, substring, unique)
526+
for dd in updated._identifiers]
516527
return updated
517528

518529

ibllib/oneibl/registration.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ def register_session(self, ses_path, file_list=True, projects=None, procedures=N
239239
task_protocols = task_data = settings = []
240240
json_field = None
241241
users = session_details['users']
242+
n_trials, n_correct_trials = 0
242243
else: # Get session info from task data
243244
collections = ensure_list(collections)
244245
# read meta data from the rig for the session from the task settings file

0 commit comments

Comments
 (0)