(u.Msun / u.yr))
print("SFR({1} Myr) = {0}".format(sfrbrickage_totmax, sgrb2_brick_age_myr))

with open(paths.texpath('sfr.tex'), 'w') as fh:
    fh.write("\\newcommand{{\\sfrdynage}}{{{0}\\xspace}}\n".format(
        totalrow[-1].to(u.Msun / u.yr).value))
    fh.write("\\newcommand{{\\sfrbrickage}}{{{0}\\xspace}}\n".format(
        sfrbrickage.to(u.Msun / u.yr).value))
    fh.write("\\newcommand{{\\sfrdynagemax}}{{{0}\\xspace}}\n".format(
        sfrdynage_totmax))
    fh.write("\\newcommand{{\\sfrbrickagemax}}{{{0}\\xspace}}\n".format(
        sfrbrickage_totmax.to(u.Msun / u.yr).value))

formats = {
    'SFR':
    lambda x: latex_info.strip_trailing_zeros(str(x)),
    '$M_{\\rm inf}^s$':
    lambda x: "{0}".format(x) if x != -999 else '-',
    '$M_{\\rm count}^s$':
    lambda x: "{0}".format(x) if x != -999 else '-',
    '$N({\\rm cores})$':
    lambda x: "{0}".format(x) if x != -999 else '-',
    '$N({\\rm H\\textsc{ii}})$':
    lambda x: "{0}".format(x) if x != -999 else '-',
    '$M_{\\rm count}$':
    lambda x: "{0}".format(x) if x != -999 else '-',
    '$M_{\\rm inferred}$':
    lambda x: "{0}".format(x) if x != -999 else '-',
    '$M_{\\rm inferred, H\\textsc{ii}}$':
    lambda x: "{0}".format(x) if x != -999 else '-',
    '$M_{\\rm inferred, cores}$':
Example #2
0
    '$\\sigma_{MAD}$',
    '$\\theta_{req}$',
    '\\sigma_{req}$',
    '$\\sigma_{MAD}/\\sigma_{req}$',
    # '$\\theta_{req}/\\theta_{maj}$',
    "$\Omega_{syn}^{1/2}/\Omega_{req}^{1/2}$",
    'DR$_{pre}$',
    'DR$_{post}$',
    'DR$_{post}$/DR$_{pre}$'
]

# convert to mJy
fwtbl['$\sigma_{MAD}$'] *= 1000

formats = {
    key: lambda x: strip_trailing_zeros('{0:0.3f}'.format(round_to_n(x, 2)))
    for key in float_cols
}

fwtbl.write('selfcal_summary.ecsv', format='ascii.ecsv', overwrite=True)

# caption needs to be *before* preamble.
#latexdict['caption'] = 'Continuum Source IDs and photometry'
latexdict['header_start'] = '\label{tab:selfcal}'  #\n\\footnotesize'
latexdict[
    'preamble'] = '\caption{Selfcal Summary}\n\\resizebox{\\textwidth}{!}{'
latexdict['col_align'] = 'l' * len(fwtbl.columns)
latexdict['tabletype'] = 'table*'
latexdict['tablefoot'] = (
    "}\par\n"
    "$n_{sc}$ is the number of self-calibration iterations adopted.  "
        'Muno_xray_ID',
        'Muno_xray_Counts',
        'peak_mass_20K',
        'peak_col_20K',
        'McGrath_V_H2O',
        'McGrath_matchdistance',
        'nn11',
        'Muno_xray_matchdistance',
]:
    cont_tbl.remove_column(colname)

