def load_from_output_metadata(output_metadata):
        """Set Impact Function based on an output of an analysis's metadata.

        If possible, we will try to use layers already in the legend and to not
        recreating new ones. We will keep the style for instance.

        :param output_metadata: Metadata from an output layer.
        :type output_metadata: OutputLayerMetadata

        :returns: Impact Function based on the metadata.
        :rtype: ImpactFunction
        """
        impact_function = MultiExposureImpactFunction()
        provenance = output_metadata['provenance_data']

        # Set exposure layer
        paths = get_provenance(provenance, provenance_multi_exposure_layers)
        if paths:
            for path in paths:
                impact_function.add_exposure(load_layer_from_registry(path))

        # Set hazard layer
        path = get_provenance(provenance, provenance_hazard_layer)
        if path:
            impact_function.hazard = load_layer_from_registry(path)

        # Set aggregation layer
        path = get_provenance(provenance, provenance_aggregation_layer)
        if path:
            impact_function.aggregation = load_layer_from_registry(path)

        # Analysis extent
        extent = get_provenance(provenance, provenance_analysis_extent)
        if extent:
            impact_function._analysis_extent = QgsGeometry.fromWkt(extent)

        # Data store
        data_store_uri = get_provenance(provenance, provenance_data_store_uri)
        if data_store_uri:
            impact_function.datastore = Folder(data_store_uri)

        # Name
        name = get_provenance(provenance, provenance_impact_function_name)
        impact_function._name = name

        # Start date time
        start_datetime = get_provenance(provenance, provenance_start_datetime)
        impact_function._start_datetime = start_datetime

        # End date time
        end_datetime = get_provenance(provenance, provenance_end_datetime)
        impact_function._end_datetime = end_datetime

        # Duration
        duration = get_provenance(provenance, provenance_duration)
        impact_function._duration = duration

        # Debug mode
        debug_mode = get_provenance(provenance, provenance_debug_mode)
        impact_function.debug_mode = debug_mode

        # Output layers
        # aggregation_summary
        path = get_provenance(provenance, provenance_layer_aggregation_summary)
        if path:
            impact_function._aggregation_summary = load_layer_from_registry(
                path)

            # make sure the layer id is equal with the one loaded in the IF
            set_provenance(
                provenance,
                provenance_layer_aggregation_summary_id,
                impact_function._aggregation_summary.id())

        # analysis_impacted
        path = get_provenance(provenance, provenance_layer_analysis_impacted)
        if path:
            impact_function._analysis_summary = load_layer_from_registry(path)

            # make sure the layer id is equal with the one loaded in the IF
            set_provenance(
                provenance,
                provenance_layer_analysis_impacted_id,
                impact_function._analysis_summary.id())

        dict_of_exposure_summary = get_provenance(
            provenance, provenance_multi_exposure_summary_layers)
        dict_of_exposure_summary_id = {}
        dict_of_analysis_summary_id = {}

        for exposure_key, exposure_summary in (
                iter(list(dict_of_exposure_summary.items()))):
            layer = load_layer_from_registry(exposure_summary)
            keywords = KeywordIO.read_keywords(layer)

            # append single IF for each exposure
            serialized_impact_function = (
                ImpactFunction.load_from_output_metadata(keywords))
            impact_function._impact_functions.append(
                serialized_impact_function)

            # make sure the layer id is equal with the one loaded in the IF
            impact_layer = serialized_impact_function.exposure_summary or (
                serialized_impact_function.aggregate_hazard_impacted)
            dict_of_exposure_summary_id[exposure_key] = impact_layer.id()

        for analysis in impact_function._impact_functions:
            exposure_key = (
                analysis.provenance['exposure_keywords']['exposure'])
            analysis_summary = analysis.analysis_impacted
            dict_of_analysis_summary_id[exposure_key] = analysis_summary.id()

        # update the provenance for exposure summary layers
        set_provenance(
            provenance,
            provenance_multi_exposure_summary_layers_id,
            dict_of_exposure_summary_id)

        # update the provenance for analysis summary layers
        set_provenance(
            provenance,
            provenance_multi_exposure_analysis_summary_layers_id,
            dict_of_analysis_summary_id)

        impact_function._output_layer_expected = \
            impact_function._compute_output_layer_expected()

        # crs
        crs = get_provenance(provenance, provenance_crs)
        if crs:
            impact_function._crs = QgsCoordinateReferenceSystem(crs)

        # Set provenance data
        impact_function._provenance = provenance
        impact_function._provenance_ready = True

        return impact_function
