Skip to content

Commit

Permalink
Bug/pull behavior items (#200)
Browse files Browse the repository at this point in the history
* Option to add stim table to modality formatted files.

* Opt. to write stim table to modality directory and compute fps from behavior sessions.
  • Loading branch information
arielleleon authored Nov 19, 2024
1 parent 9e56ddd commit ddec95f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
3 changes: 3 additions & 0 deletions src/aind_metadata_mapper/mesoscope/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class JobSettings(BaseJobSettings):
input_source: Path = Field(..., title="Path to the input source")
session_id: str = Field(..., title="ID of the session")
behavior_source: Path = Field(..., title="Path to the behavior source")
make_camsitm_dir: bool = Field(
default=False, title="Make camsitm directory"
)
output_directory: Path = Field(..., title="Path to the output directory")
session_start_time: datetime = Field(
..., title="Start time of the session"
Expand Down
8 changes: 7 additions & 1 deletion src/aind_metadata_mapper/mesoscope/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,16 @@ def __init__(self, job_settings: Union[JobSettings, str]):
job_settings_model.behavior_source = Path(
job_settings_model.behavior_source
)
camstim_output = job_settings_model.output_directory
if job_settings_model.make_camsitm_dir:
camstim_output = (
job_settings_model.output_directory
/ f"{job_settings_model.session_id}_behavior"
)
super().__init__(job_settings=job_settings_model)
camstim_settings = CamstimSettings(
input_source=self.job_settings.input_source,
output_directory=self.job_settings.output_directory,
output_directory=camstim_output,
session_id=self.job_settings.session_id,
subject_id=self.job_settings.subject_id,
)
Expand Down
8 changes: 7 additions & 1 deletion src/aind_metadata_mapper/open_ephys/utils/pkl_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,13 @@ def get_fps(pkl):
fps.
"""
return pkl["fps"]
if not pkl.get("fps"):
fps = round(
1 / np.mean(pkl["items"]["behavior"]["intervalsms"]) * 0.001, 2
)
else:
fps = pkl["fps"]
return fps


def get_pre_blank_sec(pkl):
Expand Down
11 changes: 4 additions & 7 deletions src/aind_metadata_mapper/stimulus/camstim.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,12 @@ def __init__(
self.input_source = Path(self.camstim_settings.input_source)
session_id = self.camstim_settings.session_id
self.pkl_path = next(self.input_source.rglob("*.pkl"))
if not self.camstim_settings.output_directory.is_dir():
self.camstim_settings.output_directory.mkdir(parents=True)
self.stim_table_path = (
self.pkl_path.parent / f"{session_id}_stim_table.csv"
self.camstim_settings.output_directory
/ f"{session_id}_stim_table.csv"
)
if self.camstim_settings.output_directory:
self.stim_table_path = (
self.camstim_settings.output_directory
/ f"{session_id}_behavior"
/ f"{session_id}_stim_table.csv"
)
self.pkl_data = pkl.load_pkl(self.pkl_path)
self.fps = pkl.get_fps(self.pkl_data)
self.session_start, self.session_end = self._get_sync_times()
Expand Down

0 comments on commit ddec95f

Please sign in to comment.