def read_calibrate_and_model_dpss(input_data_files, input_model_files=None, input_gain_files=None, resid_outfilename=None, gain_outfilename=None, model_outfilename=None, fitted_info_outfilename=None, x_orientation='east', clobber=False, bllen_min=0.0, bllen_max=np.inf, bl_ew_min=0.0, ex_ants=None, select_ants=None, gpu_index=None, gpu_memory_limit=None, precision=32, use_autocorrs_in_weights=False, **calibration_kwargs):
    "\n    Driver function for using calamity with DPSS modeling.\n\n    Parameters\n    ----------\n    input_data_files: list of strings or UVData object.\n        list of paths to input files to read in and calibrate.\n    input_model_files: list of strings or UVData object, optional\n        list of paths to model files for overal phase/amp reference.\n        Default is None -> use input files as model for overall\n        phase and amplitude calibration.\n    input_gain_files: list of strings or UVCal object, optional\n        list of paths to gain files to use as initial guesses for calibration.\n    resid_outfilename: str, optional\n        path for file to write residuals.\n        default is None -> don't write out residuals.\n    gain_outfilename: str, optional\n        path to gain calfits to write fitted gains.\n        default is None -> don't write out gains.\n    model_outfilename, str, optional\n        path to file to write model output.\n        default is None -> Don't write model.\n    fitting_info_outfilename, str, optional\n        string to pickel fitting info to.\n    n_output_chunks: int optional\n        split up outputs into n_output_chunks chunked by time.\n        default is None -> write single output file.\n    bllen_min: float, optional\n        select all baselines with length greater then this value [meters].\n        default is 0.0\n    bllen_max: float, optional\n        select only baselines with length less then this value [meters].\n        default is np.inf.\n    bl_ew_min: float, optional\n        select all baselines with EW projected length greater then this value [meters].\n        default is 0.0\n    gpu_index: int, optional\n        limit visible GPUs to be the index of this GPU.\n        default: None -> all GPUs are visible.\n    gpu_memory_limit: float, optional\n        GiB of memory on GPU that can be used.\n        default None -> all memory available.\n    use_autocorrs_in_weights: bool, optional\n        if True, use smooth fits to autocorrelations as\n        inverse variance weights.\n        default is False.\n    calibration_kwargs: kwarg dict\n        see kwrags for calibration_and_model_dpss()\n    Returns\n    -------\n\n    model_fit: UVData object\n        uvdata object containing DPSS model of intrinsic foregrounds.\n    resid_fit: UVData object\n        uvdata object containing residuals after subtracting model times gains and applying gains.\n    gains_fit: UVCal object\n        uvcal object containing fitted gains.\n    fit_info:\n        dictionary containing fit history for each time-step and polarization in the data with fields:\n        'loss_history': list of values of the loss function in each minimization iteration.\n    "
    gpus = tf.config.list_physical_devices('GPU')
    if (gpu_index is not None):
        if gpus:
            if (gpu_memory_limit is None):
                tf.config.set_visible_devices(gpus[gpu_index], 'GPU')
            else:
                tf.config.set_logical_device_configuration(gpus[gpu_index], [tf.config.LogicalDeviceConfiguration(memory_limit=(gpu_memory_limit * 1024))])
            logical_gpus = tf.config.list_logical_devices('GPU')
            print(len(gpus), 'Physical GPUs,', len(logical_gpus), 'Logical GPU')
    if isinstance(input_data_files, str):
        input_data_files = [input_data_files]
    if isinstance(input_data_files, list):
        uvd = UVData()
        uvd.read(input_data_files)
    else:
        uvd = input_data_files
    if use_autocorrs_in_weights:
        weights = get_auto_weights(uvd)
    else:
        weights = None
    utils.select_baselines(uvd, bllen_min=bllen_min, bllen_max=bllen_max, bl_ew_min=bl_ew_min, ex_ants=ex_ants, select_ants=select_ants)
    if isinstance(input_model_files, str):
        input_model_files = [input_model_files]
    if (input_model_files is not None):
        if isinstance(input_model_files, list):
            uvd_model = UVData()
            uvd_model.read(input_model_files)
        else:
            uvd_model = input_model_files
    else:
        uvd_model = None
    if (uvd_model is not None):
        utils.select_baselines(uvd, bllen_min=bllen_min, bllen_max=bllen_max, bl_ew_min=bl_ew_min)
    if isinstance(input_gain_files, str):
        input_gain_files = [input_gain_files]
    if (input_gain_files is not None):
        if isinstance(input_gain_files, list):
            uvc = UVCal()
            uvc.read_calfits(input_gain_files)
        else:
            uvc = input_gain_files
    else:
        uvc = None
    dtype = {32: np.float32, 64: np.float64}[precision]
    if ((gpu_index is not None) and gpus):
        with tf.device(f'/device:GPU:{gpus[gpu_index].name[(- 1)]}'):
            (model_fit, resid_fit, gains_fit, fit_info) = calibrate_and_model_dpss(uvdata=uvd, sky_model=uvd_model, gains=uvc, dtype=dtype, weights=weights, **calibration_kwargs)
    else:
        (model_fit, resid_fit, gains_fit, fit_info) = calibrate_and_model_dpss(uvdata=uvd, sky_model=uvd_model, gains=uvc, dtype=dtype, weights=weights, **calibration_kwargs)
    if (resid_outfilename is not None):
        resid_fit.write_uvh5(resid_outfilename, clobber=clobber)
    if (gain_outfilename is not None):
        gains_fit.x_orientation = x_orientation
        gains_fit.write_calfits(gain_outfilename, clobber=clobber)
    if (model_outfilename is not None):
        model_fit.write_uvh5(model_outfilename, clobber=clobber)
    fit_info['calibration_kwargs'] = calibration_kwargs
    fit_info['calibration_kwargs']['dtype'] = dtype
    return (model_fit, resid_fit, gains_fit, fit_info)
Driver function for using calamity with DPSS modeling.

Parameters
----------
input_data_files: list of strings or UVData object.
    list of paths to input files to read in and calibrate.
input_model_files: list of strings or UVData object, optional
    list of paths to model files for overal phase/amp reference.
    Default is None -> use input files as model for overall
    phase and amplitude calibration.
input_gain_files: list of strings or UVCal object, optional
    list of paths to gain files to use as initial guesses for calibration.
resid_outfilename: str, optional
    path for file to write residuals.
    default is None -> don't write out residuals.
gain_outfilename: str, optional
    path to gain calfits to write fitted gains.
    default is None -> don't write out gains.
model_outfilename, str, optional
    path to file to write model output.
    default is None -> Don't write model.
fitting_info_outfilename, str, optional
    string to pickel fitting info to.
n_output_chunks: int optional
    split up outputs into n_output_chunks chunked by time.
    default is None -> write single output file.
bllen_min: float, optional
    select all baselines with length greater then this value [meters].
    default is 0.0
bllen_max: float, optional
    select only baselines with length less then this value [meters].
    default is np.inf.
bl_ew_min: float, optional
    select all baselines with EW projected length greater then this value [meters].
    default is 0.0
gpu_index: int, optional
    limit visible GPUs to be the index of this GPU.
    default: None -> all GPUs are visible.
gpu_memory_limit: float, optional
    GiB of memory on GPU that can be used.
    default None -> all memory available.
use_autocorrs_in_weights: bool, optional
    if True, use smooth fits to autocorrelations as
    inverse variance weights.
    default is False.
calibration_kwargs: kwarg dict
    see kwrags for calibration_and_model_dpss()
Returns
-------

model_fit: UVData object
    uvdata object containing DPSS model of intrinsic foregrounds.
resid_fit: UVData object
    uvdata object containing residuals after subtracting model times gains and applying gains.
gains_fit: UVCal object
    uvcal object containing fitted gains.
fit_info:
    dictionary containing fit history for each time-step and polarization in the data with fields:
    'loss_history': list of values of the loss function in each minimization iteration.
