From 01926df4bba1c98005726d521c5971efb0239664 Mon Sep 17 00:00:00 2001 From: arjunsridhar12345 Date: Tue, 7 Jul 2026 23:29:06 -0700 Subject: [PATCH 1/4] refactor: update references to is_auto_reward_right --- .../processing/_trial_table.py | 22 +++++++++---------- .../utils/rewards.py | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/dynamic_foraging_processing/processing/_trial_table.py b/src/dynamic_foraging_processing/processing/_trial_table.py index 7dcd4b5..b83fb63 100644 --- a/src/dynamic_foraging_processing/processing/_trial_table.py +++ b/src/dynamic_foraging_processing/processing/_trial_table.py @@ -327,7 +327,7 @@ def _is_baited(trial: t.Optional[Trial], *, is_right: bool) -> bool: probability is ``1``) *and* the trial was not auto-responded to *that same* port. - ``is_auto_response_right`` encodes the auto-response: ``True`` means the + ``is_auto_reward_right`` encodes the auto-response: ``True`` means the trial was auto-responded to the right, ``False`` to the left, and ``None`` means there was no auto-response. @@ -335,10 +335,10 @@ def _is_baited(trial: t.Optional[Trial], *, is_right: bool) -> bool: * ``p_reward_right == 1`` — reward is certain on the right, and * the trial was *not* auto-responded to the right - (``is_auto_response_right`` is ``None`` or ``False``). + (``is_auto_reward_right`` is ``None`` or ``False``). The left port is the mirror image (``p_reward_left == 1`` and not - auto-responded to the left, i.e. ``is_auto_response_right`` is ``None`` + auto-responded to the left, i.e. ``is_auto_reward_right`` is ``None`` or ``True``). Parameters @@ -358,25 +358,25 @@ def _is_baited(trial: t.Optional[Trial], *, is_right: bool) -> bool: -------- Right port guaranteed reward, no auto-response → baited: - >>> trial = Trial(p_reward_right=1, p_reward_left=0, is_auto_response_right=None) + >>> trial = Trial(p_reward_right=1, p_reward_left=0, is_auto_reward_right=None) >>> TrialTableBuilder._is_baited(trial, is_right=True) True Same trial, but auto-responded to the right collects (forfeits) the bait: - >>> trial = Trial(p_reward_right=1, p_reward_left=0, is_auto_response_right=True) + >>> trial = Trial(p_reward_right=1, p_reward_left=0, is_auto_reward_right=True) >>> TrialTableBuilder._is_baited(trial, is_right=True) False Left port without guaranteed reward → not baited: - >>> trial = Trial(p_reward_right=1, p_reward_left=0, is_auto_response_right=None) + >>> trial = Trial(p_reward_right=1, p_reward_left=0, is_auto_reward_right=None) >>> TrialTableBuilder._is_baited(trial, is_right=False) False """ if trial is None: return False - auto = trial.is_auto_response_right + auto = trial.is_auto_reward_right if is_right: # Right stays baited unless the animal was auto-responded right. return trial.p_reward_right == 1 and auto in (None, False) @@ -385,16 +385,16 @@ def _is_baited(trial: t.Optional[Trial], *, is_right: bool) -> bool: @staticmethod def _auto_water(trial: t.Optional[Trial], *, is_right: bool) -> int: - """Encode autowater for a side from ``is_auto_response_right``. + """Encode autowater for a side from ``is_auto_reward_right``. Returns ``1`` if the auto response was to the requested side, else ``0``. - A missing trial or no auto-response (``is_auto_response_right`` is + A missing trial or no auto-response (``is_auto_reward_right`` is ``None``) counts as no autowater (``0``). ``is_right`` is ``True`` for right. """ - if trial is None or trial.is_auto_response_right is None: + if trial is None or trial.is_auto_reward_right is None: return 0 - return int(trial.is_auto_response_right is is_right) + return int(trial.is_auto_reward_right is is_right) @staticmethod def _block_reward_probability(trial: t.Optional[Trial], *, is_right: bool) -> t.Optional[float]: diff --git a/src/dynamic_foraging_processing/utils/rewards.py b/src/dynamic_foraging_processing/utils/rewards.py index e31d0fc..068a144 100644 --- a/src/dynamic_foraging_processing/utils/rewards.py +++ b/src/dynamic_foraging_processing/utils/rewards.py @@ -46,7 +46,7 @@ def get_annotated_rewards( timestamps are correlated to the reward-delivery timestamps with :func:`find_closest_timestamps`. - ``automatic`` -- otherwise, when the matching trial auto-responded - (``is_auto_response_right is not None``). + (``is_auto_reward_right is not None``). - ``earned`` -- otherwise (no matching trial, or no auto-response). Parameters @@ -80,7 +80,7 @@ def get_annotated_rewards( for trial_index in trial_indices_in_reward_times: outcome = _parse_outcome(trial_outcome_df.iloc[trial_index]["data"]) trial = outcome.trial if outcome is not None else None - if trial is None or trial.is_auto_response_right is None: + if trial is None or trial.is_auto_reward_right is None: annotated_rewards.append("earned") else: annotated_rewards.append("automatic") From 8180683c59ee125d1601140e31f43dcdf655810e Mon Sep 17 00:00:00 2001 From: arjunsridhar12345 Date: Tue, 7 Jul 2026 23:29:19 -0700 Subject: [PATCH 2/4] test: update tests --- tests/test_nwb/test_acquisition/test_acquisition_builder.py | 2 +- tests/test_processing/test_trial_table.py | 2 +- tests/test_utils/test_rewards.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_nwb/test_acquisition/test_acquisition_builder.py b/tests/test_nwb/test_acquisition/test_acquisition_builder.py index 29d9b1c..3ee8c05 100644 --- a/tests/test_nwb/test_acquisition/test_acquisition_builder.py +++ b/tests/test_nwb/test_acquisition/test_acquisition_builder.py @@ -67,7 +67,7 @@ def _outcome_payload(auto) -> dict: "reward_consumption_duration": 1.0, "quiescence_period_duration": 0.5, "inter_trial_interval_duration": 4.0, - "is_auto_response_right": auto, + "is_auto_reward_right": auto, }, "is_right_choice": True, "is_rewarded": True, diff --git a/tests/test_processing/test_trial_table.py b/tests/test_processing/test_trial_table.py index 7246427..e4b91a6 100644 --- a/tests/test_processing/test_trial_table.py +++ b/tests/test_processing/test_trial_table.py @@ -104,7 +104,7 @@ def _outcome( "reward_consumption_duration": 1.0, "quiescence_period_duration": 0.5, "inter_trial_interval_duration": 4.0, - "is_auto_response_right": auto, + "is_auto_reward_right": auto, } if block_p_left is not None or block_p_right is not None: trial["metadata"] = {"p_reward_left": block_p_left, "p_reward_right": block_p_right} diff --git a/tests/test_utils/test_rewards.py b/tests/test_utils/test_rewards.py index 0876946..3fcc4e0 100644 --- a/tests/test_utils/test_rewards.py +++ b/tests/test_utils/test_rewards.py @@ -19,7 +19,7 @@ def _outcome_payload(auto=None) -> dict: "reward_consumption_duration": 1.0, "quiescence_period_duration": 0.5, "inter_trial_interval_duration": 4.0, - "is_auto_response_right": auto, + "is_auto_reward_right": auto, }, "is_right_choice": True, "is_rewarded": True, @@ -46,7 +46,7 @@ def test_get_annotated_rewards_marks_default_trials_as_earned(): def test_get_annotated_rewards_marks_auto_response_trials_as_automatic(): - """Trials with ``is_auto_response_right`` set (either side) are ``automatic``.""" + """Trials with ``is_auto_reward_right`` set (either side) are ``automatic``.""" reward_times = np.array([0.15, 0.42]) trial_outcome_df = _trial_outcome_df(np.array([0.1, 0.4]), autos=[True, False]) From b22b64de5f7670648deead185035d8c68e9e0509 Mon Sep 17 00:00:00 2001 From: arjunsridhar12345 Date: Tue, 7 Jul 2026 23:29:34 -0700 Subject: [PATCH 3/4] build: update lock --- pyproject.toml | 2 +- uv.lock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 81203f7..343a81f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,7 +17,7 @@ readme = "README.md" version = "0.0.0" dependencies = [ - "aind-behavior-dynamic-foraging[data] @ git+https://github.com/AllenNeuralDynamics/Aind.Behavior.DynamicForaging.git@f517d14ff965763a8f713b8a1be5dfb26b9312e1", + "aind-behavior-dynamic-foraging[data] @ git+https://github.com/AllenNeuralDynamics/Aind.Behavior.DynamicForaging.git@baab12133b22f599c1ba0583260eca9eca216cc0", "ipykernel", ] diff --git a/uv.lock b/uv.lock index 3f9b950..80b09ce 100644 --- a/uv.lock +++ b/uv.lock @@ -39,7 +39,7 @@ wheels = [ [[package]] name = "aind-behavior-dynamic-foraging" version = "0.0.2" -source = { git = "https://github.com/AllenNeuralDynamics/Aind.Behavior.DynamicForaging.git?rev=f517d14ff965763a8f713b8a1be5dfb26b9312e1#f517d14ff965763a8f713b8a1be5dfb26b9312e1" } +source = { git = "https://github.com/AllenNeuralDynamics/Aind.Behavior.DynamicForaging.git?rev=baab12133b22f599c1ba0583260eca9eca216cc0#baab12133b22f599c1ba0583260eca9eca216cc0" } dependencies = [ { name = "aind-behavior-services" }, { name = "pydantic-settings" }, @@ -570,7 +570,7 @@ dev = [ [package.metadata] requires-dist = [ - { name = "aind-behavior-dynamic-foraging", extras = ["data"], git = "https://github.com/AllenNeuralDynamics/Aind.Behavior.DynamicForaging.git?rev=f517d14ff965763a8f713b8a1be5dfb26b9312e1" }, + { name = "aind-behavior-dynamic-foraging", extras = ["data"], git = "https://github.com/AllenNeuralDynamics/Aind.Behavior.DynamicForaging.git?rev=baab12133b22f599c1ba0583260eca9eca216cc0" }, { name = "aind-data-schema", marker = "extra == 'qc'", specifier = ">=2.4.1" }, { name = "dynamic-foraging-processing", extras = ["qc"], marker = "extra == 'full'" }, { name = "ipykernel" }, From 45897f3fb28a20c7c37240e7b1aea26555ca6886 Mon Sep 17 00:00:00 2001 From: arjunsridhar12345 Date: Tue, 7 Jul 2026 23:29:48 -0700 Subject: [PATCH 4/4] docs: update docs to reflect reference --- docs/trials_table_mapping.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/trials_table_mapping.md b/docs/trials_table_mapping.md index f1b3d30..d53a059 100644 --- a/docs/trials_table_mapping.md +++ b/docs/trials_table_mapping.md @@ -71,13 +71,13 @@ Columns are grouped by the raw source they map from. ### From `TrialOutcome.json` (`SoftwareEvents` stream) -> **Note:** For `is_auto_response_right`, `True` means right and `False` +> **Note:** For `is_auto_reward_right`, `True` means right and `False` > means left. | Trials column | Mapping | | --- | --- | -| `auto_waterL` / `auto_waterR` | From `is_auto_response_right`. `1` on the auto-responded side; `0` on the other side, when there was no auto-response (`None`), or when the trial is missing. | -| `bait_left` / `bait_right` | Boolean. `bait_right` is `True` if `p_reward_right == 1` and `is_auto_response_right` is `None` or `False`. `bait_left` is `True` if `p_reward_left == 1` and `is_auto_response_right` is `None` or `True`. | +| `auto_waterL` / `auto_waterR` | From `is_auto_reward_right`. `1` on the auto-responded side; `0` on the other side, when there was no auto-response (`None`), or when the trial is missing. | +| `bait_left` / `bait_right` | Boolean. `bait_right` is `True` if `p_reward_right == 1` and `is_auto_reward_right` is `None` or `False`. `bait_left` is `True` if `p_reward_left == 1` and `is_auto_reward_right` is `None` or `True`. | | `response_duration` | `response_deadline_duration`. | | `reward_consumption_duration` | `Trial -> reward_consumption_duration`. | | `reward_probabilityL` / `reward_probabilityR` | The **block** probability from `Trial -> metadata -> p_reward_left` / `p_reward_right`. The top-level `trial.p_reward_left` / `p_reward_right` is the per-trial probability, not the block probability, so it is not used here. `None` when the trial or its metadata is missing. | @@ -152,6 +152,6 @@ These were mapped during exploration but are no longer in scope: | Date | Change | | --- | --- | | 2026-06-17 | `animal_response` now decodes the `Response` event's `{ "Item1":