def main(pargs): """ Run """ import json from linetools import utils as ltu from linetools.scripts.utils import coord_arg_to_coord from frb.galaxies import nebular from frb import mw from frb.surveys import survey_utils # Deal with coord icoord = ltu.radec_to_coord(coord_arg_to_coord(pargs.coord)) # EBV EBV = nebular.get_ebv(icoord)['meanValue'] # AV = EBV * 3.1 # RV print("AV = {}".format(AV)) # NE 2001 DM_ISM = mw.ismDM(icoord) print(f"NE2001 = {DM_ISM}") # Surveys print("Checking the imaging surveys...") inside = survey_utils.in_which_survey(icoord) print(inside)
def main(args, unit_test=False, **kwargs): """ Run """ import numpy as np from astropy import units as u from specdb.utils import load_db from specdb import group_utils from linetools.scripts.utils import coord_arg_to_coord # init Specdb = load_db(args.dbase, db_file=args.db_file, **kwargs) # Grab icoord = coord_arg_to_coord(args.coord) if args.group is not None: groups=[args.group] else: groups = None meta = Specdb.meta_from_position(icoord, args.tol*u.arcsec, groups=groups) if unit_test: return meta # Outcome if meta is None: print("No source found within the data groups, try another location or a larger tolerance.") return else: group_utils.show_group_meta(meta, idkey=Specdb.idkey, show_all_keys=False)
def main(args, unit_test=False, **kwargs): """ Run """ import numpy as np from astropy import units as u from specdb.utils import load_db from linetools.scripts.utils import coord_arg_to_coord # init Specdb = load_db(args.dbase, db_file=args.db_file, **kwargs) # Grab icoord = coord_arg_to_coord(args.coord) if args.group is not None: groups = [args.group] else: groups = None spec, meta = Specdb.spectra_from_coord(icoord, tol=args.tol * u.arcsec, groups=groups) # Outcome if meta is None: print("No source found, try another location or a larger tolerance.") return elif len(meta) == 1: # One group hit print("Source located in group: {:s}".format(meta['GROUP'][0])) else: # More than 1 spectrum print( "More than 1 spectrum found for input source. Here is a summary:") #meta = all_meta[idx] #groups = [meta.meta['group'] for meta in all_meta] #print("Using group {:s}. You can choose from this list {}".format(groups[idx], groups)) indices = np.arange(len(meta)).astype(int) meta['INDEX'] = indices print(meta[[ 'INDEX', 'GROUP', 'RA_GROUP', 'DEC_GROUP', Specdb.idkey, 'INSTR', 'DISPERSER', 'GROUP_ID' ]]) idx = args.select print( "Plotting index={:d} which you can specify with --select".format(idx)) #if args.meta: # group_utils.show_group_meta(meta) # Load spectra spec.select = args.select if unit_test: return # Add labels lbls = [] for imeta in meta: lbls.append('{:d}_{:s}'.format(imeta['INDEX'], imeta['GROUP'])) spec.labels = lbls # Show if args.mplot: spec.plot() else: spec.plot(xspec=True)
def main(args=None): from linetools.scripts.utils import coord_arg_to_coord from linetools import utils as ltu from astropy.io import fits, ascii from astropy.coordinates import SkyCoord import astropy.units as u from pyntejos.catalogs import add_radec_deg_columns pargs = parser(options=args) # RA,DEC icoord = coord_arg_to_coord(pargs.radec) coord = ltu.radec_to_coord(icoord) # define catalog print('Reading {} catalog'.format(pargs.catalog)) if pargs.catalog == 'QSO': # read qsos from MILLIQUAS catalog col_names = [ 'ra_d', 'dec_d', 'name', 'description', 'rmag', 'bmag', 'comment', 'psf_r', 'psf_b', 'z', 'cite', 'zcite', 'qso_prob', 'Xname', 'Rname', 'Lobe1', 'Lobe2' ] cat = ascii.read( '/media/ntejos/disk1/catalogs/qsos/milliquas/milliquas.txt', format='fixed_width', names=col_names) elif pargs.catalog == 'GC': # read MW globular cluster catalog cat = ascii.read( '/media/ntejos/disk1/catalogs/globular_clusters/mwgc10_1.dat', format='fixed_width') # add ra_d, dec_d columns cat = add_radec_deg_columns(cat) else: print(' Not implemented for such catalog.') return # cross-match print('Cross-matching...') cat_coords = SkyCoord(cat['ra_d'], cat['dec_d'], unit='deg') seplim = pargs.angsep * u.arcmin sep2d = coord.separation(cat_coords) cond = sep2d <= seplim cat = cat[cond] if len(cat) < 1: print("No matches found.") else: cat['sep2d'] = sep2d[cond] if pargs.redshift is not None: from astropy.cosmology import Planck15 as cosmo import pdb pdb.set_trace() sep = (cosmo.kpc_comoving_per_arcmin(float(pargs.redshift)) * cat['sep2d']).to('Mpc') cat['sep_mpc'] = sep.value cat.sort('sep2d') print(cat)
def main(pargs): """ Run """ import numpy as np from linetools import utils as ltu from linetools.scripts.utils import coord_arg_to_coord from frb import mw from frb.dm import prob_dmz # Deal with coord icoord = ltu.radec_to_coord(coord_arg_to_coord(pargs.coord)) # NE 2001 DM_ISM = mw.ismDM(icoord) print("") print("-----------------------------------------------------") print(f"NE2001 = {DM_ISM:.2f}") # DM Cosmic DM_cosmic = pargs.DM_FRB - DM_ISM.value - pargs.dm_hostmw # Redshift estimates # Load sdict = prob_dmz.grab_repo_grid() PDM_z = sdict['PDM_z'] z = sdict['z'] DM = sdict['DM'] # Do it iDM = np.argmin(np.abs(DM - DM_cosmic)) PzDM = PDM_z[iDM, :] / np.sum(PDM_z[iDM, :]) cum_sum = np.cumsum(PzDM) limits = pargs.cl z_min = z[np.argmin(np.abs(cum_sum - limits[0] / 100.))] z_max = z[np.argmin(np.abs(cum_sum - limits[1] / 100.))] # Finish print("") print(f"The redshift range for your confidence interval {pargs.cl} is:") print(f"z = [{z_min:.3f}, {z_max:.3f}]") return z_min, z_max
def main(pargs): """ Run """ import warnings import numpy as np from matplotlib import pyplot as plt from astropy.io import fits from astropy import units from frb import frb from frb.figures import galaxies as ffgal from frb.figures import utils as ffutils from linetools.scripts.utils import coord_arg_to_coord # Load up hdu = fits.open(pargs.fits_file) icoord = coord_arg_to_coord(pargs.frb_coord) # Parse if pargs.vmnx is not None: tstr = pargs.vmnx.split(',') vmnx = (float(tstr[0]), float(tstr[1])) else: vmnx = (None, None) # Dummy FRB object FRB = frb.FRB('TMP', icoord, 0.) FRB.set_ee(1.0, 1.0, 0., 95.) fig = plt.figure(figsize=(7, 7)) ffutils.set_mplrc() ffgal.sub_image(fig, hdu, FRB, vmnx=vmnx, cmap='gist_heat', frb_clr='white', imsize=pargs.imsize) #img_center=HG190608.coord, # Layout and save plt.tight_layout(pad=0.2, h_pad=0.1, w_pad=0.1) plt.savefig(pargs.outfile, dpi=300) plt.close() print('Wrote {:s}'.format(pargs.outfile))
def main(args=None): from linetools.scripts.utils import coord_arg_to_coord from linetools import utils as ltu from astropy.io import fits, ascii from astropy.coordinates import SkyCoord import astropy.units as u from pyntejos.catalogs import add_radec_deg_columns pargs = parser(options=args) # RA,DEC icoord = coord_arg_to_coord(pargs.radec) coord = ltu.radec_to_coord(icoord) # define catalog print('Reading {} catalog'.format(pargs.catalog)) if pargs.catalog == 'QSO': # read qsos from MILLIQUAS catalog col_names = ['ra_d', 'dec_d', 'name', 'description', 'rmag', 'bmag', 'comment', 'psf_r', 'psf_b', 'z', 'cite', 'zcite', 'qso_prob', 'Xname', 'Rname', 'Lobe1', 'Lobe2'] cat = ascii.read('/media/ntejos/disk1/catalogs/qsos/milliquas/milliquas.txt', format='fixed_width', names=col_names) elif pargs.catalog == 'GC': # read MW globular cluster catalog cat = ascii.read('/media/ntejos/disk1/catalogs/globular_clusters/mwgc10_1.dat', format='fixed_width') # add ra_d, dec_d columns cat = add_radec_deg_columns(cat) else: print(' Not implemented for such catalog.') return # cross-match print('Cross-matching...') cat_coords = SkyCoord(cat['ra_d'], cat['dec_d'], unit='deg') seplim = pargs.angsep * u.arcmin sep2d = coord.separation(cat_coords) cond = sep2d <= seplim cat = cat[cond] if len(cat) < 1: print("No matches found.") else: cat['sep2d'] = sep2d[cond] if pargs.redshift is not None: from astropy.cosmology import Planck15 as cosmo import pdb; pdb.set_trace() sep = (cosmo.kpc_comoving_per_arcmin(float(pargs.redshift)) * cat['sep2d']).to('Mpc') cat['sep_mpc'] = sep.value cat.sort('sep2d') print(cat)
def main(args, unit_test=False, **kwargs): """ Run """ import numpy as np from astropy import units as u from specdb.utils import load_db from specdb import group_utils from linetools.scripts.utils import coord_arg_to_coord # init Specdb = load_db(args.dbase, db_file=args.db_file, **kwargs) # Grab icoord = coord_arg_to_coord(args.coord) # Cut down using source catalog matches, sub_cat, IDs = Specdb.qcat.query_position(icoord, args.tol * u.arcsec) print(sub_cat['RA', 'DEC', 'zem', 'flag_group', 'STYPE'])
def main(pargs): """ Run """ import json import os import numpy as np from pkg_resources import resource_filename from linetools import utils as ltu from linetools.scripts.utils import coord_arg_to_coord from frb.galaxies import nebular from frb.galaxies import photom from frb.galaxies import utils as frb_gal_u from frb import mw from frb.dm import prob_dmz # Deal with coord icoord = ltu.radec_to_coord(coord_arg_to_coord(pargs.coord)) # EBV EBV = nebular.get_ebv(icoord)['meanValue'] # print(f"EBV = {EBV}") # NE 2001 DM_ISM = mw.ismDM(icoord) print(f"NE2001 = {DM_ISM}") # DM Cosmic DM_cosmic = pargs.DM_FRB - DM_ISM.value - pargs.dm_hostmw # Redshift estimates # Load sdict = prob_dmz.grab_repo_grid() PDM_z = sdict['PDM_z'] z = sdict['z'] DM = sdict['DM'] # Do it iDM = np.argmin(np.abs(DM - DM_cosmic)) PzDM = PDM_z[iDM, :] / np.sum(PDM_z[iDM, :]) cum_sum = np.cumsum(PzDM) limits = [10, 90] z_min = z[np.argmin(np.abs(cum_sum - limits[0] / 100.))] z_max = z[np.argmin(np.abs(cum_sum - limits[1] / 100.))] # Setup Luminosity # Extinction correct dust_correct = photom.extinction_correction(pargs.filter, EBV) mag_dust = 2.5 * np.log10(1. / dust_correct) mag_corr = pargs.mag_limit + mag_dust # ##########################3 # Convert to L # Load f_mL f_mL = frb_gal_u.load_f_mL() # m_r(L*) m_r_Lstar_min = float(f_mL(z_min)) m_r_Lstar_max = float(f_mL(z_max)) frac_Lstar_min = 10**(-0.4 * (mag_corr - m_r_Lstar_min)) frac_Lstar_max = 10**(-0.4 * (mag_corr - m_r_Lstar_max)) # Finish print("-----------------------------------------------------") print( f"For z_{limits[0]}={z_min:.2f}, the limiting magnitude corresponds to L={frac_Lstar_min:.5f}L*" ) print( f"For z_{limits[1]}={z_max:.2f}, the limiting magnitude corresponds to L={frac_Lstar_max:.5f}L*" ) return frac_Lstar_min, frac_Lstar_max
def main(pargs): """ Run """ import warnings import numpy as np from astropy import units from frb import frb from frb.galaxies import utils as gutils from linetools.scripts.utils import coord_arg_to_coord try: from specdb import group_utils except ImportError: print("You need to first install specdb") return # Load it up specDB = gutils.load_specdb(specdb_file=pargs.specdb) if specDB is None: return if pargs.coord[0:3].upper() == 'FRB': frb = frb.FRB.by_name(pargs.coord.upper()) icoord = frb.coord.ra.value, frb.coord.dec.value else: icoord = coord_arg_to_coord(pargs.coord) # Meta? if pargs.cat: if pargs.ang_offset is not None: _, cat, _ = specDB.qcat.query_position( icoord, pargs.ang_offset * units.arcsec) else: _, cat, _ = specDB.qcat.query_position(icoord, pargs.rho * units.kpc) # Show ckeys = ['RA', 'DEC', 'zem', 'ZQ'] group_utils.show_group_meta(cat, show_all_keys=False, meta_keys=ckeys) else: # Meta if pargs.ang_offset is not None: meta = specDB.meta_from_position(icoord, pargs.ang_offset * units.arcsec) else: meta = specDB.meta_from_position(icoord, pargs.rho * units.kpc) # Keys mkeys = ['GROUP', 'RA_GROUP', 'DEC_GROUP', 'zem_GROUP', 'ZQ', 'Ref'] # Show if meta is None: print( "No source found, try another location or a larger tolerance.") return else: group_utils.show_group_meta( meta, show_all_keys=False, meta_keys=mkeys) #, max_lines=10000000) # Plot if pargs.plot: if pargs.cat: print("Cannot mix --plot with --cat. Try again!") return plot_spec(specDB, meta, frb=frb)