11import logging
22
33import numpy as np
4+ import pandas as pd
45
56from iblrig import sound
67from iblrig .base_tasks import BaseSession , BpodMixin
@@ -30,6 +31,23 @@ def __init__(self, *args, **kwargs):
3031 )
3132 Session .frequencies = np .round (self .frequencies ).astype (int )
3233
34+ # get LUT (or create new one based on frequencies)
35+ attenuation_file = self .get_task_directory ().joinpath ('attenuation.csv' )
36+ if attenuation_file .exists ():
37+ self .attenuation_lut = pd .read_csv (self .get_task_directory ().joinpath ('attenuation.csv' ))
38+ else :
39+ self .attenuation_lut = pd .DataFrame (
40+ {'frequency_hz' : self .frequencies , 'attenuation_db' : np .zeros (self .n_frequencies )}
41+ )
42+ self .attenuation_lut .to_csv (attenuation_file , index = False )
43+
44+ # get attenuation values from LUT (linear interpolation for missing values)
45+ self .attenuation = np .interp (
46+ self .frequencies ,
47+ self .attenuation_lut ['frequency_hz' ],
48+ self .attenuation_lut ['attenuation_db' ],
49+ )
50+
3351 # calculate repetitions per state machine run (255 states max)
3452 self .repetitions = []
3553 max_reps_per_trial = 255 // self .n_frequencies
@@ -40,21 +58,19 @@ def __init__(self, *args, **kwargs):
4058
4159 # generate stimuli
4260 self .stimuli = []
43- for f in self .frequencies :
61+ for idx , f in enumerate ( self .frequencies ) :
4462 tmp = sound .make_sound (
4563 rate = self .task_params ['fs' ],
4664 frequency = f ,
4765 duration = self .task_params ['d_sound' ],
4866 amplitude = self .task_params ['amplitude' ],
4967 fade = self .task_params ['d_ramp' ],
5068 chans = 'stereo' ,
51- gain_db = 0 ,
69+ gain_db = self . attenuation [ idx ] ,
5270 )
5371 self .stimuli .append (tmp )
5472 self .indices = [i for i in range (2 , len (self .stimuli ) + 2 )]
5573
56- # self.attenuation = pd.read_csv(self.get_task_directory().joinpath('attenuation.csv'))
57-
5874 @property
5975 def n_frequencies (self ):
6076 return len (self .frequencies )
0 commit comments