Skip to content

Commit

Permalink
Merge pull request #121 from computational-psychology/dev
Browse files Browse the repository at this point in the history
Bugfixes
  • Loading branch information
LynnSchmittwilken authored Feb 9, 2024
2 parents d56e528 + 533e1e2 commit da97ecf
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 22 deletions.
16 changes: 9 additions & 7 deletions docs/getting_started/stimulus.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ For this specific stimulus,
the {py:func}`sbcs.basic <stimupy.stimuli.sbcs.basic>` provides little use over
the base component.
But, realistically, we would not show just this one part of a SBC display, but rather
show both sides of the SBC displays as implemented in {py:func}`two_sided <stimupy.stimuli.sbcs.two_sided>`:
show both sides of the SBC displays as implemented in {py:func}`two_sided <stimupy.stimuli.sbcs.basic_two_sided>`:
```{code-cell}
two_sided_stim = sbcs.two_sided(visual_size=(6,8), ppd=10,
two_sided_stim = sbcs.basic_two_sided(visual_size=(6,8), ppd=10,
target_size=(2,2))
plot_stim(two_sided_stim)
Expand All @@ -100,18 +100,19 @@ plt.show()
```
and they are controlled by the same `target_size` argument:
```{code-cell}
two_sided_stim = sbcs.two_sided(visual_size=(6,8), ppd=10,
target_size=(1,1))
two_sided_stim = sbcs.basic_two_sided(visual_size=(6,8), ppd=10,
target_size=(1,1),
intensity_background=(0.0,1.0))
plot_stim(two_sided_stim)
plt.show()
```

The `intensity_backgrounds` can also be specified at creation:
The `intensity_background` can also be varied at creation:
```{code-cell}
two_sided_stim = sbcs.two_sided(visual_size=(6,8), ppd=10,
two_sided_stim = sbcs.basic_two_sided(visual_size=(6,8), ppd=10,
target_size=(2,2),
intensity_backgrounds=(.25,.75))
intensity_background=(.25,.75))
plot_stim(two_sided_stim)
plt.show()
Expand Down Expand Up @@ -157,6 +158,7 @@ stim_2bull = bullseyes.circular_two_sided(
ppd=10,
n_rings=5,
ring_width=1,
intensity_rings=((0, 1), (1, 0))
)
plot_stim(stim_2bull)
Expand Down
2 changes: 1 addition & 1 deletion docs/topic_guides/waves.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ sinewave = waves.sine_linear(visual_size=(10, 10), ppd=10,
gabor = gabors.gabor(visual_size=(10, 10), ppd=10,
n_bars=5,
intensity_bars=(0.0, 1.0),
intensities=(0.0, 1.0),
origin='center',
sigma=1)
Expand Down
13 changes: 9 additions & 4 deletions stimupy/components/texts.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def text(
intensity_background=0.5,
fontsize=36,
align="center",
direction="ltr",
# direction="ltr",
):
"""Draw given text into a (numpy) image-array
Expand All @@ -42,8 +42,6 @@ def text(
font size, by default 36
align : "left", "center" (default), "right"
alignment of text, by default "center"
direction : "ltr" (default), "rtl"
text drawing direction, left-to-right, right-to-left
Returns
-------
Expand Down Expand Up @@ -89,7 +87,14 @@ def text(
draw = ImageDraw.Draw(img)

# Draw text into this image
draw.text((0, 0), text, fill=1, font=font, align=align, direction=direction)
draw.text(
(0, 0),
text,
fill=1,
font=font,
align=align,
# direction=direction
)

# Turn into mask-array
mask = np.array(img)
Expand Down
2 changes: 1 addition & 1 deletion stimupy/papers/RHS2007.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,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, keep_mask_indices=True)
stim = stack_dicts(stim1, stim2, keep_mask_indices=False)

params.update(
visual_size=np.array(stim["img"].shape) / ppd,
Expand Down
24 changes: 16 additions & 8 deletions stimupy/stimuli/checkerboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import numpy as np

from stimupy.components import waves
from stimupy.components import draw_regions, waves
from stimupy.utils import resolution
from stimupy.utils.contrast_conversions import transparency

Expand Down Expand Up @@ -84,8 +84,10 @@ def add_targets(checkerboard_stim, target_indices=(), extend_targets=False, inte
target indices (row, column of checkerboard)
extend_targets : bool, optional
if true, extends the targets by 1 check in all 4 directions, by default False
intensity_target : float, optional
intensity value of the target checks, by default 0.5
intensity_target : float, or Sequence[float, ...], optional
intensity value for each target, by default 0.5.
Can specify as many intensities as number of target_indices;
If fewer intensities are passed than target_indices, cycles through intensities
Returns
-------
Expand All @@ -96,19 +98,25 @@ def add_targets(checkerboard_stim, target_indices=(), extend_targets=False, inte
"""
if target_indices is None:
target_indices = ()
mask = np.zeros(checkerboard_stim["shape"])
target_mask = np.zeros(checkerboard_stim["shape"])

# Define target mask
for i, target in enumerate(target_indices):
if extend_targets:
target_idc = extend_target_idx(target)
else:
target_idc = [target]
for target_idx in target_idc:
mask += mask_from_idx(checkerboard_stim, (target_idx,)) * (i + 1)
img = np.where(mask, intensity_target, checkerboard_stim["img"])
target_mask += mask_from_idx(checkerboard_stim, (target_idx,)) * (i + 1)
checkerboard_stim["target_mask"] = target_mask.astype(int)

# Draw targets
checkerboard_stim["img"] = np.where(
target_mask,
draw_regions(mask=target_mask, intensities=intensity_target, intensity_background=0.0),
checkerboard_stim["img"],
)

checkerboard_stim["img"] = img
checkerboard_stim["target_mask"] = mask.astype(int)
return checkerboard_stim


Expand Down
2 changes: 2 additions & 0 deletions stimupy/stimuli/whites.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ def generalized(
target_bar_mask = mask_targets(
element_mask=stim["grating_mask"], target_indices=target_indices
)
if isinstance(target_indices, (int, float)):
target_indices = (target_indices,)
stim["target_indices"] = target_indices

# Mask rectangular regions
Expand Down
2 changes: 1 addition & 1 deletion tests/papers/RHS2007.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"WE_dual": {
"img": "0eb7042718b74b8973d8e945f0454867",
"mask": "d6eff24ab36465877ff03f79da860e52"
"mask": "1cdb8e0c80fc90b36f061804a34616d1"
},
"WE_anderson": {
"img": "c057361b1e23043ada45923cf73f9b98",
Expand Down

0 comments on commit da97ecf

Please sign in to comment.