code: def add_debug_layers_to_canvas(impact_function):
      
      name = 'DEBUG %s' % impact_function.name
      root = QgsProject.instance().layerTreeRoot()
      group_debug = root.insertGroup(0, name)
      group_debug.setItemVisibilityChecked(False)
      group_debug.setExpanded(False)
      hazard_keywords = impact_function.provenance['hazard_keywords']
      exposure_keywords = impact_function.provenance['exposure_keywords']
  
      # Let's style the hazard class in each layers.
      # noinspection PyBroadException
      try:
          classification = active_classification(
              hazard_keywords, exposure_keywords['exposure'])
          classification = definition(classification)
  
          classes = OrderedDict()
          for f in reversed(classification['classes']):
              classes[f['key']] = (f['color'], f['name'])
          hazard_class = hazard_class_field['key']
      except BaseException:
          # We might not have a classification. But this is the debug group so
          # let's not raise a new exception.
          classification = None
  
      datastore = impact_function.datastore
      for layer in datastore.layers():
          qgis_layer = datastore.layer(layer)
          if not isinstance(qgis_layer, QgsMapLayer):
              continue
          QgsProject.instance().addMapLayer(
              qgis_layer, False)
          layer_node = group_debug.insertLayer(0, qgis_layer)
          layer_node.setItemVisibilityChecked(False)
          layer_node.setExpanded(False)
  
          # Let's style layers which have a geometry and have
          # hazard_class
          if qgis_layer.type() == QgsMapLayer.VectorLayer:
              if qgis_layer.geometryType() not in [
                          QgsWkbTypes.NullGeometry,
                          QgsWkbTypes.UnknownGeometry
                      ] and classification: # noqa
                  if qgis_layer.keywords['inasafe_fields'].get(hazard_class):
                      hazard_class_style(qgis_layer, classes, True)
docs: Helper method to add debug layers to QGIS from impact function.
  
      :param impact_function: The impact function used.
      :type impact_function: ImpactFunction