def plotE(self,*args,**kwargs): """ NAME: plotE PURPOSE: plot E(.) along the orbit INPUT: pot - Potential instance or list of instances in which the orbit was integrated d1= - plot Ez vs d1: e.g., 't', 'R', 'vR', 'vT' +bovy_plot.bovy_plot inputs OUTPUT: figure to output device HISTORY: 2010-07-10 - Written - Bovy (NYU) """ labeldict= {'t':r'$t$','R':r'$R$','vR':r'$v_R$','vT':r'$v_T$', 'z':r'$z$','vz':r'$v_z$','phi':r'$\phi$', 'x':r'$x$','y':r'$y$','vx':r'$v_x$','vy':r'$v_y$'} if not kwargs.has_key('pot'): try: pot= self._pot except AttributeError: raise AttributeError("Integrate orbit first or specify pot=") else: pot= kwargs['pot'] kwargs.pop('pot') if kwargs.has_key('d1'): d1= kwargs['d1'] kwargs.pop('d1') else: d1= 't' if len(self.vxvv) == 4: self.Es= [evaluateplanarPotentials(self.orbit[ii,0],pot, phi=self.orbit[ii,3], t=self.t[ii])+ self.orbit[ii,1]**2./2.+self.orbit[ii,2]**2./2. for ii in range(len(self.t))] else: self.Es= [evaluateplanarPotentials(self.orbit[ii,0],pot, t=self.t[ii])+ self.orbit[ii,1]**2./2.+self.orbit[ii,2]**2./2. for ii in range(len(self.t))] if not kwargs.has_key('xlabel'): kwargs['xlabel']= labeldict[d1] if not kwargs.has_key('ylabel'): kwargs['ylabel']= r'$E$' if d1 == 't': plot.bovy_plot(nu.array(self.t),nu.array(self.Es)/self.Es[0], *args,**kwargs) elif d1 == 'R': plot.bovy_plot(self.orbit[:,0],nu.array(self.Es)/self.Es[0], *args,**kwargs) elif d1 == 'vR': plot.bovy_plot(self.orbit[:,1],nu.array(self.Es)/self.Es[0], *args,**kwargs) elif d1 == 'vT': plot.bovy_plot(self.orbit[:,2],nu.array(self.Es)/self.Es[0], *args,**kwargs)
def _EOM_dxdv(x,t,pot): """ NAME: _EOM_dxdv PURPOSE: implements the EOM, i.e., the right-hand side of the differential equation, for integrating phase space differences, rectangular INPUT: x - current phase-space position t - current time pot - (list of) Potential instance(s) OUTPUT: dy/dt HISTORY: 2011-10-18 - Written - Bovy (NYU) """ #x is rectangular so calculate R and phi R= nu.sqrt(x[0]**2.+x[1]**2.) phi= nu.arccos(x[0]/R) sinphi= x[1]/R cosphi= x[0]/R if x[1] < 0.: phi= 2.*nu.pi-phi #calculate forces Rforce= evaluateplanarRforces(R,pot,phi=phi,t=t) phiforce= evaluateplanarphiforces(R,pot,phi=phi,t=t) R2deriv= evaluateplanarPotentials(R,pot,phi=phi,t=t,dR=2) phi2deriv= evaluateplanarPotentials(R,pot,phi=phi,t=t,dphi=2) Rphideriv= evaluateplanarPotentials(R,pot,phi=phi,t=t,dR=1,dphi=1) #Calculate derivatives and derivatives+time derivatives dFxdx= -cosphi**2.*R2deriv\ +2.*cosphi*sinphi/R**2.*phiforce\ +sinphi**2./R*Rforce\ +2.*sinphi*cosphi/R*Rphideriv\ -sinphi**2./R**2.*phi2deriv dFxdy= -sinphi*cosphi*R2deriv\ +(sinphi**2.-cosphi**2.)/R**2.*phiforce\ -cosphi*sinphi/R*Rforce\ -(cosphi**2.-sinphi**2.)/R*Rphideriv\ +cosphi*sinphi/R**2.*phi2deriv dFydx= -cosphi*sinphi*R2deriv\ +(sinphi**2.-cosphi**2.)/R**2.*phiforce\ +(sinphi**2.-cosphi**2.)/R*Rphideriv\ -sinphi*cosphi/R*Rforce\ +sinphi*cosphi/R**2.*phi2deriv dFydy= -sinphi**2.*R2deriv\ -2.*sinphi*cosphi/R**2.*phiforce\ -2.*sinphi*cosphi/R*Rphideriv\ +cosphi**2./R*Rforce\ -cosphi**2./R**2.*phi2deriv return nu.array([x[2],x[3], cosphi*Rforce-1./R*sinphi*phiforce, sinphi*Rforce+1./R*cosphi*phiforce, x[6],x[7], dFxdx*x[4]+dFxdy*x[5], dFydx*x[4]+dFydy*x[5]])
def _EOM_dxdv(x, t, pot): """ NAME: _EOM_dxdv PURPOSE: implements the EOM, i.e., the right-hand side of the differential equation, for integrating phase space differences, rectangular INPUT: x - current phase-space position t - current time pot - (list of) Potential instance(s) OUTPUT: dy/dt HISTORY: 2011-10-18 - Written - Bovy (NYU) """ #x is rectangular so calculate R and phi R = nu.sqrt(x[0]**2. + x[1]**2.) phi = nu.arccos(x[0] / R) sinphi = x[1] / R cosphi = x[0] / R if x[1] < 0.: phi = 2. * nu.pi - phi #calculate forces Rforce = evaluateplanarRforces(R, pot, phi=phi, t=t) phiforce = evaluateplanarphiforces(R, pot, phi=phi, t=t) R2deriv = evaluateplanarPotentials(R, pot, phi=phi, t=t, dR=2) phi2deriv = evaluateplanarPotentials(R, pot, phi=phi, t=t, dphi=2) Rphideriv = evaluateplanarPotentials(R, pot, phi=phi, t=t, dR=1, dphi=1) #Calculate derivatives and derivatives+time derivatives dFxdx= -cosphi**2.*R2deriv\ +2.*cosphi*sinphi/R**2.*phiforce\ +sinphi**2./R*Rforce\ +2.*sinphi*cosphi/R*Rphideriv\ -sinphi**2./R**2.*phi2deriv dFxdy= -sinphi*cosphi*R2deriv\ +(sinphi**2.-cosphi**2.)/R**2.*phiforce\ -cosphi*sinphi/R*Rforce\ -(cosphi**2.-sinphi**2.)/R*Rphideriv\ +cosphi*sinphi/R**2.*phi2deriv dFydx= -cosphi*sinphi*R2deriv\ +(sinphi**2.-cosphi**2.)/R**2.*phiforce\ +(sinphi**2.-cosphi**2.)/R*Rphideriv\ -sinphi*cosphi/R*Rforce\ +sinphi*cosphi/R**2.*phi2deriv dFydy= -sinphi**2.*R2deriv\ -2.*sinphi*cosphi/R**2.*phiforce\ -2.*sinphi*cosphi/R*Rphideriv\ +cosphi**2./R*Rforce\ -cosphi**2./R**2.*phi2deriv return nu.array([ x[2], x[3], cosphi * Rforce - 1. / R * sinphi * phiforce, sinphi * Rforce + 1. / R * cosphi * phiforce, x[6], x[7], dFxdx * x[4] + dFxdy * x[5], dFydx * x[4] + dFydy * x[5] ])
def E(self, *args, **kwargs): """ NAME: E PURPOSE: calculate the energy INPUT: pot= t= time at which to evaluate E OUTPUT: energy HISTORY: 2010-09-15 - Written - Bovy (NYU) """ if not kwargs.has_key('pot') or kwargs['pot'] is None: try: pot = self._pot except AttributeError: raise AttributeError("Integrate orbit or specify pot=") if kwargs.has_key('pot') and kwargs['pot'] is None: kwargs.pop('pot') else: pot = kwargs['pot'] kwargs.pop('pot') if isinstance(pot, Potential): thispot = RZToplanarPotential(pot) elif isinstance(pot, list): thispot = [] for p in pot: if isinstance(p, Potential): thispot.append(RZToplanarPotential(p)) else: thispot.append(p) else: thispot = pot if len(args) > 0: t = args[0] else: t = 0. #Get orbit thiso = self(*args, **kwargs) onet = (len(thiso.shape) == 1) if onet: return evaluateplanarPotentials(thiso[0],thispot, phi=thiso[3],t=t)\ +thiso[1]**2./2.\ +thiso[2]**2./2. else: return nu.array([evaluateplanarPotentials(thiso[0,ii],thispot, phi=thiso[3,ii], t=t[ii])\ +thiso[1,ii]**2./2.\ +thiso[2,ii]**2./2. for ii in range(len(t))])
def E(self,*args,**kwargs): """ NAME: E PURPOSE: calculate the energy INPUT: pot= t= time at which to evaluate E OUTPUT: energy HISTORY: 2010-09-15 - Written - Bovy (NYU) """ if not kwargs.has_key('pot') or kwargs['pot'] is None: try: pot= self._pot except AttributeError: raise AttributeError("Integrate orbit or specify pot=") if kwargs.has_key('pot') and kwargs['pot'] is None: kwargs.pop('pot') else: pot= kwargs['pot'] kwargs.pop('pot') if isinstance(pot,Potential): thispot= RZToplanarPotential(pot) elif isinstance(pot,list): thispot= [] for p in pot: if isinstance(p,Potential): thispot.append(RZToplanarPotential(p)) else: thispot.append(p) else: thispot= pot if len(args) > 0: t= args[0] else: t= 0. #Get orbit thiso= self(*args,**kwargs) onet= (len(thiso.shape) == 1) if onet: return evaluateplanarPotentials(thiso[0],thispot, phi=thiso[3],t=t)\ +thiso[1]**2./2.\ +thiso[2]**2./2. else: return nu.array([evaluateplanarPotentials(thiso[0,ii],thispot, phi=thiso[3,ii], t=t[ii])\ +thiso[1,ii]**2./2.\ +thiso[2,ii]**2./2. for ii in range(len(t))])
def _wrap_pot_func(self,attribute): if attribute == '_evaluate': return evaluateplanarPotentials elif attribute == '_Rforce': return evaluateplanarRforces elif attribute == '_phiforce': return evaluateplanarphiforces elif attribute == '_R2deriv': return evaluateplanarR2derivs elif attribute == '_phi2deriv': return lambda p,R,phi=0.,t=0.: \ evaluateplanarPotentials(p,R,phi=phi,t=t,dphi=2) elif attribute == '_Rphideriv': return lambda p,R,phi=0.,t=0.: \ evaluateplanarPotentials(p,R,phi=phi,t=t,dR=1,dphi=1) else: #pragma: no cover raise AttributeError("Attribute %s not found in for this WrapperPotential" % attribute)
def _wrap_pot_func(self, attribute): if attribute == '_evaluate': return evaluateplanarPotentials elif attribute == '_Rforce': return evaluateplanarRforces elif attribute == '_phiforce': return evaluateplanarphiforces elif attribute == '_R2deriv': return evaluateplanarR2derivs elif attribute == '_phi2deriv': return lambda p,R,phi=0.,t=0.: \ evaluateplanarPotentials(p,R,phi=phi,t=t,dphi=2) elif attribute == '_Rphideriv': return lambda p,R,phi=0.,t=0.: \ evaluateplanarPotentials(p,R,phi=phi,t=t,dR=1,dphi=1) else: #pragma: no cover raise AttributeError( "Attribute %s not found in for this WrapperPotential" % attribute)
def potentialAxi(R,pot,vc=1.,ro=1.): """ NAME: potentialAxi PURPOSE: return the potential INPUT: R - Galactocentric radius (/ro) pot - potential vc - circular velocity ro - reference radius OUTPUT: Phi(R) HISTORY: 2010-11-30 - Written - Bovy (NYU) """ return evaluateplanarPotentials(R,pot)
def plotE(self, *args, **kwargs): """ NAME: plotE PURPOSE: plot E(.) along the orbit INPUT: pot - Potential instance or list of instances in which the orbit was integrated d1= - plot Ez vs d1: e.g., 't', 'R', 'vR', 'vT', 'phi' +bovy_plot.bovy_plot inputs OUTPUT: figure to output device HISTORY: 2010-07-10 - Written - Bovy (NYU) """ labeldict = { 't': r'$t$', 'R': r'$R$', 'vR': r'$v_R$', 'vT': r'$v_T$', 'z': r'$z$', 'vz': r'$v_z$', 'phi': r'$\phi$', 'x': r'$x$', 'y': r'$y$', 'vx': r'$v_x$', 'vy': r'$v_y$' } if not kwargs.has_key('pot'): try: pot = self._pot except AttributeError: raise AttributeError("Integrate orbit first or specify pot=") else: pot = kwargs['pot'] kwargs.pop('pot') if kwargs.has_key('d1'): d1 = kwargs['d1'] kwargs.pop('d1') else: d1 = 't' self.Es = [ evaluateplanarPotentials( self.orbit[ii, 0], pot, phi=self.orbit[ii, 3]) + self.orbit[ii, 1]**2. / 2. + self.orbit[ii, 2]**2. / 2. for ii in range(len(self.t)) ] if not kwargs.has_key('xlabel'): kwargs['xlabel'] = labeldict[d1] if not kwargs.has_key('ylabel'): kwargs['ylabel'] = r'$E$' if d1 == 't': plot.bovy_plot(nu.array(self.t), nu.array(self.Es) / self.Es[0], *args, **kwargs) elif d1 == 'R': plot.bovy_plot(self.orbit[:, 0], nu.array(self.Es) / self.Es[0], *args, **kwargs) elif d1 == 'vR': plot.bovy_plot(self.orbit[:, 1], nu.array(self.Es) / self.Es[0], *args, **kwargs) elif d1 == 'vT': plot.bovy_plot(self.orbit[:, 2], nu.array(self.Es) / self.Es[0], *args, **kwargs) elif d1 == 'phi': plot.bovy_plot(self.orbit[:, 3], nu.array(self.Es) / self.Es[0], *args, **kwargs)