# pulse2percept.utils.geometry¶

Functions

 cart2pol(x, y) Convert Cartesian to polar coordinates delta_angle(source_angle, target_angle[, hi]) Returns the signed difference between two angles (rad) pol2cart(theta, rho) Convert polar to Cartesian coordinates

Classes

 Curcio1990Map Converts between visual angle and retinal eccentricity [Curcio1990] Grid2D(x_range, y_range[, step, grid_type]) 2D spatial grid VisualFieldMap Base class for a visual field map (retinotopy) Watson2014DisplaceMap Converts between visual angle and retinal eccentricity using RGC Watson2014Map Converts between visual angle and retinal eccentricity [Watson2014]
class pulse2percept.utils.geometry.Curcio1990Map[source]

Converts between visual angle and retinal eccentricity [Curcio1990]

static dva2ret(xdva, ydva)[source]

Convert degrees of visual angle (dva) to retinal eccentricity (um)

Assumes that one degree of visual angle is equal to 280 um on the retina [Curcio1990].

static ret2dva(xret, yret)[source]

Convert retinal eccentricity (um) to degrees of visual angle (dva)

Assumes that one degree of visual angle is equal to 280 um on the retina [Curcio1990]

class pulse2percept.utils.geometry.Grid2D(x_range, y_range, step=1, grid_type='rectangular')[source]

2D spatial grid

This class generates a two-dimensional mesh grid from a range of x, y values and provides an iterator to loop over elements.

New in version 0.6.

Parameters: x_range ((x_min, x_max)) – A tuple indicating the range of x values (includes end points) y_range (tuple, (y_min, y_max)) – A tuple indicating the range of y values (includes end points) step (int, double, tuple) – Step size. If int or double, the same step will apply to both x and y ranges. If a tuple, it is interpreted as (x_step, y_step). grid_type ({'rectangular', 'hexagonal'}) – The grid type

Notes

• The grid uses Cartesian indexing (indexing='xy' for NumPy’s meshgrid function). This implies that the grid’s shape will be (number of y coordinates) x (number of x coordinates).
• If a range is zero, the step size is irrelevant.

Examples

You can iterate through a grid as if it were a list:

>>> grid = Grid2D((0, 1), (2, 3))
>>> for x, y in grid:
...     print(x, y)
0.0 2.0
1.0 2.0
0.0 3.0
1.0 3.0

plot(transform=None, label=None, style='hull', autoscale=True, zorder=None, ax=None, figsize=None, fc='gray')[source]

Plot the extension of the grid

Parameters: transform (function, optional) – A coordinate transform to be applied to the (x,y) coordinates of the grid (e.g., Curcio1990Transform.dva2ret). It must accept two input arguments (x and y) and output two variables (the transformed x and y). label (str, optional) – A name to be used as the label of the matplotlib plot. This can be used to label plots with multiple regions (i.e. call plt.legend after) style ({'hull', 'scatter', 'cell'}, optional) – ‘hull’: Show the convex hull of the grid (that is, the outline of the smallest convex set that contains all grid points). ’scatter’: Scatter plot all grid points ’cell’: Show the outline of each grid cell as a polygon. Note that this can be costly for a high-resolution grid. autoscale (bool, optional) – Whether to adjust the x,y limits of the plot to fit the implant zorder (int, optional) – The Matplotlib zorder at which to plot the grid ax (matplotlib.axes._subplots.AxesSubplot, optional) – A Matplotlib axes object. If None, will either use the current axes (if exists) or create a new Axes object figsize ((float, float), optional) – Desired (width, height) of the figure in inches fc (str or valid matplotlib color, optional) – Facecolor, or edge color if style=scatter, of the plotted region Defaults to gray
class pulse2percept.utils.geometry.VisualFieldMap[source]

Base class for a visual field map (retinotopy)

A template

dva2ret(x, y)[source]

Convert degrees of visual angle (dva) to retinal coords (um)

ret2dva(x, y)[source]

