Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat 33 schema version #40

Merged
merged 8 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ readme = "README.md"
dynamic = ["version"]

dependencies = [
"aind-data-schema==0.26.5",
"aind-data-schema==0.33.3",
"scanimage-tiff-reader==1.4.1.4",
"tifffile==2024.2.12",
"pydantic-settings>=2.0",
Expand Down
163 changes: 85 additions & 78 deletions src/aind_metadata_mapper/bergamo/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
LaserConfig,
Modality,
Session,
StimulusEpoch,
StimulusModality,
Stream,
)
from aind_data_schema.models.stimulus import (
PhotoStimulation,
PhotoStimulationGroup,
StimulusEpoch,
)
from aind_data_schema.models.units import PowerUnit, SizeUnit
from pydantic import Field
Expand Down Expand Up @@ -401,8 +402,6 @@ def _transform(self, extracted_source: RawImageInfo) -> Session:
]

data_stream = Stream(
mouse_platform_name=self.job_settings.mouse_platform_name,
active_mouse_platform=self.job_settings.active_mouse_platform,
stream_start_time=self.job_settings.stream_start_time,
stream_end_time=self.job_settings.stream_end_time,
stream_modalities=[Modality.POPHYS],
Expand Down Expand Up @@ -451,6 +450,8 @@ def _transform(self, extracted_source: RawImageInfo) -> Session:
),
],
)
stimulus_name = "PhotoStimulation"
photostim_interval = self.job_settings.photo_stim_inter_trial_interval
return Session(
experimenter_full_name=self.job_settings.experimenter_full_name,
session_start_time=self.job_settings.session_start_time,
Expand All @@ -462,93 +463,99 @@ def _transform(self, extracted_source: RawImageInfo) -> Session:
data_streams=[data_stream],
stimulus_epochs=[
StimulusEpoch(
stimulus=PhotoStimulation(
stimulus_name="PhotoStimulation",
number_groups=(
self.job_settings.num_of_photo_stim_groups
),
groups=[
PhotoStimulationGroup(
group_index=(
self.job_settings.photo_stim_groups[0][
"group_index"
]
),
number_of_neurons=int(
np.array(
stimulus_name=stimulus_name,
stimulus_modalities=[
StimulusModality.OPTOGENETICS,
],
stimulus_parameters=[
PhotoStimulation(
stimulus_name="PhotoStimulation",
number_groups=(
self.job_settings.num_of_photo_stim_groups
),
groups=[
PhotoStimulationGroup(
group_index=(
self.job_settings.photo_stim_groups[0][
"group_index"
]
),
number_of_neurons=int(
np.array(
photostim_groups[0]["rois"][1][
"scanfields"
]["slmPattern"]
).shape[0]
),
stimulation_laser_power=int(
photostim_groups[0]["rois"][1][
"scanfields"
]["slmPattern"]
).shape[0]
),
stimulation_laser_power=int(
photostim_groups[0]["rois"][1][
"scanfields"
]["powers"]
),
number_trials=(
self.job_settings.photo_stim_groups[0][
"number_trials"
]
),
number_spirals=int(
photostim_groups[0]["rois"][1][
"scanfields"
]["repetitions"]
),
spiral_duration=photostim_groups[0]["rois"][1][
"scanfields"
]["duration"],
inter_spiral_interval=photostim_groups[0][
"rois"
][2]["scanfields"]["duration"],
),
PhotoStimulationGroup(
group_index=(
self.job_settings.photo_stim_groups[1][
"group_index"
]
),
number_of_neurons=int(
np.array(
]["powers"]
),
number_trials=(
self.job_settings.photo_stim_groups[0][
"number_trials"
]
),
number_spirals=int(
photostim_groups[0]["rois"][1][
"scanfields"
]["slmPattern"]
).shape[0]
),
stimulation_laser_power=int(
photostim_groups[0]["rois"][1][
"scanfields"
]["powers"]
),
number_trials=(
self.job_settings.photo_stim_groups[1][
"number_trials"
]
]["repetitions"]
),
spiral_duration=photostim_groups[0][
"rois"
][1]["scanfields"]["duration"],
inter_spiral_interval=photostim_groups[0][
"rois"
][2]["scanfields"]["duration"],
),
number_spirals=int(
photostim_groups[0]["rois"][1][
"scanfields"
]["repetitions"]
PhotoStimulationGroup(
Copy link
Contributor

Choose a reason for hiding this comment

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

@jtyoung84 This looks like a duplicate

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think they're close, but there is a slight difference with the group index

group_index=(
self.job_settings.photo_stim_groups[1][
"group_index"
]
),
number_of_neurons=int(
np.array(
photostim_groups[0]["rois"][1][
"scanfields"
]["slmPattern"]
).shape[0]
),
stimulation_laser_power=int(
photostim_groups[0]["rois"][1][
"scanfields"
]["powers"]
),
number_trials=(
self.job_settings.photo_stim_groups[1][
"number_trials"
]
),
number_spirals=int(
photostim_groups[0]["rois"][1][
"scanfields"
]["repetitions"]
),
spiral_duration=photostim_groups[0][
"rois"
][1]["scanfields"]["duration"],
inter_spiral_interval=photostim_groups[0][
"rois"
][2]["scanfields"]["duration"],
),
spiral_duration=photostim_groups[0]["rois"][1][
"scanfields"
]["duration"],
inter_spiral_interval=photostim_groups[0][
"rois"
][2]["scanfields"]["duration"],
),
],
inter_trial_interval=(
self.job_settings.photo_stim_inter_trial_interval
),
),
],
inter_trial_interval=(photostim_interval),
)
],
stimulus_start_time=(
self.job_settings.stimulus_start_time
),
stimulus_end_time=self.job_settings.stimulus_end_time,
)
],
mouse_platform_name=self.job_settings.mouse_platform_name,
active_mouse_platform=self.job_settings.active_mouse_platform,
)