formats = {
    'Coordinates':
    lambda x: x.to_string('hmsdms', sep=":"),
    '$S_{\\nu,max}$':
    lambda x: strip_trailing_zeros('{0:0.2f}'.format(round_to_n(x, 2))),
    '$S_{\\nu,tot}$':
    lambda x: strip_trailing_zeros('{0:0.2f}'.format(round_to_n(x, 2))),
    '$\sigma_{bg}$':
    lambda x: strip_trailing_zeros('{0:0.2f}'.format(round_to_n(x, 2))),
    '$\\alpha$':
    lambda x: '-' if np.isnan(x) else strip_trailing_zeros('{0:0.2f}'.format(
        round_to_n(x, 2))),
    '$E(\\alpha)$':
    lambda x: '-' if np.isnan(x) else strip_trailing_zeros('{0:0.3f}'.format(
        round_to_n(x, 2))),
    '$N(\hh)_{40 K}$':
    format_float,
    '$M_{40K}$':
    lambda x: '-' if np.isnan(x) else strip_trailing_zeros('{0:0.2f}'.format(
        round_to_n(x, 2))),
Example #4
0
def make_latex_table(releasename='February2021', savename='selfcal_summary'):
    if datetime.datetime.today() > datetime.datetime(
            year=2021, month=1, day=10):
        result = requests.get(
            f'https://data.rc.ufl.edu/secure/adamginsburg/ALMA-IMF/{releasename}Release/tables/metadata_sc.ecsv',
            auth=('almaimf', keyring.get_password('almaimf', 'almaimf')))
        with open(f'{releasename}_metadata_sc.ecsv', 'w') as fh:
            fh.write(result.text)

        result = requests.get(
            'https://data.rc.ufl.edu/secure/adamginsburg/ALMA-IMF/tables/bandpass_fraction.ecsv',
            auth=('almaimf', keyring.get_password('almaimf', 'almaimf')))
        with open('bandpass_fraction.ecsv', 'w') as fh:
            fh.write(result.text)

    bp_tbl = Table.read('bandpass_fraction.ecsv')
    bp_tbl['band'] = [f'B{b}' for b in bp_tbl['band']]
    bp_tbl.rename_column('field', 'region')
    bp_tbl = table.join(bp_tbl.group_by('config').groups[0],
                        bp_tbl.group_by('config').groups[1],
                        keys=('region', 'band'))
    bp_tbl.rename_column('bwfrac_1', '12Mlong_frac')
    bp_tbl.rename_column('bwfrac_2', '12Mshort_frac')
    bp_tbl.remove_column('config_1')
    bp_tbl.remove_column('config_2')

    tbl = table.join(Table.read(f'{releasename}_metadata_sc.ecsv'),
                     bp_tbl,
                     keys=('region', 'band'))
    bad = np.array([('diff' in x) or ('noco' in x) for x in tbl['filename']])

    # downselect
    keep = ((tbl['suffix'] == 'finaliter') & (tbl['robust'] == 'r0.0') &
            (~tbl['pbcor']) & (~tbl['bsens']) & (~tbl['nobright']) & (~bad))

    wtbl = tbl[keep]

    assert not any(np.isnan(wtbl['dr_improvement']))

    print(len(wtbl))
    print(wtbl)

    # strip preceding "sc" from selfcal numbers
    wtbl['selfcaliter'] = Column(data=[
        row['selfcaliter'][2:] + ("a" if row['has_amp'] else "")
        for row in wtbl
    ])

    # SensVsReq can be populated with either pre- or post-; we want post
    wtbl['SensVsReqPost'] = wtbl['mad_sample_post'] / wtbl['Req_Sens']
    wtbl['SensVsReqPre'] = wtbl['mad_sample_pre'] / wtbl['Req_Sens']

    wtbl['mad_sample_post'].unit = u.mJy / u.beam
    wtbl['mad_sample_pre'].unit = u.mJy / u.beam

    # convert 'peak' to mJy
    # ("imstats" uses Jy, "compare" uses mJy)
    wtbl['peak'] *= 1e3
    wtbl['peak'].unit = u.mJy / u.beam

    cols_to_keep = {
        'region': 'Region',
        'band': 'Band',
        'selfcaliter': '$n_{sc}$',
        'bmaj': r'$\theta_{maj}$',
        'bmin': r'$\theta_{min}$',
        'bpa': 'BPA',
        'Req_Res': r"$\theta_{req}$",
        'BeamVsReq': r"$\Omega_{syn}^{1/2}/\Omega_{req}^{1/2}$",
        #'peak/mad': "DR",
        'peak': '$S_{peak}$',
        'mad_sample_post': '$\sigma_{MAD}$',
        'Req_Sens': r"$\sigma_{req}$",
        'SensVsReqPost': r"$\sigma_{MAD}/\sigma_{req}$",
        'dr_pre': "DR$_{pre}$",
        'dr_post': "DR$_{post}$",
        'dr_improvement': "DR$_{post}$/DR$_{pre}$"
    }

    units = {
        '$S_{peak}$': (u.mJy / u.beam).to_string(u.format.LatexInline),
        '$\sigma_{MAD}$': (u.mJy / u.beam).to_string(u.format.LatexInline),
        '$\sigma_{req}$': (u.mJy / u.beam).to_string(u.format.LatexInline),
        r'$\theta_{req}$': u.arcsec.to_string(u.format.LatexInline),
        r'$\theta_{maj}$': u.arcsec.to_string(u.format.LatexInline),
        r'$\theta_{min}$': u.arcsec.to_string(u.format.LatexInline),
        r'PA': u.deg.to_string(u.format.LatexInline),
    }
    latexdict['units'] = units

    fwtbl = wtbl[list(cols_to_keep.keys())]

    for old, new in cols_to_keep.items():
        if old in wtbl.colnames:
            #wtbl[old].meta['description'] = description[old]
            fwtbl.rename_column(old, new)
            if new in units:
                fwtbl[new].unit = units[new]

    float_cols = [
        '$\\theta_{maj}$',
        '$\\theta_{min}$',
        'BPA',
        '$S_{peak}$',
        '$\\sigma_{MAD}$',
        '$\\theta_{req}$',
        '\\sigma_{req}$',
        '$\\sigma_{MAD}/\\sigma_{req}$',
        # '$\\theta_{req}/\\theta_{maj}$',
        "$\Omega_{syn}^{1/2}/\Omega_{req}^{1/2}$",
        'DR$_{pre}$',
        'DR$_{post}$',
        'DR$_{post}$/DR$_{pre}$'
    ]

    # ALREADY IN mJy
    # convert to mJy
    #fwtbl['$\sigma_{MAD}$'] *= 1000

    formats = {
        key: lambda x: strip_trailing_zeros('{0:0.3f}'.format(round_to_n(x, 2),
                                                              nsf=2))
        for key in float_cols
    }
    formats = {
        key: lambda x: str(sigfig.round(str(x), sigfigs=2))
        for key in float_cols
    }

    fwtbl.write('selfcal_summary.ecsv', format='ascii.ecsv', overwrite=True)

    # caption needs to be *before* preamble.
    #latexdict['caption'] = 'Continuum Source IDs and photometry'
    latexdict['header_start'] = '\label{tab:selfcal}'  #\n\\footnotesize'
    latexdict[
        'preamble'] = '\caption{Selfcal Summary}\n\\resizebox{\\textwidth}{!}{'
    latexdict['col_align'] = 'l' * len(fwtbl.columns)
    latexdict['tabletype'] = 'table*'
    latexdict['tablefoot'] = (
        "}\par\n"
        "$n_{sc}$ is the number of self-calibration iterations adopted.  "
        "Those with a final iteration of amplitude self-calibration are denoted with the `a' suffix.  "
        "$\\theta_{maj}, \\theta_{min}$, and BPA give the major and minor full-width-half-maxima (FWHM) of the synthesized beams.  "
        "$\\theta_{req}$ is the requested beam size, "
        "and $\\Omega_{syn}^{1/2}/\\Omega_{req}^{1/2}$ gives the ratio of the synthesized to the "
        "requested beam area; larger numbers imply poorer resolution.  "
        "$\sigma_{MAD}$ and $\sigma_{req}$ are the measured and requested "
        "RMS sensitivity, respectively, and $\sigma_{MAD}/\sigma_{req}$ is the excess noise "
        "in the image over that requested.  $\sigma_{MAD}$ is measured on the \\texttt{cleanest} images.  "
        "$DR_{pre}$ and $DR_{post}$ are the dynamic range, $S_{peak} / \sigma_{MAD}$, for the "
        "pre- and post-self-calibration data; $DR_{post}/DR_{pre}$ gives the improvement "
        "factor.")

    fwtbl.sort(['Region', 'Band'])

    fwtbl.write(f"../datapaper/{savename}.tex",
                formats=formats,
                overwrite=True,
                latexdict=latexdict)

    return fwtbl
Example #5
0
        'bolocam_and_mgps_detected', 'atlasgal_and_mgps_detected',
        'higal_and_mgps_detected', 'cm_and_mgps_detected',
        'mm_and_mgps_detected', 'mgps_detected_mm_and_cm_nondetected',
        'mgps_and_mm_detected_cm_nondetected',
        'mgps_and_mm_detected_nocm_compact'
]:
    if colname in cont_tbl.colnames:
        cont_tbl.remove_column(colname)

