Commit 06372299 authored by Ossi Laine's avatar Ossi Laine
Browse files

Added script for testing embody randomization

parent 7be514aa
......@@ -263,7 +263,6 @@ def task(page_num):
def completed():
session.pop('user', None)
session.pop('exp_id', None)
session.pop('agree', None)
Script for testing embody drawing results from
Install requirements:
pip install numpy
pip install matplotlib
Export data from and after that run the script in the same folder
by passing exported_file as a parameter to the script
$ python <exported_file>.csv
Program prints header of the file, from which you must select column where the
image data is. After you have selected the right column, program prints the
drawing results from embody answers.
If you want the program to draw default embody image to the background, then
you must put a copy of the 'dummy_6000.png' -file (this is the same that is used
in onni.utu.fu) to the same path as the script.
import copy
import numpy as np
import matplotlib.pyplot as plt
import csv
import sys
import json
def show_images(images, cols=1, titles=None):
"""Display a list of images in a single figure with matplotlib.
images: List of np.arrays compatible with plt.imshow.
cols (Default = 1): Number of columns in figure (number of rows is
set to np.ceil(n_images/float(cols))).
titles: List of titles corresponding to each image. Must have
the same length as titles.
# default embody image for the background
default_img = plt.imread("./dummy_600.png")
# get a copy of the gray color map
my_cmap = copy.copy('gray'))
# set how the colormap handles 'bad' values
assert((titles is None) or (len(images) == len(titles)))
n_images = len(images)
if titles is None:
titles = ['Image (%d)' % i for i in range(1, n_images + 1)]
fig = plt.figure()
for n, (image, title) in enumerate(zip(images, titles)):
a = fig.add_subplot(cols, np.ceil(n_images/float(cols)), n + 1)
# draw points from users answers
plt.imshow(image, cmap=my_cmap)
# draw default background image with transparency on top of the points
plt.imshow(default_img, extent=[0, 200, 600, 0], alpha=0.33)
fig.set_size_inches(np.array(fig.get_size_inches()) * n_images)
if __name__ == '__main__':
images = []
titles = []
# filename = 'experiment_1_2020-05-20.csv'
filename = sys.argv[1]
with open(filename, 'r+') as csvfile:
for row_no, row in enumerate(csv.reader(csvfile, delimiter=';')):
# parse header
if row_no == 0:
for column, title in enumerate(row):
print("Column (no. {}): {}".format(column, title))
print('Enter the column number which has image data:')
x = int(input())
np_array = np.array(eval(row[x]))
except NameError:
"Column didn't contain image data. Try again with different column number.")
np_array = np.transpose(np_array)
# add id of the answerer to the image
show_images(images, titles=titles)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment