def tensorize_fg_coeffs(data, wgts, fg_model_comps, notebook_progressbar=False, verbose=False):
    'Initialize foreground coefficient tensors from uvdata and modeling component dictionaries.\n\n\n    Parameters\n    ----------\n    data: list\n        list of tf.Tensor objects, each with shape (ngrps, nbls, nfreqs)\n        representing data\n    wgts: list\n        list of tf.Tensor objects, each with shape (ngrps, nbls, nfreqs)\n        representing weights.\n    fg_model_comps: list\n        list of fg modeling tf.Tensor objects\n        representing foreground modeling vectors.\n        Each tensor is (nvecs, ngrps, nbls, nfreqs)\n        see description in tensorize_fg_model_comps_dict\n        docstring.\n    notebook_progressbar: bool, optional\n        use progress bar optimized for notebook output.\n        default is False.\n    verbose: bool, optional\n        lots of text output\n        default is False.\n    Returns\n    -------\n    fg_coeffs_re: tf.Tensor object\n        1d tensor containing real parts of coeffs for each modeling vector.\n        ordering is over foreground modeling vector per redundant group and then\n        redundant group in the order of groups appearing in red_grps\n    fg_coeffs_im: tf.Tensor object\n        1d tensor containing imag parts of coeffs for each modeling vector.\n        ordering is over foreground modeling vector per redundant group and then\n        redundant group in the order of groups appearing in red_grps\n    '
    echo(f'''{datetime.datetime.now()} Computing initial foreground coefficient guesses using linear-leastsq...
''', verbose=verbose)
    fg_coeffs = []
    nchunks = len(data)
    binary_wgts = [tf.convert_to_tensor((~ np.isclose(wgts[cnum].numpy(), 0.0)), dtype=wgts[cnum].dtype) for cnum in range(nchunks)]
    for cnum in PBARS[notebook_progressbar](range(nchunks)):
        fg_coeff_chunk = []
        ngrps = data[cnum].shape[0]
        ndata = (data[cnum].shape[1] * data[cnum].shape[2])
        nvecs = fg_model_comps[cnum].shape[0]
        for gnum in range(ngrps):
            nonzero_rows = np.where(np.all(np.isclose(fg_model_comps[cnum][:, gnum].numpy().reshape(nvecs, ndata), 0.0), axis=1))[0]
            if (len(nonzero_rows) > 0):
                nvecs_nonzero = np.min(nonzero_rows)
            else:
                nvecs_nonzero = nvecs
            fg_coeff_chunk.append(tf.reshape(tf.linalg.lstsq(tf.transpose(tf.reshape(fg_model_comps[cnum][:, gnum], (nvecs, ndata)))[:, :nvecs_nonzero], tf.reshape((data[cnum][gnum] * binary_wgts[cnum][gnum]), (ndata, 1))), (nvecs_nonzero,)))
            fg_coeff_chunk[(- 1)] = tf.pad(fg_coeff_chunk[(- 1)], [(0, (nvecs - nvecs_nonzero))])
        fg_coeff_chunk = tf.reshape(tf.transpose(tf.stack(fg_coeff_chunk)), (nvecs, ngrps, 1, 1))
        fg_coeffs.append(fg_coeff_chunk)
    echo(f'''{datetime.datetime.now()} Finished initial foreground coefficient guesses...
''', verbose=verbose)
    return fg_coeffs
Initialize foreground coefficient tensors from uvdata and modeling component dictionaries.


Parameters
----------
data: list
    list of tf.Tensor objects, each with shape (ngrps, nbls, nfreqs)
    representing data
wgts: list
    list of tf.Tensor objects, each with shape (ngrps, nbls, nfreqs)
    representing weights.
fg_model_comps: list
    list of fg modeling tf.Tensor objects
    representing foreground modeling vectors.
    Each tensor is (nvecs, ngrps, nbls, nfreqs)
    see description in tensorize_fg_model_comps_dict
    docstring.
