Skip to content

Commit

Permalink
Merge pull request #121 from AllenNeuralDynamics/feat-add-new-harp-de…
Browse files Browse the repository at this point in the history
…vices

Implement clock output mapping from clock generator devices
  • Loading branch information
bruno-f-cruz authored Nov 11, 2024
2 parents 1acbe67 + a0ed0e3 commit 5c21349
Show file tree
Hide file tree
Showing 26 changed files with 236 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/Extensions/AindBehaviorSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace AindBehaviorServices.AindBehaviorSession
public partial class AindBehaviorSessionModel
{

private string _aindBehaviorServicesPkgVersion = "0.8.5";
private string _aindBehaviorServicesPkgVersion = "0.8.6";

private string _version = "0.3.0";

Expand Down
2 changes: 1 addition & 1 deletion src/Extensions/AindManipulatorCalibrationLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public partial class CalibrationParameters

private double? _rngSeed;

private string _aindBehaviorServicesPkgVersion = "0.8.5";
private string _aindBehaviorServicesPkgVersion = "0.8.6";

public CalibrationParameters()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Extensions/AindManipulatorCalibrationRig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ public enum MotorOperationMode
public partial class CalibrationRig
{

private string _aindBehaviorServicesPkgVersion = "0.8.5";
private string _aindBehaviorServicesPkgVersion = "0.8.6";

private string _version = "0.1.0";

Expand Down
2 changes: 1 addition & 1 deletion src/Extensions/LoadCellsCalibrationLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public partial class CalibrationParameters

private double? _rngSeed;

private string _aindBehaviorServicesPkgVersion = "0.8.5";
private string _aindBehaviorServicesPkgVersion = "0.8.6";

private System.Collections.Generic.List<int> _channels = new System.Collections.Generic.List<int>();

Expand Down
2 changes: 1 addition & 1 deletion src/Extensions/LoadCellsCalibrationRig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ public override string ToString()
public partial class CalibrationRig
{

private string _aindBehaviorServicesPkgVersion = "0.8.5";
private string _aindBehaviorServicesPkgVersion = "0.8.6";

private string _version = "0.0.0";

Expand Down
2 changes: 1 addition & 1 deletion src/Extensions/OlfactometerCalibrationLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public partial class CalibrationParameters

private double? _rngSeed;

private string _aindBehaviorServicesPkgVersion = "0.8.5";
private string _aindBehaviorServicesPkgVersion = "0.8.6";

private System.Collections.Generic.IDictionary<string, OlfactometerChannelConfig> _channelConfig;

Expand Down
118 changes: 116 additions & 2 deletions src/Extensions/OlfactometerCalibrationRig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,92 @@ 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 ConnectedClockOutput
{

private string _targetDevice;

private int _outputChannel;

public ConnectedClockOutput()
{
}

protected ConnectedClockOutput(ConnectedClockOutput other)
{
_targetDevice = other._targetDevice;
_outputChannel = other._outputChannel;
}

/// <summary>
/// Optional device name to provide user additional information
/// </summary>
[Newtonsoft.Json.JsonPropertyAttribute("target_device")]
[System.ComponentModel.DescriptionAttribute("Optional device name to provide user additional information")]
public string TargetDevice
{
get
{
return _targetDevice;
}
set
{
_targetDevice = value;
}
}

/// <summary>
/// Output channel
/// </summary>
[Newtonsoft.Json.JsonPropertyAttribute("output_channel", Required=Newtonsoft.Json.Required.Always)]
[System.ComponentModel.DescriptionAttribute("Output channel")]
public int OutputChannel
{
get
{
return _outputChannel;
}
set
{
_outputChannel = value;
}
}

public System.IObservable<ConnectedClockOutput> Process()
{
return System.Reactive.Linq.Observable.Defer(() => System.Reactive.Linq.Observable.Return(new ConnectedClockOutput(this)));
}

public System.IObservable<ConnectedClockOutput> Process<TSource>(System.IObservable<TSource> source)
{
return System.Reactive.Linq.Observable.Select(source, _ => new ConnectedClockOutput(this));
}

protected virtual bool PrintMembers(System.Text.StringBuilder stringBuilder)
{
stringBuilder.Append("target_device = " + _targetDevice + ", ");
stringBuilder.Append("output_channel = " + _outputChannel);
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)]
Expand Down Expand Up @@ -235,6 +321,8 @@ public partial class HarpClockGenerator

private string _portName;

private System.Collections.Generic.List<ConnectedClockOutput> _connectedClockOutputs = new System.Collections.Generic.List<ConnectedClockOutput>();

public HarpClockGenerator()
{
}
Expand All @@ -247,6 +335,7 @@ protected HarpClockGenerator(HarpClockGenerator other)
_whoAmI = other._whoAmI;
_serialNumber = other._serialNumber;
_portName = other._portName;
_connectedClockOutputs = other._connectedClockOutputs;
}

[Newtonsoft.Json.JsonPropertyAttribute("device_type")]
Expand Down Expand Up @@ -345,6 +434,24 @@ public string PortName
}
}

