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)
def main(argv=[__name__]): idx = 1 if argv[1] == "-v": setup_logging(None, True) idx = 2 ad = AcquisitionImage(argv[idx]) ui.display(ad.get_science_data(), zscale=True)
def main(argv=[__name__]): acqimage = AcquisitionImage(argv[1]) ui.display(acqimage.get_science_data(), zscale=True) # the listener will collect the actual data we want verbose = False listener = SelectionCursorListener(acqimage, verbose) listener.start()
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
def get_reconstructed_image(self, measured_fiber_center): debug("...measured fiber center =", measured_fiber_center) debug("...reference fiber center =", self.reference_fiber_center) fiber_correction = measured_fiber_center - self.reference_fiber_center debug("...fiber correction =", fiber_correction) fiber_width = 5.68 stamp_size = 10 skyarray = FiberArray(self.get_fibers(is_sky=True), stamp_size) ifuarray = FiberArray(self.get_fibers(is_sky=False), stamp_size) yvalues, xvalues = np.indices((stamp_size, stamp_size)) def gaussian(fiber_center): xcenter, ycenter = fiber_center dist = (xcenter - xvalues)**2 + (ycenter - yvalues)**2 return np.exp(-dist / fiber_width) for fiber in self.get_fibers(): arr = ifuarray if is_fiber_sky(fiber): arr = skyarray detector_position = get_fiber_position(fiber) + fiber_correction stamp = self._get_fiber_stamp(detector_position, stamp_size, stamp_size) stamp_fiber_center = detector_position - stamp.get_detector_offset() sampling = gaussian(stamp_fiber_center - 1.0) sample = sampling * stamp.get_data() flux = np.sum(sample) arr.add_fiber_flux(fiber, flux) if is_debug_mode(): arr.add_fiber_stamp(fiber, stamp.get_data()) arr.add_fiber_sample(fiber, sample) if is_debug_mode(): ui.display(ifuarray.get_stamp_image(), frame=get_frame_number(), zscale=True) ui.display(ifuarray.get_samples_image(), frame=get_frame_number(), zscale=True) ui.display(ifuarray.get_flux_image(), frame=get_frame_number(), zscale=True) ifuarray.write_block_file(self.acqimage.instrument() + "_ifu_mapping.txt") ui.display(skyarray.get_stamp_image(), frame=get_frame_number(), zscale=True) ui.display(skyarray.get_samples_image(), frame=get_frame_number(), zscale=True) ui.display(skyarray.get_flux_image(), frame=get_frame_number(), zscale=True) skyarray.write_block_file(self.acqimage.instrument() + "_sky_mapping.txt") self.fiber_bundles.write_detector_mapping(self.acqimage.instrument() + "_detector_mapping.txt") ifudata = ifuarray.get_shifted_image() skydata = skyarray.get_shifted_image() return ReconstructedImage(ifudata, skydata, ifuarray.get_pixel_scale())
while fiber_center is None: print "== Press 'a' on this fiber, and then 'q' when happy ==" listener = FiberDetectionListener(fiberfield, verbose=True) listener.start() fiber_center = listener.get_fiber_center() return fiber_center acqimage = AcquisitionImage(sys.argv[1]) if acqimage.focal_plane_mask().upper() != "IFU-2" or acqimage.grating().upper() != "MIRROR": print "Should only be run on a IFU-2 flat non-dispersed image" sys.exit(1) fiberfield = FiberField(acqimage.get_full_field_of_view()) ui.display(fiberfield.get_data(), zscale=True) fname = sys.argv[2] newfname = fname if not os.path.exists(fname): fname = None fiberbundles = FiberBundleCollection(fname, acqimage) try: for bundle in fiberbundles.get_bundles(): if not bundle.has_cached_fiber_positions(): print "== MDF record for the first fiber for bundle '%s' ==" % bundle.get_block() print fiberbundles.get_column_header() print fiberbundles.format_record(bundle.get_first_fiber()) fiber_center = fiber_finder(fiberfield)