예제 #1
0
def spectra_near_position(KT, SegMap, X, Y, distance=2, ixmap=None,
                            pixel_shift = 0):
    """Queries the KD tree for points near the source, returns the spectra.

    Args:
        KT: The KD tree. This can be created in segmap_to_kdtree
        SegMap: The segmentation map
        X,Y: The X/Y position of the spectrum to extract
        distance: Distance to the spaxel in pixels. Default is 100
        ixmap: The mapping of index from KT.data to SegMap
        pixel_shift: For flexure correction, the number of pixels to shift
            the wavelength solution

    Returns a list of (Wavelength, Spectra, SegMap index). E.g.:
        [   [array(365 .. 1000) , array( 50 .. 63)] ,
            [array(366 .. 1001) , array( 53 .. 61)] ,
            ]

    """

    print "query in ", distance/2
    ixs = KT.query_ball_point( (X, Y), distance/2)

    if ixmap is None:
        ixmap = range(len(SegMap))

    results = []
    for index in ixs:
        ix = ixmap[index]
        if len(SegMap[ix]['WaveCalib'][0]) == 0:
            continue
        lam = SegMap[ix]['WaveCalib'][0][0][:]
        lam = FF.shift_pixels(lam, pixel_shift)

        results.append( [lam,
                        SegMap[ix]['SpexSpecFit'][0][0], 
                        ix])

    return results
예제 #2
0
def spectra_in_annulus(KT, SegMap, X, Y, small=200, large=300, ixmap=None,
                        pixel_shift=0):
    """Queries the KD tree for points within the annulus, returns the spectra.

    Args:
        KT: The KD tree. This can be created in segmap_to_kdtree
        SegMap: The segmentation map
        X,Y: The X/Y position of the spectrum to extract
        small,large: The near and far distances of the annulus
        ixmap: The map of KT.data to SegMap
        pixel_shift: For flexure correction, the number of pixels to shift
            the wavelength solution

    Returns a list of (Wavelength, Spectra). E.g.:
        [   [array(365 .. 1000) , array( 50 .. 63)] ,
            [array(366 .. 1001) , array( 53 .. 61)] ,
            ]

    """
    near = set(KT.query_ball_point( (X, Y), small/2))
    far = set(KT.query_ball_point( (X, Y), large/2))

    if ixmap is None: ixmap = range(len(SegMap))

    in_annulus = far.difference(near)
    results = []
    for index in in_annulus:
        ix = ixmap[index]
        try: lam = SegMap[ix]['WaveCalib'][0][0][:]
        except: continue
        lam = FF.shift_pixels(lam, pixel_shift)
        results.append( [lam,
                        SegMap[ix]['SpexSpecFit'][0][0],
                        ix])

    return results