Ejemplo n.º 1
0
 def load_file(self, filepath):
     image = load_data(filepath, logger=self.logger)
     self.fitsimage.set_image(image)
     # self.setWindowTitle(filepath)
     left, right, up, down = self.getROI()
     try:
         self.fitsimage.get_canvas().get_object_by_tag(self.boxtag)
         self.fitsimage.get_canvas().delete_object_by_tag(self.boxtag)
         self.box = self.recdc(left, down, right, up, color='green')
         self.fitsimage.get_canvas().add(self.box,
                                         tag=self.boxtag,
                                         redraw=True)
     except KeyError:
         self.box = self.recdc(left, down, right, up, color='green')
         self.fitsimage.get_canvas().add(self.box,
                                         tag=self.boxtag,
                                         redraw=True)
     try:
         self.fitsimage.get_canvas().get_object_by_tag(self.picktag)
         self.fitsimage.get_canvas().delete_object_by_tag(self.picktag)
     except KeyError:
         pass
     width, height = image.get_size()
     data_x, data_y = width / 2.0, height / 2.0
     # x, y = self.fitsimage.get_canvas_xy(data_x, data_y)
     radius = float(max(width, height)) / 20
     self.fitsimage.get_canvas().add(
         self.compdc(data_x, data_y, radius, color='skyblue', fontsize=8))
     self.bd._orient(self.fitsimage, righthand=False, msg=True)
Ejemplo n.º 2
0
    def load_file(self, filepath):
        image = load_data(filepath, logger=self.logger)
        self.fitsimage.set_image(image)
        self.setWindowTitle(filepath)

        # create compass
        try:
            try:
                self.fitsimage.delete_object_by_tag(self.cp_tag)
            except KeyError:
                pass

            width, height = image.get_size()
            x, y = width / 2.0, height / 2.0
            # radius we want the arms to be (approx 1/4 the largest dimension)
            radius = float(max(width, height)) / 4.0

            Compass = self.fitsimage.get_draw_class('compass')
            self.fitsimage.add(Compass(x,
                                       y,
                                       radius,
                                       color='skyblue',
                                       fontsize=14),
                               tag=self.cp_tag)
        except Exception as e:
            self.logger.warning("Can't calculate compass: %s" % (str(e)))
Ejemplo n.º 3
0
def convert(filepath, outfilepath):
    """Convert FITS image to PDF."""

    logger = logging.getLogger("example1")
    logger.setLevel(logging.INFO)
    fmt = logging.Formatter(STD_FORMAT)
    stderrHdlr = logging.StreamHandler()
    stderrHdlr.setFormatter(fmt)
    logger.addHandler(stderrHdlr)

    fi = ImageViewCairo(logger)
    fi.configure(500, 1000)

    # Load fits file
    image = load_data(filepath, logger=logger)

    # Make any adjustments to the image that we want
    fi.set_bg(1.0, 1.0, 1.0)
    fi.set_image(image)
    fi.auto_levels()
    fi.zoom_fit()
    fi.center_image()

    ht_pts = 11.0 / point_in
    wd_pts = 8.5 / point_in
    off_x, off_y = 0, 0

    out_f = open(outfilepath, 'w')
    surface = cairo.PDFSurface(out_f, wd_pts, ht_pts)
    # set pixels per inch
    surface.set_fallback_resolution(300, 300)
    surface.set_device_offset(off_x, off_y)
    try:
        fi.save_image_as_surface(surface)
        surface.show_page()
        surface.flush()
        surface.finish()
    finally:
        out_f.close()
Ejemplo n.º 4
0
    def load_file(self, filepath):
        image = load_data(filepath, logger=self.logger)
        self.fitsimage.set_image(image)
        self.setWindowTitle(filepath)

        # create compass
        try:
            try:
                self.fitsimage.delete_object_by_tag(self.cp_tag)
            except KeyError:
                pass

            width, height = image.get_size()
            x, y = width / 2.0, height / 2.0
            # radius we want the arms to be (approx 1/4 the largest dimension)
            radius = float(max(width, height)) / 4.0

            Compass = self.fitsimage.get_draw_class('compass')
            self.fitsimage.add(Compass(x, y, radius, color='skyblue',
                                       fontsize=14), tag=self.cp_tag)
        except Exception as e:
            self.logger.warning("Can't calculate compass: %s" % (
                str(e)))
Ejemplo n.º 5
0
 def load_fits(self, filepath):
     """
     Load a FITS file into the viewer.
     """
     image = loader.load_data(filepath, logger=self.logger)
     self.set_image(image)
Ejemplo n.º 6
0
 def load_file(self, filepath):
     image = load_data(filepath, logger=self.logger)
     self.fitsimage.set_image(image)
     self.root.set_title(filepath)
Ejemplo n.º 7
0
 def load_file(path):
     image = load_data(path, logger=logger)
     viewer.set_image(image)