notebook_progressbar: bool, optional
    use progress bar optimized for notebook output.
    default is False.
verbose: bool, optional
    lots of text output
    default is False.
Returns
-------
fg_coeffs_re: tf.Tensor object
    1d tensor containing real parts of coeffs for each modeling vector.
    ordering is over foreground modeling vector per redundant group and then
    redundant group in the order of groups appearing in red_grps
fg_coeffs_im: tf.Tensor object
    1d tensor containing imag parts of coeffs for each modeling vector.
    ordering is over foreground modeling vector per redundant group and then
    redundant group in the order of groups appearing in red_grps
def tensorize_fg_coeffs(data, wgts, fg_model_comps, notebook_progressbar=False, verbose=False):
    'Initialize foreground coefficient tensors from uvdata and modeling component dictionaries.\n\n\n    Parameters\n    ----------\n    data: list\n        list of tf.Tensor objects, each with shape (ngrps, nbls, nfreqs)\n        representing data\n    wgts: list\n        list of tf.Tensor objects, each with shape (ngrps, nbls, nfreqs)\n        representing weights.\n    fg_model_comps: list\n        list of fg modeling tf.Tensor objects\n        representing foreground modeling vectors.\n        Each tensor is (nvecs, ngrps, nbls, nfreqs)\n        see description in tensorize_fg_model_comps_dict\n        docstring.\n    notebook_progressbar: bool, optional\n        use progress bar optimized for notebook output.\n        default is False.\n    verbose: bool, optional\n        lots of text output\n        default is False.\n    Returns\n    -------\n    fg_coeffs_re: tf.Tensor object\n        1d tensor containing real parts of coeffs for each modeling vector.\n        ordering is over foreground modeling vector per redundant group and then\n        redundant group in the order of groups appearing in red_grps\n    fg_coeffs_im: tf.Tensor object\n        1d tensor containing imag parts of coeffs for each modeling vector.\n        ordering is over foreground modeling vector per redundant group and then\n        redundant group in the order of groups appearing in red_grps\n    '
    echo(f'{datetime.datetime.now()} Computing initial foreground coefficient guesses using linear-leastsq...
', verbose=verbose)
    fg_coeffs = []
    nchunks = len(data)
    binary_wgts = [tf.convert_to_tensor((~ np.isclose(wgts[cnum].numpy(), 0.0)), dtype=wgts[cnum].dtype) for cnum in range(nchunks)]
    for cnum in PBARS[notebook_progressbar](range(nchunks)):
        fg_coeff_chunk = []
        ngrps = data[cnum].shape[0]
        ndata = (data[cnum].shape[1] * data[cnum].shape[2])
        nvecs = fg_model_comps[cnum].shape[0]
        for gnum in range(ngrps):
            nonzero_rows = np.where(np.all(np.isclose(fg_model_comps[cnum][:, gnum].numpy().reshape(nvecs, ndata), 0.0), axis=1))[0]
            if (len(nonzero_rows) > 0):
                nvecs_nonzero = np.min(nonzero_rows)
            else:
                nvecs_nonzero = nvecs
            fg_coeff_chunk.append(tf.reshape(tf.linalg.lstsq(tf.transpose(tf.reshape(fg_model_comps[cnum][:, gnum], (nvecs, ndata)))[:, :nvecs_nonzero], tf.reshape((data[cnum][gnum] * binary_wgts[cnum][gnum]), (ndata, 1))), (nvecs_nonzero,)))
            fg_coeff_chunk[(- 1)] = tf.pad(fg_coeff_chunk[(- 1)], [(0, (nvecs - nvecs_nonzero))])
        fg_coeff_chunk = tf.reshape(tf.transpose(tf.stack(fg_coeff_chunk)), (nvecs, ngrps, 1, 1))
        fg_coeffs.append(fg_coeff_chunk)
    echo(f'{datetime.datetime.now()} Finished initial foreground coefficient guesses...
', verbose=verbose)
    return fg_coeffs