How to use the pulse2percept.utils function in pulse2percept

To help you get started, we’ve selected a few pulse2percept examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pulse2percept / pulse2percept / pulse2percept / effectivecurrent2brightness.py View on Github external
else:
            resp_nfl = np.zeros((ecm[1].data.shape))

        # Here we are converting from current  - where a cathodic (effective)
        # stimulus is negative - to a vague concept of neuronal response,
        # where positive implies a neuronal response.
        # There is a rectification here because we used to assume that the
        # anodic part of the pulse is ineffective (which is wrong).
        resp_cathodic = self.lweight * np.maximum(-resp_inl, 0) + \
            np.maximum(-resp_nfl, 0)
        resp_anodic = self.lweight * np.maximum(resp_inl, 0) + \
            np.maximum(resp_nfl, 0)
        resp = resp_cathodic + self.aweight * resp_anodic
        resp = self.stationary_nonlinearity(resp)
        resp = self.slow_response(resp)
        return utils.TimeSeries(self.tsample, resp)
github pulse2percept / pulse2percept / pulse2percept / api.py View on Github external
ecs_list.append(ecs[yy, xx])
                    idx_list.append([yy, xx])

        s_info = "tol=%.1f%%, %d/%d px selected" % (tol * 100, len(ecs_list),
                                                    np.prod(ecs.shape[:2]))
        logging.getLogger(__name__).info(s_info)

        sr_list = utils.parfor(self.gcl.model_cascade,
                               ecs_list, n_jobs=self.n_jobs,
                               engine=self.engine, scheduler=self.scheduler,
                               func_args=[pt_data, layers, self.use_jit])
        bm = np.zeros(self.ofl.gridx.shape +
                      (sr_list[0].data.shape[-1], ))
        idxer = tuple(np.array(idx_list)[:, i] for i in range(2))
        bm[idxer] = [sr.data for sr in sr_list]
        percept = utils.TimeSeries(sr_list[0].tsample, bm)

        # It is possible to specify an additional sampling rate for the
        # percept: If different from the input sampling rate, need to resample.
        if t_percept != percept.tsample:
            percept = percept.resample(t_percept)

        logging.getLogger(__name__).info("Done.")

        return percept
github pulse2percept / pulse2percept / pulse2percept / electrode2currentmap.py View on Github external
string identifier `name`. If found, the index of that electrode is
        returned, else None.

        Parameters
        ----------
        name : str
            An electrode name (string identifier).

        Returns
        -------
        A valid electrode index or None.
        """
        # Is `name` a valid electrode name?
        # Iterate through electrodes to find a matching name. Shuffle list
        # to reduce time complexity of average lookup.
        for idx, el in utils.traverse_randomly(enumerate(self.electrodes)):
            if el.name == name:
                return idx

        # Worst case O(n): name could not be found.
        return None
github pulse2percept / pulse2percept / pulse2percept / electrode2currentmap.py View on Github external
([x, y] index) and the stimuli through these electrodes.

    Parameters
    ----------
    ecs_list: nlayer x npixels (over threshold) arrays

    stimuli : list of TimeSeries objects with the electrode stimulation
        pulse trains.

    Returns
    -------
    A TimeSeries object with the effective current for this stimulus
    """

    ecm = np.sum(ecs_item[:, :, None] * ptrain_data, 1)
    return utils.TimeSeries(tsample, ecm)
github pulse2percept / pulse2percept / pulse2percept / effectivecurrent2brightness.py View on Github external
-------
        Fast response, b2(r,t) in Nanduri et al. (2012).

        Notes
        -----
        The function utils.sparseconv can be much faster than np.convolve and
        signal.fftconvolve if `stim` is sparse and much longer than the
        convolution kernel.

        The output is not converted to a TimeSeries object for speedup.
        """
        # FFT is faster on non-sparse data
        if usefft:
            conv = self.tsample * signal.fftconvolve(stim, gamma, mode='full')
        else:
            conv = self.tsample * utils.sparseconv(gamma, stim, mode='full',
                                                   dojit=dojit)
            # Cut off the tail of the convolution to make the output signal
            # match the dimensions of the input signal.
        return conv[:stim.shape[-1]]
github pulse2percept / pulse2percept / pulse2percept / retina.py View on Github external
self.tau_inl = 18.0 / 1000
        self.tau_ca = 45.25 / 1000
        self.tau_slow = 26.25 / 1000
        self.scale_ca = 42.1
        self.scale_slow = 1150.0
        self.lweight = 0.636
        self.aweight = 0.5
        self.slope = 3.0
        self.shift = 15.0

        # Overwrite any given keyword arguments, print warning message (True)
        # if attempting to set an unrecognized keyword
        self.set_kwargs(True, **kwargs)

        # perform one-time setup calculations
        _, self.gamma_inl = utils.gamma(1, self.tau_inl, self.tsample)
        _, self.gamma_gcl = utils.gamma(1, self.tau_gcl, self.tsample)

        # gamma_ca is used to calculate charge accumulation
        _, self.gamma_ca = utils.gamma(1, self.tau_ca, self.tsample)

        # gamma_slow is used to calculate the slow response
        _, self.gamma_slow = utils.gamma(3, self.tau_slow, self.tsample)
github pulse2percept / pulse2percept / pulse2percept / retina.py View on Github external
@utils.deprecated(alt_func='p2p.retina.jansonius2009',
                  deprecated_version='0.3', removed_version='0.4')
def jansonius(num_cells=500, num_samples=801, center=np.array([15, 2]),
              rot=0 * np.pi / 180, scale=1, bs=-1.9, bi=.5, r0=4,
              max_samples=45, ang_range=60):
    """Implements the model of retinal axonal pathways by generating a
    matrix of(x, y) positions.

    Assumes that the fovea is at[0, 0]

    Parameters
    ----------
    num_cells: int
        Number of axons(cells).
    num_samples: int
        Number of samples per axon(spatial resolution).
    Center: 2 item array