AllenInstitute / AllenSDK

code for reading and processing Allen Institute for Brain Science data
https://allensdk.readthedocs.io/en/latest/
Other
333 stars 149 forks source link

Simultaneously importing `ecephys_project_cache` and `behavior_ecephys_session` breaks nwb file reading #2713

Open brendanjohnharris opened 10 months ago

brendanjohnharris commented 10 months ago

Describe the bug Importing both allensdk.brain_observatory.ecephys.ecephys_project_cache and allensdk.brain_observatory.ecephys.behavior_ecephys_session seems to break reading from NWB files

To Reproduce Using a sample Neuropixels Visual Behavior nwb file, this runs as expected:

import allensdk
from allensdk.brain_observatory.ecephys import behavior_ecephys_session
S = behavior_ecephys_session.BehaviorEcephysSession.from_nwb_path('ecephys_session_1152811536.nwb') # Runs fine

But this fails:

import allensdk
from allensdk.brain_observatory.ecephys import ecephys_project_cache
from allensdk.brain_observatory.ecephys import behavior_ecephys_session
S = behavior_ecephys_session.BehaviorEcephysSession.from_nwb_path('ecephys_session_1152811536.nwb') # Fails

Expected behavior BehaviourEcephysSession can be constructed from an NWB file.

Actual Behavior The following error:

ConstructError: (root/general/metadata GroupBuilder {'attributes': {'behavior_session_id': 1152845816, 'behavior_session_uuid': 'None', 'equipment_name': 'NP.1', 'namespace': 'ndx-aibs-behavior-ophys', 'neurodata_type': 'BehaviorMetadata', 'object_id': 'c2891e70-2766-456c-8404-7955c316a657', 'session_type': 'EPHYS_1_images_H_3uL_reward', 'stimulus_frame_rate': 60.0}, 'groups': {}, 'datasets': {}, 'links': {}}, "Could not construct BehaviorMetadata object due to: CustomClassGenerator.set_init..__init__: missing argument 'project_code'")

Environment (please complete the following information):

brendanjohnharris commented 10 months ago

This occurs even when directly reading the nwb file using pynwb, without importing behavior_ecephys_session. The following also fails:

import allensdk
import pynwb
from allensdk.brain_observatory.ecephys import ecephys_project_cache

with pynwb.NWBHDF5IO('ecephys_session_1152811536.nwb', "r", load_namespaces=True) as read_io:
            nwbfile = read_io.read()
nwbfile 
brendanjohnharris commented 10 months ago

Seems to be an issue with the allensdk nwb_api. The following fails also:


import allensdk
import pynwb
from allensdk.brain_observatory.nwb.nwb_api import NwbApi
with pynwb.NWBHDF5IO('ecephys_session_1152811536.nwb', "r", load_namespaces=True) as read_io:
            nwbfile = read_io.read()
nwbfile
brendanjohnharris commented 10 months ago

In particular, the conflicting namespace loaded as below:

import allensdk
import pynwb

namespace_path = './allensdk/brain_observatory/nwb/ndx-aibs-behavior-ophys.namespace.yaml'
pynwb.load_namespaces(str(namespace_path))

with pynwb.NWBHDF5IO('ecephys_session_1152811536.nwb', "r", load_namespaces=True) as read_io:
            nwbfile = read_io.read()
nwbfile