Skip to content

Commit

Permalink
Merge branch 'feat_testing' into dev_refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
JorisVincent committed Jun 24, 2022
2 parents 975c8bf + 653b36a commit 72278d4
Show file tree
Hide file tree
Showing 14 changed files with 340 additions and 993 deletions.
30 changes: 23 additions & 7 deletions stimuli/papers/RHS2007.py
Expand Up @@ -39,6 +39,28 @@
PPD = 32


def gen_all(ppd=PPD, skip=False):
stims = {} # save the stimulus-dicts in a larger dict, with name as key
for stim_name in __all__:
print(f"Generating RHS2007.{stim_name}")

# Get a reference to the actual function
func = globals()[stim_name]
try:
stim = func()

# Accumulate
stims[stim_name] = stim
except NotImplementedError as e:
if not skip:
raise e
# Skip stimuli that aren't implemented
print("-- not implemented")
pass

return stims


def WE_thick(ppd=PPD):
height, width = 12.0, 16.0
n_cycles = 4.0
Expand Down Expand Up @@ -660,12 +682,6 @@ def bullseye_thick(ppd=PPD):
if __name__ == "__main__":
from stimuli.utils import plot_stimuli

stims = {}
for stimname in __all__:
print("Generating " + stimname)
try:
stims[stimname] = globals()[stimname]()
except NotImplementedError:
print("-- not implemented")
stims = gen_all(skip=True)

plot_stimuli(stims, mask=False)
2 changes: 1 addition & 1 deletion stimuli/papers/__init__.py
@@ -1 +1 @@
from . import RHS2007, domijan2015, murray2020
__all__ = ["RHS2007", "domijan2015", "murray2020"]
30 changes: 23 additions & 7 deletions stimuli/papers/domijan2015.py
Expand Up @@ -19,6 +19,28 @@
PPD = 10


def gen_all(ppd=PPD, skip=False):
stims = {} # save the stimulus-dicts in a larger dict, with name as key
for stim_name in __all__:
print(f"Generating domijan2015.{stim_name}")

# Get a reference to the actual function
func = globals()[stim_name]
try:
stim = func()

# Accumulate
stims[stim_name] = stim
except NotImplementedError as e:
if not skip:
raise e
# Skip stimuli that aren't implemented
print("-- not implemented")
pass

return stims


