docstr: Invert the velocity if the particle is out of bounds
  
  The velocity is inverted and shrinked. The shrinking is determined by the
  kwarg :code:`z`. The default shrinking factor is :code:`0.5`. For all
  velocities whose particles are out of bounds the following equation is
  applied:
  
  .. math::
  
      \mathbf{v_{i,t}} = -z\mathbf{v_{i,t}}
docstr_tok: ["Invert","the","velocity","if","the","particle","is","out","of","bounds","The","velocity","is","inverted","and","shrinked",".","The","shrinking","is","determined","by","the","kwarg",":","code",":","`","z","`",".","The","default","shrinking","factor","is",":","code",":","`","0.5","`",".","For","all","velocities","whose","particles","are","out","of","bounds","the","following","equation","is","applied",":","..","math",":",":","\\mathbf","{","v_","{","i",",","t","}","}","=","-z\\mathbf","{","v_","{","i",",","t","}","}"]
code: def invert(self, velocity, clamp=None, **kwargs):
      r"""Invert the velocity if the particle is out of bounds
  
      The velocity is inverted and shrinked. The shrinking is determined by the
      kwarg :code:`z`. The default shrinking factor is :code:`0.5`. For all
      velocities whose particles are out of bounds the following equation is
      applied:
  
      .. math::
  
          \mathbf{v_{i,t}} = -z\mathbf{v_{i,t}}
      """
      try:
          # Default for the shrinking factor
          if "z" not in kwargs:
              z = 0.5
          else:
              z = kwargs["z"]
          lower_than_bound, greater_than_bound = self._out_of_bounds(
              kwargs["position"], kwargs["bounds"]
          )
          new_vel = velocity
          new_vel[lower_than_bound[0]] = (-z) * new_vel[
              lower_than_bound[0]
          ]
          new_vel[greater_than_bound[0]] = (-z) * new_vel[
              greater_than_bound[0]
          ]
          if clamp is not None:
              new_vel = self.__apply_clamp(new_vel, clamp)
      except KeyError:
          self.rep.logger.exception(
              "Keyword 'position' or 'bounds' missing"
          )
          raise
      else:
          return new_vel
  
imports: import inspect
  import logging
  import numpy
  import math
  from copy import copy
  from ..utils.reporter import Reporter
label_desc: Use image node_id 6 for calling the VelocityHandler obj's underlying member method code with example usage: obj.invert(velocity, clamp) and returns: new_vel