accessmod/layer.py
def expand_priorities(self, priorities: List[dict]) -> List[dict]:
        """Expand class priorities dictionary.

        If an element of the priorities list refers to the land cover or
        transport network layer without providing a class label, then it is
        automatically expanded to all the missing class labels for the specified
        layer.
        """
        # layer is not available in the current stack
        for stack_class in priorities:
            if stack_class["name"] not in self.names:
                priorities.remove(stack_class)
                logger.info(
                    f"Layer {stack_class['name']} removed from priorities because it is not in the stack."
                )

        # class is not available in the specified layer
        for stack_class in priorities:
            layer = self.get(stack_class["name"])

            # which classes are available in the source file?
            if layer.role.value == Role.LAND_COVER.value:
                available_classes = [str(v) for v in layer.unique]
                logger.info(
                    f"Available classes for {layer.name}: {', '.join(available_classes)}"
                )
            elif layer.role.value == Role.TRANSPORT_NETWORK.value:
                available_classes = list(layer.unique)
                logger.info(
                    f"Available classes for {layer.name}: {', '.join(available_classes)}"
                )
            else:
                continue

            # remove references to classes not available in source file
            if "class" in stack_class:
                if (
                    stack_class.get("class")
                    and stack_class.get("class") not in available_classes
                ):
                    priorities.remove(stack_class)
                    logger.info(
                        f"Class {stack_class['class']} removed from priorities because it is not available in the layer."
                    )

        # expand land cover and transport network class labels if needed
        for i, stack_class in enumerate(priorities):
            layer = self.get(stack_class["name"])
            if layer.role.value in (
                Role.LAND_COVER.value,
                Role.TRANSPORT_NETWORK.value,
            ) and not stack_class.get("class"):

                # class labels that are already present in the priorities
                present = []
                for stack_class in priorities:
                    if stack_class["name"] == layer.name and "class" in stack_class:
                        if stack_class.get("class"):
                            present.append(stack_class["class"])

                # class labels that are missing from the priorities
                available = [str(v) for v in layer.unique]
                missing = [value for value in available if value not in present]
                for value in reversed(missing):
                    priorities.insert(i, {"name": layer.name, "class": value})
                    logger.info(f"Added priority for layer {layer.name} class {value}")

        # remove none land cover and transport network priorities
        priorities_ = []
        for stack_class in priorities:
            layer = self.get(stack_class["name"])
            if layer.role.value in (
                Role.LAND_COVER.value,
                Role.TRANSPORT_NETWORK.value,
            ):
                if stack_class.get("class"):
                    priorities_.append(stack_class)
            else:
                priorities_.append(stack_class)

        return priorities_
Expand class priorities dictionary.

        If an element of the priorities list refers to the land cover or
        transport network layer without providing a class label, then it is
        automatically expanded to all the missing class labels for the specified
        layer.
        