formats = {
    key: lambda x: ('{0:0.2f}'.format(np.round(x, 2)))
    for key in rename_mapping.values()
}

formats.update({  #'Coordinates': lambda x: x.to_string('hmsdms', sep=":"),
    '$S_{\\nu,10\'\'}$': lambda x: strip_trailing_zeros(str(
        x)),  #'{0:0.2f}'.format(round_to_n(x,2))),
    '$S_{\\nu,15\'\'}$': lambda x: strip_trailing_zeros(str(
        x)),  #'{0:0.2f}'.format(round_to_n(x,2))),
    '$S_{bg;15-20\'\'}$': lambda x: strip_trailing_zeros(str(
        x)),  #'{0:0.2f}'.format(round_to_n(x,2))),
    '$\ell$': lambda x: ('{0:0.3f}'.format(np.round(x, 3))),
    '$b$': lambda x: ('{0:0.3f}'.format(np.round(x, 3))),
    '$\ell_G$': lambda x: ('{0:0.3f}'.format(np.round(x, 3))),
    '$b_G$': lambda x: ('{0:0.3f}'.format(np.round(x, 3))),
    'PA$_G$': lambda x: strip_trailing_zeros(str(
        x)),  # lambda x: ('{0:0.1f}'.format(np.round(x,1))),
    'FWHM$_{maj,G}$':
    lambda x: str(x),  # lambda x: ('{0:0.1f}'.format(np.round(x,1))),
    'FWHM$_{min,G}$':
    lambda x: str(x),  # lambda x: ('{0:0.1f}'.format(np.round(x,1))),
})
Example #6
0
    if 'FWHM' in key_:
        newname = "$\mathrm{FWHM}$(" + key_.split("FWHM")[1] + ")"
    if 'AMPLITUDE' in key_:
        #newname = key_.replace("AMPLITUDE","Peak")
        del depree_merged_tex[key]
        continue
    depree_merged_tex.rename_column(key, pfx + newname)

merged_tex_ok = (np.isfinite(depree_merged_tex['RA']) &
                 (np.isfinite(depree_merged_tex['V$_\\mathrm{LSR}$(41)'])
                  | np.isfinite(depree_merged_tex['V$_\\mathrm{LSR}$(52)'])
                  | np.isfinite(depree_merged_tex['V$_\\mathrm{LSR}$(66)'])))
depree_merged_tex = depree_merged_tex[merged_tex_ok]

formats = {
    key: (lambda x: (strip_trailing_zeros('{0:0.1f}'.format(round_to_n(x, 2)))
                     if not np.isnan(x) else '-')) if key[0] == 'e' else
    (lambda x: (strip_trailing_zeros('{0:0.3f}'.format(round_to_n(x, 3)))
                if not np.isnan(x) else '-'))
    for key in depree_merged_tex.colnames
}
del formats['Source']
del formats['RA']
del formats['Dec']

coords_column = coordinates.SkyCoord(depree_merged_tex['RA'],
                                     depree_merged_tex['Dec'],
                                     frame='fk5',
                                     unit=(u.deg, u.deg))
depree_merged_tex.remove_column('RA')
depree_merged_tex.remove_column('Dec')
                          "and \\texttt{-} is indeterminate (either $20<T<50$K "
                          "or no measurement).  "
                          "In column 3, \\texttt{c} indicates compact sources, "
                          "and \\texttt{-} indicates a diffuse source."
                         )
