def actionsFreqs(self,*args,**kwargs): """ NAME: actionsFreqs PURPOSE: evaluate the actions and frequencies (jr,lz,jz,Omegar,Omegaphi,Omegaz) INPUT: Either: a) R,vR,vT,z,vz b) Orbit instance: initial condition used if that's it, orbit(t) if there is a time given as well scipy.integrate.quadrature keywords OUTPUT: (jr,lz,jz,Omegar,Omegaphi,Omegaz) HISTORY: 2013-08-28 - Written - Bovy (IAS) """ if ((self._c and not (kwargs.has_key('c') and not kwargs['c']))\ or (ext_loaded and ((kwargs.has_key('c') and kwargs['c'])))) \ and _check_c(self._pot): if len(args) == 5: #R,vR.vT, z, vz R,vR,vT, z, vz= args elif len(args) == 6: #R,vR.vT, z, vz, phi R,vR,vT, z, vz, phi= args else: meta= actionAngle(*args) R= meta._R vR= meta._vR vT= meta._vT z= meta._z vz= meta._vz if isinstance(R,float): R= nu.array([R]) vR= nu.array([vR]) vT= nu.array([vT]) z= nu.array([z]) vz= nu.array([vz]) Lz= R*vT if self._useu0: #First calculate u0 if kwargs.has_key('u0'): u0= kwargs['u0'] else: E= nu.array([evaluatePotentials(R[ii],z[ii],self._pot) +vR[ii]**2./2.+vz[ii]**2./2.+vT[ii]**2./2. for ii in range(len(R))]) u0= actionAngleStaeckel_c.actionAngleStaeckel_calcu0(E,Lz, self._pot, self._delta)[0] if kwargs.has_key('u0'): kwargs.pop('u0') else: u0= None jr, jz, Omegar, Omegaphi, Omegaz, err= actionAngleStaeckel_c.actionAngleFreqStaeckel_c(\ self._pot,self._delta,R,vR,vT,z,vz,u0=u0) if err == 0: return (jr,Lz,jz,Omegar,Omegaphi,Omegaz) else: raise RuntimeError("C-code for calculation actions failed; try with c=False") else: if kwargs.has_key('c') and kwargs['c'] and not self._c: warnings.warn("C module not used because potential does not have a C implementation",galpyWarning) raise NotImplementedError("actionsFreqs with c=False not implemented")
def calczmax(self,*args,**kwargs): """ NAME: calczmax PURPOSE: calculate the maximum height INPUT: Either: a) R,vR,vT,z,vz b) Orbit instance: initial condition used if that's it, orbit(t) if there is a time given as well OUTPUT: zmax HISTORY: 2012-06-01 - Written - Bovy (IAS) """ #Set up the actionAngleAxi object meta= actionAngle(*args) if isinstance(self._pot,list): thispot= [p.toPlanar() for p in self._pot] else: thispot= self._pot.toPlanar() if isinstance(self._pot,list): thisverticalpot= [p.toVertical(meta._R) for p in self._pot] else: thisverticalpot= self._pot.toVertical(meta._R) aAAxi= actionAngleAxi(*args,pot=thispot, verticalPot=thisverticalpot, gamma=self._gamma) return aAAxi.calczmax(**kwargs)
def JR(self, *args, **kwargs): """ NAME: JR PURPOSE: evaluate the action jr INPUT: Either: a) R,vR,vT,z,vz b) Orbit instance: initial condition used if that's it, orbit(t) if there is a time given as well scipy.integrate.quadrature keywords OUTPUT: Jr HISTORY: 2012-07-30 - Written - Bovy (IAS@MPIA) """ #Set up the actionAngleAxi object meta = actionAngle(*args) if isinstance(self._pot, list): thispot = [p.toPlanar() for p in self._pot] else: thispot = self._pot.toPlanar() aAAxi = actionAngleAxi(*args, pot=thispot, gamma=self._gamma) return aAAxi.JR(**kwargs)
def __call__(self, *args, **kwargs): """ NAME: __call__ PURPOSE: evaluate the actions (jr,lz,jz) INPUT: Either: a) R,vR,vT,z,vz b) Orbit instance: initial condition used if that's it, orbit(t) if there is a time given as well scipy.integrate.quadrature keywords OUTPUT: (jr,lz,jz), where jr=[jr,jrerr], and jz=[jz,jzerr] HISTORY: 2012-07-26 - Written - Bovy (IAS@MPIA) """ #Set up the actionAngleAxi object meta = actionAngle(*args) if isinstance(self._pot, list): thispot = [p.toPlanar() for p in self._pot] else: thispot = self._pot.toPlanar() if isinstance(self._pot, list): thisverticalpot = [p.toVertical(meta._R) for p in self._pot] else: thisverticalpot = self._pot.toVertical(meta._R) aAAxi = actionAngleAxi(*args, pot=thispot, verticalPot=thisverticalpot, gamma=self._gamma) return (aAAxi.JR(**kwargs), aAAxi._R * aAAxi._vT, aAAxi.Jz(**kwargs))
def Jz(self,*args,**kwargs): """ NAME: Jz PURPOSE: evaluate the action jz INPUT: Either: a) R,vR,vT,z,vz b) Orbit instance: initial condition used if that's it, orbit(t) if there is a time given as well scipy.integrate.quadrature keywords OUTPUT: jz,jzerr HISTORY: 2012-07-27 - Written - Bovy (IAS@MPIA) """ #Set up the actionAngleAxi object meta= actionAngle(*args) if isinstance(self._pot,list): thispot= [p.toPlanar() for p in self._pot] else: thispot= self._pot.toPlanar() if isinstance(self._pot,list): thisverticalpot= [p.toVertical(meta._R) for p in self._pot] else: thisverticalpot= self._pot.toVertical(meta._R) aAAxi= actionAngleAxi(*args,pot=thispot, verticalPot=thisverticalpot, gamma=self._gamma) return aAAxi.Jz(**kwargs)
def actionsFreqs(self,*args,**kwargs): """ NAME: actionsFreqs PURPOSE: evaluate the actions and frequencies (jr,lz,jz,Omegar,Omegaphi,Omegaz) INPUT: Either: a) R,vR,vT,z,vz b) Orbit instance: initial condition used if that's it, orbit(t) if there is a time given as well scipy.integrate.quadrature keywords OUTPUT: (jr,lz,jz,Omegar,Omegaphi,Omegaz) HISTORY: 2013-09-08 - Written - Bovy (IAS) """ if len(args) == 5: #R,vR.vT, z, vz R,vR,vT, z, vz= args elif len(args) == 6: #R,vR.vT, z, vz, phi R,vR,vT, z, vz, phi= args else: meta= actionAngle(*args) R= meta._R vR= meta._vR vT= meta._vT z= meta._z vz= meta._vz if isinstance(R,float): R= nu.array([R]) vR= nu.array([vR]) vT= nu.array([vT]) z= nu.array([z]) vz= nu.array([vz]) if self._c: pass else: Lz= R*vT Lx= -z*vT Ly= z*vR-R*vz L2= Lx*Lx+Ly*Ly+Lz*Lz E= self._ip(R,z)+vR**2./2.+vT**2./2.+vz**2./2. L= nu.sqrt(L2) #Actions Jphi= Lz Jz= L-nu.fabs(Lz) Jr= self.amp/nu.sqrt(-2.*E)\ -0.5*(L+nu.sqrt((L2+4.*self.amp*self.b))) #Frequencies Omegar= (-2.*E)**1.5/self.amp Omegaz= 0.5*(1.+L/nu.sqrt(L2+4.*self.amp*self.b))*Omegar Omegaphi= copy.copy(Omegaz) indx= Lz < 0. Omegaphi[indx]*= -1. return (Jr,Jphi,Jz,Omegar,Omegaphi,Omegaz)
def __call__(self,*args,**kwargs): """ NAME: __call__ PURPOSE: evaluate the actions (jr,lz,jz) INPUT: Either: a) R,vR,vT,z,vz b) Orbit instance: initial condition used if that's it, orbit(t) if there is a time given as well scipy.integrate.quadrature keywords OUTPUT: (jr,lz,jz) HISTORY: 2013-09-08 - Written - Bovy (IAS) """ if len(args) == 5: #R,vR.vT, z, vz R,vR,vT, z, vz= args elif len(args) == 6: #R,vR.vT, z, vz, phi R,vR,vT, z, vz, phi= args else: meta= actionAngle(*args) R= meta._R vR= meta._vR vT= meta._vT z= meta._z vz= meta._vz if isinstance(R,float): R= nu.array([R]) vR= nu.array([vR]) vT= nu.array([vT]) z= nu.array([z]) vz= nu.array([vz]) if self._c: #pragma: no cover pass else: Lz= R*vT Lx= -z*vT Ly= z*vR-R*vz L2= Lx*Lx+Ly*Ly+Lz*Lz E= self._ip(R,z)+vR**2./2.+vT**2./2.+vz**2./2. L= nu.sqrt(L2) #Actions Jphi= Lz Jz= L-nu.fabs(Lz) Jr= self.amp/nu.sqrt(-2.*E)\ -0.5*(L+nu.sqrt((L2+4.*self.amp*self.b))) return (Jr,Jphi,Jz)
def actionsFreqsAngles(self,*args,**kwargs): """ NAME: actionsFreqsAngles PURPOSE: evaluate the actions, frequencies, and angles (jr,lz,jz,Omegar,Omegaphi,Omegaz,angler,anglephi,anglez) INPUT: Either: a) R,vR,vT,z,vz,phi (MUST HAVE PHI) b) Orbit instance: initial condition used if that's it, orbit(t) if there is a time given as well scipy.integrate.quadrature keywords OUTPUT: (jr,lz,jz,Omegar,Omegaphi,Omegaz,angler,anglephi,anglez) HISTORY: 2013-09-08 - Written - Bovy (IAS) """ if len(args) == 5: #R,vR.vT, z, vz raise IOError("You need to provide phi when calculating angles") elif len(args) == 6: #R,vR.vT, z, vz, phi R,vR,vT, z, vz, phi= args else: meta= actionAngle(*args) R= meta._R vR= meta._vR vT= meta._vT z= meta._z vz= meta._vz phi= meta._phi if isinstance(R,float): R= nu.array([R]) vR= nu.array([vR]) vT= nu.array([vT]) z= nu.array([z]) vz= nu.array([vz]) phi= nu.array([phi]) if self._c: pass else: Lz= R*vT Lx= -z*vT Ly= z*vR-R*vz L2= Lx*Lx+Ly*Ly+Lz*Lz E= self._ip(R,z)+vR**2./2.+vT**2./2.+vz**2./2. L= nu.sqrt(L2) #Actions Jphi= Lz Jz= L-nu.fabs(Lz) Jr= self.amp/nu.sqrt(-2.*E)\ -0.5*(L+nu.sqrt((L2+4.*self.amp*self.b))) #Frequencies Omegar= (-2.*E)**1.5/self.amp Omegaz= 0.5*(1.+L/nu.sqrt(L2+4.*self.amp*self.b))*Omegar Omegaphi= copy.copy(Omegaz) indx= Lz < 0. Omegaphi[indx]*= -1. #Angles c= -self.amp/2./E-self.b e2= 1.-L2/self.amp/c*(1.+self.b/c) e= nu.sqrt(e2) s= 1.+nu.sqrt(1.+(R**2.+z**2.)/self.b**2.) coseta= 1/e*(1.-self.b/c*(s-2.)) pindx= (coseta > 1.)*(coseta < (1.+10.**-7.)) coseta[pindx]= 1. pindx= (coseta < -1.)*(coseta > (-1.-10.**-7.)) coseta[pindx]= -1. eta= nu.arccos(coseta) costheta= z/nu.sqrt(R**2.+z**2.) sintheta= R/nu.sqrt(R**2.+z**2.) vrindx= (vR*sintheta+vz*costheta) < 0. eta[vrindx]= 2.*nu.pi-eta[vrindx] angler= eta-e*c/(c+self.b)*nu.sin(eta) tan11= nu.arctan(nu.sqrt((1.+e)/(1.-e))*nu.tan(0.5*eta)) tan12= nu.arctan(nu.sqrt((1.+e+2.*self.b/c)/(1.-e+2.*self.b/c))*nu.tan(0.5*eta)) vzindx= (-vz*sintheta+vR*costheta) > 0. tan11[tan11 < 0.]+= nu.pi tan12[tan12 < 0.]+= nu.pi pindx= (Lz/L > 1.)*(Lz/L < (1.+10.**-7.)) Lz[pindx]= L[pindx] pindx= (Lz/L < -1.)*(Lz/L > (-1.-10.**-7.)) Lz[pindx]= -L[pindx] i= nu.arccos(Lz/L) sinpsi= costheta/nu.sin(i) pindx= (sinpsi > 1.)*(sinpsi < (1.+10.**-7.)) sinpsi[pindx]= 1. pindx= (sinpsi < -1.)*(sinpsi > (-1.-10.**-7.)) sinpsi[pindx]= -1. psi= nu.arcsin(sinpsi) psi[vzindx]= nu.pi-psi[vzindx] psi= psi % (2.*nu.pi) anglez= psi+Omegaz/Omegar*angler\ -tan11-1./nu.sqrt(1.+4*self.amp*self.b/L2)*tan12 sinu= z/R/nu.tan(i) pindx= (sinu > 1.)*(sinu < (1.+10.**-7.)) sinu[pindx]= 1. pindx= (sinu < -1.)*(sinu > (-1.-10.**-7.)) sinu[pindx]= -1. u= nu.arcsin(sinu) u[vzindx]= nu.pi-u[vzindx] Omega= phi-u anglephi= Omega anglephi[indx]-= anglez[indx] anglephi[True-indx]+= anglez[True-indx] angler= angler % (2.*nu.pi) anglephi= anglephi % (2.*nu.pi) anglez= anglez % (2.*nu.pi) return (Jr,Jphi,Jz,Omegar,Omegaphi,Omegaz,angler,anglephi,anglez)
def __call__(self,*args,**kwargs): """ NAME: __call__ PURPOSE: evaluate the actions (jr,lz,jz) INPUT: Either: a) R,vR,vT,z,vz b) Orbit instance: initial condition used if that's it, orbit(t) if there is a time given as well scipy.integrate.quadrature keywords _justjr, _justjz= if True, only calculate the radial or vertical action (internal use) OUTPUT: (jr,lz,jz), where jr=[jr,jrerr], and jz=[jz,jzerr] HISTORY: 2012-07-26 - Written - Bovy (IAS@MPIA) """ if ((self._c and not (kwargs.has_key('c') and not kwargs['c']))\ or (ext_loaded and ((kwargs.has_key('c') and kwargs['c'])))) \ and _check_c(self._pot): if len(args) == 5: #R,vR.vT, z, vz R,vR,vT, z, vz= args elif len(args) == 6: #R,vR.vT, z, vz, phi R,vR,vT, z, vz, phi= args else: meta= actionAngle(*args) R= meta._R vR= meta._vR vT= meta._vT z= meta._z vz= meta._vz if isinstance(R,float): R= nu.array([R]) vR= nu.array([vR]) vT= nu.array([vT]) z= nu.array([z]) vz= nu.array([vz]) Lz= R*vT jr, jz, err= actionAngleAdiabatic_c.actionAngleAdiabatic_c(\ self._pot,self._gamma,R,vR,vT,z,vz) if err == 0: return (jr,Lz,jz) else: #pragma: no cover raise RuntimeError("C-code for calculation actions failed; try with c=False") else: if kwargs.has_key('c') and kwargs['c'] and not self._c: warnings.warn("C module not used because potential does not have a C implementation",galpyWarning) #pragma: no cover if kwargs.has_key('c'): kwargs.pop('c') if (len(args) == 5 or len(args) == 6) \ and isinstance(args[0],nu.ndarray): ojr= nu.zeros((len(args[0]))) olz= nu.zeros((len(args[0]))) ojz= nu.zeros((len(args[0]))) for ii in range(len(args[0])): if len(args) == 5: targs= (args[0][ii],args[1][ii],args[2][ii], args[3][ii],args[4][ii]) elif len(args) == 6: targs= (args[0][ii],args[1][ii],args[2][ii], args[3][ii],args[4][ii],args[5][ii]) tjr,tlz,tjz= self(*targs,**copy.copy(kwargs)) ojr[ii]= tjr ojz[ii]= tjz olz[ii]= tlz return (ojr,olz,ojz) else: #Set up the actionAngleAxi object meta= actionAngle(*args) if isinstance(self._pot,list): thispot= [p.toPlanar() for p in self._pot] else: thispot= self._pot.toPlanar() if isinstance(self._pot,list): thisverticalpot= [p.toVertical(meta._R) for p in self._pot] else: thisverticalpot= self._pot.toVertical(meta._R) aAAxi= actionAngleAxi(*args,pot=thispot, verticalPot=thisverticalpot, gamma=self._gamma) if kwargs.get('_justjr',False): kwargs.pop('_justjr') return (aAAxi.JR(**kwargs),nu.nan,nu.nan) elif kwargs.get('_justjz',False): kwargs.pop('_justjz') return (nu.nan,nu.nan,aAAxi.Jz(**kwargs)) else: return (aAAxi.JR(**kwargs),aAAxi._R*aAAxi._vT,aAAxi.Jz(**kwargs))
def __call__(self,*args,**kwargs): """ NAME: __call__ PURPOSE: evaluate the actions (jr,lz,jz) INPUT: Either: a) R,vR,vT,z,vz b) Orbit instance: initial condition used if that's it, orbit(t) if there is a time given as well c= True/False; overrides the object's c= keyword to use C or not scipy.integrate.quadrature keywords OUTPUT: (jr,lz,jz) HISTORY: 2012-11-27 - Written - Bovy (IAS) """ if ((self._c and not (kwargs.has_key('c') and not kwargs['c']))\ or (ext_loaded and ((kwargs.has_key('c') and kwargs['c'])))) \ and _check_c(self._pot): if len(args) == 5: #R,vR.vT, z, vz R,vR,vT, z, vz= args elif len(args) == 6: #R,vR.vT, z, vz, phi R,vR,vT, z, vz, phi= args else: meta= actionAngle(*args) R= meta._R vR= meta._vR vT= meta._vT z= meta._z vz= meta._vz if isinstance(R,float): R= nu.array([R]) vR= nu.array([vR]) vT= nu.array([vT]) z= nu.array([z]) vz= nu.array([vz]) Lz= R*vT if self._useu0: #First calculate u0 if kwargs.has_key('u0'): u0= kwargs['u0'] else: E= nu.array([evaluatePotentials(R[ii],z[ii],self._pot) +vR[ii]**2./2.+vz[ii]**2./2.+vT[ii]**2./2. for ii in range(len(R))]) u0= actionAngleStaeckel_c.actionAngleStaeckel_calcu0(E,Lz, self._pot, self._delta)[0] if kwargs.has_key('u0'): kwargs.pop('u0') else: u0= None jr, jz, err= actionAngleStaeckel_c.actionAngleStaeckel_c(\ self._pot,self._delta,R,vR,vT,z,vz,u0=u0) if err == 0: return (jr,Lz,jz) else: raise RuntimeError("C-code for calculation actions failed; try with c=False") else: if kwargs.has_key('c') and kwargs['c'] and not self._c: warnings.warn("C module not used because potential does not have a C implementation",galpyWarning) if kwargs.has_key('c'): kwargs.pop('c') if (len(args) == 5 or len(args) == 6) \ and isinstance(args[0],nu.ndarray): ojr= nu.zeros((len(args[0]))) olz= nu.zeros((len(args[0]))) ojz= nu.zeros((len(args[0]))) for ii in range(len(args[0])): if len(args) == 5: targs= (args[0][ii],args[1][ii],args[2][ii], args[3][ii],args[4][ii]) elif len(args) == 6: targs= (args[0][ii],args[1][ii],args[2][ii], args[3][ii],args[4][ii],args[5][ii]) tjr,tlz,tjz= self(*targs,**copy.copy(kwargs)) ojr[ii]= tjr ojz[ii]= tjz olz[ii]= tlz return (ojr,olz,ojz) else: #Set up the actionAngleStaeckelSingle object aASingle= actionAngleStaeckelSingle(*args,pot=self._pot, delta=self._delta) return (aASingle.JR(**copy.copy(kwargs)), aASingle._R*aASingle._vT, aASingle.Jz(**copy.copy(kwargs)))