-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'ticket/ecephys/33a/metadata/writer' into vbn_2022_dev
- Loading branch information
Showing
31 changed files
with
2,948 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...brain_observatory/behavior/behavior_project_cache/tables/util/image_presentation_utils.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from typing import Optional | ||
import pandas as pd | ||
import re | ||
|
||
|
||
def get_image_set(df: pd.DataFrame) -> pd.Series: | ||
"""Get image set | ||
The image set here is the letter part of the session type | ||
ie for session type OPHYS_1_images_B, it would be "B" | ||
Some session types don't have an image set name, such as | ||
gratings, which will be set to null | ||
Parameters | ||
---------- | ||
df | ||
The session df | ||
Returns | ||
-------- | ||
Series with index same as df whose values are image_set | ||
""" | ||
def __get_image_set_name(session_type: Optional[str]): | ||
match = re.match(r'.*images_(?P<image_set>\w)', session_type) | ||
if match is None: | ||
return None | ||
return match.group('image_set') | ||
|
||
session_type = df['session_type'][ | ||
df['session_type'].notnull()] | ||
image_set = session_type.apply(__get_image_set_name) | ||
return image_set |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# empty |
1 change: 1 addition & 0 deletions
1
allensdk/brain_observatory/data_release_utils/metadata_utils/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# empty |
51 changes: 51 additions & 0 deletions
51
allensdk/brain_observatory/data_release_utils/metadata_utils/id_generator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import pathlib | ||
|
||
|
||
class FileIDGenerator(object): | ||
""" | ||
A class to generate a unique integer ID for each file in the | ||
data release | ||
""" | ||
|
||
def __init__(self): | ||
self._id_lookup = dict() | ||
self._next_id = 0 | ||
self._dummy_value = -999 | ||
|
||
@property | ||
def dummy_value(self) -> int: | ||
""" | ||
Value reserved for files that are missing from the | ||
release | ||
""" | ||
return self._dummy_value | ||
|
||
def id_from_path(self, | ||
file_path: pathlib.Path) -> int: | ||
""" | ||
Get the unique ID for a file path. If the file has already | ||
been assigned a unique ID, return that. Otherwise, assign | ||
a unique ID to the file path and return it | ||
""" | ||
if not isinstance(file_path, pathlib.Path): | ||
msg = ("file_path must be a pathlib.Path (this is so " | ||
"we can resolve it into an absolute path). You passed " | ||
f"in a {type(file_path)}") | ||
raise ValueError(msg) | ||
|
||
if not file_path.is_file(): | ||
msg = f"{file_path} is not a file" | ||
raise ValueError(msg) | ||
|
||
if file_path.is_symlink(): | ||
msg = f"{file_path} is a symlink; must be an actual path" | ||
raise ValueError(msg) | ||
|
||
str_path = str(file_path.resolve().absolute()) | ||
if str_path not in self._id_lookup: | ||
self._id_lookup[str_path] = self._next_id | ||
self._next_id += 1 | ||
while self._next_id == self.dummy_value: | ||
self._next_id += 1 | ||
|
||
return self._id_lookup[str_path] |
Oops, something went wrong.