def update_step() -> None: global mc_step, field, free_energy, figure field, free_energy = update_metropolis(field, states, free_energy, INTERACTION, interaction_coefficient=J, magnetization_coefficient=h, random_state=rg, temperature=TEMPERATURE) mc_step += 1 if mc_step % PLOT_EVERY_X_STEPS == 0: figure = plot_field(field, states) draw_figure(canvas, figure) update_energy_label(label, mc_step, free_energy)
def show_harmonics_graph(): global fig_canvas_agg global toolbar enable_harmonics() if fig_canvas_agg: destroy_figure(fig_canvas_agg, toolbar) fig = plt.figure() window.find_element('Define baseline').Update(disabled=False) if window['r1'].get(): plt.plot(volt_range, harm_one, color='b') if window['r2'].get(): plt.plot(volt_range, harm_two, color='#40BAD3') if window['r3'].get(): plt.plot(volt_range, harm_three, color='orange') if window['r4'].get(): plt.plot(volt_range, harm_four, color='g') if window['r5'].get(): plt.plot(volt_range, harm_five, color='y') fig.suptitle('Harmonics', fontsize=16) fig.set_size_inches(6, 4) #original 9,6 fig.set_dpi(100) plt.xlabel('voltage(V)') plt.ylabel('Current (S.U)') fig_canvas_agg, toolbar = draw_figure(window['-CANVAS-'].TKCanvas, fig)
def show_envelope_graph(): global fig_canvas_agg global toolbar global harm_one global harm_two global harm_three global harm_four global harm_five enable_harmonics() if fig_canvas_agg: destroy_figure(fig_canvas_agg, toolbar) fig = plt.figure() fig.clf() print(plt.xlim()) if window['r1'].get(): envelope = pk.envelope(harm_one, deg=5, max_it=None, tol=1e-3) plt.plot(volt_range, envelope, color='b') if window['r2'].get(): envelope = pk.envelope(harm_two, deg=5, max_it=None, tol=1e-3) plt.plot(volt_range, envelope, color='#40BAD3') if window['r3'].get(): envelope = pk.envelope(harm_three, deg=5, max_it=None, tol=1e-3) plt.plot(volt_range, envelope, color='orange') if window['r4'].get(): envelope = pk.envelope(harm_four, deg=5, max_it=100, tol=1e-3) plt.plot(volt_range, envelope, color='g') if window['r5'].get(): envelope = pk.envelope(harm_five, deg=5, max_it=100, tol=1e-3) plt.plot(volt_range, envelope, color='y') fig.suptitle('Envelope', fontsize=16) fig.set_size_inches(6, 4) #orig 9,6 fig.set_dpi(100) plt.xlabel('voltage(V)') plt.ylabel('Current (S.U)') fig_canvas_agg, toolbar = draw_figure(window['-CANVAS-'].TKCanvas, fig)
def calculate_results(): global fig_canvas_agg global toolbar global height global area enable_harmonics() area = 0 height = 0 fig = plt.figure() if window['r1'].get(): plt.plot(volt_range, harm_one, color='b') if maths.is_y_valid(volt_range, harm_one, xdata, ydata): copy_x_data = np.copy(xdata) copy_y_data = np.copy(ydata) curve_1, curve_2, peak_height, index_of_peak, diff_curves, area_between_curves = maths.map_baseline( volt_range, harm_one, copy_x_data, copy_y_data) plt.plot(volt_range, curve_2, color='b') plt.plot([volt_range, [index_of_peak], t[index_of_peak]], [curve_2[index_of_peak], curve_1[index_of_peak]], color='r') plt.fill_between(volt_range, curve_1, curve_2, alpha=0.3) print("Harm One") if window['r2'].get(): plt.plot(volt_range, harm_two, color='#40BAD3') if maths.is_y_valid(volt_range, harm_two, xdata, ydata): copy_x_data = np.copy(xdata) copy_y_data = np.copy(ydata) curve_1, curve_2, peak_height, index_of_peak, diff_curves, area_between_curves = maths.map_baseline( volt_range, harm_two, copy_x_data, copy_y_data) plt.plot(volt_range, curve_2, color='#40BAD3') plt.plot( [volt_range, [index_of_peak], volt_range, [index_of_peak]], [curve_2[index_of_peak], curve_1[index_of_peak]], color='r', label='Height: ' + str(peak_height)) plt.fill_between(volt_range, curve_1, curve_2, alpha=0.3, label='Area: ' + str(area_between_curves)) plt.legend(loc="upper left") area = area_between_curves height = peak_height print("Harm Two") if window['r3'].get(): plt.plot(volt_range, harm_three, color='orange') if maths.is_y_valid(volt_range, harm_three, xdata, ydata): copy_x_data = np.copy(xdata) copy_y_data = np.copy(ydata) curve_1, curve_2, peak_height, index_of_peak, diff_curves, area_between_curves = maths.map_baseline( volt_range, harm_three, copy_x_data, copy_y_data) plt.plot(volt_range, curve_2, color='orange') plt.plot( [volt_range, [index_of_peak], volt_range, [index_of_peak]], [curve_2[index_of_peak], curve_1[index_of_peak]], color='r') plt.fill_between(volt_range, curve_1, curve_2, alpha=0.3) if window['r4'].get(): plt.plot(volt_range, harm_four, color='g') if maths.is_y_valid(volt_range, harm_four, xdata, ydata): copy_x_data = np.copy(xdata) copy_y_data = np.copy(ydata) curve_1, curve_2, peak_height, index_of_peak, diff_curves, area_between_curves = maths.map_baseline( volt_range, harm_four, copy_x_data, copy_y_data) plt.plot(volt_range, curve_2, color='g') plt.plot( [volt_range, [index_of_peak], volt_range, [index_of_peak]], [curve_2[index_of_peak], curve_1[index_of_peak]], color='r') plt.fill_between(volt_range, curve_1, curve_2, alpha=0.3) if window['r5'].get(): plt.plot(volt_range, harm_five, color='y') if maths.is_y_valid(volt_range, harm_five, xdata, ydata): copy_x_data = np.copy(xdata) copy_y_data = np.copy(ydata) curve_1, curve_2, peak_height, index_of_peak, diff_curves, area_between_curves = maths.map_baseline( volt_range, harm_five, copy_x_data, copy_y_data) plt.plot(volt_range, curve_2, color='y') plt.plot( [volt_range, [index_of_peak], volt_range, [index_of_peak]], [curve_2[index_of_peak], curve_1[index_of_peak]], color='r') plt.fill_between(volt_range, curve_1, curve_2, alpha=0.3) fig.suptitle('Harmonics', fontsize=16) fig.set_size_inches(6, 4) #orig 9,6 fig.set_dpi(100) destroy_figure(fig_canvas_agg, toolbar) fig_canvas_agg, toolbar = draw_figure(window['-CANVAS-'].TKCanvas, fig) window.find_element('Envelope').Update(disabled=False) # handle results ret = '' ppm = maths.conc(float(parameters['a']), float(parameters['b']), float(parameters['c']), area) if ppm == -2: window.find_element('PPM').Update(text_color=RED) ret = 'Signal beyond calibration range defined by constants' elif ppm == -1: window.find_element('PPM').Update(text_color=RED) ret = 'Concentration too high, out of range of calibration' else: window.find_element('PPM').Update(text_color=GREEN) ret = str(ppm) + 'ppm free SO2' window.find_element('PPM').Update(ret) window.find_element('Define baseline').Update(disabled=False)
if fig_canvas_agg: destroy_figure(fig_canvas_agg, toolbar) window.find_element('Define baseline').Update(disabled=True) fig = plt.figure() fig.clf() plt.plot(volt_rangei) fig.suptitle('Raw Signal', fontsize=16) fig.set_size_inches(6, 4) #orig 9,6 fig.set_dpi(100) plt.xlabel('voltage(V)') plt.ylabel('Current (S.U)') fig_canvas_agg, toolbar = draw_figure(window['-CANVAS-'].TKCanvas, fig) # fig = matplotlib.figure.Figure(figsize=(9, 6), dpi=100) # fig.suptitle('Time Domain', fontsize=16) # fig.add_subplot( # 111, # xlabel='Time (s)', # ylabel='Current (S.U)').plot( # volt_range, # i, # c='#40BAD2') # fig_canvas_agg, toolbar = draw_figure(window['-CANVAS-'].TKCanvas, fig) elif event == 'Freq Domain': disable_harmonics()