Skip to content

Commit

Permalink
closes #54, closes #65, closes #35; using new grating function in whi…
Browse files Browse the repository at this point in the history
…tes - this led to 1px-changes in RHS2007-howe and anderson
  • Loading branch information
LynnSchmittwilken committed Jan 23, 2023
1 parent 7dc712b commit df751a5
Show file tree
Hide file tree
Showing 7 changed files with 480 additions and 361 deletions.
100 changes: 68 additions & 32 deletions demo/illusions/whites.ipynb
Expand Up @@ -50,10 +50,10 @@
"params = {\n",
" \"visual_size\": (8., 8.),\n",
" \"ppd\": 10.0,\n",
" \"grating_frequency\": 0.5,\n",
" \"frequency\": 0.5,\n",
" \"target_indices\": (2, 5),\n",
" \"target_center_offsets\": 0,\n",
" \"target_sizes\": 2.,\n",
" \"target_heights\": 2.,\n",
" \"intensity_bars\": (0., 1.),\n",
" \"intensity_target\": 0.5,\n",
" \"period\": \"ignore\"\n",
Expand All @@ -69,7 +69,7 @@
"metadata": {},
"source": [
"The main advantage of `white_generalized()` is that you can add as many targets as you like by adding values to the lists that you pass to `target_indices`.\n",
"In addition, you can define the vertical distance from the center of the stimulus for each target by adding values to `target_center_offsets`, and change their individual sizes by adding values to `target_sizes`.\n",
"In addition, you can define the vertical distance from the center of the stimulus for each target by adding values to `target_center_offsets`, and change their individual sizes by adding values to `target_heights`.\n",
"\n",
"Keep in mind that the number of elements for each of those input variables needs be 1 or you need to have as many elements as you want to have targets."
]
Expand All @@ -83,20 +83,20 @@
"params = {\n",
" \"visual_size\": (8., 8.),\n",
" \"ppd\": 10.0,\n",
" \"grating_frequency\": 0.5,\n",
" \"frequency\": 0.5,\n",
" \"intensity_bars\": (0., 1.),\n",
" \"intensity_target\": 0.5,\n",
" \"period\": \"ignore\"\n",
"}\n",
"stim1 = white_generalized(**params,\n",
" target_indices=(1, 3, 5, -2, -4, -6),\n",
" target_center_offsets=(-1.5, -1.5, -1.5, 1.5, 1.5, 1.5),\n",
" target_sizes=1.5)\n",
" target_heights=1.5)\n",
"\n",
"stim2 = white_generalized(**params,\n",
" target_indices=(1, 2, 3, 4, 5, 6),\n",
" target_center_offsets=(-3., -2., -1, -0., 1., 2.),\n",
" target_sizes=(0.25, 0.5, 1., 1.5, 2., 3))\n",
" target_heights=(0.25, 0.5, 1., 1.5, 2., 3))\n",
"\n",
"plot_stimuli({\"Example 1:\": stim1, \"Example 2:\": stim2})\n",
"plt.show()"
Expand All @@ -121,9 +121,9 @@
"w_ppd = iw.IntSlider(value=10, min=1, max=30, description=\"ppd\")\n",
"w_size = iw.HBox([w_height, w_width, w_ppd])\n",
"\n",
"w_freq = iw.FloatSlider(value=0.5, min=0.1, max=2.0, description=\"grating frequency\")\n",
"w_freq = iw.FloatSlider(value=0.5, min=0.1, max=2.0, description=\"frequency\")\n",
"\n",
"w_tsize = iw.FloatSlider(value=2., min=0.5, max=6.0, description=\"target size\")\n",
"w_tsize = iw.FloatSlider(value=2., min=0.5, max=6.0, description=\"target height\")\n",
"w_toff = iw.FloatSlider(value=0., min=-3, max=3, description=\"target center offset\")\n",
"w_target = iw.HBox([w_tsize, w_toff])\n",
"\n",
Expand All @@ -138,8 +138,8 @@
" height=None,\n",
" width=None,\n",
" ppd=None,\n",
" grating_frequency=None,\n",
" target_sizes=None,\n",
" frequency=None,\n",
" target_heights=None,\n",
" target_center_offsets=None,\n",
" intensity_bar1=None,\n",
" intensity_bar2=None,\n",
Expand All @@ -149,9 +149,9 @@
" stim = white_generalized(\n",
" visual_size=(height, width),\n",
" ppd=ppd,\n",
" grating_frequency=grating_frequency,\n",
" frequency=frequency,\n",
" target_indices=3,\n",
" target_sizes=target_sizes,\n",
" target_heights=target_heights,\n",
" target_center_offsets=target_center_offsets,\n",
" intensity_bars=(intensity_bar1, intensity_bar2),\n",
" intensity_target=intensity_target,\n",
Expand All @@ -165,8 +165,8 @@
" \"height\": w_height,\n",
" \"width\": w_width,\n",
" \"ppd\": w_ppd,\n",
" \"grating_frequency\": w_freq,\n",
" \"target_sizes\": w_tsize,\n",
" \"frequency\": w_freq,\n",
" \"target_heights\": w_tsize,\n",
" \"target_center_offsets\": w_toff,\n",
" \"intensity_bar1\": w_ibar1,\n",
" \"intensity_bar2\": w_ibar2,\n",
Expand Down Expand Up @@ -210,9 +210,9 @@
"params = {\n",
" \"visual_size\": (8., 8.),\n",
" \"ppd\": 10.0,\n",
" \"grating_frequency\": 0.5,\n",
" \"frequency\": 0.5,\n",
" \"target_indices\": (2, 5),\n",
" \"target_size\": 2.,\n",
" \"target_height\": 2.,\n",
" \"intensity_bars\": (0., 1.),\n",
" \"intensity_target\": 0.5,\n",
" \"period\": \"ignore\"\n",
Expand Down Expand Up @@ -256,11 +256,11 @@
"params = {\n",
" \"visual_size\": (8., 8.),\n",
" \"ppd\": 10.0,\n",
" \"grating_frequency\": 0.5,\n",
" \"frequency\": 0.5,\n",
" \"target_indices_top\": (1, 3),\n",
" \"target_indices_bottom\": (4, 6),\n",
" \"target_center_offset\": 1.,\n",
" \"target_size\": 1.,\n",
" \"target_height\": 1.,\n",
" \"intensity_bars\": (0., 1.),\n",
" \"intensity_target\": 0.5,\n",
" \"period\": \"ignore\"\n",
Expand All @@ -278,7 +278,7 @@
"# white_anderson\n",
"\n",
"Anderson variation of White's stimulus with default target placement.\n",
"Similar use as `white_two_rows()` but with additional variables for stripes (`stripe_size`, `stripe_center_offset` and `intensity_stripes`)"
"Similar use as `white_two_rows()` but with additional variables for stripes (`stripe_height`, `stripe_center_offset` and `intensity_stripes`)"
]
},
{
Expand Down Expand Up @@ -306,15 +306,15 @@
"params = {\n",
" \"visual_size\": (10., 10.),\n",
" \"ppd\": 10.0,\n",
" \"grating_frequency\": 0.5,\n",
" \"frequency\": 0.5,\n",
" \"target_indices_top\": 3,\n",
" \"target_indices_bottom\": -4,\n",
" \"target_center_offset\": 2.,\n",
" \"target_size\": 2.,\n",
" \"target_height\": 2.,\n",
" \"intensity_bars\": (0., 1.),\n",
" \"intensity_target\": 0.5,\n",
" \"period\": \"ignore\",\n",
" \"stripe_size\": 2.,\n",
" \"stripe_height\": 2.,\n",
" \"stripe_center_offset\": 3.,\n",
" \"intensity_stripes\": (0., 1.),\n",
"}\n",
Expand All @@ -333,10 +333,10 @@
"params = {\n",
" \"visual_size\": (10., 10.),\n",
" \"ppd\": 10.0,\n",
" \"grating_frequency\": 0.5,\n",
" \"frequency\": 0.5,\n",
" \"target_indices_top\": 3,\n",
" \"target_indices_bottom\": -4,\n",
" \"target_size\": 2.,\n",
" \"target_height\": 2.,\n",
" \"intensity_bars\": (0., 1.),\n",
" \"intensity_target\": 0.5,\n",
" \"period\": \"ignore\",\n",
Expand All @@ -345,12 +345,12 @@
" \n",
"stim1 = white_anderson(**params,\n",
" target_center_offset=3.,\n",
" stripe_size=3.,\n",
" stripe_height=3.,\n",
" stripe_center_offset=2.)\n",
"\n",
"stim2 = white_anderson(**params,\n",
" target_center_offset=2.,\n",
" stripe_size=1.,\n",
" stripe_height=1.,\n",
" stripe_center_offset=2.)\n",
"\n",
"\n",
Expand All @@ -365,7 +365,7 @@
"# white_howe\n",
"\n",
"Howe variation of White's stimulus with default target placement.\n",
"Same use as `white_anderson()` but with `stripe_size=target_size` and `stripe_center_offset=target_center_offset`."
"Same use as `white_anderson()` but with `stripe_height=target_height` and `stripe_center_offset=target_center_offset`."
]
},
{
Expand Down Expand Up @@ -393,11 +393,11 @@
"params = {\n",
" \"visual_size\": (10., 10.),\n",
" \"ppd\": 10.0,\n",
" \"grating_frequency\": 0.5,\n",
" \"frequency\": 0.5,\n",
" \"target_indices_top\": 3,\n",
" \"target_indices_bottom\": -4,\n",
" \"target_center_offset\": 2.,\n",
" \"target_size\": 2.,\n",
" \"target_height\": 2.,\n",
" \"intensity_bars\": (0., 1.),\n",
" \"intensity_target\": 0.5,\n",
" \"period\": \"ignore\",\n",
Expand Down Expand Up @@ -444,11 +444,11 @@
"params = {\n",
" \"visual_size\": (10., 10.),\n",
" \"ppd\": 10.0,\n",
" \"grating_frequency\": 0.5,\n",
" \"frequency\": 0.5,\n",
" \"target_indices_top\": 3,\n",
" \"target_indices_bottom\": -4,\n",
" \"target_center_offset\": 2.,\n",
" \"target_size\": 2.,\n",
" \"target_height\": 2.,\n",
" \"intensity_bars\": (0., 1.),\n",
" \"intensity_target\": 0.5,\n",
" \"period\": \"ignore\",\n",
Expand All @@ -460,6 +460,13 @@
"plot_stim(stim)\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -478,7 +485,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.13"
"version": "3.10.6"
},
"toc": {
"base_numbering": 1,
Expand All @@ -493,6 +500,35 @@
"toc_section_display": true,
"toc_window_display": false
},
"varInspector": {
"cols": {
"lenName": 16,
"lenType": 16,
"lenVar": 40
},
"kernels_config": {
"python": {
"delete_cmd_postfix": "",
"delete_cmd_prefix": "del ",
"library": "var_list.py",
"varRefreshCmd": "print(var_dic_list())"
},
"r": {
"delete_cmd_postfix": ") ",
"delete_cmd_prefix": "rm(",
"library": "var_list.r",
"varRefreshCmd": "cat(var_dic_list()) "
}
},
"types_to_exclude": [
"module",
"function",
"builtin_function_or_method",
"instance",
"_Feature"
],
"window_display": false
},
"vscode": {
"interpreter": {
"hash": "d79f930315d22092267204fc095ece7b80c939bb23fde6f7397d8c6352112825"
Expand Down
16 changes: 4 additions & 12 deletions stimuli/illusions/grating.py
Expand Up @@ -33,7 +33,6 @@ def square_wave(
target_indices=(),
intensity_target=0.5,
origin="corner",
round_phase_width=True,
):
"""Spatial square-wave grating (set of bars), with some bar(s) as target(s)
Expand Down Expand Up @@ -73,8 +72,6 @@ def square_wave(
if "corner": set origin to upper left corner (default)
if "mean": set origin to hypothetical image center
if "center": set origin to real center (closest existing value to mean)
round_phase_width : Bool
if True, round width of bars
Returns
----------
Expand All @@ -97,7 +94,7 @@ def square_wave(
period=period,
intensity_bars=intensity_bars,
origin=origin,
round_phase_width=round_phase_width,
round_phase_width=True,
)

# Resolve target parameters
Expand Down Expand Up @@ -139,7 +136,6 @@ def grating_uniform(
intensity_target=0.5,
intensity_background=0.5,
origin="corner",
round_phase_width=True,
):
"""Spatial square-wave grating (set of bars), on a background
Expand Down Expand Up @@ -183,8 +179,6 @@ def grating_uniform(
if "corner": set origin to upper left corner (default)
if "mean": set origin to hypothetical image center
if "center": set origin to real center (closest existing value to mean)
round_phase_width : Bool
if True, round width of bars
Returns
----------
Expand Down Expand Up @@ -217,7 +211,6 @@ def grating_uniform(
target_indices=target_indices,
intensity_target=intensity_target,
origin=origin,
round_phase_width=round_phase_width,
)

# Padding
Expand Down Expand Up @@ -349,7 +342,6 @@ def counterphase_induction(
target_phase_shift=0,
intensity_target=0.5,
origin="corner",
round_phase_width=True,
):
if orientation == "horizontal":
rotation = 0
Expand All @@ -371,7 +363,7 @@ def counterphase_induction(
period=period,
intensity_bars=intensity_bars,
origin=origin,
round_phase_width=round_phase_width,
round_phase_width=True,
)

stim_target = square_wave_component(
Expand All @@ -383,7 +375,7 @@ def counterphase_induction(
period=period,
intensity_bars=(intensity_target, 0),
origin=origin,
round_phase_width=round_phase_width,
round_phase_width=True,
)
stim_target = pad_dict_to_shape(stim_target, stim["shape"], 0)
cycle_px = stim_target["bar_width"] * stim_target["ppd"][0] * 2
Expand Down Expand Up @@ -662,7 +654,7 @@ def grating_induction_blur(
small_grating_params={**small_grating,
"rotation": 90},
mask_size=(5, 5, 2)),
"Counterphase induction": counterphase_induction(**params, target_size=4, target_phase_shift=360),
"Counterphase induction": counterphase_induction(**params, target_size=4, target_phase_shift=90),
"Grating induction": grating_induction(**params, target_width=0.5),
"Grating induction blur": grating_induction_blur(**params, target_width=0.5, target_blur=5),
}
Expand Down

0 comments on commit df751a5

Please sign in to comment.