From 28e53972bfe5d0d40c68627df280d8525a4b6373 Mon Sep 17 00:00:00 2001 From: Thinh Nguyen Date: Wed, 3 Apr 2024 19:19:05 -0500 Subject: [PATCH] update(schemas): update social schemas to use the refactored Stream, StreamGroup and Device --- aeon/schema/schemas.py | 150 ++++++++++++++++++++------------------- aeon/schema/social.py | 113 ----------------------------- aeon/schema/social_01.py | 12 ++++ aeon/schema/social_02.py | 88 +++++++++++++++++++++++ 4 files changed, 177 insertions(+), 186 deletions(-) delete mode 100644 aeon/schema/social.py create mode 100644 aeon/schema/social_01.py create mode 100644 aeon/schema/social_02.py diff --git a/aeon/schema/schemas.py b/aeon/schema/schemas.py index 72820fdc..bc6eaa31 100644 --- a/aeon/schema/schemas.py +++ b/aeon/schema/schemas.py @@ -1,48 +1,51 @@ from dotmap import DotMap -from aeon.io.device import Device -from aeon.schema import core, foraging, octagon, social + +import aeon.schema.core as stream +from aeon.schema.streams import Device +from aeon.schema import foraging, octagon, social_01, social_02 + exp02 = DotMap( [ - Device("Metadata", core.metadata), - Device("ExperimentalMetadata", core.environment, core.message_log), - Device("CameraTop", core.video, core.position, foraging.region), - Device("CameraEast", core.video), - Device("CameraNest", core.video), - Device("CameraNorth", core.video), - Device("CameraPatch1", core.video), - Device("CameraPatch2", core.video), - Device("CameraSouth", core.video), - Device("CameraWest", core.video), - Device("Nest", foraging.weight), - Device("Patch1", foraging.patch), - Device("Patch2", foraging.patch), + Device("Metadata", stream.Metadata), + Device("ExperimentalMetadata", stream.Environment, stream.MessageLog), + Device("CameraTop", stream.Video, stream.Position, foraging.Region), + Device("CameraEast", stream.Video), + Device("CameraNest", stream.Video), + Device("CameraNorth", stream.Video), + Device("CameraPatch1", stream.Video), + Device("CameraPatch2", stream.Video), + Device("CameraSouth", stream.Video), + Device("CameraWest", stream.Video), + Device("Nest", foraging.Weight), + Device("Patch1", foraging.Patch), + Device("Patch2", foraging.Patch), ] ) exp01 = DotMap( [ - Device("SessionData", foraging.session), - Device("FrameTop", core.video, core.position), - Device("FrameEast", core.video), - Device("FrameGate", core.video), - Device("FrameNorth", core.video), - Device("FramePatch1", core.video), - Device("FramePatch2", core.video), - Device("FrameSouth", core.video), - Device("FrameWest", core.video), - Device("Patch1", foraging.depletion_function, core.encoder, foraging.feeder), - Device("Patch2", foraging.depletion_function, core.encoder, foraging.feeder), + Device("SessionData", foraging.SessionData), + Device("FrameTop", stream.Video, stream.Position), + Device("FrameEast", stream.Video), + Device("FrameGate", stream.Video), + Device("FrameNorth", stream.Video), + Device("FramePatch1", stream.Video), + Device("FramePatch2", stream.Video), + Device("FrameSouth", stream.Video), + Device("FrameWest", stream.Video), + Device("Patch1", foraging.DepletionFunction, stream.Encoder, foraging.Feeder), + Device("Patch2", foraging.DepletionFunction, stream.Encoder, foraging.Feeder), ] ) octagon01 = DotMap( [ - Device("Metadata", core.metadata), - Device("CameraTop", core.video, core.position), - Device("CameraColorTop", core.video), - Device("ExperimentalMetadata", core.subject_state), - Device("Photodiode", octagon.photodiode), + Device("Metadata", stream.Metadata), + Device("CameraTop", stream.Video, stream.Position), + Device("CameraColorTop", stream.Video), + Device("ExperimentalMetadata", stream.SubjectState), + Device("Photodiode", octagon.Photodiode), Device("OSC", octagon.OSC), Device("TaskLogic", octagon.TaskLogic), Device("Wall1", octagon.Wall), @@ -58,55 +61,56 @@ social01 = DotMap( [ - Device("Metadata", core.metadata), - Device("Environment", social.environment_b, social.subject_b), - Device("CameraTop", core.video, social.camera_top_pos_b), - Device("CameraNorth", core.video), - Device("CameraSouth", core.video), - Device("CameraEast", core.video), - Device("CameraWest", core.video), - Device("CameraPatch1", core.video), - Device("CameraPatch2", core.video), - Device("CameraPatch3", core.video), - Device("CameraNest", core.video), - Device("Nest", social.weight_raw_b, social.weight_filtered_b), - Device("Patch1", social.patch_streams_b), - Device("Patch2", social.patch_streams_b), - Device("Patch3", social.patch_streams_b), - Device("RfidGate", social.rfid_events_social01_b), - Device("RfidNest1", social.rfid_events_social01_b), - Device("RfidNest2", social.rfid_events_social01_b), - Device("RfidPatch1", social.rfid_events_social01_b), - Device("RfidPatch2", social.rfid_events_social01_b), - Device("RfidPatch3", social.rfid_events_social01_b), + Device("Metadata", stream.Metadata), + Device("Environment", social_02.Environment, social_02.SubjectData), + Device("CameraTop", stream.Video, social_02.Pose), + Device("CameraNorth", stream.Video), + Device("CameraSouth", stream.Video), + Device("CameraEast", stream.Video), + Device("CameraWest", stream.Video), + Device("CameraPatch1", stream.Video), + Device("CameraPatch2", stream.Video), + Device("CameraPatch3", stream.Video), + Device("CameraNest", stream.Video), + Device("Nest", social_02.WeightRaw, social_02.WeightFiltered), + Device("Patch1", social_02.Patch), + Device("Patch2", social_02.Patch), + Device("Patch3", social_02.Patch), + Device("RfidGate", social_01.RfidEvents), + Device("RfidNest1", social_01.RfidEvents), + Device("RfidNest2", social_01.RfidEvents), + Device("RfidPatch1", social_01.RfidEvents), + Device("RfidPatch2", social_01.RfidEvents), + Device("RfidPatch3", social_01.RfidEvents), ] ) social02 = DotMap( [ - Device("Metadata", core.metadata), - Device("Environment", social.environment_b, social.subject_b), - Device("CameraTop", core.video, social.camera_top_pos_b), - Device("CameraNorth", core.video), - Device("CameraSouth", core.video), - Device("CameraEast", core.video), - Device("CameraWest", core.video), - Device("CameraPatch1", core.video), - Device("CameraPatch2", core.video), - Device("CameraPatch3", core.video), - Device("CameraNest", core.video), - Device("Nest", social.weight_raw_b, social.weight_filtered_b), - Device("Patch1", social.patch_streams_b), - Device("Patch2", social.patch_streams_b), - Device("Patch3", social.patch_streams_b), - Device("Patch1Rfid", social.rfid_events_b), - Device("Patch2Rfid", social.rfid_events_b), - Device("Patch3Rfid", social.rfid_events_b), - Device("NestRfid1", social.rfid_events_b), - Device("NestRfid2", social.rfid_events_b), - Device("GateRfid", social.rfid_events_b), + Device("Metadata", stream.Metadata), + Device("Environment", social_02.Environment, social_02.SubjectData), + Device("CameraTop", stream.Video, social_02.Pose), + Device("CameraNorth", stream.Video), + Device("CameraSouth", stream.Video), + Device("CameraEast", stream.Video), + Device("CameraWest", stream.Video), + Device("CameraPatch1", stream.Video), + Device("CameraPatch2", stream.Video), + Device("CameraPatch3", stream.Video), + Device("CameraNest", stream.Video), + Device("Nest", social_02.WeightRaw, social_02.WeightFiltered), + Device("Patch1", social_02.Patch), + Device("Patch2", social_02.Patch), + Device("Patch3", social_02.Patch), + Device("RfidGate", social_02.RfidEvents), + Device("RfidNest1", social_02.RfidEvents), + Device("RfidNest2", social_02.RfidEvents), + Device("RfidPatch1", social_02.RfidEvents), + Device("RfidPatch2", social_02.RfidEvents), + Device("RfidPatch3", social_02.RfidEvents), ] ) + __all__ = ["exp01", "exp02", "octagon01", "social01", "social02"] diff --git a/aeon/schema/social.py b/aeon/schema/social.py deleted file mode 100644 index 54c08302..00000000 --- a/aeon/schema/social.py +++ /dev/null @@ -1,113 +0,0 @@ -from aeon.io import reader -from aeon.io.device import Device, register -from aeon.schema import core, foraging - - -"""Creating the Social 0.1 schema""" - -# Above we've listed out all the streams we recorded from during Social0.1, but we won't care to analyze all -# of them. Instead, we'll create a DotMap schema from Device objects that only contains Readers for the -# streams we want to analyze. - -# We'll see both examples of binder functions we saw previously: 1. "empty pattern", and -# 2. "device-name passed". - -# And we'll see both examples of instantiating Device objects we saw previously: 1. from singleton binder -# functions; 2. from multiple and/or nested binder functions. - -# (Note, in the simplest case, a schema can always be created from / reduced to "empty pattern" binder -# functions as singletons in Device objects.) - -# Metadata.yml (will be a singleton binder function Device object) -# --- - -metadata = Device("Metadata", core.metadata) - -# --- - -# Environment (will be a nested, multiple binder function Device object) -# --- - -# BlockState -block_state_b = lambda pattern: { - "BlockState": reader.Csv(f"{pattern}_BlockState_*", ["pellet_ct", "pellet_ct_thresh", "due_time"]) -} - -# LightEvents -light_events_b = lambda pattern: { - "LightEvents": reader.Csv(f"{pattern}_LightEvents_*", ["channel", "value"]) -} - -# Combine EnvironmentState, BlockState, LightEvents -environment_b = lambda pattern: register( - pattern, core.environment_state, block_state_b, light_events_b, core.message_log -) - -# SubjectState -subject_state_b = lambda pattern: { - "SubjectState": reader.Csv(f"{pattern}_SubjectState_*", ["id", "weight", "type"]) -} - -# SubjectVisits -subject_visits_b = lambda pattern: { - "SubjectVisits": reader.Csv(f"{pattern}_SubjectVisits_*", ["id", "type", "region"]) -} - -# SubjectWeight -subject_weight_b = lambda pattern: { - "SubjectWeight": reader.Csv( - f"{pattern}_SubjectWeight_*", ["weight", "confidence", "subject_id", "int_id"] - ) -} - -# Separate Device object for subject-specific streams. -subject_b = lambda pattern: register(pattern, subject_state_b, subject_visits_b, subject_weight_b) -# --- - -# Camera -# --- - -camera_top_pos_b = lambda pattern: {"Pose": reader.Pose(f"{pattern}_test-node1*")} - -# --- - -# Nest -# --- - -weight_raw_b = lambda pattern: {"WeightRaw": reader.Harp(f"{pattern}_200_*", ["weight(g)", "stability"])} -weight_filtered_b = lambda pattern: { - "WeightFiltered": reader.Harp(f"{pattern}_202_*", ["weight(g)", "stability"]) -} - -# --- - -# Patch -# --- - -# Combine streams for Patch device -patch_streams_b = lambda pattern: register( - pattern, - foraging.pellet_depletion_state, - core.encoder, - foraging.feeder, - foraging.pellet_manual_delivery, - foraging.missed_pellet, - foraging.pellet_retried_delivery, -) -# --- - -# Rfid -# --- - - -def rfid_events_social01_b(pattern): - """RFID events reader (with social0.1 specific logic)""" - pattern = pattern.replace("Rfid", "") - if pattern.startswith("Events"): - pattern = pattern.replace("Events", "") - return {"RfidEvents": reader.Harp(f"RfidEvents{pattern}_*", ["rfid"])} - - -def rfid_events_b(pattern): - """RFID events reader""" - return {"RfidEvents": reader.Harp(f"{pattern}_32*", ["rfid"])} diff --git a/aeon/schema/social_01.py b/aeon/schema/social_01.py new file mode 100644 index 00000000..becfc252 --- /dev/null +++ b/aeon/schema/social_01.py @@ -0,0 +1,12 @@ +import aeon.io.reader as _reader +from aeon.schema.streams import Stream + + +class RfidEvents(Stream): + + def __init__(self, path): + path = path.replace("Rfid", "") + if path.startswith("Events"): + path = path.replace("Events", "") + + super().__init__(_reader.Harp(f"RfidEvents{path}_32*", ["rfid"])) diff --git a/aeon/schema/social_02.py b/aeon/schema/social_02.py new file mode 100644 index 00000000..44c26c91 --- /dev/null +++ b/aeon/schema/social_02.py @@ -0,0 +1,88 @@ +import aeon.io.reader as _reader +from aeon.schema.streams import Stream, StreamGroup +from aeon.schema import core, foraging + + +class Environment(StreamGroup): + + def __init__(self, path): + super().__init__(path) + + EnvironmentState = core.EnvironmentState + + class BlockState(Stream): + def __init__(self, path): + super().__init__(_reader.Csv(f"{path}_BlockState_*", columns=["pellet_ct", "pellet_ct_thresh", "due_time"])) + + class LightEvents(Stream): + def __init__(self, path): + super().__init__(_reader.Csv(f"{path}_LightEvents_*", columns=["channel", "value"])) + + MessageLog = core.MessageLog + + +class SubjectData(StreamGroup): + def __init__(self, path): + super().__init__(path) + + class SubjectState(Stream): + def __init__(self, path): + super().__init__(_reader.Csv(f"{path}_SubjectState_*", columns=["id", "weight", "type"])) + + class SubjectVisits(Stream): + def __init__(self, path): + super().__init__(_reader.Csv(f"{path}_SubjectVisits_*", columns=["id", "type", "region"])) + + class SubjectWeight(Stream): + def __init__(self, path): + super().__init__(_reader.Csv(f"{path}_SubjectWeight_*", columns=["weight", "confidence", "subject_id", "int_id"])) + + +class Pose(Stream): + + def __init__(self, path): + super().__init__(_reader.Pose(f"{path}_test-node1*")) + + +class WeightRaw(Stream): + + def __init__(self, path): + super().__init__(_reader.Harp(f"{path}_200_*", ["weight(g)", "stability"])) + + +class WeightFiltered(Stream): + + def __init__(self, path): + super().__init__(_reader.Harp(f"{path}_202_*", ["weight(g)", "stability"])) + + +class Patch(StreamGroup): + + def __init__(self, path): + super().__init__(path) + + class DepletionState(Stream): + def __init__(self, path): + super().__init__(_reader.Csv(f"{path}_State_*", columns=["threshold", "offset", "rate"])) + + Encoder = core.Encoder + + Feeder = foraging.Feeder + + class ManualDelivery(Stream): + def __init__(self, path): + super().__init__(_reader.Harp(f"{path}_201_*", ["manual_delivery"])) + + class MissedPellet(Stream): + def __init__(self, path): + super().__init__(_reader.Harp(f"{path}_202_*", ["missed_pellet"])) + + class RetriedDelivery(Stream): + def __init__(self, path): + super().__init__(_reader.Harp(f"{path}_203_*", ["retried_delivery"])) + + +class RfidEvents(Stream): + + def __init__(self, path): + super().__init__(_reader.Harp(f"{path}_32*", ["rfid"]))