How to use the uwsift.common.Kind function in uwsift

To help you get started, we’ve selected a few uwsift 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 ssec / sift / uwsift / model / document.py View on Github external
def change_layers_image_kind(self, uuids, new_kind):
        """Change an image or contour layer to present as a different kind."""
        nfo = {}
        layer_set = self.current_layer_set
        assert new_kind in Kind
        all_uuids = set()
        for u in uuids:
            fam = self.family_for_product_or_layer(u)
            all_uuids.update(self._families[fam])
        for idx, pz, layer in self.current_layers_where(uuids=all_uuids):
            if pz.kind not in [Kind.IMAGE, Kind.CONTOUR]:
                LOG.warning("Can't change image kind for Kind: %s", pz.kind.name)
                continue
            new_pz = pz._replace(kind=new_kind)
            nfo[layer.uuid] = new_pz
            layer_set[idx] = new_pz
        self.didChangeImageKind.emit(nfo)
github ssec / sift / uwsift / view / layer_details.py View on Github external
def _get_shared_color_limits(self, shared_info: defaultdict, layer_info: DocBasicLayer, this_prez: Presentation):
        new_clims = ""
        if this_prez is not None:
            new_clims = np.array(this_prez.climits)
            unit_info = self.document[this_prez.uuid][Info.UNIT_CONVERSION]
            new_clims = unit_info[1](new_clims, inverse=False)
            try:
                if layer_info[Info.KIND] in [Kind.IMAGE, Kind.COMPOSITE, Kind.CONTOUR]:
                    min_str = layer_info[Info.UNIT_CONVERSION][2](new_clims[0], include_units=False)
                    max_str = layer_info[Info.UNIT_CONVERSION][2](new_clims[1])
                    new_clims = '{} ~ {}'.format(min_str, max_str)
                elif layer_info[Info.KIND] in [Kind.RGB]:
                    # FUTURE: Other layer types
                    deps = (layer_info.r, layer_info.g, layer_info.b)

                    tmp_clims = []
                    for i, dep in enumerate(deps):
                        if dep is None:
                            tmp_clims.append('N/A')
                            continue

                        min_str = dep[Info.UNIT_CONVERSION][2](new_clims[i][0], include_units=False)
                        max_str = dep[Info.UNIT_CONVERSION][2](new_clims[i][1])
                        tmp_clims.append('{} ~ {}'.format(min_str, max_str))
                    new_clims = ", ".join(tmp_clims)
                else:
                    new_clims = "N/A"
            except TypeError:
