-
Notifications
You must be signed in to change notification settings - Fork 0
Feat metadata mapping #63
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
base: main
Are you sure you want to change the base?
Changes from 24 commits
eba6406
441ad11
a32a842
3fef59b
062b917
6d0f998
6dbe0f0
91febd4
79dc6f9
9e03163
963292f
062aa2f
1f5a2fc
ba96b5f
2f0a446
382ae85
f160fbd
f1fff6d
f7502b1
37f9c84
690982d
c9ee84a
e68fe44
a107aa8
6ef9ed3
0a7e2f4
2c411f9
96ea485
4a305d1
80080af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| from pathlib import Path | ||
|
|
||
| from aind_behavior_curriculum import TrainerState | ||
| from aind_behavior_curriculum import Metrics, TrainerState | ||
| from aind_behavior_services.session import Session | ||
| from contraqctor.contract import Dataset, DataStreamCollection | ||
| from contraqctor.contract.camera import Camera | ||
|
|
@@ -61,10 +61,18 @@ def make_dataset( | |
| data_streams=[ | ||
| Json( | ||
| name="PreviousMetrics", | ||
| reader_params=Json.make_params( | ||
| reader_params=PydanticModel.make_params( | ||
| model=Metrics, | ||
|
Comment on lines
61
to
+65
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is fine (and even a good practice.) However, keep in mind this requires you not to make breaking changes to the Metrics model. IF you break it, the contract will not be backwards compatible anymore. |
||
| path=root_path / "behavior/previous_metrics.json", | ||
| ), | ||
| ), | ||
| PydanticModel( | ||
| name="Metrics", | ||
| reader_params=PydanticModel.make_params( | ||
| model=Metrics, | ||
| path=root_path / "behavior/metrics.json", | ||
| ), | ||
| ), | ||
| PydanticModel( | ||
| name="TrainerState", | ||
| reader_params=PydanticModel.make_params( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import os | ||
| from typing import Optional | ||
|
|
||
| from aind_behavior_dynamic_foraging.data_contract import dataset | ||
| from aind_behavior_dynamic_foraging.task_logic import AindDynamicForagingTaskLogic | ||
|
|
||
|
|
||
| def calculate_consumed_water(session_path: os.PathLike) -> Optional[float]: | ||
| """Calculate the total volume of water consumed during a session. | ||
|
|
||
| Args: | ||
| session_path (os.PathLike): Path to the session directory. | ||
|
|
||
| Returns: | ||
| Optional[float]: Total volume of water consumed in milliliters, or None if unavailable. | ||
| """ | ||
|
|
||
| trial_outcomes = dataset(session_path)["Behavior"]["SoftwareEvents"]["TrialOutcome"].load().data["data"] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can validate this with the TrialOutcome pydantic class to make your life easier |
||
| is_right_choice = [to["is_right_choice"] for to in trial_outcomes] | ||
| is_rewarded = [to["is_rewarded"] for to in trial_outcomes] | ||
|
|
||
| task_logic_data = dataset(session_path)["Behavior"]["InputSchemas"]["TaskLogic"].load().data | ||
| task_logic = AindDynamicForagingTaskLogic.model_validate(task_logic_data) | ||
| right_reward_size = task_logic.task_parameters.reward_size.right_value_volume | ||
| left_reward_size = task_logic.task_parameters.reward_size.left_value_volume | ||
|
|
||
| total = 0 | ||
| for choice, rewarded in zip(is_right_choice, is_rewarded): | ||
| if rewarded: | ||
| if choice is True: | ||
| total += right_reward_size * 1e-3 | ||
| if choice is False: | ||
| total += left_reward_size * 1e-3 | ||
| return total | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the #noqa?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm remembering correctly, it was because I was failing the linting tests since the imports weren't grouped at the top of the file and I had to set up logging before importing the trail generators