import warnings


def get_clp_mapping_from_tc_mapping(tc_mapping):
    """
    Get a CHECLabPy mapping dataframe from a TargetCalib Mapping class,
    along with the metadata

    Parameters
    ----------
    tc_mapping : `target_calib.Mapping`

    Returns
    -------
    df : `pandas.DataFrame`

    """
    df = tc_mapping.as_dataframe()
    with warnings.catch_warnings():
        warnings.simplefilter('ignore', UserWarning)
        df.metadata = dict(
            cfgfile=tc_mapping.GetCfgPath(),
            is_single_module=tc_mapping.IsSingleModule(),
            n_pixels=tc_mapping.GetNPixels(),
            n_modules=tc_mapping.GetNModules(),
            n_tmpix=tc_mapping.GetNTMPix(),
            n_superpixels=tc_mapping.GetNSuperPixels(),
            n_rows=tc_mapping.GetNRows(),
            n_columns=tc_mapping.GetNColumns(),
            size=tc_mapping.GetSize(),
            fOTUpRow_l=tc_mapping.fOTUpRow_l,
            fOTUpRow_u=tc_mapping.fOTUpRow_u,
            fOTUpCol_l=tc_mapping.fOTUpCol_l,
            fOTUpCol_u=tc_mapping.fOTUpCol_u,
            fOTUpX_l=tc_mapping.fOTUpX_l,
            fOTUpX_u=tc_mapping.fOTUpX_u,
            fOTUpY_l=tc_mapping.fOTUpY_l,
            fOTUpY_u=tc_mapping.fOTUpY_u
        )
    return df