#latexdict['tablefoot'] = ('\par\nJy-Kelvin gives the conversion factor from Jy '
#                          'to Kelvin given the synthesized beam size and '
#                          'observation frequency.')
latexdict['col_align'] = 'l'*len(tbl.columns)
#latexdict['tabletype'] = 'longtable'
#latexdict['tabulartype'] = 'longtable'
latexdict['units'] = {}

formats={'RA': lambda x: '{0:0.4f}'.format(x),
         'Dec': lambda x: '{0:0.4f}'.format(x),
         '$S_{\\nu}(0.2\\arcsec)$': lambda x: strip_trailing_zeros('{0:0.2f}'.format(round_to_n(x,2))),
         '$S_{\\nu}(0.4\\arcsec)$': lambda x: strip_trailing_zeros('{0:0.2f}'.format(round_to_n(x,2))),
         '$T_{B,max}(\mathrm{line})$': lambda x: strip_trailing_zeros('{0:0.2f}'.format(round_to_n(x,2))),
         '$T_{B,max}(\mathrm{line+cont})$': lambda x: strip_trailing_zeros('{0:0.2f}'.format(round_to_n(x,2))),
         '$T_{B,max}$': lambda x: strip_trailing_zeros('{0:0.2f}'.format(round_to_n(x,2))),
         'M$(T_B, 0.2\\arcsec)$': lambda x: strip_trailing_zeros('{0:0.2f}'.format(round_to_n(x,2))),
         'M$(T_B, \mathrm{peak})$': lambda x: strip_trailing_zeros('{0:0.2f}'.format(round_to_n(x,2))),
        }

tbl_towrite.write('../paper1/photometry_table.tex',
                  latexdict=latexdict, format='ascii.latex', overwrite=True,
                  formats=formats)