Expand class priorities dictionary.
If an element of the priorities list refers to the land cover or
transport network layer without providing a class label, then it is
automatically expanded to all the missing class labels for the specified
layer.
Expand class priorities dictionary . If an element of the priorities list refers to the land cover or transport network layer without providing a class label then it is automatically expanded to all the missing class labels for the specified layer .
def expand_priorities(self, priorities: List[dict]) -> List[dict]:
        for stack_class in priorities:
            if stack_class["name"] not in self.names:
                priorities.remove(stack_class)
                logger.info(
                    f"Layer {stack_class['name']} removed from priorities because it is not in the stack."
                )
        for stack_class in priorities:
            layer = self.get(stack_class["name"])
            if layer.role.value == Role.LAND_COVER.value:
                available_classes = [str(v) for v in layer.unique]
                logger.info(
                    f"Available classes for {layer.name}: {', '.join(available_classes)}"
                )
            elif layer.role.value == Role.TRANSPORT_NETWORK.value:
                available_classes = list(layer.unique)
                logger.info(
                    f"Available classes for {layer.name}: {', '.join(available_classes)}"
                )
            else:
                continue
            if "class" in stack_class:
                if (
                    stack_class.get("class")
                    and stack_class.get("class") not in available_classes
                ):
                    priorities.remove(stack_class)
                    logger.info(
                        f"Class {stack_class['class']} removed from priorities because it is not available in the layer."
                    )
        for i, stack_class in enumerate(priorities):
            layer = self.get(stack_class["name"])
            if layer.role.value in (
                Role.LAND_COVER.value,
                Role.TRANSPORT_NETWORK.value,
            ) and not stack_class.get("class"):
                present = []
                for stack_class in priorities:
                    if stack_class["name"] == layer.name and "class" in stack_class:
                        if stack_class.get("class"):
                            present.append(stack_class["class"])
                available = [str(v) for v in layer.unique]
                missing = [value for value in available if value not in present]
                for value in reversed(missing):
                    priorities.insert(i, {"name": layer.name, "class": value})
                    logger.info(f"Added priority for layer {layer.name} class {value}")
        priorities_ = []
        for stack_class in priorities:
            layer = self.get(stack_class["name"])
            if layer.role.value in (
                Role.LAND_COVER.value,
                Role.TRANSPORT_NETWORK.value,
            ):
                if stack_class.get("class"):
                    priorities_.append(stack_class)
            else:
                priorities_.append(stack_class)
        return priorities_
def expand_priorities ( self , priorities : List [ dict ] ) -> List [ dict ] : for stack_class in priorities : if stack_class [ "name" ] not in self . names : priorities . remove ( stack_class ) logger . info ( f"Layer {stack_class['name']} removed from priorities because it is not in the stack." ) for stack_class in priorities : layer = self . get ( stack_class [ "name" ] ) if layer . role . value == Role . LAND_COVER . value : available_classes = [ str ( v ) for v in layer . unique ] logger . info ( f"Available classes for {layer.name}: {', '.join(available_classes)}" ) elif layer . role . value == Role . TRANSPORT_NETWORK . value : available_classes = list ( layer . unique ) logger . info ( f"Available classes for {layer.name}: {', '.join(available_classes)}" ) else : continue if "class" in stack_class : if ( stack_class . get ( "class" ) and stack_class . get ( "class" ) not in available_classes ) : priorities . remove ( stack_class ) logger . info ( f"Class {stack_class['class']} removed from priorities because it is not available in the layer." ) for i , stack_class in enumerate ( priorities ) : layer = self . get ( stack_class [ "name" ] ) if layer . role . value in ( Role . LAND_COVER . value , Role . TRANSPORT_NETWORK . value , ) and not stack_class . get ( "class" ) : present = [ ] for stack_class in priorities : if stack_class [ "name" ] == layer . name and "class" in stack_class : if stack_class . get ( "class" ) : present . append ( stack_class [ "class" ] ) available = [ str ( v ) for v in layer . unique ] missing = [ value for value in available if value not in present ] for value in reversed ( missing ) : priorities . insert ( i , { "name" : layer . name , "class" : value } ) logger . info ( f"Added priority for layer {layer.name} class {value}" ) priorities_ = [ ] for stack_class in priorities : layer = self . get ( stack_class [ "name" ] ) if layer . role . value in ( Role . LAND_COVER . value , Role . TRANSPORT_NETWORK . value , ) : if stack_class . get ( "class" ) : priorities_ . append ( stack_class ) else : priorities_ . append ( stack_class ) return priorities_
Expand class priorities dictionary.
Expand class priorities dictionary .
"""Expand class priorities dictionary.

        If an element of the priorities list refers to the land cover or
        transport network layer without providing a class label, then it is
        automatically expanded to all the missing class labels for the specified
        layer.
        """ # layer is not available in the current stack # class is not available in the specified layer # which classes are available in the source file? # remove references to classes not available in source file # expand land cover and transport network class labels if needed # class labels that are already present in the priorities # class labels that are missing from the priorities # remove none land cover and transport network priorities
self
priorities
List[dict]