Beispiel #1
0
def main(args, unit_test=False):
    """ Runs the XSpecGui on an input file
    """
    import sys
    import pdb

    # List only?
    if args.list:
        from astropy.io import fits
        print("Showing object names for input file...")
        hdu = fits.open(args.file)
        for ii in range(1,len(hdu)):
            name = hdu[ii].name
            print("EXT{:07d} = {}".format(ii, name))
        sys.exit()

    from linetools.guis.xspecgui import XSpecGui
    from pypit import arload

    # Load spectrum
    spec = arload.load_1dspec(args.file, exten=args.exten, extract=args.extract,
                              objname=args.obj, flux=args.flux)

    if unit_test is False:
        from PyQt5.QtWidgets import QApplication
        app = QApplication(sys.argv)
        # Screen dimensions
        width = app.desktop().screenGeometry().width()
        scale = 2. * (width/3200.)

    gui = XSpecGui(spec, unit_test=unit_test, screen_scale=scale)
    if unit_test is False:
        gui.show()
        app.exec_()
Beispiel #2
0
    def main(args):
        """ Runs the XSpecGui on an input file
        """
        import sys
        import numpy as np

        from qtpy.QtWidgets import QApplication

        from linetools.guis.xspecgui import XSpecGui

        from pypeit import specobjs
        from pypeit import msgs

        sobjs = specobjs.SpecObjs.from_fitsfile(args.file, chk_version=False)

        # List only?
        if args.list:
            print("Showing object names for input file...")
            for ii in range(len(sobjs)):
                line = "EXT{:07d} = {}".format(ii + 1, sobjs[ii].NAME)
                if sobjs[ii].RA is not None:
                    line += " {:0.5f} {:0.5f} {:s}".format(
                        sobjs[ii].RA, sobjs[ii].DEC, sobjs[ii].MASKDEF_OBJNAME)
                if sobjs[ii].MASKDEF_EXTRACT is not None and sobjs[
                        ii].MASKDEF_EXTRACT is True:
                    line += " maskdef_extract"
                if sobjs[ii].hand_extract_flag is True:
                    line += " manual_extract"
                #
                print(line)
            return

        if args.obj is not None:
            exten = np.where(sobjs.NAME == args.obj)[0][0]
            if exten < 0:
                msgs.error("Bad input object name: {:s}".format(args.obj))
        else:
            exten = args.exten - 1  # 1-index in FITS file

        # Check Extraction
        if args.extract == 'OPT':
            if sobjs[exten][
                    'OPT_WAVE'] is None:  #not in sobjs[exten]._data.keys():
                msgs.error(
                    "Spectrum not extracted with OPT.  Try --extract BOX")

        spec = sobjs[exten].to_xspec1d(extraction=args.extract,
                                       fluxed=args.flux)

        # Setup
        app = QApplication(sys.argv)
        # Screen dimensions
        width = app.screens()[0].geometry().width()
        scale = 2. * (width / 3200.)

        # Launch
        gui = XSpecGui(spec)  #, screen_scale=scale)
        gui.show()
        app.exec_()
Beispiel #3
0
def main(args, unit_test=False):
    """ Runs the XSpecGui on an input file
    """

    import sys
    import pdb

    from astropy.io import fits
    from PyQt5.QtWidgets import QApplication

    from linetools.guis.xspecgui import XSpecGui

    from pypeit import specobjs
    from pypeit import msgs

    from IPython import embed

    sobjs = specobjs.SpecObjs.from_fitsfile(args.file)

    # List only?
    if args.list:
        print("Showing object names for input file...")
        for ii in range(len(sobjs)):
            name = sobjs[ii].name
            print("EXT{:07d} = {}".format(ii + 1, name))
        return

    # Load spectrum
    if args.obj is not None:
        exten = sobjs.name.index(args.obj)
        if exten < 0:
            msgs.error("Bad input object name: {:s}".format(args.obj))
    else:
        exten = args.exten - 1  # 1-index in FITS file

    # Check Extraction
    if args.extract == 'OPT':
        if 'OPT_WAVE' not in sobjs[exten]._data.keys():
            msgs.error("Spectrum not extracted with OPT.  Try --extract=BOX")

    # XSpectrum1D
    spec = sobjs[exten].to_xspec1d(extraction=args.extract, fluxed=args.flux)

    if unit_test is False:
        app = QApplication(sys.argv)
        # Screen dimensions
        width = app.desktop().screenGeometry().width()
        scale = 2. * (width / 3200.)

    gui = XSpecGui(spec, unit_test=unit_test, screen_scale=scale)
    if unit_test is False:
        gui.show()
        app.exec_()
