-
Notifications
You must be signed in to change notification settings - Fork 18
Export to nwb #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
54 commits
Select commit
Hold shift + click to select a range
1b684d3
export session to nwb
bendichter 2d1f76d
Merge branch 'main' into export_to_nwb
bendichter bb73c58
Update nwb.py
bendichter 79bdcc6
Update element_session/export/nwb.py
bendichter e069b75
Update element_session/export/nwb.py
bendichter 5e4be2f
user `dja` -> `anaconda`
CBroz1 48db607
Update element_session/export/nwb.py
bendichter 62b3927
Update element_session/export/nwb.py
bendichter 7cc7988
Update element_session/export/nwb.py
bendichter 22ac715
Update requirements.txt
bendichter 8e03909
Update element_session/export/nwb.py
bendichter 7eda08d
Update element_session/export/nwb.py
bendichter 233535a
simpler imports
bendichter 24ce00e
Update element_session/export/nwb.py
bendichter e03604a
Update element_session/export/nwb.py
bendichter dc1d67a
Update element_session/export/nwb.py
bendichter b7e7577
Update element_session/export/nwb.py
bendichter 49022ac
* import subject_to_nwb from element_animal
bendichter 469e145
remove timezone stuff
bendichter c9ac2e5
Update element_session/export/nwb.py
bendichter c9c874e
* add lab, project, and protocol keys
bendichter 9672ad4
Merge remote-tracking branch 'bendichter/export_to_nwb' into export_t…
bendichter b25bdf6
Update element_session/session.py
bendichter 480b99e
fix subject lookup
bendichter f1284de
import session from workflow
bendichter c750ce2
* handle experimenters
bendichter f85ee55
pass session_key to subject
bendichter 263ed7a
add test
bendichter c89c172
Rebased. See Details
CBroz1 7c82d16
Update element_session/export/nwb.py
bendichter 85912ba
Update element_session/export/nwb.py
bendichter 957884b
Update element_session/export/test_nwb.py
bendichter f1de431
Update element_session/export/test_nwb.py
bendichter f039d25
Avoid linking_module issues. See details.
CBroz1 7ec8115
nwb function specification in linking_module
478602c
Merge pull request #3 from ttngu207/chris-nwb
CBroz1 414e388
modify docstring
CBroz1 17c3d52
fix test indenting
bendichter 2d8a2af
Merge branch 'main' into export_to_nwb
bendichter 093ddd8
Merge remote-tracking branch 'cbroz1/ben' into export_to_nwb
bendichter b85ee53
merge with linking module
bendichter 2dc67b6
Merge remote-tracking branch 'bendichter/export_to_nwb' into export_t…
bendichter 1da9a60
merge with linking module
bendichter f90c9da
rmv tests (they are moved to workflow-array-ephys)
bendichter 8bbaa8e
Merge remote-tracking branch 'dj/main' into export_to_nwb
bendichter d806913
add init
bendichter 99fcb8f
Update element_session/export/nwb.py
bendichter 9f751bc
Update element_session/export/nwb.py
bendichter 0aed4b3
Update element_session/export/nwb.py
bendichter eaefef9
Update element_session/export/nwb.py
bendichter 5605270
Update element_session/session_with_id.py
bendichter 49ad6fe
Update element_session/export/nwb.py
bendichter 5ca6470
Update element_session/export/nwb.py
bendichter 89abe1c
Update element_session/export/nwb.py
bendichter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains hidden or 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,107 @@ | ||
import datetime | ||
from uuid import uuid4 | ||
import pynwb | ||
|
||
from .. import session | ||
|
||
assert session.schema.is_activated() | ||
|
||
|
||
def session_to_nwb( | ||
session_key: dict, | ||
lab_key=None, | ||
project_key=None, | ||
protocol_key=None, | ||
additional_nwbfile_kwargs=None, | ||
): | ||
"""Gather session- and subject-level metadata and use it to create an NWBFile. If | ||
there is no subject_to_nwb export function in the current namespace, subject_id will | ||
be inferred from the set of primary attributes in the Subject table upstream of Session. | ||
|
||
Parameters | ||
---------- | ||
session_key: dict, | ||
e.g., | ||
{ | ||
'subject': 'subject5', | ||
'session_datetime': datetime.datetime(2020, 5, 12, 4, 13, 7), | ||
} | ||
lab_key, project_key, protocol_key: dict, optional | ||
Used to gather additional optional metadata. | ||
additional_nwbfile_kwargs: dict, optional | ||
Optionally overwrite or add fields to NWBFile. | ||
|
||
Returns | ||
------- | ||
pynwb.NWBFile | ||
|
||
mappings: | ||
session.Session::KEY -> NWBFile.session_id | ||
session.Session::session_datetime -> NWBFile.session_start_time | ||
session.SessionNote::session_note -> NWBFile.session_description | ||
session.SessionExperimenter::user -> NWBFile.experimenter | ||
|
||
subject.Subject::subject -> NWBFile.subject.subject_id | ||
subject.Subject::sex -> NWBFile.subject.sex | ||
|
||
lab.Lab::institution -> NWBFile.institution | ||
lab.Lab::lab_name -> NWBFile.lab | ||
|
||
lab.Protocol::protocol -> NWBFile.protocol | ||
lab.Protocol::protocol_description -> NWBFile.notes | ||
|
||
lab.Project::project_description -> NWBFile.experiment_description | ||
lab.ProjectKeywords.keyword -> NWBFile.keywords | ||
lab.ProjectPublication.publication -> NWBFile.related_publications | ||
|
||
""" | ||
|
||
# ensure only one session key is entered | ||
session_key = (session.Session & session_key).fetch1("KEY") | ||
|
||
session_identifier = { | ||
k: v.isoformat() if isinstance(v, datetime.datetime) else v | ||
for k, v in session_key.items() | ||
} | ||
|
||
nwbfile_kwargs = dict( | ||
session_id="_".join(session_identifier.values()), identifier=str(uuid4()), | ||
) | ||
|
||
session_info = (session.Session & session_key).join(session.SessionNote, left=True).fetch1() | ||
|
||
nwbfile_kwargs.update( | ||
session_start_time=session_info["session_datetime"].astimezone( | ||
datetime.timezone.utc | ||
) | ||
) | ||
|
||
nwbfile_kwargs.update(session_description=session_info.get("session_note", "")) | ||
|
||
experimenters =(session.SessionExperimenter & session_key).fetch("user") | ||
|
||
nwbfile_kwargs.update(experimenter=list(experimenters) or None) | ||
|
||
subject_to_nwb = getattr(session._linking_module, "subject_to_nwb", False) | ||
|
||
if subject_to_nwb: | ||
nwbfile_kwargs.update(subject=subject_to_nwb(session_key)) | ||
else: | ||
subject_id = '_'.join((getattr(session._linking_module, 'Subject') & session_key).fetch1('KEY').values()) | ||
nwbfile_kwargs.update(subject=pynwb.file.Subject(subject_id=subject_id)) | ||
|
||
if any([lab_key, project_key, protocol_key]): | ||
element_lab_to_nwb_dict = getattr(session._linking_module, "element_lab_to_nwb_dict", {}) | ||
|
||
nwbfile_kwargs.update( | ||
CBroz1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
element_lab_to_nwb_dict( | ||
lab_key=lab_key, | ||
project_key=project_key, | ||
protocol_key=protocol_key, | ||
) | ||
) | ||
|
||
if additional_nwbfile_kwargs is not None: | ||
nwbfile_kwargs.update(additional_nwbfile_kwargs) | ||
|
||
return pynwb.NWBFile(**nwbfile_kwargs) |
This file contains hidden or 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 hidden or 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
datajoint>=0.13.0 | ||
datajoint>=0.13.0 | ||
pynwb | ||
CBroz1 marked this conversation as resolved.
Show resolved
Hide resolved
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.