<jupyter_start><jupyter_text>PV  Basic starting measurements<jupyter_code>meter_readings = np.array([
    [22.7,23.9,24.2,23.1],
    [22.2,26.2,32.9,26.2]
])
umeter_readings = np.array([
    [ufloat(i, i*.03) for i in j]
    for j in meter_readings
])
umeter_readings
[print_unc(i) for i in j for ]
true_power = meter_readings/12.5
true_power # mW
utrue_power = umeter_readings/12.5
utrue_power
uncertainty = true_power.reshape(-1).std()*1e-3
avg_power
uncertainty
uncertainty/avg_power
round(uncertainty*1e4)
str(uncertainty).split('.')
te = uncertainty
dig = 0
while te < 1:
    te *= 10
    dig += 1
print(np.round(uncertainty, dig))
def get_leading_figure(unc):
    sci = str(unc).split('e')
    if len(sci) > 1:
        dig = -int(sci[-1])
    else:
        sp = str(unc).split('.')
        if len(sp) > 1:
            if int(sp[0]) > 0:
                decimal = False
            else:
                decimal = True            
        else:
            decimal = True

        if decimal:
            te = unc
            dig = 0
            while te < 1:
                print(te)
                te *= 10
                dig += 1

        else:
            te = unc
            dig = 0
            while te > 10:
                te /= 10
                dig -= 1
    return dig
def print_unc(val, unc = []):
    if isinstance(unc, list):
        val, unc = val.n, val.s
    dig = get_leading_figure(unc)

    print("{:.{}f} +- {:.{}f}".format(val, dig, unc, dig))
    return np.round(val, dig), np.round(unc, dig), dig
from uncertainties import ufloat
uavg_power = ufloat(avg_power, uncertainty)
print_unc(uavg_power)
avg_power = true_power.mean().mean()*1e-3
avg_power # W
meter_area = (9.5e-3/2)**2*np.pi
meter_area # m^2
from uncertainties.umath import 
pvc_dimensions = [0.0985, 0.0785]  # in meters
pvc_area = pvc_dimensions[0]*pvc_dimensions[1]
upvc_dimensions = [ufloat(i, 5e-4) for i in pvc_dimensions]
upvc_area = upvc_dimensions[0]*upvc_dimensions[1]
upvc_area, pvc_area

# single_cell_dimension = []  # in meters
# n_cells = 8
# pvc_area = single_cell_dimension[0] * single_cell_dimension[1] * n_cells
print_unc(upvc_area)<jupyter_output>0.00773225 6.297717840614964e-05
0.00773 +- 0.00006<jupyter_text>Prelim calculations<jupyter_code>avg_intensity = uavg_power/meter_area
avg_intensity
total_avg_light_power = avg_intensity * pvc_area
total_avg_light_power # Watts
print_unc(total_avg_light_power)<jupyter_output>0.21969909174663516 0.02821680386621582
0.02821680386621582
0.2821680386621582
0.22 +- 0.03<jupyter_text>Main test measurements<jupyter_code>pv = pd.DataFrame({
    'R': [
        0.1, 3, 10, 30, 70, 100, 150, 300,
        500, 800, 1e3, 5e3, 10e3, 5e4, 8e4, 1e5,
        5e5, 1e6
    ],
    'C': [
        23.77, 23.7, 23.67, 23.52, 21.3, 17.2,
        12.29, 6.49, 3.98, 2.54, 2.05, 0.3886,
        .1971, .03088, .02454, .01957, .00403,
        .00206
    ],
    'V': [
        .02918, .1014, .2645, .7361, 1.529, 1.7444,
        1.8527, 1.9285, 1.9528, 1.9651, 1.97, 1.9816,
        1.9829, 1.9838, 1.9843, 1.9834, 1.9832, 1.985
    ]
})
def make_unc_4(val):
    return get_leading_figure(val) + 4
