-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui_frame_mode_locking.py
505 lines (407 loc) · 25.3 KB
/
gui_frame_mode_locking.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
import numpy as np
import laser_mode_locking as worker
import wx
import matplotlib.pyplot as plt
import matplotlib.pylab as pylab
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.backends.backend_wxagg import NavigationToolbar2WxAgg as NavigationToolbar
# CONFIG ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
# CONFIG \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
def to_float(string_val):
try:
float_val = float(string_val)
except ValueError:
print(f'[ERROR] Invalid Input. Could not convert {string_val} to float.')
raise ValueError(f'Invalid Input. Could not convert {string_val} to float.')
else:
return float_val
def to_integer(string_val):
try:
int_val = int(string_val)
except ValueError:
print(f'[ERROR] Invalid Input. Could not convert {string_val} to integer.')
raise ValueError(f'Invalid Input. Could not convert {string_val} to integer.')
else:
return int_val
class MyDemoPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent, wx.ID_ANY)
self.frame = parent
self.left_panel = wx.Panel(self, wx.ID_ANY)
self.plot_panel = wx.Panel(self, wx.ID_ANY, style=wx.SIMPLE_BORDER)
# PLOT Panel ---------------------------------------------------------------------------------------------------
self.figure = plt.figure(figsize=(1, 1)) # look into Figure((5, 4), 75)
self.canvas = FigureCanvas(self.plot_panel, -1, self.figure)
self.toolbar = NavigationToolbar(self.canvas)
self.toolbar.Realize()
# Plot objects -------------------------------------------------------------------------------------------------
self.ax1 = self.figure.add_subplot(311)
self.ax2 = self.figure.add_subplot(312)
self.ax3 = self.figure.add_subplot(313)
self.temporal, = self.ax1.plot([], [], linestyle='-')
self.temporal_sum, = self.ax2.plot([], [], linestyle='-', marker='')
self.temporal_hilbert, = self.ax2.plot([], [], linestyle='-', marker='')
self.spectral, = self.ax3.plot([], [], color='#C02942')
self.spectral_envelope, = self.ax3.plot([], [], color='tab:blue')
# Plot Annotations ---------------------------------------------------------------------------------------------
# https://stackoverflow.com/a/38677732
self.arrow_dim_obj = self.ax3.annotate("", xy=(0, 0), xytext=(0, 0),
textcoords=self.ax3.transData, arrowprops=dict(arrowstyle='<->'))
self.bar_dim_obj = self.ax3.annotate("", xy=(0, 0), xytext=(0, 0),
textcoords=self.ax3.transData, arrowprops=dict(arrowstyle='|-|'))
bbox = dict(fc="white", ec="none")
self.dim_text = self.ax3.text(0, 0, "", ha="center", va="center", bbox=bbox)
# BINDINGS =====================================================================================================
self.combo_window = wx.ComboBox(self.left_panel, wx.ID_ANY,
choices=["Rectangular", "Bartlett", "Hanning", "Hamming", "Blackman"],
style=wx.CB_DROPDOWN | wx.CB_READONLY)
self.combo_bandwidth_shape = wx.ComboBox(self.left_panel, wx.ID_ANY,
choices=["Flat-Top", "Gaussian"],
style=wx.CB_DROPDOWN | wx.CB_READONLY)
self.text_ctrl_fc = wx.TextCtrl(self.left_panel, wx.ID_ANY, style=wx.TE_PROCESS_ENTER)
self.text_ctrl_laser_bw = wx.TextCtrl(self.left_panel, wx.ID_ANY, style=wx.TE_PROCESS_ENTER)
self.text_ctrl_mainlobe = wx.TextCtrl(self.left_panel, wx.ID_ANY, style=wx.TE_PROCESS_ENTER)
self.text_ctrl_mainlobe.SetToolTip("Mainlobe width")
self.text_ctrl_emitted_modes = wx.TextCtrl(self.left_panel, wx.ID_ANY, style=wx.TE_PROCESS_ENTER)
self.text_ctrl_index = wx.TextCtrl(self.left_panel, wx.ID_ANY, style=wx.TE_PROCESS_ENTER)
self.checkbox_random_phase = wx.CheckBox(self.left_panel, wx.ID_ANY, "Random Phase")
self.report_runtime = wx.TextCtrl(self.left_panel, wx.ID_ANY, "", style=wx.TE_READONLY)
self.report_laser_bw = wx.TextCtrl(self.left_panel, wx.ID_ANY, "", style=wx.TE_READONLY)
self.report_wavelength = wx.TextCtrl(self.left_panel, wx.ID_ANY, "", style=wx.TE_READONLY)
self.report_cavity_modes = wx.TextCtrl(self.left_panel, wx.ID_ANY, "", style=wx.TE_READONLY)
self.report_cavity_length = wx.TextCtrl(self.left_panel, wx.ID_ANY, "", style=wx.TE_READONLY)
self.report_df = wx.TextCtrl(self.left_panel, wx.ID_ANY, "", style=wx.TE_READONLY)
self.report_longitudinal_modes = wx.TextCtrl(self.left_panel, wx.ID_ANY, "", style=wx.TE_READONLY)
self.report_fwhm = wx.TextCtrl(self.left_panel, wx.ID_ANY, "", style=wx.TE_READONLY)
self.report_fwhm_width = wx.TextCtrl(self.left_panel, wx.ID_ANY, "", style=wx.TE_READONLY)
on_update = lambda event: self.update(event)
self.Bind(wx.EVT_TEXT_ENTER, on_update, self.text_ctrl_fc)
self.Bind(wx.EVT_TEXT_ENTER, on_update, self.text_ctrl_laser_bw)
self.Bind(wx.EVT_TEXT_ENTER, on_update, self.text_ctrl_mainlobe)
self.Bind(wx.EVT_TEXT_ENTER, on_update, self.text_ctrl_emitted_modes)
self.Bind(wx.EVT_TEXT_ENTER, on_update, self.text_ctrl_index)
self.Bind(wx.EVT_COMBOBOX_CLOSEUP, on_update, self.combo_bandwidth_shape)
self.Bind(wx.EVT_CHECKBOX, on_update, self.checkbox_random_phase)
self.__set_properties()
self.__do_layout()
self.__do_plot_layout()
self.update(wx.Event)
def __set_properties(self):
self.SetBackgroundColour(wx.Colour(240, 240, 240))
self.canvas.SetMinSize((700, 490))
self.combo_window.SetSelection(0)
self.combo_bandwidth_shape.SetSelection(0)
self.checkbox_random_phase.SetValue(0)
self.text_ctrl_fc.SetValue("473.613") # (THz)
self.text_ctrl_laser_bw.SetValue("0.1")
self.text_ctrl_index.SetValue("1.0")
self.text_ctrl_emitted_modes.SetValue("15")
self.text_ctrl_mainlobe.SetValue("0.01")
self.report_runtime.SetValue("--")
self.report_laser_bw.SetValue("--")
self.report_wavelength.SetValue("--")
self.report_cavity_modes.SetValue("--")
self.report_cavity_length.SetValue("--")
self.report_df.SetValue("--")
self.report_longitudinal_modes.SetValue("--")
self.report_fwhm.SetValue("--")
self.report_fwhm_width.SetValue("--")
def __do_layout(self):
sizer_2 = wx.GridSizer(1, 1, 0, 0)
grid_sizer_1 = wx.FlexGridSizer(1, 2, 0, 0)
grid_sizer_plot = wx.GridBagSizer(0, 0)
grid_sizer_left_panel = wx.GridBagSizer(0, 0)
# LEFT PANEL ---------------------------------------------------------------------------------------------------
# TITLE --------------------------------------------------------------------------------------------------------
row = 0
label_1 = wx.StaticText(self.left_panel, wx.ID_ANY, "LASER MODE-LOCKING")
label_1.SetFont(wx.Font(16, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, 0, ""))
grid_sizer_left_panel.Add(label_1, (row, 0), (1, 3), wx.LEFT | wx.RIGHT | wx.TOP, 5)
row += 1
static_line_1 = wx.StaticLine(self.left_panel, wx.ID_ANY)
static_line_1.SetMinSize((300, 2))
grid_sizer_left_panel.Add(static_line_1, (row, 0), (1, 3), wx.BOTTOM | wx.RIGHT | wx.TOP, 5)
# PARAMETERS ---------------------------------------------------------------------------------------------------
row += 2
lbl_settings = wx.StaticText(self.left_panel, wx.ID_ANY, "Parameters")
lbl_settings.SetFont(wx.Font(14, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, 0, ""))
grid_sizer_left_panel.Add(lbl_settings, (row, 0), (1, 3), wx.LEFT | wx.RIGHT, 5)
row += 1
static_line_2 = wx.StaticLine(self.left_panel, wx.ID_ANY)
static_line_2.SetMinSize((300, 2))
grid_sizer_left_panel.Add(static_line_2, (row, 0), (1, 3), wx.BOTTOM | wx.RIGHT | wx.TOP, 5)
row += 1
lbl_fc = wx.StaticText(self.left_panel, wx.ID_ANY, "Fc:")
grid_sizer_left_panel.Add(lbl_fc, (row, 0), (1, 1),
wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM | wx.LEFT | wx.RIGHT, 5)
grid_sizer_left_panel.Add(self.text_ctrl_fc, (row, 1), (1, 1), wx.BOTTOM, 5)
lbl_units_THz = wx.StaticText(self.left_panel, wx.ID_ANY, "(THz):")
grid_sizer_left_panel.Add(lbl_units_THz, (row, 2), (1, 1),
wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM | wx.LEFT | wx.RIGHT, 5)
row += 1
lbl_laser_bw = wx.StaticText(self.left_panel, wx.ID_ANY, "Laser BW:")
grid_sizer_left_panel.Add(lbl_laser_bw, (row, 0), (1, 1),
wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM | wx.LEFT | wx.RIGHT, 5)
grid_sizer_left_panel.Add(self.text_ctrl_laser_bw, (row, 1), (1, 1), wx.BOTTOM, 5)
lbl_units_laser_bw = wx.StaticText(self.left_panel, wx.ID_ANY, "(x Fc)")
grid_sizer_left_panel.Add(lbl_units_laser_bw, (row, 2), (1, 1),
wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM | wx.LEFT | wx.RIGHT, 5)
row += 1
lbl_emitted_modes = wx.StaticText(self.left_panel, wx.ID_ANY, "Emitted Modes:")
lbl_emitted_modes.SetToolTip("The number of emitted modes inside the cavity")
grid_sizer_left_panel.Add(lbl_emitted_modes, (row, 0), (1, 1),
wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM | wx.LEFT | wx.RIGHT, 5)
grid_sizer_left_panel.Add(self.text_ctrl_emitted_modes, (row, 1), (1, 1), wx.BOTTOM, 5)
row += 1
lbl_reflective_index = wx.StaticText(self.left_panel, wx.ID_ANY, "Reflective Index:")
grid_sizer_left_panel.Add(lbl_reflective_index, (row, 0), (1, 1),
wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM | wx.LEFT | wx.RIGHT, 5)
grid_sizer_left_panel.Add(self.text_ctrl_index, (row, 1), (1, 1), wx.BOTTOM, 5)
row += 1
label_bandwidth_shape = wx.StaticText(self.left_panel, wx.ID_ANY, "Gain Bandwidth Shape:")
grid_sizer_left_panel.Add(label_bandwidth_shape, (row, 0), (1, 1),
wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM | wx.LEFT | wx.RIGHT, 5)
grid_sizer_left_panel.Add(self.combo_bandwidth_shape, (row, 1), (1, 2), wx.BOTTOM, 5)
row += 1
grid_sizer_left_panel.Add(self.checkbox_random_phase, (row, 1), (1, 1), wx.LEFT | wx.TOP, 5)
# SAMPLING PARAMETERS ------------------------------------------------------------------------------------------
row += 1
lbl_results = wx.StaticText(self.left_panel, wx.ID_ANY, "SAMPLING")
lbl_results.SetFont(wx.Font(14, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, 0, ""))
grid_sizer_left_panel.Add(lbl_results, (row, 0), (1, 3), wx.LEFT | wx.RIGHT, 5)
row += 1
static_line_3 = wx.StaticLine(self.left_panel, wx.ID_ANY)
static_line_3.SetMinSize((300, 2))
grid_sizer_left_panel.Add(static_line_3, (row, 0), (1, 3), wx.BOTTOM | wx.RIGHT | wx.TOP, 5)
row += 1
label_window = wx.StaticText(self.left_panel, wx.ID_ANY, "Windowing Function:")
grid_sizer_left_panel.Add(label_window, (row, 0), (1, 1),
wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM | wx.LEFT | wx.RIGHT, 5)
grid_sizer_left_panel.Add(self.combo_window, (row, 1), (1, 2), wx.BOTTOM, 5)
row += 1
label_Hz = wx.StaticText(self.left_panel, wx.ID_ANY, "Mainlobe Width:")
grid_sizer_left_panel.Add(label_Hz, (row, 0), (1, 1),
wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM | wx.LEFT | wx.RIGHT, 5)
grid_sizer_left_panel.Add(self.text_ctrl_mainlobe, (row, 1), (1, 1), wx.BOTTOM, 5)
label_Hz = wx.StaticText(self.left_panel, wx.ID_ANY, "MLW (Hz)")
grid_sizer_left_panel.Add(label_Hz, (row, 2), (1, 1), wx.BOTTOM, 5)
# REPORT -------------------------------------------------------------------------------------------------------
row += 1
row += 1
lbl_results = wx.StaticText(self.left_panel, wx.ID_ANY, "REPORT")
lbl_results.SetFont(wx.Font(14, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, 0, ""))
grid_sizer_left_panel.Add(lbl_results, (row, 0), (1, 3), wx.LEFT | wx.RIGHT, 5)
row += 1
static_line_3 = wx.StaticLine(self.left_panel, wx.ID_ANY)
static_line_3.SetMinSize((300, 2))
grid_sizer_left_panel.Add(static_line_3, (row, 0), (1, 3), wx.BOTTOM | wx.RIGHT | wx.TOP, 5)
row += 1
lbl_runtime = wx.StaticText(self.left_panel, wx.ID_ANY, "Total Runtime:")
grid_sizer_left_panel.Add(lbl_runtime, (row, 0), (1, 1),
wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM | wx.LEFT | wx.RIGHT, 5)
grid_sizer_left_panel.Add(self.report_runtime, (row, 1), (1, 1), wx.BOTTOM, 5)
label_ps = wx.StaticText(self.left_panel, wx.ID_ANY, "(ps)")
grid_sizer_left_panel.Add(label_ps, (row, 2), (1, 1), wx.BOTTOM, 5)
row += 1
label_bandwidth_shape = wx.StaticText(self.left_panel, wx.ID_ANY, "Laser BW:")
grid_sizer_left_panel.Add(label_bandwidth_shape, (row, 0), (1, 1),
wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM | wx.LEFT | wx.RIGHT, 5)
grid_sizer_left_panel.Add(self.report_laser_bw, (row, 1), (1, 1), wx.BOTTOM, 5)
label_THz = wx.StaticText(self.left_panel, wx.ID_ANY, "(THz)")
grid_sizer_left_panel.Add(label_THz, (row, 2), (1, 1), wx.BOTTOM, 5)
row += 1
label_wavelength = wx.StaticText(self.left_panel, wx.ID_ANY, "Wavelength, λ:")
grid_sizer_left_panel.Add(label_wavelength, (row, 0), (1, 1),
wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM | wx.LEFT | wx.RIGHT, 5)
grid_sizer_left_panel.Add(self.report_wavelength, (row, 1), (1, 1), wx.BOTTOM, 5)
label_nm = wx.StaticText(self.left_panel, wx.ID_ANY, "(nm)")
grid_sizer_left_panel.Add(label_nm, (row, 2), (1, 1), wx.BOTTOM, 5)
row += 1
label_cavity_modes = wx.StaticText(self.left_panel, wx.ID_ANY, "Cavity Modes, m:")
grid_sizer_left_panel.Add(label_cavity_modes, (row, 0), (1, 1),
wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM | wx.LEFT | wx.RIGHT, 5)
grid_sizer_left_panel.Add(self.report_cavity_modes, (row, 1), (1, 2), wx.BOTTOM, 5)
row += 1
label_cavity_length = wx.StaticText(self.left_panel, wx.ID_ANY, "Cavity Length, L:")
grid_sizer_left_panel.Add(label_cavity_length, (row, 0), (1, 1),
wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM | wx.LEFT | wx.RIGHT, 5)
grid_sizer_left_panel.Add(self.report_cavity_length, (row, 1), (1, 1), wx.BOTTOM, 5)
label_nm = wx.StaticText(self.left_panel, wx.ID_ANY, "(mm)")
grid_sizer_left_panel.Add(label_nm, (row, 2), (1, 1), wx.BOTTOM, 5)
row += 1
label_df = wx.StaticText(self.left_panel, wx.ID_ANY, "Frequency Separation, df:")
grid_sizer_left_panel.Add(label_df, (row, 0), (1, 1),
wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM | wx.LEFT | wx.RIGHT, 5)
grid_sizer_left_panel.Add(self.report_df, (row, 1), (1, 1), wx.BOTTOM, 5)
label_GHz = wx.StaticText(self.left_panel, wx.ID_ANY, "(GHz)")
grid_sizer_left_panel.Add(label_GHz, (row, 2), (1, 1), wx.BOTTOM, 5)
row += 1
label_longitudinal_modes = wx.StaticText(self.left_panel, wx.ID_ANY, "Longitudinal Modes:")
grid_sizer_left_panel.Add(label_longitudinal_modes, (row, 0), (1, 1),
wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM | wx.LEFT | wx.RIGHT, 5)
grid_sizer_left_panel.Add(self.report_longitudinal_modes, (row, 1), (1, 2), wx.BOTTOM, 5)
row += 1
lbl_fwhm = wx.StaticText(self.left_panel, wx.ID_ANY, "FWHM:")
grid_sizer_left_panel.Add(lbl_fwhm, (row, 0), (1, 1),
wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM | wx.LEFT | wx.RIGHT, 5)
grid_sizer_left_panel.Add(self.report_fwhm, (row, 1), (1, 1), wx.BOTTOM, 5)
label_blank = wx.StaticText(self.left_panel, wx.ID_ANY, "")
grid_sizer_left_panel.Add(label_blank, (row, 2), (1, 1), wx.BOTTOM, 5)
row += 1
lbl_fwhm_width = wx.StaticText(self.left_panel, wx.ID_ANY, "FWHM Width:")
grid_sizer_left_panel.Add(lbl_fwhm_width, (row, 0), (1, 1),
wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM | wx.LEFT | wx.RIGHT, 5)
grid_sizer_left_panel.Add(self.report_fwhm_width, (row, 1), (1, 1), wx.BOTTOM, 5)
label_GHz = wx.StaticText(self.left_panel, wx.ID_ANY, "(GHz)")
grid_sizer_left_panel.Add(label_GHz, (row, 2), (1, 1), wx.BOTTOM, 5)
self.left_panel.SetSizer(grid_sizer_left_panel)
# PLOT PANEL ===================================================================================================
grid_sizer_plot.Add(self.canvas, (0, 0), (1, 1), wx.ALL | wx.EXPAND)
grid_sizer_plot.Add(self.toolbar, (1, 0), (1, 1), wx.ALL | wx.EXPAND)
grid_sizer_plot.AddGrowableRow(0)
grid_sizer_plot.AddGrowableCol(0)
self.plot_panel.SetSizer(grid_sizer_plot)
# add to main panel --------------------------------------------------------------------------------------------
grid_sizer_1.Add(self.left_panel, 0, wx.EXPAND | wx.RIGHT, 5)
grid_sizer_1.Add(self.plot_panel, 1, wx.EXPAND, 5)
grid_sizer_1.AddGrowableRow(0)
grid_sizer_1.AddGrowableCol(1)
sizer_2.Add(grid_sizer_1, 0, wx.EXPAND, 0)
self.SetSizer(sizer_2)
self.Layout()
def popup_dialog(self, message):
print(message)
dial = wx.MessageDialog(None, str(message), 'Error', wx.OK | wx.ICON_ERROR)
dial.ShowModal()
def get_values(self):
fc = to_float(self.text_ctrl_fc.GetValue())
laser_bw = to_float(self.text_ctrl_laser_bw.GetValue())
emitted_modes = to_integer(self.text_ctrl_emitted_modes.GetValue())
refraction_index = to_float(self.text_ctrl_index.GetValue())
bandwidth_shape = str(self.combo_bandwidth_shape.GetValue()).lower()
window = str(self.combo_window.GetValue()).lower()
MLW = to_float(self.text_ctrl_mainlobe.GetValue())
random_phase = bool(self.checkbox_random_phase.GetValue())
return fc, laser_bw, emitted_modes, refraction_index, bandwidth_shape, window, MLW, random_phase
def update(self, evt):
try:
params = self.get_values()
data, plot_data, plot_limits = worker.worker(params)
self.results_update(data)
self.plot(plot_data, plot_limits)
except ValueError as e:
self.popup_dialog(e)
# ------------------------------------------------------------------------------------------------------------------
def __do_plot_layout(self):
self.ax1.set_title('SAMPLED TIMED SERIES DATA')
self.ax1.set_xlabel('TIME (ps)')
self.ax1.set_ylabel('AMPLITUDE')
self.ax2.set_title('SUMMATION OF ALL MODES/TONES')
self.ax2.set_xlabel('TIME (ps)')
self.ax2.set_ylabel('AMPLITUDE')
self.ax3.set_title('SPECTRAL DATA')
self.ax3.set_xlabel('FREQUENCY (THz)')
self.ax3.set_ylabel('MAGNITUDE (V)')
self.ax3.grid()
self.figure.align_ylabels([self.ax1, self.ax2, self.ax3])
self.figure.tight_layout()
def plot(self, plot_data, plot_limits):
xt, yt_list, yt, yt_envelope, xf_rfft, yf_rfft, yf_smooth = plot_data
xt1_left, xt1_right, xt2_left, xt2_right, xf_left, xf_right, dim_left, dim_right, dim_height, dim_label, dim_label_pos = plot_limits
xt_scale = 1e12
xf_scale = 1e12
# TEMPORAL -----------------------------------------------------------------------------------------------------
xt_delta = xt[1] - xt[0]
yt_limit = int(xt1_right / xt_delta)
yt_limit2 = int(xt2_right / xt_delta)
self.ax1.clear()
self.ax1.plot(xt[:yt_limit] * xt_scale, (yt_list[:, :yt_limit]).T) # All signals
self.ax1.set_title('SAMPLED TIMED SERIES DATA')
self.ax1.set_xlabel('TIME (ps)')
self.ax1.set_ylabel('AMPLITUDE')
self.temporal_sum.set_data(xt[:yt_limit2] * xt_scale, yt[:yt_limit2]) # The summation of all signals
self.temporal_hilbert.set_data(xt[:yt_limit2] * xt_scale,
yt_envelope[:yt_limit2]) # The envelope of the summation
self.ax1.set_xlim(left=xt1_left * xt_scale, right=xt1_right * xt_scale)
self.ax2.set_xlim(left=xt2_left * xt_scale, right=xt2_right * xt_scale)
# SPECTRAL -----------------------------------------------------------------------------------------------------
self.spectral.set_data(xf_rfft / xf_scale, np.abs(yf_rfft)) # The spectral plot of sum
self.spectral_envelope.set_data(xf_rfft / xf_scale, yf_smooth) # The spectral plot of sum
self.ax3.set_xlim(left=xf_left / xf_scale, right=xf_right / xf_scale)
# Arrow dimension line update ----------------------------------------------------------------------------------
# https://stackoverflow.com/a/48684902 -------------------------------------------------------------------------
self.arrow_dim_obj.xy = (dim_left, dim_height)
self.arrow_dim_obj.set_position((dim_right, dim_height))
self.arrow_dim_obj.textcoords = self.ax3.transData
# dimension text update ----------------------------------------------------------------------------------------
self.dim_text.set_position((dim_left + dim_label_pos, dim_height))
self.dim_text.set_text(dim_label)
# REDRAW PLOT --------------------------------------------------------------------------------------------------
self.plot_redraw()
def plot_redraw(self):
try:
self.ax1.relim() # recompute the ax.dataLim
self.ax2.relim() # recompute the ax.dataLim
self.ax3.relim() # recompute the ax.dataLim
except MemoryError as e:
raise ValueError(str(e))
self.ax1.margins(x=0)
self.ax1.autoscale(axis='y')
self.ax2.autoscale(axis='y')
self.ax3.autoscale(axis='y')
# UPDATE PLOT FEATURES -----------------------------------------------------------------------------------------
self.figure.tight_layout()
self.toolbar.update() # Not sure why this is needed - ADS
self.canvas.draw()
self.canvas.flush_events()
def results_update(self, data):
wavelength, laser_bw, df_max, cavity_modes, cavity_length, cavity_df, longitudinal_modes, fwhm_val, fwhm_width, runtime = data
self.report_runtime.SetValue(str(round(runtime * 1e12, 3)))
self.report_laser_bw.SetValue(str(laser_bw / 1e12))
self.report_cavity_length.SetValue(str(laser_bw / 1e12))
self.report_wavelength.SetValue(str(round(wavelength * 1e9, 3)))
self.report_df.SetValue(str(round(df_max / 1e9, 3)))
self.report_cavity_modes.SetValue(str(cavity_modes))
self.report_cavity_length.SetValue(str(round(cavity_length * 1e3, 3)))
self.report_longitudinal_modes.SetValue(str(longitudinal_modes))
self.report_fwhm.SetValue(str(round(fwhm_val, 2)))
self.report_fwhm_width.SetValue(str(round(fwhm_width * 1e12, 3)))
print('total runtime:', round(runtime * 1e12, 3), 'ps')
print('laser bandwidth:', laser_bw / 1e12, 'THz')
print('full wave, half maximum:', laser_bw / 1e12, 'THz')
print('wavelength, lambda:', round(wavelength * 1e9, 3), 'nm')
print()
print('max frequency separation for number of emitted modes, df:', round(df_max / 1e9, 3), 'GHz')
print('cavity modes, m:', cavity_modes)
print('cavity length, L:', round(cavity_length * 1e2, 3), 'cm', round(cavity_length * 1e3, 3), '(mm)')
print('frequency separation of cavity, df:', round(cavity_df / 1e9, 3), 'GHz')
print('longitudinal modes supported:', longitudinal_modes)
print()
print('FWHM value:', round(fwhm_val, 2))
print('FWHM width:', round(fwhm_width * 1e12, 3), 'ps')
print()
# FOR RUNNING INDEPENDENTLY ============================================================================================
class MyDemoFrame(wx.Frame):
def __init__(self, *args, **kwds):
kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.SetSize((1200, 705))
self.panel = MyDemoPanel(self)
self.__set_properties()
self.__do_layout()
def __set_properties(self):
self.SetTitle("Laser Mode Locking")
def __do_layout(self):
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.panel, 1, wx.ALL | wx.EXPAND, 5)
self.SetSizer(sizer)
self.Layout()
class MyApp(wx.App):
def OnInit(self):
self.frame = MyDemoFrame(None, wx.ID_ANY, "")
self.SetTopWindow(self.frame)
self.frame.Show()
return True
if __name__ == "__main__":
app = MyApp(0)
app.MainLoop()