How to use the ginga.trcalc function in ginga

To help you get started, we’ve selected a few ginga examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ejeschke / ginga / ginga / web / bokehw / CanvasRenderBokeh.py View on Github external
def draw_path(self, cpoints):
        self.cr.init()

        self.cr.update_line(self.pen)

        xy = trcalc.strip_z(cpoints)

        self.cr.plot.line(x=xy.T[0], y=xy.T[1], **self.cr.kwdargs)
github ejeschke / ginga / ginga / pilw / CanvasRenderPil.py View on Github external
def draw_polygon(self, cpoints):
        cpoints = trcalc.strip_z(cpoints)
        self.cr.polygon(cpoints, self.pen, self.brush)
github ejeschke / ginga / ginga / opengl / CanvasRenderGL.py View on Github external
dst_x, dst_y = cvs_img.crdmap.to_data((cvs_img.x, cvs_img.y))

            a1, b1, a2, b2 = 0, 0, image.width - 1, image.height - 1

            # scale by our scale
            _scale_x, _scale_y = cvs_img.scale_x, cvs_img.scale_y

            interp = cvs_img.interpolation
            if interp is None:
                t_ = viewer.get_settings()
                interp = t_.get('interpolation', 'basic')

            # previous choice might not be available if preferences
            # were saved when opencv was being used (and not used now);
            # if so, silently default to "basic"
            if interp not in trcalc.interpolation_methods:
                interp = 'basic'
            res = image.get_scaled_cutout2((a1, b1), (a2, b2),
                                           (_scale_x, _scale_y),
                                           method=interp)
            data = res.data

            # We are limited by maximum texture size supported for the
            # OpenGl implementation.  Images larger than the maximum
            # in any dimension need to be downsampled to fit.
            ht, wd = data.shape[:2]
            extra = max(wd, ht) - self.max_texture_dim
            if extra > 0:
                new_wd, new_ht = wd - extra, ht - extra
                tup = trcalc.get_scaled_cutout_wdht(data, 0, 0, wd, ht,
                                                    new_wd, new_ht,
                                                    logger=self.logger)
github ejeschke / ginga / ginga / canvas / types / mixins.py View on Github external
def get_llur(self):
        points = (self.crdmap.offset_pt((self.x, self.y),
                                        (-self.radius, -self.radius)),
                  self.crdmap.offset_pt((self.x, self.y),
                                        (self.radius, -self.radius)),
                  self.crdmap.offset_pt((self.x, self.y),
                                        (self.radius, self.radius)),
                  self.crdmap.offset_pt((self.x, self.y),
                                        (-self.radius, self.radius)))
        mpts = np.asarray(self.get_data_points(points=points))

        if hasattr(self, 'rot_deg'):
            xd, yd = self.crdmap.to_data((self.x, self.y))
            mpts = trcalc.rotate_coord(mpts, [self.rot_deg], [xd, yd])

        a, b = trcalc.get_bounds(mpts)
        return (a[0], a[1], b[0], b[1])
github ejeschke / ginga / ginga / examples / gtk / example2_gtk.py View on Github external
logger = log.get_logger("example2", options=options)

    # Check whether user wants to use OpenCv
    if options.opencv:
        from ginga import trcalc
        try:
            trcalc.use('opencv')
        except Exception as e:
            logger.warning("failed to set OpenCv preference: %s" % (str(e)))

    # Check whether user wants to use OpenCL
    elif options.opencl:
        from ginga import trcalc
        try:
            trcalc.use('opencl')
        except Exception as e:
            logger.warning("failed to set OpenCL preference: %s" % (str(e)))

    fv = FitsViewer(logger)
    root = fv.get_widget()
    root.show_all()

    if len(args) > 0:
        fv.load_file(args[0])

    gtk.main()
github ejeschke / ginga / ginga / rv / main.py View on Github external
# Check whether user wants to use OpenCv
        use_opencv = settings.get('use_opencv', False)
        if use_opencv or options.opencv:
            from ginga import trcalc
            try:
                trcalc.use('opencv')
            except Exception as e:
                logger.warning(
                    "failed to set OpenCv preference: %s" % (str(e)))

        # Check whether user wants to use OpenCL
        use_opencl = settings.get('use_opencl', False)
        if use_opencl or options.opencl:
            from ginga import trcalc
            try:
                trcalc.use('opencl')
            except Exception as e:
                logger.warning(
                    "failed to set OpenCL preference: %s" % (str(e)))

        if options.opengl:
            settings.set(use_opengl=True)

        # Create the dynamic module manager
        mm = ModuleManager.ModuleManager(logger)

        # Create and start thread pool
        ev_quit = threading.Event()
        thread_pool = Task.ThreadPool(options.numthreads, logger,
                                      ev_quit=ev_quit)
        thread_pool.startall()
