def insert_model_into_uvdata_tensor(uvdata, time, polarization, ants_map, red_grps, model_r, model_i, scale_factor=1.0):
    'Insert fitted tensor values back into uvdata object for tensor mode.\n\n    Parameters\n    ----------\n    uvdata: UVData object\n        uvdata object to insert model data into.\n    time: float\n        JD of time to insert.\n    polarization: str\n        polarization to insert.\n    ants_map: dict mapping integers to integers\n        map between each antenna number to a unique index between 0 and Nants_data\n        (typically the index of each antenna in ants_map)\n    red_grps: list of lists of int 2-tuples\n        a list of lists of 2-tuples where all antenna pairs within each sublist\n        are redundant with eachother. Assumes that conjugates are correctly taken.\n    model_r: np.ndarray\n        an Nants_data x Nants_data x Nfreqs np.ndarray with real parts of data\n    model_i: np.ndarray\n        an Nants_data x Nants_data x Nfreqs np.ndarray with imag parts of model\n    scale_factor: float, optional\n        overall scaling factor to divide tensorized data by.\n        default is 1.0\n\n    Returns\n    -------\n    N/A: Modifies uvdata inplace.\n\n    '
    antpairs_data = uvdata.get_antpairs()
    polnum = np.where((uvdata.polarization_array == uvutils.polstr2num(polarization, x_orientation=uvdata.x_orientation)))[0][0]
    for red_grp in red_grps:
        for ap in red_grp:
            (i, j) = (ants_map[ap[0]], ants_map[ap[1]])
            if (ap in antpairs_data):
                dinds = uvdata.antpair2ind(ap)
                dinds = dinds[np.where(np.isclose(time, uvdata.time_array[dinds], atol=1e-07, rtol=0.0))[0][0]]
                model = (model_r[(i, j)] + (1j * model_i[(i, j)]))
            else:
                dinds = uvdata.antpair2ind(ap[::(- 1)])
                dinds = dinds[np.where(np.isclose(time, uvdata.time_array[dinds], atol=1e-07, rtol=0.0))[0][0]]
                model = (model_r[(i, j)] - (1j * model_i[(i, j)]))
            uvdata.data_array[dinds, 0, :, polnum] = (model * scale_factor)
Insert fitted tensor values back into uvdata object for tensor mode.

Parameters
----------
uvdata: UVData object
    uvdata object to insert model data into.
time: float
    JD of time to insert.
polarization: str
    polarization to insert.
ants_map: dict mapping integers to integers
    map between each antenna number to a unique index between 0 and Nants_data
    (typically the index of each antenna in ants_map)
red_grps: list of lists of int 2-tuples
    a list of lists of 2-tuples where all antenna pairs within each sublist
    are redundant with eachother. Assumes that conjugates are correctly taken.
model_r: np.ndarray
    an Nants_data x Nants_data x Nfreqs np.ndarray with real parts of data
model_i: np.ndarray
    an Nants_data x Nants_data x Nfreqs np.ndarray with imag parts of model
scale_factor: float, optional
    overall scaling factor to divide tensorized data by.
    default is 1.0

Returns
-------
N/A: Modifies uvdata inplace.
def insert_model_into_uvdata_tensor(uvdata, time, polarization, ants_map, red_grps, model_r, model_i, scale_factor=1.0):
    'Insert fitted tensor values back into uvdata object for tensor mode.\n\n    Parameters\n    ----------\n    uvdata: UVData object\n        uvdata object to insert model data into.\n    time: float\n        JD of time to insert.\n    polarization: str\n        polarization to insert.\n    ants_map: dict mapping integers to integers\n        map between each antenna number to a unique index between 0 and Nants_data\n        (typically the index of each antenna in ants_map)\n    red_grps: list of lists of int 2-tuples\n        a list of lists of 2-tuples where all antenna pairs within each sublist\n        are redundant with eachother. Assumes that conjugates are correctly taken.\n    model_r: np.ndarray\n        an Nants_data x Nants_data x Nfreqs np.ndarray with real parts of data\n    model_i: np.ndarray\n        an Nants_data x Nants_data x Nfreqs np.ndarray with imag parts of model\n    scale_factor: float, optional\n        overall scaling factor to divide tensorized data by.\n        default is 1.0\n\n    Returns\n    -------\n    N/A: Modifies uvdata inplace.\n\n    '
    antpairs_data = uvdata.get_antpairs()
    polnum = np.where((uvdata.polarization_array == uvutils.polstr2num(polarization, x_orientation=uvdata.x_orientation)))[0][0]
    for red_grp in red_grps:
        for ap in red_grp:
            (i, j) = (ants_map[ap[0]], ants_map[ap[1]])
            if (ap in antpairs_data):
                dinds = uvdata.antpair2ind(ap)
                dinds = dinds[np.where(np.isclose(time, uvdata.time_array[dinds], atol=1e-07, rtol=0.0))[0][0]]
                model = (model_r[(i, j)] + (1j * model_i[(i, j)]))
            else:
                dinds = uvdata.antpair2ind(ap[::(- 1)])
                dinds = dinds[np.where(np.isclose(time, uvdata.time_array[dinds], atol=1e-07, rtol=0.0))[0][0]]
                model = (model_r[(i, j)] - (1j * model_i[(i, j)]))
            uvdata.data_array[dinds, 0, :, polnum] = (model * scale_factor)