def calcRapRperi(self, *args, **kwargs): """ NAME: calcRapRperi PURPOSE: calculate the apocenter and pericenter radii 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: (rperi,rap) HISTORY: 2013-11-27 - Written - Bovy (IAS) """ #Set up the actionAngleAxi object if isinstance(self._pot, list): thispot = [ p.toPlanar() for p in self._pot if not isinstance(p, planarPotential) ] thispot.extend( [p for p in self._pot if isinstance(p, planarPotential)]) elif not isinstance(self._pot, planarPotential): thispot = self._pot.toPlanar() else: thispot = self._pot aAAxi = actionAngleAxi(*args, pot=thispot, gamma=self._gamma) return aAAxi.calcRapRperi(**kwargs)
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 self._parse_eval_args(*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(self._eval_R) for p in self._pot] else: thisverticalpot= self._pot.toVertical(self._eval_R) aAAxi= actionAngleAxi(*args,pot=thispot, verticalPot=thisverticalpot, gamma=self._gamma) return aAAxi.calczmax(**kwargs)
def calczmax(self,*args,**kwargs): #pragma: no cover """ 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) """ warnings.warn("actionAngleAdiabatic.calczmax function will soon be deprecated; please contact galpy's maintainer if you require this function") #Set up the actionAngleAxi object self._parse_eval_args(*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(self._eval_R) for p in self._pot] else: thisverticalpot= self._pot.toVertical(self._eval_R) aAAxi= actionAngleAxi(*args,pot=thispot, verticalPot=thisverticalpot, gamma=self._gamma) return aAAxi.calczmax(**kwargs)
def calcRapRperi(self,*args,**kwargs): """ NAME: calcRapRperi PURPOSE: calculate the apocenter and pericenter radii 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: (rperi,rap) HISTORY: 2013-11-27 - Written - Bovy (IAS) """ #Set up the actionAngleAxi object if isinstance(self._pot,list): thispot= [p.toPlanar() for p in self._pot if not isinstance(p,planarPotential)] thispot.extend([p for p in self._pot if isinstance(p,planarPotential)]) elif not isinstance(self._pot,planarPotential): thispot= self._pot.toPlanar() else: thispot= self._pot aAAxi= actionAngleAxi(*args,pot=thispot, gamma=self._gamma) return aAAxi.calcRapRperi(**kwargs)
def calczmax(self, *args, **kwargs): #pragma: no cover """ 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) """ warnings.warn( "actionAngleAdiabatic.calczmax function will soon be deprecated; please contact galpy's maintainer if you require this function" ) #Set up the actionAngleAxi object self._parse_eval_args(*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(self._eval_R) for p in self._pot] else: thisverticalpot = self._pot.toVertical(self._eval_R) aAAxi = actionAngleAxi(*args, pot=thispot, verticalPot=thisverticalpot, gamma=self._gamma) return aAAxi.calczmax(**kwargs)
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 self._parse_eval_args(*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(self._eval_R) for p in self._pot] else: thisverticalpot = self._pot.toVertical(self._eval_R) aAAxi = actionAngleAxi(*args, pot=thispot, verticalPot=thisverticalpot, gamma=self._gamma) return aAAxi.calczmax(**kwargs)
def _EccZmaxRperiRap(self, *args, **kwargs): """ NAME: EccZmaxRperiRap (_EccZmaxRperiRap) PURPOSE: evaluate the eccentricity, maximum height above the plane, peri- and apocenter for a spherical potential INPUT: Either: a) R,vR,vT,z,vz[,phi]: 1) floats: phase-space value for single object (phi is optional) (each can be a Quantity) 2) numpy.ndarray: [N] phase-space values for N objects (each can be a Quantity) b) Orbit instance: initial condition used if that's it, orbit(t) if there is a time given as well as the second argument OUTPUT: (e,zmax,rperi,rap) HISTORY: 2017-12-22 - Written - Bovy (UofT) """ 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: self._parse_eval_args(*args) R = self._eval_R vR = self._eval_vR vT = self._eval_vT z = self._eval_z vz = self._eval_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 L = nu.sqrt(L2) #Set up an actionAngleAxi object for EL and rap/rperi calculations axiR = nu.sqrt(R**2. + z**2.) axivT = L / axiR axivR = (R * vR + z * vz) / axiR rperi, rap = [], [] for ii in range(len(axiR)): axiaA = actionAngleAxi(axiR[ii], axivR[ii], axivT[ii], pot=self._2dpot) trperi, trap = axiaA.calcRapRperi() rperi.append(trperi) rap.append(trap) rperi = nu.array(rperi) rap = nu.array(rap) return ((rap - rperi) / (rap + rperi), rap * nu.sqrt(1. - Lz**2. / L2), rperi, rap)
def _EccZmaxRperiRap(self,*args,**kwargs): """ NAME: EccZmaxRperiRap (_EccZmaxRperiRap) PURPOSE: evaluate the eccentricity, maximum height above the plane, peri- and apocenter for a spherical potential INPUT: Either: a) R,vR,vT,z,vz[,phi]: 1) floats: phase-space value for single object (phi is optional) (each can be a Quantity) 2) numpy.ndarray: [N] phase-space values for N objects (each can be a Quantity) b) Orbit instance: initial condition used if that's it, orbit(t) if there is a time given as well as the second argument OUTPUT: (e,zmax,rperi,rap) HISTORY: 2017-12-22 - Written - Bovy (UofT) """ 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: self._parse_eval_args(*args) R= self._eval_R vR= self._eval_vR vT= self._eval_vT z= self._eval_z vz= self._eval_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 L= nu.sqrt(L2) #Set up an actionAngleAxi object for EL and rap/rperi calculations axiR= nu.sqrt(R**2.+z**2.) axivT= L/axiR axivR= (R*vR+z*vz)/axiR rperi, rap= [], [] for ii in range(len(axiR)): axiaA= actionAngleAxi(axiR[ii],axivR[ii],axivT[ii], pot=self._2dpot) trperi,trap= axiaA.calcRapRperi() rperi.append(trperi) rap.append(trap) rperi= nu.array(rperi) rap= nu.array(rap) return ((rap-rperi)/(rap+rperi),rap*nu.sqrt(1.-Lz**2./L2), rperi,rap)
def _evaluate(self,*args,**kwargs): """ NAME: _evaluate 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 ('c' in kwargs and not kwargs['c']))\ or (ext_loaded and (('c' in kwargs 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: self._parse_eval_args(*args) R= self._eval_R vR= self._eval_vR vT= self._eval_vT z= self._eval_z vz= self._eval_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 'c' in kwargs 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 kwargs.pop('c',None) 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 self._parse_eval_args(*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(self._eval_R) for p in self._pot] else: thisverticalpot= self._pot.toVertical(self._eval_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 fixed_quad= (False) if True, use n=10 fixed_quad integration scipy.integrate.quadrature keywords OUTPUT: (jr,lz,jz) HISTORY: 2013-12-28 - Written - Bovy (IAS) """ fixed_quad = kwargs.pop('fixed_quad', False) 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 = evaluatePotentials( R, z, self._pot) + vR**2. / 2. + vT**2. / 2. + vz**2. / 2. L = nu.sqrt(L2) #Actions Jphi = Lz Jz = L - nu.fabs(Lz) #Jr requires some more work #Set up an actionAngleAxi object for EL and rap/rperi calculations axiR = nu.sqrt(R**2. + z**2.) axivT = L / axiR axivR = (R * vR + z * vz) / axiR Jr = [] for ii in range(len(axiR)): axiaA = actionAngleAxi(axiR[ii], axivR[ii], axivT[ii], pot=self._2dpot) (rperi, rap) = axiaA.calcRapRperi() EL = axiaA.calcEL() E, L = EL Jr.append(self._calc_jr(rperi, rap, E, L, fixed_quad, **kwargs)) return (nu.array(Jr), Jphi, Jz)
def actionsFreqsAngles(self, *args, **kwargs): """ NAME: actionsFreqsAngles PURPOSE: evaluate the actions, frequencies, and angles (jr,lz,jz,Omegar,Omegaphi,Omegaz,ar,ap,az) 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 fixed_quad= (False) if True, use n=10 fixed_quad integration scipy.integrate.quadrature keywords OUTPUT: (jr,lz,jz,Omegar,Omegaphi,Omegaz,ar,aphi,az) HISTORY: 2013-12-29 - Written - Bovy (IAS) """ fixed_quad = kwargs.pop('fixed_quad', False) if len(args) == 5: #R,vR.vT, z, vz pragma: no cover 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: #pragma: no cover pass else: Lz = R * vT Lx = -z * vT Ly = z * vR - R * vz L2 = Lx * Lx + Ly * Ly + Lz * Lz E = evaluatePotentials( R, z, self._pot) + vR**2. / 2. + vT**2. / 2. + vz**2. / 2. L = nu.sqrt(L2) #Actions Jphi = Lz Jz = L - nu.fabs(Lz) #Jr requires some more work #Set up an actionAngleAxi object for EL and rap/rperi calculations axiR = nu.sqrt(R**2. + z**2.) axivT = L / axiR #these are really spherical coords, called axi bc they go in actionAngleAxi axivR = (R * vR + z * vz) / axiR axivz = (z * vR - R * vz) / axiR Jr = [] Or = [] Op = [] ar = [] az = [] #Calculate the longitude of the ascending node asc = self._calc_long_asc(z, R, axivz, phi, Lz, L) for ii in range(len(axiR)): axiaA = actionAngleAxi(axiR[ii], axivR[ii], axivT[ii], pot=self._2dpot) (rperi, rap) = axiaA.calcRapRperi() EL = axiaA.calcEL() E, L = EL Jr.append(self._calc_jr(rperi, rap, E, L, fixed_quad, **kwargs)) #Radial period Rmean = m.exp((m.log(rperi) + m.log(rap)) / 2.) if Jr[-1] < 10.**-9.: #Circular orbit Or.append(epifreq(self._pot, axiR[ii])) Op.append(omegac(self._pot, axiR[ii])) else: Or.append( self._calc_or(Rmean, rperi, rap, E, L, fixed_quad, **kwargs)) Op.append( self._calc_op(Or[-1], Rmean, rperi, rap, E, L, fixed_quad, **kwargs)) #Angles ar.append( self._calc_angler(Or[-1], axiR[ii], Rmean, rperi, rap, E, L, axivR[ii], fixed_quad, **kwargs)) az.append( self._calc_anglez(Or[-1], Op[-1], ar[-1], z[ii], axiR[ii], Rmean, rperi, rap, E, L, Lz[ii], axivR[ii], axivz[ii], fixed_quad, **kwargs)) Op = nu.array(Op) Oz = copy.copy(Op) Op[vT < 0.] *= -1. ap = copy.copy(asc) ar = nu.array(ar) az = nu.array(az) ap[vT < 0.] -= az[vT < 0.] ap[vT >= 0.] += az[vT >= 0.] ar = ar % (2. * nu.pi) ap = ap % (2. * nu.pi) az = az % (2. * nu.pi) return (nu.array(Jr), Jphi, Jz, nu.array(Or), Op, Oz, ar, ap, az)
def _EccZmaxRperiRap(self,*args,**kwargs): """ NAME: EccZmaxRperiRap (_EccZmaxRperiRap) PURPOSE: evaluate the eccentricity, maximum height above the plane, peri- and apocenter in the adiabatic approximation INPUT: Either: a) R,vR,vT,z,vz[,phi]: 1) floats: phase-space value for single object (phi is optional) (each can be a Quantity) 2) numpy.ndarray: [N] phase-space values for N objects (each can be a Quantity) b) Orbit instance: initial condition used if that's it, orbit(t) if there is a time given as well as the second argument c= (object-wide default, bool) True/False to override the object-wide setting for whether or not to use the C implementation OUTPUT: (e,zmax,rperi,rap) HISTORY: 2017-12-21 - Written - Bovy (UofT) """ if ((self._c and not ('c' in kwargs and not kwargs['c']))\ or (ext_loaded and (('c' in kwargs 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: self._parse_eval_args(*args) R= self._eval_R vR= self._eval_vR vT= self._eval_vT z= self._eval_z vz= self._eval_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]) rperi,Rap,zmax, err= actionAngleAdiabatic_c.actionAngleRperiRapZmaxAdiabatic_c(\ self._pot,self._gamma,R,vR,vT,z,vz) if err == 0: rap= nu.sqrt(Rap**2.+zmax**2.) ecc= (rap-rperi)/(rap+rperi) return (ecc,zmax,rperi,rap) else: #pragma: no cover raise RuntimeError("C-code for calculation actions failed; try with c=False") else: if 'c' in kwargs 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 kwargs.pop('c',None) if (len(args) == 5 or len(args) == 6) \ and isinstance(args[0],nu.ndarray): oecc= nu.zeros((len(args[0]))) orperi= nu.zeros((len(args[0]))) orap= nu.zeros((len(args[0]))) ozmax= 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]) tecc, tzmax, trperi,trap= self._EccZmaxRperiRap(\ *targs,**copy.copy(kwargs)) oecc[ii]= tecc ozmax[ii]= tzmax orperi[ii]= trperi orap[ii]= trap return (oecc,ozmax,orperi,orap) else: #Set up the actionAngleAxi object self._parse_eval_args(*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(self._eval_R) for p in self._pot] else: thisverticalpot= self._pot.toVertical(self._eval_R) aAAxi= actionAngleAxi(*args,pot=thispot, verticalPot=thisverticalpot, gamma=self._gamma) rperi,Rap= aAAxi.calcRapRperi(**kwargs) zmax= aAAxi.calczmax(**kwargs) rap= nu.sqrt(Rap**2.+zmax**2.) return ((rap-rperi)/(rap+rperi),zmax,rperi,rap)
def _EccZmaxRperiRap(self, *args, **kwargs): """ NAME: EccZmaxRperiRap (_EccZmaxRperiRap) PURPOSE: evaluate the eccentricity, maximum height above the plane, peri- and apocenter in the adiabatic approximation INPUT: Either: a) R,vR,vT,z,vz[,phi]: 1) floats: phase-space value for single object (phi is optional) (each can be a Quantity) 2) numpy.ndarray: [N] phase-space values for N objects (each can be a Quantity) b) Orbit instance: initial condition used if that's it, orbit(t) if there is a time given as well as the second argument c= (object-wide default, bool) True/False to override the object-wide setting for whether or not to use the C implementation OUTPUT: (e,zmax,rperi,rap) HISTORY: 2017-12-21 - Written - Bovy (UofT) """ if ((self._c and not ('c' in kwargs and not kwargs['c']))\ or (ext_loaded and (('c' in kwargs 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: self._parse_eval_args(*args) R = self._eval_R vR = self._eval_vR vT = self._eval_vT z = self._eval_z vz = self._eval_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]) rperi,Rap,zmax, err= actionAngleAdiabatic_c.actionAngleRperiRapZmaxAdiabatic_c(\ self._pot,self._gamma,R,vR,vT,z,vz) if err == 0: rap = nu.sqrt(Rap**2. + zmax**2.) ecc = (rap - rperi) / (rap + rperi) return (ecc, zmax, rperi, rap) else: #pragma: no cover raise RuntimeError( "C-code for calculation actions failed; try with c=False") else: if 'c' in kwargs 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 kwargs.pop('c', None) if (len(args) == 5 or len(args) == 6) \ and isinstance(args[0],nu.ndarray): oecc = nu.zeros((len(args[0]))) orperi = nu.zeros((len(args[0]))) orap = nu.zeros((len(args[0]))) ozmax = 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]) tecc, tzmax, trperi,trap= self._EccZmaxRperiRap(\ *targs,**copy.copy(kwargs)) oecc[ii] = tecc ozmax[ii] = tzmax orperi[ii] = trperi orap[ii] = trap return (oecc, ozmax, orperi, orap) else: #Set up the actionAngleAxi object self._parse_eval_args(*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(self._eval_R) for p in self._pot ] else: thisverticalpot = self._pot.toVertical(self._eval_R) aAAxi = actionAngleAxi(*args, pot=thispot, verticalPot=thisverticalpot, gamma=self._gamma) rperi, Rap = aAAxi.calcRapRperi(**kwargs) zmax = aAAxi.calczmax(**kwargs) rap = nu.sqrt(Rap**2. + zmax**2.) return ((rap - rperi) / (rap + rperi), zmax, rperi, rap)
def _evaluate(self,*args,**kwargs): """ NAME: __call__ (_evaluate) PURPOSE: evaluate the actions (jr,lz,jz) INPUT: Either: a) R,vR,vT,z,vz[,phi]: 1) floats: phase-space value for single object (phi is optional) (each can be a Quantity) 2) numpy.ndarray: [N] phase-space values for N objects (each can be a Quantity) b) Orbit instance: initial condition used if that's it, orbit(t) if there is a time given as well as the second argument fixed_quad= (False) if True, use n=10 fixed_quad integration scipy.integrate.quadrature or .fixed_quad keywords OUTPUT: (jr,lz,jz) HISTORY: 2013-12-28 - Written - Bovy (IAS) """ fixed_quad= kwargs.pop('fixed_quad',False) 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: self._parse_eval_args(*args) R= self._eval_R vR= self._eval_vR vT= self._eval_vT z= self._eval_z vz= self._eval_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= _evaluatePotentials(self._pot,R,z)\ +vR**2./2.+vT**2./2.+vz**2./2. L= nu.sqrt(L2) #Actions Jphi= Lz Jz= L-nu.fabs(Lz) #Jr requires some more work #Set up an actionAngleAxi object for EL and rap/rperi calculations axiR= nu.sqrt(R**2.+z**2.) axivT= L/axiR axivR= (R*vR+z*vz)/axiR Jr= [] for ii in range(len(axiR)): axiaA= actionAngleAxi(axiR[ii],axivR[ii],axivT[ii], pot=self._2dpot) (rperi,rap)= axiaA.calcRapRperi() EL= axiaA.calcEL() E, L= EL Jr.append(self._calc_jr(rperi,rap,E,L,fixed_quad,**kwargs)) return (nu.array(Jr),Jphi,Jz)
def _actionsFreqsAngles(self,*args,**kwargs): """ NAME: actionsFreqsAngles (_actionsFreqsAngles) PURPOSE: evaluate the actions, frequencies, and angles (jr,lz,jz,Omegar,Omegaphi,Omegaz,ar,ap,az) INPUT: Either: a) R,vR,vT,z,vz[,phi]: 1) floats: phase-space value for single object (phi is optional) (each can be a Quantity) 2) numpy.ndarray: [N] phase-space values for N objects (each can be a Quantity) b) Orbit instance: initial condition used if that's it, orbit(t) if there is a time given as well as the second argument fixed_quad= (False) if True, use n=10 fixed_quad integration scipy.integrate.quadrature or .fixed_quad keywords OUTPUT: (jr,lz,jz,Omegar,Omegaphi,Omegaz,ar,aphi,az) HISTORY: 2013-12-29 - Written - Bovy (IAS) """ fixed_quad= kwargs.pop('fixed_quad',False) if len(args) == 5: #R,vR.vT, z, vz pragma: no cover 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: self._parse_eval_args(*args) R= self._eval_R vR= self._eval_vR vT= self._eval_vT z= self._eval_z vz= self._eval_vz phi= self._eval_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: #pragma: no cover pass else: Lz= R*vT Lx= -z*vT Ly= z*vR-R*vz L2= Lx*Lx+Ly*Ly+Lz*Lz E= _evaluatePotentials(self._pot,R,z)+vR**2./2.+vT**2./2.+vz**2./2. L= nu.sqrt(L2) #Actions Jphi= Lz Jz= L-nu.fabs(Lz) #Jr requires some more work #Set up an actionAngleAxi object for EL and rap/rperi calculations axiR= nu.sqrt(R**2.+z**2.) axivT= L/axiR #these are really spherical coords, called axi bc they go in actionAngleAxi axivR= (R*vR+z*vz)/axiR axivz= (z*vR-R*vz)/axiR Jr= [] Or= [] Op= [] ar= [] az= [] #Calculate the longitude of the ascending node asc= self._calc_long_asc(z,R,axivz,phi,Lz,L) for ii in range(len(axiR)): axiaA= actionAngleAxi(axiR[ii],axivR[ii],axivT[ii], pot=self._2dpot) (rperi,rap)= axiaA.calcRapRperi() EL= axiaA.calcEL() E, L= EL Jr.append(self._calc_jr(rperi,rap,E,L,fixed_quad,**kwargs)) #Radial period Rmean= m.exp((m.log(rperi)+m.log(rap))/2.) if Jr[-1] < 10.**-9.: #Circular orbit Or.append(epifreq(self._pot,axiR[ii],use_physical=False)) Op.append(omegac(self._pot,axiR[ii],use_physical=False)) else: Or.append(self._calc_or(Rmean,rperi,rap,E,L,fixed_quad,**kwargs)) Op.append(self._calc_op(Or[-1],Rmean,rperi,rap,E,L,fixed_quad,**kwargs)) #Angles ar.append(self._calc_angler(Or[-1],axiR[ii],Rmean,rperi,rap, E,L,axivR[ii],fixed_quad,**kwargs)) az.append(self._calc_anglez(Or[-1],Op[-1],ar[-1], z[ii],axiR[ii], Rmean,rperi,rap,E,L,Lz[ii], axivR[ii],axivz[ii], fixed_quad,**kwargs)) Op= nu.array(Op) Oz= copy.copy(Op) Op[vT < 0.]*= -1. ap= copy.copy(asc) ar= nu.array(ar) az= nu.array(az) ap[vT < 0.]-= az[vT < 0.] ap[vT >= 0.]+= az[vT >= 0.] ar= ar % (2.*nu.pi) ap= ap % (2.*nu.pi) az= az % (2.*nu.pi) return (nu.array(Jr),Jphi,Jz,nu.array(Or),Op,Oz, ar,ap,az)
def _actionsFreqs(self,*args,**kwargs): """ NAME: actionsFreqs (_actionsFreqs) PURPOSE: evaluate the actions and frequencies (jr,lz,jz,Omegar,Omegaphi,Omegaz) INPUT: Either: a) R,vR,vT,z,vz[,phi]: 1) floats: phase-space value for single object (phi is optional) (each can be a Quantity) 2) numpy.ndarray: [N] phase-space values for N objects (each can be a Quantity) b) Orbit instance: initial condition used if that's it, orbit(t) if there is a time given as well as the second argument fixed_quad= (False) if True, use n=10 fixed_quad integration scipy.integrate.quadrature or .fixed_quad keywords OUTPUT: (jr,lz,jz,Omegar,Omegaphi,Omegaz) HISTORY: 2013-12-28 - Written - Bovy (IAS) """ fixed_quad= kwargs.pop('fixed_quad',False) 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: self._parse_eval_args(*args) R= self._eval_R vR= self._eval_vR vT= self._eval_vT z= self._eval_z vz= self._eval_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= _evaluatePotentials(self._pot,R,z)+vR**2./2.+vT**2./2.+vz**2./2. L= nu.sqrt(L2) #Actions Jphi= Lz Jz= L-nu.fabs(Lz) #Jr requires some more work #Set up an actionAngleAxi object for EL and rap/rperi calculations axiR= nu.sqrt(R**2.+z**2.) axivT= L/axiR axivR= (R*vR+z*vz)/axiR Jr= [] Or= [] Op= [] for ii in range(len(axiR)): axiaA= actionAngleAxi(axiR[ii],axivR[ii],axivT[ii], pot=self._2dpot) (rperi,rap)= axiaA.calcRapRperi() EL= axiaA.calcEL() E, L= EL Jr.append(self._calc_jr(rperi,rap,E,L,fixed_quad,**kwargs)) #Radial period if Jr[-1] < 10.**-9.: #Circular orbit Or.append(epifreq(self._pot,axiR[ii],use_physical=False)) Op.append(omegac(self._pot,axiR[ii],use_physical=False)) continue Rmean= m.exp((m.log(rperi)+m.log(rap))/2.) Or.append(self._calc_or(Rmean,rperi,rap,E,L,fixed_quad,**kwargs)) Op.append(self._calc_op(Or[-1],Rmean,rperi,rap,E,L,fixed_quad,**kwargs)) Op= nu.array(Op) Oz= copy.copy(Op) Op[vT < 0.]*= -1. return (nu.array(Jr),Jphi,Jz,nu.array(Or),Op,Oz)
def _evaluate(self, *args, **kwargs): """ NAME: _evaluate 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 ('c' in kwargs and not kwargs['c']))\ or (ext_loaded and (('c' in kwargs 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: self._parse_eval_args(*args) R = self._eval_R vR = self._eval_vR vT = self._eval_vT z = self._eval_z vz = self._eval_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 'c' in kwargs 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 kwargs.pop('c', None) 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 self._parse_eval_args(*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(self._eval_R) for p in self._pot ] else: thisverticalpot = self._pot.toVertical(self._eval_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 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 fixed_quad= (False) if True, use n=10 fixed_quad integration scipy.integrate.quadrature keywords OUTPUT: (jr,lz,jz,Omegar,Omegaphi,Omegaz) HISTORY: 2013-12-28 - Written - Bovy (IAS) """ fixed_quad = kwargs.pop('fixed_quad', False) 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 = evaluatePotentials( R, z, self._pot) + vR**2. / 2. + vT**2. / 2. + vz**2. / 2. L = nu.sqrt(L2) #Actions Jphi = Lz Jz = L - nu.fabs(Lz) #Jr requires some more work #Set up an actionAngleAxi object for EL and rap/rperi calculations axiR = nu.sqrt(R**2. + z**2.) axivT = L / axiR axivR = (R * vR + z * vz) / axiR Jr = [] Or = [] Op = [] for ii in range(len(axiR)): axiaA = actionAngleAxi(axiR[ii], axivR[ii], axivT[ii], pot=self._2dpot) (rperi, rap) = axiaA.calcRapRperi() EL = axiaA.calcEL() E, L = EL Jr.append(self._calc_jr(rperi, rap, E, L, fixed_quad, **kwargs)) #Radial period if Jr[-1] < 10.**-9.: #Circular orbit Or.append(epifreq(self._pot, axiR[ii])) Op.append(omegac(self._pot, axiR[ii])) continue Rmean = m.exp((m.log(rperi) + m.log(rap)) / 2.) Or.append( self._calc_or(Rmean, rperi, rap, E, L, fixed_quad, **kwargs)) Op.append( self._calc_op(Or[-1], Rmean, rperi, rap, E, L, fixed_quad, **kwargs)) Op = nu.array(Op) Oz = copy.copy(Op) Op[vT < 0.] *= -1. return (nu.array(Jr), Jphi, Jz, nu.array(Or), Op, Oz)