Skip to content

Commit

Permalink
stacking dicts now by default increases mask_idx
Browse files Browse the repository at this point in the history
  • Loading branch information
LynnSchmittwilken committed Jan 13, 2023
1 parent 5f32da3 commit 90b2bcb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 46 deletions.
60 changes: 23 additions & 37 deletions stimuli/papers/RHS2007.py
Expand Up @@ -70,8 +70,8 @@
"todorovic_benary1_2",
"todorovic_benary3_4",
"todorovic_benary1_2_3_4",
# "bullseye_thin",
# "bullseye_thick",
"bullseye_thin",
"bullseye_thick",
]

VISEXTENT = (32.0, 32.0)
Expand Down Expand Up @@ -269,7 +269,7 @@ def WE_dual(ppd=PPD, pad=True):
# Pad and stack
stim1 = pad_dict_to_shape(stim1, shape, pad_value=v2)
stim2 = pad_dict_to_shape(stim2, shape, pad_value=v2)
stim = stack_dicts(stim1, stim2)
stim = stack_dicts(stim1, stim2, keep_mask_indices=True)

params.update(
visual_size=np.array(stim["img"].shape) / ppd,
Expand Down Expand Up @@ -706,7 +706,6 @@ def WE_circular1(ppd=PPD, pad=True):
intensity_rings=(v1, v3),
**params,
)
stim2["mask"] *= 2
stim = stack_dicts(stim1, stim2)

if pad:
Expand Down Expand Up @@ -766,7 +765,6 @@ def WE_circular05(ppd=PPD, pad=True):
intensity_rings=(v1, v3),
**params,
)
stim2["mask"] *= 2
stim = stack_dicts(stim1, stim2)

if pad:
Expand Down Expand Up @@ -826,7 +824,6 @@ def WE_circular025(ppd=PPD, pad=True):
intensity_rings=(v1, v3),
**params,
)
stim2["mask"] *= 2
stim = stack_dicts(stim1, stim2)

if pad:
Expand Down Expand Up @@ -941,7 +938,6 @@ def sbc_large(ppd=PPD, pad=True):
intensity_background=1.0,
**params,
)
stim2["mask"] *= 2
stim = stack_dicts(stim1, stim2)

if pad:
Expand Down Expand Up @@ -1001,7 +997,6 @@ def sbc_small(ppd=PPD, pad=True):
intensity_background=1.0,
**params,
)
stim2["mask"] *= 2
stim = stack_dicts(stim1, stim2)

if pad:
Expand Down Expand Up @@ -1067,7 +1062,6 @@ def todorovic_equal(ppd=PPD, pad=True):
intensity_covers=1.0,
**params,
)
stim2["mask"] *= 2
stim = stack_dicts(stim1, stim2)

if pad:
Expand Down Expand Up @@ -1131,7 +1125,6 @@ def todorovic_in_large(ppd=PPD, pad=True):
intensity_covers=1.0,
**params,
)
stim2["mask"] *= 2
stim = stack_dicts(stim1, stim2)

if pad:
Expand Down Expand Up @@ -1195,7 +1188,6 @@ def todorovic_in_small(ppd=PPD, pad=True):
intensity_covers=1.0,
**params,
)
stim2["mask"] *= 2
stim = stack_dicts(stim1, stim2)

if pad:
Expand Down Expand Up @@ -1262,7 +1254,6 @@ def todorovic_out(ppd=PPD, pad=True):
intensity_covers=1.0,
**params,
)
stim2["mask"] *= 2
stim = stack_dicts(stim1, stim2)

if pad:
Expand Down Expand Up @@ -1733,8 +1724,8 @@ def todorovic_benary1_2_3_4(ppd=PPD, pad=True):

def bullseye_thin(ppd=PPD, pad=True):
"""Bullseye stimulus as shown in Robinson, Hammon, & de Sa (2007) Fig 1aa.
Contains all four targets (1-2-3-4).
Ring width: 0.1 deg
Target size: 0.608x0.608 deg
Ring widths: 0.122 deg
Parameters
----------
Expand All @@ -1755,30 +1746,28 @@ def bullseye_thin(ppd=PPD, pad=True):
Research, 44, 309–319.
"""

frame_radii = np.array([0.304, 0.426, 0.548, 0.670, 0.792])

params = {
"visual_size": 0.792*2,
"ppd": ppd,
"n_frames": 8,
"frame_width": 0.1,
"frame_radii": frame_radii,
"intensity_target": v2,
}

