<jupyter_start><jupyter_text>Cyclic Voltammograms<jupyter_code>CV = load_experiment()
# CV
fig = plt.figure()
ax = fig.add_subplot()

# ax.set_title('Cyclic Voltammogram')
ax.tick_params(axis='both', which='both', direction='in', right=True, top=True)
# ax.set_prop_cycle(cc2)
ax.scatter(CV.data['Ecell'], CV.data['iw'], label = '$v=$ '+str(CV.params.loc[CV.params['parameter']=='scan_rate', 'value'].item()) + ' V/s')
ax.set_xlabel('$E_{cell}$ / V')
ax.set_ylabel('$i_{w}$ / $A$')

ax.ticklabel_format(style='sci', axis='y', scilimits=(0,0))
plt.style.use('JGW')
fig.legend()<jupyter_output><empty_output><jupyter_text>Find CV Peaks<jupyter_code># Smooth data using the Savitski Golay method
smooth_iw = savgol_filter(CV.data['iw'], 25, 2)
# Check the result
# plt.plot(CV.data['Ecell'], smooth_iw, zorder=1, color='r')
# plt.plot(CV.data['Ecell'], CV.data['iw'], label = '$v=$ '+str(CV.params.loc[CV.params['parameter']=='scan_rate', 'value'].item()) + ' V/s', zorder=0)
# plt.xlim(-.75, -.74)
# plt.ylim(.00003, .00004)

# Maxima
find_ipa = find_peaks(smooth_iw, height=0, width=3600) # Must give minimum height to get peak_heights dict.
ipa, Epa = CV.data['iw'][find_ipa[0]].to_numpy(), CV.data['Ecell'][find_ipa[0]].to_numpy()

# Invert signal to find minima - Signals are negative but indicies are correct!
find_ipc = find_peaks(-smooth_iw, height=0, width=3600) # Remember to un-invert anytime if calling ipc values from find_ipc, but not indicies.
ipc, Epc = CV.data['iw'][find_ipc[0]].to_numpy(), CV.data['Ecell'][find_ipc[0]].to_numpy()

peaks = {'ipa': ipa[0], 'Epa': Epa[0], 'ipc': ipc[0], 'Epc': Epc[0]}
# df = pd.DataFrame(data=peaks, index=[CV.params.loc[CV.params['parameter']=='scan_rate', 'value'].item()]) # Gives a little table, but rounds values...
print(peaks)<jupyter_output><empty_output><jupyter_text>Peak picking and figure saving<jupyter_code>def save_CV_fig(fig, analyte, electrode, solvent, notebook):
    ans = input('Save the figure?')
    if ans in ['y', 'yes', 'Yes', 'yeye', 'yeah', 'why, certainly', True]:
        fig.savefig("C:\\Users\\jgage\\Documents\GitHub\\CHEM274\\data\\figs\\CV_"+
            analyte + electrode + solvent +
            str(CV.params.loc[CV.params['parameter']=='scan_rate', 'value'].item()) + 'Vs-1_'+
                notebook+'.jpg')
        print('Saved')
    else:
        print('Not saved')
# Draw same plot as above, but with peaks
fig = plt.figure()
ax = fig.add_subplot()

ax.tick_params(axis='both', which='both', direction='in', right=True, top=True)
ax.plot(CV.data['Ecell'], CV.data['iw'], label = '$v=$ '+str(CV.params.loc[CV.params['parameter']=='scan_rate', 'value'].item()) + ' V/s', zorder=0)
ax.plot(CV.data['Ecell'], smooth_iw, color='C2', label='Savitsky-Golay', lw=.5, zorder=.5)
ax.scatter([*Epa, *Epc], [*ipa, *ipc], color='C1', label='Peaks', marker='|', s=200, zorder=1)
fig.tight_layout()

# ax.set_title('Cyclic Voltammogram')
ax.set_xlabel('$E_{cell}$ / V')
ax.set_ylabel('$i_{w}$ / $A$')
ax.ticklabel_format(style='sci', axis='y', scilimits=(0,0))
fig.legend(loc=(0.75, 0.78))

analyte = 'FcStar_'
electrode = 'GC_'
solvent = 'MeAc'
notebook = '_P-09-03'

plt.show()
save_CV_fig(fig, analyte, electrode, solvent, notebook)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.2167745914276904, 'fraction_numerical': 0.020043169904409498, 'mean_word_length': 5.674897119341564, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '159127', 'license': 'MIT', 'n_tokens_mistral': 1347, 'n_tokens_neox': 1290, 'n_words': 237, 'path': '.ipynb_checkpoints/CV_Offset-checkpoint.ipynb', 'repo_name': 'JGageWright/CHEM274', 'size': '3243'}