How to use the pulse2percept.utils.parfor 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 / api.py View on Github external
# enough compared to the max across pixels within the layer
                    process_pixel |= np.any(ecs[yy, xx, 0, :] >=
                                            tol * lmax[0, :])
                if ('GCL' or 'OFL') in layers:
                    process_pixel |= np.any(ecs[yy, xx, 1, :] >=
                                            tol * lmax[1, :])

                if process_pixel:
                    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.")
github pulse2percept / pulse2percept / pulse2percept / retina.py View on Github external
# Grow a number `n_axons` of axon bundles with orientations in
            # `phi_range`
            phi = np.linspace(*phi_range, num=n_axons)
            func_kwargs = {'n_rho': n_rho, 'rho_range': rho_range,
                           'loc_od': loc_od, 'eye': eye}
            self.axon_bundles = utils.parfor(jansonius2009, phi,
                                             func_kwargs=func_kwargs,
                                             engine=engine, n_jobs=n_jobs,
                                             scheduler=scheduler)
            grid_dict['axon_bundles'] = self.axon_bundles

            # Assume there is a neuron at every grid location: Use the above
            # axon bundles to assign an axon to each neuron
            xg, yg = ret2dva(self.gridx), ret2dva(self.gridy)
            pos_xy = np.column_stack((xg.ravel(), yg.ravel()))
            self.axons = utils.parfor(find_closest_axon, pos_xy,
                                      func_args=[self.axon_bundles])
            grid_dict['axons'] = self.axons

            # For every axon segment, calculate distance to soma. Snap axon
            # locations to the grid using a nearest-neighbor tree structure:
            func_kwargs = {'tree': spat.cKDTree(pos_xy)}
            self.axon_distances = utils.parfor(axon_dist_from_soma, self.axons,
                                               func_args=[xg, yg],
                                               func_kwargs=func_kwargs,
                                               engine=engine, n_jobs=n_jobs,
                                               scheduler=scheduler)
            grid_dict['axon_distances'] = self.axon_distances

            # Save the variables, together with metadata about the grid:
            if save_data:
                six.moves.cPickle.dump(grid_dict, open(filename, 'wb'))
github pulse2percept / pulse2percept / pulse2percept / retina.py View on Github external
passing the map through a mapping of axon streaks.

        Parameters
        ----------
        cs: array
            The 2D spread map in retinal space

        Returns
        -------
        ecm: array
            The effective current spread, a time series of the same size as
            the current map, where each pixel is the dot product of the pixel
            values in ecm along the pixels in the list in axon_map, weighted
            by the weights axon map.
        """
        contrib = utils.parfor(axon_contribution, self.axon_distances,
                               func_args=[current_spread], engine=self.engine,
                               func_kwargs={
                                   'sensitivity_rule': self.sensitivity_rule,
                                   'contribution_rule': self.contribution_rule,
                                   'decay_const': self.decay_const,
                                   'powermean_exp': self.powermean_exp
                               },
                               scheduler=self.scheduler, n_jobs=self.n_jobs)

        ecs = np.zeros_like(current_spread)
        px_contrib = list(filter(None, contrib))
        for idx, value in px_contrib:
            ecs.ravel()[idx] = value

        # Normalize so that the max of `ecs` is the same as `current_spread`
        return ecs / (ecs.max() + np.finfo(float).eps) * current_spread.max()
github pulse2percept / pulse2percept / pulse2percept / models / beyeler2019.py View on Github external
def grow_axon_bundles(self, n_bundles=None, prune=True):
        if n_bundles is None:
            n_bundles = self.n_axons
        # Build the Jansonius model: Grow a number of axon bundles in all dirs:
        phi = np.linspace(*self.axons_range, num=n_bundles)
        engine = 'serial' if self.engine == 'cython' else self.engine
        bundles = parfor(self._jansonius2009, phi,
                         func_kwargs={'eye': self.eye},
                         engine=engine, n_jobs=self.n_jobs,
                         scheduler=self.scheduler)
        # Keep only non-zero sized bundles:
        bundles = list(filter(lambda x: len(x) > 0, bundles))
        if prune:
            # Remove axon bundles outside the simulated area:
            xmin, xmax = self.xrange
            ymin, ymax = self.yrange
            bundles = list(filter(lambda x: (np.max(x[:, 0]) >= xmin and
                                             np.min(x[:, 0]) <= xmax and
                                             np.max(x[:, 1]) >= ymin and
                                             np.min(x[:, 1]) <= ymax),
                                  bundles))
            # Keep only reasonably sized axon bundles:
            bundles = list(filter(lambda x: len(x) > 10, bundles))
github pulse2percept / pulse2percept / pulse2percept / retina.py View on Github external
engine=engine, n_jobs=n_jobs,
                                             scheduler=scheduler)
            grid_dict['axon_bundles'] = self.axon_bundles

            # Assume there is a neuron at every grid location: Use the above
            # axon bundles to assign an axon to each neuron
            xg, yg = ret2dva(self.gridx), ret2dva(self.gridy)
            pos_xy = np.column_stack((xg.ravel(), yg.ravel()))
            self.axons = utils.parfor(find_closest_axon, pos_xy,
                                      func_args=[self.axon_bundles])
            grid_dict['axons'] = self.axons

            # For every axon segment, calculate distance to soma. Snap axon
            # locations to the grid using a nearest-neighbor tree structure:
            func_kwargs = {'tree': spat.cKDTree(pos_xy)}
            self.axon_distances = utils.parfor(axon_dist_from_soma, self.axons,
                                               func_args=[xg, yg],
                                               func_kwargs=func_kwargs,
                                               engine=engine, n_jobs=n_jobs,
                                               scheduler=scheduler)
            grid_dict['axon_distances'] = self.axon_distances

            # Save the variables, together with metadata about the grid:
            if save_data:
                six.moves.cPickle.dump(grid_dict, open(filename, 'wb'))
        else:
            # Assign all elements in the loaded dictionary to this object
            for key, value in six.iteritems(load_grid_dict):
                setattr(self, key, value)
github pulse2percept / pulse2percept / pulse2percept / retina.py View on Github external
if value != load_grid_dict[key]:
                    logging.getLogger(__name__).info('File out of date.')
                    need_new_grid = True
                    break

        # At this point we know whether we need to generate a new retina:
        if need_new_grid:
            info_str = "Generating new file '%s'." % filename
            logging.getLogger(__name__).info(info_str)

            # Grow a number `n_axons` of axon bundles with orientations in
            # `phi_range`
            phi = np.linspace(*phi_range, num=n_axons)
            func_kwargs = {'n_rho': n_rho, 'rho_range': rho_range,
                           'loc_od': loc_od, 'eye': eye}
            self.axon_bundles = utils.parfor(jansonius2009, phi,
                                             func_kwargs=func_kwargs,
                                             engine=engine, n_jobs=n_jobs,
                                             scheduler=scheduler)
            grid_dict['axon_bundles'] = self.axon_bundles

            # Assume there is a neuron at every grid location: Use the above
            # axon bundles to assign an axon to each neuron
            xg, yg = ret2dva(self.gridx), ret2dva(self.gridy)
            pos_xy = np.column_stack((xg.ravel(), yg.ravel()))
            self.axons = utils.parfor(find_closest_axon, pos_xy,
                                      func_args=[self.axon_bundles])
            grid_dict['axons'] = self.axons

            # For every axon segment, calculate distance to soma. Snap axon
            # locations to the grid using a nearest-neighbor tree structure:
            func_kwargs = {'tree': spat.cKDTree(pos_xy)}