From a0af1e59f86ddd987d6b73085ade223a77525c64 Mon Sep 17 00:00:00 2001 From: bruno-f-cruz <7049351+bruno-f-cruz@users.noreply.github.com> Date: Wed, 5 Jun 2024 10:44:52 -0700 Subject: [PATCH 01/19] Linting --- docs/conf.py | 4 +++- examples/examples.py | 5 ++++- scripts/regenerate.py | 6 +++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index e071d2b2..7a84d43d 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -5,12 +5,12 @@ import os import sys + import aind_behavior_vr_foraging.rig import aind_behavior_vr_foraging.task_logic import erdantic as erd from pydantic import BaseModel - sys.path.insert(0, os.path.abspath("../src/DataSchemas")) import aind_behavior_vr_foraging @@ -69,6 +69,7 @@ # -- Options for linkcode extension --------------------------------------- + def linkcode_resolve(domain, info): if domain != "py": return None @@ -80,6 +81,7 @@ def linkcode_resolve(domain, info): # -- Class diagram generation + def export_model_diagram(model: BaseModel, root: str = "_static") -> None: diagram = erd.create(model) diagram.draw(f"{root}/{model.__name__}.svg") diff --git a/examples/examples.py b/examples/examples.py index 61429da0..aeec6941 100644 --- a/examples/examples.py +++ b/examples/examples.py @@ -19,7 +19,10 @@ ) from aind_behavior_services.session import AindBehaviorSessionModel from aind_behavior_vr_foraging.rig import AindVrForagingRig, RigCalibration, Treadmill -from aind_behavior_vr_foraging.task_logic import AindVrForagingTaskLogic, AindVrForagingTaskParameters +from aind_behavior_vr_foraging.task_logic import ( + AindVrForagingTaskLogic, + AindVrForagingTaskParameters, +) def main(): diff --git a/scripts/regenerate.py b/scripts/regenerate.py index cf9eaa7c..20ddc6b6 100644 --- a/scripts/regenerate.py +++ b/scripts/regenerate.py @@ -4,7 +4,11 @@ import aind_behavior_vr_foraging.rig import aind_behavior_vr_foraging.task_logic from aind_behavior_services.session import AindBehaviorSessionModel -from aind_behavior_services.utils import convert_pydantic_to_bonsai, pascal_to_snake_case, snake_to_pascal_case +from aind_behavior_services.utils import ( + convert_pydantic_to_bonsai, + pascal_to_snake_case, + snake_to_pascal_case, +) SCHEMA_ROOT = Path("./src/DataSchemas/") EXTENSIONS_ROOT = Path("./src/Extensions/") From 30f804746fe30ad2bc756222040d6b0aafa32280 Mon Sep 17 00:00:00 2001 From: bruno-f-cruz <7049351+bruno-f-cruz@users.noreply.github.com> Date: Wed, 5 Jun 2024 20:06:26 -0700 Subject: [PATCH 02/19] Bump services to support x-enumNames --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index bfe4a56c..ccd68027 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,7 @@ readme = "README.md" dynamic = ["version"] dependencies = [ - "aind_behavior_services@git+https://github.com/AllenNeuralDynamics/Aind.Behavior.Services@0.7.5", + "aind_behavior_services@git+https://github.com/AllenNeuralDynamics/Aind.Behavior.Services@0.7.6", ] [project.optional-dependencies] From 8355136880518dcb0724f94031e9a4d88e6ffaee Mon Sep 17 00:00:00 2001 From: bruno-f-cruz <7049351+bruno-f-cruz@users.noreply.github.com> Date: Wed, 5 Jun 2024 20:06:48 -0700 Subject: [PATCH 03/19] Add friction to schema --- src/DataSchemas/aind_behavior_vr_foraging/task_logic.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/DataSchemas/aind_behavior_vr_foraging/task_logic.py b/src/DataSchemas/aind_behavior_vr_foraging/task_logic.py index 18f0d925..8dedf460 100644 --- a/src/DataSchemas/aind_behavior_vr_foraging/task_logic.py +++ b/src/DataSchemas/aind_behavior_vr_foraging/task_logic.py @@ -196,6 +196,10 @@ class VirtualSiteGeneration(BaseModel): ) +class TreadmillSpecification(BaseModel): + friction: Optional[float] = Field(default=0, le=1, ge=0, description="Friction of the treadmill (0-1)") + + class VirtualSite(BaseModel): id: int = Field(default=0, ge=0, description="Id of the virtual site") label: VirtualSiteLabels = Field(default=VirtualSiteLabels.UNSPECIFIED, description="Label of the virtual site") @@ -210,6 +214,9 @@ class VirtualSite(BaseModel): render_specification: RenderSpecification = Field( default=RenderSpecification(), description="The optional render specification of the virtual site" ) + treadmill_specification: Optional[TreadmillSpecification] = Field( + default=None, description="Treadmill specification" + ) class PatchStatistics(BaseModel): From 4f7b99a63bbdf685f498fe5615b36c384832531e Mon Sep 17 00:00:00 2001 From: bruno-f-cruz <7049351+bruno-f-cruz@users.noreply.github.com> Date: Wed, 5 Jun 2024 20:07:07 -0700 Subject: [PATCH 04/19] Externalize friction from CreateSite --- src/Extensions/CreateSite.bonsai | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Extensions/CreateSite.bonsai b/src/Extensions/CreateSite.bonsai index c31881f8..14749d65 100644 --- a/src/Extensions/CreateSite.bonsai +++ b/src/Extensions/CreateSite.bonsai @@ -1,5 +1,5 @@  - + CreateSite @@ -31,11 +32,11 @@ + 353 - RewardSite 35.1602135 0 From d8cd5db92d398a57cf2cc27dbd4414ac908b718d Mon Sep 17 00:00:00 2001 From: bruno-f-cruz <7049351+bruno-f-cruz@users.noreply.github.com> Date: Wed, 5 Jun 2024 20:07:50 -0700 Subject: [PATCH 05/19] Regenerate schema --- .../aind_vr_foraging_task_logic.json | 33 +++++++ src/Extensions/AindVrForagingTaskLogic.cs | 96 ++++++++++++++++++- 2 files changed, 128 insertions(+), 1 deletion(-) diff --git a/src/DataSchemas/aind_vr_foraging_task_logic.json b/src/DataSchemas/aind_vr_foraging_task_logic.json index d85ec69d..3f7544ed 100644 --- a/src/DataSchemas/aind_vr_foraging_task_logic.json +++ b/src/DataSchemas/aind_vr_foraging_task_logic.json @@ -1697,6 +1697,27 @@ "title": "Texture", "type": "object" }, + "TreadmillSpecification": { + "properties": { + "friction": { + "default": 0, + "description": "Friction of the treadmill (0-1)", + "oneOf": [ + { + "maximum": 1.0, + "minimum": 0.0, + "type": "number" + }, + { + "type": "null" + } + ], + "title": "Friction" + } + }, + "title": "TreadmillSpecification", + "type": "object" + }, "TruncationParameters": { "properties": { "is_truncated": { @@ -1883,6 +1904,18 @@ "contrast": null }, "description": "The optional render specification of the virtual site" + }, + "treadmill_specification": { + "default": null, + "description": "Treadmill specification", + "oneOf": [ + { + "$ref": "#/definitions/TreadmillSpecification" + }, + { + "type": "null" + } + ] } }, "title": "VirtualSite", diff --git a/src/Extensions/AindVrForagingTaskLogic.cs b/src/Extensions/AindVrForagingTaskLogic.cs index 8d70f3ec..05fc8a05 100644 --- a/src/Extensions/AindVrForagingTaskLogic.cs +++ b/src/Extensions/AindVrForagingTaskLogic.cs @@ -4579,6 +4579,72 @@ public override string ToString() } + [System.CodeDom.Compiler.GeneratedCodeAttribute("Bonsai.Sgen", "0.3.0.0 (Newtonsoft.Json v13.0.0.0)")] + [Bonsai.CombinatorAttribute()] + [Bonsai.WorkflowElementCategoryAttribute(Bonsai.ElementCategory.Source)] + public partial class TreadmillSpecification + { + + private double? _friction; + + public TreadmillSpecification() + { + } + + protected TreadmillSpecification(TreadmillSpecification other) + { + _friction = other._friction; + } + + /// + /// Friction of the treadmill (0-1) + /// + [System.Xml.Serialization.XmlIgnoreAttribute()] + [Newtonsoft.Json.JsonPropertyAttribute("friction")] + [System.ComponentModel.DescriptionAttribute("Friction of the treadmill (0-1)")] + public double? Friction + { + get + { + return _friction; + } + set + { + _friction = value; + } + } + + public System.IObservable Process() + { + return System.Reactive.Linq.Observable.Defer(() => System.Reactive.Linq.Observable.Return(new TreadmillSpecification(this))); + } + + public System.IObservable Process(System.IObservable source) + { + return System.Reactive.Linq.Observable.Select(source, _ => new TreadmillSpecification(this)); + } + + protected virtual bool PrintMembers(System.Text.StringBuilder stringBuilder) + { + stringBuilder.Append("friction = " + _friction); + return true; + } + + public override string ToString() + { + System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder(); + stringBuilder.Append(GetType().Name); + stringBuilder.Append(" { "); + if (PrintMembers(stringBuilder)) + { + stringBuilder.Append(" "); + } + stringBuilder.Append("}"); + return stringBuilder.ToString(); + } + } + + [System.CodeDom.Compiler.GeneratedCodeAttribute("Bonsai.Sgen", "0.3.0.0 (Newtonsoft.Json v13.0.0.0)")] [Bonsai.CombinatorAttribute()] [Bonsai.WorkflowElementCategoryAttribute(Bonsai.ElementCategory.Source)] @@ -5018,6 +5084,8 @@ public partial class VirtualSite private RenderSpecification _renderSpecification; + private TreadmillSpecification _treadmillSpecification; + public VirtualSite() { } @@ -5031,6 +5099,7 @@ protected VirtualSite(VirtualSite other) _odorSpecification = other._odorSpecification; _rewardSpecification = other._rewardSpecification; _renderSpecification = other._renderSpecification; + _treadmillSpecification = other._treadmillSpecification; } /// @@ -5156,6 +5225,24 @@ public RenderSpecification RenderSpecification } } + /// + /// Treadmill specification + /// + [System.Xml.Serialization.XmlIgnoreAttribute()] + [Newtonsoft.Json.JsonPropertyAttribute("treadmill_specification")] + [System.ComponentModel.DescriptionAttribute("Treadmill specification")] + public TreadmillSpecification TreadmillSpecification + { + get + { + return _treadmillSpecification; + } + set + { + _treadmillSpecification = value; + } + } + public System.IObservable Process() { return System.Reactive.Linq.Observable.Defer(() => System.Reactive.Linq.Observable.Return(new VirtualSite(this))); @@ -5174,7 +5261,8 @@ protected virtual bool PrintMembers(System.Text.StringBuilder stringBuilder) stringBuilder.Append("start_position = " + _startPosition + ", "); stringBuilder.Append("odor_specification = " + _odorSpecification + ", "); stringBuilder.Append("reward_specification = " + _rewardSpecification + ", "); - stringBuilder.Append("render_specification = " + _renderSpecification); + stringBuilder.Append("render_specification = " + _renderSpecification + ", "); + stringBuilder.Append("treadmill_specification = " + _treadmillSpecification); return true; } @@ -6462,6 +6550,11 @@ public System.IObservable Process(System.IObservable source) return Process(source); } + public System.IObservable Process(System.IObservable source) + { + return Process(source); + } + public System.IObservable Process(System.IObservable source) { return Process(source); @@ -6576,6 +6669,7 @@ public System.IObservable Process(System.IObservable [System.Xml.Serialization.XmlIncludeAttribute(typeof(Bonsai.Expressions.TypeMapping))] [System.Xml.Serialization.XmlIncludeAttribute(typeof(Bonsai.Expressions.TypeMapping))] [System.Xml.Serialization.XmlIncludeAttribute(typeof(Bonsai.Expressions.TypeMapping))] + [System.Xml.Serialization.XmlIncludeAttribute(typeof(Bonsai.Expressions.TypeMapping))] [System.Xml.Serialization.XmlIncludeAttribute(typeof(Bonsai.Expressions.TypeMapping))] [System.Xml.Serialization.XmlIncludeAttribute(typeof(Bonsai.Expressions.TypeMapping))] [System.Xml.Serialization.XmlIncludeAttribute(typeof(Bonsai.Expressions.TypeMapping))] From 4e6ed637388aac19e794d614f3926e4f1e3ac6c4 Mon Sep 17 00:00:00 2001 From: bruno-f-cruz <7049351+bruno-f-cruz@users.noreply.github.com> Date: Thu, 6 Jun 2024 16:37:08 -0700 Subject: [PATCH 06/19] Bump Services --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index ccd68027..e0fb1137 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,7 @@ readme = "README.md" dynamic = ["version"] dependencies = [ - "aind_behavior_services@git+https://github.com/AllenNeuralDynamics/Aind.Behavior.Services@0.7.6", + "aind_behavior_services@git+https://github.com/AllenNeuralDynamics/Aind.Behavior.Services@0.7.7", ] [project.optional-dependencies] From ee7b8a8f9a1dbd0cec362808ef590ba65dcfdf4e Mon Sep 17 00:00:00 2001 From: bruno-f-cruz <7049351+bruno-f-cruz@users.noreply.github.com> Date: Tue, 11 Jun 2024 08:36:01 -0700 Subject: [PATCH 07/19] Update Aind.Core.Design package --- bonsai/Bonsai.config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bonsai/Bonsai.config b/bonsai/Bonsai.config index 5122b570..ac974c66 100644 --- a/bonsai/Bonsai.config +++ b/bonsai/Bonsai.config @@ -5,7 +5,7 @@ - + @@ -115,7 +115,7 @@ - + From 8b02799d9125cc0b6d89a5d21eb317d18e6cfe15 Mon Sep 17 00:00:00 2001 From: bruno-f-cruz <7049351+bruno-f-cruz@users.noreply.github.com> Date: Thu, 13 Jun 2024 11:59:39 -0700 Subject: [PATCH 08/19] Update Aind core dependency --- bonsai/Bonsai.config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bonsai/Bonsai.config b/bonsai/Bonsai.config index ac974c66..b4f3c468 100644 --- a/bonsai/Bonsai.config +++ b/bonsai/Bonsai.config @@ -4,7 +4,7 @@ - + @@ -114,7 +114,7 @@ - + From fbb64ecba89e95db25f55f4f8f669f8a3694143c Mon Sep 17 00:00:00 2001 From: bruno-f-cruz <7049351+bruno-f-cruz@users.noreply.github.com> Date: Thu, 13 Jun 2024 13:08:25 -0700 Subject: [PATCH 09/19] Improve visualizer UI layout --- src/vr-foraging.bonsai | 279 +++++++++++++++++++++-------------------- 1 file changed, 142 insertions(+), 137 deletions(-) diff --git a/src/vr-foraging.bonsai b/src/vr-foraging.bonsai index 09452b23..c0541121 100644 --- a/src/vr-foraging.bonsai +++ b/src/vr-foraging.bonsai @@ -680,6 +680,8 @@ 19000 0 1 + + Mono8 @@ -9755,6 +9757,127 @@ Item2 as Start EnableExperimentUI + + LauncherControl + + + + + + + Annotations + + + + + + ExperimentState + + + + + + + + + Start + true + true + Start Experiment + + + StartExperimentToggleButton + + + + + + End + true + true + End Experiment + + + EndExperimentButton + + + + + + LauncherControl + true + true + Microsoft Sans Serif, 26pt + 2 + 2 + + + + + + + + + + + StartExperimentToggleButton + + + + 1 + + + + + StartExperimentShortcut + + + EndExperimentButton + + + + 1 + + + + + EndExperiment + + + StartExperiment + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ValveGui @@ -10082,7 +10205,7 @@ Item2 as Start TriggerAudio true true - + TriggerAudio @@ -10110,7 +10233,7 @@ Item2 as Start ForceReward true true - Force Reward + ForceReward ForceReward @@ -10122,8 +10245,9 @@ Item2 as Start HwShortcuts true true - 2 - 1 + Microsoft Sans Serif, 20pt + 5 + 5 @@ -10186,126 +10310,6 @@ Item2 as Start - - LauncherControl - - - - - - - Annotations - - - - - - ExperimentState - - - - - - - - - Start - true - true - Start Experiment - - - StartExperimentToggleButton - - - - - - End - true - true - End Experiment - - - EndExperimentButton - - - - - - LauncherControl - true - true - 2 - 2 - - - - - - - - - - - StartExperimentToggleButton - - - - 1 - - - - - StartExperimentShortcut - - - EndExperimentButton - - - - 1 - - - - - EndExperiment - - - StartExperiment - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - OperationControl @@ -10507,17 +10511,20 @@ Item2 as Start LickometerUI true true - 2 - 3 + 1 + 2 - - - - - - - - + + + Percent + 0.3 + + + Percent + 0.7 + + + @@ -10993,7 +11000,6 @@ Item2 as Start - QC @@ -11047,8 +11053,7 @@ Item2 as TotalReward) - - + From 10b8e8810f248b0f1732955bfd413957f6a5e2cd Mon Sep 17 00:00:00 2001 From: bruno-f-cruz <7049351+bruno-f-cruz@users.noreply.github.com> Date: Thu, 13 Jun 2024 13:15:06 -0700 Subject: [PATCH 10/19] Fix site generation defaults --- .../aind_behavior_vr_foraging/task_logic.py | 12 ++++++++---- .../aind_vr_foraging_task_logic.json | 18 +++++++++--------- src/Extensions/AindVrForagingTaskLogic.cs | 4 ++-- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/DataSchemas/aind_behavior_vr_foraging/task_logic.py b/src/DataSchemas/aind_behavior_vr_foraging/task_logic.py index 8dedf460..320ac139 100644 --- a/src/DataSchemas/aind_behavior_vr_foraging/task_logic.py +++ b/src/DataSchemas/aind_behavior_vr_foraging/task_logic.py @@ -183,16 +183,20 @@ class VirtualSiteGenerator(BaseModel): class VirtualSiteGeneration(BaseModel): inter_site: VirtualSiteGenerator = Field( - default=VirtualSiteGenerator(), description="Generator of the inter-site virtual sites" + default=VirtualSiteGenerator(label=VirtualSiteLabels.INTERSITE), + description="Generator of the inter-site virtual sites", ) inter_patch: VirtualSiteGenerator = Field( - default=VirtualSiteGenerator(), description="Generator of the inter-patch virtual sites" + default=VirtualSiteGenerator(label=VirtualSiteLabels.INTERPATCH), + description="Generator of the inter-patch virtual sites", ) post_patch: VirtualSiteGenerator = Field( - default=VirtualSiteGenerator(), description="Generator of the post-inter-patch virtual sites" + default=VirtualSiteGenerator(label=VirtualSiteLabels.POSTPATCH), + description="Generator of the post-patch virtual sites", ) reward_site: VirtualSiteGenerator = Field( - default=VirtualSiteGenerator(), description="Generator of the reward-site virtual sites" + default=VirtualSiteGenerator(label=VirtualSiteLabels.REWARDSITE), + description="Generator of the reward-site virtual sites", ) diff --git a/src/DataSchemas/aind_vr_foraging_task_logic.json b/src/DataSchemas/aind_vr_foraging_task_logic.json index 3f7544ed..1d903c26 100644 --- a/src/DataSchemas/aind_vr_foraging_task_logic.json +++ b/src/DataSchemas/aind_vr_foraging_task_logic.json @@ -1159,7 +1159,7 @@ ], "default": { "inter_site": { - "label": "Unspecified", + "label": "InterSite", "length_distribution": { "distribution_parameters": { "family": "Scalar", @@ -1176,7 +1176,7 @@ } }, "inter_patch": { - "label": "Unspecified", + "label": "InterPatch", "length_distribution": { "distribution_parameters": { "family": "Scalar", @@ -1193,7 +1193,7 @@ } }, "post_patch": { - "label": "Unspecified", + "label": "PostPatch", "length_distribution": { "distribution_parameters": { "family": "Scalar", @@ -1210,7 +1210,7 @@ } }, "reward_site": { - "label": "Unspecified", + "label": "RewardSite", "length_distribution": { "distribution_parameters": { "family": "Scalar", @@ -1933,7 +1933,7 @@ "render_specification": { "contrast": null }, - "label": "Unspecified", + "label": "InterSite", "length_distribution": { "distribution_parameters": { "family": "Scalar", @@ -1958,7 +1958,7 @@ "render_specification": { "contrast": null }, - "label": "Unspecified", + "label": "InterPatch", "length_distribution": { "distribution_parameters": { "family": "Scalar", @@ -1983,7 +1983,7 @@ "render_specification": { "contrast": null }, - "label": "Unspecified", + "label": "PostPatch", "length_distribution": { "distribution_parameters": { "family": "Scalar", @@ -1996,7 +1996,7 @@ "truncation_parameters": null } }, - "description": "Generator of the post-inter-patch virtual sites" + "description": "Generator of the post-patch virtual sites" }, "reward_site": { "allOf": [ @@ -2008,7 +2008,7 @@ "render_specification": { "contrast": null }, - "label": "Unspecified", + "label": "RewardSite", "length_distribution": { "distribution_parameters": { "family": "Scalar", diff --git a/src/Extensions/AindVrForagingTaskLogic.cs b/src/Extensions/AindVrForagingTaskLogic.cs index 05fc8a05..20fe1b43 100644 --- a/src/Extensions/AindVrForagingTaskLogic.cs +++ b/src/Extensions/AindVrForagingTaskLogic.cs @@ -5344,11 +5344,11 @@ public VirtualSiteGenerator InterPatch } /// - /// Generator of the post-inter-patch virtual sites + /// Generator of the post-patch virtual sites /// [System.Xml.Serialization.XmlIgnoreAttribute()] [Newtonsoft.Json.JsonPropertyAttribute("post_patch")] - [System.ComponentModel.DescriptionAttribute("Generator of the post-inter-patch virtual sites")] + [System.ComponentModel.DescriptionAttribute("Generator of the post-patch virtual sites")] public VirtualSiteGenerator PostPatch { get From 83a0176bab9bd0ffa99a29b7e266e2fd674b5508 Mon Sep 17 00:00:00 2001 From: bruno-f-cruz <7049351+bruno-f-cruz@users.noreply.github.com> Date: Thu, 13 Jun 2024 13:26:20 -0700 Subject: [PATCH 11/19] Remove support for treadmill from Harp.Behavior board --- .../aind_behavior_vr_foraging/rig.py | 19 +- src/DataSchemas/aind_vr_foraging_rig.json | 117 ++--- src/Extensions/AindVrForagingRig.cs | 444 ++++++------------ src/vr-foraging.bonsai | 319 +++---------- 4 files changed, 254 insertions(+), 645 deletions(-) diff --git a/src/DataSchemas/aind_behavior_vr_foraging/rig.py b/src/DataSchemas/aind_behavior_vr_foraging/rig.py index f9908896..0a7dab95 100644 --- a/src/DataSchemas/aind_behavior_vr_foraging/rig.py +++ b/src/DataSchemas/aind_behavior_vr_foraging/rig.py @@ -2,26 +2,21 @@ from __future__ import annotations # Import core types -from typing import Annotated, Literal, Optional, Union +from typing import Literal, Optional import aind_behavior_services.calibration.olfactometer as oc import aind_behavior_services.calibration.water_valve as wvc import aind_behavior_services.rig as rig from aind_behavior_services.rig import AindBehaviorRigModel -from pydantic import BaseModel, Field, RootModel +from pydantic import BaseModel, Field __version__ = "0.3.0" -TreadmillSettings = rig.Treadmill - -class TreadmillBoard(RootModel): - root: Annotated[Union[rig.HarpTreadmill, rig.HarpBehavior], Field(discriminator="who_am_i")] - - -class Treadmill(BaseModel): - harp_board: TreadmillBoard = Field(..., description="The board to be used as a treadmill input") - settings: rig.Treadmill = Field(default=rig.Treadmill(), description="Treadmill settings") +class HarpTreadmill(rig.HarpTreadmill): + calibration: rig.Treadmill = Field( + rig.Treadmill(), description="Treadmill calibration settings", validate_default=True + ) class RigCalibration(BaseModel): @@ -42,7 +37,7 @@ class AindVrForagingRig(AindBehaviorRigModel): harp_lickometer: rig.HarpLickometer = Field(..., description="Harp lickometer") harp_clock_generator: rig.HarpClockGenerator = Field(..., description="Harp clock generator") harp_analog_input: Optional[rig.HarpAnalogInput] = Field(default=None, description="Harp analog input") - treadmill: Treadmill = Field(..., description="Treadmill settings") + harp_treadmill: HarpTreadmill = Field(..., description="Harp treadmill") harp_sniff_detector: Optional[rig.HarpSniffDetector] = Field(None, description="Sniff detector settings") screen: rig.Screen = Field(default=rig.Screen(), description="Screen settings") calibration: RigCalibration = Field(..., description="Calibration models") diff --git a/src/DataSchemas/aind_vr_foraging_rig.json b/src/DataSchemas/aind_vr_foraging_rig.json index ca393411..1ab1977a 100644 --- a/src/DataSchemas/aind_vr_foraging_rig.json +++ b/src/DataSchemas/aind_vr_foraging_rig.json @@ -526,16 +526,17 @@ ] }, "calibration": { - "default": null, - "description": "Calibration", - "oneOf": [ - { - "$ref": "#/definitions/BaseModel" - }, + "allOf": [ { - "type": "null" + "$ref": "#/definitions/Treadmill" } - ] + ], + "default": { + "wheel_diameter": 15.0, + "pulses_per_revolution": 28800, + "invert_direction": false + }, + "description": "Treadmill calibration settings" }, "who_am_i": { "const": 1402, @@ -963,23 +964,31 @@ "title": "SpinnakerCamera", "type": "object" }, - "TreadmillBoard": { - "discriminator": { - "mapping": { - "1216": "#/definitions/HarpBehavior", - "1402": "#/definitions/HarpTreadmill" + "Treadmill": { + "properties": { + "wheel_diameter": { + "default": 15, + "description": "Wheel diameter", + "minimum": 0.0, + "title": "Wheel Diameter", + "type": "number" }, - "propertyName": "who_am_i" - }, - "oneOf": [ - { - "$ref": "#/definitions/HarpTreadmill" + "pulses_per_revolution": { + "default": 28800, + "description": "Pulses per revolution", + "minimum": 1, + "title": "Pulses Per Revolution", + "type": "integer" }, - { - "$ref": "#/definitions/HarpBehavior" + "invert_direction": { + "default": false, + "description": "Invert direction", + "title": "Invert Direction", + "type": "boolean" } - ], - "title": "TreadmillBoard" + }, + "title": "Treadmill", + "type": "object" }, "VideoWriter": { "discriminator": { @@ -1266,62 +1275,6 @@ }, "title": "WebCamera", "type": "object" - }, - "aind_behavior_services__rig__Treadmill": { - "properties": { - "wheel_diameter": { - "default": 15, - "description": "Wheel diameter", - "minimum": 0.0, - "title": "Wheel Diameter", - "type": "number" - }, - "pulses_per_revolution": { - "default": 28800, - "description": "Pulses per revolution", - "minimum": 1, - "title": "Pulses Per Revolution", - "type": "integer" - }, - "invert_direction": { - "default": false, - "description": "Invert direction", - "title": "Invert Direction", - "type": "boolean" - } - }, - "title": "Treadmill", - "type": "object" - }, - "aind_behavior_vr_foraging__rig__Treadmill": { - "properties": { - "harp_board": { - "allOf": [ - { - "$ref": "#/definitions/TreadmillBoard" - } - ], - "description": "The board to be used as a treadmill input" - }, - "settings": { - "allOf": [ - { - "$ref": "#/definitions/aind_behavior_services__rig__Treadmill" - } - ], - "default": { - "wheel_diameter": 15.0, - "pulses_per_revolution": 28800, - "invert_direction": false - }, - "description": "Treadmill settings" - } - }, - "required": [ - "harp_board" - ], - "title": "Treadmill", - "type": "object" } }, "properties": { @@ -1405,13 +1358,13 @@ } ] }, - "treadmill": { + "harp_treadmill": { "allOf": [ { - "$ref": "#/definitions/aind_behavior_vr_foraging__rig__Treadmill" + "$ref": "#/definitions/HarpTreadmill" } ], - "description": "Treadmill settings" + "description": "Harp treadmill" }, "harp_sniff_detector": { "default": null, @@ -1461,7 +1414,7 @@ "harp_olfactometer", "harp_lickometer", "harp_clock_generator", - "treadmill", + "harp_treadmill", "calibration" ], "title": "AindVrForagingRig", diff --git a/src/Extensions/AindVrForagingRig.cs b/src/Extensions/AindVrForagingRig.cs index b1982eba..0d7a3d4b 100644 --- a/src/Extensions/AindVrForagingRig.cs +++ b/src/Extensions/AindVrForagingRig.cs @@ -518,7 +518,7 @@ public override string ToString() [System.CodeDom.Compiler.GeneratedCodeAttribute("Bonsai.Sgen", "0.3.0.0 (Newtonsoft.Json v13.0.0.0)")] [Bonsai.CombinatorAttribute()] [Bonsai.WorkflowElementCategoryAttribute(Bonsai.ElementCategory.Source)] - public partial class HarpBehavior : TreadmillBoard + public partial class HarpBehavior { private string _deviceType = "behavior"; @@ -527,6 +527,8 @@ public partial class HarpBehavior : TreadmillBoard private BaseModel _calibration; + private int _whoAmI = 1216; + private string _serialNumber; private string _portName; @@ -535,12 +537,12 @@ public HarpBehavior() { } - protected HarpBehavior(HarpBehavior other) : - base(other) + protected HarpBehavior(HarpBehavior other) { _deviceType = other._deviceType; _additionalSettings = other._additionalSettings; _calibration = other._calibration; + _whoAmI = other._whoAmI; _serialNumber = other._serialNumber; _portName = other._portName; } @@ -594,6 +596,19 @@ public BaseModel Calibration } } + [Newtonsoft.Json.JsonPropertyAttribute("who_am_i")] + public int WhoAmI + { + get + { + return _whoAmI; + } + set + { + _whoAmI = value; + } + } + /// /// Device serial number /// @@ -638,19 +653,29 @@ public System.IObservable Process(System.IObservable new HarpBehavior(this)); } - protected override bool PrintMembers(System.Text.StringBuilder stringBuilder) + protected virtual bool PrintMembers(System.Text.StringBuilder stringBuilder) { - if (base.PrintMembers(stringBuilder)) - { - stringBuilder.Append(", "); - } stringBuilder.Append("device_type = " + _deviceType + ", "); stringBuilder.Append("additional_settings = " + _additionalSettings + ", "); stringBuilder.Append("calibration = " + _calibration + ", "); + stringBuilder.Append("who_am_i = " + _whoAmI + ", "); stringBuilder.Append("serial_number = " + _serialNumber + ", "); stringBuilder.Append("port_name = " + _portName); return true; } + + public override string ToString() + { + System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder(); + stringBuilder.Append(GetType().Name); + stringBuilder.Append(" { "); + if (PrintMembers(stringBuilder)) + { + stringBuilder.Append(" "); + } + stringBuilder.Append("}"); + return stringBuilder.ToString(); + } } @@ -1313,14 +1338,16 @@ public override string ToString() [System.CodeDom.Compiler.GeneratedCodeAttribute("Bonsai.Sgen", "0.3.0.0 (Newtonsoft.Json v13.0.0.0)")] [Bonsai.CombinatorAttribute()] [Bonsai.WorkflowElementCategoryAttribute(Bonsai.ElementCategory.Source)] - public partial class HarpTreadmill : TreadmillBoard + public partial class HarpTreadmill { private string _deviceType = "treadmill"; private BaseModel _additionalSettings; - private BaseModel _calibration; + private Treadmill _calibration; + + private int _whoAmI = 1402; private string _serialNumber; @@ -1330,12 +1357,12 @@ public HarpTreadmill() { } - protected HarpTreadmill(HarpTreadmill other) : - base(other) + protected HarpTreadmill(HarpTreadmill other) { _deviceType = other._deviceType; _additionalSettings = other._additionalSettings; _calibration = other._calibration; + _whoAmI = other._whoAmI; _serialNumber = other._serialNumber; _portName = other._portName; } @@ -1372,12 +1399,12 @@ public BaseModel AdditionalSettings } /// - /// Calibration + /// Treadmill calibration settings /// [System.Xml.Serialization.XmlIgnoreAttribute()] [Newtonsoft.Json.JsonPropertyAttribute("calibration")] - [System.ComponentModel.DescriptionAttribute("Calibration")] - public BaseModel Calibration + [System.ComponentModel.DescriptionAttribute("Treadmill calibration settings")] + public Treadmill Calibration { get { @@ -1389,6 +1416,19 @@ public BaseModel Calibration } } + [Newtonsoft.Json.JsonPropertyAttribute("who_am_i")] + public int WhoAmI + { + get + { + return _whoAmI; + } + set + { + _whoAmI = value; + } + } + /// /// Device serial number /// @@ -1433,19 +1473,29 @@ public System.IObservable Process(System.IObservable new HarpTreadmill(this)); } - protected override bool PrintMembers(System.Text.StringBuilder stringBuilder) + protected virtual bool PrintMembers(System.Text.StringBuilder stringBuilder) { - if (base.PrintMembers(stringBuilder)) - { - stringBuilder.Append(", "); - } stringBuilder.Append("device_type = " + _deviceType + ", "); stringBuilder.Append("additional_settings = " + _additionalSettings + ", "); stringBuilder.Append("calibration = " + _calibration + ", "); + stringBuilder.Append("who_am_i = " + _whoAmI + ", "); stringBuilder.Append("serial_number = " + _serialNumber + ", "); stringBuilder.Append("port_name = " + _portName); return true; } + + public override string ToString() + { + System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder(); + stringBuilder.Append(GetType().Name); + stringBuilder.Append(" { "); + if (PrintMembers(stringBuilder)) + { + stringBuilder.Append(" "); + } + stringBuilder.Append("}"); + return stringBuilder.ToString(); + } } @@ -2596,35 +2646,95 @@ public override string ToString() [System.CodeDom.Compiler.GeneratedCodeAttribute("Bonsai.Sgen", "0.3.0.0 (Newtonsoft.Json v13.0.0.0)")] - [Newtonsoft.Json.JsonConverter(typeof(JsonInheritanceConverter), "who_am_i")] - [JsonInheritanceAttribute("1216", typeof(HarpBehavior))] - [JsonInheritanceAttribute("1402", typeof(HarpTreadmill))] [Bonsai.CombinatorAttribute()] [Bonsai.WorkflowElementCategoryAttribute(Bonsai.ElementCategory.Source)] - public partial class TreadmillBoard + public partial class Treadmill { - public TreadmillBoard() + private double _wheelDiameter = 15D; + + private int _pulsesPerRevolution = 28800; + + private bool _invertDirection = false; + + public Treadmill() { } - protected TreadmillBoard(TreadmillBoard other) + protected Treadmill(Treadmill other) { + _wheelDiameter = other._wheelDiameter; + _pulsesPerRevolution = other._pulsesPerRevolution; + _invertDirection = other._invertDirection; } - public System.IObservable Process() + /// + /// Wheel diameter + /// + [Newtonsoft.Json.JsonPropertyAttribute("wheel_diameter")] + [System.ComponentModel.DescriptionAttribute("Wheel diameter")] + public double WheelDiameter + { + get + { + return _wheelDiameter; + } + set + { + _wheelDiameter = value; + } + } + + /// + /// Pulses per revolution + /// + [Newtonsoft.Json.JsonPropertyAttribute("pulses_per_revolution")] + [System.ComponentModel.DescriptionAttribute("Pulses per revolution")] + public int PulsesPerRevolution + { + get + { + return _pulsesPerRevolution; + } + set + { + _pulsesPerRevolution = value; + } + } + + /// + /// Invert direction + /// + [Newtonsoft.Json.JsonPropertyAttribute("invert_direction")] + [System.ComponentModel.DescriptionAttribute("Invert direction")] + public bool InvertDirection + { + get + { + return _invertDirection; + } + set + { + _invertDirection = value; + } + } + + public System.IObservable Process() { - return System.Reactive.Linq.Observable.Defer(() => System.Reactive.Linq.Observable.Return(new TreadmillBoard(this))); + return System.Reactive.Linq.Observable.Defer(() => System.Reactive.Linq.Observable.Return(new Treadmill(this))); } - public System.IObservable Process(System.IObservable source) + public System.IObservable Process(System.IObservable source) { - return System.Reactive.Linq.Observable.Select(source, _ => new TreadmillBoard(this)); + return System.Reactive.Linq.Observable.Select(source, _ => new Treadmill(this)); } protected virtual bool PrintMembers(System.Text.StringBuilder stringBuilder) { - return false; + stringBuilder.Append("wheel_diameter = " + _wheelDiameter + ", "); + stringBuilder.Append("pulses_per_revolution = " + _pulsesPerRevolution + ", "); + stringBuilder.Append("invert_direction = " + _invertDirection); + return true; } public override string ToString() @@ -3419,201 +3529,6 @@ public override string ToString() } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Bonsai.Sgen", "0.3.0.0 (Newtonsoft.Json v13.0.0.0)")] - [Bonsai.CombinatorAttribute()] - [Bonsai.WorkflowElementCategoryAttribute(Bonsai.ElementCategory.Source)] - public partial class AindBehaviorServicesRigTreadmill - { - - private double _wheelDiameter = 15D; - - private int _pulsesPerRevolution = 28800; - - private bool _invertDirection = false; - - public AindBehaviorServicesRigTreadmill() - { - } - - protected AindBehaviorServicesRigTreadmill(AindBehaviorServicesRigTreadmill other) - { - _wheelDiameter = other._wheelDiameter; - _pulsesPerRevolution = other._pulsesPerRevolution; - _invertDirection = other._invertDirection; - } - - /// - /// Wheel diameter - /// - [Newtonsoft.Json.JsonPropertyAttribute("wheel_diameter")] - [System.ComponentModel.DescriptionAttribute("Wheel diameter")] - public double WheelDiameter - { - get - { - return _wheelDiameter; - } - set - { - _wheelDiameter = value; - } - } - - /// - /// Pulses per revolution - /// - [Newtonsoft.Json.JsonPropertyAttribute("pulses_per_revolution")] - [System.ComponentModel.DescriptionAttribute("Pulses per revolution")] - public int PulsesPerRevolution - { - get - { - return _pulsesPerRevolution; - } - set - { - _pulsesPerRevolution = value; - } - } - - /// - /// Invert direction - /// - [Newtonsoft.Json.JsonPropertyAttribute("invert_direction")] - [System.ComponentModel.DescriptionAttribute("Invert direction")] - public bool InvertDirection - { - get - { - return _invertDirection; - } - set - { - _invertDirection = value; - } - } - - public System.IObservable Process() - { - return System.Reactive.Linq.Observable.Defer(() => System.Reactive.Linq.Observable.Return(new AindBehaviorServicesRigTreadmill(this))); - } - - public System.IObservable Process(System.IObservable source) - { - return System.Reactive.Linq.Observable.Select(source, _ => new AindBehaviorServicesRigTreadmill(this)); - } - - protected virtual bool PrintMembers(System.Text.StringBuilder stringBuilder) - { - stringBuilder.Append("wheel_diameter = " + _wheelDiameter + ", "); - stringBuilder.Append("pulses_per_revolution = " + _pulsesPerRevolution + ", "); - stringBuilder.Append("invert_direction = " + _invertDirection); - return true; - } - - public override string ToString() - { - System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder(); - stringBuilder.Append(GetType().Name); - stringBuilder.Append(" { "); - if (PrintMembers(stringBuilder)) - { - stringBuilder.Append(" "); - } - stringBuilder.Append("}"); - return stringBuilder.ToString(); - } - } - - - [System.CodeDom.Compiler.GeneratedCodeAttribute("Bonsai.Sgen", "0.3.0.0 (Newtonsoft.Json v13.0.0.0)")] - [Bonsai.CombinatorAttribute()] - [Bonsai.WorkflowElementCategoryAttribute(Bonsai.ElementCategory.Source)] - public partial class AindBehaviorVrForagingRigTreadmill - { - - private TreadmillBoard _harpBoard; - - private AindBehaviorServicesRigTreadmill _settings; - - public AindBehaviorVrForagingRigTreadmill() - { - } - - protected AindBehaviorVrForagingRigTreadmill(AindBehaviorVrForagingRigTreadmill other) - { - _harpBoard = other._harpBoard; - _settings = other._settings; - } - - /// - /// The board to be used as a treadmill input - /// - [System.Xml.Serialization.XmlIgnoreAttribute()] - [Newtonsoft.Json.JsonPropertyAttribute("harp_board", Required=Newtonsoft.Json.Required.Always)] - [System.ComponentModel.DescriptionAttribute("The board to be used as a treadmill input")] - public TreadmillBoard HarpBoard - { - get - { - return _harpBoard; - } - set - { - _harpBoard = value; - } - } - - /// - /// Treadmill settings - /// - [System.Xml.Serialization.XmlIgnoreAttribute()] - [Newtonsoft.Json.JsonPropertyAttribute("settings")] - [System.ComponentModel.DescriptionAttribute("Treadmill settings")] - public AindBehaviorServicesRigTreadmill Settings - { - get - { - return _settings; - } - set - { - _settings = value; - } - } - - public System.IObservable Process() - { - return System.Reactive.Linq.Observable.Defer(() => System.Reactive.Linq.Observable.Return(new AindBehaviorVrForagingRigTreadmill(this))); - } - - public System.IObservable Process(System.IObservable source) - { - return System.Reactive.Linq.Observable.Select(source, _ => new AindBehaviorVrForagingRigTreadmill(this)); - } - - protected virtual bool PrintMembers(System.Text.StringBuilder stringBuilder) - { - stringBuilder.Append("harp_board = " + _harpBoard + ", "); - stringBuilder.Append("settings = " + _settings); - return true; - } - - public override string ToString() - { - System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder(); - stringBuilder.Append(GetType().Name); - stringBuilder.Append(" { "); - if (PrintMembers(stringBuilder)) - { - stringBuilder.Append(" "); - } - stringBuilder.Append("}"); - return stringBuilder.ToString(); - } - } - - [System.CodeDom.Compiler.GeneratedCodeAttribute("Bonsai.Sgen", "0.3.0.0 (Newtonsoft.Json v13.0.0.0)")] [Bonsai.CombinatorAttribute()] [Bonsai.WorkflowElementCategoryAttribute(Bonsai.ElementCategory.Source)] @@ -3640,7 +3555,7 @@ public partial class AindVrForagingRig private HarpAnalogInput _harpAnalogInput; - private AindBehaviorVrForagingRigTreadmill _treadmill = new AindBehaviorVrForagingRigTreadmill(); + private HarpTreadmill _harpTreadmill = new HarpTreadmill(); private HarpSniffDetector _harpSniffDetector; @@ -3664,7 +3579,7 @@ protected AindVrForagingRig(AindVrForagingRig other) _harpLickometer = other._harpLickometer; _harpClockGenerator = other._harpClockGenerator; _harpAnalogInput = other._harpAnalogInput; - _treadmill = other._treadmill; + _harpTreadmill = other._harpTreadmill; _harpSniffDetector = other._harpSniffDetector; _screen = other._screen; _calibration = other._calibration; @@ -3844,20 +3759,20 @@ public HarpAnalogInput HarpAnalogInput } /// - /// Treadmill settings + /// Harp treadmill /// [System.Xml.Serialization.XmlIgnoreAttribute()] - [Newtonsoft.Json.JsonPropertyAttribute("treadmill", Required=Newtonsoft.Json.Required.Always)] - [System.ComponentModel.DescriptionAttribute("Treadmill settings")] - public AindBehaviorVrForagingRigTreadmill Treadmill + [Newtonsoft.Json.JsonPropertyAttribute("harp_treadmill", Required=Newtonsoft.Json.Required.Always)] + [System.ComponentModel.DescriptionAttribute("Harp treadmill")] + public HarpTreadmill HarpTreadmill { get { - return _treadmill; + return _harpTreadmill; } set { - _treadmill = value; + _harpTreadmill = value; } } @@ -3937,7 +3852,7 @@ protected virtual bool PrintMembers(System.Text.StringBuilder stringBuilder) stringBuilder.Append("harp_lickometer = " + _harpLickometer + ", "); stringBuilder.Append("harp_clock_generator = " + _harpClockGenerator + ", "); stringBuilder.Append("harp_analog_input = " + _harpAnalogInput + ", "); - stringBuilder.Append("treadmill = " + _treadmill + ", "); + stringBuilder.Append("harp_treadmill = " + _harpTreadmill + ", "); stringBuilder.Append("harp_sniff_detector = " + _harpSniffDetector + ", "); stringBuilder.Append("screen = " + _screen + ", "); stringBuilder.Append("calibration = " + _calibration); @@ -4121,47 +4036,6 @@ private string GetSubtypeDiscriminator(System.Type objectType) } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Bonsai.Sgen", "0.3.0.0 (Newtonsoft.Json v13.0.0.0)")] - [System.ComponentModel.DefaultPropertyAttribute("Type")] - [Bonsai.WorkflowElementCategoryAttribute(Bonsai.ElementCategory.Combinator)] - [System.Xml.Serialization.XmlIncludeAttribute(typeof(Bonsai.Expressions.TypeMapping))] - [System.Xml.Serialization.XmlIncludeAttribute(typeof(Bonsai.Expressions.TypeMapping))] - public partial class MatchTreadmillBoard : Bonsai.Expressions.SingleArgumentExpressionBuilder - { - - public Bonsai.Expressions.TypeMapping Type { get; set; } - - public override System.Linq.Expressions.Expression Build(System.Collections.Generic.IEnumerable arguments) - { - var typeMapping = Type; - var returnType = typeMapping != null ? typeMapping.GetType().GetGenericArguments()[0] : typeof(TreadmillBoard); - return System.Linq.Expressions.Expression.Call( - typeof(MatchTreadmillBoard), - "Process", - new System.Type[] { returnType }, - System.Linq.Enumerable.Single(arguments)); - } - - - private static System.IObservable Process(System.IObservable source) - where TResult : TreadmillBoard - { - return System.Reactive.Linq.Observable.Create(observer => - { - var sourceObserver = System.Reactive.Observer.Create( - value => - { - var match = value as TResult; - if (match != null) observer.OnNext(match); - }, - observer.OnError, - observer.OnCompleted); - return System.ObservableExtensions.SubscribeSafe(source, sourceObserver); - }); - } - } - - [System.CodeDom.Compiler.GeneratedCodeAttribute("Bonsai.Sgen", "0.3.0.0 (Newtonsoft.Json v13.0.0.0)")] [System.ComponentModel.DefaultPropertyAttribute("Type")] [Bonsai.WorkflowElementCategoryAttribute(Bonsai.ElementCategory.Combinator)] @@ -4308,9 +4182,9 @@ public System.IObservable Process(System.IObservable so return Process(source); } - public System.IObservable Process(System.IObservable source) + public System.IObservable Process(System.IObservable source) { - return Process(source); + return Process(source); } public System.IObservable Process(System.IObservable source) @@ -4348,16 +4222,6 @@ public System.IObservable Process(System.IObservable source) return Process(source); } - public System.IObservable Process(System.IObservable source) - { - return Process(source); - } - - public System.IObservable Process(System.IObservable source) - { - return Process(source); - } - public System.IObservable Process(System.IObservable source) { return Process(source); @@ -4390,7 +4254,7 @@ public System.IObservable Process(System.IObservable [System.Xml.Serialization.XmlIncludeAttribute(typeof(Bonsai.Expressions.TypeMapping))] [System.Xml.Serialization.XmlIncludeAttribute(typeof(Bonsai.Expressions.TypeMapping))] [System.Xml.Serialization.XmlIncludeAttribute(typeof(Bonsai.Expressions.TypeMapping))] - [System.Xml.Serialization.XmlIncludeAttribute(typeof(Bonsai.Expressions.TypeMapping))] + [System.Xml.Serialization.XmlIncludeAttribute(typeof(Bonsai.Expressions.TypeMapping))] [System.Xml.Serialization.XmlIncludeAttribute(typeof(Bonsai.Expressions.TypeMapping))] [System.Xml.Serialization.XmlIncludeAttribute(typeof(Bonsai.Expressions.TypeMapping))] [System.Xml.Serialization.XmlIncludeAttribute(typeof(Bonsai.Expressions.TypeMapping))] @@ -4398,8 +4262,6 @@ public System.IObservable Process(System.IObservable [System.Xml.Serialization.XmlIncludeAttribute(typeof(Bonsai.Expressions.TypeMapping))] [System.Xml.Serialization.XmlIncludeAttribute(typeof(Bonsai.Expressions.TypeMapping))] [System.Xml.Serialization.XmlIncludeAttribute(typeof(Bonsai.Expressions.TypeMapping))] - [System.Xml.Serialization.XmlIncludeAttribute(typeof(Bonsai.Expressions.TypeMapping))] - [System.Xml.Serialization.XmlIncludeAttribute(typeof(Bonsai.Expressions.TypeMapping))] [System.Xml.Serialization.XmlIncludeAttribute(typeof(Bonsai.Expressions.TypeMapping))] public partial class DeserializeFromJson : Bonsai.Expressions.SingleArgumentExpressionBuilder { diff --git a/src/vr-foraging.bonsai b/src/vr-foraging.bonsai index c0541121..13f3fa60 100644 --- a/src/vr-foraging.bonsai +++ b/src/vr-foraging.bonsai @@ -410,14 +410,17 @@ RigSchema - HarpSniffDetector.PortName + HarpTreadmill + + + PortName - + COMx StartExperiment @@ -425,33 +428,14 @@ RigSchema - HarpSniffDetector - - - - - - - RigSchema - - - Treadmill - - - HarpBoard - - - - - - PortName + HarpSniffDetector.PortName - + COMx StartExperiment @@ -459,13 +443,7 @@ RigSchema - Treadmill - - - HarpBoard - - - + HarpSniffDetector @@ -510,29 +488,21 @@ - - + - - + + + - - + - + - + - - - - - - - @@ -7216,7 +7186,7 @@ Value as IsStopped) RigSchema - Treadmill.Settings + HarpTreadmill.Calibration WheelDiameter @@ -7225,12 +7195,6 @@ Value as IsStopped) Perimeter it * Math.Pi - - RigSchema - - - Treadmill.Settings - PulsesPerRevolution @@ -7241,12 +7205,6 @@ Value as IsStopped) CentimetersPerTick Item1 / Item2 - - RigSchema - - - Treadmill.Settings - InvertDirection @@ -7261,222 +7219,65 @@ Value as IsStopped) + + - - + + - - - + + + - - - - TreadmillScaling - - HarpTreadmill - - - - HarpTreadmillEvents - - - - - - - 1 - - - - - - - CalculateDisplacement - (Item1.Value.Encoder - Item2.Value.Encoder) - - - TreadmillScaling - - - - - - - - - 0 - 1 - 0 - -0.005752427954571154 - Linear - - - - Item1.Seconds - - - - - - - - - - - - - - - - - - - - - - - - - - - RigSchema - - - Treadmill + HarpTreadmillEvents - - HarpBoard + + - - + + + 1 + - - + - - HarpBehavior - - - - HarpBehaviorHeartBeat - - - Set displacement mode - - - - Write - - 83 - U8 - 1 - - - - HarpBehaviorCommands - - - Write - - EncoderPort2 - - - - - 1 - - - - HarpBehaviorCommands - - - HarpBehaviorEvents - - - - - - Value.Encoder,Seconds - - - Item1 - - - TreadmillScaling - - - - - - - - - 0 - 1 - 0 - -0.005752427954571154 - Linear - - - - Item2 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + CalculateDisplacement + (Item1.Value.Encoder - Item2.Value.Encoder) - RigSchema + TreadmillScaling - - Treadmill + + + + - - HarpBoard + + + 0 + 1 + 0 + -0.005752427954571154 + Linear + - - + + Item1.Seconds - - + - + EncoderData @@ -7484,21 +7285,19 @@ Value as IsStopped) - + + - - - - - + + + + + + - - - - From 1f4fa7ed3741003d98d9c09b8967c70f2de6adc4 Mon Sep 17 00:00:00 2001 From: bruno-f-cruz <7049351+bruno-f-cruz@users.noreply.github.com> Date: Mon, 17 Jun 2024 15:40:13 -0700 Subject: [PATCH 12/19] Bump services package --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index e0fb1137..e0bb397e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,7 @@ readme = "README.md" dynamic = ["version"] dependencies = [ - "aind_behavior_services@git+https://github.com/AllenNeuralDynamics/Aind.Behavior.Services@0.7.7", + "aind_behavior_services@git+https://github.com/AllenNeuralDynamics/Aind.Behavior.Services@0.7.8", ] [project.optional-dependencies] From 575691085edf3e48893e40721c3774af5dbe7095 Mon Sep 17 00:00:00 2001 From: bruno-f-cruz <7049351+bruno-f-cruz@users.noreply.github.com> Date: Mon, 17 Jun 2024 15:40:45 -0700 Subject: [PATCH 13/19] Regenerate schema --- src/Extensions/AindVrForagingTaskLogic.cs | 41 +++++++++++++++++------ 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/src/Extensions/AindVrForagingTaskLogic.cs b/src/Extensions/AindVrForagingTaskLogic.cs index 20fe1b43..21383e23 100644 --- a/src/Extensions/AindVrForagingTaskLogic.cs +++ b/src/Extensions/AindVrForagingTaskLogic.cs @@ -5838,9 +5838,11 @@ public partial class AindVrForagingTaskLogic private string _description = ""; + private AindVrForagingTaskParameters _taskParameters = new AindVrForagingTaskParameters(); + private string _version = "0.4.0"; - private AindVrForagingTaskParameters _taskParameters = new AindVrForagingTaskParameters(); + private string _stageName; public AindVrForagingTaskLogic() { @@ -5850,8 +5852,9 @@ protected AindVrForagingTaskLogic(AindVrForagingTaskLogic other) { _name = other._name; _description = other._description; - _version = other._version; _taskParameters = other._taskParameters; + _version = other._version; + _stageName = other._stageName; } /// @@ -5888,6 +5891,24 @@ public string Description } } + /// + /// Parameters of the task logic + /// + [System.Xml.Serialization.XmlIgnoreAttribute()] + [Newtonsoft.Json.JsonPropertyAttribute("task_parameters", Required=Newtonsoft.Json.Required.Always)] + [System.ComponentModel.DescriptionAttribute("Parameters of the task logic")] + public AindVrForagingTaskParameters TaskParameters + { + get + { + return _taskParameters; + } + set + { + _taskParameters = value; + } + } + [Newtonsoft.Json.JsonPropertyAttribute("version")] public string Version { @@ -5902,20 +5923,19 @@ public string Version } /// - /// Parameters of the task logic + /// Optional stage name the `Task` object instance represents. /// - [System.Xml.Serialization.XmlIgnoreAttribute()] - [Newtonsoft.Json.JsonPropertyAttribute("task_parameters", Required=Newtonsoft.Json.Required.Always)] - [System.ComponentModel.DescriptionAttribute("Parameters of the task logic")] - public AindVrForagingTaskParameters TaskParameters + [Newtonsoft.Json.JsonPropertyAttribute("stage_name")] + [System.ComponentModel.DescriptionAttribute("Optional stage name the `Task` object instance represents.")] + public string StageName { get { - return _taskParameters; + return _stageName; } set { - _taskParameters = value; + _stageName = value; } } @@ -5933,8 +5953,9 @@ protected virtual bool PrintMembers(System.Text.StringBuilder stringBuilder) { stringBuilder.Append("name = " + _name + ", "); stringBuilder.Append("description = " + _description + ", "); + stringBuilder.Append("task_parameters = " + _taskParameters + ", "); stringBuilder.Append("version = " + _version + ", "); - stringBuilder.Append("task_parameters = " + _taskParameters); + stringBuilder.Append("stage_name = " + _stageName); return true; } From 2345d16741aa2723677acbe457374730dee2d7cd Mon Sep 17 00:00:00 2001 From: bruno-f-cruz <7049351+bruno-f-cruz@users.noreply.github.com> Date: Mon, 17 Jun 2024 17:07:38 -0700 Subject: [PATCH 14/19] Add operator to filter objects that contain a given property --- src/Extensions/AindVrForagingRigExtensions.cs | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/Extensions/AindVrForagingRigExtensions.cs diff --git a/src/Extensions/AindVrForagingRigExtensions.cs b/src/Extensions/AindVrForagingRigExtensions.cs new file mode 100644 index 00000000..2974b5ff --- /dev/null +++ b/src/Extensions/AindVrForagingRigExtensions.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Reactive.Linq; +using System.Reflection; +using Bonsai; + + +namespace AindVrForagingDataSchema.Rig{ + public static class Extensions{ + + internal static PropertyInfo[] GetProperties(object obj){ + return obj.GetType().GetProperties(); + } + + internal static PropertyInfo GetProperty(PropertyInfo property, string propertyName){ + return property.PropertyType.GetProperty(propertyName); + + } + + public static List EntriesWithProperty(object obj, string propertyName, bool includeNulls = false){ + var entries = new List(); + foreach (var objectProperty in GetProperties(obj)) + { + var prop = GetProperty(objectProperty, propertyName); + if (prop != null) + { + var value = objectProperty.GetValue(obj); + if (value != null || includeNulls) + { + entries.Add(objectProperty); + } + } + } + return entries; + } + } + + [WorkflowElementCategory(ElementCategory.Transform)] + public class ListObjectsWithProperty : Transform> + { + public string PropertyName { get; set; } + + public bool IncludeNulls { get; set; } + + public override IObservable> Process(IObservable source) + { + return source.Select(value => Extensions.EntriesWithProperty(value, PropertyName, IncludeNulls).ConvertAll(x => x.Name)); + } + } +} + From d00c6a34856437cd609c8cf5ed07c907af062c29 Mon Sep 17 00:00:00 2001 From: bruno-f-cruz <7049351+bruno-f-cruz@users.noreply.github.com> Date: Tue, 18 Jun 2024 08:59:26 -0700 Subject: [PATCH 15/19] Handle null PostPatch site specification --- .../aind_behavior_vr_foraging/task_logic.py | 12 ++- .../aind_vr_foraging_task_logic.json | 64 ++++++--------- src/vr-foraging.bonsai | 79 +++++++++++++++++-- 3 files changed, 104 insertions(+), 51 deletions(-) diff --git a/src/DataSchemas/aind_behavior_vr_foraging/task_logic.py b/src/DataSchemas/aind_behavior_vr_foraging/task_logic.py index 320ac139..68adb1dd 100644 --- a/src/DataSchemas/aind_behavior_vr_foraging/task_logic.py +++ b/src/DataSchemas/aind_behavior_vr_foraging/task_logic.py @@ -173,7 +173,7 @@ class RenderSpecification(BaseModel): class VirtualSiteGenerator(BaseModel): render_specification: RenderSpecification = Field( - default=RenderSpecification(), description="Contrast of the environment" + default=RenderSpecification(), description="Contrast of the environment", validate_default=True ) label: VirtualSiteLabels = Field(default=VirtualSiteLabels.UNSPECIFIED, description="Label of the virtual site") length_distribution: distributions.Distribution = Field( @@ -184,18 +184,22 @@ class VirtualSiteGenerator(BaseModel): class VirtualSiteGeneration(BaseModel): inter_site: VirtualSiteGenerator = Field( default=VirtualSiteGenerator(label=VirtualSiteLabels.INTERSITE), + validate_default=True, description="Generator of the inter-site virtual sites", ) inter_patch: VirtualSiteGenerator = Field( default=VirtualSiteGenerator(label=VirtualSiteLabels.INTERPATCH), + validate_default=True, description="Generator of the inter-patch virtual sites", ) - post_patch: VirtualSiteGenerator = Field( - default=VirtualSiteGenerator(label=VirtualSiteLabels.POSTPATCH), + post_patch: Optional[VirtualSiteGenerator] = Field( + default=None, + validate_default=True, description="Generator of the post-patch virtual sites", ) reward_site: VirtualSiteGenerator = Field( default=VirtualSiteGenerator(label=VirtualSiteLabels.REWARDSITE), + validate_default=True, description="Generator of the reward-site virtual sites", ) @@ -233,7 +237,7 @@ class PatchStatistics(BaseModel): default=None, description="The optional reward specification of the patch" ) virtual_site_generation: VirtualSiteGeneration = Field( - default=VirtualSiteGeneration(), description="Virtual site generation specification" + default=VirtualSiteGeneration(), validate_default=True, description="Virtual site generation specification" ) diff --git a/src/DataSchemas/aind_vr_foraging_task_logic.json b/src/DataSchemas/aind_vr_foraging_task_logic.json index 1d903c26..5e32f3c6 100644 --- a/src/DataSchemas/aind_vr_foraging_task_logic.json +++ b/src/DataSchemas/aind_vr_foraging_task_logic.json @@ -1192,23 +1192,7 @@ "contrast": null } }, - "post_patch": { - "label": "PostPatch", - "length_distribution": { - "distribution_parameters": { - "family": "Scalar", - "scaling_parameters": null, - "truncation_parameters": null, - "value": 20.0 - }, - "family": "Scalar", - "scaling_parameters": null, - "truncation_parameters": null - }, - "render_specification": { - "contrast": null - } - }, + "post_patch": null, "reward_site": { "label": "RewardSite", "length_distribution": { @@ -1974,29 +1958,16 @@ "description": "Generator of the inter-patch virtual sites" }, "post_patch": { - "allOf": [ + "default": null, + "description": "Generator of the post-patch virtual sites", + "oneOf": [ { "$ref": "#/definitions/VirtualSiteGenerator" - } - ], - "default": { - "render_specification": { - "contrast": null }, - "label": "PostPatch", - "length_distribution": { - "distribution_parameters": { - "family": "Scalar", - "scaling_parameters": null, - "truncation_parameters": null, - "value": 20.0 - }, - "family": "Scalar", - "scaling_parameters": null, - "truncation_parameters": null + { + "type": "null" } - }, - "description": "Generator of the post-patch virtual sites" + ] }, "reward_site": { "allOf": [ @@ -2192,19 +2163,32 @@ "title": "Description", "type": "string" }, + "task_parameters": { + "allOf": [ + { + "$ref": "#/definitions/AindVrForagingTaskParameters" + } + ], + "description": "Parameters of the task logic" + }, "version": { "const": "0.4.0", "default": "0.4.0", "title": "Version", "type": "string" }, - "task_parameters": { - "allOf": [ + "stage_name": { + "default": null, + "description": "Optional stage name the `Task` object instance represents.", + "oneOf": [ { - "$ref": "#/definitions/AindVrForagingTaskParameters" + "type": "string" + }, + { + "type": "null" } ], - "description": "Parameters of the task logic" + "title": "Stage Name" } }, "required": [ diff --git a/src/vr-foraging.bonsai b/src/vr-foraging.bonsai index 13f3fa60..0a4c1c51 100644 --- a/src/vr-foraging.bonsai +++ b/src/vr-foraging.bonsai @@ -8182,6 +8182,25 @@ Item2 as Start Foraging + + ActivePatch + + + VirtualSiteGeneration.PostPatch + + + IsNull + it == null + + + + + 1 + + + + HasPostPatch + PT0S @@ -8641,6 +8660,40 @@ Item2 as Start + + HasNotPostPatch + + + + HasPostPatch + + + + false + + + + + + + + + + + + HasPostPatch + + + + HasPostPatch + + + + + + + + ActivePatch @@ -8738,6 +8791,9 @@ Item2 as Start + + + @@ -8745,18 +8801,27 @@ Item2 as Start - + - - - - + + + - - + + + + + + + + + + + + From d67b9116aeaf28540f18bc1f7cdddd61e453ef38 Mon Sep 17 00:00:00 2001 From: bruno-f-cruz <7049351+bruno-f-cruz@users.noreply.github.com> Date: Tue, 18 Jun 2024 12:57:19 -0700 Subject: [PATCH 16/19] Change wheel friction on site instantiation --- src/Extensions/InstantiateSite.bonsai | 39 ++++++- src/vr-foraging.bonsai | 145 ++++++++++++++++++++++++-- 2 files changed, 172 insertions(+), 12 deletions(-) diff --git a/src/Extensions/InstantiateSite.bonsai b/src/Extensions/InstantiateSite.bonsai index 2f07e23f..fd0447cf 100644 --- a/src/Extensions/InstantiateSite.bonsai +++ b/src/Extensions/InstantiateSite.bonsai @@ -1,5 +1,5 @@  - WorldContrast + + ThisSiteSpecs + + + TreadmillSpecification + + + Friction + + + + + + Source1 + + + HasValue + + + + + + + + + + + Value + + + TreadmillFriction + @@ -1110,6 +1142,11 @@ it.Item2 as EntryPosition) + + + + + diff --git a/src/vr-foraging.bonsai b/src/vr-foraging.bonsai index 0a4c1c51..dcbf43a3 100644 --- a/src/vr-foraging.bonsai +++ b/src/vr-foraging.bonsai @@ -7175,9 +7175,22 @@ Value as IsStopped) - WheelEncoder + Treadmill + + + 0 + + + + + 1 + + + + TreadmillFriction + DetermineTreadmillScaling @@ -7282,22 +7295,132 @@ Value as IsStopped) EncoderData + + TreadmillFriction + + + + + + + + + + + 0 + 1 + 0 + 1 + Clamp + + + + Write + + + + SendMessage + + + + Source1 + + + + 1 + + + + HarpMessage + + + HarpTreadmillEvents + + + + + + HarpMessage + + + + + + + PT0.1S + PT0.1S + + + + HarpMessage + + + + + + Item2 + + + + + + HarpTreadmillCommands + + + + + + + 1 + + + + + + + + + + + + + + + + + + + + + + + + + - + - - - - + + - - - - - + + + + + + + + + + + + + + + From 9b83e27a5b631e2efee3aa5b91ece18d12a9b679 Mon Sep 17 00:00:00 2001 From: bruno-f-cruz <7049351+bruno-f-cruz@users.noreply.github.com> Date: Tue, 18 Jun 2024 14:38:45 -0700 Subject: [PATCH 17/19] Add linear interpolator for break calibration --- .../aind_behavior_vr_foraging/rig.py | 18 ++- src/DataSchemas/aind_vr_foraging_rig.json | 38 +++++- src/Extensions/AindVrForagingRig.cs | 25 +++- src/vr-foraging.bonsai | 129 ++++++++++-------- 4 files changed, 150 insertions(+), 60 deletions(-) diff --git a/src/DataSchemas/aind_behavior_vr_foraging/rig.py b/src/DataSchemas/aind_behavior_vr_foraging/rig.py index 0a7dab95..0fc00044 100644 --- a/src/DataSchemas/aind_behavior_vr_foraging/rig.py +++ b/src/DataSchemas/aind_behavior_vr_foraging/rig.py @@ -2,7 +2,7 @@ from __future__ import annotations # Import core types -from typing import Literal, Optional +from typing import Literal, Optional, Annotated, List import aind_behavior_services.calibration.olfactometer as oc import aind_behavior_services.calibration.water_valve as wvc @@ -13,9 +13,21 @@ __version__ = "0.3.0" +ValuePair = Annotated[ + List[float], + Field(min_length=2, max_length=2, description="A tuple of two values")] + + +class Treadmill(rig.Treadmill): + break_lookup_calibration: List[ValuePair] = Field( + default=[[0, 0], [1, 65535]], validate_default=True, min_length=2, min=0, + description="Break lookup calibration. Each Tuple is (0-1 (percent), 0-full-scale). \ + Values are linearly interpolated") + + class HarpTreadmill(rig.HarpTreadmill): - calibration: rig.Treadmill = Field( - rig.Treadmill(), description="Treadmill calibration settings", validate_default=True + calibration: Treadmill = Field( + Treadmill(), description="Treadmill calibration settings", validate_default=True ) diff --git a/src/DataSchemas/aind_vr_foraging_rig.json b/src/DataSchemas/aind_vr_foraging_rig.json index 1ab1977a..34f9666d 100644 --- a/src/DataSchemas/aind_vr_foraging_rig.json +++ b/src/DataSchemas/aind_vr_foraging_rig.json @@ -534,7 +534,17 @@ "default": { "wheel_diameter": 15.0, "pulses_per_revolution": 28800, - "invert_direction": false + "invert_direction": false, + "break_lookup_calibration": [ + [ + 0.0, + 0.0 + ], + [ + 1.0, + 65535.0 + ] + ] }, "description": "Treadmill calibration settings" }, @@ -985,6 +995,32 @@ "description": "Invert direction", "title": "Invert Direction", "type": "boolean" + }, + "break_lookup_calibration": { + "default": [ + [ + 0, + 0 + ], + [ + 1, + 65535 + ] + ], + "description": "Break lookup calibration. Each Tuple is (0-1 (percent), 0-full-scale). Values are linearly interpolated", + "items": { + "description": "A tuple of two values", + "items": { + "type": "number" + }, + "maxItems": 2, + "minItems": 2, + "type": "array" + }, + "min": 0, + "minItems": 2, + "title": "Break Lookup Calibration", + "type": "array" } }, "title": "Treadmill", diff --git a/src/Extensions/AindVrForagingRig.cs b/src/Extensions/AindVrForagingRig.cs index 0d7a3d4b..45ef878b 100644 --- a/src/Extensions/AindVrForagingRig.cs +++ b/src/Extensions/AindVrForagingRig.cs @@ -2657,6 +2657,8 @@ public partial class Treadmill private bool _invertDirection = false; + private System.Collections.Generic.List> _breakLookupCalibration = new System.Collections.Generic.List>(); + public Treadmill() { } @@ -2666,6 +2668,7 @@ protected Treadmill(Treadmill other) _wheelDiameter = other._wheelDiameter; _pulsesPerRevolution = other._pulsesPerRevolution; _invertDirection = other._invertDirection; + _breakLookupCalibration = other._breakLookupCalibration; } /// @@ -2719,6 +2722,25 @@ public bool InvertDirection } } + /// + /// Break lookup calibration. Each Tuple is (0-1 (percent), 0-full-scale). Values are linearly interpolated + /// + [System.Xml.Serialization.XmlIgnoreAttribute()] + [Newtonsoft.Json.JsonPropertyAttribute("break_lookup_calibration")] + [System.ComponentModel.DescriptionAttribute("Break lookup calibration. Each Tuple is (0-1 (percent), 0-full-scale). " + + " Values are linearly interpolated")] + public System.Collections.Generic.List> BreakLookupCalibration + { + get + { + return _breakLookupCalibration; + } + set + { + _breakLookupCalibration = value; + } + } + public System.IObservable Process() { return System.Reactive.Linq.Observable.Defer(() => System.Reactive.Linq.Observable.Return(new Treadmill(this))); @@ -2733,7 +2755,8 @@ protected virtual bool PrintMembers(System.Text.StringBuilder stringBuilder) { stringBuilder.Append("wheel_diameter = " + _wheelDiameter + ", "); stringBuilder.Append("pulses_per_revolution = " + _pulsesPerRevolution + ", "); - stringBuilder.Append("invert_direction = " + _invertDirection); + stringBuilder.Append("invert_direction = " + _invertDirection + ", "); + stringBuilder.Append("break_lookup_calibration = " + _breakLookupCalibration); return true; } diff --git a/src/vr-foraging.bonsai b/src/vr-foraging.bonsai index dcbf43a3..c8526396 100644 --- a/src/vr-foraging.bonsai +++ b/src/vr-foraging.bonsai @@ -30,10 +30,11 @@ xmlns:bv="clr-namespace:BonVision;assembly=BonVision" xmlns:p14="clr-namespace:AllenNeuralDynamics.LicketySplit;assembly=AllenNeuralDynamics.LicketySplit" xmlns:p15="clr-namespace:AllenNeuralDynamics.Treadmill;assembly=AllenNeuralDynamics.Treadmill" + xmlns:p16="clr-namespace:Bonsai.Numerics.Interpolation;assembly=Bonsai.Numerics" xmlns:gui="clr-namespace:Bonsai.Gui;assembly=Bonsai.Gui" xmlns:gli="clr-namespace:Bonsai.Shaders.Input;assembly=Bonsai.Shaders" - xmlns:p16="clr-namespace:Bonsai.Design;assembly=Bonsai.Design" - xmlns:p17="clr-namespace:Bonsai.Vision.Design;assembly=Bonsai.Vision.Design" + xmlns:p17="clr-namespace:Bonsai.Design;assembly=Bonsai.Design" + xmlns:p18="clr-namespace:Bonsai.Vision.Design;assembly=Bonsai.Vision.Design" xmlns:viz="clr-namespace:Bonsai.Design.Visualizers;assembly=Bonsai.Design.Visualizers" xmlns="https://bonsai-rx.org/2018/workflow"> @@ -7127,30 +7128,6 @@ Value as IsStopped) - - HarpBehaviorEvents - - - - - - Value.AnalogInput0 - - - Convert.ToUInt16(it) - - - Seconds - - - - - - - - - - ThermistorData @@ -7161,16 +7138,7 @@ Value as IsStopped) - - - - - - - - - - + @@ -7301,18 +7269,68 @@ Value as IsStopped) - - - + + GetInterpolator + + + + RigSchema + + + HarpTreadmill.Calibration + + + BreakLookupCalibration + + + + 0 + + + + + + + + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - 0 - 1 - 0 - 1 - Clamp - + Write @@ -7416,11 +7434,12 @@ Value as IsStopped) - - - + + + + @@ -10315,7 +10334,7 @@ Item2 as Start Item1,Item2 - + +Trigger @@ -10647,7 +10666,7 @@ Item2 as Start Value.Image - + TriggeredCamerasStream @@ -10669,7 +10688,7 @@ Item2 as Start Value.Image - + MonitoringCamerasStream @@ -10686,7 +10705,7 @@ Item2 as Start Value - + 3 @@ -10702,7 +10721,7 @@ Item2 as Start QCDiagnosis - + @@ -10721,7 +10740,7 @@ Item2 as Start - + LickometerState From 5ff8fb8d3c1c91d3da33de5a49402865a43529a5 Mon Sep 17 00:00:00 2001 From: bruno-f-cruz <7049351+bruno-f-cruz@users.noreply.github.com> Date: Tue, 18 Jun 2024 14:49:00 -0700 Subject: [PATCH 18/19] Clamp brake values to [0,1] --- src/vr-foraging.bonsai | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/vr-foraging.bonsai b/src/vr-foraging.bonsai index c8526396..62cb5610 100644 --- a/src/vr-foraging.bonsai +++ b/src/vr-foraging.bonsai @@ -7266,6 +7266,15 @@ Value as IsStopped) TreadmillFriction + + + 0 + 1 + 0 + 1 + Clamp + + @@ -7434,12 +7443,13 @@ Value as IsStopped) - - - - + + + + + From 1fc22370e597d49d1aefc04cd85aefd0f641eca7 Mon Sep 17 00:00:00 2001 From: bruno-f-cruz <7049351+bruno-f-cruz@users.noreply.github.com> Date: Tue, 18 Jun 2024 15:31:27 -0700 Subject: [PATCH 19/19] Allow brake friction to be defined as a distribution object --- .../aind_behavior_vr_foraging/rig.py | 18 +++++------ .../aind_behavior_vr_foraging/task_logic.py | 5 ++- .../aind_vr_foraging_task_logic.json | 11 +++---- src/Extensions/AindVrForagingTaskLogic.cs | 8 ++--- src/Extensions/InstantiateSite.bonsai | 32 ++++++++----------- 5 files changed, 34 insertions(+), 40 deletions(-) diff --git a/src/DataSchemas/aind_behavior_vr_foraging/rig.py b/src/DataSchemas/aind_behavior_vr_foraging/rig.py index 0fc00044..746c100b 100644 --- a/src/DataSchemas/aind_behavior_vr_foraging/rig.py +++ b/src/DataSchemas/aind_behavior_vr_foraging/rig.py @@ -2,7 +2,7 @@ from __future__ import annotations # Import core types -from typing import Literal, Optional, Annotated, List +from typing import Annotated, List, Literal, Optional import aind_behavior_services.calibration.olfactometer as oc import aind_behavior_services.calibration.water_valve as wvc @@ -13,22 +13,22 @@ __version__ = "0.3.0" -ValuePair = Annotated[ - List[float], - Field(min_length=2, max_length=2, description="A tuple of two values")] +ValuePair = Annotated[List[float], Field(min_length=2, max_length=2, description="A tuple of two values")] class Treadmill(rig.Treadmill): break_lookup_calibration: List[ValuePair] = Field( - default=[[0, 0], [1, 65535]], validate_default=True, min_length=2, min=0, + default=[[0, 0], [1, 65535]], + validate_default=True, + min_length=2, + min=0, description="Break lookup calibration. Each Tuple is (0-1 (percent), 0-full-scale). \ - Values are linearly interpolated") + Values are linearly interpolated", + ) class HarpTreadmill(rig.HarpTreadmill): - calibration: Treadmill = Field( - Treadmill(), description="Treadmill calibration settings", validate_default=True - ) + calibration: Treadmill = Field(Treadmill(), description="Treadmill calibration settings", validate_default=True) class RigCalibration(BaseModel): diff --git a/src/DataSchemas/aind_behavior_vr_foraging/task_logic.py b/src/DataSchemas/aind_behavior_vr_foraging/task_logic.py index 68adb1dd..3f011e3e 100644 --- a/src/DataSchemas/aind_behavior_vr_foraging/task_logic.py +++ b/src/DataSchemas/aind_behavior_vr_foraging/task_logic.py @@ -205,7 +205,10 @@ class VirtualSiteGeneration(BaseModel): class TreadmillSpecification(BaseModel): - friction: Optional[float] = Field(default=0, le=1, ge=0, description="Friction of the treadmill (0-1)") + friction: Optional[distributions.Distribution] = Field( + default=None, + description="Friction of the treadmill (0-1). The drawn value must be between 0 and 1", + ) class VirtualSite(BaseModel): diff --git a/src/DataSchemas/aind_vr_foraging_task_logic.json b/src/DataSchemas/aind_vr_foraging_task_logic.json index 5e32f3c6..880cdd45 100644 --- a/src/DataSchemas/aind_vr_foraging_task_logic.json +++ b/src/DataSchemas/aind_vr_foraging_task_logic.json @@ -1684,19 +1684,16 @@ "TreadmillSpecification": { "properties": { "friction": { - "default": 0, - "description": "Friction of the treadmill (0-1)", + "default": null, + "description": "Friction of the treadmill (0-1). The drawn value must be between 0 and 1", "oneOf": [ { - "maximum": 1.0, - "minimum": 0.0, - "type": "number" + "$ref": "#/definitions/Distribution" }, { "type": "null" } - ], - "title": "Friction" + ] } }, "title": "TreadmillSpecification", diff --git a/src/Extensions/AindVrForagingTaskLogic.cs b/src/Extensions/AindVrForagingTaskLogic.cs index 21383e23..52985964 100644 --- a/src/Extensions/AindVrForagingTaskLogic.cs +++ b/src/Extensions/AindVrForagingTaskLogic.cs @@ -4585,7 +4585,7 @@ public override string ToString() public partial class TreadmillSpecification { - private double? _friction; + private Distribution _friction; public TreadmillSpecification() { @@ -4597,12 +4597,12 @@ protected TreadmillSpecification(TreadmillSpecification other) } /// - /// Friction of the treadmill (0-1) + /// Friction of the treadmill (0-1). The drawn value must be between 0 and 1 /// [System.Xml.Serialization.XmlIgnoreAttribute()] [Newtonsoft.Json.JsonPropertyAttribute("friction")] - [System.ComponentModel.DescriptionAttribute("Friction of the treadmill (0-1)")] - public double? Friction + [System.ComponentModel.DescriptionAttribute("Friction of the treadmill (0-1). The drawn value must be between 0 and 1")] + public Distribution Friction { get { diff --git a/src/Extensions/InstantiateSite.bonsai b/src/Extensions/InstantiateSite.bonsai index fd0447cf..018b383c 100644 --- a/src/Extensions/InstantiateSite.bonsai +++ b/src/Extensions/InstantiateSite.bonsai @@ -1102,25 +1102,17 @@ it.Item2 as EntryPosition) Friction - - - - - Source1 - - - HasValue - - - - - - - - + + + RngSeed - - Value + + + + + + + TreadmillFriction @@ -1145,8 +1137,10 @@ it.Item2 as EntryPosition) - + + +