-
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/2541/dev' into rc/2.15.0
- Loading branch information
Showing
22 changed files
with
7,718 additions
and
7,558 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
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
42 changes: 42 additions & 0 deletions
42
allensdk/brain_observatory/behavior/data_objects/metadata/behavior_metadata/project_code.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,42 @@ | ||
from pynwb import NWBFile | ||
from typing import Optional | ||
|
||
from allensdk.core import DataObject | ||
from allensdk.core import \ | ||
LimsReadableInterface | ||
from allensdk.internal.api import PostgresQueryMixin | ||
from allensdk.core import NwbReadableInterface | ||
|
||
|
||
class ProjectCode(DataObject, LimsReadableInterface, NwbReadableInterface): | ||
"""Unique identifier for the project this BehaviorSession is associated | ||
with. Project ids can be used internally to extract a project code. | ||
If project_Code is null/None, we set the value to string 'Not Available'. | ||
""" | ||
|
||
def __init__(self, project_code: Optional[str] = None): | ||
if project_code is None: | ||
project_code = 'Not Available' | ||
super().__init__(name='project_code', value=project_code) | ||
|
||
@classmethod | ||
def from_lims(cls, behavior_session_id: int, | ||
lims_db: PostgresQueryMixin) -> "ProjectCode": | ||
query = f""" | ||
SELECT ps.code AS project_code | ||
FROM behavior_sessions bs | ||
LEFT JOIN projects ps on bs.project_id = ps.id | ||
WHERE bs.id = {behavior_session_id} | ||
""" | ||
project_code = lims_db.fetchone(query, strict=False) | ||
return cls(project_code=project_code) | ||
|
||
@classmethod | ||
def from_nwb(cls, nwbfile: NWBFile) -> "ProjectCode": | ||
try: | ||
metadata = nwbfile.lab_meta_data['metadata'] | ||
return cls(project_code=metadata.project_code) | ||
except AttributeError: | ||
# Return values for NWBs without the project code set/available. | ||
return cls() |
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
Oops, something went wrong.