'Intermediate method called by public arithmetics (i.e. ``add``)
before the processing method (``_arithmetic``) is invoked.
.. warning::
Do not override this method in subclasses.
This method checks if it was called as instance or as class method and
then wraps the operands and the result from ``_arithmetics`` in the
appropriate subclass.
Parameters
self_or_cls : instance or class
``sharedmethod`` behaves like a normal method if called on the
instance (then this parameter is ``self``) but like a classmethod
when called on the class (then this parameter is ``cls``).
operations : callable
The operation (normally a numpy-ufunc) that represents the
appropriate action.
operand, operand2, kwargs :
See for example ``add``.
Result
result : `~astropy.nddata.NDData`-like
Depending how this method was called either ``self_or_cls``
(called on class) or ``self_or_cls.__class__`` (called on instance)
is the NDData-subclass that is used as wrapper for the result.'

@sharedmethod
def _prepare_then_do_arithmetic(self_or_cls, operation, operand, operand2, **kwargs):

    if isinstance(self_or_cls, NDArithmeticMixin):
        cls = self_or_cls.__class__
        if (operand2 is None):
            operand2 = operand
            operand = self_or_cls
        else:
            operand = cls(operand)
    else:
        cls = self_or_cls
        if (operand2 is None):
            raise TypeError(u"operand2    must    be    given    when    the    method    isn't    called    on    an    instance.")
        operand = cls(operand)
    operand2 = cls(operand2)
    (result, init_kwds) = operand._arithmetic(operation, operand2, **kwargs)
    return cls(result, **init_kwds)