def run_job(self) -> JobResponse:
Expand Down
13 changes: 7 additions & 6 deletions src/aind_metadata_mapper/ephys/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,6 @@ def _transform(self, extracted_source: ParsedInformation) -> Session:
session_stream["stream_end_time"] = datetime.strptime(
stage[-1][0], "%Y/%m/%d %H:%M:%S.%f"
)
session_stream["mouse_platform_name"] = data_stream[
"mouse_platform_name"
]
session_stream["active_mouse_platform"] = data_stream[
"active_mouse_platform"
]
session_stream["stream_modalities"] = [Modality.ECEPHYS]
session_stream["stick_microscopes"] = stick_microscopes
session_stream["camera_names"] = camera_names
Expand All @@ -134,6 +128,13 @@ def _transform(self, extracted_source: ParsedInformation) -> Session:

ephys_session["data_streams"].append(session_stream)

ephys_session["mouse_platform_name"] = data_stream[
"mouse_platform_name"
]
ephys_session["active_mouse_platform"] = data_stream[
"active_mouse_platform"
]

end_times = [
datetime.strptime(x[-1][0], "%Y/%m/%d %H:%M:%S.%f")
for x in stage_logs
Expand Down
34 changes: 22 additions & 12 deletions src/aind_metadata_mapper/fib/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@
FiberConnectionConfig,
LightEmittingDiodeConfig,
Session,
StimulusEpoch,
StimulusModality,
Stream,
)
from aind_data_schema.models.modalities import Modality
from aind_data_schema.models.stimulus import (
OptoStimulation,
PulseShape,
StimulusEpoch,
)
from aind_data_schema.models.stimulus import OptoStimulation, PulseShape
from pydantic import Field
from pydantic_settings import BaseSettings

