def renormalize(uvdata_reference_model, uvdata_deconv, gains, polarization, time, additional_flags=None):
    'Remove arbitrary phase and amplitude from deconvolved model and gains.\n\n    Parameters\n    ----------\n    uvdata_reference_model: UVData object\n        Reference model for "true" visibilities.\n    uvdata_deconv: UVData object\n        "Deconvolved" data solved for in self-cal loop.\n    gains: UVCal object\n        Gains solved for in self-cal loop.\n    polarization: str\n        Polarization string to compute phase and amplitude correction for.\n    additional_flags: np.ndarray\n        Any additional flags you wish to use for excluding data from normalization\n        fed as an np.ndarray with same shape as uvdata_reference_model and uvdata_deconv.\n        default is None -> Only exclude data in flags from reference model and deconv from\n        determinging normalization.\n    Returns\n    -------\n    N/A: Modifies uvdata_deconv and gains in-place.\n    '
    polnum_data = np.where((uvdata_deconv.polarization_array == uvutils.polstr2num(polarization, x_orientation=uvdata_deconv.x_orientation)))[0][0]
    bltsel = np.isclose(uvdata_deconv.time_array, time, atol=1e-07, rtol=0.0)
    selection = ((~ uvdata_deconv.flag_array[bltsel, :, :, polnum_data]) & (~ uvdata_reference_model.flag_array[bltsel, :, :, polnum_data]))
    if (additional_flags is not None):
        selection = (selection & (~ additional_flags[bltsel, :, :, polnum_data]))
    data_ratio = (uvdata_reference_model.data_array[bltsel, :, :, polnum_data][selection] / uvdata_deconv.data_array[bltsel, :, :, polnum_data][selection])
    data_ratio[(~ np.isfinite(data_ratio))] = np.nan
    scale_factor_phase = np.angle(np.nanmean(data_ratio))
    scale_factor_abs = np.sqrt(np.nanmean((np.abs(data_ratio) ** 2.0)))
    scale_factor = scale_factor_abs
    uvdata_deconv.data_array[bltsel, :, :, polnum_data] *= scale_factor
    polnum_gains = np.where((gains.jones_array == uvutils.polstr2num(polarization, x_orientation=uvdata_deconv.x_orientation)))[0][0]
    gindt = np.where(np.isclose(gains.time_array, time, atol=1e-07, rtol=0.0))[0][0]
    gains.gain_array[:, :, :, gindt, polnum_gains] *= (scale_factor ** (- 0.5))
Remove arbitrary phase and amplitude from deconvolved model and gains.

Parameters
----------
uvdata_reference_model: UVData object
    Reference model for "true" visibilities.
uvdata_deconv: UVData object
    "Deconvolved" data solved for in self-cal loop.
gains: UVCal object
    Gains solved for in self-cal loop.
polarization: str
    Polarization string to compute phase and amplitude correction for.
additional_flags: np.ndarray
    Any additional flags you wish to use for excluding data from normalization
    fed as an np.ndarray with same shape as uvdata_reference_model and uvdata_deconv.
    default is None -> Only exclude data in flags from reference model and deconv from
    determinging normalization.
Returns
-------
N/A: Modifies uvdata_deconv and gains in-place.
def renormalize(uvdata_reference_model, uvdata_deconv, gains, polarization, time, additional_flags=None):
    'Remove arbitrary phase and amplitude from deconvolved model and gains.\n\n    Parameters\n    ----------\n    uvdata_reference_model: UVData object\n        Reference model for "true" visibilities.\n    uvdata_deconv: UVData object\n        "Deconvolved" data solved for in self-cal loop.\n    gains: UVCal object\n        Gains solved for in self-cal loop.\n    polarization: str\n        Polarization string to compute phase and amplitude correction for.\n    additional_flags: np.ndarray\n        Any additional flags you wish to use for excluding data from normalization\n        fed as an np.ndarray with same shape as uvdata_reference_model and uvdata_deconv.\n        default is None -> Only exclude data in flags from reference model and deconv from\n        determinging normalization.\n    Returns\n    -------\n    N/A: Modifies uvdata_deconv and gains in-place.\n    '
    polnum_data = np.where((uvdata_deconv.polarization_array == uvutils.polstr2num(polarization, x_orientation=uvdata_deconv.x_orientation)))[0][0]
    bltsel = np.isclose(uvdata_deconv.time_array, time, atol=1e-07, rtol=0.0)
    selection = ((~ uvdata_deconv.flag_array[bltsel, :, :, polnum_data]) & (~ uvdata_reference_model.flag_array[bltsel, :, :, polnum_data]))
    if (additional_flags is not None):
        selection = (selection & (~ additional_flags[bltsel, :, :, polnum_data]))
    data_ratio = (uvdata_reference_model.data_array[bltsel, :, :, polnum_data][selection] / uvdata_deconv.data_array[bltsel, :, :, polnum_data][selection])
    data_ratio[(~ np.isfinite(data_ratio))] = np.nan
    scale_factor_phase = np.angle(np.nanmean(data_ratio))
    scale_factor_abs = np.sqrt(np.nanmean((np.abs(data_ratio) ** 2.0)))
    scale_factor = scale_factor_abs
    uvdata_deconv.data_array[bltsel, :, :, polnum_data] *= scale_factor
    polnum_gains = np.where((gains.jones_array == uvutils.polstr2num(polarization, x_orientation=uvdata_deconv.x_orientation)))[0][0]
    gindt = np.where(np.isclose(gains.time_array, time, atol=1e-07, rtol=0.0))[0][0]
    gains.gain_array[:, :, :, gindt, polnum_gains] *= (scale_factor ** (- 0.5))