Skip to content

Commit

Permalink
Merge branch 'ticket/PSB-227/dev' into rc/2.16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
morriscb committed Sep 28, 2023
2 parents dccacd9 + 715f728 commit d0c44bc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def sanitize_data_columns(


class BehaviorProjectCloudApi(BehaviorProjectBase, ProjectCloudApiBase):
MANIFEST_COMPATIBILITY = ["1.0.0", "2.0.0"]
MANIFEST_COMPATIBILITY = ["0.0.0", "2.0.0"]

def _load_manifest_tables(self):
expected_metadata = set(
Expand Down
28 changes: 28 additions & 0 deletions allensdk/brain_observatory/ecephys/write_nwb/nwb_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,34 @@ def __init__(
serializer=serializer
)

def write_nwb(self, **kwargs):
"""Tries to write nwb to disk. If it fails, the filepath has ".error"
appended
Parameters
----------
kwargs: kwargs sent to `from_json`, `from_nwb`, `to_nwb`
"""
from_json_kwargs = {
k: v for k, v in kwargs.items()
if k in inspect.signature(self._serializer.from_json).parameters}
json_session = self._serializer.from_json(
session_data=self._session_data, **from_json_kwargs)

try:
nwbfile = self._write_nwb(
session=json_session, **kwargs)
self._compare_sessions(nwbfile=nwbfile,
loaded_session=json_session,
**kwargs)
os.rename(self.nwb_filepath_inprogress, self._nwb_filepath)
except Exception as e:
if os.path.isfile(self.nwb_filepath_inprogress):
os.rename(self.nwb_filepath_inprogress,
self._nwb_filepath_error)
raise e

def _write_nwb(
self,
session: BehaviorEcephysSession,
Expand Down
6 changes: 3 additions & 3 deletions allensdk/brain_observatory/nwb/nwb_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def write_nwb(
skip_stim=skip_stim,
)
self._compare_sessions(
nwbfile=nwbfile, lims_session=lims_session, **kwargs
nwbfile=nwbfile, loaded_session=lims_session, **kwargs
)
os.rename(self.nwb_filepath_inprogress, self._nwb_filepath)
except Exception as e:
Expand Down Expand Up @@ -326,12 +326,12 @@ def _compare_stimulus_file(
raise ValueError(error_message)

def _compare_sessions(
self, nwbfile: NWBFile, lims_session: DataObject, **kwargs
self, nwbfile: NWBFile, loaded_session: DataObject, **kwargs
):
kwargs = {
k: v
for k, v in kwargs.items()
if k in inspect.signature(self._serializer.from_nwb).parameters
}
nwb_session = self._serializer.from_nwb(nwbfile, **kwargs)
assert sessions_are_equal(lims_session, nwb_session, reraise=True)
assert sessions_are_equal(loaded_session, nwb_session, reraise=True)

0 comments on commit d0c44bc

Please sign in to comment.