14
14
sep = os .path .sep
15
15
16
16
# dictionary of the fit parameter positions
17
+ # only used as reference
17
18
par_dic = {
18
19
"x" : 2 ,
19
20
"y" : 3 ,
@@ -85,7 +86,8 @@ def plot_t_fitpar(fig, led_id, fit_par, channel, image_id_start, image_id_finish
85
86
def plot_t_fitpar_with_moving_average (fig , led_id , fit_par , channel , image_id_start , image_id_finish , box_size = 61 ):
86
87
"""Plots the time development of a fit parameter and its moving average"""
87
88
plot_info = _calc_t_fitpar_plot_info (led_id , fit_par , channel , image_id_start , image_id_finish )
88
- average = plot_info [fit_par ].rolling (box_size , center = True , win_type = 'gaussian' ).sum (std = 10 ) / 10 / np .sqrt (2 * np .pi )
89
+ average = plot_info [fit_par ].rolling (box_size , center = True , win_type = 'gaussian' ).sum (std = 10 ) / (10 *
90
+ np .sqrt (2 * np .pi ))
89
91
90
92
ax = fig .gca (xlabel = 'time[s]' , ylabel = fit_par )
91
93
plot , = ax .plot (plot_info ['experiment_time' ], plot_info [fit_par ], alpha = 0.2 )
@@ -119,7 +121,6 @@ def plot_led_with_fit(channel, time, led_id, window_radius=10):
119
121
120
122
plt .title (f'Channel { channel } , Image { img_id } , LED { led_id } ' )
121
123
122
- # plt.savefig(model.png)
123
124
plt .show ()
124
125
125
126
@@ -139,11 +140,13 @@ def plot_model(fig, channel, img_id, led_id, window_radius):
139
140
mesh = np .meshgrid (np .linspace (0.5 , 2 * window_radius - 0.5 , 2 * window_radius ),
140
141
np .linspace (0.5 , 2 * window_radius - 0.5 , 2 * window_radius ))
141
142
142
- fit_results = fit_led (img_id , led_id , channel )
143
- model_params = fit_results .x
144
- print (model_params )
145
- print (fit_results .keys ())
146
- print (fit_results )
143
+ # fit model
144
+ # fit_results = fit_led(img_id, led_id, channel)
145
+ # model_params = fit_results.x
146
+
147
+ # load model
148
+ model_params = load_model (img_id , led_id , channel , window_radius )
149
+
147
150
led_model = led .led_fit (mesh [0 ], mesh [1 ], model_params [0 ], model_params [1 ], model_params [2 ], model_params [3 ],
148
151
model_params [4 ], model_params [5 ], model_params [6 ], model_params [7 ])
149
152
@@ -154,8 +157,8 @@ def plot_model(fig, channel, img_id, led_id, window_radius):
154
157
con = ax .contour (mesh [0 ], mesh [1 ], led_model , levels = 10 , alpha = 0.9 )
155
158
fig .colorbar (mappable = con , ax = ax )
156
159
ax .scatter (model_params [0 ], model_params [1 ], color = 'Red' )
157
- plt .text (0 , window_radius * 2.2 , f'Num. of Iterations: { fit_results .nit } -/- l2 + penalty: { fit_results .fun :.4} ' ,
158
- ha = 'left' )
160
+ # plt.text(0, window_radius * 2.2, f'Num. of Iterations: {fit_results.nit} -/- l2 + penalty: {fit_results.fun:.4}',
161
+ # ha='left')
159
162
160
163
plt .figure (current_fig .number )
161
164
@@ -222,17 +225,22 @@ def fit_led(img_id, led_id, channel):
222
225
return fit_res
223
226
224
227
228
+ def load_model (img_id , led_id , channel , window_radius = 10 ):
229
+ fit_parameters = calc .read_hdf (channel )
230
+ model_params = np .array (fit_parameters .loc [img_id , led_id ])[1 :9 ]
231
+ pix_pos = get_led_pos (led_id )
232
+ model_params [0 :2 ] = model_params [0 :2 ] - pix_pos + window_radius
233
+ return model_params
234
+
235
+
225
236
def get_led_img (time , led_id , window_radius = 10 ):
226
237
filename = led .get_img_name (led .get_img_id_from_time (time ))
227
- print (filename )
228
238
path = get_img_path ()
229
239
led_im = Image .open (path + filename )
230
240
231
241
x , y = get_led_pos (led_id )
232
- print (x , y )
233
242
led_im = led_im .crop ((y - window_radius ,
234
243
x - window_radius ,
235
244
y + window_radius ,
236
245
x + window_radius ))
237
246
return led_im
238
-
0 commit comments