diff --git a/hp4194/cv.py b/hp4194/cv.py index 908ef808b42de6bfba5664c59a1ef1e4d70cbe61..614a580f63879f895255fd77d89fab63001445e2 100644 --- a/hp4194/cv.py +++ b/hp4194/cv.py @@ -18,7 +18,7 @@ device.write('meas_imp') sample,sample_dict = probendaten() messparameter,messparameter_dict = messparameter() sweep_parameter,sweep_parameter_dict = sweep_parameter() -control_panel,measure,clear_graphs,view=control_panel() +control_panel,measure,view=control_panel() #set up interface out = widgets.Output() @@ -30,7 +30,7 @@ display(hbox2,out) #add widgets to a list for disabling them -all_widgets = [measure,clear_graphs] +all_widgets = [measure] add_widgets_to_list(sample_dict,all_widgets) add_widgets_to_list(sweep_parameter_dict,all_widgets) add_widgets_to_list(messparameter_dict,all_widgets) @@ -111,9 +111,65 @@ def on_measure_clicked(b): area = np.pi * radius**2 # in um2 area = area * 10**(-8) # in cm2 biases= np.round(np.linspace(messparameter_dict["start"].value,messparameter_dict["stop"].value,num_of_points,endpoint = True),3) + + # frequency index + f_index = messparameter_dict['f_point'].value-1 + + + + # create the figure + fig = plt.figure(layout = "constrained") + spec = fig.add_gridspec(ncols=3, nrows=2) + + ax1 = fig.add_subplot(spec[0,0]) + ax1_twin = ax1.twinx() + ax1.set_title("Cp/D(f) live") + ax1.set_xlabel("Frequency (Hz)") + ax1.set_ylabel("Cp (F)") + ax1_twin.set_ylabel("D") + + ax2 = fig.add_subplot(spec[0,1]) + ax2_twin = ax2.twinx() + ax2.set_title("Z/Phi(f) live") + ax2.set_xlabel("Frequency (Hz)") + ax2.set_ylabel("Z (Ohm)") + ax2_twin.set_ylabel("Phi (°)") + + ax3 = fig.add_subplot(spec[0,2]) + ax3.set_title("ImZ(ReZ(f)) live") + ax3.set_xlabel("Re Z (Ohm)") + ax3.set_ylabel("Im Z (Ohm)") + + ax4 = fig.add_subplot(spec[1,0]) + ax4_twin = ax4.twinx() + ax4.set_title("Cp/D(U)") + ax4.set_xlabel("Voltage U (V)") + ax4.set_ylabel("Cp (F)") + ax4_twin.set_ylabel("D") + + ax5 = fig.add_subplot(spec[1,1]) + ax5_twin = ax5.twinx() + ax5.set_title("Z/Phi(U)") + ax5.set_xlabel("Voltage U (V)") + ax5.set_ylabel("Z (Ohm)") + ax5_twin.set_ylabel("Phi (°)") + + ax6 = fig.add_subplot(spec[1,2]) + ax6_twin = ax6.twinx() + ax6.set_title("Cp/D(f)") + ax6.set_xlabel("Frequency (Hz)") + ax6.set_ylabel("Cp (F)") + ax6_twin.set_ylabel("D") + + mng = plt.get_current_fig_manager() + mng.window.state('zoomed') for bias in biases: view["v-value"].value = str(bias) + + # voltage index + v_index = messparameter_dict['v_point'].value-1 + U_values.extend([bias]*sweep_parameter_dict['nop'].value) area_values.extend([area]*sweep_parameter_dict['nop'].value) device.set_parameter('set_bias', bias) #set the bias @@ -172,12 +228,70 @@ def on_measure_clicked(b): G_area_omega= G/area/omega G_area_omega_values.extend(G_area_omega) + + # do the plots + # first the live ones + + #clear the live axes + ax1.clear() + ax1_twin.clear() + ax2.clear() + ax2_twin.clear() + ax3.clear() + + # frequency Cp/D plot + ax1.plot(freq,Cp,color = 'b') + ax1.tick_params(axis = 'y',labelcolor = 'b') + + ax1_twin.plot(freq,D, color = 'y') + ax1_twin.tick_params(axis='y',labelcolor = 'y') + + # frequecy Z-phi + ax2.plot(freq,Z,color = 'b') + ax2.tick_params(axis = 'y',labelcolor = 'b') + + ax2_twin.plot(freq,phi, color = 'y') + ax2_twin.tick_params(axis='y',labelcolor = 'y') + + # Rez - Imz + ax3.plot(ReZ,ImZ,color = 'b') + ax3.tick_params(axis = 'y',labelcolor = 'b') + # now the rest of the plots + # Voltage vs Cp D for the user specified frequency + # This is updated for every iteration + ax4.scatter(bias, Cp[f_index],color ='b') + ax4.tick_params(axis = 'y',labelcolor = 'b') + + ax4_twin.scatter(bias, D[f_index],color ='y') + ax4_twin.tick_params(axis = 'y',labelcolor = 'y') + # Voltage, Z-phi + # This is also updated every iteration + ax5.scatter(bias, Z[f_index],color ='b') + ax4.tick_params(axis = 'y',labelcolor = 'b') + + ax5_twin.scatter(bias, phi[f_index],color ='y') + ax5_twin.tick_params(axis = 'y',labelcolor = 'y') + + # Final Plot + # This if for all the frequencies for the calculated voltage + + if biases[v_index]== bias: + ax6.scatter(freq,Cp,color = 'b') + ax6.tick_params(axis = 'y',labelcolor = 'b') + + ax6_twin.scatter(freq,D, color = 'y') + ax6_twin.tick_params(axis='y',labelcolor = 'y') + + fig.draw() if messparameter_dict["hysterisis"].value == True: reversed_biases = reversed_array(biases) for bias in reversed_biases: - view["v-value"].value = str(bias) + view["v-value"].value = str(bias) + + # voltage index + v_index = -messparameter_dict['v_point'].value # in reverse U_values.extend([bias]*sweep_parameter_dict['nop'].value) area_values.extend([area]*sweep_parameter_dict['nop'].value) device.set_parameter('set_bias', bias) #set the bias @@ -236,8 +350,65 @@ def on_measure_clicked(b): G_area_omega= G/area/omega G_area_omega_values.extend(G_area_omega) - - + + # do the plots + # first the live ones + + #clear the live axes + ax1.clear() + ax1_twin.clear() + ax2.clear() + ax2_twin.clear() + ax3.clear() + + # frequency Cp/D plot + ax1.plot(freq,Cp,color = 'b') + ax1.tick_params(axis = 'y',labelcolor = 'b') + + ax1_twin.plot(freq,D, color = 'y') + ax1_twin.tick_params(axis='y',labelcolor = 'y') + + # frequecy Z-phi + ax2.plot(freq,Z,color = 'b') + ax2.tick_params(axis = 'y',labelcolor = 'b') + + ax2_twin.plot(freq,phi, color = 'y') + ax2_twin.tick_params(axis='y',labelcolor = 'y') + + # Rez - Imz + ax3.plot(ReZ,ImZ,color = 'b') + ax3.tick_params(axis = 'y',labelcolor = 'b') + + # now the rest of the plots + # Voltage vs Cp D for the user specified frequency + # This is updated for every iteration + ax4.scatter(bias, Cp[f_index],color ='b') + ax4.tick_params(axis = 'y',labelcolor = 'b') + + ax4_twin.scatter(bias, D[f_index],color ='y') + ax4_twin.tick_params(axis = 'y',labelcolor = 'y') + + # Voltage, Z-phi + # This is also updated every iteration + ax5.scatter(bias, Z[f_index],color ='b') + ax4.tick_params(axis = 'y',labelcolor = 'b') + + ax5_twin.scatter(bias, phi[f_index],color ='y') + ax5_twin.tick_params(axis = 'y',labelcolor = 'y') + + # Final Plot + # This if for all the frequencies for the calculated voltage + + if biases[v_index]== bias: + ax6.scatter(freq,Cp,color = 'g') + ax6.tick_params(axis = 'y',labelcolor = 'g') + + ax6_twin.scatter(freq,D, color = 'r') + ax6_twin.tick_params(axis='y',labelcolor = 'r') + + fig.draw() + + fig.show() device.write('bias_off') # save to file @@ -249,7 +420,7 @@ def on_measure_clicked(b): f.write(f"# f_start {sweep_parameter_dict['stop'].value} Hz f_stop {sweep_parameter_dict['stop'].value} Hz no_steps {sweep_parameter_dict['nop'].value} SweepType {sweep_parameter_dict['type'].value}"+"\n") f.write(f"# OSC {sweep_parameter_dict['osc'].value} V"+"\n") f.write(f"# integration time {sweep_parameter_dict['integration'].value} averaging {sweep_parameter_dict['averaging'].value}"+"\n") - f.write(f"area {area} cm^2"+"\n") + f.write(f"# area {area} cm^2"+"\n") f.write("\n") # create the dataframe diff --git a/hp4194/examples/figure.ipynb b/hp4194/examples/figure.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..510fb9f3bb2c7897425e8fc24b5aeecddd311f6a --- /dev/null +++ b/hp4194/examples/figure.ipynb @@ -0,0 +1,102 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 15, + "id": "52e7274d-b638-4da1-acca-94cfc0c86c5a", + "metadata": {}, + "outputs": [], + "source": [ + "%matplotlib tk" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "0a1db92b-e4d3-49f4-a95f-40d58e575404", + "metadata": {}, + "outputs": [], + "source": [ + "import matplotlib.pyplot as plt\n", + "\n", + "# create the figure\n", + "fig = plt.figure(layout = \"constrained\")\n", + "spec = fig.add_gridspec(ncols=3, nrows=2)\n", + "\n", + "ax1 = fig.add_subplot(spec[0,0])\n", + "ax1_twin = ax1.twinx()\n", + "ax1.set_title(\"Cp/D(f) live\")\n", + "ax1.set_xlabel(\"Frequency (Hz)\")\n", + "ax1.set_ylabel(\"Cp (F)\")\n", + "ax1_twin.set_ylabel(\"D\")\n", + "\n", + "ax2 = fig.add_subplot(spec[0,1])\n", + "ax2_twin = ax2.twinx()\n", + "ax2.set_title(\"Z/Phi(f) live\")\n", + "ax2.set_xlabel(\"Frequency (Hz)\")\n", + "ax2.set_ylabel(\"Z (Ohm)\")\n", + "ax2_twin.set_ylabel(\"Phi (°)\")\n", + "\n", + "ax3 = fig.add_subplot(spec[0,2])\n", + "ax3.set_title(\"ImZ(ReZ(f)) live\")\n", + "ax3.set_xlabel(\"Re Z (Ohm)\")\n", + "ax3.set_ylabel(\"Im Z (Ohm)\")\n", + "\n", + "ax4 = fig.add_subplot(spec[1,0])\n", + "ax4_twin = ax4.twinx()\n", + "ax4.set_title(\"Cp/D(U)\")\n", + "ax4.set_xlabel(\"Voltage U (V)\")\n", + "ax4.set_ylabel(\"Cp (F)\")\n", + "ax4_twin.set_ylabel(\"D\")\n", + "\n", + "ax5 = fig.add_subplot(spec[1,1])\n", + "ax5_twin = ax5.twinx()\n", + "ax5.set_title(\"Z/Phi(U)\")\n", + "ax5.set_xlabel(\"Voltage U (V)\")\n", + "ax5.set_ylabel(\"Z (Ohm)\")\n", + "ax5_twin.set_ylabel(\"Phi (°)\")\n", + "\n", + "ax6 = fig.add_subplot(spec[1,2])\n", + "ax6_twin = ax6.twinx()\n", + "ax6.set_title(\"Cp/D(f)\")\n", + "ax6.set_xlabel(\"Frequency (Hz)\")\n", + "ax6.set_ylabel(\"Cp (F)\")\n", + "ax6_twin.set_ylabel(\"D\")\n", + "\n", + "mng = plt.get_current_fig_manager()\n", + "mng.window.state('zoomed')\n", + "\n", + "fig.show()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ff74d7a2-3426-433a-8152-43083bda500a", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.0" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/hp4194/help.py b/hp4194/help.py index d4026c51b530fa7c478b0490ac21052d3eefb522..e4c513f06d3e6658fc0941e2f831e1e2374ea839 100644 --- a/hp4194/help.py +++ b/hp4194/help.py @@ -72,11 +72,9 @@ def check_values(voltage:dict,freq:dict): # calculate the number of points for voltage voltage_points = abs(voltage["stop"].value-voltage["start"].value)/abs(voltage["step"].value) + 1 - if voltage["v_point"].value > voltage_points and voltage["hysterisis"].value == False: + if voltage["v_point"].value > voltage_points: return False - elif voltage["v_point"].value > 2*voltage_points and voltage["hysterisis"].value == True: - return False - + # prove that we check a valld frequency point if voltage["f_point"].value > freq['nop'].value: return False diff --git a/hp4194/interface.py b/hp4194/interface.py index d4e0a7a2e966e680bbd82e5c04cd9d78a61d3fef..4f2fb49f4b270e2e10ff5790206828b2cac314f2 100644 --- a/hp4194/interface.py +++ b/hp4194/interface.py @@ -141,7 +141,6 @@ def control_panel(): control_panel[4,1] = widgets.Checkbox(description = 'Clear Graphs',value = True,indent = False,layout=Layout(height='auto', width = width)) measure = control_panel[0,:] - clear_graphs = control_panel[4,1] view = { 'v-point': control_panel[2,0], @@ -149,7 +148,7 @@ def control_panel(): 'v-value':control_panel[4,0] } - return control_panel,measure,clear_graphs,view + return control_panel,measure,view