def assert_mos_acquisition(acqimage, centers, tolerance):
    print acqimage.unbinned_pixel_scale()
    assert acqimage.has_mos_mask()
    assert_equals(acqimage.get_num_mos_boxes(), len(centers))

    data = acqimage.get_science_data()
    assert_equals(*data.shape)

    boxes = []
    z1 = Ellipsis
    z2 = None
    for box in acqimage.get_mos_boxes():
        acqbox = find_optimal_box(box, display=True)
        boxes.append(acqbox)
        box_z1, box_z2 = acqbox.get_zscale()

        z1 = min(box_z1, z1)
        z2 = max(box_z2, z2)

    ui.display(data, z1=z1, z2=z2, zscale=False)

    for border in acqimage.get_mos_box_borders():
        ui.polyline(points=border, color=ui.BLUE)

    for box in boxes:
        ui.polyline(points=box.get_mosaic_predicted_borders(), color=ui.MAGENTA)

        x_center, y_center = box.get_mosaic_center()
        assert 0 <= x_center < data.shape[1] 
        assert 0 <= y_center < data.shape[0]

    detector_centers = [b.get_detector_center() for b in boxes]
    assert_tolerance(detector_centers, centers, tolerance=tolerance)
示例#2
0
def draw_slit(midpoint, width):
    # mark the center
    mark = ui.marker(midpoint, color=ui.MAGENTA)
    
    # display a box 
    box = get_predicted_slit(midpoint, width)
    line = ui.polyline(points=box, color=ui.MAGENTA)
    return [mark, line]
    def draw_box(self):
        points = self.get_mosaic_predicted_borders()
        border = ui.polyline(points=points, color=ui.MAGENTA)

        point  = self.get_mosaic_center()
        debug("...drawing box with center at %r" % point)

        center = ui.marker(point, color=ui.MAGENTA)
        
        self.box_overlay = [border, center]
    def handle_box_discard(self, discard):
        """
        discard == True  => get rid of box
        discard == False => reset box to previous
        """
        self.undo_midway_through_exact_acquisition_box()
        self.undo_previous_star_selection()
        self.undo_previous_box()
        self.undo_box_discard()

        if discard:
            tile_size    = self.mosaic_box.get_size()
            bottom_left  = self.mosaic_box.get_mosaic_offset() - 1.0
            bottom_right = bottom_left + np.array([tile_size, 0])
            top_left     = bottom_left + np.array([0, tile_size])
            top_right    = bottom_left + np.array([tile_size, tile_size])

            backslash = ui.polyline(points=(bottom_left, top_right), color=ui.RED)
            fwdslash  = ui.polyline(points=(top_left, bottom_right), color=ui.RED)
            self.box_discard_overlay = [fwdslash, backslash]
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