Beispiel #1
0
def main(*args, **kwargs):
    """ Runs the XSpecGui on an input file
    """
    import argparse

    parser = argparse.ArgumentParser(description='Parse for XSpec')
    parser.add_argument("file", type=str, help="Spectral file")
    parser.add_argument("-zsys", type=float, help="System Redshift")
    parser.add_argument("--un_norm", help="Spectrum is NOT normalized",
                        action="store_true")
    parser.add_argument("-exten", type=int, help="FITS extension")

    pargs = parser.parse_args()


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

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

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

    # Second spectral file?
    zsys = (pargs.zsys if hasattr(pargs, 'zsys') else None)


    app = QtGui.QApplication(sys.argv)
    gui = XSpecGui(pargs.file, zsys=zsys, norm=norm, exten=exten)
    gui.show()
    app.exec_()
Beispiel #2
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 #3
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 #4
0
def main(*args, **kwargs):
    """ Runs the XSpecGui on an input file
    """
    import argparse

    parser = argparse.ArgumentParser(description='Parse for XSpec')
    parser.add_argument("file", type=str, help="Spectral file")
    parser.add_argument("--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("--exten", type=int, help="FITS extension")
    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()


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

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

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

    # Second spectral file?
    zsys = (pargs.zsys if hasattr(pargs, 'zsys') else None)

    # Read spec keywords
    rsp_kwargs = {}
    if pargs.wave_tag is not None:
        rsp_kwargs['wave_tag'] = pargs.wave_tag
    if pargs.flux_tag is not None:
        rsp_kwargs['flux_tag'] = pargs.flux_tag
    if pargs.sig_tag is not None:
        rsp_kwargs['sig_tag'] = pargs.sig_tag
    if pargs.var_tag is not None:
        rsp_kwargs['var_tag'] = pargs.var_tag
    if pargs.ivar_tag is not None:
        rsp_kwargs['ivar_tag'] = pargs.ivar_tag

    app = QtGui.QApplication(sys.argv)

    gui = XSpecGui(pargs.file, zsys=zsys, norm=norm, exten=exten,
                   rsp_kwargs=rsp_kwargs)
    gui.show()
    app.exec_()
Beispiel #5
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 #6
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 #7
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 #8
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 #9
0
def main(args, unit_test=False):
    """ Runs the XSpecGui on an input file
    """
    import sys

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

    from linetools.guis.xspecgui import XSpecGui

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

    # Read spec keywords
    rsp_kwargs = {}
    if args.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'

    if unit_test is False:
        from PyQt4 import QtGui
        app = QtGui.QApplication(sys.argv)

    gui = XSpecGui(args.file, exten=exten, rsp_kwargs=rsp_kwargs, unit_test=unit_test)
    if unit_test is False:
        gui.show()
        app.exec_()
Beispiel #10
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 #11
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 PyQt5 import QtGui
    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)


    # 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)
    gui = XSpecGui(file, zsys=zsys, norm=norm, exten=exten,
                   rsp_kwargs=rsp_kwargs, air=pargs.air)
    gui.show()
    app.exec_()
Beispiel #12
0
    def plot(self, **kwargs):
        """ Plot the spectrum

        Parameters
        ----------
        show : bool
          If True (the default), then run the matplotlib.pyplot show
          command to display the plot. Disable this if you are running
          from a script and wish to delay showing the plot.
        xlim : tuple of two floats
          The initial x plotting limits (xmin, xmax)
        inline : bool
          Recommended to use if displaying inline in a Notebook
        plot_two : XSpectrum1D
          Plot another spectrum
        xspec : bool
          Launch XSpecGUI instead

        Other keyword arguments are passed to the matplotlib plot
        command.
        """
        # Launch XSpectrum1D??
        if 'xspec' in kwargs:
            import sys
            from PyQt4 import QtGui
            from linetools.guis.xspecgui import XSpecGui
            app = QtGui.QApplication(sys.argv)
            gui = XSpecGui(self)
            gui.show()
            app.exec_()
            return

        import matplotlib.pyplot as plt
        from ..analysis.interactive_plot import PlotWrapNav
        plt.rcParams['axes.formatter.useoffset'] = False  # avoid scientific notation in axes tick labels

        # Keywords
        nocolor = (False if 'color' in kwargs else True)
        xlim = kwargs.pop('xlim', None)
        inline = kwargs.pop('inline', False)
        xspec2 = kwargs.pop('plot_two', None)

        if inline:
            fig = plt.figure(figsize=(12,8))
        else:
            fig = plt.gcf()
        ax = plt.gca()

        artists = {}
        ax.axhline(0, color='k', lw=0.5)

        show = kwargs.pop('show', True)

        if nocolor:
            kwargs.update(color='0.5')
        artists['fl'] = ax.plot(self.wavelength, self.flux,
                                drawstyle='steps-mid', **kwargs)[0]

        # Error
        if nocolor:
            kwargs.update(color='g')
        if self.sig_is_set:
            ax.plot(self.wavelength, self.sig, **kwargs)

        # Continuum
        if (not np.isnan(self.data['co'][self.select][0])) and (not self.normed):
            if nocolor:
                kwargs.update(color='r')
            ax.plot(self.wavelength, self.co, **kwargs)

        # Second spectrum
        if xspec2 is not None:
            ax.plot(xspec2.wavelength, xspec2.flux, color='blue')

        ax.set_ylim(*get_flux_plotrange(self.flux))

        if xlim is not None:
            xmin, xmax = xlim
        else:
            xmin, xmax = self.wavelength.value[0], self.wavelength.value[-1]

        ax.set_xlim(xmin, xmax)

        # Labels
        ax.set_xlabel('Wavelength ({:s})'.format(self.units['wave'].name), size=16)
        ax.set_ylabel('Flux', size=16)

        if plt.get_backend() == 'MacOSX':
            warnings.warn("""\
Looks like you're using the MacOSX matplotlib backend. Switch to the TkAgg
or QtAgg backends to enable all interactive plotting commands.
""")
        else:
            # Enable xspecplot-style navigation (i/o for zooming, etc).
            # Need to save this as an attribute so it doesn't get
            # garbage-collected.
            self._plotter = PlotWrapNav(
                fig, ax, self.wavelength, self.flux, artists, printhelp=False,
                xlim=(xmin, xmax))

            if show:
                plt.show()
Beispiel #13
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_()