Convert retinal coords (um) to degrees of visual angle (dva)

class pulse2percept.utils.geometry.Watson2014DisplaceMap[source]
Converts between visual angle and retinal eccentricity using RGC
displacement [Watson2014]

Converts from eccentricity (defined as distance from a visual center) in degrees of visual angle (dva) to microns on the retina using Eqs. 5, A5, and A6 in [Watson2014].

In a central retinal zone, the retinal ganglion cell (RGC) bodies are displaced centrifugally some distance from the inner segments of the cones to which they are connected through the bipolar cells, and thus from their receptive field. The displacement function is described in Eq. 5 of [Watson2014].

dva2ret(xdva, ydva)[source]

Converts dva to retinal coords

Parameters: ydva (xdva,) – x,y coordinates in dva xret, yret (double or array-like) – Corresponding x,y coordinates in microns
ret2dva(xret, yret)[source]

Converts retinal distances (um) to visual angles (deg)

This function converts an eccentricity measurement on the retinal surface(in micrometers), measured from the optic axis, into degrees of visual angle using Eq. A6 in [Watson2014].

Parameters: y_um (x_um,) – Original x and y coordinates on the retina (microns) coords ({'cart', 'polar'}) – Whether to return the result in Cartesian or polar coordinates x_dva, y_dva (double or array-like) – Transformed x and y coordinates (degrees of visual angle, dva)
static watson_displacement(r, meridian='temporal')[source]

Ganglion cell displacement function

Implements the ganglion cell displacement function described in Eq. 5 of [Watson2014].

Parameters: r (double|array-like) – Eccentricity in degrees of visual angle (dva) meridian ('temporal' or 'nasal') – The displacement in dva experienced by ganglion cells at eccentricity r.
class pulse2percept.utils.geometry.Watson2014Map[source]

Converts between visual angle and retinal eccentricity [Watson2014]

static dva2ret(x_deg, y_deg, coords='cart')[source]

Converts visual angles (deg) into retinal distances (um)

This function converts degrees of visual angle into a retinal distance from the optic axis (um) using Eq. A5 in [Watson2014].

Parameters: y_dva (x_dva,) – Original x and y coordinates (degrees of visual angle, dva) coords ({'cart', 'polar'}) – Whether to return the result in Cartesian or polar coordinates x_ret, y_ret (double or array-like) – Transformed x and y coordinates on the retina (microns)
static ret2dva(x_um, y_um, coords='cart')[source]

Converts retinal distances (um) to visual angles (deg)

This function converts an eccentricity measurement on the retinal surface(in micrometers), measured from the optic axis, into degrees of visual angle using Eq. A6 in [Watson2014].

Parameters: y_um (x_um,) – Original x and y coordinates on the retina (microns) coords ({'cart', 'polar'}) – Whether to return the result in Cartesian or polar coordinates x_dva, y_dva (double or array-like) – Transformed x and y coordinates (degrees of visual angle, dva)
pulse2percept.utils.geometry.cart2pol(x, y)[source]

Convert Cartesian to polar coordinates

Parameters: y (x,) – The x,y Cartesian coordinates theta, rho (scalar or array-like) – The transformed polar coordinates
pulse2percept.utils.geometry.delta_angle(source_angle, target_angle, hi=6.283185307179586)[source]

Returns the signed difference between two angles (rad)

The difference is calculated as target_angle - source_angle. The difference will thus be positive if target_angle > source_angle.

New in version 0.7.

Parameters: target_angle (source_angle,) – Input arrays with circular data in the range [0, hi] hi (float, optional) – Sets the upper bounds of the range (e.g., 2*np.pi or 360). Lower bound is always 0 The signed difference target_angle - source_angle in [0, hi]
pulse2percept.utils.geometry.pol2cart(theta, rho)[source]

Convert polar to Cartesian coordinates

Parameters: rho (theta,) – The polar coordinates x, y (scalar or array-like) – The transformed Cartesian coordinates