Package: ndx-acquisition-module
ndx-acquisition-moduleThis extension is used to allow adding modules innwbfile.acquisition, similarly to hownwbfile.processingallows adding modules.More specifically, this allows creating a module that hasTimeSeriesandDynamicTableobjects, then users can add this module.This is in alpha development stages. Please use with discretion.[TOC]RequirementThe requirements and additional development requirements can be seen inpyproject.tomlfile.Here are the minimum requirements:python >=3.8pynwb>=1.5.0,<3hdmf>=3.4.7,<4InstallationYou can install viapip:pipinstallndx-acquisition-moduleOrconda:condainstall-cfleischmannlabndx-acquisition-moduleOr directly from thegitrepository:pipinstallgit+https://gitlab.com/fleischmann-lab/ndx/ndx-acquisition-moduleUsageMain usageHere's a short example to create the module, add objects into it then add to acquisitionfromndx_acquisition_moduleimportAcquisitionModulemod=AcquisitionModule(name="raw_mod",description="raw acq module")# Add data objects to created AcquisitionModulemod.add(time_series)# add time seriesmod.add(dynamic_table)# add dynamic table# Add AcquisitionModule to nwbfile.acquisitionnwbfile.add_acquisition(mod)Full exampleHere's a full example that you can copy and paste in a script/notebook and run. Atest.nwbfile would be created.Expand to see full example scriptfromdatetimeimportdatetimeimportnumpyasnpfromdateutilimporttzfromhdmf.commonimportDynamicTable,VectorDatafromndx_acquisition_moduleimportAcquisitionModulefrompynwbimportNWBHDF5IO,NWBFile,TimeSeries# Create an example NWBFilenwbfile=NWBFile(session_description="test session description",identifier="unique_identifier",session_start_time=datetime(2012,2,21,tzinfo=tz.gettz("US/Pacific")),)# Create time seriests=TimeSeries(name="choice_series",description="raw choice series",data=np.random.randint(4,size=100),timestamps=(np.arange(100).astype("float")+2)/30,unit="-",)# Create dynamic tabletbl=DynamicTable(name="lookup_table",description="lookup table for `choice_series`",columns=[VectorData(name="lookup_id",description="ID to look up",data=[0,1,2,3]),VectorData(name="lookup_name",description="name of ID",data=["water","earth","fire","air"],),],)# Create AcquisitionModule to store these objectsmod=AcquisitionModule(name="raw_mod",description="raw acq module")# Add data objects to created AcquisitionModulemod.add(ts)# add time seriesmod.add(tbl)# add dynamic table# Add AcquisitionModule to nwbfile.acquisitionnwbfile.add_acquisition(mod)# Write the file to diskfilename="test.nwb"withNWBHDF5IO(path=filename,mode="w")asio:io.write(nwbfile)API usage notes and limitationsWith package installedCurrently to usemod.get(<object_name>)ormod[<object_name>], users would also need to install this package, for example withpipinstallndx-acquisition-moduleAnd import, usingNWBHDF5IO(..., load_namespaces=True)would not be enough.# new file completelyfrompynwbimportNWBHDF5IOfromndx_acquisition_moduleimportAcquisitionModulenwb=NWBHDF5IO('test.nwb',mode='r').read()# notice `load_namepsaces` is not neededprint(nwb.acquisition['raw_mod'])which outputs:raw_mod ndx_acquisition_module.AcquisitionModule at 0x139742592581104
Fields:
  data_interfaces: {
    choice_series <class 'pynwb.base.TimeSeries'>,
    lookup_table <class 'hdmf.common.table.DynamicTable'>
  }To access:nwb.acquisition['raw_mod']['lookup_table']nwb.acquisition['raw_mod']['choice_series']Without package installedOtherwise, ifndx-acquisition-moduleis not installed, accessing the inside objects have to be done based on types:# new file completelyfrompynwbimportNWBHDF5IOnwb=NWBHDF5IO('test.nwb',mode='r',load_namespaces=True).read()# notice `load_namepsaces` is NEEDEDprint(nwb.acquisition['raw_mod'])which outputs:raw_mod abc.AcquisitionModule at 0x140252603705728
Fields:
  description: raw acq module
  dynamic_tables: {
    lookup_table <class 'hdmf.common.table.DynamicTable'>
  }
  nwb_data_interfaces: {
    choice_series <class 'pynwb.base.TimeSeries'>
  }To access:nwb.acquisition['raw_mod'].dynamic_tables['lookup_table']nwb.acquisition['raw_mod'].nwb_data_interfaces['choice_series']TODOsFigure out how to allow consistent access even if package is not installed, so that usingload_namespaces=Trueis sufficient.Editsphinxdeploy stagePublish onpypiPublish oncondaThis extension was created usingndx-template.