auto-pi-lot / autopilot

Distributed behavioral experiments
https://docs.auto-pi-lot.com
Mozilla Public License 2.0
93 stars 24 forks source link

session discontinuity detection problem with where #189

Open cxrodgers opened 2 years ago

cxrodgers commented 2 years ago

I get this error:

                    ERROR    [data.subject.Subject.DistractorTaskHigh220726_v7] Couldnt trim data given to graduation objects to current set of sessions, using    subject.py:781
                             full data history. got exception                                                                                                                    
                              only size-1 arrays can be converted to Python scalars                                                                                              
                             ╭──────────────────────────────────────────────── Traceback (most recent call last) ────────────────────────────────────────────────╮               
                             │                                                                                                                                   │               
                             │ /home/mouse/dev/autopilot/autopilot/data/subject.py:778 in _trim_trial_to_session                                                 │               
                             │                                                                                                                                   │               
                             │    775 │   │   │   │   │   │   # fine, use the whole thing                                                                        │               
                             │    776 │   │   │   │   │   │   pass                                                                                               │               
                             │    777 │   │   │   │   │   else:                                                                                                  │               
                             │ ❱  778 │   │   │   │   │   │   slice_start = int(discontinuities[-1]+1)                                                           │               
                             │    779 │   │   │                                                                                                                  │               
                             │    780 │   │   │   except Exception as e:                                                                                         │               
                             │    781 │   │   │   │   self.logger.exception(                                                                                     │               
                             ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯               
                             TypeError: only size-1 arrays can be converted to Python scalars 

From quickly perusing the code, I am pretty sure this is the classic gotcha with np.where, in which its result always needs to be indexed with [0]. (np.where should be rewritten to do this automatically when the input data is 1d in my opinion)

for example:

In [3]: np.where(np.array([1,2,3]) == 2)
Out[3]: (array([1]),)

In [4]: np.where(np.array([1,2,3]) == 2)[0]
Out[4]: array([1])

fix (?) is here: https://github.com/Rodgers-PAC-Lab/autopilot/commit/3caefcc68b2fa718daf727c5cb329af3ec8d6a40