Skip to content

Commit

Permalink
Remove ability to pass LUT in schema
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-f-cruz committed Aug 10, 2024
1 parent 833b4d5 commit 757db65
Show file tree
Hide file tree
Showing 3 changed files with 459 additions and 930 deletions.
37 changes: 7 additions & 30 deletions src/DataSchemas/aind_behavior_force_foraging/task_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

from enum import Enum
from functools import partial
from typing import Annotated, Any, Dict, List, Literal, Optional, Self, Union
from typing import Annotated, Dict, List, Literal, Optional, Self, Union

import aind_behavior_services.task_logic.distributions as distributions
from aind_behavior_services.task_logic import AindBehaviorTaskLogicModel, TaskParameters
from pydantic import BaseModel, Field, RootModel, field_validator, model_validator
from pydantic import BaseModel, Field, RootModel, model_validator

from aind_behavior_force_foraging import __version__

Expand Down Expand Up @@ -280,8 +280,8 @@ class PressMode(str, Enum):
SINGLE_LOOKUP_TABLE = "SingleLookupTable"


class _LUTBase(BaseModel):
look_up_table_type: str = Field(..., description="Type of the look up table")
class ForceLookUpTable(BaseModel):
path: str = Field(..., description="Reference to the look up table image.")
x_min: float = Field(..., description="The lower value of X used to linearly scale the input coordinate to.")
x_max: float = Field(..., description="The upper value of X used to linearly scale the input coordinate to.")
y_min: float = Field(..., description="The lower value of Y used to linearly scale the input coordinate to.")
Expand All @@ -308,38 +308,15 @@ def _validate_bounds(self) -> Self:
return self


class LUTByValue(_LUTBase):
look_up_table_type: Literal["Value"] = "Value"
lut: List[List[float]] = Field(..., description="LUT for force projection. Must be a MxN matrix, where N, M > 1")

@field_validator("lut", mode="after")
@classmethod
def _validate_lut(cls, v: Any):
if len(v) < 2:
raise ValueError("Look up table must have two rows")
if all(len(row) == len(v[0]) for row in v):
raise ValueError("Look up table must have the same number of columns in each row")
if len(v[0]) < 2:
raise ValueError("Look up table must have two columns")
return v


class LUTByReference(_LUTBase):
look_up_table_type: Literal["Reference"] = "Reference"
path: str = Field(..., description="Reference to the look up table")


class ForceLUT(RootModel):
root: Annotated[Union[LUTByValue, LUTByReference], Field(discriminator="look_up_table_type")]


class ForceOperationControl(BaseModel):
press_mode: PressMode = Field(
default=PressMode.DOUBLE, description="Defines the press mode. Default is to use both sensors individually"
)
left_index: int = Field(default=0, description="Index of the left sensor")
right_index: int = Field(default=1, description="Index of the right sensor")
force_lookup_table: Optional[ForceLUT] = Field(default=None, description="Look up table for force projection")
force_lookup_table: Optional[ForceLookUpTable] = Field(
default=None, description="Look up table for force projection"
)

