code: def toVerticalPotential(Pot,R,phi=None):
      
      Pot= flatten(Pot)
      if _APY_LOADED:
          if isinstance(R,units.Quantity):
              if hasattr(Pot,'_ro'):
                  R= R.to(units.kpc).value/Pot._ro
              else:
                  R= R.to(units.kpc).value/Pot[0]._ro
          if isinstance(phi,units.Quantity):
              phi= phi.to(units.rad).value
      if isinstance(Pot,list):
          out= []
          for pot in Pot:
              if isinstance(pot,linearPotential):
                  out.append(pot)
              elif isinstance(pot,Potential):
                  out.append(verticalPotential(pot,R,phi=phi))
              elif isinstance(pot,planarPotential):
                  raise PotentialError("Input to 'toVerticalPotential' cannot be a planarPotential")
              else:
                  raise PotentialError("Input to 'toVerticalPotential' is neither an RZPotential-instance or a list of such instances")
          return out
      elif isinstance(Pot,Potential):
          return verticalPotential(Pot,R,phi=phi)
      elif isinstance(Pot,linearPotential):
          return Pot
      elif isinstance(Pot,planarPotential):
          raise PotentialError("Input to 'toVerticalPotential' cannot be a planarPotential")
      else:
          raise PotentialError("Input to 'toVerticalPotential' is neither an Potential-instance or a list of such instances")
docs: NAME:
  
         toVerticalPotential
  
      PURPOSE:
  
         convert a Potential to a vertical potential at a given R
  
      INPUT:
  
         Pot - Potential instance or list of such instances
  
         R - Galactocentric radius at which to evaluate the vertical potential (can be Quantity)
  
         phi= (None) Galactocentric azimuth at which to evaluate the vertical potential (can be Quantity); required if Pot is non-axisymmetric
  
      OUTPUT:
  
         (list of) linearPotential instance(s)
  
      HISTORY:
  
         2018-10-07 - Written - Bovy (UofT)