def _safeDerivative(quant,index):
    """Safely performs derivative of a quantity. e.g. in complex quantities with a missing real or imaginary part"""
    if quant is None or quant == 0:
        return quant
    else:
        return quant.dx(index)