Skip to content

Commit

Permalink
added disc_and_rings to components and made it stim-pkg compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
LynnSchmittwilken committed Jul 25, 2022
1 parent 4c12d75 commit 190256f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 75 deletions.
65 changes: 54 additions & 11 deletions stimuli/components/components.py
Expand Up @@ -237,50 +237,93 @@ def checkerboard(
return img


def disc(
def disc_and_rings(
ppd=20,
radius=3,
radii=(3, 6, 9),
vback=0.,
vdisc=1.,
vdiscs=(1., 0., 1.),
ssf=5,
):
"""
Create a central disc
Create a central disc with rings
Parameters
----------
ppd : int
pixels per degree (visual angle)
radius : float
radius of disc in degree visual angle
radii : tuple of floats
radii of disc in degree visual angle
vback : float
value of background
vdisc : float
value of disc
vdiscs : tuple of floats
values of discs
ssf : int (optional)
the supersampling-factor used for anti-aliasing. Default is 5.
Returns
-------
A 2d-array with a disc
"""
radius_px = degrees_to_pixels(radius, ppd) * ssf
radii_px = degrees_to_pixels(radii, ppd) * ssf

# create stimulus at 5 times size to allow for supersampling antialiasing
img = np.ones([radius_px*2, radius_px*2]) * vback
img = np.ones([radii_px.max()*2, radii_px.max()*2]) * vback

# compute distance from center of array for every point, cap at 1.0
x = np.linspace(-img.shape[1] / 2.0, img.shape[1] / 2.0, img.shape[1])
y = np.linspace(-img.shape[0] / 2.0, img.shape[0] / 2.0, img.shape[0])
dist = np.sqrt(x[np.newaxis, :] ** 2 + y[:, np.newaxis] ** 2)
img[dist < radius_px] = vdisc

radii_px = radii_px[::-1]
vdiscs = vdiscs[::-1]
for radius, value in zip(radii_px, vdiscs):
img[dist < radius] = value

# downsample the stimulus by local averaging along rows and columns
sampler = resize_array(np.eye(img.shape[0] // ssf), (1, ssf))
img = np.dot(sampler, np.dot(img, sampler.T)) / ssf**2
return img


def disc(
ppd=20,
radius=3,
vback=0.,
vdisc=1.,
ssf=5,
):
"""
Create a central disc
Parameters
----------
ppd : int
pixels per degree (visual angle)
radius : float
radius of disc in degree visual angle
vback : float
value of background
vdisc : float
value of disc
ssf : int (optional)
the supersampling-factor used for anti-aliasing. Default is 5.
Returns
-------
A 2d-array with a disc
"""
radius = [radius]
vdisc = [vdisc]

if len(radius) > 1:
raise ValueError("Too many radii passed")
if len(vdisc) > 1:
raise ValueError("Too many values for discs passed")

img = disc_and_rings(ppd, radius, vback, vdisc, ssf)
return img


def square_wave_grating(
ppd=10,
n_bars=8,
Expand Down
64 changes: 0 additions & 64 deletions stimuli/illusions/disc_and_ring.py

This file was deleted.

0 comments on commit 190256f

Please sign in to comment.