github ejeschke / ginga / ginga / rv / plugins / Preferences.py View on Github external
scale_min, scale_max = self.t_['scale_min'], self.t_['scale_max']
        b.scale_min.set_text(str(scale_min))
        b.scale_min.add_callback('activated', self.set_scale_limit_cb)
        b.scale_min.set_tooltip("Set the minimum allowed scale in any axis")

        b.scale_max.set_text(str(scale_max))
        b.scale_max.add_callback('activated', self.set_scale_limit_cb)
        b.scale_min.set_tooltip("Set the maximum allowed scale in any axis")

        index = 0
        for name in trcalc.interpolation_methods:
            b.interpolation.append_text(name)
            index += 1
        interp = self.t_.get('interpolation', "basic")
        try:
            index = trcalc.interpolation_methods.index(interp)
        except ValueError:
            # previous choice might not be available if preferences
            # were saved when opencv was being used--if so, default
            # to "basic"
            index = trcalc.interpolation_methods.index('basic')
        b.interpolation.set_index(index)
        b.interpolation.set_tooltip("Choose interpolation method")
        b.interpolation.add_callback('activated', self.set_interp_cb)

        fr.set_widget(w)
        vbox.add_widget(fr, stretch=0)

        # PAN OPTIONS
        fr = Widgets.Frame("Panning")

        captions = (('Pan X:', 'label', 'Pan X', 'entry',
github ejeschke / ginga / ginga / util / mosaic.py View on Github external
# Get rotation and scale of piece
        header = image.get_header()
        ((xrot, yrot),
         (cdelt1, cdelt2)) = wcs.get_xy_rotation_and_scale(header)
        self.logger.debug("image(%s) xrot=%f yrot=%f cdelt1=%f "
                          "cdelt2=%f" % (name, xrot, yrot, cdelt1, cdelt2))

        # scale if necessary to scale of reference image
        if (not np.isclose(math.fabs(cdelt1), self.scale_x) or
            not np.isclose(math.fabs(cdelt2), self.scale_y)):
            nscale_x = math.fabs(cdelt1) / self.scale_x
            nscale_y = math.fabs(cdelt2) / self.scale_y
            self.logger.debug("scaling piece by x(%f), y(%f)" % (
                nscale_x, nscale_y))
            data_np, (ascale_x, ascale_y) = trcalc.get_scaled_cutout_basic(
                #data_np, 0, 0, wd - 1, ht - 1, nscale_x, nscale_y,
                data_np, 0, 0, wd, ht, nscale_x, nscale_y,
                logger=self.logger)

        # Rotate piece into our orientation, according to wcs
        rot_dx, rot_dy = xrot - self.xrot_ref, yrot - self.yrot_ref

        flip_x = False
        flip_y = False

        # Optomization for 180 rotations
        if (np.isclose(math.fabs(rot_dx), 180.0) or
            np.isclose(math.fabs(rot_dy), 180.0)):
            rotdata = trcalc.transform(data_np,
                                       flip_x=True, flip_y=True)
            rot_dx = 0.0
github ejeschke / ginga / ginga / examples / pg / example2_pg.py View on Github external
def main(options, args):

    logger = log.get_logger("example2", options=options)

    if options.use_opencv:
        from ginga import trcalc
        try:
            trcalc.use('opencv')
        except Exception as e:
            logger.warning("Error using OpenCv: %s" % str(e))

    if options.use_opencl:
        from ginga import trcalc
        try:
            trcalc.use('opencl')
        except Exception as e:
            logger.warning("Error using OpenCL: %s" % str(e))

    #base_url = "http://%s:%d/app" % (options.host, options.port)

    # establish our widget application
    app = Widgets.Application(logger=logger,
                              host=options.host, port=options.port)
github ejeschke / ginga / ginga / canvas / CanvasObject.py View on Github external
def get_bbox(self, points=None):
        """
        Get bounding box of this object.

        Returns
        -------
        (p1, p2, p3, p4): a 4-tuple of the points in data coordinates,
        beginning with the lower-left and proceeding counter-clockwise.
        """
        if points is None:
            x1, y1, x2, y2 = self.get_llur()
            return ((x1, y1), (x1, y2), (x2, y2), (x2, y1))
        else:
            return trcalc.strip_z(trcalc.get_bounds(points))