Exemplo n.º 1
0
def load_specdb(specdb_file=None):
    """
    Automatically load the specDB file from $SPECDB/FRB_specDB.hdf5

    Args:
        specdb_file (str, optional):
            Over-ride the default file

    Returns:
        specdb.specdb.SpecDB:

    """
    if not flg_specdb:
        raise IOError("You must install the specdb package first!")
        return
    if specdb_file is None:
        if os.getenv('SPECDB') is None:
            raise IOError("You must set the SPECDB environmental variable")
        specdb_files = glob.glob(
            os.path.join(os.getenv('SPECDB'), 'FRB_specDB_*.hdf5'))
        if len(specdb_files) > 0:
            specdb_file = specdb_files[0]
            print("Loading spectra from {:s}".format(specdb_file))
        else:
            raise IOError(
                "There are no FRB_specdb.hdf5 files in your SPECDB folder")
    # Load it up
    specDB = SpecDB(db_file=specdb_file)
    # Return
    return specDB
Exemplo n.º 2
0
def load_db(db_type, **kwargs):
    """
    Parameters
    ----------
    db_type : str
      Type of database
      Current allowed entries are [igmspec]


    Returns
    -------
    dbobj : SpecDB object
      Generally a child

    """
    if db_type == 'igmspec':
        from specdb.specdb import IgmSpec
        Specdb = IgmSpec(**kwargs)
    elif db_type == 'uvqs':
        from specdb.specdb import UVQS
        Specdb = UVQS(**kwargs)
    elif db_type == 'priv':  # Private
        from specdb.specdb import SpecDB
        Specdb = SpecDB(**kwargs)
    else:
        raise IOError("Not ready for this dbase value: {:s}".format(db_type))

    # Return
    return Specdb
Exemplo n.º 3
0
def test_load_group():
    db_file = data_path('IGMspec_DB_{:s}_debug.hdf5'.format(version))
    # Instantiate
    sdb = SpecDB(db_file=db_file)
    # Load a DB
    sdb['BOSS_DR12']
    assert 'BOSS_DR12' in sdb._gdict.keys()
    # Try meta
    assert isinstance(sdb['BOSS_DR12'].meta, Table)
Exemplo n.º 4
0
def load_specb(specdb_file):
    """
    Load a specdb_file

    Parameters
    ----------
    specdb_file: str
      Full path to the specdb file

    Returns
    -------
    spdb: SpecDB or None
      Returns None if specdb cannot be imported

    """
    # Required import?
    if not flg_specdb:
        return None
    #
    spdb = SpecDB(db_file=specdb_file)
    return spdb
Exemplo n.º 5
0
def main(*args, **kwargs):
    """ Runs the XAbsSysGui on input files
    """
    import argparse

    parser = argparse.ArgumentParser(description='Parse for XAbsSys')
    parser.add_argument("spec_file", type=str, help="Spectral file")
    parser.add_argument("abssys_file", type=str, help="AbsSys file (JSON)")
    parser.add_argument("-outfile", type=str, help="Output filename")
    parser.add_argument("-llist", type=str, help="Name of LineList")
    #parser.add_argument("-exten", type=int, help="FITS extension")
    parser.add_argument("--specdb",
                        help="Spectral file is a SPECDB database",
                        action="store_true")
    parser.add_argument("--group", type=str, help="SPECDB group name")
    parser.add_argument("--un_norm",
                        help="Spectrum is NOT normalized",
                        action="store_true")
    parser.add_argument(
        "--chk_z",
        help="Check the z limits of your components? [default=False]",
        action="store_true")

    pargs = parser.parse_args()

    from PyQt5.QtWidgets import QApplication
    from linetools.guis.xabssysgui import XAbsSysGui
    from linetools.isgm.io import abssys_from_json
    from IPython import embed

    # Normalized?
    norm = True
    if pargs.un_norm:
        norm = False

    # Extension
    #exten = (pargs.exten if hasattr(pargs, 'exten') else 0)

    # Read spec keywords
    rsp_kwargs = {}

    # Line list
    if pargs.llist is not None:
        from linetools.lists.linelist import LineList
        llist = LineList(pargs.llist)
    else:
        llist = None

    # Read AbsSystem
    from linetools.isgm.abssystem import GenericAbsSystem
    abs_sys = GenericAbsSystem.from_json(pargs.abssys_file)  #, chk_vel=False)
    if not pargs.chk_z:
        warnings.warn(
            "Not checking your system's velocity limits.  This is the Default but be so warned."
        )
    abs_sys = GenericAbsSystem.from_json(pargs.abssys_file, chk_z=pargs.chk_z)
    if len(abs_sys.list_of_abslines()) == 0:
        warnings.warn(
            "No absorption lines given.  I hope you intended that to be the case!"
        )

    app = QApplication(sys.argv)

    # Load spectrum using specdb?
    if pargs.specdb:
        # Instantiate
        from specdb.specdb import SpecDB
        from specdb import group_utils
        sdb = SpecDB(db_file=pargs.spec_file)
        # Grab spectrum
        if pargs.group is not None:
            groups = [pargs.group]
        else:
            groups = None
        spec, meta = sdb.spectra_from_coord(abs_sys.coord, groups=groups)
        if spec.nspec > 1:
            group_utils.show_group_meta(meta,
                                        idkey=sdb.idkey,
                                        show_all_keys=False)
            raise ValueError(
                "Retreived more than 1 spectrum.  Choose your GROUP with --group="
            )
        spec_file = pargs.spec_file + '_{:s}'.format(meta['GROUP'][0])
    else:
        spec = pargs.spec_file
        spec_file = pargs.spec_file
    # Save spectrum filename to AbsSystem
    abs_sys.spec_file = spec_file

    # Run
    gui = XAbsSysGui(spec,
                     abs_sys,
                     norm=norm,
                     llist=llist,
                     outfil=pargs.outfile)
    gui.show()
    app.exec_()
Exemplo n.º 6
0
def test_init():
    db_file = data_path('IGMspec_DB_{:s}_debug.hdf5'.format(version))
    # Instantiate
    sdb = SpecDB(db_file=db_file)
    assert 'BOSS_DR12' in sdb.groups