Skip to content

Commit

Permalink
Merge pull request #253 from AllenNeuralDynamics/feat-add-patch-flanking
Browse files Browse the repository at this point in the history
Implement patch flanking sites
  • Loading branch information
bruno-f-cruz authored Jun 4, 2024
2 parents 2f76929 + a6a0544 commit 6c3909b
Show file tree
Hide file tree
Showing 9 changed files with 369 additions and 70 deletions.
2 changes: 1 addition & 1 deletion src/DataSchemas/aind_behavior_vr_foraging/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.4.2"
__version__ = "0.4.0"
2 changes: 1 addition & 1 deletion src/DataSchemas/aind_behavior_vr_foraging/rig.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from aind_behavior_services.rig import AindBehaviorRigModel
from pydantic import BaseModel, Field, RootModel

__version__ = "0.3.1"
__version__ = "0.3.0"

TreadmillSettings = rig.Treadmill

Expand Down
31 changes: 17 additions & 14 deletions src/DataSchemas/aind_behavior_vr_foraging/task_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
from aind_behavior_services.task_logic import AindBehaviorTaskLogicModel, TaskParameters
from pydantic import BaseModel, Field, RootModel


__version__ = "0.4.1"
__version__ = "0.4.0"


def scalar_value(value: float) -> distributions.Scalar:
Expand Down Expand Up @@ -41,7 +40,7 @@ class Vector3(BaseModel):


class Matrix2D(BaseModel):
data: List[List[float]] = Field([[1]], description="Defines a 2D matrix")
data: List[List[float]] = Field(default=[[1]], description="Defines a 2D matrix")


# Updaters
Expand All @@ -66,7 +65,7 @@ class NumericalUpdater(BaseModel):
default=NumericalUpdaterOperation.NONE, description="Operation to perform on the parameter"
)
parameters: NumericalUpdaterParameters = Field(
NumericalUpdaterParameters(), description="Parameters of the updater"
default=NumericalUpdaterParameters(), description="Parameters of the updater"
)


Expand Down Expand Up @@ -149,7 +148,7 @@ class PatchRewardFunction(BaseModel):


class RewardSpecification(BaseModel):
operant_logic: Optional[OperantLogic] = Field(None, description="The optional operant logic of the reward")
operant_logic: Optional[OperantLogic] = Field(default=None, description="The optional operant logic of the reward")
delay: distributions.Distribution = Field(
default=scalar_value(0),
description="The optional distribution where the delay to reward will be drawn from",
Expand All @@ -163,6 +162,7 @@ class RewardSpecification(BaseModel):
class VirtualSiteLabels(str, Enum):
UNSPECIFIED = "Unspecified"
INTERPATCH = "InterPatch"
POSTPATCH = "PostPatch"
REWARDSITE = "RewardSite"
INTERSITE = "InterSite"

Expand All @@ -183,29 +183,32 @@ class VirtualSiteGenerator(BaseModel):

class VirtualSiteGeneration(BaseModel):
inter_site: VirtualSiteGenerator = Field(
VirtualSiteGenerator(), description="Generator of the inter-site virtual sites"
default=VirtualSiteGenerator(), description="Generator of the inter-site virtual sites"
)
inter_patch: VirtualSiteGenerator = Field(
VirtualSiteGenerator(), description="Generator of the inter-patch virtual sites"
default=VirtualSiteGenerator(), description="Generator of the inter-patch virtual sites"
)
post_patch: VirtualSiteGenerator = Field(
default=VirtualSiteGenerator(), description="Generator of the post-inter-patch virtual sites"
)
reward_site: VirtualSiteGenerator = Field(
VirtualSiteGenerator(), description="Generator of the reward-site virtual sites"
default=VirtualSiteGenerator(), description="Generator of the reward-site virtual sites"
)


class VirtualSite(BaseModel):
id: int = Field(default=0, ge=0, description="Id of the virtual site")
label: VirtualSiteLabels = Field(VirtualSiteLabels.UNSPECIFIED, description="Label of the virtual site")
length: float = Field(20, description="Length of the virtual site (cm)")
label: VirtualSiteLabels = Field(default=VirtualSiteLabels.UNSPECIFIED, description="Label of the virtual site")
length: float = Field(default=20, description="Length of the virtual site (cm)")
start_position: float = Field(default=0, ge=0, description="Start position of the virtual site (cm)")
odor_specification: Optional[OdorSpecification] = Field(
None, description="The optional odor specification of the virtual site"
default=None, description="The optional odor specification of the virtual site"
)
reward_specification: Optional[RewardSpecification] = Field(
None, description="The optional reward specification of the virtual site"
default=None, description="The optional reward specification of the virtual site"
)
render_specification: RenderSpecification = Field(
RenderSpecification(), description="The optional render specification of the virtual site"
default=RenderSpecification(), description="The optional render specification of the virtual site"
)


Expand All @@ -219,7 +222,7 @@ class PatchStatistics(BaseModel):
default=None, description="The optional reward specification of the patch"
)
virtual_site_generation: VirtualSiteGeneration = Field(
VirtualSiteGeneration(), description="Virtual site generation specification"
default=VirtualSiteGeneration(), description="Virtual site generation specification"
)