Beispiel #4
0
def main(args):
    """ Runs the XSpecGui on an input file
    """

    try:
        sobjs = specobjs.SpecObjs.from_fitsfile(args.file)
    except:
        # place holder until coadd data model is sorted out
        wave, flux, flux_ivar, flux_mask, meta_spec, head = general_spec_reader(
            args.file)
        spec = XSpectrum1D.from_tuple(
            (wave * u.AA, flux, np.sqrt(utils.inverse(flux_ivar))),
            masking='none')
    else:
        # List only?
        if args.list:
            print("Showing object names for input file...")
            for ii in range(len(sobjs)):
                name = sobjs[ii].NAME
                print("EXT{:07d} = {}".format(ii + 1, name))
            return

        if args.obj is not None:
            exten = sobjs.name.index(args.obj)
            if exten < 0:
                msgs.error("Bad input object name: {:s}".format(args.obj))
        else:
            exten = args.exten - 1  # 1-index in FITS file

        # Check Extraction
        if args.extract == 'OPT':
            if 'OPT_WAVE' not in sobjs[exten]._data.keys():
                msgs.error(
                    "Spectrum not extracted with OPT.  Try --extract=BOX")

        spec = sobjs[exten].to_xspec1d(extraction=args.extract,
                                       fluxed=args.flux)

    # Setup
    app = QApplication(sys.argv)
    # Screen dimensions
    width = app.desktop().screenGeometry().width()
    scale = 2. * (width / 3200.)

    # Launch
    gui = XSpecGui(spec, screen_scale=scale)
    gui.show()
    app.exec_()
Beispiel #5
0
def main(*args, **kwargs):
    """ Runs the XSpecGui on an input file
    """
    import argparse

    parser = argparse.ArgumentParser(description='Parse')
    parser.add_argument("file", type=str, help="Spectral file")
    parser.add_argument("--list", default=False, help="List the extensions only?", action="store_true")
    parser.add_argument("--exten", type=int, help="FITS extension")
    parser.add_argument("--optimal", default=False,
                        help="Show Optimal? Default is boxcar", action="store_true")

    pargs = parser.parse_args()


    # List?
    if pargs.list:
        from astropy.io import fits
        hdu = fits.open(pargs.file)
        print(hdu.info())
        return

    from PyQt4 import QtGui
    from linetools.guis.xspecgui import XSpecGui

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

    # Read spec keywords
    rsp_kwargs = {}
    if pargs.optimal:
        rsp_kwargs['wave_tag'] = 'opt_wave'
        rsp_kwargs['flux_tag'] = 'opt_counts'
        rsp_kwargs['var_tag'] = 'opt_var'
    else:
        rsp_kwargs['wave_tag'] = 'box_wave'
        rsp_kwargs['flux_tag'] = 'box_counts'
        rsp_kwargs['var_tag'] = 'box_var'

    app = QtGui.QApplication(sys.argv)

    gui = XSpecGui(pargs.file, exten=exten, rsp_kwargs=rsp_kwargs)
    gui.show()
    app.exec_()
Beispiel #6
0
def main(args):
    """ Runs the XSpecGui on an input file
    """

    sobjs = specobjs.SpecObjs.from_fitsfile(args.file)
    # List only?
    if args.list:
        print("Showing object names for input file...")
        for ii in range(len(sobjs)):
            name = sobjs[ii].NAME
            print("EXT{:07d} = {}".format(ii + 1, name))
        return

    if args.obj is not None:
        exten = np.where(sobjs.NAME == args.obj)[0][0]
        if exten < 0:
            msgs.error("Bad input object name: {:s}".format(args.obj))
    else:
        exten = args.exten - 1  # 1-index in FITS file

    # Check Extraction
    if args.extract == 'OPT':
        if sobjs[exten]['OPT_WAVE'] is None:  #not in sobjs[exten]._data.keys():
            msgs.error("Spectrum not extracted with OPT.  Try --extract=BOX")

    spec = sobjs[exten].to_xspec1d(extraction=args.extract, fluxed=args.flux)

    # Setup
    app = QApplication(sys.argv)
    # Screen dimensions
    width = app.desktop().screenGeometry().width()
    scale = 2. * (width / 3200.)

    # Launch
    gui = XSpecGui(spec, screen_scale=scale)
    gui.show()
    app.exec_()
