Skip to content

Conversation

@njmei
Copy link
Contributor

@njmei njmei commented Oct 21, 2020

Overview:

This PR contains commits to address pyNWB best practice recommendations for behavior ophys NWB files.

Addresses:

Addresses issue: #1733

Changes:

  • Removes many fields from our custom behavior ophys extension in favor of already existing pyNWB classes (fixes how our custom extension is generated)
  • Transposes how dff and fluorescence data are stored in NWB file
  • Add better/missing documentation to pyNWB fields
  • Fix a bug with how ROIs were stored in NWB files
  • Rename 'two_photon_imaging' processing module to 'ophys' to better conform to pyNWB best practice

Validation:

  • New behavior ophys NWB files can be produced after changes

Checklist

  • My code follows
    Allen Institute Contribution Guidelines
  • My code is unit tested and does not decrease test coverage
  • I have performed a self review of my own code
  • My code is well-documented, and the docstrings conform to
    Numpy Standards
  • I have updated the documentation of the repository where
    appropriate
  • The header on my commit includes the issue number
  • My Pull Request has the latest AllenSDK release candidate branch
    rc/x.y.z as its merge target
  • My code passes all AllenSDK tests

Notes:

njmei added 7 commits October 20, 2020 11:30
This commit removes fields that already exist as part of the pyNWB
"Subject" class from the custom behavior ophys subject extension.
Previously dff and fluorescence traces were being stored as
ROIs x timepoints Numpy arrays. This commit implements pyNWB
best practice by storing the data with the time dimension
first.
This is a combination of the following 3 commits:

1) Simplify custom behavior ophys pyNWB extension

   Previously, the OphysBehaviorMetadata extension included a number
   of fields that already exist in base pyNWB classes. This commit
   moves "emission_lambda", "excitation_lambda", "indicator",
   "location", "session_start_time", and "imaging_rate" fields so
   that they are stored in pyNWB classes like ImagingPlane and
   OpticalChannel. This greatly simplifies the OphysBehaviorMetadata
   extension definition.

2) Add more detailed "doc" description to pyNWB extension fields

3) Address pyNWB NWBFile.modules deprecation warning

   Trying to access pyNWB processing modules via the "NWBFile.modules"
   attribute is now deprecated in favor of "NWBFile.processing".
   This commit implements the favored method for accessing
   pyNWB processing modules from an NWBFile object.
Previously, ROIs were added to the behavior ophys NWB file
incorrectly. ROIs all ended up starting at the 0,0 corner of the
whole imaging space.

This was caused by feeding the "LIMS formatted ROI" (List[List[bool]])
through the allensdk.brain_observatory.roi_masks.create_roi_mask
function twice instead of only once. This happened once in
allensdk.internal.api.ophys_lims_api.OphysLimsApi
get_cell_specimen_table() method and yet again in the
allensdk.brain_observatory.nwb.__init__ add_cell_specimen_table()
function.

Now, only the OphysLimsApi get_cell_specimen_table() is the only
place where LIMS formatted ROIs are deserialized to the
allensdk.brain_observatory.roi_masks.RoiMask class.

A CellSpecimenTable schema discrepancy was also fixed.
'x' and 'y' fields should be Int not Float based on what the
behavior_ophys_write_nwb_strategy from LIMS is passing in.
This commit adds experiment descriptions to be havior ophys NWB files.
These descriptions can be determined based on the behavior ophys
"session type" string. Example:

"OPHYS_1_images_A" is the first stage of the visual behavior experiments
"OPHYS_6_images_A" is the last stage of the visual behavior experiments
@njmei
Copy link
Contributor Author

njmei commented Oct 21, 2020

@matchings @dougollerenshaw Let me know if you'd like any changes for the wording of experiment descriptions: ac7fde7

@kschelonka
Copy link
Contributor

kschelonka commented Oct 21, 2020 via email

@codecov-io
Copy link

codecov-io commented Oct 21, 2020

Codecov Report

Merging #1760 into rc/2.4.0 will increase coverage by 0.13%.
The diff coverage is 91.47%.

Impacted file tree graph

@@             Coverage Diff              @@
##           rc/2.4.0    #1760      +/-   ##
============================================
+ Coverage     36.16%   36.30%   +0.13%     
============================================
  Files           346      346              
  Lines         33819    33859      +40     
============================================
+ Hits          12232    12293      +61     
+ Misses        21587    21566      -21     
Impacted Files Coverage Δ
allensdk/internal/api/ophys_lims_api.py 32.63% <0.00%> (-0.89%) ⬇️
allensdk/brain_observatory/nwb/__init__.py 89.01% <94.44%> (ø)
...avior/behavior_ophys_api/behavior_ophys_nwb_api.py 61.46% <96.29%> (+1.87%) ⬆️
.../brain_observatory/behavior/metadata_processing.py 100.00% <100.00%> (ø)
allensdk/brain_observatory/behavior/schemas.py 100.00% <100.00%> (ø)
...k/brain_observatory/behavior/write_nwb/_schemas.py 100.00% <100.00%> (ø)
allensdk/brain_observatory/nwb/metadata.py 75.00% <100.00%> (+3.57%) ⬆️
...rain_observatory/ecephys/visualization/__init__.py 100.00% <0.00%> (+100.00%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8c1144c...5fd764b. Read the comment docs.

@njmei njmei requested a review from kschelonka October 23, 2020 20:43
Copy link
Contributor

@kschelonka kschelonka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏞️

@njmei njmei merged commit 5418524 into rc/2.4.0 Oct 23, 2020
@njmei njmei deleted the 1733-address-behavior-ophys-nwb-issues branch October 23, 2020 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants