示例#1
0
def mark_selection(coords, fwhm):
    mark = ui.marker(coords, color=ui.GREEN)
    if math.isnan(fwhm) or math.isinf(fwhm):
        fwhm = 10.0
    radius = abs(fwhm)
    circle = ui.circle(coords, radius)
    return [mark, circle]
    def handle_fiber_selection(self, pos):
        self.undo_previous_selection()

        fiber = find_fiber(self.fiberstamp, pos.get_position() - 1.0, display_plot=self.verbose)

        # failed to detect a fiber using contours, falling back on exact location
        if fiber is None:
            self.handle_exact_location(pos)
            return

        self.fiber = fiber
        center = fiber.get_data_center() 
        
        overlay = ui.circle(center, radius=FIBER_RADIUS + 1.0, color=ui.GREEN)
        self.undo = [overlay]
def get_integrated_field_unit_offsets(acqimage, verbose=False):
    ifucoords = FiberCoordinates(acqimage)

    # display a stamp around the fiber we would like measured
    fiberstamp = ifucoords.get_fiber_stamp()
    z1, z2 = fiberstamp.get_zscale()
    ui.display(fiberstamp.get_data(), frame=1, z1=z1, z2=z2) #zscale=True)
    ui.circle(fiberstamp.get_data_center(), radius=10, color=ui.MAGENTA)

    print("")
    print("   Put cursor on top fiber of lower set (in circle) - press 'a'.")
    print("   When finished, press 'q'.")
    print("")
    print("   If fibers are too faint, just press 'q' for default values.")
    print("   For short exposures the top set of fibers may not be visible.")
    print("")

    
    listener = FiberDetectionListener(fiberstamp, verbose=verbose)
    listener.start()
    
    fiber_center = listener.get_fiber_center()

    # reconstruct the image based upon that measurement
    reconstructed = ifucoords.get_reconstructed_image(fiber_center)

    data = reconstructed.get_ifu_and_sky_data()
    ui.display(data, frame=1, zscale=True)
    ui.polyline(reconstructed.get_sky_line(), color=ui.BLUE)

    print("")
    print("   Point to the object and press 'a' or 'r', the target will then be fitted and marked in DS9.")
    print("   - press 'x' to use an exact location on the acquisition image")
    print("   - press 'e' to see a plot of the profile (clicking in the plot selects an exact location)")
    print("")
    print("   Press 'q' when you're happy with the selection")


    listener = SelectionCursorListener(reconstructed,
                                       verbose=verbose,
                                       pixel_buffer=max(data.shape),
                                       circle_radius=min(data.shape) / 4,
                                       offset=reconstructed.get_sky_offset())
    
    listener.start()

    objcrds = listener.get_object_coords()
    debug("...object coords =", objcrds)
    
    center = reconstructed.get_data_center()
    debug("...center =", center)

    pixscale = reconstructed.get_pixel_scale()
    debug("...pixscale =", pixscale)
    offsets = (center - objcrds) * pixscale

    if acqimage.is_type("GMOS_S"):
        # Check for N&S mode and adjust offset from rec image cen to field cen
        maskname = acqimage.focal_plane_mask()

        nscorr = np.array((0.52, 0.0))
        if maskname == "IFU-NS-B":
            offsets += nscorr
        elif maskname == "IFU-NS-R":
            offsets -= nscorr
        
    return offsets