stim1 = illusions.bullseye(
stim1 = illusions.frames.bullseye_generalized(
**params,
intensity_frames=(v3, v1),
intensity_frames=(v1, v3),
)
stim2 = illusions.bullseye(
stim2 = illusions.frames.bullseye_generalized(
**params,
intensity_frames=(v1, v3),
intensity_frames=(v3, v1),
)

# Individual padding
if pad:
stim1 = pad_dict_to_visual_size(stim1, np.array(VISEXTENT) / 2, ppd, pad_value=v2)
stim2 = pad_dict_to_visual_size(stim2, np.array(VISEXTENT) / 2, ppd, pad_value=v2)

# Increase target index of right stimulus half
stim2["mask"] = stim2["mask"] + 1
stim2["mask"][stim2["mask"] == 1] = 0
stim = stack_dicts(stim1, stim2)

if pad:
Expand All @@ -1794,8 +1783,8 @@ def bullseye_thin(ppd=PPD, pad=True):

def bullseye_thick(ppd=PPD, pad=True):
"""Bullseye stimulus as shown in Robinson, Hammon, & de Sa (2007) Fig 1bb.
Contains all four targets (1-2-3-4).
Ring width: 0.2 deg
Target size: 0.608x0.608 deg
Ring widths: 0.243 deg
Parameters
----------
Expand All @@ -1815,31 +1804,28 @@ def bullseye_thick(ppd=PPD, pad=True):
Bindman, D., & Chubb, C. (2004). Brightness assimilation in bullseye displays. Vision
Research, 44, 309–319.
"""
frame_radii = np.array([0.304, 0.547, 0.790, 1.033, 1.276])

params = {
"visual_size": 1.276*2,
"ppd": ppd,
"n_frames": 6,
"frame_width": 0.2,
"frame_radii": frame_radii,
"intensity_target": v2,
}

stim1 = illusions.bullseye(
stim1 = illusions.frames.bullseye_generalized(
**params,
intensity_frames=(v3, v1),
intensity_frames=(v1, v3),
)
stim2 = illusions.bullseye(
stim2 = illusions.frames.bullseye_generalized(
**params,
intensity_frames=(v1, v3),
intensity_frames=(v3, v1),
)

# Individual padding
if pad:
stim1 = pad_dict_to_visual_size(stim1, np.array(VISEXTENT) / 2, ppd, pad_value=v2)
stim2 = pad_dict_to_visual_size(stim2, np.array(VISEXTENT) / 2, ppd, pad_value=v2)

# Increase target index of right stimulus half
stim2["mask"] = stim2["mask"] + 1
stim2["mask"][stim2["mask"] == 1] = 0
stim = stack_dicts(stim1, stim2)

if pad:
Expand All @@ -1857,4 +1843,4 @@ def bullseye_thick(ppd=PPD, pad=True):
from stimuli.utils import plot_stimuli

stims = gen_all(pad=True, skip=True)
plot_stimuli(stims, mask=False)
plot_stimuli(stims, mask=True)
8 changes: 0 additions & 8 deletions stimuli/papers/domijan2015.py
Expand Up @@ -230,7 +230,6 @@ def dungeon(visual_size=VSIZES["dungeon"], ppd=PPD, shape=SHAPES["dungeon"]):
intensity_grid=v1,
intensity_target=v2,
)
stim2["mask"] *= 2

# Pad and stack
padding = np.array((0.9, 1.1)) * visual_resize
Expand Down Expand Up @@ -299,7 +298,6 @@ def cube(visual_size=VSIZES["cube"], ppd=PPD, shape=SHAPES["cube"]):
intensity_grid=v1,
intensity_target=v2,
)
stim2["mask"] *= 2

# Pad and stack
padding = np.array((0.9, 1.0)) * visual_resize
Expand Down Expand Up @@ -370,7 +368,6 @@ def grating(visual_size=VSIZES["grating"], ppd=PPD, shape=SHAPES["grating"]):
intensity_bars=(v1, v3),
intensity_target=v2,
)
stim2["mask"] *= 2

# Pad and stack
padding = np.array(((0.9, 1.0), (0.9, 1.1))) * visual_resize
Expand Down Expand Up @@ -437,7 +434,6 @@ def rings(visual_size=VSIZES["rings"], ppd=PPD, shape=SHAPES["rings"]):
intensity_frames=(v1, v3),
intensity_target=v2,
)
stim2["mask"] *= 2

# Pad and stack
stim1 = pad_dict_to_shape(stim1, shape=np.array(shape) / (1, 2), pad_value=v1)
Expand Down Expand Up @@ -501,7 +497,6 @@ def bullseye(visual_size=VSIZES["bullseye"], ppd=PPD, shape=SHAPES["bullseye"]):
intensity_frames=(v3, v1),
intensity_target=v2,
)
stim2["mask"] *= 2

# Pad and stack
stim1 = pad_dict_to_shape(stim1, shape=np.array(shape) / (1, 2), pad_value=v1)
Expand Down Expand Up @@ -572,7 +567,6 @@ def simultaneous_brightness_contrast(
intensity_background=v1,
intensity_target=v2,
)
stim2["mask"] *= 2

# Stacking
stim = stack_dicts(stim1, stim2)
Expand Down Expand Up @@ -766,7 +760,6 @@ def todorovic(visual_size=VSIZES["todorovic"], ppd=PPD, shape=SHAPES["todorovic"
intensity_target=0.5,
intensity_covers=0.0,
)
stim2["mask"] *= 2

# Stacking
stim = stack_dicts(stim1, stim2)
Expand Down Expand Up @@ -843,7 +836,6 @@ def checkerboard_contrast_contrast(

# Put smaller checkerboard on background (equally large as large checkerboard)
stim2 = pad_dict_to_shape(stim2, stim1["img"].shape, pad_value=v2)
stim2["mask"] *= 2

# Overall padding
if pad:
Expand Down
5 changes: 4 additions & 1 deletion stimuli/utils/pad.py
Expand Up @@ -403,7 +403,7 @@ def resize_dict(dct, factor, keys=("img", "*mask")):
return new_dict


def stack_dicts(dct1, dct2, direction="horizontal", keys=("img", "*mask")):
def stack_dicts(dct1, dct2, direction="horizontal", keys=("img", "*mask"), keep_mask_indices=False):
"""
Return a dict with resized key-arrays by the given factor. Every value is
repeated factor[d] times along dimension d.
Expand Down Expand Up @@ -448,6 +448,9 @@ def stack_dicts(dct1, dct2, direction="horizontal", keys=("img", "*mask")):
img1 = dct1[key]
img2 = dct2[key]
if isinstance(img1, np.ndarray) and isinstance(img2, np.ndarray):
if key.endswith("mask") and not keep_mask_indices:
img2 = np.where(img2 != 0, img2+img1.max(), 0)

if direction == "horizontal":
img = np.hstack([img1, img2])
elif direction == "vertical":
Expand Down

0 comments on commit 90b2bcb

Please sign in to comment.