def view_ruptures_per_trt(token, dstore): tbl = [] header = ('source_model grp_id trt eff_ruptures tot_ruptures'.split()) num_trts = 0 eff_ruptures = 0 tot_ruptures = 0 csm_info = dstore['csm_info'] for i, sm in enumerate(csm_info.source_models): for src_group in sm.src_groups: trt = source.capitalize(src_group.trt) er = src_group.eff_ruptures if er: num_trts += 1 eff_ruptures += er tbl.append( (sm.name, src_group.id, trt, er, src_group.tot_ruptures)) tot_ruptures += src_group.tot_ruptures rows = [('#TRT models', num_trts), ('#eff_ruptures', eff_ruptures), ('#tot_ruptures', tot_ruptures), ('#tot_weight', csm_info.tot_weight)] if len(tbl) > 1: summary = '\n\n' + rst_table(rows) else: summary = '' return rst_table(tbl, header=header) + summary
def view_ruptures_per_trt(token, dstore): tbl = [] header = ('source_model grp_id trt eff_ruptures tot_ruptures'.split()) num_trts = 0 eff_ruptures = 0 tot_ruptures = 0 csm_info = dstore['csm_info'] for i, sm in enumerate(csm_info.source_models): for src_group in sm.src_groups: trt = source.capitalize(src_group.trt) er = src_group.eff_ruptures if er: num_trts += 1 eff_ruptures += er tbl.append( (sm.name, src_group.id, trt, er, src_group.tot_ruptures)) tot_ruptures += src_group.tot_ruptures rows = [('#TRT models', num_trts), ('#eff_ruptures', eff_ruptures), ('#tot_ruptures', tot_ruptures), ('#tot_weight', csm_info.tot_weight)] if len(tbl) > 1: summary = '\n\n' + rst_table(rows) else: summary = '' return rst_table(tbl, header=header) + summary
def export_sourcegroups(ekey, dstore): csm_info = dstore['csm_info'] data = [['grp_id', 'trt', 'eff_ruptures']] for i, sm in enumerate(csm_info.source_models): for src_group in sm.src_groups: trt = source.capitalize(src_group.trt) er = src_group.eff_ruptures data.append((src_group.id, trt, er)) path = dstore.export_path('sourcegroups.csv') writers.write_csv(path, data, fmt='%s') return [path]
def export_sourcegroups(ekey, dstore): csm_info = dstore['csm_info'] data = [['grp_id', 'trt', 'eff_ruptures']] for i, sm in enumerate(csm_info.source_models): for src_group in sm.src_groups: trt = source.capitalize(src_group.trt) er = src_group.eff_ruptures data.append((src_group.id, trt, er)) path = dstore.export_path('sourcegroups.csv') writers.write_csv(path, data, fmt='%s') return [path]
def view_ruptures_per_trt(token, dstore): tbl = [] header = ('source_model trt_id trt num_sources ' 'eff_ruptures weight'.split()) num_trts = 0 tot_sources = 0 eff_ruptures = 0 tot_weight = 0 source_info = dstore['source_info'].value csm_info = dstore['rlzs_assoc'].csm_info w = groupby(source_info, operator.itemgetter('trt_model_id'), lambda rows: sum(r['weight'] for r in rows)) n = groupby(source_info, operator.itemgetter('trt_model_id'), lambda rows: sum(1 for r in rows)) for i, sm in enumerate(csm_info.source_models): # NB: the number of effective ruptures per tectonic region model # is stored in the array eff_ruptures as a literal string describing # an array {trt_model_id: num_ruptures}; see the method # CompositionInfo.get_rlzs_assoc erdict = ast.literal_eval(csm_info.eff_ruptures[i]) for trt_model in sm.trt_models: trt = source.capitalize(trt_model.trt) er = erdict.get(trt, 0) # effective ruptures if er: num_trts += 1 num_sources = n.get(trt_model.id, 0) tot_sources += num_sources eff_ruptures += er weight = w.get(trt_model.id, 0) tot_weight += weight tbl.append((sm.name, trt_model.id, trt, num_sources, er, weight)) rows = [('#TRT models', num_trts), ('#sources', tot_sources), ('#eff_ruptures', eff_ruptures), ('filtered_weight', tot_weight)] if len(tbl) > 1: summary = '\n\n' + rst_table(rows) else: summary = '' return rst_table(tbl, header=header) + summary
def view_ruptures_per_trt(token, dstore): tbl = [] header = ('source_model grp_id trt num_sources ' 'eff_ruptures tot_ruptures'.split()) num_trts = 0 tot_sources = 0 eff_ruptures = 0 tot_ruptures = 0 source_info = dstore['source_info'].value csm_info = dstore['csm_info'] r = groupby(source_info, operator.itemgetter('grp_id'), lambda rows: sum(r['num_ruptures'] for r in rows)) n = groupby(source_info, operator.itemgetter('grp_id'), lambda rows: sum(1 for r in rows)) for i, sm in enumerate(csm_info.source_models): for src_group in sm.src_groups: trt = source.capitalize(src_group.trt) er = src_group.eff_ruptures if er: num_trts += 1 num_sources = n.get(src_group.id, 0) tot_sources += num_sources eff_ruptures += er ruptures = r.get(src_group.id, 0) tot_ruptures += ruptures tbl.append( (sm.name, src_group.id, trt, num_sources, er, ruptures)) rows = [ ('#TRT models', num_trts), ('#sources', tot_sources), ('#eff_ruptures', eff_ruptures), ('#tot_ruptures', tot_ruptures), ('#tot_weight', csm_info.tot_weight), ] if len(tbl) > 1: summary = '\n\n' + rst_table(rows) else: summary = '' return rst_table(tbl, header=header) + summary
def view_ruptures_per_trt(token, dstore): tbl = [] header = ('source_model trt_id trt num_sources ' 'eff_ruptures weight'.split()) num_trts = 0 tot_sources = 0 eff_ruptures = 0 tot_weight = 0 source_info = dstore['source_info'].value csm_info = dstore['rlzs_assoc'].csm_info w = groupby(source_info, operator.itemgetter('trt_model_id'), lambda rows: sum(r['weight'] for r in rows)) n = groupby(source_info, operator.itemgetter('trt_model_id'), lambda rows: sum(1 for r in rows)) for i, sm in enumerate(csm_info.source_models): # NB: the number of effective ruptures per tectonic region model # is stored in the array eff_ruptures as a literal string describing # an array {trt_model_id: num_ruptures}; see the method # CompositionInfo.get_rlzs_assoc erdict = ast.literal_eval(csm_info.eff_ruptures[i]) for trt_model in sm.trt_models: trt = source.capitalize(trt_model.trt) er = erdict.get(trt, 0) # effective ruptures if er: num_trts += 1 num_sources = n.get(trt_model.id, 0) tot_sources += num_sources eff_ruptures += er weight = w.get(trt_model.id, 0) tot_weight += weight tbl.append( (sm.name, trt_model.id, trt, num_sources, er, weight)) rows = [('#TRT models', num_trts), ('#sources', tot_sources), ('#eff_ruptures', eff_ruptures), ('filtered_weight', tot_weight)] if len(tbl) > 1: summary = '\n\n' + rst_table(rows) else: summary = '' return rst_table(tbl, header=header) + summary
def view_ruptures_per_trt(token, dstore): tbl = [] header = ('source_model grp_id trt num_sources ' 'eff_ruptures tot_ruptures'.split()) num_trts = 0 tot_sources = 0 eff_ruptures = 0 tot_ruptures = 0 source_info = dstore['source_info'].value csm_info = dstore['csm_info'] r = groupby(source_info, operator.itemgetter('grp_id'), lambda rows: sum(r['num_ruptures'] for r in rows)) n = groupby(source_info, operator.itemgetter('grp_id'), lambda rows: sum(1 for r in rows)) for i, sm in enumerate(csm_info.source_models): for src_group in sm.src_groups: trt = source.capitalize(src_group.trt) er = src_group.eff_ruptures if er: num_trts += 1 num_sources = n.get(src_group.id, 0) tot_sources += num_sources eff_ruptures += er ruptures = r.get(src_group.id, 0) tot_ruptures += ruptures tbl.append((sm.name, src_group.id, trt, num_sources, er, ruptures)) rows = [('#TRT models', num_trts), ('#sources', tot_sources), ('#eff_ruptures', eff_ruptures), ('#tot_ruptures', tot_ruptures), ('#tot_weight', csm_info.tot_weight), ] if len(tbl) > 1: summary = '\n\n' + rst_table(rows) else: summary = '' return rst_table(tbl, header=header) + summary
def view_ruptures_per_trt(token, dstore): tbl = [] header = ('source_model trt_id trt num_sources ' 'eff_ruptures weight'.split()) num_trts = 0 tot_sources = 0 eff_ruptures = 0 tot_weight = 0 source_info = dstore['source_info'].value csm_info = dstore['csm_info'] w = groupby(source_info, operator.itemgetter('trt_model_id'), lambda rows: sum(r['weight'] for r in rows)) n = groupby(source_info, operator.itemgetter('trt_model_id'), lambda rows: sum(1 for r in rows)) for i, sm in enumerate(csm_info.source_models): for trt_model in sm.trt_models: trt = source.capitalize(trt_model.trt) er = trt_model.eff_ruptures if er: num_trts += 1 num_sources = n.get(trt_model.id, 0) tot_sources += num_sources eff_ruptures += er weight = w.get(trt_model.id, 0) tot_weight += weight tbl.append((sm.name, trt_model.id, trt, num_sources, er, weight)) rows = [('#TRT models', num_trts), ('#sources', tot_sources), ('#eff_ruptures', eff_ruptures), ('filtered_weight', tot_weight)] if len(tbl) > 1: summary = '\n\n' + rst_table(rows) else: summary = '' return rst_table(tbl, header=header) + summary