Exemplo n.º 1
0
Arquivo: manual.py Projeto: gmace/plp
def strip_find(band, icol, dpix=50, margin=10, devide=8.0):
    '''
    Find the start and the end position of each strip 
      by using numerical derivatives 
      - input 
        1. column data (1d-array) 
        2. dpix (pixel width to distinguish different aperture)
        3. margin (margin for eliminating the edge of numerical derivatives)
      - output 
        1. a list of starting positions of the apertures
        2. a list of ending positions of the apertures
    '''

    if band == "H":
        devide = 5.5
    else:
        devide = 20.0

    ny = len(icol)
    print 'len icol', ny
    yy = np.arange(ny)
    dval = ip.nderiv(yy, icol)

    # maximun and minimum of numerical derivatives
    vmin, vmax = np.nanmin(dval[margin:(ny - margin)]), np.nanmax(
        dval[margin:(ny - margin)])
    print 'vmin, vmax', vmin, vmax
    # define the threshold for detecting local maxima
    vthres = (np.abs(vmax) + np.abs(vmin)) / devide  #8.0  # Edit by Huynh Anh
    # find the local maxima and minima
    pll, pval = ip.find_features(yy, dval, gpix=dpix, thres=vthres)
    nll, nval = ip.find_features(yy, -dval, gpix=dpix, thres=vthres)
    # exclude the edge positions
    pvv, = np.where((pll > margin) & (pll < ny - margin))
    nvv, = np.where((nll > margin) & (nll < ny - margin))
    p_num, n_num = len(pll), len(nll)

    if p_num * n_num == 0:
        print 'Found no strips ...'
        p_pos, n_pos = None, None
    else:
        p_pos, n_pos = pll[pvv], nll[nvv]

    #p_pos, n_pos = pll, nll
    '''
    plt.subplot(211)
    plt.plot(yy,icol)
    plt.plot(p_pos, icol[p_pos], 'go')
    plt.plot(n_pos, icol[n_pos], 'ro')
    plt.subplot(212)
    plt.plot(yy,dval)
    plt.plot(p_pos, dval[p_pos], 'go')
    plt.plot(n_pos, dval[n_pos], 'ro')
    plt.show()
    '''
    return p_pos, n_pos
Exemplo n.º 2
0
Arquivo: manual.py Projeto: gmace/plp
def strip_find(band, icol, dpix=50, margin=10, devide=8.0):
    '''
    Find the start and the end position of each strip 
      by using numerical derivatives 
      - input 
        1. column data (1d-array) 
        2. dpix (pixel width to distinguish different aperture)
        3. margin (margin for eliminating the edge of numerical derivatives)
      - output 
        1. a list of starting positions of the apertures
        2. a list of ending positions of the apertures
    '''
    
    if band == "H":
        devide = 5.5
    else:
        devide = 20.0
    
    ny = len(icol)
    print 'len icol', ny
    yy = np.arange(ny)
    dval = ip.nderiv(yy, icol)
    
    # maximun and minimum of numerical derivatives
    vmin, vmax = np.nanmin(dval[margin:(ny-margin)]), np.nanmax(dval[margin:(ny-margin)])
    print 'vmin, vmax', vmin, vmax
    # define the threshold for detecting local maxima
    vthres = (np.abs(vmax) +  np.abs(vmin)) / devide #8.0  # Edit by Huynh Anh
    # find the local maxima and minima 
    pll, pval = ip.find_features(yy, dval, gpix=dpix, thres=vthres)
    nll, nval = ip.find_features(yy, -dval, gpix=dpix, thres=vthres)
    # exclude the edge positions 
    pvv, = np.where((pll > margin) & (pll < ny-margin))
    nvv, = np.where((nll > margin) & (nll < ny-margin))
    p_num, n_num = len(pll), len(nll)
    
    if p_num * n_num == 0:
        print 'Found no strips ...' 
        p_pos, n_pos = None, None
    else:
        p_pos, n_pos = pll[pvv], nll[nvv]
    
    #p_pos, n_pos = pll, nll

    '''
    plt.subplot(211)
    plt.plot(yy,icol)
    plt.plot(p_pos, icol[p_pos], 'go')
    plt.plot(n_pos, icol[n_pos], 'ro')
    plt.subplot(212)
    plt.plot(yy,dval)
    plt.plot(p_pos, dval[p_pos], 'go')
    plt.plot(n_pos, dval[n_pos], 'ro')
    plt.show()
    '''
    return p_pos, n_pos 
Exemplo n.º 3
0
Arquivo: extract.py Projeto: gmace/plp
    def key_press(event): 
        
        ax = event.inaxes 
        if ax == None: return 
        ax_title = ax.get_title()
        
        if event.key == 'q': plt.close('all')

        if event.key == 'm':
            click_x, click_y = event.xdata, event.ydata
            rr = np.arange((x2-2*dpix),(x2+2*dpix+1), dtype=np.int)
            #p = ip.gauss_fit(rr, row[rr], p0=[1, x2, 1])
            #a2.plot(rr, ip.gauss(rr, *p), 'r--')
            #mx = p[1]
            mx, mval = ip.find_features(rr, row[rr], gpix=dpix)
            mx, mval = mx[0], mval[0]
            a2.plot(mx, mval, 'ro')
            fig.canvas.draw()
            fwv = cwv[np.argmin(np.abs(cwv-wav[mx]))]
            strtmp = raw_input('input wavelength at (%d, %d) = %.7f:' % (mx, my, fwv))
            if strtmp == '': strtmp = fwv
            try:
                mwv = np.float(strtmp)
                lxx.append(mx)
                lyy.append(my)
                lwv.append(mwv)
                a1.plot(mx, my, 'ro')
                fig.canvas.draw()
                print '%.7f at (%d, %d)' % (mwv, mx, my)
            except:
                print 'No input, again...'
Exemplo n.º 4
0
Arquivo: manual.py Projeto: gmace/plp
    def key_press(event):

        ax = event.inaxes
        if ax == None: return
        ax_title = ax.get_title()

        if event.key == 'q': plt.close('all')

        if event.key == 'm':
            click_x, click_y = event.xdata, event.ydata
            rr = np.arange((click_x - 2 * dpix), (click_x + 2 * dpix + 1),
                           dtype=np.int)
            #p = ip.gauss_fit(rr, row[rr], p0=[1, x2, 1])
            #a2.plot(rr, ip.gauss(rr, *p), 'r--')
            #mx = p[1]
            mx, mval = ip.find_features(rr, row[rr], gpix=dpix)
            mx, mval = mx[0], mval[0]
            a2.plot(mx, mval, 'ro')
            fig.canvas.draw()
            fwv = cwv[np.argmin(np.abs(cwv - wav[mx]))]
            strtmp = raw_input('input wavelength at (%d, %d) = %.7f:' %
                               (mx, my, fwv))
            if strtmp == '': strtmp = fwv
            try:
                mwv = np.float(strtmp)
                lxx.append(mx)
                lyy.append(my)
                lwv.append(mwv)
                a1.plot(mx, my, 'ro')
                fig.canvas.draw()
                print '%.7f at (%d, %d)' % (mwv, mx, my)
            except:
                print 'No input, again...'