def get_Porb(self, unit_system="SI"): nmu.set_units(system=unit_system) energy_unit = nmu.units["energy"] time_unit = nmu.units["time"] Porb = [] for sdata, _ in self.data: nmu.set_units(sdata["unit_system"]) Porb.append( nmu.convert_time(sdata["system"]["Porb"], nmu.units["time"], time_unit) ) return Porb
def get_Edot(self, unit_system="SI"): nmu.set_units(system=unit_system) energy_unit = nmu.units["energy"] time_unit = nmu.units["time"] mEdot = [] sEdot = [] for sdata, _ in self.data: nmu.set_units(sdata["unit_system"]) Eorb = nmu.convert_energy(abs(sdata["system"]["Eorb"]), nmu.units["energy"], energy_unit) porb = nmu.convert_time(sdata["system"]["Porb"], nmu.units["time"], time_unit) mEdot.append( sdata["stats"]["mean{|sum{Edot}|*(Porb/|Eorb|)}"] * Eorb/porb ) sEdot.append( sdata["stats"]["stdv{|sum{Edot}|*(Porb/|Eorb|)}"] * Eorb/porb ) return mEdot, sEdot
### compute power law fits (logp, logedot), (sedot, sp), (m, b) = fitting.sweeps_Edot_powerlaw(clusters, unit_system=opts.unit_system) if opts.verbose: print "\tlog(Edot) = %f * log(P) + %f"%(m, b) ### plot data from ste file directly if opts.raw_data: mEdot = [] Porb = [] for cluster in clusters: mEdot += cluster.get_Edot(unit_system=opts.unit_system)[0] Porb += cluster.get_Porb(unit_system=opts.unit_system) ax.plot([nmu.convert_time(p, nmu.units["time"], time_unit) for p in Porb], mEdot, marker="*", markerfacecolor="none", markeredgecolor=color, markersize=4, linestyle="none") ### plot fitting function p = nmu.convert_time(np.exp(logp), nmu.units["time"], time_unit) sp = nmu.convert_time(np.array(sp), nmu.units["time"], time_unit) ax.plot(p, np.exp(logedot), marker=marker, markerfacecolor="none", markeredgecolor=color, markersize=6, linestyle="none") ### plot error estimates for abscissa, ordinate, errx, erry in zip(p, np.exp(logedot), sp, sedot): ax.plot( [abscissa, abscissa], [ordinate+erry, ordinate-erry], marker="none", color=color, linestyle="-") ax.plot( [abscissa-errx, abscissa+errx], [ordinate, ordinate], marker="none", color=color, linestyle="-") if opts.verbose: print label print "\tedot sedot p sp" for A, B, C, D in zip(np.exp(logedot), sedot, p, sp): print "\t", A, B, C, D
def harmonic_average(cluster, key, unit_system="SI"): """ computes the harmonic average over the data within cluster we compute <Edot> = int dt Edot / int dt but we take the integral over Porb, so changing the integration variable to Porb yields <Edot> = int dP ( E/P * Edot**-1) * key / int dP ( E/P * Edot**-1 ) ASSUMES spacing is even in Porb-space (within each cluster!), so the integral's measure drops out """ nmu.set_units(unit_system) time_unit = nmu.units["time"] energy_unit = nmu.units["energy"] P = [] E = [] mEdot = [] sEdot = [] x = [] sx = [] for sdata, mdata in cluster.data: nmu.set_units(sdata["unit_system"]) ### convertion to Porb measure Porb = nmu.convert_time(sdata["system"]["Porb"], nmu.units["time"], time_unit) Eorb = nmu.convert_energy(sdata["system"]["Eorb"], nmu.units["energy"], energy_unit) P.append( Porb ) E.append( Eorb ) mEdot.append( sdata["stats"]["mean{|sum{Edot}|*(Porb/|Eorb|)}"] * Eorb/Porb ) sEdot.append( sdata["stats"]["stdv{|sum{Edot}|*(Porb/|Eorb|)}"] * Eorb/Porb ) if key == "Edot": x.append( sdata["stats"]["mean{|sum{Edot}|*(Porb/|Eorb|)}"] * Eorb/Porb ) sx.append( sdata["stats"]["stdv{|sum{Edot}|*(Porb/|Eorb|)}"] * Eorb/Porb ) elif key == "E": x.append( sdata["stats"]["mean{sum{E}/|Eorb|}"] * Eorb ) sx.append( sdata["stats"]["stdv{sum{E}/|Eorb|}"] * Eorb ) else: raise KeyError, "key=%s not understood"%key ### cast to arrays P = np.array(P) E = np.array(E) mEdot = np.array(mEdot) sEdot = np.array(sEdot) x = np.array(x) sx = np.array(sx) ### compute averages integrand = Eorb/(Porb*mEdot) num = np.sum( integrand * x ) den = np.sum( integrand ) p = np.sum( integrand * P ) mx = num/den mp = p/den ### compute uncertainties T = np.sum( integrand ) integrate = E/(P*mEdot**2) a = np.sum( integrand**2 * sx**2 ) / T**2 b = np.sum( (integrate * ( x*T - np.sum( x*integrand) ))**2 * sEdot**2 ) / T**4 smx = a + b ### uncertainty in x smp = np.sum( (integrate * ( P*T - np.sum( P*integrand) ))**2 * sEdot**2 ) / T**4 ### uncertainty in p return (mx, smx**0.5) , (mp, smp**0.5) '''