latexdict['caption'] = 'Continuum Source IDs and photometry Part 2'
latexdict['header_start'] = '\label{tab:photometry2}'
tbl_towrite[35:].write('../paper1/photometry_table_2.tex',
    lambda x: "-" if np.isnan(x.ra) else "{0:0.4} {1:0.3}".format(
        x.ra.hms.s - 14, x.dec.dms.s + 30),
    'Pt RA':
    lambda x: "-" if np.isnan(x) else "{0:0.3}".format(x - 14),
    'Pt Dec':
    lambda x: "-" if np.isnan(x) else "{0:0.3}".format(x + 30),
    'ePt RA':
    lambda x: "-" if np.isnan(x) else "{0:0.4}".format(x),
    'ePt Dec':
    lambda x: "-" if np.isnan(x) else "{0:0.3}".format(x),
    'Pt Amp':
    lambda x: ('{0:0.2f}'.format(round_to_n(x, 2))),
    'ePt Amp':
    lambda x: ('{0:0.2f}'.format(round_to_n(x, 2))),
    'Pt Width':
    lambda x: strip_trailing_zeros('{0:0.2f}'.format(round_to_n(x, 2))),
    'Disk PA':
    lambda x: strip_trailing_zeros('{0:0.2f}'.format(round_to_n(x, 2))),
    'Disk FWHM':
    lambda x: strip_trailing_zeros('{0:0.2f}'.format(round_to_n(x, 2))),
    'Disk Radius':
    lambda x: strip_trailing_zeros('{0:0.2f}'.format(round_to_n(x, 2))),
    'Total Flux':
    lambda x: strip_trailing_zeros('{0:0.2f}'.format(round_to_n(x, 2))),
    'Pt Flux':
    lambda x: strip_trailing_zeros('{0:0.2f}'.format(round_to_n(x, 2))),
    'Pt \%':
    lambda x: strip_trailing_zeros('{0:0.5g}\%'.format(round_to_n(x, 2) * 100)
                                   ),
}
Example #9
0
def make_latex_table_overview(releasename='June2021', savename='res_sens'):
    if datetime.datetime.today() > datetime.datetime(
            year=2021, month=1, day=10):
        result = requests.get(
            f'https://bio.rc.ufl.edu/secure/adamginsburg/ALMA-IMF/{releasename}Release/tables/metadata_bsens_cleanest.ecsv',
            auth=('almaimf', keyring.get_password('almaimf', 'almaimf')))
        with open(f'{releasename}_metadata_bsens_cleanest.ecsv', 'w') as fh:
            fh.write(result.text)

        result = requests.get(
            'https://bio.rc.ufl.edu/secure/adamginsburg/ALMA-IMF/tables/bandpass_fraction.ecsv',
            auth=('almaimf', keyring.get_password('almaimf', 'almaimf')))
        with open('bandpass_fraction.ecsv', 'w') as fh:
            fh.write(result.text)

    result = requests.get(
        'https://data.rc.ufl.edu/secure/adamginsburg/ALMA-IMF/May2021Release/tables/uvspacings.ecsv',
        auth=('almaimf', keyring.get_password('almaimf', 'almaimf')))
    with open('uvspacings.ecsv', 'w') as fh:
        fh.write(result.text)

    bp_tbl = Table.read('bandpass_fraction.ecsv')
    bp_tbl['band'] = [f'B{b}' for b in bp_tbl['band']]
    bp_tbl.rename_column('field', 'region')
    bp_tbl = table.join(bp_tbl.group_by('config').groups[0],
                        bp_tbl.group_by('config').groups[1],
                        keys=('region', 'band'))
    bp_tbl.rename_column('bwfrac_1', '12Mlong_frac')
    bp_tbl.rename_column('bwfrac_2', '12Mshort_frac')
    bp_tbl.remove_column('config_1')
    bp_tbl.remove_column('config_2')

    uvtbl = Table.read('uvspacings.ecsv')

    tbl = table.join(Table.read(f'{releasename}_metadata_bsens_cleanest.ecsv'),
                     bp_tbl,
                     keys=('region', 'band'))
    tbl = table.join(tbl, uvtbl)
    bad = np.array(['diff' in x for x in tbl['filename']])

    # downselect (need bsens=true to avoid duplication - but be wary in case you remove duplicates upstream!)
    keep = ((tbl['suffix'] == 'finaliter') & (tbl['robust'] == 'r0.0') &
            (~tbl['pbcor']) & (tbl['bsens']) & (~tbl['nobright']) & (~bad))

    wtbl = tbl[keep]

    print(len(wtbl))
    print(wtbl)

    wtbl['selfcaliter'] = Column(
        data=[int(x[2:]) for x in wtbl['selfcaliter']])
    wtbl['bsens_div_cleanest_mad'] = wtbl['mad_sample_bsens'] / wtbl[
        'mad_sample_cleanest']
    wtbl['bsens_div_cleanest_max'] = wtbl['max_bsens'] / wtbl['max_cleanest']
    wtbl['bsens_mad_div_req'] = wtbl['mad_sample_bsens'] / wtbl[
        'Req_Sens']  # * 1e3

    wtbl['max_bsens'].unit = u.mJy / u.beam
    wtbl['max_cleanest'].unit = u.mJy / u.beam

    cols_to_keep = {
        'region': 'Region',
        'FOV_B3': 'FOV(B3)',
        'FOV_B6': 'FOV(B6)'
    }

    for band in ('B3', 'B6'):
        cols_to_keep[f'bmaj_{band}'] = f'$\\theta_{{maj}}({band})$'
        cols_to_keep[f'bmin_{band}'] = f'$\\theta_{{min}}({band})$'
        cols_to_keep[
            f'mad_sample_bsens_{band}'] = f'$\sigma_{{MAD}}$(bsens,{band})'
        cols_to_keep[
            f'mad_sample_cleanest_{band}'] = f'$\sigma_{{MAD}}$(cleanest,{band})'
        cols_to_keep[f'10%_{band}'] = f'LAS$_{{10\%}}$({band})'

    # Region &
    # FOV$_{B6}$ &	$\theta_{maj}\times\theta_{min}(B6)$ &	 $\sigma_{MAD}(cleanest)$ & $\sigma_{MAD}(bsens)$   & LAS(5\%, B6) &
    # FOV$_{B3}$ &	$\theta_{maj}\times\theta_{min}(B3)$ &	 $\sigma_{MAD}(cleanest)$ & $\sigma_{MAD}(bsens)$   & LAS(5\%, B3) \\

    cols = ['bmaj', 'bmin', '10%', 'mad_sample_bsens', 'mad_sample_cleanest']

    wtbl.add_index('region')
    wtbl.add_index('band')
    rows = []
    for region in set(wtbl['region']):
        row = {
            f'{key}_{band}': wtbl.loc['band', band].loc['region', region][key]
            for key in cols for band in ('B3', 'B6')
        }
        row['region'] = region
        row['FOV_B3'] = FOV[(region, 'B3')]
        row['FOV_B6'] = FOV[(region, 'B6')]
        rows.append(row)

    mtbl = Table(rows)

    units = {
        '$S_{peak}(bsens)$': (u.mJy / u.beam).to_string(u.format.LatexInline),
        '$S_{peak}(cleanest)$':
        (u.mJy / u.beam).to_string(u.format.LatexInline),
        '$\sigma_{MAD}(bsens,B6)$':
        (u.mJy / u.beam).to_string(u.format.LatexInline),
        '$\sigma_{MAD}(cleanes,B6)$':
        (u.mJy / u.beam).to_string(u.format.LatexInline),
        '$\sigma_{MAD}(bsens,B3)$':
        (u.mJy / u.beam).to_string(u.format.LatexInline),
        '$\sigma_{MAD}(cleanest,B3)$':
        (u.mJy / u.beam).to_string(u.format.LatexInline),
        #'$\sigma_{req}$':u.mJy.to_string(u.format.LatexInline),
        #r'$\theta_{req}$':u.arcsec.to_string(u.format.LatexInline),
        r'$\theta_{maj}(B3)$':
        u.arcsec.to_string(u.format.LatexInline),
        r'$\theta_{min}(B3)$':
        u.arcsec.to_string(u.format.LatexInline),
        r'$\theta_{maj}(B6)$':
        u.arcsec.to_string(u.format.LatexInline),
        r'$\theta_{min}(B6)$':
        u.arcsec.to_string(u.format.LatexInline),
        'LAS$_{10\%}$(B3)':
        u.arcsec.to_string(u.format.LatexInline),
        'LAS$_{10\%}$(B6)':
        u.arcsec.to_string(u.format.LatexInline),
        #r'PA':u.deg.to_string(u.format.LatexInline),
    }
    latexdict['units'] = units

    mtbl.add_column(col=[
        f'${major:0.2f}\\times{minor:0.2f}$'
        for major, minor in zip(mtbl['bmaj_B3'], mtbl['bmin_B3'])
    ],
                    name='Res. B3')
    mtbl.add_column(col=[
        f'${major:0.2f}\\times{minor:0.2f}$'
        for major, minor in zip(mtbl['bmaj_B6'], mtbl['bmin_B6'])
    ],
                    name='Res. B6')

    column_order = [
        'region',
    ]
    for band in ('B3', 'B6'):
        column_order += [
            f'FOV_{band}', f'Res. {band}', f'mad_sample_cleanest_{band}',
            f'mad_sample_bsens_{band}', f'10%_{band}'
        ]

    mtbl = mtbl[column_order]

    for old, new in cols_to_keep.items():
        if old in mtbl.colnames:
            #mtbl[old].meta['description'] = description[old]
            mtbl.rename_column(old, new)
            if new in units:
                mtbl[new].unit = units[new]

    for colname in [
            '$\sigma_{MAD}$(bsens,B3)',
            '$\sigma_{MAD}$(cleanest,B3)',
            '$\sigma_{MAD}$(bsens,B6)',
            '$\sigma_{MAD}$(cleanest,B6)',
    ]:
        mtbl[colname].unit = u.mJy / u.beam

    for colname in ('FOV(B3)', 'FOV(B6)', 'Res. B3', 'Res. B6'):
        mtbl[colname].unit = u.arcsec

    float_cols = [
        '$\\theta_{maj}(B3)$',
        '$\\theta_{min}(B3)$',
        '$\\theta_{maj}(B6)$',
        '$\\theta_{min}(B6)$',
        'LAS$_{10\%}$(B3)',
        'LAS$_{10\%}$(B6)',
        'BPA',
        '$S_{peak}$(bsens)',
        '$S_{peak}$(cleanest)',
        '$\\frac{S_{peak}(\mathrm{bsens})}{S_{peak}(\mathrm{cleanest})}$',
        '$\\sigma_{MAD}$(bsens,B3)',
        '$\\sigma_{MAD}$(cleanest,B3)',
        '$\\sigma_{MAD}$(bsens,B6)',
        '$\\sigma_{MAD}$(cleanest,B6)',
        '$\\frac{\sigma_{MAD}(\mathrm{bsens})}{\sigma_{MAD}(\mathrm{cleanest})}$',
        'Requested $\sigma$',
        '$\sigma_{\mathrm{bsens}}/\sigma_{\mathrm{req}}$',
        '$f_{BW,cleanest}$',
        #'$\\theta_{req}$',
        #'\\sigma_{req}$',
        #'$\\sigma_{req}/\\sigma_{MAD}$',
        #'$\\theta_{req}/\\theta_{maj}$',
        #'DR$_{cleanest}$',
        #'DR$_{bsens}$',
        #'DR$_{bsens}$/DR$_{cleanest}$'
    ]

    # convert to mJy
    # mtbl['$\sigma_{MAD}$(bsens)'] *= 1000
    # mtbl['$\sigma_{MAD}$(cleanest)'] *= 1000

    formats = {
        key: lambda x: strip_trailing_zeros(
            ('{0:0.3f}'.format(round_to_n(x, 2))))
        for key in float_cols
    }
    formats = {
        key: lambda x: str(sigfig.round(str(x), sigfigs=2))
        for key in float_cols
    }

    mtbl.write('overviewpapertble.ecsv', format='ascii.ecsv', overwrite=True)

    # caption needs to be *before* preamble.
    #latexdict['caption'] = 'Continuum Source IDs and photometry'
    latexdict['header_start'] = (
        '\label{tab:sensitivity_scale_overview}\n\n'
        ' & \multicolumn{5}{c}{B3} & \multicolumn{5}{c}{B6}\\\\')
    latexdict[
        'preamble'] = '\caption{Overview of sensitivity and angular scales}\n\\resizebox{\\textwidth}{!}{'
    latexdict['col_align'] = 'l|lllll|lllll|'
    latexdict['tabletype'] = 'table*'
    latexdict['tablefoot'] = ("}\par\n" "")

    mtbl.sort(['Region'])

    mtbl.write(f"../overviewpaper/tables/{savename}.tex",
               formats=formats,
               overwrite=True,
               latexdict=latexdict)

    with open(f"../overviewpaper/tables/{savename}.tex", 'r') as fh:
        lines = fh.readlines()
    with open(f"../overviewpaper/tables/{savename}.tex", 'w') as fh:
        for row in lines:
            if 'FOV(B3)' in row:
                row = row.replace('(B3)', '').replace('(B6)', '').replace(
                    ',B3', '').replace(',B6',
                                       '').replace(" B3",
                                                   "").replace(" B6", "")
            fh.write(row)

    return mtbl
