def solve(input_data,baseDir): q,dphi,rw,twd,p = input_data # Kepler's law gives a quantity related to wd mass and separation, a # scaled_mass = a**3/M_wd. I call this the scaled mass. scaled_mass = const.G * (1+q) * p**2 / 4.0 / np.pi**2 # convert white dwarf radius to units of separation, rw/a xl1_a = roche.xl1(q) rw_a = rw*xl1_a solved = True try: # try wood models mw = find_wdmass(twd,scaled_mass,rw_a,baseDir,model='wood') except: # try panei models (usually for masses above 1 Msun) try: mw = find_wdmass(twd,scaled_mass,rw_a,baseDir,model='panei') except: # try hamada models (for masses less than 0.4 or more than 1.2 Msun) try: mw=find_wdmass(twd,scaled_mass,rw_a,baseDir,model='hamada') except: solved = False # do nothing if none of the models yielded a solution # otherwise, if solved: # donor star mass mr = mw*q # from this wd mass and scaled mass, find a a3 = scaled_mass*mw a = a3**(1./3.) a = a.to(units.R_sun) # inc inc = roche.findi(q,dphi) sini = np.sin(np.radians(inc)) # radial velocities kw = (2.0*np.pi*sini*q*a/(1+q)/p).to(units.km/units.s) kr = kw/q #secondary radius #use from Warner 1995 (eggleton) #radius of sphere with same volume as Roche Lobe... r2 = 0.49*a*q**(2.0/3.0) r2 /= 0.6 * q**(2.0/3.0) + np.log(1.0+q**(1.0/3.0)) # need to be a little careful here for different versions of astropy data = (q,mw,rw_a*a,mr,r2,a,kw,kr,inc) if not quantitySupport: data = [getval(datum) for datum in data] return data else: return None
def findi(q, deltai): """ Finds value of i from q and deltai, assuming an eclipse phase width given in mgutils. If iangle would be > 90, sets = 90. """ # By MJG avphi = 0.037134275925356952 iangle = roche.findi(q, avphi) + deltai if iangle > 90.0: iangle = 90.0 return iangle
def calcChangepoints(self,phi): # Also get object for dphi, q and rwd as this is required to determine changepoints dphi = self.getParam('dphi') q = self.getParam('q') rwd = self.getParam('rwd') phi0Template = 'phi0_{0}' dphi_change = np.fabs(self._olddphi - dphi.currVal)/dphi.currVal q_change = np.fabs(self._oldq - q.currVal)/q.currVal rwd_change = np.fabs(self._oldrwd - rwd.currVal)/rwd.currVal if (dphi_change > 1.2) or (q_change > 1.2) or (rwd_change > 1.2): # Calculate inclination inc = roche.findi(q.currVal,dphi.currVal) # Calculate wd contact phases 3 and 4 phi3, phi4 = roche.wdphases(q.currVal, inc, rwd.currVal, ntheta=10) # Calculate length of wd egress dpwd = phi4 - phi3 # Distance from changepoints to mideclipse dist_cp = (dphi.currVal+dpwd)/2. else: dist_cp = self._dist_cp '''# Find location of all changepoints for iecl in range(self.necl): changepoints = [] phi0 = self.getParam(phi0Template.format(iecl)) # the following range construction gives a list # of all mid-eclipse phases within phi array for n in range (int( phi.min() ), int( phi.max() )+1, 1): changepoints.append(n+phi0.currVal-dist_cp) changepoints.append(n+phi0.currVal+dist_cp) ''' # Find location of all changepoints changepoints = [] # the following range construction gives a list # of all mid-eclipse phases within phi array for n in range (int( phi.min() ), int( phi.max() )+1, 1): changepoints.append(n-dist_cp) changepoints.append(n+dist_cp) # save these values for speed if (dphi_change > 1.2) or (q_change > 1.2) or (rwd_change > 1.2): self._dist_cp = dist_cp self._oldq = q.currVal self._olddphi = dphi.currVal self._oldrwd = rwd.currVal return changepoints
def solve(input_data, baseDir): q, dphi, rw, twd, p = input_data # Kepler's law gives a quantity related to wd mass and separation, a # scaled_mass = a**3/M_wd. I call this the scaled mass. scaled_mass = const.G * (1 + q) * p**2 / 4.0 / np.pi**2 # convert white dwarf radius to units of separation, rw/a xl1_a = roche.xl1(q) rw_a = rw * xl1_a solved = True try: # try wood models mw = find_wdmass(twd, scaled_mass, rw_a, baseDir, model='wood') except: # try panei models (usually for masses above 1 Msun) try: mw = find_wdmass(twd, scaled_mass, rw_a, baseDir, model='panei') except: # try hamada models (for masses less than 0.4 or more than 1.2 Msun) try: mw = find_wdmass(twd, scaled_mass, rw_a, baseDir, model='hamada') except: solved = False # do nothing if none of the models yielded a solution # otherwise, if solved: # donor star mass mr = mw * q # from this wd mass and scaled mass, find a a3 = scaled_mass * mw a = a3**(1. / 3.) a = a.to(units.R_sun) # inc inc = roche.findi(q, dphi) sini = np.sin(np.radians(inc)) # radial velocities kw = (2.0 * np.pi * sini * q * a / (1 + q) / p).to(units.km / units.s) kr = kw / q #secondary radius #use from Warner 1995 (eggleton) #radius of sphere with same volume as Roche Lobe... r2 = 0.49 * a * q**(2.0 / 3.0) r2 /= 0.6 * q**(2.0 / 3.0) + np.log(1.0 + q**(1.0 / 3.0)) # need to be a little careful here for different versions of astropy data = (q, mw, rw_a * a, mr, r2, a, kw, kr, inc) if not quantitySupport: data = [getval(datum) for datum in data] return data else: return None
return True ## Read in original model file labels, valsorig, a, b, c, d, footer = readMod(origname) qorig = valsorig[labels=='q'] iorig = valsorig[labels=='iangle'] phi = roche.findphi(qorig, iorig) minq = roche.findq(90,phi) ## Loop over q values wanted qlist = np.append([minq],np.linspace(0.02,0.1,9)) for q in qlist: ## find i and write model iangle = roche.findi(q,phi) vals = np.copy(valsorig) vals[labels=='q'] = q vals[labels=='iangle'] = iangle if q == minq: outname = "qmin.mod" else: outname = "q%03d.mod"%(q*100) writeMod(outname, labels, vals, a, b, c, d, footer) print "Written model with q", q, "to", outname
## Create model q/i relationship based on mean phi modelq, modelplus, modelminus = [], [], [] modeli = np.linspace(ilowerlim, 90, 1000) for j in modeli: modelq += [roche.findq(j, avphi)] modelplus += [roche.findq(j, avphi+avphierr)] modelminus += [roche.findq(j, avphi-avphierr)] ## Find statistics of points from model s = [] chisq, chisqr, chisqg, chisqb = 0, 0, 0, 0 for j in xrange(len(q[nz])): s += [(i[nz][j] - roche.findi(q[nz][j], avphi)) ** 2] #find difference squared for each point chisq += ((i[nz][j] - roche.findi(q[nz][j], avphi)) / ierr[nz][j])**2 + ((q[nz][j] - roche.findq(i[nz][j], avphi)) / qerr[nz][j])**2 if "-r" in names[j]: chisqr += ((i[nz][j] - roche.findi(q[nz][j], avphi)) / ierr[nz][j])**2 + ((q[nz][j] - roche.findq(i[nz][j], avphi)) / qerr[nz][j])**2 if "-g" in names[j]: chisqg += ((i[nz][j] - roche.findi(q[nz][j], avphi)) / ierr[nz][j])**2 + ((q[nz][j] - roche.findq(i[nz][j], avphi)) / qerr[nz][j])**2 if "-b" in names[j]: chisqb += ((i[nz][j] - roche.findi(q[nz][j], avphi)) / ierr[nz][j])**2 + ((q[nz][j] - roche.findq(i[nz][j], avphi)) / qerr[nz][j])**2 rms = np.sqrt(np.array([s]).mean()) # take mean and square root print "\nRMS is", rms print "Chisq is", chisq print "Reduced chisq is", chisq / len(q[nz]) print "\nChisq of red points is", chisqr, "reduced is", chisqr / len(q[nz][red]) print "Chisq of green points is", chisqg, "reduced is", chisqg / len(q[nz][gre]) print "Chisq of blue points is", chisqb, "reduced is", chisqb / len(q[nz][blu])
from trm import dnl, subs, sla, roche import stars, runs import mgutils as mg from os import listdir import pickle """ Script for plotting things in ingress/egress space """ avphi = 0.0373289888593 ianglemax=90 qmin = roche.findq(ianglemax, avphi) q = 0.024 iangle = roche.findi(q, avphi) q2 = 0.03 iangle2 = roche.findi(q2, avphi) plotFoldedEclipses = True plotUnfoldedEclipses = False class Eclipse(object): """ A class for handling times of an eclipse. """ def __init__(self, name): self.name = name def iestream(q, iangle, step=1./1000, n=200): """ Returns ingress, egress, x and y positions for stream. A wrapper around trm.roche.stream """