Skip to content

Commit

Permalink
enh: update bergamo session
Browse files Browse the repository at this point in the history
  • Loading branch information
jtyoung84 committed Dec 13, 2023
1 parent 7cfb786 commit ef412a5
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 46 deletions.
21 changes: 15 additions & 6 deletions src/aind_metadata_mapper/bergamo/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@
import re
import sys
from dataclasses import dataclass
from datetime import datetime, time
from datetime import datetime
from os import PathLike
from pathlib import Path
from typing import Dict, List, Tuple, Union

import numpy as np

# from aind_data_schema.models.devices import Detector, Laser
from aind_data_schema.core.session import (
DetectorConfig,
FieldOfView,
LaserConfig,
Modality,
Session,
Stream,
)
from aind_data_schema.models.devices import Detector, Laser
from aind_data_schema.models.stimulus import (
PhotoStimulation,
PhotoStimulationGroup,
Expand All @@ -43,8 +46,12 @@ class UserSettings(BaseSettings):
session_end_time: datetime
stream_start_time: datetime
stream_end_time: datetime
stimulus_start_time: time
stimulus_end_time: time
stimulus_start_time: datetime
stimulus_end_time: datetime

# TODO: Look into whether defaults can be set for these fields
mouse_platform_name: str
active_mouse_platform: bool

# Data that might change but can have default values
session_type: str = "BCI"
Expand Down Expand Up @@ -388,12 +395,14 @@ def _transform(self, extracted_source: RawImageInfo) -> Session:
]