Expand Down
4 changes: 2 additions & 2 deletions src/DataSchemas/aind_vr_foraging_rig.json
Original file line number Diff line number Diff line change
Expand Up @@ -1326,8 +1326,8 @@
},
"properties": {
"version": {
"const": "0.3.1",
"default": "0.3.1",
"const": "0.3.0",
"default": "0.3.0",
"title": "Version",
"type": "string"
},
Expand Down
47 changes: 45 additions & 2 deletions src/DataSchemas/aind_vr_foraging_task_logic.json
Original file line number Diff line number Diff line change
Expand Up @@ -1192,6 +1192,23 @@
"contrast": null
}
},
"post_patch": {
"label": "Unspecified",
"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
}
},
"reward_site": {
"label": "Unspecified",
"length_distribution": {
Expand Down Expand Up @@ -1923,6 +1940,31 @@
},
"description": "Generator of the inter-patch virtual sites"
},
"post_patch": {
"allOf": [
{
"$ref": "#/definitions/VirtualSiteGenerator"
}
],
"default": {
"render_specification": {
"contrast": null
},
"label": "Unspecified",
"length_distribution": {
"distribution_parameters": {
"family": "Scalar",
"scaling_parameters": null,
"truncation_parameters": null,
"value": 20.0
},
"family": "Scalar",
"scaling_parameters": null,
"truncation_parameters": null
}
},
"description": "Generator of the post-inter-patch virtual sites"
},
"reward_site": {
"allOf": [
{
Expand Down Expand Up @@ -2001,6 +2043,7 @@
"enum": [
"Unspecified",
"InterPatch",
"PostPatch",
"RewardSite",
"InterSite"
],
Expand Down Expand Up @@ -2117,8 +2160,8 @@
"type": "string"
},
"version": {
"const": "0.4.1",
"default": "0.4.1",
"const": "0.4.0",
"default": "0.4.0",
"title": "Version",
"type": "string"
},
Expand Down
159 changes: 159 additions & 0 deletions src/Extensions/AddPostPatchSite.bonsai
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
<?xml version="1.0" encoding="utf-8"?>
<WorkflowBuilder Version="2.8.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:rx="clr-namespace:Bonsai.Reactive;assembly=Bonsai.Core"
xmlns:p1="clr-namespace:AindVrForagingDataSchema.TaskLogic;assembly=Extensions"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:num="clr-namespace:Bonsai.Numerics;assembly=Bonsai.Numerics"
xmlns="https://bonsai-rx.org/2018/workflow">
<Workflow>
<Nodes>
<Expression xsi:type="WorkflowInput">
<Name>Source1</Name>
</Expression>
<Expression xsi:type="ExternalizedMapping">
<Property Name="Contrast" />
<Property Name="Label" />
<Property Name="LengthDistribution" />
</Expression>
<Expression xsi:type="rx:SelectMany">
<Name>InterPatch</Name>
<Workflow>
<Nodes>
<Expression xsi:type="WorkflowInput">
<Name>Source1</Name>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="rx:Take">
<rx:Count>1</rx:Count>
</Combinator>
</Expression>
<Expression xsi:type="rx:AsyncSubject">
<Name>PreviousSite</Name>
</Expression>
<Expression xsi:type="SubscribeSubject">
<Name>PreviousSite</Name>
</Expression>
<Expression xsi:type="MemberSelector">
<Selector>Length,StartPosition</Selector>
</Expression>
<Expression xsi:type="Add" />
<Expression xsi:type="SubscribeSubject">
<Name>SigmaZ</Name>
</Expression>
<Expression xsi:type="PropertyMapping">
<PropertyMappings>
<Property Name="Value" />
</PropertyMappings>
</Expression>
<Expression xsi:type="Add">
<Operand xsi:type="FloatProperty">
<Value>0</Value>
</Operand>
</Expression>
<Expression xsi:type="ExternalizedMapping">
<Property Name="Value" DisplayName="LengthDistribution" />
</Expression>
<Expression xsi:type="PropertySource" TypeArguments="p1:VirtualSiteGenerator,p1:Distribution">
<MemberName>LengthDistribution</MemberName>
</Expression>
<Expression xsi:type="SubscribeSubject">
<Name>RngSeed</Name>
</Expression>
<Expression xsi:type="PropertyMapping">
<PropertyMappings>
<Property Name="RandomSource" />
</PropertyMappings>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="p1:SampleDistribution" />
</Expression>
<Expression xsi:type="InputMapping">
<PropertyMappings />
<TypeMapping xsi:type="TypeMapping" TypeArguments="sys:Double" />
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="num:Floor" />
</Expression>
<Expression xsi:type="InputMapping">
<PropertyMappings />
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="rx:Zip" />
</Expression>
<Expression xsi:type="InputMapping">
<PropertyMappings>
<Property Name="StartPosition" Selector="Item1" />
<Property Name="Length" Selector="Item2" />
<Property Name="Id" Selector="Item3" />
</PropertyMappings>
</Expression>
<Expression xsi:type="ExternalizedMapping">
<Property Name="Contrast" />
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="p1:RenderSpecification" />
</Expression>
<Expression xsi:type="PropertyMapping">
<PropertyMappings>
<Property Name="RenderSpecification" />
</PropertyMappings>
</Expression>
<Expression xsi:type="ExternalizedMapping">
<Property Name="Label" />
</Expression>
<Expression xsi:type="IncludeWorkflow" Path="Extensions\CreateSite.bonsai">
<Id>0</Id>
<Length>120</Length>
<StartPosition>0</StartPosition>
</Expression>
<Expression xsi:type="MulticastSubject">
<Name>SiteSpecs</Name>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="rx:Take">
<rx:Count>1</rx:Count>
</Combinator>
</Expression>
<Expression xsi:type="WorkflowOutput" />
</Nodes>
<Edges>
<Edge From="0" To="1" Label="Source1" />
<Edge From="1" To="2" Label="Source1" />
<Edge From="3" To="4" Label="Source1" />
<Edge From="4" To="5" Label="Source1" />
<Edge From="5" To="8" Label="Source1" />
<Edge From="6" To="7" Label="Source1" />
<Edge From="7" To="8" Label="Source2" />
<Edge From="8" To="10" Label="Source1" />
<Edge From="8" To="14" Label="Source1" />
<Edge From="8" To="17" Label="Source1" />
<Edge From="9" To="10" Label="Source2" />
<Edge From="10" To="13" Label="Source1" />
<Edge From="11" To="12" Label="Source1" />
<Edge From="12" To="13" Label="Source2" />
<Edge From="13" To="17" Label="Source3" />
<Edge From="14" To="15" Label="Source1" />
<Edge From="15" To="16" Label="Source1" />
<Edge From="16" To="17" Label="Source4" />
<Edge From="17" To="18" Label="Source1" />
<Edge From="18" To="23" Label="Source1" />
<Edge From="19" To="20" Label="Source1" />
<Edge From="20" To="21" Label="Source1" />
<Edge From="21" To="23" Label="Source2" />
<Edge From="22" To="23" Label="Source3" />
<Edge From="23" To="24" Label="Source1" />
<Edge From="24" To="25" Label="Source1" />
<Edge From="25" To="26" Label="Source1" />
</Edges>
</Workflow>
</Expression>
<Expression xsi:type="WorkflowOutput" />
</Nodes>
<Edges>
<Edge From="0" To="2" Label="Source1" />
<Edge From="1" To="2" Label="Source2" />
<Edge From="2" To="3" Label="Source1" />
</Edges>
</Workflow>
</WorkflowBuilder>
2 changes: 1 addition & 1 deletion src/Extensions/AindVrForagingRig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3620,7 +3620,7 @@ public override string ToString()
public partial class AindVrForagingRig
{

private string _version = "0.3.1";
private string _version = "0.3.0";

private string _computerName;

Expand Down
Loading

0 comments on commit 6c3909b

Please sign in to comment.