def read_calibrate_and_model_dpss(input_data_files, input_model_files=None, input_gain_files=None, resid_outfilename=None, gain_outfilename=None, model_outfilename=None, fitted_info_outfilename=None, x_orientation='east', clobber=False, bllen_min=0.0, bllen_max=np.inf, bl_ew_min=0.0, ex_ants=None, select_ants=None, gpu_index=None, gpu_memory_limit=None, precision=32, use_autocorrs_in_weights=False, **calibration_kwargs):
    "\n    Driver function for using calamity with DPSS modeling.\n\n    Parameters\n    ----------\n    input_data_files: list of strings or UVData object.\n        list of paths to input files to read in and calibrate.\n    input_model_files: list of strings or UVData object, optional\n        list of paths to model files for overal phase/amp reference.\n        Default is None -> use input files as model for overall\n        phase and amplitude calibration.\n    input_gain_files: list of strings or UVCal object, optional\n        list of paths to gain files to use as initial guesses for calibration.\n    resid_outfilename: str, optional\n        path for file to write residuals.\n        default is None -> don't write out residuals.\n    gain_outfilename: str, optional\n        path to gain calfits to write fitted gains.\n        default is None -> don't write out gains.\n    model_outfilename, str, optional\n        path to file to write model output.\n        default is None -> Don't write model.\n    fitting_info_outfilename, str, optional\n        string to pickel fitting info to.\n    n_output_chunks: int optional\n        split up outputs into n_output_chunks chunked by time.\n        default is None -> write single output file.\n    bllen_min: float, optional\n        select all baselines with length greater then this value [meters].\n        default is 0.0\n    bllen_max: float, optional\n        select only baselines with length less then this value [meters].\n        default is np.inf.\n    bl_ew_min: float, optional\n        select all baselines with EW projected length greater then this value [meters].\n        default is 0.0\n    gpu_index: int, optional\n        limit visible GPUs to be the index of this GPU.\n        default: None -> all GPUs are visible.\n    gpu_memory_limit: float, optional\n        GiB of memory on GPU that can be used.\n        default None -> all memory available.\n    use_autocorrs_in_weights: bool, optional\n        if True, use smooth fits to autocorrelations as\n        inverse variance weights.\n        default is False.\n    calibration_kwargs: kwarg dict\n        see kwrags for calibration_and_model_dpss()\n    Returns\n    -------\n\n    model_fit: UVData object\n        uvdata object containing DPSS model of intrinsic foregrounds.\n    resid_fit: UVData object\n        uvdata object containing residuals after subtracting model times gains and applying gains.\n    gains_fit: UVCal object\n        uvcal object containing fitted gains.\n    fit_info:\n        dictionary containing fit history for each time-step and polarization in the data with fields:\n        'loss_history': list of values of the loss function in each minimization iteration.\n    "
    gpus = tf.config.list_physical_devices('GPU')
    if (gpu_index is not None):
        if gpus:
            if (gpu_memory_limit is None):
                tf.config.set_visible_devices(gpus[gpu_index], 'GPU')
            else:
                tf.config.set_logical_device_configuration(gpus[gpu_index], [tf.config.LogicalDeviceConfiguration(memory_limit=(gpu_memory_limit * 1024))])
            logical_gpus = tf.config.list_logical_devices('GPU')
            print(len(gpus), 'Physical GPUs,', len(logical_gpus), 'Logical GPU')
    if isinstance(input_data_files, str):
        input_data_files = [input_data_files]
    if isinstance(input_data_files, list):
        uvd = UVData()
        uvd.read(input_data_files)
    else:
        uvd = input_data_files
    if use_autocorrs_in_weights:
        weights = get_auto_weights(uvd)
    else:
        weights = None
    utils.select_baselines(uvd, bllen_min=bllen_min, bllen_max=bllen_max, bl_ew_min=bl_ew_min, ex_ants=ex_ants, select_ants=select_ants)
    if isinstance(input_model_files, str):
        input_model_files = [input_model_files]
    if (input_model_files is not None):
        if isinstance(input_model_files, list):
            uvd_model = UVData()
            uvd_model.read(input_model_files)
        else:
            uvd_model = input_model_files
    else:
        uvd_model = None
    if (uvd_model is not None):
        utils.select_baselines(uvd, bllen_min=bllen_min, bllen_max=bllen_max, bl_ew_min=bl_ew_min)
    if isinstance(input_gain_files, str):
        input_gain_files = [input_gain_files]
    if (input_gain_files is not None):
        if isinstance(input_gain_files, list):
            uvc = UVCal()
            uvc.read_calfits(input_gain_files)
        else:
            uvc = input_gain_files
    else:
        uvc = None
    dtype = {32: np.float32, 64: np.float64}[precision]
    if ((gpu_index is not None) and gpus):
        with tf.device(f'/device:GPU:{gpus[gpu_index].name[(- 1)]}'):
            (model_fit, resid_fit, gains_fit, fit_info) = calibrate_and_model_dpss(uvdata=uvd, sky_model=uvd_model, gains=uvc, dtype=dtype, weights=weights, **calibration_kwargs)
    else:
        (model_fit, resid_fit, gains_fit, fit_info) = calibrate_and_model_dpss(uvdata=uvd, sky_model=uvd_model, gains=uvc, dtype=dtype, weights=weights, **calibration_kwargs)
    if (resid_outfilename is not None):
        resid_fit.write_uvh5(resid_outfilename, clobber=clobber)
    if (gain_outfilename is not None):
        gains_fit.x_orientation = x_orientation
        gains_fit.write_calfits(gain_outfilename, clobber=clobber)
    if (model_outfilename is not None):
        model_fit.write_uvh5(model_outfilename, clobber=clobber)
    fit_info['calibration_kwargs'] = calibration_kwargs
    fit_info['calibration_kwargs']['dtype'] = dtype
    return (model_fit, resid_fit, gains_fit, fit_info)