/// <summary>
/// Connected clock outputs
/// </summary>
[System.Xml.Serialization.XmlIgnoreAttribute()]
[Newtonsoft.Json.JsonPropertyAttribute("connected_clock_outputs")]
[System.ComponentModel.DescriptionAttribute("Connected clock outputs")]
public System.Collections.Generic.List<ConnectedClockOutput> ConnectedClockOutputs
{
get
{
return _connectedClockOutputs;
}
set
{
_connectedClockOutputs = value;
}
}

public System.IObservable<HarpClockGenerator> Process()
{
return System.Reactive.Linq.Observable.Defer(() => System.Reactive.Linq.Observable.Return(new HarpClockGenerator(this)));
Expand All @@ -362,7 +469,8 @@ protected virtual bool PrintMembers(System.Text.StringBuilder stringBuilder)
stringBuilder.Append("calibration = " + _calibration + ", ");
stringBuilder.Append("who_am_i = " + _whoAmI + ", ");
stringBuilder.Append("serial_number = " + _serialNumber + ", ");
stringBuilder.Append("port_name = " + _portName);
stringBuilder.Append("port_name = " + _portName + ", ");
stringBuilder.Append("connected_clock_outputs = " + _connectedClockOutputs);
return true;
}

Expand Down Expand Up @@ -979,7 +1087,7 @@ public enum OlfactometerChannelType
public partial class CalibrationRig
{

private string _aindBehaviorServicesPkgVersion = "0.8.5";
private string _aindBehaviorServicesPkgVersion = "0.8.6";

private string _version = "0.0.0";

Expand Down Expand Up @@ -1179,6 +1287,11 @@ public System.IObservable<string> Process(System.IObservable<BaseModel> source)
return Process<BaseModel>(source);
}

public System.IObservable<string> Process(System.IObservable<ConnectedClockOutput> source)
{
return Process<ConnectedClockOutput>(source);
}

public System.IObservable<string> Process(System.IObservable<HarpAnalogInput> source)
{
return Process<HarpAnalogInput>(source);
Expand Down Expand Up @@ -1229,6 +1342,7 @@ public System.IObservable<string> Process(System.IObservable<CalibrationRig> sou
[System.ComponentModel.DefaultPropertyAttribute("Type")]
[Bonsai.WorkflowElementCategoryAttribute(Bonsai.ElementCategory.Transform)]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(Bonsai.Expressions.TypeMapping<BaseModel>))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(Bonsai.Expressions.TypeMapping<ConnectedClockOutput>))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(Bonsai.Expressions.TypeMapping<HarpAnalogInput>))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(Bonsai.Expressions.TypeMapping<HarpClockGenerator>))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(Bonsai.Expressions.TypeMapping<Olfactometer>))]
Expand Down
2 changes: 1 addition & 1 deletion src/Extensions/TreadmillCalibrationLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public partial class CalibrationParameters

private double? _rngSeed;

private string _aindBehaviorServicesPkgVersion = "0.8.5";
private string _aindBehaviorServicesPkgVersion = "0.8.6";

