def __init__(self,
                 RZPot=None,rgrid=(numpy.log(0.01),numpy.log(20.),101),
                 zgrid=(0.,1.,101),logR=True,
                 interpPot=False,interpRforce=False,interpzforce=False,
                 interpDens=False,
                 interpvcirc=False,
                 interpdvcircdr=False,
                 interpepifreq=False,interpverticalfreq=False,
                 ro=None,vo=None,
                 use_c=False,enable_c=False,zsym=True,
                 numcores=None):
        """
        NAME:

           __init__

        PURPOSE:

           Initialize an interpRZPotential instance

        INPUT:

           RZPot - RZPotential to be interpolated

           rgrid - R grid to be given to linspace as in rs= linspace(*rgrid)

           zgrid - z grid to be given to linspace as in zs= linspace(*zgrid)

           logR - if True, rgrid is in the log of R so logrs= linspace(*rgrid)

           interpPot, interpRforce, interpzforce, interpDens,interpvcirc, interpepifreq, interpverticalfreq, interpdvcircdr= if True, interpolate these functions

           use_c= use C to speed up the calculation of the grid

           enable_c= enable use of C for interpolations

           zsym= if True (default), the potential is assumed to be symmetric around z=0 (so you can use, e.g.,  zgrid=(0.,1.,101)).

           numcores= if set to an integer, use this many cores (only used for vcirc, dvcircdR, epifreq, and verticalfreq; NOT NECESSARILY FASTER, TIME TO MAKE SURE)

           ro=, vo= distance and velocity scales for translation into internal units (default from configuration file)

        OUTPUT:

           instance

        HISTORY:

           2010-07-21 - Written - Bovy (NYU)

           2013-01-24 - Started with new implementation - Bovy (IAS)

        """
        if isinstance(RZPot,interpRZPotential):
            from galpy.potential import PotentialError
            raise PotentialError('Cannot setup interpRZPotential with another interpRZPotential')
        # Propagate ro and vo
        roSet= True
        voSet= True
        if ro is None:
            if isinstance(RZPot,list):
                ro= RZPot[0]._ro
                roSet= RZPot[0]._roSet
            else:
                ro= RZPot._ro
                roSet= RZPot._roSet
        if vo is None:
            if isinstance(RZPot,list):
                vo= RZPot[0]._vo
                voSet= RZPot[0]._voSet
            else:
                vo= RZPot._vo
                voSet= RZPot._voSet
        Potential.__init__(self,amp=1.,ro=ro,vo=vo)
        # Turn off physical if it hadn't been on
        if not roSet: self._roSet= False
        if not voSet: self._voSet= False
        self._origPot= RZPot
        self._rgrid= numpy.linspace(*rgrid)
        self._logR= logR
        if self._logR:
            self._rgrid= numpy.exp(self._rgrid)
            self._logrgrid= numpy.log(self._rgrid)
        self._zgrid= numpy.linspace(*zgrid)
        self._interpPot= interpPot
        self._interpRforce= interpRforce
        self._interpzforce= interpzforce
        self._interpDens= interpDens
        self._interpvcirc= interpvcirc
        self._interpdvcircdr= interpdvcircdr
        self._interpepifreq= interpepifreq
        self._interpverticalfreq= interpverticalfreq
        self._enable_c= enable_c*ext_loaded
        self.hasC= self._enable_c
        self._zsym= zsym
        if interpPot:
            if use_c*ext_loaded:
                self._potGrid, err= calc_potential_c(self._origPot,self._rgrid,self._zgrid)
            else:
                from galpy.potential import evaluatePotentials
                potGrid= numpy.zeros((len(self._rgrid),len(self._zgrid)))
                for ii in range(len(self._rgrid)):
                    for jj in range(len(self._zgrid)):
                        potGrid[ii,jj]= evaluatePotentials(self._origPot,self._rgrid[ii],self._zgrid[jj])
                self._potGrid= potGrid
            if self._logR:
                self._potInterp= interpolate.RectBivariateSpline(self._logrgrid,
                                                                 self._zgrid,
                                                                 self._potGrid,
                                                                 kx=3,ky=3,s=0.)
            else:
                self._potInterp= interpolate.RectBivariateSpline(self._rgrid,
                                                                 self._zgrid,
                                                                 self._potGrid,
                                                                 kx=3,ky=3,s=0.)
            if enable_c*ext_loaded:
                self._potGrid_splinecoeffs= calc_2dsplinecoeffs_c(self._potGrid)
        if interpRforce:
            if use_c*ext_loaded:
                self._rforceGrid, err= calc_potential_c(self._origPot,self._rgrid,self._zgrid,rforce=True)
            else:
                from galpy.potential import evaluateRforces
                rforceGrid= numpy.zeros((len(self._rgrid),len(self._zgrid)))
                for ii in range(len(self._rgrid)):
                    for jj in range(len(self._zgrid)):
                        rforceGrid[ii,jj]= evaluateRforces(self._origPot,self._rgrid[ii],self._zgrid[jj])
                self._rforceGrid= rforceGrid
            if self._logR:
                self._rforceInterp= interpolate.RectBivariateSpline(self._logrgrid,
                                                                    self._zgrid,
                                                                    self._rforceGrid,
                                                                    kx=3,ky=3,s=0.)
            else:
                self._rforceInterp= interpolate.RectBivariateSpline(self._rgrid,
                                                                    self._zgrid,
                                                                    self._rforceGrid,
                                                                    kx=3,ky=3,s=0.)
            if enable_c*ext_loaded:
                self._rforceGrid_splinecoeffs= calc_2dsplinecoeffs_c(self._rforceGrid)
        if interpzforce:
            if use_c*ext_loaded:
                self._zforceGrid, err= calc_potential_c(self._origPot,self._rgrid,self._zgrid,zforce=True)
            else:
                from galpy.potential import evaluatezforces
                zforceGrid= numpy.zeros((len(self._rgrid),len(self._zgrid)))
                for ii in range(len(self._rgrid)):
                    for jj in range(len(self._zgrid)):
                        zforceGrid[ii,jj]= evaluatezforces(self._origPot,self._rgrid[ii],self._zgrid[jj])
                self._zforceGrid= zforceGrid
            if self._logR:
                self._zforceInterp= interpolate.RectBivariateSpline(self._logrgrid,
                                                                    self._zgrid,
                                                                    self._zforceGrid,
                                                                    kx=3,ky=3,s=0.)
            else:
                self._zforceInterp= interpolate.RectBivariateSpline(self._rgrid,
                                                                    self._zgrid,
                                                                    self._zforceGrid,
                                                                    kx=3,ky=3,s=0.)
            if enable_c*ext_loaded:
                self._zforceGrid_splinecoeffs= calc_2dsplinecoeffs_c(self._zforceGrid)
        if interpDens:
            from galpy.potential import evaluateDensities
            densGrid= numpy.zeros((len(self._rgrid),len(self._zgrid)))
            for ii in range(len(self._rgrid)):
                for jj in range(len(self._zgrid)):
                    densGrid[ii,jj]= evaluateDensities(self._origPot,self._rgrid[ii],self._zgrid[jj])
            self._densGrid= densGrid
            if self._logR:
                self._densInterp= interpolate.RectBivariateSpline(self._logrgrid,
                                                                  self._zgrid,
                                                                  numpy.log(self._densGrid+10.**-10.),
                                                                  kx=3,ky=3,s=0.)
            else:
                self._densInterp= interpolate.RectBivariateSpline(self._rgrid,
                                                                  self._zgrid,
                                                                  numpy.log(self._densGrid+10.**-10.),
                                                                  kx=3,ky=3,s=0.)
        if interpvcirc:
            from galpy.potential import vcirc
            if not numcores is None:
                self._vcircGrid= multi.parallel_map((lambda x: vcirc(self._origPot,self._rgrid[x])),
                                                    list(range(len(self._rgrid))),numcores=numcores)
            else:
                self._vcircGrid= numpy.array([vcirc(self._origPot,r) for r in self._rgrid])
            if self._logR:
                self._vcircInterp= interpolate.InterpolatedUnivariateSpline(self._logrgrid,self._vcircGrid,k=3)
            else:
                self._vcircInterp= interpolate.InterpolatedUnivariateSpline(self._rgrid,self._vcircGrid,k=3)
        if interpdvcircdr:
            from galpy.potential import dvcircdR
            if not numcores is None:
                self._dvcircdrGrid= multi.parallel_map((lambda x: dvcircdR(self._origPot,self._rgrid[x])),
                                                       list(range(len(self._rgrid))),numcores=numcores)
            else:
                self._dvcircdrGrid= numpy.array([dvcircdR(self._origPot,r) for r in self._rgrid])
            if self._logR:
                self._dvcircdrInterp= interpolate.InterpolatedUnivariateSpline(self._logrgrid,self._dvcircdrGrid,k=3)
            else:
                self._dvcircdrInterp= interpolate.InterpolatedUnivariateSpline(self._rgrid,self._dvcircdrGrid,k=3)
        if interpepifreq:
            from galpy.potential import epifreq
            if not numcores is None:
                self._epifreqGrid= numpy.array(multi.parallel_map((lambda x: epifreq(self._origPot,self._rgrid[x])),
                                                      list(range(len(self._rgrid))),numcores=numcores))
            else:
                self._epifreqGrid= numpy.array([epifreq(self._origPot,r) for r in self._rgrid])
            indx= True^numpy.isnan(self._epifreqGrid)
            if numpy.sum(indx) < 4:
                if self._logR:
                    self._epifreqInterp= interpolate.InterpolatedUnivariateSpline(self._logrgrid[indx],self._epifreqGrid[indx],k=1)
                else:
                    self._epifreqInterp= interpolate.InterpolatedUnivariateSpline(self._rgrid[indx],self._epifreqGrid[indx],k=1)
            else:
                if self._logR:
                    self._epifreqInterp= interpolate.InterpolatedUnivariateSpline(self._logrgrid[indx],self._epifreqGrid[indx],k=3)
                else:
                    self._epifreqInterp= interpolate.InterpolatedUnivariateSpline(self._rgrid[indx],self._epifreqGrid[indx],k=3)
        if interpverticalfreq:
            from galpy.potential import verticalfreq
            if not numcores is None:
                self._verticalfreqGrid= multi.parallel_map((lambda x: verticalfreq(self._origPot,self._rgrid[x])),
                                                       list(range(len(self._rgrid))),numcores=numcores)
            else:
                self._verticalfreqGrid= numpy.array([verticalfreq(self._origPot,r) for r in self._rgrid])
            if self._logR:
                self._verticalfreqInterp= interpolate.InterpolatedUnivariateSpline(self._logrgrid,self._verticalfreqGrid,k=3)
            else:
                self._verticalfreqInterp= interpolate.InterpolatedUnivariateSpline(self._rgrid,self._verticalfreqGrid,k=3)
        return None
