Coverage for ibllib/io/extractors/opto_trials.py: 0%

26 statements  

« prev     ^ index     » next       coverage.py v7.7.0, created at 2025-03-17 15:25 +0000

1import logging 

2import numpy as np 

3 

4from ibllib.io.extractors.base import BaseBpodTrialsExtractor 

5 

6_logger = logging.getLogger(__name__) 

7 

8 

9class LaserBool(BaseBpodTrialsExtractor): 

10 """ 

11 Extracts the laser probabilities from the bpod jsonable 

12 """ 

13 save_names = ('_ibl_trials.laserStimulation.npy', '_ibl_trials.laserProbability.npy') 

14 var_names = ('laserStimulation', 'laserProbability') 

15 

16 def _extract(self, **kwargs): 

17 _logger.info('Extracting laser datasets') 

18 # reference pybpod implementation 

19 lstim = np.array([float(t.get('laser_stimulation', np.nan)) for t in self.bpod_trials]) 

20 lprob = np.array([float(t.get('laser_probability', np.nan)) for t in self.bpod_trials]) 

21 

22 # Karolina's choice world legacy implementation - from Slack message: 

23 # it is possible that some versions I have used: 

24 # 1) opto_ON_time (NaN - no laser or some number-laser) 

25 # opto_ON_time=~isnan(opto_ON_time) 

26 # laserON_trials=(opto_ON_time==1); 

27 # laserOFF_trials=(opto_ON_time==0); 

28 # 2) optoOUT (0 - no laser or 255 - laser): 

29 # laserON_trials=(optoOUT ==255); 

30 # laserOFF_trials=(optoOUT ==0); 

31 if 'PROBABILITY_OPTO' in self.settings.keys() and np.all(np.isnan(lstim)): 

32 lprob = np.zeros_like(lprob) + self.settings['PROBABILITY_OPTO'] 

33 lstim = np.array([float(t.get('opto_ON_time', np.nan)) for t in self.bpod_trials]) 

34 if np.all(np.isnan(lstim)): 

35 lstim = np.array([float(t.get('optoOUT', np.nan)) for t in self.bpod_trials]) 

36 lstim[lstim == 255] = 1 

37 else: 

38 lstim[~np.isnan(lstim)] = 1 

39 lstim[np.isnan(lstim)] = 0 

40 

41 if np.all(np.isnan(lprob)): 

42 # this prevents the file from being saved when no data 

43 self.save_names = ('_ibl_trials.laserStimulation.npy', None) 

44 _logger.warning('No laser probability found in bpod data') 

45 if np.all(np.isnan(lstim)): 

46 # this prevents the file from being saved when no data 

47 self.save_names = (None, '_ibl_trials.laserProbability.npy') 

48 _logger.warning('No laser stimulation found in bpod data') 

49 return lstim, lprob