Expand Down Expand Up @@ -148,10 +146,18 @@ def _transform(self, extracted_source: ParsedMetadata) -> Session:
opto_stim = OptoStimulation(
stimulus_name=stimulus_name,
pulse_shape=PulseShape.SQUARE,
pulse_frequency=frequency,
number_pulse_trains=trial_num,
pulse_width=pulse_width,
pulse_train_duration=opto_duration,
pulse_frequency=[
frequency,
],
number_pulse_trains=[
trial_num,
],
pulse_width=[
pulse_width,
],
pulse_train_duration=[
opto_duration,
],
pulse_train_interval=opto_interval,
baseline_duration=opto_base,
fixed_pulse_train_interval=True, # TODO: Check this is right
Expand All @@ -165,7 +171,11 @@ def _transform(self, extracted_source: ParsedMetadata) -> Session:
seconds=experiment_duration
)
stimulus_epochs = StimulusEpoch(
stimulus=opto_stim,
stimulus_name=stimulus_name,
stimulus_modalities=[StimulusModality.OPTOGENETICS],
stimulus_parameters=[
opto_stim,
],
stimulus_start_time=session_start_time,
stimulus_end_time=end_datetime,
)
Expand Down Expand Up @@ -193,8 +203,6 @@ def _transform(self, extracted_source: ParsedMetadata) -> Session:
stream_end_time=end_datetime,
light_sources=light_source,
stream_modalities=[Modality.FIB],
mouse_platform_name=mouse_platform_name,
active_mouse_platform=active_mouse_platform,
detectors=detectors,
fiber_connections=fiber_connections,
)
Expand All @@ -211,6 +219,8 @@ def _transform(self, extracted_source: ParsedMetadata) -> Session:
session_type=session_type,
notes=notes,
data_streams=data_stream,
mouse_platform_name=mouse_platform_name,
active_mouse_platform=active_mouse_platform,
)

return ophys_session
Expand Down
14 changes: 5 additions & 9 deletions src/aind_metadata_mapper/mesoscope/session.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Mesoscope ETL"""

import argparse
import json
import sys
Expand Down Expand Up @@ -99,7 +100,8 @@ def _extract(self) -> dict:
behavior_source = self.job_settings.behavior_source
session_metadata = {}
if behavior_source.is_dir():
for ftype in behavior_source.glob("*json"):
# deterministic order
for ftype in sorted(list(behavior_source.glob("*json"))):
if (
"Behavior" in ftype.stem
or "Eye" in ftype.stem
Expand Down Expand Up @@ -167,8 +169,6 @@ def _transform(self, extracted_source: dict) -> Session:
stream_start_time=self.job_settings.session_start_time,
stream_end_time=self.job_settings.session_end_time,
ophys_fovs=fovs,
mouse_platform_name=self.job_settings.mouse_platform_name,
active_mouse_platform=True,
stream_modalities=[Modality.POPHYS],
)
)
Expand All @@ -188,10 +188,6 @@ def _transform(self, extracted_source: dict) -> Session:
camera_names=[camera_name],
stream_start_time=start_time,
stream_end_time=end_time,
mouse_platform_name=(
self.job_settings.mouse_platform_name
),
active_mouse_platform=True,
stream_modalities=[Modality.BEHAVIOR_VIDEOS],
)
)
Expand All @@ -216,8 +212,6 @@ def _transform(self, extracted_source: dict) -> Session:
camera_names=["Vasculature"],
stream_start_time=vasculature_dt,
stream_end_time=vasculature_dt,
mouse_platform_name=self.job_settings.mouse_platform_name,
active_mouse_platform=True,
stream_modalities=[
Modality.CONFOCAL
], # TODO: ask Saskia about this
Expand All @@ -232,6 +226,8 @@ def _transform(self, extracted_source: dict) -> Session:
session_end_time=self.job_settings.session_end_time,
rig_id=extracted_source["platform"]["rig_id"],
data_streams=data_streams,
mouse_platform_name=self.job_settings.mouse_platform_name,
active_mouse_platform=True,
)

def run_job(self) -> None:
Expand Down
Loading
Loading