def _reader2(config: dict) -> list: """ From an untemplated configuration list build the job list. :param config_list: A list describing the simulation. :returns: A list of jobs to process over. """ job_insts = [] for key, attributes in config.items(): add_job(job_insts, key, atts=attributes) # For testing if False: for job in job_insts: print("*******************************************") print(("job.job_instance", job.job_instance)) print(("job.atts_to_add", job.atts_to_add)) return job_insts
def _reader2(config_list): """ From an untemplated configuration list build the job list. :param config_list: A list describing the simulation. :returns: A list of jobs to process over. """ job_insts = [] for jobcalc_dic in config_list: new_string = list(jobcalc_dic.keys())[0] atts = jobcalc_dic[new_string] add_job(job_insts, new_string, atts=atts) # For testing if False: for job in job_insts: print("*******************************************") print(("job.job_instance", job.job_instance)) print(("job.atts_to_add", job.atts_to_add)) return job_insts
def _earthquake_v1_reader(config: dict) -> list: """ Build a job list from earthquake configuration. :param config: A dict describing the simulation :returns: A list of jobs to process over """ LOGGER.info("Using earthquake_v1 template") job_insts = [] atts = find_attributes(config, LOADCSVEXPOSURE) add_job(job_insts, LOADCSVEXPOSURE, atts) atts = find_attributes(config, HAZARDRASTER) atts.setdefault('attribute_label', 'MMI') add_job(job_insts, LOADRASTER, atts) vul_filename = os.path.join(misc.RESOURCE_DIR, find_attributes(config, VULNFILE)) add_job(job_insts, LOADXMLVULNERABILITY, {'file_name': vul_filename}) # The column title in the exposure file = 'WIND_VULNERABILITY_FUNCTION_ID' vulnerability_set_id = find_attributes(config, VULNSET) atts = { 'vul_functions_in_exposure': { vulnerability_set_id: 'EQ_VULNERABILITY_FUNCTION_ID' } } add_job(job_insts, SIMPLELINKER, atts) atts = {'variability_method': {vulnerability_set_id: 'mean'}} add_job(job_insts, SELECTVULNFUNCTION, atts) if PERMUTATION in config: atts = find_attributes(config, PERMUTATION) add_job(job_insts, PERMUTATE_EXPOSURE, atts) else: add_job(job_insts, LOOKUP) if CALCSTRUCTLOSS in config: atts_dict = find_attributes(config, CALCSTRUCTLOSS) if REP_VAL_NAME not in atts_dict: msg = f"Mandatory key not found in config file; {REP_VAL_NAME}" raise RuntimeError(msg) attributes = { 'var1': 'structural', 'var2': atts_dict[REP_VAL_NAME], 'var_out': 'structural_loss' } add_job(job_insts, MDMULT, attributes) if AGGREGATION in config: attributes = find_attributes(config, AGGREGATION) add_job(job_insts, AGGREGATE_LOSS, attributes) file_name = find_attributes(config, SAVEAGG) add_job(job_insts, SAVEAGG, {'file_name': file_name}) if CATEGORISE in config: attributes = find_attributes(config, CATEGORISE) add_job(job_insts, CATEGORISE, attributes) file_name = find_attributes(config, SAVE) add_job(job_insts, SAVEALL, {'file_name': file_name}) if AGGREGATE in config: attributes = find_attributes(config, AGGREGATE) add_job(job_insts, AGGREGATE, attributes) if TABULATE in config: attributes = find_attributes(config, TABULATE) add_job(job_insts, TABULATE, attributes) # Eventually, this needs to be included in pipeline.Pipeline and # automatically added to the list of jobs file_name = find_attributes(config, SAVE) base = os.path.splitext(file_name)[0] file_name = f"{base}.xml" add_job(job_insts, SAVEPROVENANCE, {'file_name': file_name}) return job_insts
def _wind_v4_reader(config: dict) -> list: """ From a wind configuration list build the job list. :param config_list: A list describing the simulation. :returns: A list of jobs to process over. """ job_insts = [] atts = find_attributes(config, LOADCSVEXPOSURE) add_job(job_insts, LOADCSVEXPOSURE, atts) file_list = find_attributes(config, [HAZARDRASTER, LOADWINDTCRM]) atts = {'file_list': file_list, 'attribute_label': '0.2s gust at 10m height m/s'} add_job(job_insts, LOADRASTER, atts) vul_filename = os.path.join(misc.RESOURCE_DIR, find_attributes(config, VULNFILE)) add_job(job_insts, LOADXMLVULNERABILITY, {'file_name': vul_filename}) # The vulnerabilitySetID from the nrml file = 'domestic_flood_2012' # The column title in the exposure file = 'WIND_VULNERABILITY_FUNCTION_ID' vulnerability_set_id = find_attributes(config, VULNSET) atts = {'vul_functions_in_exposure': { vulnerability_set_id: 'WIND_VULNERABILITY_FUNCTION_ID'}} add_job(job_insts, SIMPLELINKER, atts) atts = {'variability_method': { vulnerability_set_id: 'mean'}} add_job(job_insts, SELECTVULNFUNCTION, atts) add_job(job_insts, LOOKUP) atts_dict = find_attributes(config, CALCSTRUCTLOSS) if REP_VAL_NAME not in atts_dict: msg = '\nMandatory key not found in config file; %s\n' % REP_VAL_NAME raise RuntimeError(msg) attributes = { 'var1': 'structural', 'var2': atts_dict[REP_VAL_NAME], 'var_out': 'structural_loss'} add_job(job_insts, MDMULT, attributes) file_name = find_attributes(config, SAVE) add_job(job_insts, SAVEALL, {'file_name': file_name}) file_name = find_attributes(config, SAVE) base = os.path.splitext(file_name)[0] file_name = f"{base}.xml" add_job(job_insts, SAVEPROVENANCE, {'file_name': file_name}) return job_insts
def _flood_contents_v2_reader(config_list): # pylint: disable=R0915 """ This function does two things; * From a flood contents template v2 configuration dictionary build the job list. * Set up the attributes of the jobs and calc's specifically for a flood study. :param config_list: A list describing the simulation. :returns: A list of jobs to process over. """ job_insts = [] atts = find_atts(config_list, LOADCSVEXPOSURE) add_job(job_insts, LOADCSVEXPOSURE, atts) file_list = find_atts(config_list, LOADFLOODASCII) atts = {'file_list': file_list, 'attribute_label': WATER_DEPTH} add_job(job_insts, LOADRASTER, atts) vul_filename = os.path.join(misc.RESOURCE_DIR, 'content_flood_avg_curve.xml') add_job(job_insts, LOADXMLVULNERABILITY, {'file_name': vul_filename}) floor_height_value = find_atts(config_list, FLOOR_HEIGHT) atts = {'var': FLOOR_HEIGHT, 'value': floor_height_value} add_job(job_insts, CONSTANT, atts) add_job(job_insts, FLOOR_HEIGHT_CALC) # select save, nosave or expose atts = find_atts(config_list, CONT_ACTIONS) probs = {} for key in CONT_MAP: if key not in atts: msg = '\nMandatory key not found in config file; %s\n' % key msg += 'Section; %s\n' % CONT_ACTIONS raise RuntimeError(msg) try: probs[CONT_MAP[key]] = atts[key] except TypeError: msg = "\nError: May be due to no spaces after ':' in YAML file\n" raise RuntimeError(msg) attributes = {'var': CONT_ACTION_COL, 'values': probs} add_job(job_insts, RANDOM_CONSTANT, attributes) # select insured or uninsured atts = find_atts(config_list, INSURE_PROB) probs = {} for key in INSURE_MAP: if key not in atts: msg = '\nMandatory key not found in config file; %s\n' % key msg += 'Section; %s\n' % INSURE_PROB raise RuntimeError(msg) try: probs[INSURE_MAP[key]] = atts[key] except TypeError: msg = "\nError: May be due to no spaces after ':' in YAML file\n" raise RuntimeError(msg) attributes = {'var': CONT_INSURANCE_COL, 'values': probs} add_job(job_insts, RANDOM_CONSTANT, attributes) # combine columns to give constant_function_id attributes = { 'var1': 'BUILDING_TYPE', 'var2': CONT_INSURANCE_COL, 'var_out': CONT_TEMP } add_job(job_insts, ADD, attributes) attributes = { 'var1': CONT_TEMP, 'var2': CONT_ACTION_COL, 'var_out': 'CONTENTS_FLOOD_FUNCTION_ID' } add_job(job_insts, ADD, attributes) # The vulnerabilitySetID from the nrml file = 'domestic_flood_2012' # The column title in the exposure file = 'CONTENTS_FLOOD_FUNCTION_ID' atts = { 'vul_functions_in_exposure': { 'contents_domestic_flood_2012': 'CONTENTS_FLOOD_FUNCTION_ID' } } add_job(job_insts, SIMPLELINKER, atts) atts = {'variability_method': {'contents_domestic_flood_2012': 'mean'}} add_job(job_insts, SELECTVULNFUNCTION, atts) add_job(job_insts, LOOKUP) atts_dict = find_atts(config_list, CALCCONTLOSS) if REP_VAL_NAME not in atts_dict: msg = '\nMandatory key not found in config file; %s\n' % REP_VAL_NAME raise RuntimeError(msg) attributes = { 'var1': 'contents_loss_ratio', 'var2': atts_dict[REP_VAL_NAME], 'var_out': 'contents_loss' } add_job(job_insts, MDMULT, attributes) file_name = find_atts(config_list, SAVE) add_job(job_insts, SAVEALL, {'file_name': file_name}) return job_insts
def _flood_fabric_v2_reader(config_list): """ This function does two things; * From a flood fabric template v2 configuration dictionary build the job list. * Set up the attributes of the jobs and calc's specifically for a flood study. :param config_list: A list describing the simulation. :returns: A list of jobs to process over. """ job_insts = [] atts = find_atts(config_list, LOADCSVEXPOSURE) add_job(job_insts, LOADCSVEXPOSURE, atts) file_list = find_atts(config_list, LOADFLOODASCII) atts = {'file_list': file_list, 'attribute_label': WATER_DEPTH} add_job(job_insts, LOADRASTER, atts) vul_filename = os.path.join(misc.RESOURCE_DIR, 'fabric_flood_avg_curve.xml') add_job(job_insts, LOADXMLVULNERABILITY, {'file_name': vul_filename}) floor_height_value = find_atts(config_list, FLOOR_HEIGHT) atts = {'var': FLOOR_HEIGHT, 'value': floor_height_value} add_job(job_insts, CONSTANT, atts) add_job(job_insts, FLOOR_HEIGHT_CALC) # The vulnerabilitySetID from the nrml file = 'domestic_flood_2012' # The column title in the exposure file = 'WIND_VULNERABILITY_FUNCTION_ID' atts = { 'vul_functions_in_exposure': { 'structural_domestic_flood_2012': 'FABRIC_FLOOD_FUNCTION_ID' } } add_job(job_insts, SIMPLELINKER, atts) atts = {'variability_method': {'structural_domestic_flood_2012': 'mean'}} add_job(job_insts, SELECTVULNFUNCTION, atts) add_job(job_insts, LOOKUP) atts_dict = find_atts(config_list, CALCSTRUCTLOSS) if REP_VAL_NAME not in atts_dict: msg = '\nMandatory key not found in config file; %s\n' % REP_VAL_NAME raise RuntimeError(msg) attributes = { 'var1': 'structural_loss_ratio', 'var2': atts_dict[REP_VAL_NAME], 'var_out': 'structural_loss' } add_job(job_insts, MDMULT, attributes) file_name = find_atts(config_list, SAVE) add_job(job_insts, SAVEALL, {'file_name': file_name}) return job_insts
def _wind_v5_reader(config_list): """ Build a job list from a wind configuration list. :param config_list: A list describing the simulation :returns: A list of jobs to process over """ job_insts = [] atts = find_atts(config_list, LOADCSVEXPOSURE) add_job(job_insts, LOADCSVEXPOSURE, atts) file_list = find_atts(config_list, LOADWINDTCRM) atts = { 'file_list': file_list, 'attribute_label': '0.2s gust at 10m height m/s' } add_job(job_insts, LOADRASTER, atts) vul_filename = os.path.join(misc.RESOURCE_DIR, find_atts(config_list, VULNFILE)) add_job(job_insts, LOADXMLVULNERABILITY, {'file_name': vul_filename}) # The column title in the exposure file = 'WIND_VULNERABILITY_FUNCTION_ID' atts = { 'vul_functions_in_exposure': { 'domestic_wind_2012': 'WIND_VULNERABILITY_FUNCTION_ID' } } add_job(job_insts, SIMPLELINKER, atts) atts = {'variability_method': {'domestic_wind_2012': 'mean'}} add_job(job_insts, SELECTVULNFUNCTION, atts) atts = find_atts(config_list, PERMUTATION) add_job(job_insts, PERMUTATE_EXPOSURE, atts) atts_dict = find_atts(config_list, CALCSTRUCTLOSS) if REP_VAL_NAME not in atts_dict: msg = '\nMandatory key not found in config file; %s\n' % REP_VAL_NAME raise RuntimeError(msg) attributes = { 'var1': 'structural_loss_ratio', 'var2': atts_dict[REP_VAL_NAME], 'var_out': 'structural_loss' } add_job(job_insts, MDMULT, attributes) attributes = find_atts(config_list, AGGREGATION) add_job(job_insts, AGGREGATE_LOSS, attributes) file_name = find_atts(config_list, SAVE) add_job(job_insts, SAVEALL, {'file_name': file_name}) file_name = find_atts(config_list, SAVEAGG) add_job(job_insts, SAVEAGG, {'file_name': file_name}) return job_insts
def _wind_v5_reader(config_list): """ Build a job list from a wind configuration list. :param config_list: A list describing the simulation :returns: A list of jobs to process over """ LOGGER.info("Using wind_v5 template") config_dict = {k: v for item in config_list for k, v in list(item.items())} job_insts = [] atts = find_atts(config_list, LOADCSVEXPOSURE) add_job(job_insts, LOADCSVEXPOSURE, atts) file_list = find_atts(config_list, LOADWINDTCRM) atts = { 'file_list': file_list, 'attribute_label': '0.2s gust at 10m height m/s' } add_job(job_insts, LOADRASTER, atts) vul_filename = os.path.join(misc.RESOURCE_DIR, find_atts(config_list, VULNFILE)) add_job(job_insts, LOADXMLVULNERABILITY, {'file_name': vul_filename}) # The column title in the exposure file = 'WIND_VULNERABILITY_FUNCTION_ID' vulnerability_set_id = find_atts(config_list, VULNSET) atts = { 'vul_functions_in_exposure': { vulnerability_set_id: 'WIND_VULNERABILITY_FUNCTION_ID' } } add_job(job_insts, SIMPLELINKER, atts) atts = {'variability_method': {vulnerability_set_id: 'mean'}} add_job(job_insts, SELECTVULNFUNCTION, atts) atts = find_atts(config_list, PERMUTATION) add_job(job_insts, PERMUTATE_EXPOSURE, atts) atts_dict = find_atts(config_list, CALCSTRUCTLOSS) if REP_VAL_NAME not in atts_dict: msg = '\nMandatory key not found in config file; %s\n' % REP_VAL_NAME raise RuntimeError(msg) attributes = { 'var1': 'structural_loss_ratio', 'var2': atts_dict[REP_VAL_NAME], 'var_out': 'structural_loss' } add_job(job_insts, MDMULT, attributes) attributes = find_atts(config_list, AGGREGATION) add_job(job_insts, AGGREGATE_LOSS, attributes) if config_dict.get(CATEGORISE): attributes = find_atts(config_list, CATEGORISE) add_job(job_insts, CATEGORISE, attributes) if config_dict.get(TABULATE): attributes = find_atts(config_list, TABULATE) add_job(job_insts, TABULATE, attributes) file_name = find_atts(config_list, SAVE) add_job(job_insts, SAVEALL, {'file_name': file_name}) file_name = find_atts(config_list, SAVEAGG) add_job(job_insts, SAVEAGG, {'file_name': file_name}) # Eventually, this needs to be included in pipeline.Pipeline and # automatically added to the list of jobs file_name = find_atts(config_list, SAVE) base = os.path.splitext(file_name)[0] file_name = f"{base}.xml" add_job(job_insts, SAVEPROVENANCE, {'file_name': file_name}) return job_insts