Example #10
0
def make_latex_table(releasename='February2021',
                     savename='bsens_cleanest_diff'):
    if datetime.datetime.today() > datetime.datetime(
            year=2021, month=1, day=10):
        result = requests.get(
            f'https://bio.rc.ufl.edu/secure/adamginsburg/ALMA-IMF/{releasename}Release/tables/metadata_bsens_cleanest.ecsv',
            auth=('almaimf', keyring.get_password('almaimf', 'almaimf')))
        with open(f'{releasename}_metadata_bsens_cleanest.ecsv', 'w') as fh:
            fh.write(result.text)

        result = requests.get(
            'https://bio.rc.ufl.edu/secure/adamginsburg/ALMA-IMF/tables/bandpass_fraction.ecsv',
            auth=('almaimf', keyring.get_password('almaimf', 'almaimf')))
        with open('bandpass_fraction.ecsv', 'w') as fh:
            fh.write(result.text)

    bp_tbl = Table.read('bandpass_fraction.ecsv')
    bp_tbl['band'] = [f'B{b}' for b in bp_tbl['band']]
    bp_tbl.rename_column('field', 'region')
    bp_tbl = table.join(bp_tbl.group_by('config').groups[0],
                        bp_tbl.group_by('config').groups[1],
                        keys=('region', 'band'))
    bp_tbl.rename_column('bwfrac_1', '12Mlong_frac')
    bp_tbl.rename_column('bwfrac_2', '12Mshort_frac')
    bp_tbl.remove_column('config_1')
    bp_tbl.remove_column('config_2')

    tbl = table.join(Table.read(f'{releasename}_metadata_bsens_cleanest.ecsv'),
                     bp_tbl,
                     keys=('region', 'band'))
    bad = np.array(['diff' in x for x in tbl['filename']])

    # downselect (need bsens=true to avoid duplication - but be wary in case you remove duplicates upstream!)
    keep = ((tbl['suffix'] == 'finaliter') & (tbl['robust'] == 'r0.0') &
            (~tbl['pbcor']) & (tbl['bsens']) & (~tbl['nobright']) & (~bad))

    wtbl = tbl[keep]

    print(len(wtbl))
    print(wtbl)

    wtbl['selfcaliter'] = Column(
        data=[int(x[2:]) for x in wtbl['selfcaliter']])
    wtbl['bsens_div_cleanest_mad'] = wtbl['mad_sample_bsens'] / wtbl[
        'mad_sample_cleanest']
    wtbl['bsens_div_cleanest_max'] = wtbl['max_bsens'] / wtbl['max_cleanest']
    wtbl['bsens_mad_div_req'] = wtbl['mad_sample_bsens'] / wtbl[
        'Req_Sens']  # * 1e3

    wtbl['max_bsens'].unit = u.mJy / u.beam
    wtbl['max_cleanest'].unit = u.mJy / u.beam

    cols_to_keep = {
        'region': 'Region',
        'band': 'Band',
        #'selfcaliter':'$n_{sc}$',
        #'bmaj':r'$\theta_{maj}$',
        #'bmin':r'$\theta_{min}$',
        #'bpa':'BPA',
        #'Req_Res': r"$\theta_{req}$",
        #'BeamVsReq': r"$\theta_{req}/\theta_{maj}$",
        #'peak/mad': "DR",
        #'peak':'$S_{peak}$',
        'mad_sample_bsens': '$\sigma_{MAD}$(bsens)',
        'mad_sample_cleanest': '$\sigma_{MAD}$(cleanest)',
        'bsens_div_cleanest_mad':
        '$\\frac{\sigma_{MAD}(\mathrm{bsens})}{\sigma_{MAD}(\mathrm{cleanest})}$',
        '12Mshort_frac': '$f_{BW,cleanest}$',
        'max_bsens': '$S_{peak}$(bsens)',
        'max_cleanest': '$S_{peak}$(cleanest)',
        'bsens_div_cleanest_max':
        '$\\frac{S_{peak}(\mathrm{bsens})}{S_{peak}(\mathrm{cleanest})}$',
        'Req_Sens': 'Requested $\sigma$',
        'bsens_mad_div_req': '$\sigma_{\mathrm{bsens}}/\sigma_{\mathrm{req}}$',
        #'dr_cleanest': "DR$_{cleanest}$",
        #'dr_bsens': "DR$_{bsens}$",
    }

    units = {
        '$S_{peak}(bsens)$': (u.mJy / u.beam).to_string(u.format.LatexInline),
        '$S_{peak}(cleanest)$':
        (u.mJy / u.beam).to_string(u.format.LatexInline),
        '$\sigma_{MAD}(bsens)$':
        (u.mJy / u.beam).to_string(u.format.LatexInline),
        '$\sigma_{MAD}(cleanest)$':
        (u.mJy / u.beam).to_string(u.format.LatexInline),
        'Requested $\sigma$': (u.mJy / u.beam).to_string(u.format.LatexInline),
        #'$\sigma_{req}$':u.mJy.to_string(u.format.LatexInline),
        #r'$\theta_{req}$':u.arcsec.to_string(u.format.LatexInline),
        #r'$\theta_{maj}$':u.arcsec.to_string(u.format.LatexInline),
        #r'$\theta_{min}$':u.arcsec.to_string(u.format.LatexInline),
        #r'PA':u.deg.to_string(u.format.LatexInline),
    }
    latexdict['units'] = units

    wtbl = wtbl[list(cols_to_keep.keys())]

    for old, new in cols_to_keep.items():
        if old in wtbl.colnames:
            #wtbl[old].meta['description'] = description[old]
            wtbl.rename_column(old, new)
            if new in units:
                wtbl[new].unit = units[new]

    for colname in [
            '$\sigma_{MAD}$(bsens)',
            '$\sigma_{MAD}$(cleanest)',
    ]:
        wtbl[colname].unit = u.mJy / u.beam
    for colname in [
            '$S_{peak}$(bsens)',
            '$S_{peak}$(cleanest)',
    ]:
        wtbl[colname].unit = u.mJy / u.beam

    float_cols = [
        '$\\theta_{maj}$',
        '$\\theta_{min}$',
        'BPA',
        '$S_{peak}$(bsens)',
        '$S_{peak}$(cleanest)',
        '$\\frac{S_{peak}(\mathrm{bsens})}{S_{peak}(\mathrm{cleanest})}$',
        '$\\sigma_{MAD}$(bsens)',
        '$\\sigma_{MAD}$(cleanest)',
        '$\\frac{\sigma_{MAD}(\mathrm{bsens})}{\sigma_{MAD}(\mathrm{cleanest})}$',
        'Requested $\sigma$',
        '$\sigma_{\mathrm{bsens}}/\sigma_{\mathrm{req}}$',
        '$f_{BW,cleanest}$',
        #'$\\theta_{req}$',
        #'\\sigma_{req}$',
        #'$\\sigma_{req}/\\sigma_{MAD}$',
        #'$\\theta_{req}/\\theta_{maj}$',
        #'DR$_{cleanest}$',
        #'DR$_{bsens}$',
        #'DR$_{bsens}$/DR$_{cleanest}$'
    ]

    # convert to mJy
    # wtbl['$\sigma_{MAD}$(bsens)'] *= 1000
    # wtbl['$\sigma_{MAD}$(cleanest)'] *= 1000

    formats = {
        key: lambda x: strip_trailing_zeros(
            ('{0:0.3f}'.format(round_to_n(x, 2))))
        for key in float_cols
    }
    formats = {
        key: lambda x: str(sigfig.round(str(x), sigfigs=2))
        for key in float_cols
    }

    wtbl.write('bsens_cleanest_diff.ecsv', format='ascii.ecsv', overwrite=True)

    # caption needs to be *before* preamble.
    #latexdict['caption'] = 'Continuum Source IDs and photometry'
    latexdict[
        'header_start'] = '\label{tab:bsens_cleanest}'  #\n\\footnotesize'
    latexdict[
        'preamble'] = '\caption{Best Sensitivity vs Cleanest Continuum comparison}\n\\resizebox{\\textwidth}{!}{'
    latexdict['col_align'] = 'l' * len(wtbl.columns)
    latexdict['tabletype'] = 'table*'
    latexdict['tablefoot'] = (
        "}\par\n"
        "Like Table \\ref{tab:selfcal}, but comparing the cleanest and bsens data.  "
        "$\sigma_{MAD}$(bsens) and $\sigma_{MAD}$(cleanest) are the "
        "standard deviation error estimates computed from a signal-free "
        "region in the map using the Median Absolute Deviation as a "
        "robust estimator.  Their ratio shows that the broader included "
        "bandwidth increases sensitivity; $f_{BW,cleanest}$ specifies "
        "the fraction of the total bandwidth that was incorporated into "
        "the cleanest images.  "
        "$S_{peak}$ is the peak intensity in the images.")

    wtbl.sort(['Region', 'Band'])

    wtbl.write(f"../datapaper/{savename}.tex",
               formats=formats,
               overwrite=True,
               latexdict=latexdict)

    return wtbl
