Skip to content

Commit b7ba418

Browse files
committed
foraging translator conforms to schema
1 parent 68bbe77 commit b7ba418

3 files changed

Lines changed: 39 additions & 11 deletions

File tree

tests/translator/test_translator_functional.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from visual_behavior.schemas.extended_trials import ExtendedTrialSchema
55
from visual_behavior.translator import foraging2, foraging
66
from visual_behavior.translator.core import create_extended_dataframe
7+
from visual_behavior.uuid_utils import create_session_uuid
78

89

910
"""test the schemas vs the outputs here
@@ -50,10 +51,20 @@ def test_foraging2_translator_schema(foraging2_data_stage4_2018_05_10):
5051
core_data = foraging2.data_to_change_detection_core(
5152
foraging2_data_stage4_2018_05_10
5253
)
54+
core_data['metadata']['behavior_session_uuid'] = create_session_uuid(
55+
core_data['metadata']['mouseid'],
56+
core_data['metadata']['startdatetime'],
57+
)
5358
_test_core_data_schemas(core_data)
5459

5560
def test_foraging_translator_schema(behavioral_session_output_fixture):
5661
core_data = foraging.data_to_change_detection_core(
5762
behavioral_session_output_fixture
5863
)
64+
65+
core_data['metadata']['behavior_session_uuid'] = create_session_uuid(
66+
str(core_data['metadata']['mouseid']),
67+
core_data['metadata']['startdatetime'],
68+
)
69+
5970
_test_core_data_schemas(core_data)

visual_behavior/schemas/core.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ class RewardSchema(TimeSeriesSchema):
2020
""" schema for water reward presentations
2121
2222
"""
23-
volume = fields.Float(
24-
description='Volume of water dispensed on this reward presentation in mL',
25-
required=True,
26-
)
23+
# volume = fields.Float(
24+
# description='Volume of water dispensed on this reward presentation in mL',
25+
# required=True,
26+
# )
2727
# lickspout = fields.Int(
2828
# description='The water line on which this reward was dispensed',
2929
# required=True,

visual_behavior/translator/foraging/__init__.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import pandas as pd
33
import numpy as np
44
from scipy.signal import medfilt
5+
from .extract import get_end_time
56
from ...utilities import calc_deriv, rad_to_dist, local_time
67

78
warnings.warn(
@@ -83,13 +84,23 @@ def load_metadata(data):
8384

8485

8586
metadata['auto_reward_vol'] = 0.05 # hard coded
86-
metadata['max_session_duration'] = None
87-
metadata['min_no_lick_time'] = data.get('minimum_no_lick_time', None)
88-
metadata['free_reward_trials'] = data.get('warm_up_trials', None)
89-
metadata['abort_on_early_response'] = data.get('ignore_false_alarms', False) == False
90-
metadata['even_sampling_enabled'] = data.get('image_category_sampling_mode','') == 'even_sampling'
91-
metadata['failure_repeats'] = data.get('max_number_trial_repeats', None)
87+
metadata['max_session_duration'] = 60.0 # hard coded
88+
metadata['min_no_lick_time'] = data['minimum_no_lick_time']
89+
metadata['abort_on_early_response'] = data['ignore_false_alarms'] == False
90+
metadata['even_sampling_enabled'] = data['image_category_sampling_mode'] == 'even_sampling'
91+
metadata['failure_repeats'] = data['max_number_trial_repeats']
92+
metadata['catch_frequency'] = data['catch_frequency']
93+
metadata['volume_limit'] = data['volumelimit']
94+
metadata['initial_blank_duration'] = data['initial_blank']
95+
metadata['warm_up_trials'] = data['warmup_trials']
96+
metadata['stimulus_window'] = data['trial_duration'] - data['delta_minimum']
97+
98+
block_length = data['lick_detect_training_block_length']
9299

100+
try:
101+
metadata['free_reward_trials'] = block_length[0]
102+
except TypeError:
103+
metadata['free_reward_trials'] = block_length
93104

94105
return metadata
95106

@@ -107,6 +118,9 @@ def load_trials(data, time=None):
107118
108119
"""
109120

121+
if time is None:
122+
time = load_time(data)
123+
110124
columns = (
111125
'auto_rewarded',
112126
'change_contrast',
@@ -185,7 +199,10 @@ def stringify(x):
185199

186200
# add endframe column as startframe of last frame. Last endframe is last frame of session
187201
trials['endframe'] = trials['startframe'].shift(periods=-1)
188-
trials.at[trials.index[-1], 'endframe'] = len(load_time(data)) - 1
202+
trials.at[trials.index[-1], 'endframe'] = len(time) - 1
203+
204+
trials['endtime'] = get_end_time(trials, time)
205+
trials['trial_length'] = trials['endtime'] - trials['starttime']
189206

190207
return trials
191208

0 commit comments

Comments
 (0)