Skip to content

Commit

Permalink
autoformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
LynnSchmittwilken committed Mar 16, 2023
1 parent 6865fb7 commit 364913d
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 37 deletions.
4 changes: 2 additions & 2 deletions stimupy/illusions/angulars.py
Expand Up @@ -124,14 +124,14 @@ def pinwheel(
intensity_target = [
intensity_target,
]

# Initiate target mask
target_mask = np.zeros_like(stim["wedge_mask"])

if target_indices is not None:
if target_width is None:
raise ValueError("pinwheel() missing argument 'target_width' which is not 'None'")

target_center = itertools.cycle(target_center)
target_width = itertools.cycle(target_width)
intensity_target = itertools.cycle(intensity_target)
Expand Down
8 changes: 4 additions & 4 deletions stimupy/illusions/benarys.py
Expand Up @@ -256,7 +256,7 @@ def cross_triangles(
target_size = (target_size, target_size)
if target_size[0] != target_size[1]:
raise ValueError("target needs to have the same height and width")
if np.sqrt(target_size[0]**2 * 2.) / 2. > cross_thickness:
if np.sqrt(target_size[0] ** 2 * 2.0) / 2.0 > cross_thickness:
raise ValueError("Target size is larger than cross thickness")

# Calculate target placement for classical Benarys cross
Expand Down Expand Up @@ -350,8 +350,8 @@ def todorovic_generalized(
shape, visual_size, ppd = resolution.resolve(shape=shape, visual_size=visual_size, ppd=ppd)
if len(np.unique(ppd)) > 1:
raise ValueError("ppd should be equal in x and y direction")
if L_width > visual_size[1]/2:

if L_width > visual_size[1] / 2:
raise ValueError("L_width cannot be larger than stimulus_width / 2")

L_size = (visual_size[0] / 2, visual_size[0] / 2, L_width, visual_size[1] - L_width)
Expand Down Expand Up @@ -642,7 +642,7 @@ def add_targets(
theight, twidth = resolution.lengths_from_visual_angles_ppd(target_size, ppd)
ty = resolution.lengths_from_visual_angles_ppd(target_y, ppd)
tx = resolution.lengths_from_visual_angles_ppd(target_x, ppd)

if isinstance(ty, (int, float)):
ty = (ty,)
tx = (tx,)
Expand Down
10 changes: 6 additions & 4 deletions stimupy/illusions/checkerboards.py
Expand Up @@ -40,12 +40,14 @@ def mask_from_idx(checkerboard_stim, check_idc):
for i, coords in enumerate(check_idc):
if coords[0] < 0 or coords[0] > coords[0] or coords[1] < 0 or coords[1] > board_shape[1]:
raise ValueError(f"Cannot provide mask for check {coords} outside board {board_shape}")
m1 = np.where(checkerboard_stim["grating_mask"]==coords[1]+1, 1, 0)
m2 = np.where(checkerboard_stim["grating_mask2"]==coords[0]+1, 1, 0)
mask = np.where(m1+m2==2, i+1, mask)
m1 = np.where(checkerboard_stim["grating_mask"] == coords[1] + 1, 1, 0)
m2 = np.where(checkerboard_stim["grating_mask2"] == coords[0] + 1, 1, 0)
mask = np.where(m1 + m2 == 2, i + 1, mask)

if len(np.unique(mask)) == 1:
raise ValueError(f"Cannot provide mask for check {coords} outside board because of rotation")
raise ValueError(
f"Cannot provide mask for check {coords} outside board because of rotation"
)
return mask


Expand Down
2 changes: 1 addition & 1 deletion stimupy/illusions/circulars.py
Expand Up @@ -109,7 +109,7 @@ def rings(
for i, ring_idx in enumerate(target_indices):
stim["img"] = np.where(stim["ring_mask"] == ring_idx + 1, intensity_target, stim["img"])
stim["target_mask"] = np.where(stim["ring_mask"] == ring_idx + 1, i + 1, 0).astype(int)
if ring_idx > stim["ring_mask"].max()-1:
if ring_idx > stim["ring_mask"].max() - 1:
raise ValueError(f"target idx {ring_idx} is above maximum ring idx")

# Update stim dict
Expand Down
45 changes: 25 additions & 20 deletions stimupy/illusions/cubes.py
Expand Up @@ -75,7 +75,12 @@ def varying_cells(
clengths = resolution.lengths_from_visual_angles_ppd(cell_lengths, ppd)
cthick = resolution.lengths_from_visual_angles_ppd(cell_thickness, ppd)
cspace = resolution.lengths_from_visual_angles_ppd(cell_spacing, ppd)
height = np.maximum(clengths[0], cthick) + np.maximum(clengths[-1], cthick) + sum(clengths[1:n_cells-1]) + cspace*(n_cells-1)
height = (
np.maximum(clengths[0], cthick)
+ np.maximum(clengths[-1], cthick)
+ sum(clengths[1 : n_cells - 1])
+ cspace * (n_cells - 1)
)
width = height

# Initiate image
Expand All @@ -91,36 +96,36 @@ def varying_cells(
fill_mask = 0

# Add cells top
cell_mask[0 : cthick, xs : xs + clengths[i]] = counter
target_mask[0 : cthick, xs : xs + clengths[i]] += fill_mask
cell_mask[0:cthick, xs : xs + clengths[i]] = counter
target_mask[0:cthick, xs : xs + clengths[i]] += fill_mask

# Add cells bottom
cell_mask[height - cthick : :, width - xs - clengths[i] : width - xs] = counter+1
cell_mask[height - cthick : :, width - xs - clengths[i] : width - xs] = counter + 1
target_mask[height - cthick : :, width - xs - clengths[i] : width - xs] += fill_mask

# Add cells left
cell_mask[height - xs - clengths[i]: height - xs, 0 : cthick] = counter+2
target_mask[height - xs - clengths[i]: height - xs, 0 : cthick] += fill_mask
cell_mask[height - xs - clengths[i] : height - xs, 0:cthick] = counter + 2
target_mask[height - xs - clengths[i] : height - xs, 0:cthick] += fill_mask

# Add cells right
cell_mask[xs : xs + clengths[i], width - cthick : :] = counter+3
cell_mask[xs : xs + clengths[i], width - cthick : :] = counter + 3
target_mask[xs : xs + clengths[i], width - cthick : :] += fill_mask

if i == 0:
xs += np.maximum(clengths[i], cthick) + cspace
elif i == n_cells-2:
elif i == n_cells - 2:
xs += np.maximum(clengths[-2], cthick) + cspace
else:
xs += clengths[i] + cspace
counter += 4

unique_vals = np.unique(cell_mask)
for v in range(len(unique_vals)-1):
cell_mask[cell_mask == unique_vals[v+1]] = v + 1
for v in range(len(unique_vals) - 1):
cell_mask[cell_mask == unique_vals[v + 1]] = v + 1

img = np.where(cell_mask != 0, intensity_cells, intensity_background)
img = np.where(target_mask != 0, intensity_target, img)
target_mask = np.where(target_mask>=1, 1, 0)
target_mask = np.where(target_mask >= 1, 1, 0)

stim = {
"img": img,
Expand Down Expand Up @@ -262,14 +267,14 @@ def cube(
target_mask[rys[i] : rys[i] + cell_height, 0:cell_thick] += fill_mask
target_mask[ys[i] : ys[i] + cell_height, height - cell_thick : :] += fill_mask
counter += 2

unique_vals = np.unique(cell_mask)
for v in range(len(unique_vals)-1):
cell_mask[cell_mask == unique_vals[v+1]] = v + 1
for v in range(len(unique_vals) - 1):
cell_mask[cell_mask == unique_vals[v + 1]] = v + 1

img = np.where(cell_mask != 0, intensity_cells, intensity_background)
img = np.where(target_mask != 0, intensity_target, img)
target_mask = np.where(target_mask>=1, 1, 0)
target_mask = np.where(target_mask >= 1, 1, 0)

stim = {
"img": img,
Expand Down
10 changes: 5 additions & 5 deletions stimupy/illusions/mondrians.py
Expand Up @@ -82,7 +82,7 @@ def corrugated_mondrians(
mdepths_px = resolution.lengths_from_visual_angles_ppd(mondrian_depths, ppd[0])
max_depth = np.abs(np.array(mdepths_px)).max()
sum_depth = np.abs(np.array(mdepths_px).sum())
red_depth = np.maximum(max_depth, sum_depth+max_depth)
red_depth = np.maximum(max_depth, sum_depth + max_depth)
mheight_px, mwidth_px = int(shape[0] / nrows), int((shape[1] - red_depth) / ncols)

# Initial y coordinates
Expand All @@ -107,8 +107,8 @@ def corrugated_mondrians(
xst -= int(mondrian_depths[r] * ppd[0])

for c in range(ncols):
if c != ncols-1:
msize = (mheight_px / ppd[0], (mwidth_px+1) / ppd[1], mondrian_depths[r])
if c != ncols - 1:
msize = (mheight_px / ppd[0], (mwidth_px + 1) / ppd[1], mondrian_depths[r])
else:
msize = (mheight_px / ppd[0], mwidth_px / ppd[1], mondrian_depths[r])
mpos = (yst / ppd[0], xst / ppd[1])
Expand Down Expand Up @@ -140,10 +140,10 @@ def corrugated_mondrians(

stim["target_mask"] = target_mask.astype(int)
stim["target_indices"] = target_indices

if intensity_target is not None:
for t in range(len(tlist)):
stim["img"] = np.where(target_mask==t+1, intensity_target, stim["img"])
stim["img"] = np.where(target_mask == t + 1, intensity_target, stim["img"])

if len(np.unique(stim["img"][target_mask != 0])) > 1:
raise Exception("targets are not equiluminant.")
Expand Down
2 changes: 1 addition & 1 deletion stimupy/illusions/mueller_lyers.py
Expand Up @@ -71,7 +71,7 @@ def mueller_lyer(

# Resolve resolution
shape, visual_size, ppd = resolution.resolve(shape=shape, visual_size=visual_size, ppd=ppd)

if outer_lines_angle > 180:
outer_lines_angle -= 360

Expand Down

0 comments on commit 364913d

Please sign in to comment.