Example #11
0
tbl['Total Flux'].unit = u.mJy
tbl['Pt Width'].unit = u.au
tbl['Pt Flux'] *= 1000
tbl['Pt Flux'].unit = u.mJy

tbl['Disk PA'] = tbl['Disk PA'].to(u.deg)


formats = {'Pt Position': lambda x: "-" if np.isnan(x.ra) else "{0:0.4} {1:0.3}".format(x.ra.hms.s-14, x.dec.dms.s+30),
           'Pt RA': lambda x: "-" if np.isnan(x) else "{0:0.3}".format(x-14),
           'Pt Dec': lambda x: "-" if np.isnan(x) else "{0:0.3}".format(x+30),
           'ePt RA': lambda x: "-" if np.isnan(x) else "{0:0.4}".format(x),
           'ePt Dec': lambda x: "-" if np.isnan(x) else "{0:0.3}".format(x),
           'Pt Amp': lambda x: ('{0:0.2f}'.format(round_to_n(x,2))),
           'ePt Amp': lambda x: ('{0:0.2f}'.format(round_to_n(x,2))),
           'Pt Width': lambda x: strip_trailing_zeros('{0:0.2f}'.format(round_to_n(x,2))),
           'Disk PA': lambda x: strip_trailing_zeros('{0:0.2f}'.format(round_to_n(x,2))),
           'Disk FWHM': lambda x: strip_trailing_zeros('{0:0.2f}'.format(round_to_n(x,2))),
           'Disk Radius': lambda x: strip_trailing_zeros('{0:0.2f}'.format(round_to_n(x,2))),
           'Total Flux': lambda x: strip_trailing_zeros('{0:0.2f}'.format(round_to_n(x,2))),
           'Pt Flux': lambda x: strip_trailing_zeros('{0:0.2f}'.format(round_to_n(x,2))),
           'Pt \%': lambda x: strip_trailing_zeros('{0:0.5g}\%'.format(round_to_n(x,2)*100)),
          }


latexdict = latex_info.latexdict.copy()
latexdict['header_start'] = '\label{tab:continuum_fit_parameters}'
latexdict['caption'] = 'Continuum Fit Parameters'
latexdict['preamble'] = '\centering'
latexdict['tablefoot'] = ('\n\par The pointlike source '
                          'position is given as RA seconds and Dec arcseconds '