Skip to content

Commit 68bbe77

Browse files
Justin Kigginsneuromusic
authored andcommitted
work in progress
1 parent a9e608c commit 68bbe77

4 files changed

Lines changed: 87 additions & 12 deletions

File tree

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,59 @@
1-
from visual_behavior.translator import schemas
1+
2+
from visual_behavior.schemas.core import MetadataSchema, StimulusSchema, \
3+
RunningSchema, LickSchema, RewardSchema, TrialSchema
4+
from visual_behavior.schemas.extended_trials import ExtendedTrialSchema
5+
from visual_behavior.translator import foraging2, foraging
6+
from visual_behavior.translator.core import create_extended_dataframe
27

38

49
"""test the schemas vs the outputs here
510
"""
11+
12+
def _test_core_data_schemas(core_data):
13+
14+
# metadata
15+
16+
# core dataframes
17+
dataframe_schemas = (
18+
(StimulusSchema, core_data['visual_stimuli']),
19+
(RunningSchema, core_data['running']),
20+
(LickSchema, core_data['licks']),
21+
(RewardSchema, core_data['rewards']),
22+
(TrialSchema, core_data['trials']),
23+
)
24+
25+
for Schema, data in dataframe_schemas:
26+
errors = Schema(many=True).validate(data.to_dict(orient='records'))
27+
28+
for row, row_errors in errors.items():
29+
assert len(row_errors)==0, (Schema, data, row_errors)
30+
31+
extended_trials = create_extended_dataframe(
32+
trials=core_data['trials'],
33+
metadata=core_data['metadata'],
34+
licks=core_data['licks'],
35+
time=core_data['time'],
36+
)
37+
38+
errors = ExtendedTrialSchema(many=True).validate(
39+
extended_trials.to_dict(orient='records')
40+
)
41+
42+
for row, row_errors in errors.items():
43+
assert len(row_errors)==0, row_errors
44+
45+
errors = MetadataSchema().validate(core_data['metadata'])
46+
assert len(errors)==0, errors.keys()
47+
48+
49+
def test_foraging2_translator_schema(foraging2_data_stage4_2018_05_10):
50+
core_data = foraging2.data_to_change_detection_core(
51+
foraging2_data_stage4_2018_05_10
52+
)
53+
_test_core_data_schemas(core_data)
54+
55+
def test_foraging_translator_schema(behavioral_session_output_fixture):
56+
core_data = foraging.data_to_change_detection_core(
57+
behavioral_session_output_fixture
58+
)
59+
_test_core_data_schemas(core_data)

visual_behavior/schemas/core.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,13 @@ class StimulusSchema(TimeSeriesSchema):
208208
required=True,
209209
allow_none=True,
210210
)
211-
contrast = fields.Float(
212-
description='The contrast of a grating stimulus',
211+
orientation = fields.Float(
212+
description='The orientation of a grating stimulus',
213213
required=True,
214214
allow_none=True,
215215
)
216-
orientation = fields.Float(
217-
description='The orientation of a grating stimulus',
216+
end_frame = fields.Int(
217+
description='The last frame of this stimulus, non-inclusive',
218218
required=True,
219219
)
220220

@@ -298,7 +298,7 @@ class MetadataSchema(Schema):
298298
description='total number of stimulus frames',
299299
required=True,
300300
)
301-
auto_reward_volume = fields.Float(
301+
auto_reward_vol = fields.Float(
302302
description='volume provided during autoreward trials',
303303
required=True,
304304
)
@@ -326,6 +326,26 @@ class MetadataSchema(Schema):
326326
description='maximum number of times to repeat parameters after a false alarm',
327327
required=True,
328328
)
329+
initial_blank_duration = fields.Float(
330+
description='duration of grey screen at start of each trial, in seconds',
331+
required=True,
332+
)
333+
catch_frequency = fields.Float(
334+
description='fraction of trials that should be catch trials',
335+
required=True,
336+
)
337+
warm_up_trials = fields.Int(
338+
description='number of warm up trials at start of session',
339+
required=True,
340+
)
341+
stimulus_window = fields.Float(
342+
description='start and stop times of stimulus window',
343+
required=True,
344+
)
345+
volume_limit = fields.Float(
346+
description='maximum volume of water to deliver in a session, in mL',
347+
required=True,
348+
)
329349

330350

331351
# class ChangeDetectionSessionCoreSchema(Schema):

visual_behavior/translator/foraging/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ def load_running_speed(data, smooth=False, time=None):
282282

283283
running_speed = pd.DataFrame({
284284
'time': time,
285+
'frame': range(len(time)),
285286
'speed': speed,
286287
# 'acceleration (cm/s^2)': accel,
287288
# 'jerk (cm/s^3)': jerk,
@@ -339,15 +340,15 @@ def load_visual_stimuli(data, time=None):
339340
stimdf = pd.DataFrame(data['stimuluslog'])
340341

341342
stimdf = find_ends(stimdf)
342-
stimdf['end'] = stimdf['frames_to_end'] + stimdf['frame']
343+
stimdf['end_frame'] = stimdf['frames_to_end'] + stimdf['frame']
343344

344345
def find_time(fr):
345346
try:
346347
return time[fr]
347348
except IndexError:
348349
return np.nan
349350

350-
stimdf['end_time'] = stimdf['end'].map(find_time)
351+
stimdf['end_time'] = stimdf['end_frame'].map(find_time)
351352
stimdf['duration'] = stimdf['end_time'] - stimdf['time']
352353

353354
onset_mask = (
@@ -358,13 +359,13 @@ def find_time(fr):
358359
) > 0
359360

360361
if pd.isnull(stimdf['image_name']).any() == False: # 'image_category' in stimdf.columns:
361-
cols = ['frame', 'time', 'duration', 'image_category', 'image_name']
362+
cols = ['frame', 'end_frame', 'time', 'duration', 'image_category', 'image_name']
362363
stimuli = stimdf[onset_mask][cols]
363364
stimuli['orientation'] = None
364365
stimuli['contrast'] = None
365366

366367
elif 'ori' in stimdf.columns:
367-
cols = ['frame', 'time', 'duration', 'ori', 'contrast']
368+
cols = ['frame', 'end_frame', 'time', 'duration', 'ori', 'contrast']
368369
stimuli = stimdf[onset_mask][cols]
369370
stimuli.rename(columns={'ori': 'orientation'}, inplace=True)
370371
stimuli['image_category'] = None

visual_behavior/translator/foraging2/extract.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -725,8 +725,8 @@ def get_running_speed(exp_data, smooth=False, time=None):
725725
running_speed = pd.DataFrame({
726726
'time': time,
727727
'speed (cm/s)': speed,
728-
'acceleration (cm/s^2)': accel,
729-
'jerk (cm/s^3)': jerk,
728+
# 'acceleration (cm/s^2)': accel,
729+
# 'jerk (cm/s^3)': jerk,
730730
})
731731
return running_speed
732732

0 commit comments

Comments
 (0)