Package: ndx-photostim
ndx-photostim Extension for NWBThis is aNeuroData Without Borders (NWB)extension for storing data and metadata fromholographic photostimulationmethods. It includes containers for storing photostimulation-specific device parameters, holographic patterns 
(either 2D or 3D), and time series data related to photostimulation.We release sixPyNWBcontainers as part of this extension (we currently only have a Python implementation, rather than both Python and a MATLAB ones -- this is why thematnwbdirectory is empty):TheSpatialLightModulatorandLasercontainers store metadata about the spatial light modulator and laser used in the photostimulation, respectively. These containers are then stored within thePhotostimulationMethodparent container, which stores the remaining photostimulation method-specifici metadata.HolographicPatternstores theholographic patternused in stimulation.PhotostimulationSeriescontains thetime series datacorresponding to the presentation of a given stimulus (where the stimulus is represented by aHolographicPatterncontainer linked to thePhotostimulationSeries).We groupall time series & patterns for a given experimenttogether using thePhotostimulationTablecontainer. This object is a dynamic table, where each row in the table corresponds to a singlePhotostimulationSeries. Additionally, the table links to theStimulationDeviceused in the experiment.BackgroundState-of-the-artholographic photostimulation methods, used in concert withtwo-photon imaging, 
allow unprecedented 
control and measurement of cell activity in the living brain. Methods for managing data for two-photon imaging 
experiments are improving, but there is little to no standardization of data for holographic stimulation methods. 
Stimulation in vivo depends on fine-tuning many experimental variables, which poses a challenge for reproducibility 
and data sharing between researchers. To improvestandardizationof photostimulation data storage and processing, 
we release this extension as a generic data format for simultaneous holographic stimulation experiments, 
using the NWB format to store experimental details and data relating to both acquisition 
and photostimulation.InstallationTo install the extension, first clone thendx_photostimrepository to the desired folder using the commandgit clone https://github.com/histedlab/ndx-photostim.gitThen, to install the requisite python packages and extension, run:python -m pip install -r requirements.txt -r requirements-dev.txt
python setup.py installThe extension can then be imported into python scripts viaimport ndx_photostim.UsageFor full example usage, seetutorial.ipynbBelow is example code to:Create a device used in photostimulationSimulate and store photostimulation ROIsStore the time series corresponding to each stimulationRecord all time series and patterns used in an experiment in a tableWrite the above to an NWB file and read it backimportnumpyasnpfromdateutil.tzimporttzlocalfromdatetimeimportdatetimefrompynwbimportNWBFile,NWBHDF5IOfromndx_photostimimportSpatialLightModulator,Laser,PhotostimulationMethod,HolographicPattern,\PhotostimulationSeries,PhotostimulationTable# create an example NWB filenwbfile=NWBFile('ndx-photostim_example','EXAMPLE_ID',datetime.now(tzlocal()))# store the spatial light modulator usedslm=SpatialLightModulator(name='slm',model='Meadowlark',size=np.array([512,512]))# store the laser usedlaser=Laser(name='laser',model='Coherent Monaco',wavelength=1030,power=8,peak_pulse_energy=20,pulse_rate=500)# create a container for the method used for photostimulation, and link the SLM and laser to itps_method=PhotostimulationMethod(name="methodA",stimulus_method="scanless",sweep_pattern="none",sweep_size=0,time_per_sweep=0,num_sweeps=0)ps_method.add_slm(slm)ps_method.add_laser(laser)# define holographic patternhp=HolographicPattern(name='pattern1',image_mask_roi=np.round(np.random.rand(5,5)),stim_duration=0.300,power_per_target=8)# show the maskhp.show_mask()# define stimulation time series using holographic patternps_series=PhotostimulationSeries(name="series_1",format='interval',data=[1,-1,1,-1],timestamps=[0.5,1,2,4],pattern=hp,method=ps_method)# add the stimulus to the NWB filenwbfile.add_stimulus(ps_series)# create a table to store the time series/patterns for all stimuli together, along with experiment-specific# parametersstim_table=PhotostimulationTable(name='test',description='...')stim_table.add_series(ps_series)# plot the timestamps when the stimulus was presentedstim_table.plot_presentation_times()# create a processing module and add the PresentationTable to itmodule=nwbfile.create_processing_module(name="photostimulation",description="example photostimulation table")module.add(stim_table)# write to an NWB file and read it backwithNWBHDF5IO("example_file.nwb","w")asio:io.write(nwbfile)withNWBHDF5IO("example_file.nwb","r",load_namespaces=True)asio:read_nwbfile=io.read()# Check the file & processing moduleprint(read_nwbfile)print(read_nwbfile.processing['photostimulation'])ifos.path.exists("example_file.nwb"):os.remove("example_file.nwb")Running testsUnit and integration
testsare implemented usingpytest, and can be run via the commandpytestfrom the root of the extension directory (i.e., insidendx-photostim/src). In addition, thepytestcommand will also run a test of the example code above.DocumentationSpecificationDocumentation for the extension'sspecification, which is based on the YAML files, is generated and stored in
the./docsfolder. To create it, run the following from the home directory:cd docs
make fulldocThis will save documentation to the./docs/buildfolder, and can be accessed via the./docs/build/html/index.htmlfile.APITo generate documentation for the Python API (stores in./api_docs), we useSphinxand a template fromReadTheDocs. API documentation can
be created by runningsphinx-build -b html api_docs/source/ api_docs/build/from the home folder. Similar to the specification docs, API documentation is stored in./api_docs/build. Select./api_docs/build/index.htmlto access the API documentation in a website format.CreditCode by Carl Harris and Paul LaFosse (equal contribution). Collaboration between the NIMH'sData Science and Sharing TeamandHisted Lab.This extension was created usingndx-template.