Ejemplo n.º 8
0
 def load_file(path):
     image = load_data(path, logger=logger)
     viewer.set_image(image)
Ejemplo n.º 9
0
# tell it about the figure
fi = ImageViewCanvas(logger=logger)
fi.enable_autocuts('on')
fi.set_autocut_params('zscale')
#fi.set_cmap(cmap.get_cmap('rainbow3'))
fi.set_figure(fig)

# enable all interactive ginga features
fi.get_bindings().enable_all(True)

# load an image
if len(sys.argv) < 2:
    print("Please provide a FITS file on the command line")
    sys.exit(1)

image = load_data(sys.argv[1], logger=logger)
fi.set_image(image)
#fi.rotate(45)

# plot some example graphics via matplotlib

# Note adding axis from ginga (mpl backend) object
ax = fi.add_axes()
if MPL_V1:
    # old matplotlib API
    ax.hold(True)

wd, ht = image.get_size()

# plot a line
l = ax.plot((wd * 0.33, wd * 0.75), (ht * 0.5, ht * 0.75), 'go-', c="g",
Ejemplo n.º 10
0
 def load(self, fitspath):
     # load an image
     image = load_data(fitspath, logger=self.logger)
     self.fitsimage.set_image(image)
Ejemplo n.º 11
0
def mosaic(logger, itemlist, fov_deg=None):
    """
    Parameters
    ----------
    logger : logger object
        a logger object passed to created AstroImage instances
    itemlist : sequence like
        a sequence of either filenames or AstroImage instances
    """

    if isinstance(itemlist[0], AstroImage.AstroImage):
        image0 = itemlist[0]
        name = image0.get('name', 'image0')
    else:
        # Assume it is a file and load it
        filepath = itemlist[0]
        logger.info("Reading file '%s' ..." % (filepath))
        image0 = loader.load_data(filepath, logger=logger)
        name = filepath

    ra_deg, dec_deg = image0.get_keywords_list('CRVAL1', 'CRVAL2')
    header = image0.get_header()
    (rot_deg, cdelt1, cdelt2) = wcs.get_rotation_and_scale(header)
    logger.debug("image0 rot=%f cdelt1=%f cdelt2=%f" %
                 (rot_deg, cdelt1, cdelt2))

    px_scale = math.fabs(cdelt1)
    expand = False
    if fov_deg is None:
        # TODO: calculate fov?
        expand = True

    cdbase = [np.sign(cdelt1), np.sign(cdelt2)]
    img_mosaic = dp.create_blank_image(ra_deg,
                                       dec_deg,
                                       fov_deg,
                                       px_scale,
                                       rot_deg,
                                       cdbase=cdbase,
                                       logger=logger)
    header = img_mosaic.get_header()
    (rot, cdelt1, cdelt2) = wcs.get_rotation_and_scale(header)
    logger.debug("mosaic rot=%f cdelt1=%f cdelt2=%f" % (rot, cdelt1, cdelt2))

    logger.debug("Processing '%s' ..." % (name))
    tup = mosaic_inline(img_mosaic, [image0], allow_expand=expand)
    logger.debug("placement %s" % (str(tup)))

    count = 1
    for item in itemlist[1:]:
        if isinstance(item, AstroImage.AstroImage):
            image = item
        else:
            # Create and load the image
            filepath = item
            logger.info("Reading file '%s' ..." % (filepath))
            image = io_fits.load_file(filepath, logger=logger)

        name = image.get('name', 'image%d' % (count))

        logger.debug("Inlining '%s' ..." % (name))
        tup = mosaic_inline(img_mosaic, [image])
        logger.debug("placement %s" % (str(tup)))
        count += 1

    logger.info("Done.")
    return img_mosaic
Ejemplo n.º 12
0
 def load_file(self, viewer, filepath):
     image = load_data(filepath, logger=self.logger)
     viewer.set_image(image)
     self.top.set_title(filepath)
Ejemplo n.º 13
0
 def load(self, fitspath):
     # load an image
     image = load_data(fitspath, logger=self.logger)
     self.fitsimage.set_image(image)
Ejemplo n.º 14
0
 def load_file(self, filepath):
     image = load_data(filepath, logger=self.logger)
     self.image_wcs = WCS(filepath)
     self.fitsimage.set_image(image)
Ejemplo n.º 15
0
 def load_file(self, viewer, filepath):
     image = load_data(filepath, logger=self.logger)
     viewer.set_image(image)
     self.top.set_title(filepath)
Ejemplo n.º 16
0
 def load_file(self, filepath):
     image = load_data(filepath, logger=self.logger)
     self.fitsimage.set_image(image)
     self.root.set_title(filepath)
Ejemplo n.º 17
0
 def load_fits(self, filepath):
     """
     Load a FITS file into the viewer.
     """
     image = loader.load_data(filepath, logger=self.logger)
     self.set_image(image)