Beispiel #7
0
def main(*args, **kwargs):
    """ Runs the XSpecGui on an input file
    """
    import argparse

    parser = argparse.ArgumentParser(description='Parser for lt_xspec v1.2; \n Note: Extra arguments are passed to read_spec (e.g. --flux_tag=FX)')
    parser.add_argument("file", type=str, help="Spectral file; specify extension by appending #exten#")
    parser.add_argument("-guessfile", "--guessfile", type=str, help="Igmguesses file, see https://github.com/pyigm/pyigm/blob/master/docs/igmguesses.rst ")
    parser.add_argument("-z", "--zsys", type=float, help="System Redshift")
    parser.add_argument("--norm", help="Show spectrum continuum normalized (if continuum is provided)",
                        action="store_true")
    parser.add_argument("--air", default=False, help="Convert input spectrum wavelengths from air to vacuum", action="store_true")
    parser.add_argument("--exten", type=int, help="FITS extension")
    parser.add_argument("--splice", type=str, help="Splice with the input file; extension convention applies")
    parser.add_argument("--scale", type=float, help="Scale factor for GUI size [1. is default]")
    #parser.add_argument("--wave_tag", type=str, help="Tag for wave in Table")
    #parser.add_argument("--flux_tag", type=str, help="Tag for flux in Table")
    #parser.add_argument("--sig_tag", type=str, help="Tag for sig in Table")
    #parser.add_argument("--var_tag", type=str, help="Tag for var in Table")
    #parser.add_argument("--ivar_tag", type=str, help="Tag for ivar in Table")

    #pargs = parser.parse_args()
    pargs, unknown = parser.parse_known_args()

    from PyQt5.QtWidgets import QApplication
    from linetools.guis.xspecgui import XSpecGui

    # Normalized?
    if pargs.norm is True:
        norm = True
    else:
        norm = False

    # Extension
    file = pargs.file
    if pargs.file[-1] == '#':
        prs = pargs.file.split('#')
        exten = int(prs[1])
        file = prs[0]
    else:
        exten = (pargs.exten if hasattr(pargs, 'exten') else 0)

    # zsys
    zsys = (pargs.zsys if hasattr(pargs, 'zsys') else None)

    # guesses
    guessfile = (pargs.guessfile if hasattr(pargs, 'guessfile') else None)


    # Splice?
    if pargs.splice is not None:
        pdb.set_trace()
        if pargs.splice[-1] == '#':
            prs = pargs.splice.split('#')
            exten = [exten, int(prs[1])]
            file = [file, prs[0]]
        else:
            exten = [exten, None]
            file = [file, pargs.splice]


    # Read spec keywords
    rsp_kwargs = {}
    for arg in unknown:
        spl = arg.split('=')
        rsp_kwargs[spl[0][2:]] = spl[1]

    # GUI
    app = QApplication(sys.argv)

    # Scale
    if pargs.scale is None:
        # Screen dimensions
        width = app.desktop().screenGeometry().width()
        scale = 2. * (width/3200.)
    else:
        scale = pargs.scale
    #
    gui = XSpecGui(file, guessfile=guessfile, zsys=zsys, norm=norm, exten=exten,
                   rsp_kwargs=rsp_kwargs, air=pargs.air,
                   screen_scale=scale)
    gui.show()
    app.exec_()
Beispiel #8
0
def main(*args, **kwargs):
    """ Runs the XSpecGui on an input file
    """
    import argparse

    parser = argparse.ArgumentParser(
        description=
        'Parser for lt_xspec; \n Note: Extra arguments are passed to read_spec (e.g. --flux_tag=FX)'
    )
    parser.add_argument(
        "file",
        type=str,
        help="Spectral file; specify extension by appending #exten#")
    parser.add_argument("-z", "--zsys", type=float, help="System Redshift")
    parser.add_argument(
        "--norm",
        help="Show spectrum continuum normalized (if continuum is provided)",
        action="store_true")
    parser.add_argument(
        "--air",
        default=False,
        help="Convert input spectrum wavelengths from air to vacuum",
        action="store_true")
    parser.add_argument("--exten", type=int, help="FITS extension")
    parser.add_argument(
        "--splice",
        type=str,
        help="Splice with the input file; extension convention applies")
    #parser.add_argument("--wave_tag", type=str, help="Tag for wave in Table")
    #parser.add_argument("--flux_tag", type=str, help="Tag for flux in Table")
    #parser.add_argument("--sig_tag", type=str, help="Tag for sig in Table")
    #parser.add_argument("--var_tag", type=str, help="Tag for var in Table")
    #parser.add_argument("--ivar_tag", type=str, help="Tag for ivar in Table")

    #pargs = parser.parse_args()
    pargs, unknown = parser.parse_known_args()

    from PyQt4 import QtGui
    from linetools.guis.xspecgui import XSpecGui

    # Normalized?
    if pargs.norm is True:
        norm = True
    else:
        norm = False

    # Extension
    file = pargs.file
    if pargs.file[-1] == '#':
        prs = pargs.file.split('#')
        exten = int(prs[1])
        file = prs[0]
    else:
        exten = (pargs.exten if hasattr(pargs, 'exten') else 0)

    # zsys
    zsys = (pargs.zsys if hasattr(pargs, 'zsys') else None)

    # Splice?
    if pargs.splice is not None:
        pdb.set_trace()
        if pargs.splice[-1] == '#':
            prs = pargs.splice.split('#')
            exten = [exten, int(prs[1])]
            file = [file, prs[0]]
        else:
            exten = [exten, None]
            file = [file, pargs.splice]

    # Read spec keywords
    rsp_kwargs = {}
    for arg in unknown:
        spl = arg.split('=')
        rsp_kwargs[spl[0][2:]] = spl[1]

    # GUI
    app = QtGui.QApplication(sys.argv)
    gui = XSpecGui(file,
                   zsys=zsys,
                   norm=norm,
                   exten=exten,
                   rsp_kwargs=rsp_kwargs,
                   air=pargs.air)
    gui.show()
    app.exec_()