Skip to content

Commit 6d44368

Browse files
author
O-Sven
committed
plot_model plots now the previously fitted model and does not fit a new model
1 parent 3536791 commit 6d44368

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

ledsa/analysis/plot_functions.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
sep = os.path.sep
1515

1616
# dictionary of the fit parameter positions
17+
# only used as reference
1718
par_dic = {
1819
"x": 2,
1920
"y": 3,
@@ -85,7 +86,8 @@ def plot_t_fitpar(fig, led_id, fit_par, channel, image_id_start, image_id_finish
8586
def plot_t_fitpar_with_moving_average(fig, led_id, fit_par, channel, image_id_start, image_id_finish, box_size=61):
8687
"""Plots the time development of a fit parameter and its moving average"""
8788
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))
8991

9092
ax = fig.gca(xlabel='time[s]', ylabel=fit_par)
9193
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):
119121

120122
plt.title(f'Channel {channel}, Image {img_id}, LED {led_id}')
121123

122-
# plt.savefig(model.png)
123124
plt.show()
124125

125126

@@ -139,11 +140,13 @@ def plot_model(fig, channel, img_id, led_id, window_radius):
139140
mesh = np.meshgrid(np.linspace(0.5, 2 * window_radius - 0.5, 2 * window_radius),
140141
np.linspace(0.5, 2 * window_radius - 0.5, 2 * window_radius))
141142

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+
147150
led_model = led.led_fit(mesh[0], mesh[1], model_params[0], model_params[1], model_params[2], model_params[3],
148151
model_params[4], model_params[5], model_params[6], model_params[7])
149152

@@ -154,8 +157,8 @@ def plot_model(fig, channel, img_id, led_id, window_radius):
154157
con = ax.contour(mesh[0], mesh[1], led_model, levels=10, alpha=0.9)
155158
fig.colorbar(mappable=con, ax=ax)
156159
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')
159162

160163
plt.figure(current_fig.number)
161164

@@ -222,17 +225,22 @@ def fit_led(img_id, led_id, channel):
222225
return fit_res
223226

224227

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+
225236
def get_led_img(time, led_id, window_radius=10):
226237
filename = led.get_img_name(led.get_img_id_from_time(time))
227-
print(filename)
228238
path = get_img_path()
229239
led_im = Image.open(path + filename)
230240

231241
x, y = get_led_pos(led_id)
232-
print(x, y)
233242
led_im = led_im.crop((y - window_radius,
234243
x - window_radius,
235244
y + window_radius,
236245
x + window_radius))
237246
return led_im
238-

ledsa/core/_led_helper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ def get_img_data(config, build_experiment_infos=False, build_analysis_infos=Fals
8282
experiment_time = experiment_time.total_seconds()
8383
time_diff = config[build_type]['exif_time_infront_real_time'].split('.')
8484
time = date_time_img - timedelta(seconds=int(time_diff[0]), milliseconds=int(time_diff[1]))
85-
img_data += (str(img_idx) + ',' + config[build_type]['img_name_string'].format(int(img_number)) + ',' +
86-
time.strftime('%H:%M:%S') + ',' + str(experiment_time) + '\n')
85+
img_data += (str(img_idx) + ',' + config[build_type]['img_name_string'].format(int(img_number)) +
86+
',' + time.strftime('%H:%M:%S') + ',' + str(experiment_time) + '\n')
8787
img_idx += 1
8888
return img_data
8989

ledsa/tests/log_analysis.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def plot_image(self):
4848
mesh = np.meshgrid(np.linspace(0.5, self.nx - 0.5, self.nx), np.linspace(0.5, self.ny - 0.5, self.ny))
4949

5050
led_model = led.led_fit(mesh[0], mesh[1], self.fit[0], self.fit[1], self.fit[2], self.fit[3], self.fit[4],
51-
self.fit[5], self.fit[6], self.fit[7])
51+
self.fit[5], self.fit[6], self.fit[7])
5252

5353
fig, ax = plt.subplots(1, 2, dpi=600)
5454

@@ -59,7 +59,7 @@ def plot_image(self):
5959
ax[1].imshow(led_model, cmap='Greys')
6060

6161
ampl = np.max(np.abs(data[s] - led_model)) # 0.25
62-
maxA = 255 # np.max(np.abs(data[s]))
62+
maxA = 255 # np.max(np.abs(data[s]))
6363

6464
im2 = ax[1].imshow((data[s] - led_model)/maxA, cmap='seismic', vmin=-ampl/maxA, vmax=ampl/maxA)
6565
plt.colorbar(mappable=im2)

0 commit comments

Comments
 (0)