@@ -89,8 +89,10 @@ def decomposition(movie, n_components=5):
89
89
90
90
ica = FastICA (n_components = n_components , fun = "exp" , random_state = 0 )
91
91
92
- spatial_components = np .abs (ica .fit_transform (X ). reshape ( * dims , n_components ). T )
92
+ spatial_components = np .abs (ica .fit_transform (X ))
93
93
temporal_components = np .abs (ica .mixing_ )
94
+ temporal_components *= spatial_components .max (axis = 0 )
95
+ spatial_components = spatial_components .reshape (* dims , n_components ).T
94
96
95
97
contours = list ()
96
98
for index in range (n_components ):
@@ -121,13 +123,13 @@ def decomposition(movie, n_components=5):
121
123
figure = fpl .Figure (
122
124
(3 , 1 ),
123
125
size = (700 , 1024 ),
124
- names = ["movie" , "heatmap" , "selected" ]
126
+ names = ["movie" , "heatmap" , "selected" ],
125
127
)
126
128
127
129
figure ["heatmap" ].camera .maintain_aspect = False
128
130
figure ["selected" ].camera .maintain_aspect = False
129
131
130
- movie_graphic = figure ["movie" ].add_image (movie [0 ], cmap = "viridis" )
132
+ movie_graphic = figure ["movie" ].add_image (movie [0 ], cmap = "viridis" , vmin = movie . min (), vmax = movie . max () )
131
133
contours_graphic = figure ["movie" ].add_line_collection (contours , cmap = "tab10" )
132
134
133
135
heatmap_graphic = figure ["heatmap" ].add_image (time_series , cmap = "viridis" )
@@ -138,17 +140,22 @@ def decomposition(movie, n_components=5):
138
140
selector_time_line = temporal_selected_graphic .add_linear_selector ()
139
141
140
142
def set_timepoint (ev ):
141
- timepoint = ev .info ["selection " ]
142
- movie_graphic .data [:] = movie [round (timepoint )]
143
+ timepoint = ev .info ["value " ]
144
+ movie_graphic .data [:] = movie [int (timepoint )]
143
145
selector_time_heatmap .selection = timepoint
144
146
selector_time_line .selection = timepoint
145
147
148
+ selector_time_line .add_event_handler (set_timepoint , "selection" )
149
+ selector_time_heatmap .add_event_handler (set_timepoint , "selection" )
146
150
147
151
@movie_graphic .add_event_handler ("click" )
148
152
def image_clicked (ev ):
149
153
contours_graphic .cmap = "tab10"
150
- nearest_contour = fpl .utils .get_nearest_graphics ((ev .x , ev .y ), contours_graphic )[0 ]
154
+ pos = figure ["movie" ].map_screen_to_world (ev )
155
+ index = fpl .utils .get_nearest_graphics_indices (pos , contours_graphic )[0 ]
156
+ nearest_contour = contours_graphic .graphics [index ]
151
157
nearest_contour .colors = "w"
158
+ selector_component_heatmap .selection = index
152
159
153
160
154
161
@selector_component_heatmap .add_event_handler ("selection" )
@@ -157,6 +164,8 @@ def heatmap_component_changed(ev):
157
164
contours_graphic .cmap = "tab10"
158
165
contours_graphic .graphics [index ].colors = "w"
159
166
167
+ temporal_selected_graphic .data [:, 1 ] = time_series [index ]
168
+
160
169
161
170
figure .show ()
162
171
fpl .loop .run ()
0 commit comments