def filter_by_keyword_string( cls, hazard_keywords=None, exposure_keywords=None): """Get available impact functions from hazard and exposure keywords. Disabled impact function will not be loaded. :param hazard_keywords: The keywords of the hazard. :type hazard_keywords: dict :param exposure_keywords: The keywords of the exposure. :type exposure_keywords: dict """ if hazard_keywords is None and exposure_keywords is None: return cls._impact_functions impact_functions = [] categories = [] keywords = {} if hazard_keywords is not None: categories.append('hazard') keywords['hazard'] = hazard_keywords if exposure_keywords is not None: categories.append('exposure') keywords['exposure'] = exposure_keywords for impact_function in cls._impact_functions: requirement_met = True for category in categories: f_category = impact_function.metadata().as_dict()[ 'categories'][category] subcategories = f_category['subcategories'] subcategories = project_list( convert_to_list(subcategories), 'id') units = f_category['units'] units = project_list(convert_to_list(units), 'id') layer_constraints = convert_to_list( f_category['layer_constraints']) layer_types = project_list(layer_constraints, 'layer_type') data_types = project_list(layer_constraints, 'data_type') keyword = keywords[category] if keyword.get('subcategory') not in subcategories: requirement_met = False continue if (len(units) > 0 and keyword.get('unit') is not None and keyword.get('unit') not in units): requirement_met = False continue if keyword.get('layer_type') not in layer_types: requirement_met = False continue if keyword.get('data_type') not in data_types: requirement_met = False continue if requirement_met and impact_function not in impact_functions: impact_functions.append(impact_function) return impact_functions
def filter_by_keyword_string( cls, hazard_keywords=None, exposure_keywords=None): """Get available impact functions from hazard and exposure keywords. Disabled impact function will not be loaded. :param hazard_keywords: The keywords of the hazard. :type hazard_keywords: dict :param exposure_keywords: The keywords of the exposure. :type exposure_keywords: dict """ if hazard_keywords is None and exposure_keywords is None: return cls._impact_functions impact_functions = [] layer_purposes = [] keywords = {} if hazard_keywords is not None: layer_purposes.append('hazard') keywords['hazard'] = hazard_keywords if exposure_keywords is not None: layer_purposes.append('exposure') keywords['exposure'] = exposure_keywords for impact_function in cls._impact_functions: requirement_met = True for layer_purpose in layer_purposes: layer_requirement = impact_function.metadata().as_dict()[ 'layer_requirements'][layer_purpose] # general requirements layer_mode = layer_requirement['layer_mode'] layer_mode = project_list(convert_to_list(layer_mode), 'key') layer_geometries = layer_requirement['layer_geometries'] layer_geometries = project_list( convert_to_list(layer_geometries), 'key') # hazard layer specific requirements if layer_purpose == 'hazard': hazard_categories = layer_requirement['hazard_categories'] hazard_categories = project_list( convert_to_list(hazard_categories), 'key') hazard_types = layer_requirement['hazard_types'] hazard_types = project_list( convert_to_list(hazard_types), 'key') continuous_hazard_units = layer_requirement.get( 'continuous_hazard_units') continuous_hazard_units = project_list( convert_to_list(continuous_hazard_units), 'key') vector_hazard_classifications = layer_requirement.get( 'vector_hazard_classifications') vector_hazard_classifications = project_list( convert_to_list(vector_hazard_classifications), 'key') raster_hazard_classifications = layer_requirement.get( 'raster_hazard_classifications') raster_hazard_classifications = project_list( convert_to_list(raster_hazard_classifications), 'key') # exposure layer specific requirements if layer_purpose == 'exposure': exposure_types = layer_requirement['exposure_types'] exposure_types = project_list( convert_to_list(exposure_types), 'key') exposure_units = layer_requirement['exposure_units'] exposure_units = project_list( convert_to_list(exposure_units), 'key') keyword = keywords[layer_purpose] if layer_mode and keyword.get('layer_mode') not in layer_mode: requirement_met = False continue if (layer_geometries and keyword.get('layer_geometry') not in layer_geometries): requirement_met = False continue # hazard layer specific requirements if layer_purpose == 'hazard': if (hazard_types and keyword.get('hazard') not in hazard_types): requirement_met = False continue if (hazard_categories and keyword.get('hazard_category') not in hazard_categories): requirement_met = False continue if (continuous_hazard_units and keyword.get( 'continuous_hazard_unit') not in continuous_hazard_units): requirement_met = False continue if (vector_hazard_classifications and keyword.get( 'vector_hazard_classification') not in vector_hazard_classifications): requirement_met = False continue if (raster_hazard_classifications and keyword.get( 'raster_hazard_classification') not in raster_hazard_classifications): requirement_met = False continue # exposure layer specific requirements if layer_purpose == 'exposure': if (exposure_types and keyword.get('exposure') not in exposure_types): requirement_met = False continue if (exposure_units and keyword.get('exposure_unit') not in exposure_units): requirement_met = False continue if requirement_met and impact_function not in impact_functions: impact_functions.append(impact_function) return impact_functions
def filter_by_keyword_string(cls, hazard_keywords=None, exposure_keywords=None): """Get available impact functions from hazard and exposure keywords. Disabled impact function will not be loaded. :param hazard_keywords: The keywords of the hazard. :type hazard_keywords: dict :param exposure_keywords: The keywords of the exposure. :type exposure_keywords: dict """ if hazard_keywords is None and exposure_keywords is None: return cls._impact_functions impact_functions = [] layer_purposes = [] keywords = {} if hazard_keywords is not None: layer_purposes.append('hazard') keywords['hazard'] = hazard_keywords if exposure_keywords is not None: layer_purposes.append('exposure') keywords['exposure'] = exposure_keywords for impact_function in cls._impact_functions: requirement_met = True for layer_purpose in layer_purposes: layer_requirement = impact_function.metadata().as_dict( )['layer_requirements'][layer_purpose] # general requirements layer_mode = layer_requirement['layer_mode'] layer_mode = project_list(convert_to_list(layer_mode), 'key') layer_geometries = layer_requirement['layer_geometries'] layer_geometries = project_list( convert_to_list(layer_geometries), 'key') # hazard layer specific requirements if layer_purpose == 'hazard': hazard_categories = layer_requirement['hazard_categories'] hazard_categories = project_list( convert_to_list(hazard_categories), 'key') hazard_types = layer_requirement['hazard_types'] hazard_types = project_list(convert_to_list(hazard_types), 'key') continuous_hazard_units = layer_requirement.get( 'continuous_hazard_units') continuous_hazard_units = project_list( convert_to_list(continuous_hazard_units), 'key') vector_hazard_classifications = layer_requirement.get( 'vector_hazard_classifications') vector_hazard_classifications = project_list( convert_to_list(vector_hazard_classifications), 'key') raster_hazard_classifications = layer_requirement.get( 'raster_hazard_classifications') raster_hazard_classifications = project_list( convert_to_list(raster_hazard_classifications), 'key') # exposure layer specific requirements if layer_purpose == 'exposure': exposure_types = layer_requirement['exposure_types'] exposure_types = project_list( convert_to_list(exposure_types), 'key') exposure_units = layer_requirement['exposure_units'] exposure_units = project_list( convert_to_list(exposure_units), 'key') keyword = keywords[layer_purpose] if layer_mode and keyword.get('layer_mode') not in layer_mode: requirement_met = False continue if (layer_geometries and keyword.get('layer_geometry') not in layer_geometries): requirement_met = False continue # hazard layer specific requirements if layer_purpose == 'hazard': if (hazard_types and keyword.get('hazard') not in hazard_types): requirement_met = False continue if (hazard_categories and keyword.get('hazard_category') not in hazard_categories): requirement_met = False continue if (continuous_hazard_units and keyword.get('continuous_hazard_unit') not in continuous_hazard_units): requirement_met = False continue if (vector_hazard_classifications and keyword.get('vector_hazard_classification') not in vector_hazard_classifications): requirement_met = False continue if (raster_hazard_classifications and keyword.get('raster_hazard_classification') not in raster_hazard_classifications): requirement_met = False continue # exposure layer specific requirements if layer_purpose == 'exposure': if (exposure_types and keyword.get('exposure') not in exposure_types): requirement_met = False continue if (exposure_units and keyword.get('exposure_unit') not in exposure_units): requirement_met = False continue if requirement_met and impact_function not in impact_functions: impact_functions.append(impact_function) return impact_functions
def filter_by_keyword_string(cls, hazard_keywords=None, exposure_keywords=None): """Get available impact functions from hazard and exposure keywords. Disabled impact function will not be loaded. :param hazard_keywords: The keywords of the hazard. :type hazard_keywords: dict :param exposure_keywords: The keywords of the exposure. :type exposure_keywords: dict """ if hazard_keywords is None and exposure_keywords is None: return cls._impact_functions impact_functions = [] categories = [] keywords = {} if hazard_keywords is not None: categories.append('hazard') keywords['hazard'] = hazard_keywords if exposure_keywords is not None: categories.append('exposure') keywords['exposure'] = exposure_keywords for impact_function in cls._impact_functions: requirement_met = True for category in categories: f_category = impact_function.metadata().as_dict( )['categories'][category] subcategories = f_category['subcategories'] subcategories = project_list(convert_to_list(subcategories), 'id') units = f_category['units'] units = project_list(convert_to_list(units), 'id') layer_constraints = convert_to_list( f_category['layer_constraints']) layer_types = project_list(layer_constraints, 'layer_type') data_types = project_list(layer_constraints, 'data_type') keyword = keywords[category] if keyword.get('subcategory') not in subcategories: requirement_met = False continue if (len(units) > 0 and keyword.get('unit') is not None and keyword.get('unit') not in units): requirement_met = False continue if keyword.get('layer_type') not in layer_types: requirement_met = False continue if keyword.get('data_type') not in data_types: requirement_met = False continue if requirement_met and impact_function not in impact_functions: impact_functions.append(impact_function) return impact_functions