Skip to main content

extension for fiber photometry data

Project description

ndx-photometry Extension for NWB

Build Status Documentation Status

NWB - Photometry

Introduction

This is an NWB extension for storing photometry recordings and associated metadata. This extension stores photometry information across three folders in the NWB file: acquisition, processing, and general. The acquisiton folder contains an ROIResponseSeries (inherited from pynwb.ophys), which references rows of a FibersTable rather than 2 Photon ROIs. The new types for this extension are in metadata and processing

Metadata

  1. FibersTable stores rows for each fiber with information about the location, excitation, source, photodetector, fluorophore, and more (associated with each fiber).
  2. ExcitationSourcesTable stores rows for each excitation source with information about the peak wavelength, source type, and the commanded voltage series of type CommandedVoltageSeries
  3. PhotodectorsTable stores rows for each photodetector with information about the peak wavelength, type, etc.
  4. FluorophoresTable stores rows for each fluorophore with information about the fluorophore itself and the injeciton site.

Processing

  1. DeconvoledROIResponseSeries stores DfOverF and Fluorescence traces and extends ROIResponseSeries to contain information about the deconvolutional and downsampling procedures performed.

This extension was developed by Akshay Jaggi, Ben Dichter, and Ryan Ly.

Installation

pip install ndx-photometry

Usage

import datetime
import numpy as np

from pynwb import NWBHDF5IO, NWBFile
from pynwb.core import DynamicTableRegion
from pynwb.ophys import RoiResponseSeries
from ndx_photometry import (
    FibersTable,
    PhotodetectorsTable,
    ExcitationSourcesTable,
    DeconvolvedRoiResponseSeries,
    MultiCommandedVoltage,
    FiberPhotometry,
    FluorophoresTable
)


nwbfile = NWBFile(
    session_description="session_description",
    identifier="identifier",
    session_start_time=datetime.datetime.now(datetime.timezone.utc),
)

# In the next ten calls or so, we'll set up the metadata from the bottom of the metadata tree up
# You can follow along here: 

# Create a commanded voltage container, this can store one or more commanded voltage series
multi_commanded_voltage = MultiCommandedVoltage(
    name="MyMultiCommandedVoltage",
)

# Add a commanded voltage series to this container
commandedvoltage_series = (
    multi_commanded_voltage.create_commanded_voltage_series(
        name="commanded_voltage",
        data=[1.0, 2.0, 3.0],
        frequency=30.0,
        power=500.0,
        rate=30.0,
    )
)

# Create an excitation sources table
excitationsources_table = ExcitationSourcesTable(
    description="excitation sources table"
)

# Add one row to the table per excitation source
# You can repeat this in a for-loop for many sources
excitationsources_table.add_row(
    peak_wavelength=700.0,
    source_type="laser",
    commanded_voltage=commandedvoltage_series,
)

photodetectors_table = PhotodetectorsTable(
    description="photodetectors table"
)

# Add one row to the table per photodetector
photodetectors_table.add_row(
    peak_wavelength=500.0, 
    type="PMT", 
    gain=100.0
)


fluorophores_table = FluorophoresTable(
    description='fluorophores'
)

fluorophores_table.add_row(
    label='dlight',
    location='VTA',
    coordinates=(3.0,2.0,1.0)
)

fibers_table = FibersTable(
    description="fibers table"
)

# Here we add the metadata tables to the metadata section
nwbfile.add_lab_meta_data(
    FiberPhotometry(
        fibers=fibers_table,
        excitation_sources=excitationsources_table,
        photodetectors=photodetectors_table,
        fluorophores=fluorophores_table
    )
)

# Important: we add the fibers to the fibers table _after_ adding the metadata
# This ensures that we can find this data in their tables of origin
fibers_table.add_fiber(
    excitation_source=0, #integers indicated rows of excitation sources table
    photodetector=0,
    fluorophores=[0], #potentially multiple fluorophores, so list of indices
    location='my location',
    notes='notes'
)

# Here we set up a list of fibers that our recording came from
fibers_ref = DynamicTableRegion(
    name="rois", 
    data=[0], # potentially multiple fibers
    description="source fibers", 
    table=fibers_table
)

# Create a raw roiresponseseries, this is your main acquisition
roi_response_series = RoiResponseSeries(
    name="roi_response_series",
    description="my roi response series",
    data=np.random.randn(100, 1),
    unit='F',
    rate=30.0,
    rois=fibers_ref,
)

# This is your processed data 
deconv_roi_response_series = DeconvolvedRoiResponseSeries(
    name="DeconvolvedRoiResponseSeries",
    description="my roi response series",
    data=np.random.randn(100, 1),
    unit='F',
    rate=30.0,
    rois=fibers_ref,
    raw=roi_response_series,
)

ophys_module = nwbfile.create_processing_module(
    name="ophys", description="fiber photometry"
)

ophys_module.add(multi_commanded_voltage)
nwbfile.add_acquisition(roi_response_series)
ophys_module.add(deconv_roi_response_series)

# write nwb file
filename = 'test.nwb'
with NWBHDF5IO(filename, 'w') as io:
    io.write(nwbfile)
    
# read nwb file and check its contents
with NWBHDF5IO(filename, 'r', load_namespaces=True) as io:
    nwbfile = io.read()
    # Access and print information about the acquisition
    print(nwbfile.acquisition["roi_response_series"])
    # Access and print information about the processed data
    print(nwbfile.processing['ophys']["DeconvolvedRoiResponseSeries"])
    # Access and print all of the metadata
    print(nwbfile.lab_meta_data)

This extension was created using ndx-template.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ndx-photometry-0.1.0.tar.gz (48.2 kB view details)

Uploaded Source

Built Distribution

ndx_photometry-0.1.0-py2.py3-none-any.whl (11.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file ndx-photometry-0.1.0.tar.gz.

File metadata

  • Download URL: ndx-photometry-0.1.0.tar.gz
  • Upload date:
  • Size: 48.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.12.0 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.11

File hashes

Hashes for ndx-photometry-0.1.0.tar.gz
Algorithm Hash digest
SHA256 52dae4ed7406433e509533d90a4f6e15c892dbd6f2b772a1fef914e7ccec749e
MD5 3789dc8c0facf95eff0e3286b30d1d86
BLAKE2b-256 f18cbe421d3e104610651d01d8093c67d102dbdec2929365587c11521d8e7eac

See more details on using hashes here.

File details

Details for the file ndx_photometry-0.1.0-py2.py3-none-any.whl.

File metadata

  • Download URL: ndx_photometry-0.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.12.0 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.11

File hashes

Hashes for ndx_photometry-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 8649ab96253021d452b8fcebcf9f2978566e7eb6e40e11337e74a8408c7fdc41
MD5 dc8b2f993ed467464827c05f750a3c15
BLAKE2b-256 d982b42f93a8350906935aeaaa53e060f0dc28ecefdac313cc4b91395e219e2b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page