def __init__ ( self , RZPot = None , rgrid = ( numpy . log ( 0.01 ) , numpy . log ( 20. ) , 101 ) , zgrid = ( 0. , 1. , 101 ) , logR = True , interpPot = False , interpRforce = False , interpzforce = False , interpDens = False , interpvcirc = False , interpdvcircdr = False , interpepifreq = False , interpverticalfreq = False , ro = None , vo = None , use_c = False , enable_c = False , zsym = True , numcores = None ) : if isinstance ( RZPot , interpRZPotential ) : from galpy . potential import PotentialError raise PotentialError ( 'Cannot setup interpRZPotential with another interpRZPotential' ) roSet = True voSet = True if ro is None : if isinstance ( RZPot , list ) : ro = RZPot [ 0 ] . _ro roSet = RZPot [ 0 ] . _roSet else : ro = RZPot . _ro roSet = RZPot . _roSet if vo is None : if isinstance ( RZPot , list ) : vo = RZPot [ 0 ] . _vo voSet = RZPot [ 0 ] . _voSet else : vo = RZPot . _vo voSet = RZPot . _voSet Potential . __init__ ( self , amp = 1. , ro = ro , vo = vo ) if not roSet : self . _roSet = False if not voSet : self . _voSet = False self . _origPot = RZPot self . _rgrid = numpy . linspace ( * rgrid ) self . _logR = logR if self . _logR : self . _rgrid = numpy . exp ( self . _rgrid ) self . _logrgrid = numpy . log ( self . _rgrid ) self . _zgrid = numpy . linspace ( * zgrid ) self . _interpPot = interpPot self . _interpRforce = interpRforce self . _interpzforce = interpzforce self . _interpDens = interpDens self . _interpvcirc = interpvcirc self . _interpdvcircdr = interpdvcircdr self . _interpepifreq = interpepifreq self . _interpverticalfreq = interpverticalfreq self . _enable_c = enable_c * ext_loaded self . hasC = self . _enable_c self . _zsym = zsym if interpPot : if use_c * ext_loaded : self . _potGrid , err = calc_potential_c ( self . _origPot , self . _rgrid , self . _zgrid ) else : from galpy . potential import evaluatePotentials potGrid = numpy . zeros ( ( len ( self . _rgrid ) , len ( self . _zgrid ) ) ) for ii in range ( len ( self . _rgrid ) ) : for jj in range ( len ( self . _zgrid ) ) : potGrid [ ii , jj ] = evaluatePotentials ( self . _origPot , self . _rgrid [ ii ] , self . _zgrid [ jj ] ) self . _potGrid = potGrid if self . _logR : self . _potInterp = interpolate . RectBivariateSpline ( self . _logrgrid , self . _zgrid , self . _potGrid , kx = 3 , ky = 3 , s = 0. ) else : self . _potInterp = interpolate . RectBivariateSpline ( self . _rgrid , self . _zgrid , self . _potGrid , kx = 3 , ky = 3 , s = 0. ) if enable_c * ext_loaded : self . _potGrid_splinecoeffs = calc_2dsplinecoeffs_c ( self . _potGrid ) if interpRforce : if use_c * ext_loaded : self . _rforceGrid , err = calc_potential_c ( self . _origPot , self . _rgrid , self . _zgrid , rforce = True ) else : from galpy . potential import evaluateRforces rforceGrid = numpy . zeros ( ( len ( self . _rgrid ) , len ( self . _zgrid ) ) ) for ii in range ( len ( self . _rgrid ) ) : for jj in range ( len ( self . _zgrid ) ) : rforceGrid [ ii , jj ] = evaluateRforces ( self . _origPot , self . _rgrid [ ii ] , self . _zgrid [ jj ] ) self . _rforceGrid = rforceGrid if self . _logR : self . _rforceInterp = interpolate . RectBivariateSpline ( self . _logrgrid , self . _zgrid , self . _rforceGrid , kx = 3 , ky = 3 , s = 0. ) else : self . _rforceInterp = interpolate . RectBivariateSpline ( self . _rgrid , self . _zgrid , self . _rforceGrid , kx = 3 , ky = 3 , s = 0. ) if enable_c * ext_loaded : self . _rforceGrid_splinecoeffs = calc_2dsplinecoeffs_c ( self . _rforceGrid ) if interpzforce : if use_c * ext_loaded : self . _zforceGrid , err = calc_potential_c ( self . _origPot , self . _rgrid , self . _zgrid , zforce = True ) else : from galpy . potential import evaluatezforces zforceGrid = numpy . zeros ( ( len ( self . _rgrid ) , len ( self . _zgrid ) ) ) for ii in range ( len ( self . _rgrid ) ) : for jj in range ( len ( self . _zgrid ) ) : zforceGrid [ ii , jj ] = evaluatezforces ( self . _origPot , self . _rgrid [ ii ] , self . _zgrid [ jj ] ) self . _zforceGrid = zforceGrid if self . _logR : self . _zforceInterp = interpolate . RectBivariateSpline ( self . _logrgrid , self . _zgrid , self . _zforceGrid , kx = 3 , ky = 3 , s = 0. ) else : self . _zforceInterp = interpolate . RectBivariateSpline ( self . _rgrid , self . _zgrid , self . _zforceGrid , kx = 3 , ky = 3 , s = 0. ) if enable_c * ext_loaded : self . _zforceGrid_splinecoeffs = calc_2dsplinecoeffs_c ( self . _zforceGrid ) if interpDens : from galpy . potential import evaluateDensities densGrid = numpy . zeros ( ( len ( self . _rgrid ) , len ( self . _zgrid ) ) ) for ii in range ( len ( self . _rgrid ) ) : for jj in range ( len ( self . _zgrid ) ) : densGrid [ ii , jj ] = evaluateDensities ( self . _origPot , self . _rgrid [ ii ] , self . _zgrid [ jj ] ) self . _densGrid = densGrid if self . _logR : self . _densInterp = interpolate . RectBivariateSpline ( self . _logrgrid , self . _zgrid , numpy . log ( self . _densGrid + 10. ** - 10. ) , kx = 3 , ky = 3 , s = 0. ) else : self . _densInterp = interpolate . RectBivariateSpline ( self . _rgrid , self . _zgrid , numpy . log ( self . _densGrid + 10. ** - 10. ) , kx = 3 , ky = 3 , s = 0. ) if interpvcirc : from galpy . potential import vcirc if not numcores is None : self . _vcircGrid = multi . parallel_map ( ( lambda x : vcirc ( self . _origPot , self . _rgrid [ x ] ) ) , list ( range ( len ( self . _rgrid ) ) ) , numcores = numcores ) else : self . _vcircGrid = numpy . array ( [ vcirc ( self . _origPot , r ) for r in self . _rgrid ] ) if self . _logR : self . _vcircInterp = interpolate . InterpolatedUnivariateSpline ( self . _logrgrid , self . _vcircGrid , k = 3 ) else : self . _vcircInterp = interpolate . InterpolatedUnivariateSpline ( self . _rgrid , self . _vcircGrid , k = 3 ) if interpdvcircdr : from galpy . potential import dvcircdR if not numcores is None : self . _dvcircdrGrid = multi . parallel_map ( ( lambda x : dvcircdR ( self . _origPot , self . _rgrid [ x ] ) ) , list ( range ( len ( self . _rgrid ) ) ) , numcores = numcores ) else : self . _dvcircdrGrid = numpy . array ( [ dvcircdR ( self . _origPot , r ) for r in self . _rgrid ] ) if self . _logR : self . _dvcircdrInterp = interpolate . InterpolatedUnivariateSpline ( self . _logrgrid , self . _dvcircdrGrid , k = 3 ) else : self . _dvcircdrInterp = interpolate . InterpolatedUnivariateSpline ( self . _rgrid , self . _dvcircdrGrid , k = 3 ) if interpepifreq : from galpy . potential import epifreq if not numcores is None : self . _epifreqGrid = numpy . array ( multi . parallel_map ( ( lambda x : epifreq ( self . _origPot , self . _rgrid [ x ] ) ) , list ( range ( len ( self . _rgrid ) ) ) , numcores = numcores ) ) else : self . _epifreqGrid = numpy . array ( [ epifreq ( self . _origPot , r ) for r in self . _rgrid ] ) indx = True ^ numpy . isnan ( self . _epifreqGrid ) if numpy . sum ( indx ) < 4 : if self . _logR : self . _epifreqInterp = interpolate . InterpolatedUnivariateSpline ( self . _logrgrid [ indx ] , self . _epifreqGrid [ indx ] , k = 1 ) else : self . _epifreqInterp = interpolate . InterpolatedUnivariateSpline ( self . _rgrid [ indx ] , self . _epifreqGrid [ indx ] , k = 1 ) else : if self . _logR : self . _epifreqInterp = interpolate . InterpolatedUnivariateSpline ( self . _logrgrid [ indx ] , self . _epifreqGrid [ indx ] , k = 3 ) else : self . _epifreqInterp = interpolate . InterpolatedUnivariateSpline ( self . _rgrid [ indx ] , self . _epifreqGrid [ indx ] , k = 3 ) if interpverticalfreq : from galpy . potential import verticalfreq if not numcores is None : self . _verticalfreqGrid = multi . parallel_map ( ( lambda x : verticalfreq ( self . _origPot , self . _rgrid [ x ] ) ) , list ( range ( len ( self . _rgrid ) ) ) , numcores = numcores ) else : self . _verticalfreqGrid = numpy . array ( [ verticalfreq ( self . _origPot , r ) for r in self . _rgrid ] ) if self . _logR : self . _verticalfreqInterp = interpolate . InterpolatedUnivariateSpline ( self . _logrgrid , self . _verticalfreqGrid , k = 3 ) else : self . _verticalfreqInterp = interpolate . InterpolatedUnivariateSpline ( self . _rgrid , self . _verticalfreqGrid , k = 3 ) return None
NAME:

           __init__

        PURPOSE:

           Initialize an interpRZPotential instance

        INPUT:

           RZPot - RZPotential to be interpolated

           rgrid - R grid to be given to linspace as in rs= linspace(*rgrid)

           zgrid - z grid to be given to linspace as in zs= linspace(*zgrid)

           logR - if True, rgrid is in the log of R so logrs= linspace(*rgrid)

           interpPot, interpRforce, interpzforce, interpDens,interpvcirc, interpepifreq, interpverticalfreq, interpdvcircdr= if True, interpolate these functions

           use_c= use C to speed up the calculation of the grid

           enable_c= enable use of C for interpolations

           zsym= if True (default), the potential is assumed to be symmetric around z=0 (so you can use, e.g.,  zgrid=(0.,1.,101)).

           numcores= if set to an integer, use this many cores (only used for vcirc, dvcircdR, epifreq, and verticalfreq; NOT NECESSARILY FASTER, TIME TO MAKE SURE)

           ro=, vo= distance and velocity scales for translation into internal units (default from configuration file)

        OUTPUT:

           instance

        HISTORY:

           2010-07-21 - Written - Bovy (NYU)

           2013-01-24 - Started with new implementation - Bovy (IAS)