Example #1
0
    def _set_up_coordinate_component_links(self, ndim):
        def make_toworld_func(i):
            def pix2world(*args):
                return self.coords.pixel2world_single_axis(*args[::-1],
                                                           axis=ndim - 1 - i)

            return pix2world

        def make_topixel_func(i):
            def world2pix(*args):
                return self.coords.world2pixel_single_axis(*args[::-1],
                                                           axis=ndim - 1 - i)

            return world2pix

        result = []
        for i in range(ndim):
            link = CoordinateComponentLink(self._pixel_component_ids,
                                           self._world_component_ids[i],
                                           self.coords, i)
            result.append(link)
            link = CoordinateComponentLink(self._world_component_ids,
                                           self._pixel_component_ids[i],
                                           self.coords,
                                           i,
                                           pixel2world=False)
            result.append(link)

        self._coordinate_links = result
        return result
Example #2
0
def _load_coordinate_component_link(rec, context):
    to = list(map(context.object, rec['to']))[0]  # XXX why is this a list?
    coords = context.object(rec['coords'])
    index = rec['index']
    pix2world = rec['pix2world']
    frm = list(map(context.object, rec['frm']))
    return CoordinateComponentLink(frm, to, coords, index, pix2world)
Example #3
0
    def coordinate_links(self):
        """A list of the ComponentLinks that connect pixel and
        world. If no coordinate transformation object is present,
        return an empty list.
        """
        if self._coordinate_links:
            return self._coordinate_links

        if not self.coords:
            return []

        if self.ndim != len(self._pixel_component_ids) or \
                self.ndim != len(self._world_component_ids):
            # haven't populated pixel, world coordinates yet
            return []

        def make_toworld_func(i):
            def pix2world(*args):
                return self.coords.pixel2world_single_axis(*args[::-1],
                                                           axis=self.ndim - 1 -
                                                           i)

            return pix2world

        def make_topixel_func(i):
            def world2pix(*args):
                return self.coords.world2pixel_single_axis(*args[::-1],
                                                           axis=self.ndim - 1 -
                                                           i)

            return world2pix

        result = []
        for i in range(self.ndim):
            link = CoordinateComponentLink(self._pixel_component_ids,
                                           self._world_component_ids[i],
                                           self.coords, i)
            result.append(link)
            link = CoordinateComponentLink(self._world_component_ids,
                                           self._pixel_component_ids[i],
                                           self.coords,
                                           i,
                                           pixel2world=False)
            result.append(link)

        self._coordinate_links = result
        return result