@model_validator(mode="after")
def _validate_press_mode_versus_lut(self) -> Self:
Expand Down
298 changes: 86 additions & 212 deletions src/DataSchemas/aind_force_foraging_task_logic.json
Original file line number Diff line number Diff line change
Expand Up @@ -553,23 +553,95 @@
"title": "ExponentialDistributionParameters",
"type": "object"
},
"ForceLUT": {
"discriminator": {
"mapping": {
"Reference": "#/definitions/LUTByReference",
"Value": "#/definitions/LUTByValue"
"ForceLookUpTable": {
"properties": {
"path": {
"description": "Reference to the look up table image.",
"title": "Path",
"type": "string"
},
"propertyName": "look_up_table_type"
},
"oneOf": [
{
"$ref": "#/definitions/LUTByValue"
"x_min": {
"description": "The lower value of X used to linearly scale the input coordinate to.",
"title": "X Min",
"type": "number"
},
{
"$ref": "#/definitions/LUTByReference"
"x_max": {
"description": "The upper value of X used to linearly scale the input coordinate to.",
"title": "X Max",
"type": "number"
},
"y_min": {
"description": "The lower value of Y used to linearly scale the input coordinate to.",
"title": "Y Min",
"type": "number"
},
"y_max": {
"description": "The upper value of Y used to linearly scale the input coordinate to.",
"title": "Y Max",
"type": "number"
},
"x_min_bound_to": {
"default": null,
"description": "The value given to X < XMin. if null it will default to XMin.",
"oneOf": [
{
"type": "number"
},
{
"type": "null"
}
],
"title": "X Min Bound To"
},
"x_max_bound_to": {
"default": null,
"description": "The value given to X > XMax. if null it will default to XMax.",
"oneOf": [
{
"type": "number"
},
{
"type": "null"
}
],
"title": "X Max Bound To"
},
"y_min_bound_to": {
"default": null,
"description": "The value given to Y < YMin. if null it will default to YMin.",
"oneOf": [
{
"type": "number"
},
{
"type": "null"
}
],
"title": "Y Min Bound To"
},
"y_max_bound_to": {
"default": null,
"description": "The value given to Y > YMax. if null it will default to YMax.",
"oneOf": [
{
"type": "number"
},
{
"type": "null"
}
],
"title": "Y Max Bound To"
}
},
"required": [
"path",
"x_min",
"x_max",
"y_min",
"y_max"
],
"title": "ForceLUT"
"title": "ForceLookUpTable",
"type": "object"
},
"ForceOperationControl": {
"properties": {
Expand Down Expand Up @@ -599,7 +671,7 @@
"description": "Look up table for force projection",
"oneOf": [
{
"$ref": "#/definitions/ForceLUT"
"$ref": "#/definitions/ForceLookUpTable"
},
{
"type": "null"
Expand Down Expand Up @@ -814,204 +886,6 @@
"title": "InitiationPeriod",
"type": "object"
},
"LUTByReference": {
"properties": {
"look_up_table_type": {
"const": "Reference",
"default": "Reference",
"title": "Look Up Table Type",
"type": "string"
},
"x_min": {
"description": "The lower value of X used to linearly scale the input coordinate to.",
"title": "X Min",
"type": "number"
},
"x_max": {
"description": "The upper value of X used to linearly scale the input coordinate to.",
"title": "X Max",
"type": "number"
},
"y_min": {
"description": "The lower value of Y used to linearly scale the input coordinate to.",
"title": "Y Min",
"type": "number"
},
"y_max": {
"description": "The upper value of Y used to linearly scale the input coordinate to.",
"title": "Y Max",
"type": "number"
},
"x_min_bound_to": {
"default": null,
"description": "The value given to X < XMin. if null it will default to XMin.",
"oneOf": [
{
"type": "number"
},
{
"type": "null"
}
],
"title": "X Min Bound To"
},
"x_max_bound_to": {
"default": null,
"description": "The value given to X > XMax. if null it will default to XMax.",
"oneOf": [
{
"type": "number"
},
{
"type": "null"
}
],
"title": "X Max Bound To"
},
"y_min_bound_to": {
"default": null,
"description": "The value given to Y < YMin. if null it will default to YMin.",
"oneOf": [
{
"type": "number"
},
{
"type": "null"
}
],
"title": "Y Min Bound To"
},
"y_max_bound_to": {
"default": null,
"description": "The value given to Y > YMax. if null it will default to YMax.",
"oneOf": [
{
"type": "number"
},
{
"type": "null"
}
],
"title": "Y Max Bound To"
},
"path": {
"description": "Reference to the look up table",
"title": "Path",
"type": "string"
}
},
"required": [
"x_min",
"x_max",
"y_min",
"y_max",
"path"
],
"title": "LUTByReference",
"type": "object"
},
"LUTByValue": {
"properties": {
"look_up_table_type": {
"const": "Value",
"default": "Value",
"title": "Look Up Table Type",
"type": "string"
},
"x_min": {
"description": "The lower value of X used to linearly scale the input coordinate to.",
"title": "X Min",
"type": "number"
},
"x_max": {
"description": "The upper value of X used to linearly scale the input coordinate to.",
"title": "X Max",
"type": "number"
},
"y_min": {
"description": "The lower value of Y used to linearly scale the input coordinate to.",
"title": "Y Min",
"type": "number"
},
"y_max": {
"description": "The upper value of Y used to linearly scale the input coordinate to.",
"title": "Y Max",
"type": "number"
},
"x_min_bound_to": {
"default": null,
"description": "The value given to X < XMin. if null it will default to XMin.",
"oneOf": [
{
"type": "number"
},
{
"type": "null"
}
],
"title": "X Min Bound To"
},
"x_max_bound_to": {
"default": null,
"description": "The value given to X > XMax. if null it will default to XMax.",
"oneOf": [
{
"type": "number"
},
{
"type": "null"
}
],
"title": "X Max Bound To"
},
"y_min_bound_to": {
"default": null,
"description": "The value given to Y < YMin. if null it will default to YMin.",
"oneOf": [
{
"type": "number"
},
{
"type": "null"
}
],
"title": "Y Min Bound To"
},
"y_max_bound_to": {
"default": null,
"description": "The value given to Y > YMax. if null it will default to YMax.",
"oneOf": [
{
"type": "number"
},
{
"type": "null"
}
],
"title": "Y Max Bound To"
},
"lut": {
"description": "LUT for force projection. Must be a MxN matrix, where N, M > 1",
"items": {
"items": {
"type": "number"
},
"type": "array"
},
"title": "Lut",
"type": "array"
}
},
"required": [
"x_min",
"x_max",
"y_min",
"y_max",
"lut"
],
"title": "LUTByValue",
"type": "object"
},
"LogNormalDistribution": {
"properties": {
"family": {
Expand Down
Loading

0 comments on commit 757db65

Please sign in to comment.