@@ -111,14 +111,14 @@ def get_sessions(subj, date=None, one=None):
111111 latest_sess = date
112112
113113 sessions = one .alyx .rest ('sessions' , 'list' , subject = subj , date_range = [latest_minus_week ,
114- latest_sess ], dataset_types = 'trials.intervals ' )
114+ latest_sess ], dataset_types = 'trials.goCueTrigger_times ' )
115115
116116 # If not enough sessions in the last week, then just fetch them all
117117 if len (sessions ) < 3 :
118118 specified_date_plus = (specified_date + datetime .timedelta (days = 1 )).strftime ("%Y-%m-%d" )
119119 django_query = 'start_time__lte,' + specified_date_plus
120120 sessions = one .alyx .rest ('sessions' , 'list' , subject = subj ,
121- dataset_types = 'trials.intervals ' , django = django_query )
121+ dataset_types = 'trials.goCueTrigger_times ' , django = django_query )
122122
123123 # If still 0 sessions then return with warning
124124 if len (sessions ) == 0 :
@@ -349,7 +349,7 @@ def compute_training_info(trials, trials_all):
349349 perf_easy = np .array ([compute_performance_easy (trials [k ]) for k in trials .keys ()])
350350 n_trials = np .array ([compute_n_trials (trials [k ]) for k in trials .keys ()])
351351 psych = compute_psychometric (trials_all , signed_contrast = signed_contrast )
352- rt = compute_median_reaction_time (trials_all , signed_contrast = signed_contrast )
352+ rt = compute_median_reaction_time (trials_all , contrast = 0 , signed_contrast = signed_contrast )
353353
354354 return perf_easy , n_trials , psych , rt
355355
@@ -376,7 +376,7 @@ def compute_bias_info(trials, trials_all):
376376 n_trials = np .array ([compute_n_trials (trials [k ]) for k in trials .keys ()])
377377 psych_20 = compute_psychometric (trials_all , signed_contrast = signed_contrast , block = 0.2 )
378378 psych_80 = compute_psychometric (trials_all , signed_contrast = signed_contrast , block = 0.8 )
379- rt = compute_median_reaction_time (trials_all , signed_contrast = signed_contrast )
379+ rt = compute_median_reaction_time (trials_all , contrast = 0 , signed_contrast = signed_contrast )
380380
381381 return perf_easy , n_trials , psych_20 , psych_80 , rt
382382
@@ -452,7 +452,7 @@ def compute_n_trials(trials):
452452 return trials ['choice' ].shape [0 ]
453453
454454
455- def compute_psychometric (trials , signed_contrast = None , block = None ):
455+ def compute_psychometric (trials , signed_contrast = None , block = None , plotting = False ):
456456 """
457457 Compute psychometric fit parameters for trials object
458458
@@ -479,17 +479,27 @@ def compute_psychometric(trials, signed_contrast=None, block=None):
479479 prob_choose_right , contrasts , n_contrasts = compute_performance (trials , signed_contrast = signed_contrast , block = block ,
480480 prob_right = True )
481481
482- psych , _ = psy .mle_fit_psycho (
483- np .vstack ([contrasts , n_contrasts , prob_choose_right ]),
484- P_model = 'erf_psycho_2gammas' ,
485- parstart = np .array ([np .mean (contrasts ), 20. , 0.05 , 0.05 ]),
486- parmin = np .array ([np .min (contrasts ), 0. , 0. , 0. ]),
487- parmax = np .array ([np .max (contrasts ), 100. , 1 , 1 ]))
482+ if plotting :
483+ psych , _ = psy .mle_fit_psycho (
484+ np .vstack ([contrasts , n_contrasts , prob_choose_right ]),
485+ P_model = 'erf_psycho_2gammas' ,
486+ parstart = np .array ([0. , 40. , 0.1 , 0.1 ]),
487+ parmin = np .array ([- 50. , 10. , 0. , 0. ]),
488+ parmax = np .array ([50. , 50. , 0.2 , 0.2 ]),
489+ nfits = 10 )
490+ else :
491+
492+ psych , _ = psy .mle_fit_psycho (
493+ np .vstack ([contrasts , n_contrasts , prob_choose_right ]),
494+ P_model = 'erf_psycho_2gammas' ,
495+ parstart = np .array ([np .mean (contrasts ), 20. , 0.05 , 0.05 ]),
496+ parmin = np .array ([np .min (contrasts ), 0. , 0. , 0. ]),
497+ parmax = np .array ([np .max (contrasts ), 100. , 1 , 1 ]))
488498
489499 return psych
490500
491501
492- def compute_median_reaction_time (trials , stim_on_type = 'stimOn_times' , signed_contrast = None ):
502+ def compute_median_reaction_time (trials , stim_on_type = 'stimOn_times' , contrast = None , signed_contrast = None ):
493503 """
494504 Compute median reaction time on zero contrast trials from trials object
495505
@@ -505,10 +515,15 @@ def compute_median_reaction_time(trials, stim_on_type='stimOn_times', signed_con
505515 """
506516 if signed_contrast is None :
507517 signed_contrast = get_signed_contrast (trials )
508- zero_trials = (trials .response_times - trials [stim_on_type ])[signed_contrast == 0 ]
509- if np .any (zero_trials ):
518+
519+ if contrast is None :
520+ contrast_idx = np .full (trials .probabilityLeft .shape , True , dtype = bool )
521+ else :
522+ contrast_idx = signed_contrast == contrast
523+
524+ if np .any (contrast_idx ):
510525 reaction_time = np .nanmedian ((trials .response_times - trials [stim_on_type ])
511- [signed_contrast == 0 ])
526+ [contrast_idx ])
512527 else :
513528 reaction_time = np .nan
514529
@@ -590,15 +605,15 @@ def plot_psychometric(trials, ax=None, title=None, **kwargs):
590605 contrasts_fit = np .arange (- 100 , 100 )
591606
592607 prob_right_50 , contrasts_50 , _ = compute_performance (trials , signed_contrast = signed_contrast , block = 0.5 , prob_right = True )
593- pars_50 = compute_psychometric (trials , signed_contrast = signed_contrast , block = 0.5 )
608+ pars_50 = compute_psychometric (trials , signed_contrast = signed_contrast , block = 0.5 , plotting = True )
594609 prob_right_fit_50 = psy .erf_psycho_2gammas (pars_50 , contrasts_fit )
595610
596611 prob_right_20 , contrasts_20 , _ = compute_performance (trials , signed_contrast = signed_contrast , block = 0.2 , prob_right = True )
597- pars_20 = compute_psychometric (trials , signed_contrast = signed_contrast , block = 0.2 )
612+ pars_20 = compute_psychometric (trials , signed_contrast = signed_contrast , block = 0.2 , plotting = True )
598613 prob_right_fit_20 = psy .erf_psycho_2gammas (pars_20 , contrasts_fit )
599614
600615 prob_right_80 , contrasts_80 , _ = compute_performance (trials , signed_contrast = signed_contrast , block = 0.8 , prob_right = True )
601- pars_80 = compute_psychometric (trials , signed_contrast = signed_contrast , block = 0.8 )
616+ pars_80 = compute_psychometric (trials , signed_contrast = signed_contrast , block = 0.8 , plotting = True )
602617 prob_right_fit_80 = psy .erf_psycho_2gammas (pars_80 , contrasts_fit )
603618
604619 cmap = sns .diverging_palette (20 , 220 , n = 3 , center = "dark" )
0 commit comments