Last active
October 2, 2017 20:44
-
-
Save neuromusic/28742cbd858fa874a99864e24667401c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# NOTE: `dataset` is an internal object for data ingest & time alignment | |
session_start_time = dataset.pkl['startdatetime'] | |
roi_masks = dataset.get_roi_mask_array() | |
max_projection = dataset.get_max_projection() | |
dFF, dFF_t = dataset.get_dff_traces() | |
NA = 'THIS REQUIRED ATTRIBUTE INTENTIONALLY LEFT BLANK.' | |
from pynwb import NWBFile | |
nwb = NWBFile( | |
source = NA, | |
session_description = NA, | |
identifier = NA, | |
session_start_time = session_start_time, | |
) | |
from pynwb import ophys | |
optical_channel = ophys.OpticalChannel( | |
name = 'Optical Channel', | |
source = NA, | |
description = NA, | |
emission_lambda = NA, | |
) | |
from pynwb import image | |
max_proj = image.ImageSeries( | |
name = 'Maximum Projection Image', | |
source = NA, | |
data = max_projection, | |
unit = NA, | |
format = 'raw', | |
timestamps = [0.0], # <- This is required, so let's make it at the beginning of the experiment | |
) | |
roi_list = [] | |
for ii, mask in enumerate(roi_masks): | |
roi_list.append( | |
ophys.ROI( | |
name = str(ii), | |
source = NA, | |
roi_description = NA, | |
pix_mask = [], | |
pix_mask_weight = [], | |
img_mask = mask, | |
reference_images = max_proj, # <- Ugh, I need to define reference image(s) just to define an ROI? | |
) | |
) | |
imaging_plane = ophys.ImagingPlane( | |
name = 'Imaging Plane', | |
source = NA, | |
optical_channel = optical_channel, # <- Ugh, I need to define an OpticalChannel just to define an ImagingPlane? | |
description = NA, # <- Why is this required? | |
device = 'scientifica', # <- this is an implicit link to /general/devices [device (str): Name of device in /general/devices] | |
excitation_lambda = "910nm", # <- this should be a float or int with a "units" field | |
imaging_rate = NA, # <- why is this required? & why is it a string? | |
indicator = NA, | |
location = NA, | |
manifold = [], # <- I don't understand what this is. | |
conversion = 1.0, | |
unit = 'um', | |
reference_frame = NA, | |
) | |
segmentation = ophys.PlaneSegmentation( | |
name = 'Plane Segmentation', | |
source = NA, | |
description = NA, | |
roi_list = roi_list, # <- Ugh, I need to define a list of ROIs just to define an PlaneSegmentation? | |
imaging_plane = imaging_plane, # <- Ugh, I need to define an imaging plane just to define a PlaneSegmentation? | |
reference_images = max_proj, | |
) | |
seg_interface = ophys.ImageSegmentation( | |
name = 'Image Segmentation', | |
source = NA, | |
plane_segmentation = segmentation, # <- Ugh, I need to define an segmentation just to store calcium traces? | |
) | |
dFF_series = ophys.RoiResponseSeries( | |
name = 'dF_F', | |
source = NA, | |
data = dFF, | |
unit = 'dF/F', | |
roi_names = [roi.name for roi in roi_list], # <- shouldn't this be a more explicit link to the ROIs? | |
segmenttation_interface = seg_interface, # <- Ugh, I need to define an interface just to store calcium traces? | |
timestamps = dFF_t, | |
) | |
dFF = ophys.DfOverF( | |
source = NA, | |
roi_response_series = dFF_series, # <- Wait, this object is just a wrapper for an RoiResponseSeries? | |
) | |
# not let's create the processing module to store this in | |
ophys_module = nwb.create_processing_module( | |
name="ophys", | |
description="calcium responses", | |
source="Allen Brain Observatory: Visual Behavior", | |
) | |
# what happens if we only add one container? | |
ophys_module.add_container(dFF) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I was just going to ask for an update on your gist, so that I can start back-filling in data from brain observatory. Is the write broken, or the validation?