Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions examples/clabe.yml

This file was deleted.

63 changes: 43 additions & 20 deletions examples/olfactometer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,8 @@
from aind_behavior_device_olfactometer import rig, task_logic
from aind_behavior_device_olfactometer.rig import AlicatFlowmeter

olf_calibration = olf.OlfactometerCalibration(
channel_config={
olf.OlfactometerChannel.Channel0: olf.OlfactometerChannelConfig(
channel_index=olf.OlfactometerChannel.Channel0,
channel_type=olf.OlfactometerChannelType.ODOR,
flow_rate=100,
odorant="Banana",
odorant_dilution=0.1,
),
olf.OlfactometerChannel.Channel3: olf.OlfactometerChannelConfig(
channel_index=olf.OlfactometerChannel.Channel3,
channel_type=olf.OlfactometerChannelType.CARRIER,
odorant="Air",
),
}
)


calibration_logic = task_logic.OlfactometerCalibrationLogic(
task_parameters=task_logic.OlfactometerCalibrationParameters(
channel_config=olf_calibration.channel_config,
full_flow_rate=1000,
n_repeats_per_stimulus=10,
time_on=2,
Expand Down Expand Up @@ -57,11 +38,53 @@
initial_position=man.ManipulatorPosition(y1=0, y2=0, x=0, z=0),
)


olf_calibration = olf.OlfactometerCalibration(
channel_config={
olf.OlfactometerChannel.Channel0: olf.OlfactometerChannelConfig(
channel_index=olf.OlfactometerChannel.Channel0,
channel_type=olf.OlfactometerChannelType.ODOR,
flow_rate=100,
odorant="Banana",
odorant_dilution=0.1,
),
olf.OlfactometerChannel.Channel1: olf.OlfactometerChannelConfig(
channel_index=olf.OlfactometerChannel.Channel1,
channel_type=olf.OlfactometerChannelType.ODOR,
flow_rate=100,
odorant="None",
odorant_dilution=0.0,
),
olf.OlfactometerChannel.Channel2: olf.OlfactometerChannelConfig(
channel_index=olf.OlfactometerChannel.Channel2,
channel_type=olf.OlfactometerChannelType.ODOR,
flow_rate=100,
odorant="None",
odorant_dilution=0.0,
),
olf.OlfactometerChannel.Channel3: olf.OlfactometerChannelConfig(
channel_index=olf.OlfactometerChannel.Channel3,
channel_type=olf.OlfactometerChannelType.CARRIER,
odorant="Air",
),
}
)

extra_olf = olf_calibration.model_copy()
extra_olf.channel_config[olf.OlfactometerChannel.Channel3] = olf.OlfactometerChannelConfig(
channel_index=olf.OlfactometerChannel.Channel3,
channel_type=olf.OlfactometerChannelType.ODOR,
flow_rate=100,
odorant="Vanilla",
)


_rig = rig.OlfactometerCalibrationRig(
computer_name="TestPC",
data_directory="c:/data",
data_directory=r"C:/data",
rig_name="OlfactometerRig",
harp_olfactometer=olf.Olfactometer(port_name="COM10", calibration=olf_calibration),
harp_olfactometer_extension=[olf.Olfactometer(port_name="COM11", calibration=extra_olf)],
harp_analog_input=HarpAnalogInput(port_name="COM8"),
harp_clock_generator=HarpWhiteRabbit(port_name="COM9"),
harp_manipulator=man.AindManipulator(port_name="COM7", calibration=manipulator_calibration),
Expand Down
29 changes: 13 additions & 16 deletions schema/aind_behavior_device_olfactometer.json
Original file line number Diff line number Diff line change
Expand Up @@ -675,22 +675,11 @@
"title": "Rng Seed"
},
"aind_behavior_services_pkg_version": {
"default": "0.13.6",
"default": "0.13.7",
"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"
},
"channel_config": {
"additionalProperties": {
"$ref": "#/$defs/OlfactometerChannelConfig"
},
"description": "Configuration of olfactometer channels",
"propertyNames": {
"$ref": "#/$defs/OlfactometerChannel"
},
"title": "Channel Config",
"type": "object"
},
"full_flow_rate": {
"default": 1000,
"description": "Full flow rate of the olfactometer",
Expand Down Expand Up @@ -727,7 +716,7 @@
"OlfactometerCalibrationRig": {
"properties": {
"aind_behavior_services_pkg_version": {
"default": "0.13.6",
"default": "0.13.7",
"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 Expand Up @@ -758,6 +747,14 @@
"$ref": "#/$defs/Olfactometer",
"title": "Olfactometer device"
},
"harp_olfactometer_extension": {
"description": "A collection of subordinate olfactometers that can be added to increase the number of independently delivered odors. The order of the list determines the order by which odors are numbered",
"items": {
"$ref": "#/$defs/Olfactometer"
},
"title": "Harp Olfactometer Extension",
"type": "array"
},
"harp_analog_input": {
"$ref": "#/$defs/HarpAnalogInput",
"title": "Analog input device"
Expand Down Expand Up @@ -882,14 +879,14 @@
"Session": {
"properties": {
"aind_behavior_services_pkg_version": {
"default": "0.13.6",
"default": "0.13.7",
"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"
},
"version": {
"const": "0.13.6",
"default": "0.13.6",
"const": "0.13.7",
"default": "0.13.7",
"title": "Version",
"type": "string"
},
Expand Down
46 changes: 11 additions & 35 deletions scripts/aind_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from pydantic_settings import CliApp

from aind_behavior_device_olfactometer.rig import OlfactometerCalibrationRig
from aind_behavior_device_olfactometer.task_logic import OlfactometerCalibrationLogic
from aind_behavior_device_olfactometer.task_logic import OlfactometerCalibrationLogic, OlfactometerCalibrationParameters

logger = logging.getLogger(__name__)

Expand All @@ -29,9 +29,16 @@ async def calibration_experiment(launcher: Launcher) -> None:
)

session = picker.pick_session(Session)
task_logic = picker.pick_task(OlfactometerCalibrationLogic)

task_logic = OlfactometerCalibrationLogic(task_parameters=OlfactometerCalibrationParameters())
launcher.ui_helper.print(f"Loading task logic with default parameters: {task_logic.task_parameters}")
skip_manual_task = launcher.ui_helper.prompt_yes_no_question(
"Skip manual task parameter configuration and use defaults?"
)
if not skip_manual_task:
task_logic = picker.pick_task(OlfactometerCalibrationLogic)

rig = picker.pick_rig(OlfactometerCalibrationRig)
ensure_rig_and_computer_name(rig)

launcher.register_session(session, rig.data_directory)

Expand Down Expand Up @@ -67,7 +74,7 @@ async def calibration_experiment(launcher: Launcher) -> None:
runner.run_all_with_progress(reporter=reporter)
webbrowser.open(qc_path.as_uri(), new=2)
except Exception as e:
logger.error(f"Failed to run data QC: {e}")
logger.error("Failed to run data QC: %s", e)

# Transfer data
is_transfer = picker.ui_helper.prompt_yes_no_question("Would you like to transfer data?")
Expand All @@ -80,37 +87,6 @@ async def calibration_experiment(launcher: Launcher) -> None:
return


def ensure_rig_and_computer_name(rig: OlfactometerCalibrationRig) -> None:
"""Ensures rig and computer name are set from environment variables if available, otherwise defaults to rig configuration values."""

import os

rig_name = os.environ.get("aibs_comp_id", None)
computer_name = os.environ.get("hostname", None)

if rig_name is None:
logger.warning(
"'aibs_comp_id' environment variable not set. Defaulting to rig name from configuration. %s", rig.rig_name
)
rig_name = rig.rig_name
if computer_name is None:
computer_name = rig.computer_name
logger.warning(
"'hostname' environment variable not set. Defaulting to computer name from configuration. %s",
rig.computer_name,
)

if rig_name != rig.rig_name or computer_name != rig.computer_name:
logger.warning(
"Rig name or computer name from environment variables do not match the rig configuration. "
"Forcing rig name: %s and computer name: %s from environment variables.",
rig_name,
computer_name,
)
rig.rig_name = rig_name
rig.computer_name = computer_name


class ClabeCli(LauncherCliArgs):
def cli_cmd(self):
launcher = Launcher(settings=self)
Expand Down
3 changes: 2 additions & 1 deletion src/Extensions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Bonsai.Core" Version="2.8.1" />
<PackageReference Include="Bonsai.Core" Version="2.9.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Bonsai.Harp" Version="3.6.1" />
<PackageReference Include="AllenNeuralDynamics.AindBehaviorServices" Version="0.13.4" />
<PackageReference Include="AllenNeuralDynamics.AindBehaviorServices.Distributions" Version="0.2.0" />
<PackageReference Include="AllenNeuralDynamics.AindManipulator" Version="0.3.0" />
<PackageReference Include="Harp.Olfactometer" Version="0.4.0" />
</ItemGroup>

</Project>
55 changes: 29 additions & 26 deletions src/Extensions/AindBehaviorDeviceOlfactometer.Generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -994,8 +994,6 @@ public partial class OlfactometerCalibrationParameters

private string _aindBehaviorServicesPkgVersion;

private System.Collections.Generic.Dictionary<OlfactometerChannel, OlfactometerChannelConfig> _channelConfig;

private double _fullFlowRate;

private int _nRepeatsPerStimulus;
Expand All @@ -1006,7 +1004,7 @@ public partial class OlfactometerCalibrationParameters

public OlfactometerCalibrationParameters()
{
_aindBehaviorServicesPkgVersion = "0.13.6";
_aindBehaviorServicesPkgVersion = "0.13.7";
_fullFlowRate = 1000D;
_nRepeatsPerStimulus = 1;
_timeOn = 1D;
Expand All @@ -1017,7 +1015,6 @@ protected OlfactometerCalibrationParameters(OlfactometerCalibrationParameters ot
{
_rngSeed = other._rngSeed;
_aindBehaviorServicesPkgVersion = other._aindBehaviorServicesPkgVersion;
_channelConfig = other._channelConfig;
_fullFlowRate = other._fullFlowRate;
_nRepeatsPerStimulus = other._nRepeatsPerStimulus;
_timeOn = other._timeOn;
Expand Down Expand Up @@ -1054,24 +1051,6 @@ public string AindBehaviorServicesPkgVersion
}
}

/// <summary>
/// Configuration of olfactometer channels
/// </summary>
[System.Xml.Serialization.XmlIgnoreAttribute()]
[Newtonsoft.Json.JsonPropertyAttribute("channel_config")]
[System.ComponentModel.DescriptionAttribute("Configuration of olfactometer channels")]
public System.Collections.Generic.Dictionary<OlfactometerChannel, OlfactometerChannelConfig> ChannelConfig
{
get
{
return _channelConfig;
}
set
{
_channelConfig = value;
}
}

/// <summary>
/// Full flow rate of the olfactometer
/// </summary>
Expand Down Expand Up @@ -1154,7 +1133,6 @@ protected virtual bool PrintMembers(System.Text.StringBuilder stringBuilder)
{
stringBuilder.Append("RngSeed = " + _rngSeed + ", ");
stringBuilder.Append("AindBehaviorServicesPkgVersion = " + _aindBehaviorServicesPkgVersion + ", ");
stringBuilder.Append("ChannelConfig = " + _channelConfig + ", ");
stringBuilder.Append("FullFlowRate = " + _fullFlowRate + ", ");
stringBuilder.Append("NRepeatsPerStimulus = " + _nRepeatsPerStimulus + ", ");
stringBuilder.Append("TimeOn = " + _timeOn + ", ");
Expand Down Expand Up @@ -1195,6 +1173,8 @@ public partial class OlfactometerCalibrationRig

private Olfactometer _harpOlfactometer;

private System.Collections.Generic.List<Olfactometer> _harpOlfactometerExtension;

private HarpAnalogInput _harpAnalogInput;

private HarpWhiteRabbit _harpClockGenerator;
Expand All @@ -1205,9 +1185,10 @@ public partial class OlfactometerCalibrationRig

public OlfactometerCalibrationRig()
{
_aindBehaviorServicesPkgVersion = "0.13.6";
_aindBehaviorServicesPkgVersion = "0.13.7";
_version = "0.2.0-rc1";
_harpOlfactometer = new Olfactometer();
_harpOlfactometerExtension = new System.Collections.Generic.List<Olfactometer>();
_harpAnalogInput = new HarpAnalogInput();
_harpClockGenerator = new HarpWhiteRabbit();
_harpManipulator = new AllenNeuralDynamics.AindManipulator.AindManipulator();
Expand All @@ -1221,6 +1202,7 @@ protected OlfactometerCalibrationRig(OlfactometerCalibrationRig other)
_rigName = other._rigName;
_dataDirectory = other._dataDirectory;
_harpOlfactometer = other._harpOlfactometer;
_harpOlfactometerExtension = other._harpOlfactometerExtension;
_harpAnalogInput = other._harpAnalogInput;
_harpClockGenerator = other._harpClockGenerator;
_harpManipulator = other._harpManipulator;
Expand Down Expand Up @@ -1318,6 +1300,26 @@ public Olfactometer HarpOlfactometer
}
}

/// <summary>
/// A collection of subordinate olfactometers that can be added to increase the number of independently delivered odors. The order of the list determines the order by which odors are numbered
/// </summary>
[System.Xml.Serialization.XmlIgnoreAttribute()]
[Newtonsoft.Json.JsonPropertyAttribute("harp_olfactometer_extension")]
[System.ComponentModel.DescriptionAttribute("A collection of subordinate olfactometers that can be added to increase the numbe" +
"r of independently delivered odors. The order of the list determines the order b" +
"y which odors are numbered")]
public System.Collections.Generic.List<Olfactometer> HarpOlfactometerExtension
{
get
{
return _harpOlfactometerExtension;
}
set
{
_harpOlfactometerExtension = value;
}
}

[System.Xml.Serialization.XmlIgnoreAttribute()]
[Newtonsoft.Json.JsonPropertyAttribute("harp_analog_input", Required=Newtonsoft.Json.Required.Always)]
public HarpAnalogInput HarpAnalogInput
Expand Down Expand Up @@ -1400,6 +1402,7 @@ protected virtual bool PrintMembers(System.Text.StringBuilder stringBuilder)
stringBuilder.Append("RigName = " + _rigName + ", ");
stringBuilder.Append("DataDirectory = " + _dataDirectory + ", ");
stringBuilder.Append("HarpOlfactometer = " + _harpOlfactometer + ", ");
stringBuilder.Append("HarpOlfactometerExtension = " + _harpOlfactometerExtension + ", ");
stringBuilder.Append("HarpAnalogInput = " + _harpAnalogInput + ", ");
stringBuilder.Append("HarpClockGenerator = " + _harpClockGenerator + ", ");
stringBuilder.Append("HarpManipulator = " + _harpManipulator + ", ");
Expand Down Expand Up @@ -1642,8 +1645,8 @@ public partial class Session

public Session()
{
_aindBehaviorServicesPkgVersion = "0.13.6";
_version = "0.13.6";
_aindBehaviorServicesPkgVersion = "0.13.7";
_version = "0.13.7";
_experimenter = new System.Collections.Generic.List<string>();
_allowDirtyRepo = false;
_skipHardwareValidation = false;
Expand Down
Loading
Loading