def load_from_output_metadata ( output_metadata ) : impact_function = MultiExposureImpactFunction ( ) provenance = output_metadata [ 'provenance_data' ] paths = get_provenance ( provenance , provenance_multi_exposure_layers ) if paths : for path in paths : impact_function . add_exposure ( load_layer_from_registry ( path ) ) path = get_provenance ( provenance , provenance_hazard_layer ) if path : impact_function . hazard = load_layer_from_registry ( path ) path = get_provenance ( provenance , provenance_aggregation_layer ) if path : impact_function . aggregation = load_layer_from_registry ( path ) extent = get_provenance ( provenance , provenance_analysis_extent ) if extent : impact_function . _analysis_extent = QgsGeometry . fromWkt ( extent ) data_store_uri = get_provenance ( provenance , provenance_data_store_uri ) if data_store_uri : impact_function . datastore = Folder ( data_store_uri ) name = get_provenance ( provenance , provenance_impact_function_name ) impact_function . _name = name start_datetime = get_provenance ( provenance , provenance_start_datetime ) impact_function . _start_datetime = start_datetime end_datetime = get_provenance ( provenance , provenance_end_datetime ) impact_function . _end_datetime = end_datetime duration = get_provenance ( provenance , provenance_duration ) impact_function . _duration = duration debug_mode = get_provenance ( provenance , provenance_debug_mode ) impact_function . debug_mode = debug_mode path = get_provenance ( provenance , provenance_layer_aggregation_summary ) if path : impact_function . _aggregation_summary = load_layer_from_registry ( path ) set_provenance ( provenance , provenance_layer_aggregation_summary_id , impact_function . _aggregation_summary . id ( ) ) path = get_provenance ( provenance , provenance_layer_analysis_impacted ) if path : impact_function . _analysis_summary = load_layer_from_registry ( path ) set_provenance ( provenance , provenance_layer_analysis_impacted_id , impact_function . _analysis_summary . id ( ) ) dict_of_exposure_summary = get_provenance ( provenance , provenance_multi_exposure_summary_layers ) dict_of_exposure_summary_id = { } dict_of_analysis_summary_id = { } for exposure_key , exposure_summary in ( iter ( list ( dict_of_exposure_summary . items ( ) ) ) ) : layer = load_layer_from_registry ( exposure_summary ) keywords = KeywordIO . read_keywords ( layer ) serialized_impact_function = ( ImpactFunction . load_from_output_metadata ( keywords ) ) impact_function . _impact_functions . append ( serialized_impact_function ) impact_layer = serialized_impact_function . exposure_summary or ( serialized_impact_function . aggregate_hazard_impacted ) dict_of_exposure_summary_id [ exposure_key ] = impact_layer . id ( ) for analysis in impact_function . _impact_functions : exposure_key = ( analysis . provenance [ 'exposure_keywords' ] [ 'exposure' ] ) analysis_summary = analysis . analysis_impacted dict_of_analysis_summary_id [ exposure_key ] = analysis_summary . id ( ) set_provenance ( provenance , provenance_multi_exposure_summary_layers_id , dict_of_exposure_summary_id ) set_provenance ( provenance , provenance_multi_exposure_analysis_summary_layers_id , dict_of_analysis_summary_id ) impact_function . _output_layer_expected = impact_function . _compute_output_layer_expected ( ) crs = get_provenance ( provenance , provenance_crs ) if crs : impact_function . _crs = QgsCoordinateReferenceSystem ( crs ) impact_function . _provenance = provenance impact_function . _provenance_ready = True return impact_function
Set Impact Function based on an output of an analysis's metadata.

        If possible, we will try to use layers already in the legend and to not
        recreating new ones. We will keep the style for instance.

        :param output_metadata: Metadata from an output layer.
        :type output_metadata: OutputLayerMetadata

        :returns: Impact Function based on the metadata.
        :rtype: ImpactFunction