Пример #1
0
 def regionChange(self, y1, y2):
     self.saveWS()
     print "RegionChange:", y1, y2
     self.y1 = y1
     self.y2 = y2
     self.farr = apext.makeflat(self.specarr, self.y1, self.y2)
     # set up variables
     print "FINAL WS:", self.ws.coef
     self.ws = self.newWS(0.5 * (self.y1 + self.y2))
     self.arcdisplay = ArcDisplay(
         self.xarr,
         self.farr,
         self.slines,
         self.sfluxes,
         self.ws,
         res=self.res,
         dres=self.dres,
         niter=self.niter,
         sigma=self.sigma,
         xp=[],
         wp=[])
     self.arcPage = arcWidget(self.arcdisplay, hmin=self.hmin, wmin=self.wmin, y1=self.y1, y2=self.y2)
     # set up the residual page
     self.errPage = errWidget(self.arcdisplay, hmin=self.hmin, wmin=self.wmin)
     # reset the pages
     self.tabWidget.removeTab(2)
     self.tabWidget.removeTab(1)
     self.tabWidget.insertTab(1, self.arcPage, 'Arc')
     self.tabWidget.insertTab(2, self.errPage, 'Residual')
Пример #2
0
def solution(xarr, specarr, sl, sf, ws, func, y1, y2, min_lines=2, dsigma=5, dniter=3, pad=50, **kwargs):
    """Extract a single line and calculate the wavelneght solution"""

    # set up the flux from the set of lines
    farr = apext.makeflat(specarr, y1, y2)
    farr = st.flatspectrum(xarr, farr, mode='poly', order=2)

    # check to see if there are any points
    xp = st.detectlines(xarr, farr, dsigma, dniter)

    if len(xp) > min_lines and ws:
        # make the artificial list
        wmin = ws.value(xarr.min())
        wmax = ws.value(xarr.max())
        smask = (sl > wmin - pad) * (sl < wmax + pad)

        # fit the function
        fws = func(xarr, farr, sl[smask], sf[smask], ws, **kwargs)
        return fws

    return None
Пример #3
0
    def __init__(self, xarr, specarr, slines, sfluxes, ws, hmin=150, wmin=400,
                 filename=None, res=2.0, dres=0.1, sigma=5, niter=5,
                 ivar=None, nrows=1, nsteps=100, cmap='gray', scale='zscale', contrast=1.0):
        """Default constructor."""

        # set up the variables
        self.y1 = int(0.5 * len(specarr))
        self.y2 = self.y1 + nrows
        self.specarr = specarr
        self.xarr = xarr
        self.ivar = ivar
        self.slines = slines
        self.sfluxes = sfluxes
        self.hmin = hmin
        self.wmin = wmin
        self.ws = ws
        self.res = res
        self.dres = dres
        self.sigma = sigma
        self.niter = niter
        self.nrows = nrows
        self.cmap = cmap
        self.scale = scale
        self.contrast = contrast
        self.filename = filename
        self.ImageSolution = {}

        # Setup widget
        QtGui.QMainWindow.__init__(self)

        # Set main widget
        self.main = QtGui.QWidget(self)

        # Set window title
        self.setWindowTitle("InterIdentify")

        # create the Image page
        self.imagePage = imageWidget(self.specarr, y1=self.y1, y2=self.y2, hmin=self.hmin, wmin=self.wmin, cmap=self.cmap,
                                     name=self.filename, scale=self.scale, contrast=self.contrast)

        # set up the arc page
        self.farr = apext.makeflat(self.specarr, self.y1, self.y2)

        # set up variables
        self.arcdisplay = ArcDisplay(
            xarr,
            self.farr,
            slines,
            sfluxes,
            self.ws,
            res=self.res,
            dres=self.dres,
            niter=self.niter,
            sigma=self.sigma)
        self.arcPage = arcWidget(self.arcdisplay, hmin=hmin, wmin=wmin, y1=self.y1, y2=self.y2)
        # set up the residual page
        self.errPage = errWidget(self.arcdisplay, hmin=hmin, wmin=wmin)

        # create the tabs
        self.tabWidget = QtGui.QTabWidget()
        self.tabWidget.addTab(self.imagePage, 'Image')
        self.tabWidget.addTab(self.arcPage, 'Arc')
        self.tabWidget.addTab(self.errPage, 'Residual')

        # layout the widgets
        mainLayout = QtGui.QVBoxLayout(self.main)
        mainLayout.addWidget(self.tabWidget)
        # self.setLayout(mainLayout)

        # Set focus to main widget
        # self.main.setFocus()

        # Set the main widget as the central widget
        self.setCentralWidget(self.main)

        # Destroy widget on close
        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)

        # Close when config dialog is closed
        #self.connect(self.conf, QtCore.SIGNAL('destroyed()'), self, QtCore.SLOT('close()'))
        self.connect(self.tabWidget, QtCore.SIGNAL('currentChanged(int)'), self.currentChanged)
        self.connect(self.imagePage, QtCore.SIGNAL('regionChange(int,int)'), self.regionChange)
Пример #4
0
def runsolution(xarr, specarr, slines, sfluxes, ws, func, ivar=None,
                fline=True, oneline=False,
                rstep=20,
                icenter=None, nrows=1, dsigma=5, dniter=5, res=2.0, dres=0.1, verbose=True, **kwargs):
    """Starting in the middle of the image, it will determine the solution
       by working its way out to either edge and compiling all the results into
       ImageSolution

       xarr--Full range in x of pixels to solve for

       specarr--Input 2D flux

       func--function to use for the solution


    """
    # set up the variables
    ImageSolution = {}

    # Setup the central line if it isn't specified
    if icenter is None:
        icenter = int(0.5 * len(specarr))

    # set up the flux from the central line (or the line specified by the user in icenter)
    farr = apext.makeflat(specarr, icenter, icenter + nrows)
    farr = st.flatspectrum(xarr, farr, mode='poly', order=2)
    cxp = st.detectlines(xarr, farr, dsigma, dniter)

    # first set up the artificial spectrum
    swarr, sfarr = st.makeartificial(slines, sfluxes, farr.max(), res, dres)

    # find the solution for the central wavelegnth
    k = icenter
    min_lines = 0.1 * len(cxp)
    if fline:
        mws = solution(xarr, specarr, slines, sfluxes, ws, func, k, k + nrows,
                       min_lines=min_lines, dsigma=dsigma, dniter=dniter, **kwargs)
    else:
        mws = solution(xarr, specarr, swarr, sfarr, ws, func, k, k + nrows,
                       min_lines=min_lines, dsigma=dsigma, dniter=dniter, **kwargs)

    print('runsolution:', mws.coef)
    if oneline:
        return mws

    ImageSolution[k] = mws

    # now loop through each step, and calculate the wavelengths for the given
    for i in range(rstep, int(0.5 * len(specarr)), rstep):
        for k in [icenter - i, icenter + i]:
            lws = getwsfromIS(k, ImageSolution)
            if fline:
                fws = solution(xarr, specarr, slines, sfluxes, lws, func, k, k + nrows,
                               min_lines=min_lines, dsigma=dsigma, dniter=dniter, **kwargs)
            else:
                fws = solution(xarr, specarr, swarr, sfarr, lws, func, k, k + nrows,
                               min_lines=min_lines, dsigma=dsigma, dniter=dniter, **kwargs)
            ImageSolution[k] = fws

            if verbose:
                p_new = i * 100.0 / (0.5 * len(specarr))
                ctext = 'Percentage Complete: %d %d %f\r' % (i, p_new, time.clock())  # p_new
                sys.stdout.write(ctext)
                sys.stdout.flush()

    return ImageSolution