github ssec / sift / uwsift / view / scene_graph.py View on Github external
def add_basic_layer(self, new_order: tuple, uuid: UUID, p: Presentation):
        layer = self.document[uuid]
        # create a new layer in the imagelist
        if not layer.is_valid:
            LOG.warning('unable to add an invalid layer, will try again later when layer changes')
            return
        if layer[Info.UUID] in self.image_elements:
            image = self.image_elements[layer[Info.UUID]]
            if p.kind == Kind.CONTOUR and isinstance(image, PrecomputedIsocurve):
                LOG.warning("Contour layer already exists in scene")
                return
            if p.kind == Kind.IMAGE and isinstance(image, TiledGeolocatedImage):
                LOG.warning("Image layer already exists in scene")
                return
            # we already have an image layer for it and it isn't what we want
            # remove the existing image object and create the proper type now
            image.parent = None
            del self.image_elements[layer[Info.UUID]]

        overview_content = self.workspace.get_content(layer.uuid, kind=p.kind)
        if p.kind == Kind.CONTOUR:
            return self.add_contour_layer(layer, p, overview_content)

        image = TiledGeolocatedImage(
            overview_content,
            layer[Info.ORIGIN_X],
            layer[Info.ORIGIN_Y],
            layer[Info.CELL_WIDTH],
github ssec / sift / uwsift / model / document.py View on Github external
def _component_generator(family, this_rgba):
            # limit what layers are returned
            if this_rgba not in rgba:
                return {}

            # FIXME: Should we use SERIAL instead?
            #        Algebraic layers and RGBs need to use the same thing
            #        Any call to 'sync_composite_layer_prereqs' needs to use
            #        SERIAL instead of SCHED_TIME too.
            if family is None:
                layers = self.current_layers_where(kinds=[Kind.IMAGE, Kind.COMPOSITE])
                layers = (x[-1] for x in layers)
                # return empty `None` layers since we don't know what is wanted right now
                # we look at all possible times
                inst_layers = {
                    k: {l[Info.SCHED_TIME]: None for l in g}
                    for k, g in groupby(sorted(layers, key=_key_func), _key_func)}
                return inst_layers
            else:
                family_uuids = self._families[family]
                family_layers = [self[u] for u in family_uuids]
            # (sat, inst) -> {time -> layer}
            inst_layers = {k: {l[Info.SCHED_TIME]: l for l in g} for k, g in
                           groupby(sorted(family_layers, key=_key_func), _key_func)}
            return inst_layers
github ssec / sift / uwsift / view / scene_graph.py View on Github external
def change_composite_layer(self, new_order: tuple, uuid: UUID, presentation: Presentation):
        layer = self.document[uuid]
        if presentation.kind == Kind.RGB:
            if layer.uuid in self.image_elements:
                if layer.is_valid:
                    # RGB selection has changed, rebuild the layer
                    LOG.debug("Changing existing composite layer to Scene Graph Manager with UUID: %s", layer.uuid)
                    dep_uuids = r, g, b = [c.uuid if c is not None else None for c in [layer.r, layer.g, layer.b]]
                    overview_content = list(self.workspace.get_content(cuuid) for cuuid in dep_uuids)
                    self.composite_element_dependencies[layer.uuid] = dep_uuids
                    elem = self.image_elements[layer.uuid]
                    elem.set_channels(overview_content,
                                      cell_width=layer[Info.CELL_WIDTH],
                                      cell_height=layer[Info.CELL_HEIGHT],
                                      origin_x=layer[Info.ORIGIN_X],
                                      origin_y=layer[Info.ORIGIN_Y])
                    elem.init_overview(overview_content)
                    elem.clim = presentation.climits
                    elem.gamma = presentation.gamma
github ssec / sift / uwsift / view / create_algebraic.py View on Github external
self.ui = Ui_create_algebraic_dialog()
        self.ui.setupUi(self)
        # NOTE: For now disable the operations area
        self.ui.operations_text.setDisabled(True)
        self._name_validator = QtGui.QRegExpValidator()
        # allow names that don't start with numbers but accept all other "word" characters
        self._name_validator.setRegExp(QtCore.QRegExp(r'^\w[-\+\*/\w\s]+'))
        self.ui.layer_name_edit.setValidator(self._name_validator)
        self.doc = doc

        # setup UI elements
        available_info = {}
        available_short_names = []
        selected_short_names = []
        # use DATASET_NAME as unique group identifier
        for idx, prez, layer in self.doc.current_layers_where(kinds=(Kind.IMAGE, Kind.COMPOSITE)):
            # use the UUID as a representative when talking to the document
            available_info.setdefault(layer[Info.SHORT_NAME],
                                      layer[Info.UUID])
            available_short_names.append(layer[Info.SHORT_NAME])
            if layer[Info.UUID] in selected_uuids:
                selected_short_names.append(layer[Info.SHORT_NAME])

        self.ui.layer_name_edit.textEdited.connect(self._validate)
        self.accepted.connect(self._create_algebraic)
        for idx, combo in enumerate(self.layer_combos):
            if len(selected_short_names) > idx:
                a_select = selected_short_names[idx]
            elif len(available_info) > idx:
                a_select = available_short_names[idx]
            else:
                a_select = None
github ssec / sift / uwsift / control / rgb_behaviors.py View on Github external
def _selection_did_change(self, uuids=None):
        if uuids is not None and len(uuids) == 1:
            # get the recipe for the RGB layer if that's what this is
            layer = self.doc[uuids[0]]
            if layer[Info.KIND] == Kind.RGB:
                recipe = layer.get('recipe')
                self.rgb_pane.selection_did_change(recipe)
                return
        # disable the rgb pane
        self.rgb_pane.selection_did_change(None)