<jupyter_start><jupyter_text>ANC Example Code<jupyter_code>!pip install aguaclara
from aguaclara.core.units import unit_registry as u
import aguaclara as ac
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
import pandas as pd
from scipy import special
from scipy.optimize import curve_fit
import collections<jupyter_output><empty_output><jupyter_text>Equation for the First Gran Function$${F_1}  =  \frac{{{V_S} + {V_T}}}{{{V_S}}}{\text{[}}{{\text{H}}^ + }{\text{]}}$$The ANC can be calculated from the equivalent volume from$$ANC=\frac{V_e N_t }{V_s }$$<jupyter_code># read the Gran data from the tab delimitted file created by ProCoDA
Gran_data = 'https://raw.githubusercontent.com/monroews/CEE4530/master/Examples/data/Gran.xls'
V_titrant, pH, V_sample, Normality_Titrant, V_equivalent, ANC = ac.Gran(Gran_data)
#Define the gran function.
def F1(V_sample,V_titrant,pH):
  return (V_sample + V_titrant)/V_sample * ac.invpH(pH)
#Create an array of the F1 values.
F1_data = F1(V_sample,V_titrant,pH)
#By inspection I guess that there are 4 good data points in the linear region.
N_good_points = 3
#use scipy linear regression. Note that the we can extract the last n points from an array using the notation [-N:]
slope, intercept, r_value, p_value, std_err = stats.linregress(V_titrant[-N_good_points:],F1_data[-N_good_points:])
#reattach the correct units to the slope and intercept.
intercept = intercept*u.mole/u.L
slope = slope*(u.mole/u.L)/u.mL
V_eq = -intercept/slope
ANC_sample = V_eq*Normality_Titrant/V_sample
print('The r value for this curve fit is', ac.round_sig_figs(r_value,5))
print('The equivalent volume was', ac.round_sig_figs(V_eq,2))
print('The acid neutralizing capacity was',ac.round_sig_figs(ANC_sample.to(u.meq/u.L),2))

#The equivalent volume agrees well with the value calculated by ProCoDA.
#create an array of points to draw the linear regression line
x=[V_eq.magnitude,V_titrant[-1].magnitude ]
y=[0,(V_titrant[-1]*slope+intercept).magnitude]
#Now plot the data and the linear regression
plt.plot(V_titrant, F1_data,'o')
plt.plot(x, y,'r')
plt.xlabel('Titrant Volume (mL)')
plt.ylabel('Gran function (mole/L)')
plt.legend(['data'])
plt.show()<jupyter_output>The r value for this curve fit is 0.99999
The equivalent volume was 0.21 milliliter
The acid neutralizing capacity was 0.43 milliequivalent / liter
{'fraction_non_alphanumeric': 0.11483050847457626, 'fraction_numerical': 0.013135593220338982, 'mean_word_length': 6.04776119402985, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 1, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '597620', 'license': 'MIT', 'n_tokens_mistral': 893, 'n_tokens_neox': 836, 'n_words': 247, 'path': 'Examples/ANC.ipynb', 'repo_name': 'hf245/CEE4530', 'size': '2360'}