def dungeon(ppd=PPD):
return illusions.dungeon.dungeon_illusion(
ppd=ppd,
Expand Down Expand Up @@ -222,12 +244,6 @@ def checkerboard_extended(ppd=PPD):
if __name__ == "__main__":
from stimuli.utils import plot_stimuli

stims = {}
for stimname in __all__:
print("Generating " + stimname)
try:
stims[stimname] = globals()[stimname]()
except NotImplementedError:
print("-- not implemented")
stims = gen_all(skip=True)

plot_stimuli(stims, mask=False)
31 changes: 24 additions & 7 deletions stimuli/papers/murray2020.py
Expand Up @@ -59,6 +59,28 @@
mat_content = scipy.io.loadmat(mat_fname)


def gen_all(skip=False):
stims = {} # save the stimulus-dicts in a larger dict, with name as key
for stim_name in __all__:
print(f"Generating murray2020.{stim_name}")

# Get a reference to the actual function
func = globals()[stim_name]
try:
stim = func()

# Accumulate
stims[stim_name] = stim
except NotImplementedError as e:
if not skip:
raise e
# Skip stimuli that aren't implemented
print("-- not implemented")
pass

return stims


def get_mask(target1, target2, shape):
mask = np.zeros(shape)

Expand Down Expand Up @@ -322,12 +344,7 @@ def white():
if __name__ == "__main__":
from stimuli.utils import plot_stimuli

stims = {}
for stimname in __all__:
print("Generating " + stimname)
try:
stims[stimname] = globals()[stimname]()
except NotImplementedError:
print("-- not implemented")
# Generate all stimuli exported in __all__
stims = gen_all(skip=True)

plot_stimuli(stims, mask=False)
18 changes: 18 additions & 0 deletions stimuli/utils/export.py
@@ -0,0 +1,18 @@
import json
from hashlib import md5

import numpy as np


def arrs_to_checksum(stim, keys=["img", "mask"]):
# Hash (md5) values, and save only the hex
for key in keys:
stim[key] = md5(np.ascontiguousarray(stim[key])).hexdigest()

return stim


def to_json(stim, filename):
# stimulus-dict(s) as (pretty) JSON
with open(filename, "w", encoding="utf-8") as f:
json.dump(stim, f, ensure_ascii=False, indent=4)
90 changes: 90 additions & 0 deletions tests/papers/RHS2007.json
@@ -0,0 +1,90 @@
{
"WE_thick": {
"img": "4e6d0130b6f37eeaff7f568c31c68325",
"mask": "b523788d266b5f7ded635717acad5a54"
},
"WE_thin_wide": {
"img": "d0540819930d454dd272f9ee91739114",
"mask": "82738b790feeb3d762822cf13136abd5"
},
"WE_dual": {
"img": "0eb7042718b74b8973d8e945f0454867",
"mask": "88a5faacb4e5db2d7f5761066dc92f38"
},
"WE_anderson": {
"img": "34284f8560d01e2231fe30b9362e8577",
"mask": "ec5671221e98b96b6b35622424266eaf"
},
"WE_howe": {
"img": "f68a1210ae539a0dd4976bc8eaa701a8",
"mask": "c05d4411f96114b3b7ffe73254ff2875"
},
"WE_radial_thick_small": {
"img": "b92d533177eed4a009625d6d2cb0da59",
"mask": "78da2d5ec63b48e53f5bdbd90d2b82b9"
},
"WE_radial_thick": {
"img": "d0067dfb57016354f7b107ae410d217c",
"mask": "482a1a903b54df01f3e16cb284b8bfeb"
},
"WE_radial_thin_small": {
"img": "94e6b546f8ad5c6b95a502a8b409c00d",
"mask": "38a4da8d63237ac33b1a7f5e1cd021ec"
},
"WE_circular1": {
"img": "2ecc5cb5ad9cfef50de681ee3b923f46",
"mask": "32f876b2d56ce7a9f712f7784dc60289"
},
"WE_circular05": {
"img": "5d09c011b57d3afffcaf82e7aea84b34",
"mask": "dde7cc1ee48b2d47b37fbe9422e0f677"
},
"WE_circular025": {
"img": "ec3feee88c49aed0a5554c3838be8519",
"mask": "e4e9c650c9a247180211dbcde0e38fb2"
},
"grating_induction": {
"img": "da62004fdc198660b44529f8b6358362",
"mask": "40f02639e692658b9f357b09c11e9df1"
},
"sbc_large": {
"img": "8c1d036742bdf01159177f42625fe144",
"mask": "6f1f89e7d2a6d1b88c29c051ef3a2dd0"
},
"sbc_small": {
"img": "ae061d71fede147fcc8e7680e14e82c9",
"mask": "f4f124cbfae47fd81b7d398c09836495"
},
"todorovic_equal": {
"img": "caecfb4065b54222e8d810e00da685af",
"mask": "2821bec9b23503e1598696d0ab418f3b"
},
"todorovic_in_large": {
"img": "ba9c3382426f8e0e9864d4b999c7979c",
"mask": "265174ba6cc11c8a90fe9c822b18dfeb"
},
"todorovic_in_small": {
"img": "0ab88dbeb1419b4b786134cc432d73d7",
"mask": "a711607fc494557ce2b52e984dc103b4"
},
"checkerboard_016": {
"img": "cffb926181df5cea95608b95bbc163f1",
"mask": "1eb12e597ac5c454830dc2873730ccc1"
},
"checkerboard_0938": {
"img": "ffe0d07c218fa56eecce2a9386908ff5",
"mask": "845b86fd98823fc4778f76a360da6d52"
},
"checkerboard209": {
"img": "3058e7c3d03899760fede8aba1c940ac",
"mask": "1172e323e0af65b431a4641be9836b7b"
},
"bullseye_thin": {
"img": "59c97cb1feffb4c9c502b143c5699fb3",
"mask": "08cfee34814f232afda08e138da10661"
},
"bullseye_thick": {
"img": "59c97cb1feffb4c9c502b143c5699fb3",
"mask": "08cfee34814f232afda08e138da10661"
}
}
50 changes: 50 additions & 0 deletions tests/papers/domijan2015.json
@@ -0,0 +1,50 @@
{
"dungeon": {
"img": "23859250c9f5a895de48c20e7095f4e9",
"mask": "1954462ad5eeb864935b349630f918f9"
},
"cube": {
"img": "59ac0095ba9c17a2cdd98ffff6613447",
"mask": "3a6543daa69e82047d0b84b76a446312"
},
"grating": {
"img": "44286e04ca4f44fe98930722c0d45b1a",
"mask": "cb796a47e9ca6c8426a2585c9b604989"
},
"rings": {
"img": "38a7bc014428864fffcee590d0953465",
"mask": "3c5c395de3b4cae5b6956314624ea012"
},
"bullseye": {
"img": "e30fb79cf7897dfed4ce04983b36ba28",
"mask": "721937af54e313931f38a22b7a6ce885"
},
"simultaneous_brightness_contrast": {
"img": "a0e0353cd1fb9a829241ddecc51fbc64",
"mask": "c46a87aa52c48192ce96c90fbe10c062"
},
"white": {
"img": "377a2903002d526da2ba1d052eb193d2",
"mask": "306423f9e89e6d3bd21a946881ef684a"
},
"benary": {
"img": "4c3f2278ac91effebf1db9f580a24db6",
"mask": "c790aa14edddb57f8054a4f330c7ddc6"
},
"todorovic": {
"img": "1b9d5b09475aace9b97f599c5731177b",
"mask": "2eeeeb428daf6be031c64ef841e7c897"
},
"checkerboard_contrast_contrast": {
"img": "246c282926e1a0b390eb4bca6bd00b16",
"mask": "487c5cbe9dfd08719ead98ea9a7e901c"
},
"checkerboard": {
"img": "6891d301caf87043b99c199f13fdf607",
"mask": "70844521cd62275df0cab9a7c1184d9d"
},
"checkerboard_extended": {
"img": "570e9597fa49a33a6e96687a007ad3e0",
"mask": "f6ee08aeab807602449271ee7367cc44"
}
}
468 changes: 0 additions & 468 deletions tests/papers/domijan2015.pickle

This file was deleted.

22 changes: 22 additions & 0 deletions tests/papers/gen_ground_truth.py
@@ -0,0 +1,22 @@
from os.path import abspath, dirname

from stimuli.papers import *
from stimuli.papers import __all__ as papers
from stimuli.utils import export

d = dirname(abspath(__file__))

# Generate the ground_truth dict for each paper; save as .JSON
for paper in papers:
# Get a reference to the actual module, from the name-string
paper_module = globals()[paper]

# Generate all the stimulus-dicts (skip over NotImplemented)
stims = paper_module.gen_all(skip=True)

# Convert "img", "mask" to checksums
for stim in stims.values():
export.arrs_to_checksum(stim, ["img", "mask"])

# Save all as .JSON
export.to_json(stims, f"{d}/{paper}.json")
50 changes: 50 additions & 0 deletions tests/papers/murray2020.json
@@ -0,0 +1,50 @@
{
"argyle": {
"img": "cb4ed25c9e5d878c4daf41a57656e4ba",
"mask": "b9c1760d980dc13c5bb2fda8ebe537c2"
},
"argyle_control": {
"img": "e3e1e33d7eb3f1e4ea2c0100e551b3e6",
"mask": "91dbc28e28a6209bcd187a11e0321cae"
},
"argyle_long": {
"img": "ce09cf6536bc04037536c767c973ef9c",
"mask": "83ffc7391ddcbebfe6cec7b0944c6dc0"
},
"snake": {
"img": "06337656c123eeb36dd75963639adaa2",
"mask": "02636e9e6289b9ae0bb36e518fc20e3f"
},
"snake_control": {
"img": "3473bf614bdf0eb68b4c7c8ce1b29697",
"mask": "02636e9e6289b9ae0bb36e518fc20e3f"
},
"koffka_adelson": {
"img": "16f09cb37a170053a73f5183f289b6df",
"mask": "ecf8713ae03549fa9ee16b1462ff5bf1"
},
"koffka_broken": {
"img": "f710a7d1ceb75d1f6cac9d91e1c2a821",
"mask": "40c249e4d8835580b7f57d04e0df65c4"
},
"koffka_connected": {
"img": "9ffb69c20afbaf731877b4626d61c404",
"mask": "4e4fa0cbe12df9fa7bdab6b0fc073270"
},
"checkassim": {
"img": "ef5b9b410280b3f2e2ff45ee165e32d7",
"mask": "4bc92371e105629f30513c1050f99cf4"
},
"simcon": {
"img": "87da2163dcd4ce3ef214c48fa243c787",
"mask": "99fbc73e5c8aefd70501838130b806e9"
},
"simcon_articulated": {
"img": "61685f75a7352ff756d566a6ffcc8faf",
"mask": "99fbc73e5c8aefd70501838130b806e9"
},
"white": {
"img": "0fb691c397d4bdcbb0eb5f89134be5aa",
"mask": "b0f4ec00fd2d12d15f005af9b53b29f8"
}
}

0 comments on commit 72278d4

Please sign in to comment.