You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I’m working on an extension for fiber photometry data, and in that extension I want to make reference (with a link and with an include) to one of the neurodata types that’s being created. Example:
fiberphotometryresponse_series=NWBGroupSpec(
neurodata_type_def="FiberPhotometryResponseSeries",
neurodata_type_inc="TimeSeries",
doc="Extends TimeSeries to hold Fiber Photometry data",
datasets=[
NWBDatasetSpec(
name="fibers",
doc="references row(s) of FibersTable",
neurodata_type_inc="DynamicTableRegion",
quantity="?",
),
... otherattributes ...
]
)
deconvolved_fiberphotometryresponse_series_series=NWBGroupSpec(
neurodata_type_def="DeconvolvedFiberPhotometryResponseSeries",
neurodata_type_inc="FiberPhotometryResponseSeries",
doc="Extends FiberPhotometryResponseSeries to hold deconvolved data",
links=[
NWBLinkSpec(
name="raw",
target_type="FiberPhotometryResponseSeries",
doc="ref to fiber photometry response series",
)
],
datasets=[
NWBDatasetSpec(
name="deconvolution_filter",
doc="description of deconvolution filter used",
dtype="text",
neurodata_type_inc="VectorData",
quantity="?",
),
NWBDatasetSpec(
name="downsampling_filter",
doc="description of downsampling filter used",
dtype="text",
neurodata_type_inc="VectorData",
quantity="?",
),
],
)
It seems to be caused by FiberPhotometryResponseSeries not being found in the namespace, when used as an include to the DeconvolvedFiberPhotometryResponseSeries class.
File/mnt/shared_storage/Github/nelson-lab-to-nwb/src/nelson_lab_to_nwb/interfaces/tdt_interface.py:97frompynwbimportNWBFile8frompynwb.coreimportDynamicTableRegion---->9fromndx_photometryimport (
10FibersTable,
11PhotodetectorsTable,
12ExcitationSourcesTable,
13FluorophoresTable,
14FiberPhotometryResponseSeries,
15FiberPhotometry16 )
19classTdtFiberPhotometryInterface(BaseDataInterface):
20""" 21 Custom data interface class for converting TDT Fiber Photometry recordings. 22 """File/mnt/shared_storage/Github/ndx-photometry/src/pynwb/ndx_photometry/__init__.py:2412ndx_photometry_specpath=os.path.abspath(
13os.path.join(
14os.path.dirname(__file__),
(...)
20 )
21 )
23# Load the namespace--->24load_namespaces(ndx_photometry_specpath)
26# TODO: import your classes here or define your class using get_class to make27# them accessible at the package level28from .photometryimportFibersTable, FluorophoresTable, PhotodetectorsTable, ExcitationSourcesTable, FiberPhotometryResponseSeriesFile~/anaconda3/envs/nelson_lab_to_nwb_env/lib/python3.12/site-packages/hdmf/utils.py:672, indocval.<locals>.dec.<locals>.func_call(*args, **kwargs)
670deffunc_call(*args, **kwargs):
671pargs=_check_args(args, kwargs)
-->672returnfunc(**pargs)
File~/anaconda3/envs/nelson_lab_to_nwb_env/lib/python3.12/site-packages/pynwb/__init__.py:109, inload_namespaces(**kwargs)
105''' 106 Load namespaces from file 107 '''108namespace_path=getargs('namespace_path', kwargs)
-->109return__TYPE_MAP.load_namespaces(namespace_path)
File~/anaconda3/envs/nelson_lab_to_nwb_env/lib/python3.12/site-packages/hdmf/utils.py:668, indocval.<locals>.dec.<locals>.func_call(*args, **kwargs)
666deffunc_call(*args, **kwargs):
667pargs=_check_args(args, kwargs)
-->668returnfunc(args[0], **pargs)
File~/anaconda3/envs/nelson_lab_to_nwb_env/lib/python3.12/site-packages/hdmf/build/manager.py:473, inTypeMap.load_namespaces(self, **kwargs)
465 @docval(*get_docval(NamespaceCatalog.load_namespaces),
466returns="the namespaces loaded from the given file", rtype=dict)
467defload_namespaces(self, **kwargs):
468'''Load namespaces from a namespace file. 469 This method will call load_namespaces on the NamespaceCatalog used to construct this TypeMap. Additionally, 470 it will process the return value to keep track of what types were included in the loaded namespaces. Calling 471 load_namespaces here has the advantage of being able to keep track of type dependencies across namespaces. 472 '''-->473deps=self.__ns_catalog.load_namespaces(**kwargs)
474fornew_ns, ns_depsindeps.items():
475forsrc_ns, typesinns_deps.items():
File~/anaconda3/envs/nelson_lab_to_nwb_env/lib/python3.12/site-packages/hdmf/utils.py:668, indocval.<locals>.dec.<locals>.func_call(*args, **kwargs)
666deffunc_call(*args, **kwargs):
667pargs=_check_args(args, kwargs)
-->668returnfunc(args[0], **pargs)
File~/anaconda3/envs/nelson_lab_to_nwb_env/lib/python3.12/site-packages/hdmf/spec/namespace.py:537, inNamespaceCatalog.load_namespaces(self, **kwargs)
535# now load specs into namespace536fornsinto_load:
-->537ret[ns['name']] =self.__load_namespace(ns, reader, resolve=resolve)
538self.__included_specs[ns_path_key] =ret539returnretFile~/anaconda3/envs/nelson_lab_to_nwb_env/lib/python3.12/site-packages/hdmf/spec/namespace.py:447, inNamespaceCatalog.__load_namespace(self, namespace, reader, resolve)
444types_to_load=set(types_to_load)
445if'source'ins:
446# read specs from file-->447self.__load_spec_file(reader, s['source'], catalog, types_to_load=types_to_load, resolve=resolve)
448self.__included_sources.setdefault(ns_name, list()).append(s['source'])
449elif'namespace'ins:
450# load specs from namespaceFile~/anaconda3/envs/nelson_lab_to_nwb_env/lib/python3.12/site-packages/hdmf/spec/namespace.py:401, inNamespaceCatalog.__load_spec_file(self, reader, spec_source, catalog, types_to_load, resolve)
399forspec_dictinspecs:
400self.__convert_spec_cls_keys(GroupSpec, self.__group_spec_cls, spec_dict)
-->401temp_dict= {k: Noneforkin__reg_spec(self.__group_spec_cls, spec_dict)}
402ret.update(temp_dict)
403self.__loaded_specs[spec_source] =retFile~/anaconda3/envs/nelson_lab_to_nwb_env/lib/python3.12/site-packages/hdmf/spec/namespace.py:386, inNamespaceCatalog.__load_spec_file.<locals>.__reg_spec(spec_cls, spec_dict)
384return385ifresolve:
-->386self.__resolve_includes(spec_cls, spec_dict, catalog)
387spec_obj=spec_cls.build_spec(spec_dict)
388returncatalog.auto_register(spec_obj, spec_source)
File~/anaconda3/envs/nelson_lab_to_nwb_env/lib/python3.12/site-packages/hdmf/spec/namespace.py:424, inNamespaceCatalog.__resolve_includes(self, spec_cls, spec_dict, catalog)
422ifparent_specisNone:
423msg="Cannot resolve include spec '%s' for type '%s'"% (dt_inc, dt_def)
-->424raiseValueError(msg)
425# replace the inc key value from string to the inc spec so that the spec can be updated with all of the426# attributes, datasets, groups, and links of the inc spec when spec_cls.build_spec(spec_dict) is called427spec_dict[spec_cls.inc_key()] =parent_specValueError: Cannotresolveincludespec'FiberPhotometryResponseSeries'fortype'DeconvolvedFiberPhotometryResponseSeries'
@luiztauffer it looks like the order of the spec matters for resolution. If I move the definition of FiberPhotometryResponseSeries above the definition of DeconvolvedFiberPhotometryResponseSeries which contains the link and neurodata_type_inc to FiberPhotometryResponseSeries, then the import works.
If you reorder the data types in create_extension_spec.py to have fiberphotometryresponse_series before deconvolved_fiberphotometryresponse_series_series:
# Add all new data types to this listnew_data_types= [
fibers_table,
photodetectors_table,
excitationsources_table,
commandedvoltage_series,
fiberphotometryresponse_series,
deconvolved_fiberphotometryresponse_series_series,
multi_commanded_voltage,
fiber_photometry,
fluorophores_table,
]
and re-generate the spec and re-install the package, then the new spec will have a working definition order, and the import will work.
This is not ideal very user-friendly behavior. I created an issue in HDMF for it hdmf-dev/hdmf#1086
What happened?
I’m working on an extension for fiber photometry data, and in that extension I want to make reference (with a link and with an include) to one of the neurodata types that’s being created. Example:
The spec yaml file is created without problems, but when trying to import the new classes in Python I get an import error.
The error happens at this line: https://github.com/catalystneuro/ndx-photometry/blob/29eb6c43f61e6456e2d124241e97953526a548bd/src/pynwb/ndx_photometry/__init__.py#L24
It seems to be caused by FiberPhotometryResponseSeries not being found in the namespace, when used as an include to the DeconvolvedFiberPhotometryResponseSeries class.
In order to reproduce, you should install the version from this branch: https://github.com/catalystneuro/ndx-photometry/tree/general-improvements
Steps to Reproduce
Traceback
Operating System
Linux
Python Executable
Conda
Python Version
3.10
Package Versions
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: