Skip to content

Commit

Permalink
Merge pull request #15 from catalystneuro/add_2p_imaging
Browse files Browse the repository at this point in the history
Add 2p imaging fro Benisty2024
  • Loading branch information
alessandratrapani authored May 16, 2024
2 parents eb5a154 + 3686b30 commit ce2afb0
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 263 deletions.
18 changes: 12 additions & 6 deletions src/higley_lab_to_nwb/benisty_2024/benisty_2024_convert_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,27 @@ def session_to_nwb(
output_dir_path = output_dir_path / "nwb_stub"
output_dir_path.mkdir(parents=True, exist_ok=True)

nwbfile_path = output_dir_path / f"{session_id}_new.nwb"
nwbfile_path = output_dir_path / f"{session_id}.nwb"

source_data = dict()
conversion_options = dict()

search_pattern = "_".join(session_id.split("_")[:2])
nwbfile_path = output_dir_path / f"{session_id}.nwb"

source_data = dict()
conversion_options = dict()

# Add 2p Imaging
imaging_path = folder_path / "tiff"
source_data.update(dict(TwoPhotonImagingGreenChannel=dict(folder_path=str(imaging_path), file_pattern=f"*.tif")))
conversion_options.update(dict(TwoPhotonImagingGreenChannel=dict(stub_test=stub_test)))

converter = Benisty2024NWBConverter(
source_data=source_data,
)

# Add datetime to conversion
metadata = converter.get_metadata()
date = read_session_start_time(folder_path=folder_path)
metadata["NWBFile"]["session_start_time"] = date
subject_id = session_id.split("_")[1]
metadata["Subject"].update(subject_id=subject_id)
metadata["NWBFile"].update(session_id=session_id)
Expand All @@ -44,6 +50,7 @@ def session_to_nwb(
# Add ophys metadata
ophys_metadata_path = Path(__file__).parent / "metadata" / "benisty_2024_ophys_metadata.yaml"
ophys_metadata = load_dict_from_file(ophys_metadata_path)
metadata.pop("Ophys", None)
metadata = dict_deep_update(metadata, ophys_metadata)

# Run conversion
Expand All @@ -59,8 +66,7 @@ def session_to_nwb(
data_dir_path = root_path / "Higley-CN-data-share"
output_dir_path = root_path / "Higley-conversion_nwb/"
stub_test = True
session_ids = os.listdir(data_dir_path)
session_id = "11222019_grabAM06_vis_stim"
session_id = "04072021_am2psi_05_spont"
folder_path = data_dir_path / Path(session_id)
session_to_nwb(
folder_path=folder_path,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""Primary NWBConverter class for this dataset."""

from typing import Dict, List
from neuroconv import NWBConverter


from neuroconv import NWBConverter
from neuroconv.datainterfaces import ScanImageMultiFileImagingInterface

class Benisty2024NWBConverter(NWBConverter):
"""Primary conversion class."""

data_interface_classes = dict(
TwoPhotonImagingGreenChannel=ScanImageMultiFileImagingInterface,
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
Ophys:
Device:
OnePhotonSeries:
ImagingPlane:
- name: TwoPhotonMicroscope
description: MOM microscope (Sutter Instruments) coupled to a 16x, 0.8 NA objective (Nikon). Excitation was driven by a Titanium-Sapphire Laser (Mai-Tai eHP DeepSee, Spectra-Physics).
manufacturer: Sutter Instruments
TwoPhotonSeries:
- name: TwoPhotonSeriesGreenChannel
description: Imaging data from Green channel recorded with 2p microscope. Images were acquired at 512x512 resolution at 30 Hz using a galvo-resonant scan system controlled by ScanImage software (Vidrio).
imaging_plane: ImagingPlaneGreenChannel
unit: n.a.
ImagingPlane:
- name: ImagingPlaneGreenChannel
description: Imaging plane for the Green channel recorded with 2p microscope.
excitation_lambda: 920.0 # in nm
location: Whole Brain
device: TwoPhotonMicroscope
optical_channel:
- name: Green
description: Emitted light was collected through a 525/50 filter and a gallium arsenide phosphide photomultiplier tube (Hamamatsu).
emission_lambda: 525.0
indicator: GCaMP6s
259 changes: 7 additions & 252 deletions src/higley_lab_to_nwb/benisty_2024/tutorial/tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"from pathlib import Path\n",
"\n",
"# Choose which epoch to explore\n",
"session_id = '11222019_grabAM06_vis_stim'\n",
"session_id = '04072021_am2psi_05_spont'\n",
"\n",
"# The file path to a .nwb file\n",
"root_path = Path(\"/media/amtra/Samsung_T5/CN_data\")\n",
Expand Down Expand Up @@ -124,9 +124,9 @@
"\n",
"## Raw OnePhoton Imaging\n",
"\n",
"The raw TwoPhoton imaging data is stored in `pynwb.ophys.OnePhotonSeries` objects (for each channel and excitation type separately) which is added to `nwbfile.acquisition`. The data can be accessed as `nwbfile.acquisition['OnePhotonSeries_color_Excitation_color_Channel']`.\n",
"The raw TwoPhoton imaging data is stored in `pynwb.ophys.TwoPhotonSeries` objects (for each channel and excitation type separately) which is added to `nwbfile.acquisition`. The data can be accessed as `nwbfile.acquisition['TwoPhotonSeries_color_Channel']`.\n",
"\n",
"The data in [OnePhotonSeries](https://pynwb.readthedocs.io/en/stable/pynwb.ophys.html#pynwb.ophys.OnePhotonSeries) is stored as a three dimensional array: the first dimension is time (frame), the second and third dimensions represent x and y (width by height). "
"The data in [TwoPhotonSeries](https://pynwb.readthedocs.io/en/stable/pynwb.ophys.html#pynwb.ophys.TwoPhotonSeries) is stored as a three dimensional array: the first dimension is time (frame), the second and third dimensions represent x and y (width by height). "
]
},
{
Expand All @@ -137,17 +137,7 @@
"outputs": [],
"source": [
"names_of_photon_series = nwbfile.acquisition.keys()\n",
"_ = [print(name) for name in names_of_photon_series if \"OnePhotonSeries\" in name ]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "eb243ecc",
"metadata": {},
"outputs": [],
"source": [
"excitation_channel_combination = \"BlueExcitationGreenChannel\""
"_ = [print(name) for name in names_of_photon_series if \"TwoPhotonSeries\" in name ]"
]
},
{
Expand All @@ -157,7 +147,7 @@
"metadata": {},
"outputs": [],
"source": [
"photon_series = nwbfile.acquisition[f\"OnePhotonSeries{excitation_channel_combination}\"]"
"photon_series = nwbfile.acquisition[\"TwoPhotonSeriesGreenChannel\"]"
]
},
{
Expand All @@ -181,8 +171,8 @@
"\n",
"from matplotlib import pyplot as plt\n",
"\n",
"plt.imshow(photon_series.data[10], aspect=\"auto\", cmap=\"RdYlBu_r\")\n",
"plt.title(f\"One frame from {excitation_channel_combination}\")\n",
"plt.imshow(photon_series.data[10], aspect=\"auto\")\n",
"plt.title(f\"One frame from TwoPhotonSeriesGreenChannel\")\n",
"plt.show()\n"
]
},
Expand All @@ -205,241 +195,6 @@
"source": [
"photon_series.starting_time"
]
},
{
"cell_type": "markdown",
"id": "ce538054-666b-4ad1-9d34-f9730973b3ff",
"metadata": {},
"source": [
"# Access TTL Signals <a name=\"#ttl-signals\"></a>\n",
"\n",
"This section demonstrates how to access the TTL signals stored in the NWBFile.\n",
"TTLTypesTable contains the description and the id for each TTL signal\n",
"TTLsTable contains the respective timestamps (rising times)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6c899439-be9f-4187-bc02-b6c9cb2491c3",
"metadata": {},
"outputs": [],
"source": [
"nwbfile.acquisition[\"TTLTypesTable\"]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cc12d0df",
"metadata": {},
"outputs": [],
"source": [
"nwbfile.acquisition[\"TTLsTable\"]\n"
]
},
{
"cell_type": "markdown",
"id": "027bc135",
"metadata": {},
"source": [
"# Access Wheel Signal <a name=\"#wheel-signal\"></a>\n",
"\n",
"This section demonstrates how to access the wheel velocity trace stored in the NWBFile."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1bd4b538",
"metadata": {},
"outputs": [],
"source": [
"wheel_signal = nwbfile.acquisition[\"WheelSignal\"]\n",
"wheel_signal"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b6852179",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"time = np.linspace(0, wheel_signal.data.shape[0]/wheel_signal.rate,wheel_signal.data.shape[0])\n",
"plt.plot(time,wheel_signal.data*wheel_signal.conversion)\n",
"plt.ylabel(wheel_signal.unit)\n",
"plt.xlabel(\"Time (s)\")\n",
"plt.title(wheel_signal.name)"
]
},
{
"cell_type": "markdown",
"id": "e83cc1bf",
"metadata": {},
"source": [
"# Access Raw Behavior <a name=\"#raw-behavior\"></a>\n",
"\n",
"This section demonstrates how to access the raw behavioral video stored in the NWBFile."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e6e22c09",
"metadata": {},
"outputs": [],
"source": [
"video = nwbfile.acquisition[\"Video: 11222019_grabAM06_visual_stim\"]\n",
"video"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f0c05e5a",
"metadata": {},
"outputs": [],
"source": [
"plt.imshow(video.data[1], aspect=\"auto\")\n",
"plt.title(f\"A frame of {video.name} at {video.timestamps[1]} sec\")\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"id": "74d1bb0d",
"metadata": {},
"source": [
"# Access Processed Behavior <a name=\"#processed-behavior\"></a>\n",
"\n",
"This section demonstrates how to access the Facemap output stored in the NWBFile.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "58b7e241",
"metadata": {},
"outputs": [],
"source": [
"nwbfile.processing[\"behavior\"][\"EyeTracking\"]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0f57bf13",
"metadata": {},
"outputs": [],
"source": [
"nwbfile.processing[\"behavior\"][\"PupilTracking\"]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "83f4fd8e",
"metadata": {},
"outputs": [],
"source": [
"motion_svd_series = nwbfile.processing[\"behavior\"][\"MotionSVDSeriesROI1\"]\n",
"motion_svd_series"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9e8ed951",
"metadata": {},
"outputs": [],
"source": [
"motion_svd_series.data.shape"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "90f6f43e",
"metadata": {},
"outputs": [],
"source": [
"plt.plot(motion_svd_series.data[0])\n",
"plt.title(motion_svd_series.name)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ff291bec",
"metadata": {},
"outputs": [],
"source": [
"motion_svd_masks = nwbfile.processing[\"behavior\"][\"MotionSVDMasksROI1\"]\n",
"motion_svd_masks"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d35fbac0",
"metadata": {},
"outputs": [],
"source": [
"motion_svd_masks.mask_coordinates[:]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "79eaedbb",
"metadata": {},
"outputs": [],
"source": [
"motion_svd_masks.processed_frame_dimension[:]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bdde8a91",
"metadata": {},
"outputs": [],
"source": [
"masks = motion_svd_masks.image_mask_index[:10]\n",
"# plt.imshow(mask, aspect=\"auto\", cmap=\"RdYlBu_r\" )\n",
"# plt.title(\"First component mask\")\n",
"# plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5654d13e",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "b50a377e",
"metadata": {},
"source": [
"# Access Visual Stimulus <a name=\"access-visualstim\"></a>\n",
"\n",
"This section demonstrates how to access the visual stimulus data."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ce2b8da7",
"metadata": {},
"outputs": [],
"source": [
"nwbfile.intervals[\"VisualStimulus\"]"
]
}
],
"metadata": {
Expand Down

0 comments on commit ce2afb0

Please sign in to comment.