data_stream = Stream(
mouse_platform_name=self.user_settings.mouse_platform_name,
active_mouse_platform=self.user_settings.active_mouse_platform,
stream_start_time=self.user_settings.stream_start_time,
stream_end_time=self.user_settings.stream_end_time,
stream_modalities=[Modality.POPHYS],
camera_names=list(self.user_settings.camera_names),
light_sources=[
Laser(
LaserConfig(
name=self.user_settings.laser_a_name,
wavelength=self.user_settings.laser_a_wavelength,
wavelength_unit=self.user_settings.laser_a_wavelength_unit,
Expand All @@ -404,7 +413,7 @@ def _transform(self, extracted_source: RawImageInfo) -> Session:
),
],
detectors=[
Detector(
DetectorConfig(
name=self.user_settings.detector_a_name,
exposure_time=self.user_settings.detector_a_exposure_time,
trigger_type=self.user_settings.detector_a_trigger_type,
Expand Down
79 changes: 43 additions & 36 deletions tests/resources/bergamo/expected_session.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"describedBy": "https://raw.githubusercontent.com/AllenNeuralDynamics/aind-data-schema/main/src/aind_data_schema/session.py",
"schema_version": "0.0.1",
"describedBy": "https://raw.githubusercontent.com/AllenNeuralDynamics/aind-data-schema/main/src/aind_data_schema/core/session.py",
"schema_version": "0.1.0",
"experimenter_full_name": [
"John Smith",
"Jane Smith"
Expand All @@ -10,23 +10,17 @@
"session_type": "BCI",
"iacuc_protocol": "2115",
"rig_id": "Bergamo photostim.",
"calibrations": null,
"maintenance": null,
"subject_id": 12345,
"calibrations": [],
"maintenance": [],
"subject_id": "12345",
"animal_weight_prior": null,
"animal_weight_post": null,
"weight_unit": "gram",
"data_streams": [
{
"stream_start_time": "2023-10-10T15:00:00",
"stream_end_time": "2023-10-10T16:00:00",
"stream_modalities": [
{
"name": "Planar optical physiology",
"abbreviation": "ophys"
}
],
"daq_names": null,
"daq_names": [],
"camera_names": [
"Side Camera"
],
Expand All @@ -36,43 +30,55 @@
"name": "Laser A",
"wavelength": 920,
"wavelength_unit": "nanometer",
"excitation_power": 15,
"excitation_power": "15",
"excitation_power_unit": "percent"
}
],
"ephys_modules": null,
"manipulator_modules": null,
"ephys_modules": [],
"stick_microscopes": [],
"manipulator_modules": [],
"detectors": [
{
"name": "PMT A",
"exposure_time": 0.1,
"exposure_time": "0.1",
"exposure_time_unit": "millisecond",
"trigger_type": "Internal"
}
],
"fiber_photometry_assemblies": null,
"fiber_connections": [],
"fiber_modules": [],
"ophys_fovs": [
{
"index": 0,
"imaging_depth": 150,
"imaging_depth_unit": "micrometer",
"targeted_structure": "M1",
"fov_coordinate_ml": 1.5,
"fov_coordinate_ap": 1.5,
"fov_coordinate_ml": "1.5",
"fov_coordinate_ap": "1.5",
"fov_coordinate_unit": "micrometer",
"fov_reference": "Bregma",
"fov_width": 512,
"fov_height": 512,
"fov_size_unit": "pixel",
"magnification": "16x",
"fov_scale_factor": 1.2,
"fov_scale_factor": "1.2",
"fov_scale_factor_unit": "um/pixel",
"frame_rate": 30.0119,
"frame_rate_unit": "hertz"
"frame_rate": "30.0119",
"frame_rate_unit": "hertz",
"coupled_fov_index": null
}
],
"slap_fovs": null,
"stack_parameters": null,
"stimulus_device_names": null,
"stimulus_device_names": [],
"mouse_platform_name": "some_mouse_platform_name",
"active_mouse_platform": true,
"stream_modalities": [
{
"name": "Planar optical physiology",
"abbreviation": "ophys"
}
],
"notes": null
}
],
Expand All @@ -86,42 +92,43 @@
{
"group_index": 0,
"number_of_neurons": 10,
"stimulation_laser_power": 20,
"stimulation_laser_power": "20",
"stimulation_laser_power_unit": "milliwatt",
"number_trials": 5,
"number_spirals": 10,
"spiral_duration": 0.01,
"spiral_duration": "0.01",
"spiral_duration_unit": "second",
"inter_spiral_interval": 0.001,
"inter_spiral_interval": "0.001",
"inter_spiral_interval_unit": "second",
"other_parameters": null,
"other_parameters": {},
"notes": null
},
{
"group_index": 0,
"number_of_neurons": 10,
"stimulation_laser_power": 20,
"stimulation_laser_power": "20",
"stimulation_laser_power_unit": "milliwatt",
"number_trials": 5,
"number_spirals": 10,
"spiral_duration": 0.01,
"spiral_duration": "0.01",
"spiral_duration_unit": "second",
"inter_spiral_interval": 0.001,
"inter_spiral_interval": "0.001",
"inter_spiral_interval_unit": "second",
"other_parameters": null,
"other_parameters": {},
"notes": null
}
],
"inter_trial_interval": 10,
"inter_trial_interval": "10",
"inter_trial_interval_unit": "second",
"other_parameters": null,
"other_parameters": {},
"notes": null
},
"stimulus_start_time": "15:15:00",
"stimulus_end_time": "15:45:00"
"stimulus_start_time": "2023-10-10T15:15:00",
"stimulus_end_time": "2023-10-10T15:45:00"
}
],
"reward_delivery": null,
"stick_microscopes": null,
"reward_consumed_total": null,
"reward_consumed_unit": "microliter",
"notes": null
}
10 changes: 6 additions & 4 deletions tests/test_bergamo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import json
import os
import unittest
from datetime import datetime, time
from datetime import datetime
from pathlib import Path
from unittest.mock import MagicMock, patch

Expand Down Expand Up @@ -39,14 +39,16 @@ def setUpClass(cls):
cls.example_description0 = raw_des0_contents
cls.example_shape = [347, 512, 512]
cls.example_user_settings = UserSettings(
mouse_platform_name="some_mouse_platform_name",
active_mouse_platform=True,
experimenter_full_name=["John Smith", "Jane Smith"],
subject_id="12345",
session_start_time=datetime(2023, 10, 10, 14, 0, 0),
session_end_time=datetime(2023, 10, 10, 17, 0, 0),
stream_start_time=datetime(2023, 10, 10, 15, 0, 0),
stream_end_time=datetime(2023, 10, 10, 16, 0, 0),
stimulus_start_time=time(15, 15, 0),
stimulus_end_time=time(15, 45, 0),
stimulus_start_time=datetime(2023, 10, 10, 15, 15, 0),
stimulus_end_time=datetime(2023, 10, 10, 15, 45, 0),
)
cls.expected_session = expected_session_contents

Expand Down Expand Up @@ -197,7 +199,7 @@ def test_transform(self, mock_log: MagicMock):
)
actual_session = etl_job1._transform(raw_image_info)
self.assertEqual(
self.expected_session, json.loads(actual_session.json())
self.expected_session, json.loads(actual_session.model_dump_json())
)
mock_log.assert_called_once_with(
"Multiple planes not handled in metadata collection. "
Expand Down

0 comments on commit ef412a5

Please sign in to comment.