def orderbook_better_stddev(orderbook, r): samples = [ orderbook.price_at(timestamp) for timestamp in r if orderbook.offer_at(timestamp) != float('inf') and orderbook.bid_at(timestamp) != 0 ] if len(samples) == 0: return 0 return stddev(samples)
def getPedestral(tDict, vDict, timetupel): # # returns dict with timber var as keys and corresponding # averaged pedestral for time period # # (dtStart, dtEnd, labText) = timetupel tsStart = stringDateToTimeStamp(dtStart) tsEnd = stringDateToTimeStamp(dtEnd) pedList = [] if debug: print "Starting time", dtStart print "Ending time", dtEnd vars = vDict.keys() for det in vDict.keys(): xarray, yarray = [], [] if debug: print "timber var ", det detData = tDict[det] for ts, dt, val in detData: if ts > tsEnd or ts <= tsStart: continue yarray += [val] meanPedestral = mean(yarray) stddevPed = stddev(yarray) pedList += [(det, [meanPedestral, stddevPed])] pedDict = dict(pedList) if debug: print "pedDict", pedDict return pedDict
################### # Operating point # ################### delta_V_4 = hp.fetch2('data/operating_point.xlsx', 'err V_4 [mV]') V_4 = hp.fetch2('data/operating_point.xlsx', 'V_4 [mV]', delta_V_4)/1000 delta_I = hp.fetch2('data/operating_point.xlsx', 'err I [mu A]') I = hp.fetch2('data/operating_point.xlsx', 'I [mu A]', delta_I)/10**6 T = hp.fetch2('data/operating_point.xlsx', 'T [°C]', 0.1) R_S = V_4/I fig, ax1 = plt.subplots() ax1.errorbar(hp.nominal(I)*10**3, hp.nominal(T), fmt='b.', xerr=hp.stddev(I)*10**3, yerr=hp.stddev(T)) ax1.set_xlabel('Current $I \, [mA]$') ax1.set_ylabel('Temperature $T \, [^{\circ}C]$', color='b') ax1.tick_params('y', colors='b') ax2 = ax1.twinx() ax2.errorbar([100000], [1000000], fmt='b.', xerr=0, yerr=0, label="measured temperature") # dummy for the label ax2.errorbar(hp.nominal(I)*10**3, hp.nominal(R_S)/1000, fmt='r.', xerr=hp.stddev(I)*10**3, yerr=hp.stddev(R_S)/1000, label="measured resistance") ax2.set_ylabel('Resistance $R_S \, [k\Omega]$', color='r') ax2.tick_params('y', colors='r') I_Op = 0.4007 V_2_Op = 3.250 hp.replace("I_Op", I_Op) hp.replace("V_2_Op", V_2_Op)
coeffs3 = hp.phpolyfit(I_mean, deltaTplus + deltaTminus, 2) p3 = lambda x: np.polyval(coeffs3, x) x3 = np.linspace(0, 18, 100) coeffs4 = hp.phpolyfit(I, deltaT, 2) p4 = lambda x: np.polyval(coeffs4, x) x4 = np.linspace(-18, 18, 100) ### PLOTS ### # I - Pi12V plt.figure(0) plt.errorbar(hp.nominal(I_mean), hp.nominal(Pi12V) * 10**3, xerr=hp.stddev(I_mean), yerr=hp.stddev(Pi12V) * 10**3, label=r'' + Temp + '°C') plt.ylabel(r'$\Pi_{12}^{(V)}$ [mV]') # I - Pi12I plt.figure(1) plt.errorbar(hp.nominal(I_mean), hp.nominal(Pi12I) * 10**3, xerr=hp.stddev(I_mean), yerr=hp.stddev(Pi12I) * 10**3, label=r'' + Temp + '°C') plt.ylabel(r'$\Pi_{12}^{(I)}$ [mV]') # I - dT plt.figure(2)
hp.replace("delta_turns", hp.physical(delta_turns, 0, 1)) # erf fit def erf_param(x, a, b, c, d): return (np.vectorize(lambda x, a, b, c, d: a * erf(b * x + c) + d)(x, a, b, c, d)) guess_a, guess_b, guess_c, guess_d = -20.0, 1.2, -3.5, 20.0 # erf() guesses = np.array([guess_a, guess_b, guess_c, guess_d]) popt, pcov = curve_fit(erf_param, hp.nominal(turns), hp.nominal(ctps), p0=guesses, sigma=hp.stddev(ctps), absolute_sigma=True) aerr, berr, cerr, derr = list(np.sqrt(np.diag(pcov))) a, b, c, d = list(popt) erf_fit = lambda x: np.vectorize(lambda x: a * erf(b * x + c) + d)(x) # parameters of the erf fit hp.replace("fit:erf_a", hp.physical(a, aerr, 4)) hp.replace("fit:erf_b", hp.physical(b, berr, 4)) hp.replace("fit:erf_c", hp.physical(c, cerr, 4)) hp.replace("fit:erf_d", hp.physical(d, derr, 4)) X = np.linspace(0, 6, 500) gauss = lambda x: 2 * a * b * np.exp(-(b * x + c)**2) / np.sqrt(np.pi)
def orderbook_stddev(orderbook, r): samples = [orderbook.price_at(timestamp) for timestamp in r] return stddev(samples)
x = hp.fetch2('data/doserate.xlsx', 'x [cm]', 1) / 100 A = hp.fetch2('data/doserate.xlsx', 'A [muSv/hr]', 0.2) A[10].sf = 1 def invsq_param(x, a): return (np.vectorize(lambda x, a: a / (x**2))(x, a)) fit_x = hp.nominal(x) fit_x[0] = 10**-10 # "very" small => "zero" guesses = np.array([0.0207]) popt, pcov = curve_fit(invsq_param, fit_x, hp.nominal(A), p0=guesses, sigma=hp.stddev(A), absolute_sigma=True) aerr = list(np.sqrt(np.diag(pcov))) #a = list(popt) a = popt[0] invsq_fit = lambda x: np.vectorize(lambda x: 0.02 / (x**2))(x) X = np.linspace(0.001, 2.2, 500) plt.figure(figNr) plt.errorbar(hp.nominal(x * 100), hp.nominal(A), fmt='x', xerr=hp.stddev(x * 100), yerr=hp.stddev(A), label=r'dose rate data')