pv[['uC','uV']] = pv[['C','V']].apply(lambda x: [ufloat(i, 10**-make_unc_4(i)) for i in x.values] )<jupyter_output>0.3886
0.1971
0.03088
0.3088
0.02454
0.2454
0.01957
0.1957
0.00403
0.040299999999999996
0.40299999999999997
0.00206
0.0206
0.20600000000000002
0.02918
0.2918
0.1014
0.2645
0.7361<jupyter_text>Analysis<jupyter_code>plt.figure(figsize = (9, 5.5))
plt.plot(pv.V, pv.C)
plt.xlabel('V')
plt.ylabel('I (mA)')
plt.title('I(V) with varying Resistance')
plt.savefig("../Images/l1_a_1.png")
plt.show()
plt.figure(figsize = (9, 5.5))
plt.plot(pv.R, pv.V*pv.C)
plt.xscale('log')
plt.xlabel('log R')
plt.ylabel('P (mW)')
plt.title('Output PVC Power with varying Resistance')
plt.savefig("../Images/l1_a_2.png")
plt.show()<jupyter_output><empty_output><jupyter_text>Results<jupyter_code>P = pv.V*pv.C # power in mW
uP = pv.uV*pv.uC # power in mW
# quick aside to interpolate the peak just for fun
from scipy.interpolate import interp1d
lmax = np.where(P==P.max())[0][0]
inds = [lmax - 1, lmax, lmax + 1, lmax + 2]
plt.figure(figsize = (9, 5.5))
plt.plot(pv.R, pv.V*pv.C, label='Measured')
inp = np.log10(pv.R[inds])
interp = interp1d(np.log10(pv.R), P, 'cubic')
x = np.linspace(inp.min(), inp.max(), 1000)
y = interp(x)
plt.plot(10**x, y, label = 'Spline')
plt.legend()
plt.xscale('log')
plt.xlabel('log R')
plt.ylabel('P (mW)')
plt.ylim([0, 40])
plt.title('Output PVC Power with varying Resistance')
plt.savefig("../Images/l1_b_1.png")
plt.show()
max_p_e = (uP).max()*1e-3
max_p_e/total_avg_light_power
# n_pv = P_E/P_L
f"{print_unc(max_p_e/total_avg_light_power * 100)[:2]} % Efficiency"<jupyter_output>15 +- 2<jupyter_text>Part C   starting values<jupyter_code>vol = 5 #cm^3
HHV = 1.42e8 
LHV = 1.20e8 # J/kg
M_H2 = 2.01e-3<jupyter_output><empty_output><jupyter_text>measurements<jupyter_code>res = pd.DataFrame({
    't': [112.5],
    'V': [1.892],
    'I': [0.3215]
})<jupyter_output><empty_output><jupyter_text>Results<jupyter_code>res.insert(3, 'P', res.V*res.I)
res.insert(4, 'E', res.P*res.t)
res<jupyter_output><empty_output><jupyter_text>Part D  Trial 1<jupyter_code>res = pd.DataFrame([
    [1, 0.079, 62.3, 0.0623, 0.0049217],
    [3, 0.1942, 59.9, 0.0599, 0.01163258],
    [3, 0.29, 88, 0.088, 0.02552],
    [4, 0.505, 95.5, 0.0955, 0.0482275],
    [5, 0.545, 86.4, 0.0864, 0.047088],
    [7, 0.483, 58.6, 0.0586, 0.0283038],
    [7, 0.4343, 52.7, 0.0527, 0.02288761],
    [10, 0.496, 49.5, 0.0495, 0.024552],
    [30, 0.626, 21.6, 0.0216, 0.0135216],
    [100, 0.71, 7.9, 0.0079, 0.005609],
    [300, 0.774, 3.5, 0.0035, 0.002709],
    [1000, 0.83, 1.73, 0.00173, 0.0014359],
    [3000, 0.855, 0.294, 0.000294, 0.00025137],
    [10000, 0.872, 0.096, 0.000096, 0.000083712]],
    columns=['R', 'V', 'I', 'I(A)', 'P'],
)
res
import seaborn as sns
from scipy.optimize import curve_fit
n = sum(res.P[:5])
mean = sum(res.R[:5]*res.P[:5])/n
sigma = np.sqrt(sum(res.P[:5]*(res.R[:5]-mean)**2)/n)


def gaus(x, a, x0, sigma, offset):
    return a*np.exp(-(x-x0)**2/(2*sigma**2)) + offset


