Skip to content
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

ticket/PSB-227: Revert to json for vbn packaging. #2723

Merged
merged 1 commit into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)