def _update_pixel_components(self, ndim): for i in range(ndim): comp = CoordinateComponent(self, i) label = pixel_label(i, ndim) cid = PixelComponentID(i, "Pixel Axis %s" % label, parent=self) self.add_component(comp, cid) self._pixel_component_ids.append(cid)
def _create_pixel_and_world_components(self): for i in range(self.ndim): comp = CoordinateComponent(self, i) label = pixel_label(i, self.ndim) cid = PixelComponentID(i, "Pixel Axis %s" % label, hidden=True) self.add_component(comp, cid) self._pixel_component_ids.append(cid) if self.coords: for i in range(self.ndim): comp = CoordinateComponent(self, i, world=True) label = self.coords.axis_label(i) cid = self.add_component(comp, label, hidden=True) self._world_component_ids.append(cid)
def _load_data(rec, context): label = rec['label'] result = Data(label=label) if 'coords' in rec: result.coords = context.object(rec['coords']) # we manually rebuild pixel/world components, so # we override this function. This is pretty ugly result._create_pixel_and_world_components = lambda ndim: None comps = [ list(map(context.object, [cid, comp])) for cid, comp in rec['components'] ] for icomp, (cid, comp) in enumerate(comps): if isinstance(comp, CoordinateComponent): comp._data = result # For backward compatibility, we need to check for cases where # the component ID for the pixel components was not a PixelComponentID # and upgrade it to one. This can be removed once we no longer # support pre-v0.8 session files. if not comp.world and not isinstance(cid, PixelComponentID): cid = PixelComponentID(comp.axis, cid.label, parent=cid.parent) comps[icomp] = (cid, comp) result.add_component(comp, cid) assert result._world_component_ids == [] coord = [c for c in comps if isinstance(c[1], CoordinateComponent)] coord = [x[0] for x in sorted(coord, key=lambda x: x[1])] if getattr(result, 'coords') is not None: assert len(coord) == result.ndim * 2 result._world_component_ids = coord[:len(coord) // 2] result._pixel_component_ids = coord[len(coord) // 2:] else: assert len(coord) == result.ndim result._pixel_component_ids = coord # We can now re-generate the coordinate links result._set_up_coordinate_component_links(result.ndim) for s in rec['subsets']: result.add_subset(context.object(s)) return result
def _create_pixel_and_world_components(self, ndim): for i in range(ndim): comp = CoordinateComponent(self, i) label = pixel_label(i, ndim) cid = PixelComponentID(i, "Pixel Axis %s" % label, parent=self) self.add_component(comp, cid) self._pixel_component_ids.append(cid) if self.coords: for i in range(ndim): comp = CoordinateComponent(self, i, world=True) label = self.coords.axis_label(i) cid = self.add_component(comp, label) self._world_component_ids.append(cid) self._set_up_coordinate_component_links(ndim)
def _load_pixel_component_id(rec, context): if 'axis' in rec: axis = rec['axis'] else: # backward-compatibility axis = int(rec['label'].split()[2]) return PixelComponentID(axis, rec['label'])