-
Notifications
You must be signed in to change notification settings - Fork 1
/
matchOMBandchecker.py
139 lines (105 loc) · 3.75 KB
/
matchOMBandchecker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
"""
import numpy as np
import matplotlib.pyplot as plt
import analysis_scripts as asc
import iofuncs as iof
def read_and_match_pars(exp, omb_stimnr, chk_stimnr):
OMB_DEFAULT_TEXTURESIZE = np.array([800, 800])
_, metadata = asc.read_spikesheet(exp)
scr_x, scr_y = metadata['screen_width'], metadata['screen_height']
#datao = iof.load(exp, omb_stimnr)
#datac = iof.load(exp, checker_stimnr)
parso = asc.read_parameters(exp, omb_stimnr)
parsc = asc.read_parameters(exp, chk_stimnr)
chk_stxw, chk_stxh = [parsc[key] for key in ['stixelwidth', 'stixelheight']]
if (not chk_stxw == chk_stxh or
parsc['stimulus_type'] not in ['FrozenNoise', 'checkerflicker']):
ValueError(f'{iof.getstimname(exp, chk_stimnr)} is not '
'checkerflicker!')
# ckdim = scr_x//chk_stxw
# omb_dim = np.array(OMB_DEFAULT_TEXTURESIZE)//parso['bgstixel']
ombstx = parso['bgstixel']
chkstx = chk_stxw
# Calculate the difference between the dimensions for both stimuli in pixels
px_diff = OMB_DEFAULT_TEXTURESIZE - np.array([scr_x, scr_y])
# We divide by two because the texture is centered in the screen and
# clipped.
px_diff //= 2
# HINT
px_diff = px_diff[::-1]
return ombstx, chkstx, px_diff
def coord_omb2chk(omb_coord, exp, omb_stimnr, chk_stimnr):
"""
Convert OMB coordinates to checkerflicker to match the locations
from both stimuli.
Parameters
------
omb_coord:
(x, y) coordinates in the OMB texture
omb_stimnr:
The stimulus number for OMB
chk_stimnr:
The stimulus number for checkerflicker
Returns
------
chk_coord:
Coordinates in the checkerflicker stimulus
"""
ombstx, chkstx, px_diff = read_and_match_pars(exp, omb_stimnr, chk_stimnr)
coord = omb_coord * ombstx
coord -= px_diff
coord = (np.round(coord / chkstx)).astype(int)
return coord
def coord_chk2omb(chk_coord, exp, omb_stimnr, chk_stimnr):
"""
Convert checkerflicker coordinates to OMB to match the locations
from both stimuli.
Parameters
------
chk_coord:
(x, y) coordinates in the checkerflicker stimulus
omb_stimnr:
The stimulus number for OMB
chk_stimnr:
The stimulus number for checkerflicker
Returns
------
chk_coord:
Coordinates in the OMB texture
"""
ombstx, chkstx, px_diff = read_and_match_pars(exp, omb_stimnr, chk_stimnr)
coord = chk_coord * chkstx
coord += px_diff
coord = (np.round(coord / ombstx)).astype(int)
return coord
def chkmax2ombcoord(cell_i, exp, omb_stimnr, chk_stimnr):
"""
Starting from the index of the cell, return the coordinates of the
maximum pixel of checkerflicker STA in OMB coordinates.
Parameters
---------
cell_i
Cell index
"""
data = iof.load(exp, chk_stimnr)
maxinds = np.array(data['max_inds'])
coord = coord_chk2omb(maxinds[cell_i][:-1], exp, omb_stimnr, chk_stimnr)
return coord
#%%
if __name__ == '__main__':
exp, omb_stimnr = '20180710_YE', 8
chk_stimnr = 6
omstx, ckstx, _ = read_and_match_pars(exp, omb_stimnr, chk_stimnr)
#ckstx = parsc['stixelwidth']
#omstx = parso['bgstixel']
test_coords_omb = np.array([[400, 300], [600, 300], [400, 250],
[800, 600], [0, 0]])/omstx
res_coords_chk = np.empty(test_coords_omb.shape)
for i, test_coord in enumerate(test_coords_omb):
tochk = coord_omb2chk(test_coord, exp, omb_stimnr, chk_stimnr)
res_coords_chk[i] = tochk
tochktoomb = coord_chk2omb(tochk, exp, omb_stimnr, chk_stimnr)
print(test_coord*omstx, test_coord, tochk, tochk*ckstx, tochktoomb, tochktoomb*omstx)