Closed theilmbh closed 8 years ago
hmm. I have no problem loading the acute block at /mnt/cube/ephys-example-data/Pen01_Lft_AP100_ML1300__Site03_Z2500__B1056_cat_P01_S03_1/
wait, hold on. that was with some older code. just a sec
yep. no problems with latest
from ephys import events
block_path = '/mnt/cube/ephys-example-data/Pen01_Lft_AP100_ML1300__Site03_Z2500__B1056_cat_P01_S03_1/'
trials = events.get_trials(block_path)
print trials.head()
Output:
recording time_samples stimulus stimulus_end response \
0 0 125068 D_scaled_burung 331790 NaN
1 0 440996 D_scaled_burung 647718 NaN
2 0 780458 D_scaled_burung 987180 NaN
3 0 1109634 H_scaled_burung 1316357 NaN
4 0 1399201 L_scaled_burung 1605920 NaN
response_time consequence correct
0 NaN NaN NaN
1 NaN NaN NaN
2 NaN NaN NaN
3 NaN NaN NaN
4 NaN NaN NaN
I run the exact same code and get this:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-5-7c06945441e5> in <module>()
1 from ephys import events
2 block_path = '/mnt/cube/ephys-example-data/Pen01_Lft_AP100_ML1300__Site03_Z2500__B1056_cat_P01_S03_1/'
----> 3 trials = events.get_trials(block_path)
4 print trials.head()
/home/btheilma/code/ephys-analysis/ephys/events.py in get_trials(block_path)
239 trials['response'] = trials.apply(lambda row: get_response(row,digmarks,fs)['codes'],axis=1)
240 trials['response_time'] = trials.apply(lambda row: get_response(row,digmarks,fs)['time_samples'],axis=1)
--> 241 trials['consequence'] = trials.apply(lambda row: get_consequence(row,digmarks,fs)['codes'],axis=1)
242 trials['correct'] = trials['consequence'].apply(is_correct)
243 return trials
/usr/local/anaconda/lib/python2.7/site-packages/pandas/core/frame.pyc in apply(self, func, axis, broadcast, raw, reduce, args, **kwds)
3716 if reduce is None:
3717 reduce = True
-> 3718 return self._apply_standard(f, axis, reduce=reduce)
3719 else:
3720 return self._apply_broadcast(f, axis)
/usr/local/anaconda/lib/python2.7/site-packages/pandas/core/frame.pyc in _apply_standard(self, func, axis, ignore_failures, reduce)
3806 try:
3807 for i, v in enumerate(series_gen):
-> 3808 results[i] = func(v)
3809 keys.append(v.name)
3810 except Exception as e:
/home/btheilma/code/ephys-analysis/ephys/events.py in <lambda>(row)
239 trials['response'] = trials.apply(lambda row: get_response(row,digmarks,fs)['codes'],axis=1)
240 trials['response_time'] = trials.apply(lambda row: get_response(row,digmarks,fs)['time_samples'],axis=1)
--> 241 trials['consequence'] = trials.apply(lambda row: get_consequence(row,digmarks,fs)['codes'],axis=1)
242 trials['correct'] = trials['consequence'].apply(is_correct)
243 return trials
/home/btheilma/code/ephys-analysis/ephys/events.py in get_consequence(trial_row, digmarks, fs, window)
179 & (digmarks['time_samples']>bds[0])
180 & (digmarks['time_samples']<bds[1])
--> 181 & digmarks['codes'].str.contains('[FfTt]')
182 )
183 if digmarks[resp_mask].shape[0]>0:
/usr/local/anaconda/lib/python2.7/site-packages/pandas/core/ops.pyc in wrapper(self, other, axis)
606 else:
607 values = self.get_values()
--> 608 other = _index.convert_scalar(values,_values_from_object(other))
609
610 if issubclass(values.dtype.type, (np.datetime64, np.timedelta64)):
pandas/index.pyx in pandas.index.convert_scalar (pandas/index.c:12052)()
pandas/index.pyx in pandas.index.convert_scalar (pandas/index.c:11937)()
ValueError: ('Cannot assign nan to integer series', u'occurred at index 0')
Are you sure you've pulled my latest changes?
& digmarks['codes'].str.contains('[FfTt]')
is currently line 179, not 180 as your error says:
https://github.com/gentnerlab/ephys-analysis/blob/justin/ephys/events.py#L179
I guess I missed them. Been waiting for all of the core functionality to make it into master
Ok, that works now
And for some reason today it doesn't work.
When building the trial dataframe from acute data, everything goes well up until line 241 where consequences get assigned. The problem stems from the fact that both 'response' and 'response_time' get filled in with nans because this is an acute trial. get_consequence tries to get the response time to build the bounds for the mask, but because the response time is nan, this results in a type conversion error in pandas.
get_consequence should check if reponse_time is nan before doing anything else.