popt, pcov = curve_fit(gaus, res.R[:5], res.P[:5], p0=[1, mean, sigma, 0.0])

plt.scatter(res.R, res.P)
plt.plot(10**np.linspace(0, 2, 100), gaus(10**np.linspace(0, 2, 100), *popt), 'b*:', label='fit')
plt.xscale('log')
plt.xlabel('R (Ohms)')
plt.ylabel('P (J/s)')
plt.show()<jupyter_output><empty_output><jupyter_text>Trial 2  Phase 1<jupyter_code>res = pd.DataFrame({
    'R': [
        1, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 30,
        60, 100, 500, 1000, 5000, 10000, 50000,
        100000, 500000, 1e6, 
    ],
    'V': [
        0.0560, 0.1256, 0.165, 0.12036, 0.2432,
        0.2815, 0.3544, 0.3881, 0.4162, 0.5479,
        0.6281, 0.7195, 0.7844, 0.8332, 0.8813,
        0.9007, 0.9156, 0.922, 0.9267, 0.9272, 
        0.9279, 0.9280, 
    ],
    'I': [
        0.049, 0.0405, 0.040, 0.040, 0.0394,
        0.0398, 0.0385, 0.03826, 0.03761, 0.0346,
        0.02996, 0.02293, 0.0123, 0.00831, 1.85e-3,
        8.9e-4, .1802e-3, 84.04e-6, 18.21e-6, 9.25e-6,
        1.94e-06, 1.01e-6
    ]
})
res.insert(3, 'P', res.V*res.I)
res
fit = np.polyfit(np.log10(res.R[3:11]), res.P[3:11], 2)
x = np.linspace(.7, 1.7, 110)
plt.plot(10**x, fit[0]*x**2 + fit[1]*x + fit[2])
plt.scatter(res.R, res.P)
plt.xscale('log')
plt.xlabel('R (Ohms)')
plt.ylabel('P (J/s)')
plt.show()
"""
This value below corresponds to the difference in measured power at 15 ohms
when zipping up through the resistance quickly and sitting at that resistance
for some time. The power was 1/4.4 the size when resting.
"""
res.loc[res.P==res.P.max(), 'P']/(.2629*16.32e-3)<jupyter_output><empty_output><jupyter_text>Phase 2 $ \eta_{FC} = \frac{E_{FC}}{E_{Hydrogen}}  = \frac{P_{FC} \cdot t_{FC}}{V_H \cdot LHV} $<jupyter_code>res = pd.DataFrame({
    'R': [
        15, 10, 7, 9
    ],
    'Volume': [
        3, 3, 5, 5
    ],
    'T': [
        467.26, 8*60+19.78, 10*60 + 49.57, 60*9 + 57.19
    ],
    'I': [
        16.24e-3, 50.86e-3, 56.22e-3, 53.57e-3
    ],
    'V': [
        .2616, .586, 0.4658, 0.5462
    ]
})
res['P'] = res['I'] * res['V']
res
h_density = 0.08988 #g/L<jupyter_output><empty_output><jupyter_text>$ cm^3 $ to kilograms$ V_H cm^3 \cdot \sigma \frac{g}{L} $$ V_H cm^3 \cdot \frac{1 L}{1000 cm^3} \cdot \sigma \frac{g}{L} \cdot \frac{1 kg}{1000\ g} = m\ (kg) $<jupyter_code>(1+1j)**4
plt.scatter(res['R'], res['P'])
# plt.xscale('log')
res['mass'] = res['V'] * 1e-3 * h_density * 1/1000
res
res['E_FC'] = (res['T'] * res['P'])
res['E_H'] = res['mass'] * LHV
res['E_FC']/res['E_H']<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1957629080805742, 'fraction_numerical': 0.15906459828664044, 'mean_word_length': 3.1020892687559356, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 3, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '587172', 'license': 'MIT', 'n_tokens_mistral': 4868, 'n_tokens_neox': 3963, 'n_words': 771, 'path': 'Lab/Lab1/.ipynb_checkpoints/APL_1_cell-checkpoint.ipynb', 'repo_name': 'trevorm4x/APL-fuel-first', 'size': '8638'}