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 HISTORY: 2012-07-30 - Written - Bovy (IAS@MPIA) """ meta = actionAngle(*args) Phi = galpy.potential.evaluatePotentials(meta._R, meta._z, self._pot) Phio = galpy.potential.evaluatePotentials(meta._R, 0.0, self._pot) Ez = Phi - Phio + meta._vz ** 2.0 / 2.0 # Bigger than Ezzmax? thisEzZmax = numpy.exp(self._EzZmaxsInterp(meta._R)) if ( meta._R > self._Rmax or meta._R < self._Rmin or (Ez != 0.0 and numpy.log(Ez) > thisEzZmax) ): # Outside of the grid if _PRINTOUTSIDEGRID: print "Outside of grid in Ez" jz = self._aA.Jz(meta._R, 0.0, 1.0, 0.0, math.sqrt(2.0 * Ez), **kwargs)[0] # these two r dummies else: jz = (self._jzInterp(meta._R, Ez / thisEzZmax) * (numpy.exp(self._jzEzmaxInterp(meta._R)) - 10.0 ** -5.0))[ 0 ][0] return jz
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 HISTORY: 2012-07-30 - Written - Bovy (IAS@MPIA) """ meta = actionAngle(*args) Phi = galpy.potential.evaluatePotentials(meta._R, meta._z, self._pot) Phio = galpy.potential.evaluatePotentials(meta._R, 0., self._pot) Ez = Phi - Phio + meta._vz**2. / 2. #Bigger than Ezzmax? thisEzZmax = numpy.exp(self._EzZmaxsInterp(meta._R)) if meta._R > self._Rmax or meta._R < self._Rmin or ( Ez != 0. and numpy.log(Ez) > thisEzZmax): #Outside of the grid if _PRINTOUTSIDEGRID: print "Outside of grid in Ez" jz = self._aA.Jz( meta._R, 0., 1., #these two r dummies 0., math.sqrt(2. * Ez), **kwargs)[0] else: jz= (self._jzInterp(meta._R,Ez/thisEzZmax)\ *(numpy.exp(self._jzEzmaxInterp(meta._R))-10.**-5.))[0][0] return jz
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: 2012-07-27 - Written - Bovy (IAS@MPIA) NOTE: For a Miyamoto-Nagai potential, this seems accurate to 0.1% and takes ~0.13 ms For a MWPotential, this takes ~ 0.17 ms """ 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 #First work on the vertical action Phi = galpy.potential.evaluatePotentials(R, z, self._pot) Phio = galpy.potential.evaluatePotentials(R, 0., self._pot) Ez = Phi - Phio + vz**2. / 2. #Bigger than Ezzmax? thisEzZmax = numpy.exp(self._EzZmaxsInterp(R)) if isinstance(R, numpy.ndarray): indx = (R > self._Rmax) indx += (R < self._Rmin) indx += (Ez != 0.) * (numpy.log(Ez) > thisEzZmax) indxc = True - indx jz = numpy.empty(R.shape) if numpy.sum(indxc) > 0: jz[indxc]= (self._jzInterp.ev(R[indxc],Ez[indxc]/thisEzZmax[indxc])\ *(numpy.exp(self._jzEzmaxInterp(R[indxc]))-10.**-5.)) if numpy.sum(indx) > 0: jzindiv = numpy.empty(numpy.sum(indx)) for ii in range(numpy.sum(indx)): try: jzindiv[ii] = self._aA.Jz( R[indx][ii], 0., 1., #these two r dummies 0., numpy.sqrt(2. * Ez[indx][ii]), **kwargs)[0] except UnboundError: jzindiv[ii] = numpy.nan jz[indx] = jzindiv else: if R > self._Rmax or R < self._Rmin or ( Ez != 0 and numpy.log(Ez) > thisEzZmax): #Outside of the grid if _PRINTOUTSIDEGRID: print "Outside of grid in Ez", R > self._Rmax, R < self._Rmin, ( Ez != 0 and numpy.log(Ez) > thisEzZmax) jz = self._aA.Jz( R, 0., 1., #these two r dummies 0., math.sqrt(2. * Ez), **kwargs)[0] else: jz= (self._jzInterp(R,Ez/thisEzZmax)\ *(numpy.exp(self._jzEzmaxInterp(R))-10.**-5.))[0][0] #Radial action ERLz = numpy.fabs(R * vT) + self._gamma * jz ER = Phio + vR**2. / 2. + ERLz**2. / 2. / R**2. thisRL = self._RLInterp(ERLz) thisERRL = -numpy.exp(self._ERRLInterp(ERLz)) + self._ERRLmax thisERRa = -numpy.exp(self._ERRaInterp(ERLz)) + self._ERRamax if isinstance(R, numpy.ndarray): indx= ((ER-thisERRa)/(thisERRL-thisERRa) > 1.)\ *(((ER-thisERRa)/(thisERRL-thisERRa)-1.) < 10.**-2.) ER[indx] = thisERRL[indx] indx= ((ER-thisERRa)/(thisERRL-thisERRa) < 0.)\ *((ER-thisERRa)/(thisERRL-thisERRa) > -10.**-2.) ER[indx] = thisERRa[indx] indx = (ERLz < self._Lzmin) indx += (ERLz > self._Lzmax) indx += ((ER - thisERRa) / (thisERRL - thisERRa) > 1.) indx += ((ER - thisERRa) / (thisERRL - thisERRa) < 0.) indxc = True - indx jr = numpy.empty(R.shape) if numpy.sum(indxc) > 0: jr[indxc]= (self._jrInterp.ev(ERLz[indxc], (ER[indxc]-thisERRa[indxc])/(thisERRL[indxc]-thisERRa[indxc]))\ *(numpy.exp(self._jrERRaInterp(ERLz[indxc]))-10.**-5.)) if numpy.sum(indx) > 0: jrindiv = numpy.empty(numpy.sum(indx)) for ii in range(numpy.sum(indx)): try: jrindiv[ii] = self._aA.JR( thisRL[indx][ii], numpy.sqrt(2. * (ER[indx][ii] - galpy.potential.evaluatePotentials( thisRL[indx][ii], 0., self._pot)) - ERLz[indx][ii]**2. / thisRL[indx][ii]**2.), ERLz[indx][ii] / thisRL[indx][ii], 0., 0., **kwargs)[0] except (UnboundError, OverflowError): jrindiv[ii] = numpy.nan jr[indx] = jrindiv else: if (ER-thisERRa)/(thisERRL-thisERRa) > 1. \ and ((ER-thisERRa)/(thisERRL-thisERRa)-1.) < 10.**-2.: ER = thisERRL elif (ER-thisERRa)/(thisERRL-thisERRa) < 0. \ and (ER-thisERRa)/(thisERRL-thisERRa) > -10.**-2.: ER = thisERRa #Outside of grid? if ERLz < self._Lzmin or ERLz > self._Lzmax \ or (ER-thisERRa)/(thisERRL-thisERRa) > 1. \ or (ER-thisERRa)/(thisERRL-thisERRa) < 0.: if _PRINTOUTSIDEGRID: print "Outside of grid in ER/Lz", ERLz < self._Lzmin , ERLz > self._Lzmax \ , (ER-thisERRa)/(thisERRL-thisERRa) > 1. \ , (ER-thisERRa)/(thisERRL-thisERRa) < 0., ER, thisERRL, thisERRa, (ER-thisERRa)/(thisERRL-thisERRa) jr = self._aA.JR( thisRL, numpy.sqrt(2. * (ER - galpy.potential.evaluatePotentials( thisRL, 0., self._pot)) - ERLz**2. / thisRL**2.), ERLz / thisRL, 0., 0., **kwargs)[0] else: jr= (self._jrInterp(ERLz, (ER-thisERRa)/(thisERRL-thisERRa))\ *(numpy.exp(self._jrERRaInterp(ERLz))-10.**-5.))[0][0] return (jr, R * vT, jz)
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: 2012-07-27 - Written - Bovy (IAS@MPIA) NOTE: For a Miyamoto-Nagai potential, this seems accurate to 0.1% and takes ~0.13 ms For a MWPotential, this takes ~ 0.17 ms """ 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 # First work on the vertical action Phi = galpy.potential.evaluatePotentials(R, z, self._pot) Phio = galpy.potential.evaluatePotentials(R, 0.0, self._pot) Ez = Phi - Phio + vz ** 2.0 / 2.0 # Bigger than Ezzmax? thisEzZmax = numpy.exp(self._EzZmaxsInterp(R)) if isinstance(R, numpy.ndarray): indx = R > self._Rmax indx += R < self._Rmin indx += (Ez != 0.0) * (numpy.log(Ez) > thisEzZmax) indxc = True - indx jz = numpy.empty(R.shape) if numpy.sum(indxc) > 0: jz[indxc] = self._jzInterp.ev(R[indxc], Ez[indxc] / thisEzZmax[indxc]) * ( numpy.exp(self._jzEzmaxInterp(R[indxc])) - 10.0 ** -5.0 ) if numpy.sum(indx) > 0: jzindiv = numpy.empty(numpy.sum(indx)) for ii in range(numpy.sum(indx)): try: jzindiv[ii] = self._aA.Jz( R[indx][ii], 0.0, 1.0, 0.0, numpy.sqrt(2.0 * Ez[indx][ii]), **kwargs # these two r dummies )[0] except UnboundError: jzindiv[ii] = numpy.nan jz[indx] = jzindiv else: if R > self._Rmax or R < self._Rmin or (Ez != 0 and numpy.log(Ez) > thisEzZmax): # Outside of the grid if _PRINTOUTSIDEGRID: print "Outside of grid in Ez", R > self._Rmax, R < self._Rmin, ( Ez != 0 and numpy.log(Ez) > thisEzZmax ) jz = self._aA.Jz(R, 0.0, 1.0, 0.0, math.sqrt(2.0 * Ez), **kwargs)[0] # these two r dummies else: jz = (self._jzInterp(R, Ez / thisEzZmax) * (numpy.exp(self._jzEzmaxInterp(R)) - 10.0 ** -5.0))[0][0] # Radial action ERLz = numpy.fabs(R * vT) + self._gamma * jz ER = Phio + vR ** 2.0 / 2.0 + ERLz ** 2.0 / 2.0 / R ** 2.0 thisRL = self._RLInterp(ERLz) thisERRL = -numpy.exp(self._ERRLInterp(ERLz)) + self._ERRLmax thisERRa = -numpy.exp(self._ERRaInterp(ERLz)) + self._ERRamax if isinstance(R, numpy.ndarray): indx = ((ER - thisERRa) / (thisERRL - thisERRa) > 1.0) * ( ((ER - thisERRa) / (thisERRL - thisERRa) - 1.0) < 10.0 ** -2.0 ) ER[indx] = thisERRL[indx] indx = ((ER - thisERRa) / (thisERRL - thisERRa) < 0.0) * ( (ER - thisERRa) / (thisERRL - thisERRa) > -10.0 ** -2.0 ) ER[indx] = thisERRa[indx] indx = ERLz < self._Lzmin indx += ERLz > self._Lzmax indx += (ER - thisERRa) / (thisERRL - thisERRa) > 1.0 indx += (ER - thisERRa) / (thisERRL - thisERRa) < 0.0 indxc = True - indx jr = numpy.empty(R.shape) if numpy.sum(indxc) > 0: jr[indxc] = self._jrInterp.ev( ERLz[indxc], (ER[indxc] - thisERRa[indxc]) / (thisERRL[indxc] - thisERRa[indxc]) ) * (numpy.exp(self._jrERRaInterp(ERLz[indxc])) - 10.0 ** -5.0) if numpy.sum(indx) > 0: jrindiv = numpy.empty(numpy.sum(indx)) for ii in range(numpy.sum(indx)): try: jrindiv[ii] = self._aA.JR( thisRL[indx][ii], numpy.sqrt( 2.0 * (ER[indx][ii] - galpy.potential.evaluatePotentials(thisRL[indx][ii], 0.0, self._pot)) - ERLz[indx][ii] ** 2.0 / thisRL[indx][ii] ** 2.0 ), ERLz[indx][ii] / thisRL[indx][ii], 0.0, 0.0, **kwargs )[0] except (UnboundError, OverflowError): jrindiv[ii] = numpy.nan jr[indx] = jrindiv else: if (ER - thisERRa) / (thisERRL - thisERRa) > 1.0 and ( (ER - thisERRa) / (thisERRL - thisERRa) - 1.0 ) < 10.0 ** -2.0: ER = thisERRL elif (ER - thisERRa) / (thisERRL - thisERRa) < 0.0 and (ER - thisERRa) / ( thisERRL - thisERRa ) > -10.0 ** -2.0: ER = thisERRa # Outside of grid? if ( ERLz < self._Lzmin or ERLz > self._Lzmax or (ER - thisERRa) / (thisERRL - thisERRa) > 1.0 or (ER - thisERRa) / (thisERRL - thisERRa) < 0.0 ): if _PRINTOUTSIDEGRID: print "Outside of grid in ER/Lz", ERLz < self._Lzmin, ERLz > self._Lzmax, (ER - thisERRa) / ( thisERRL - thisERRa ) > 1.0, (ER - thisERRa) / (thisERRL - thisERRa) < 0.0, ER, thisERRL, thisERRa, (ER - thisERRa) / ( thisERRL - thisERRa ) jr = self._aA.JR( thisRL, numpy.sqrt( 2.0 * (ER - galpy.potential.evaluatePotentials(thisRL, 0.0, self._pot)) - ERLz ** 2.0 / thisRL ** 2.0 ), ERLz / thisRL, 0.0, 0.0, **kwargs )[0] else: jr = ( self._jrInterp(ERLz, (ER - thisERRa) / (thisERRL - thisERRa)) * (numpy.exp(self._jrERRaInterp(ERLz)) - 10.0 ** -5.0) )[0][0] return (jr, R * vT, jz)