<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _ts_value_newton(position, counts, bkg, model, C_0_map):
 """ Compute TS value at a given pixel position using the newton method. Parameters position : tuple Pixel position. counts : `~numpy.ndarray` Count map. bkg : `~numpy.ndarray` Background map. model : `~numpy.ndarray` Source model map. Returns ------- TS : float TS value at the given pixel position. amp : float Best-fit amplitude of the test source. niter : int Number of fit iterations. """

    extract_fn = _collect_wrapper(extract_large_array)
    truncate_fn = _collect_wrapper(extract_small_array)

    # Get data slices
    counts_slice = extract_fn(counts, model, position)
    bkg_slice = extract_fn(bkg, model, position)
    C_0_map_slice = extract_fn(C_0_map, model, position)
    model_slice = truncate_fn(model, counts, position)

    # Mask of pixels with > 0 counts
    mask = [c > 0 for c in counts_slice]

    # Sum of background and model in empty pixels
    bkg_sum = np.sum(np.array([np.sum(t[~m])
                               for t, m in zip(bkg_slice, mask)]))
    model_sum = np.sum(np.array([np.sum(t[~m])
                                 for t, m in zip(model_slice, mask)]))

    # Flattened Arrays
    counts_ = np.concatenate([t[m].flat for t, m in zip(counts_slice, mask)])
    bkg_ = np.concatenate([t[m].flat for t, m in zip(bkg_slice, mask)])
    model_ = np.concatenate([t[m].flat for t, m in zip(model_slice, mask)])
    C_0 = np.sum(np.array([np.sum(t) for t in C_0_map_slice]))

    amplitude, niter = _fit_amplitude_newton(counts_, bkg_, model_,
                                             model_sum)

    if niter > MAX_NITER:
        print('Exceeded maximum number of function evaluations!')
        return np.nan, amplitude, niter

    with np.errstate(invalid='ignore', divide='ignore'):
        C_1 = f_cash_sum(amplitude, counts_, bkg_, model_, bkg_sum, model_sum)

    # Compute and return TS value
    return (C_0 - C_1) * np.sign(amplitude), amplitude, niter