Example #1
0
def get_trial_reward_time(rebased_reward_times, start_time, stop_time):
    '''extract reward times in time range'''
    reward_times = rebased_reward_times[np.where(np.logical_and(
        rebased_reward_times >= start_time, 
        rebased_reward_times <= stop_time
    ))]
    return float('nan') if len(reward_times) == 0 else one(reward_times)
Example #2
0
def get_dprime(hit_rate, fa_rate, sliding_window=SLIDING_WINDOW):
    """ calculates the d-prime for a given hit rate and false alarm rate
    https://en.wikipedia.org/wiki/Sensitivity_index
    Parameters
    ----------
    hit_rate : float
        rate of hits in the True class
    fa_rate : float
        rate of false alarms in the False class
    limits : tuple, optional
        limits on extreme values, which distort. default: (0.01,0.99)
    Returns
    -------
    d_prime
    """

    limits = (1/SLIDING_WINDOW, 1 - 1/SLIDING_WINDOW)
    assert limits[0] > 0.0, 'limits[0] must be greater than 0.0'
    assert limits[1] < 1.0, 'limits[1] must be less than 1.0'
    Z = norm.ppf

    # Limit values in order to avoid d' infinity
    hit_rate = np.clip(hit_rate, limits[0], limits[1])
    fa_rate = np.clip(fa_rate, limits[0], limits[1])
    d_prime = Z(pd.Series(hit_rate)) - Z(pd.Series(fa_rate))
    return one(d_prime)
Example #3
0
 def _get_reward_time(rebased_reward_times,
                      start_time,
                      stop_time) -> float:
     """extract reward times in time range"""
     reward_times = rebased_reward_times[np.where(np.logical_and(
         rebased_reward_times >= start_time,
         rebased_reward_times <= stop_time
     ))]
     return float('nan') if len(reward_times) == 0 else one(
         reward_times)
Example #4
0
def find_licks(reward_times, licks, window=3.5):
    if len(reward_times) == 0:
        return []
    else:
        reward_time = one(reward_times)
        reward_lick_mask = ((licks['time'] > reward_time) & (licks['time'] < (reward_time + window)))

        tr_licks = licks[reward_lick_mask].copy()
        tr_licks['time'] -= reward_time
        return tr_licks['time'].values
Example #5
0
 def fetchall(self, query, strict=True):
     response = self.select(query)
     return [one(x) for x in response.values.flat]
Example #6
0
 def fetchone(self, query, strict=True):
     response = one(list(self.select(query).to_dict().values()))
     if strict is True and (len(response) != 1 or response[0] is None):
         raise OneResultExpectedError
     return response[0]
Example #7
0
 def get_image_index_names(self):
     image_index_names = self.get_stimulus_presentations().groupby(
         'image_index').apply(
             lambda group: one(group['image_name'].unique()))
     return image_index_names