Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
def main(args, unit_test=False, **kwargs):
    """ Run
    """
    import numpy as np
    import pdb

    from specdb.utils import load_db

    # init
    if args.dbase not in ['igmspec']:
        raise IOError("Not prepared for this database: {:s}".format(
            args.dbase))
    Specdb = load_db(args.dbase, **kwargs)

    if args.survey is None:
        surveys = ['SDSS_DR7']
        for group in Specdb.groups:
            if 'BOSS_DR' in group:
                surveys += [group]
    else:
        surveys = [args.survey]

    # Load
    spec, meta = Specdb.get_sdss(args.plate, args.fiberid, groups=surveys)
    if spec is None:
        if meta == -1:
            return

    # Outcome
    if len(meta) == 0:
        print("No source found, try another location or a larger tolerance.")
        return
    elif len(meta) == 1:  # One survey hit
        pass
    else:  # More than 1 survey
        surveys = [meta['GROUP'] for row in meta]
        print("Source located in more than one SDSS survey")
    indices = np.arange(len(meta)).astype(int)
    meta['INDEX'] = indices
    print(meta[[
        'INDEX', 'GROUP', 'RA_GROUP', 'DEC_GROUP', Specdb.idkey, 'INSTR',
        'DISPERSER', 'GROUP_ID'
    ]])

    # Add labels
    lbls = []
    for imeta in meta:
        lbls.append('{:d}_{:s}'.format(imeta['INDEX'], imeta['GROUP']))
    spec.labels = lbls
    # Load spectra
    spec.select = args.select
    if unit_test:
        return
    # Show  [may transition to xspec]
    if args.plot:
        spec.plot(xspec=True)
Ejemplo n.º 4
0
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'])
Ejemplo n.º 5
0
def main(args, unit_test=False, **kwargs):
    """ Run
    """
    import numpy as np
    from astropy.table import vstack
    from astropy.coordinates import SkyCoord
    from astropy import units as u

    from specdb.utils import load_db
    from specdb import group_utils

    # init
    Specdb = load_db(args.dbase, **kwargs)

    # Load meta table(s)
    if args.survey is None:
        surveys = ['BOSS_DR12', 'SDSS_DR7']
    else:
        surveys = [args.survey]
    for kk, survey in enumerate(surveys):
        meta = Specdb[survey].meta
        if 'FIBERID' not in meta.keys():
            meta.rename_column('FIBER', 'FIBERID')
        if kk > 0:
            mtbl = vstack([mtbl, meta], join_type='inner')
        else:
            mtbl = meta

    # Find plate/fiber
    imt = np.where((mtbl['PLATE'] == args.plate)
                   & (mtbl['FIBERID'] == args.fiberid))[0]
    if len(imt) == 0:
        print("Plate and Fiber not found.  Try again")
        return
    else:
        mt = imt[0]
        scoord = SkyCoord(ra=mtbl['RA_GROUP'][mt],
                          dec=mtbl['DEC_GROUP'][mt],
                          unit='deg')

    # Grab
    print("Grabbing data for J{:s}{:s}".format(
        scoord.ra.to_string(unit=u.hour, sep='', pad=True),
        scoord.dec.to_string(sep='', pad=True, alwayssign=True)))
    spec, meta = Specdb.spectra_from_coord(scoord, groups=surveys)

    # Outcome
    if len(meta) == 0:
        print("No source found, try another location or a larger tolerance.")
        return
    elif len(meta) == 1:  # One survey hit
        pass
    else:  # More than 1 survey
        pdb.set_trace()
        idx = 0
        spec = all_spec[idx]
        meta = all_meta[idx]
        surveys = [meta.meta['group'] for meta in all_meta]
        print("Source located in more than one SDSS survey")
        print("Using survey {:s}".format(surveys[idx]))
        print("You can choose from this list {}".format(surveys))

    #group_utils.show_group_meta(meta)

    # Load spectra
    spec.select = args.select
    if unit_test:
        return
    # Show  [may transition to xspec]
    if args.plot:
        spec.plot(xspec=True)