public CalibrationParameters()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Extensions/TreadmillCalibrationRig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ public override string ToString()
public partial class CalibrationRig
{

private string _aindBehaviorServicesPkgVersion = "0.8.5";
private string _aindBehaviorServicesPkgVersion = "0.8.6";

private string _version = "0.0.0";

Expand Down
2 changes: 1 addition & 1 deletion src/Extensions/WaterValveCalibrationLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public partial class CalibrationParameters

private double? _rngSeed;

private string _aindBehaviorServicesPkgVersion = "0.8.5";
private string _aindBehaviorServicesPkgVersion = "0.8.6";

private System.Collections.Generic.List<double> _valveOpenTime = new System.Collections.Generic.List<double>();

Expand Down
2 changes: 1 addition & 1 deletion src/Extensions/WaterValveCalibrationRig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace AindBehaviorServices.WaterValveCalibrationRig
public partial class CalibrationRig
{

private string _aindBehaviorServicesPkgVersion = "0.8.5";
private string _aindBehaviorServicesPkgVersion = "0.8.6";

private string _version = "0.0.0";

Expand Down
2 changes: 1 addition & 1 deletion src/aind_behavior_services/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.8.5"
__version__ = "0.8.6"

from .rig import AindBehaviorRigModel # noqa: F401
from .session import AindBehaviorSessionModel # noqa: F401
Expand Down
70 changes: 58 additions & 12 deletions src/aind_behavior_services/rig/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import os
from enum import Enum
from typing import Annotated, Dict, Generic, Literal, Optional, TypeVar, Union
from typing import Annotated, Dict, Generic, List, Literal, Optional, TypeVar, Union

from pydantic import BaseModel, Field, field_validator
from typing_extensions import TypeAliasType
Expand Down Expand Up @@ -99,6 +99,7 @@ class CameraController(Device, Generic[TCamera]):


class HarpDeviceType(str, Enum):
GENERIC = "generic"
LOADCELLS = "loadcells"
BEHAVIOR = "behavior"
OLFACTOMETER = "olfactometer"
Expand All @@ -111,7 +112,8 @@ class HarpDeviceType(str, Enum):
SNIFFDETECTOR = "sniffdetector"
CUTTLEFISH = "cuttlefish"
STEPPERDRIVER = "stepperdriver"
GENERIC = "generic"
ENVIRONMENTSENSOR = "environmentsensor"
WHITERABBIT = "whiterabbit"


class HarpDeviceGeneric(Device):
Expand All @@ -121,6 +123,53 @@ class HarpDeviceGeneric(Device):
port_name: str = Field(..., description="Device port name")


class ConnectedClockOutput(BaseModel):
target_device: Optional[str] = Field(
default=None, description="Optional device name to provide user additional information"
)
output_channel: int = Field(..., ge=0, description="Output channel")


def _assert_unique_output_channels(outputs: List[ConnectedClockOutput]) -> List[ConnectedClockOutput]:
channels = set([ch.output_channel for ch in outputs])
if len(channels) != len(outputs):
raise ValueError("Output channels must be unique")
return outputs


class HarpClockGenerator(HarpDeviceGeneric):
device_type: Literal[HarpDeviceType.CLOCKGENERATOR] = HarpDeviceType.CLOCKGENERATOR
who_am_i: Literal[1158] = 1158
connected_clock_outputs: List[ConnectedClockOutput] = Field(default=[], description="Connected clock outputs")

@field_validator("connected_clock_outputs")
@classmethod
def validate_connected_clock_outputs(cls, v: List[ConnectedClockOutput]) -> List[ConnectedClockOutput]:
return _assert_unique_output_channels(v)


class HarpWhiteRabbit(HarpDeviceGeneric):
device_type: Literal[HarpDeviceType.WHITERABBIT] = HarpDeviceType.WHITERABBIT
who_am_i: Literal[1404] = 1404
connected_clock_outputs: List[ConnectedClockOutput] = Field(default=[], description="Connected clock outputs")

@field_validator("connected_clock_outputs")
@classmethod
def validate_connected_clock_outputs(cls, v: List[ConnectedClockOutput]) -> List[ConnectedClockOutput]:
return _assert_unique_output_channels(v)


class HarpClockSynchronizer(HarpDeviceGeneric):
device_type: Literal[HarpDeviceType.CLOCKSYNCHRONIZER] = HarpDeviceType.CLOCKSYNCHRONIZER
who_am_i: Literal[1152] = 1152
connected_clock_outputs: List[ConnectedClockOutput] = Field(default=[], description="Connected clock outputs")

@field_validator("connected_clock_outputs")
@classmethod
def validate_connected_clock_outputs(cls, v: List[ConnectedClockOutput]) -> List[ConnectedClockOutput]:
return _assert_unique_output_channels(v)


class HarpBehavior(HarpDeviceGeneric):
device_type: Literal[HarpDeviceType.BEHAVIOR] = HarpDeviceType.BEHAVIOR
who_am_i: Literal[1216] = 1216
Expand All @@ -141,16 +190,6 @@ class HarpOlfactometer(HarpDeviceGeneric):
who_am_i: Literal[1140] = 1140


class HarpClockGenerator(HarpDeviceGeneric):
device_type: Literal[HarpDeviceType.CLOCKGENERATOR] = HarpDeviceType.CLOCKGENERATOR
who_am_i: Literal[1158] = 1158


class HarpClockSynchronizer(HarpDeviceGeneric):
device_type: Literal[HarpDeviceType.CLOCKSYNCHRONIZER] = HarpDeviceType.CLOCKSYNCHRONIZER
who_am_i: Literal[1152] = 1152


class HarpAnalogInput(HarpDeviceGeneric):
device_type: Literal[HarpDeviceType.ANALOGINPUT] = HarpDeviceType.ANALOGINPUT
who_am_i: Literal[1236] = 1236
Expand Down Expand Up @@ -181,6 +220,11 @@ class HarpStepperDriver(HarpDeviceGeneric):
who_am_i: Literal[1130] = 1130


class HarpEnvironmentSensor(HarpDeviceGeneric):
device_type: Literal[HarpDeviceType.ENVIRONMENTSENSOR] = HarpDeviceType.ENVIRONMENTSENSOR
who_am_i: Literal[1405] = 1405


HarpDevice = TypeAliasType(
"HarpDevice",
Annotated[
Expand All @@ -197,6 +241,8 @@ class HarpStepperDriver(HarpDeviceGeneric):
HarpSniffDetector,
HarpClockSynchronizer,
HarpStepperDriver,
HarpEnvironmentSensor,
HarpWhiteRabbit,
],
Field(discriminator="device_type"),
],
Expand Down
2 changes: 1 addition & 1 deletion src/schemas/aind_behavior_data_types.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
},
"properties": {
"aind_behavior_services_pkg_version": {
"default": "0.8.5",
"default": "0.8.6",
"pattern": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$",
"title": "aind_behavior_services package version",
"type": "string"
Expand Down
Loading

0 comments on commit 5c21349

Please sign in to comment.