def test_one_rlz(self): oqparam = tests.get_oqparam('classical_job.ini') # the example has number_of_logic_tree_samples = 1 csm = readinput.get_composite_source_model(oqparam) # check the attributes of the groups are set [grp0, grp1] = csm.src_groups for grp in csm.src_groups: self.assertEqual(grp.src_interdep, 'indep') self.assertEqual(grp.rup_interdep, 'indep') self.assertEqual(repr(csm.gsim_lt), '''\ <GsimLogicTree Active Shallow Crust,b1,[SadighEtAl1997],w=0.5 Active Shallow Crust,b2,[ChiouYoungs2008],w=0.5 Subduction Interface,b3,[SadighEtAl1997],w=1.0>''') assoc = csm.info.get_rlzs_assoc() [rlz] = assoc.realizations self.assertEqual(assoc.gsim_by_trt[rlz.ordinal], {'Subduction Interface': '[SadighEtAl1997]', 'Active Shallow Crust': '[ChiouYoungs2008]'}) # ignoring the end of the tuple, with the uid field self.assertEqual(rlz.ordinal, 0) self.assertEqual(rlz.sm_lt_path, ('b1', 'b4', 'b7')) self.assertEqual(rlz.gsim_lt_path, ('b2', 'b3')) self.assertEqual(rlz.weight['default'], 1.) self.assertEqual( str(assoc), "<RlzsAssoc(size=2, rlzs=1)>")
def test_many_rlzs(self): oqparam = tests.get_oqparam('classical_job.ini') oqparam.number_of_logic_tree_samples = 0 csm = readinput.get_composite_source_model(oqparam) self.assertEqual(len(csm), 9) # the smlt example has 1 x 3 x 3 paths; # there are 2 distinct tectonic region types, so 18 src_groups self.assertEqual(sum(1 for tm in csm.src_groups), 18) rlzs_assoc = csm.info.get_rlzs_assoc() rlzs = rlzs_assoc.realizations self.assertEqual(len(rlzs), 18) # the gsimlt has 1 x 2 paths # counting the sources in each TRT model (after splitting) self.assertEqual( [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2], list(map(len, csm.src_groups))) # removing 9 src_groups out of 18 def count_ruptures(src_group_id): if src_group_id % 2 == 1: # Active Shallow Crust return 0 else: return 1 csm.info.update_eff_ruptures(count_ruptures) assoc = csm.info.get_rlzs_assoc() expected_assoc = "<RlzsAssoc(size=9, rlzs=9)>" self.assertEqual(str(assoc), expected_assoc) self.assertEqual(len(assoc.realizations), 9) # removing all src_groups csm.info.update_eff_ruptures(lambda t: 0) self.assertEqual(csm.info.get_rlzs_assoc().realizations, [])
def test_one_rlz(self): oqparam = tests.get_oqparam('classical_job.ini') # the example has number_of_logic_tree_samples = 1 sitecol = readinput.get_site_collection(oqparam) csm = readinput.get_composite_source_model(oqparam, sitecol) self.assertEqual( str(csm[0].gsim_lt), '''\ <GsimLogicTree Active Shallow Crust,b1,SadighEtAl1997,w=0.5 Active Shallow Crust,b2,ChiouYoungs2008,w=0.5 Subduction Interface,b3,SadighEtAl1997,w=1.0>''') assoc = csm.get_rlzs_assoc( lambda trtmod: sum(src.count_ruptures() for src in trtmod.sources)) [rlz] = assoc.realizations self.assertEqual( assoc.gsim_by_trt[rlz.ordinal], { 'Subduction Interface': 'SadighEtAl1997', 'Active Shallow Crust': 'ChiouYoungs2008' }) # ignoring the end of the tuple, with the uid field self.assertEqual(rlz.ordinal, 0) self.assertEqual(rlz.sm_lt_path, ('b1', 'b5', 'b8')) self.assertEqual(rlz.gsim_lt_path, ('b2', 'b3')) self.assertEqual(rlz.weight, 1.) self.assertEqual( str(assoc), "<RlzsAssoc(2)\n0,SadighEtAl1997: ['<0,b1_b5_b8,b2_b3,w=1.0>']\n" "1,ChiouYoungs2008: ['<0,b1_b5_b8,b2_b3,w=1.0>']>")
def test_one_rlz(self): oqparam = tests.get_oqparam('classical_job.ini') # the example has number_of_logic_tree_samples = 1 sitecol = readinput.get_site_collection(oqparam) csm = readinput.get_composite_source_model(oqparam, sitecol) self.assertEqual(str(csm[0].gsim_lt), '''\ <GsimLogicTree Active Shallow Crust,b1,SadighEtAl1997,w=0.5 Active Shallow Crust,b2,ChiouYoungs2008,w=0.5 Subduction Interface,b3,SadighEtAl1997,w=1.0>''') assoc = csm.get_rlzs_assoc( lambda trtmod: sum(src.count_ruptures() for src in trtmod.sources)) [rlz] = assoc.realizations self.assertEqual(assoc.gsim_by_trt[rlz.ordinal], {'Subduction Interface': 'SadighEtAl1997', 'Active Shallow Crust': 'ChiouYoungs2008'}) # ignoring the end of the tuple, with the uid field self.assertEqual(rlz.ordinal, 0) self.assertEqual(rlz.sm_lt_path, ('b1', 'b5', 'b8')) self.assertEqual(rlz.gsim_lt_path, ('b2', 'b3')) self.assertEqual(rlz.weight, 1.) self.assertEqual( str(assoc), "<RlzsAssoc(2)\n0,SadighEtAl1997: ['<0,b1_b5_b8,b2_b3,w=1.0>']\n" "1,ChiouYoungs2008: ['<0,b1_b5_b8,b2_b3,w=1.0>']>")
def test_one_rlz(self): oqparam = tests.get_oqparam('classical_job.ini') # the example has number_of_logic_tree_samples = 1 csm = readinput.get_composite_source_model(oqparam) # check the attributes of the groups are set [grp0, grp1] = csm.src_groups for grp in csm.src_groups: self.assertEqual(grp.src_interdep, 'indep') self.assertEqual(grp.rup_interdep, 'indep') self.assertEqual(repr(csm.gsim_lt), '''\ <GsimLogicTree Active Shallow Crust,b1,[SadighEtAl1997],w=0.5 Active Shallow Crust,b2,[ChiouYoungs2008],w=0.5 Subduction Interface,b3,[SadighEtAl1997],w=1.0>''') assoc = csm.info.get_rlzs_assoc() [rlz] = assoc.realizations self.assertEqual(assoc.gsim_by_trt[rlz.ordinal], {'Subduction Interface': '[SadighEtAl1997]', 'Active Shallow Crust': '[ChiouYoungs2008]'}) # ignoring the end of the tuple, with the uid field self.assertEqual(rlz.ordinal, 0) self.assertEqual(rlz.sm_lt_path, ('b1', 'b4', 'b7')) self.assertEqual(rlz.gsim_lt_path, ('b2', 'b3')) self.assertEqual(rlz.weight['default'], 1.) self.assertEqual( str(assoc), "<RlzsAssoc(size=2, rlzs=1)\n0,'[SadighEtAl1997]': " "[0]\n1,'[ChiouYoungs2008]': [0]>")
def test_one_rlz(self): oqparam = tests.get_oqparam('classical_job.ini') # the example has number_of_logic_tree_samples = 1 csm = readinput.get_composite_source_model(oqparam) # check the attributes of the groups are set [grp0, grp1] = csm.src_groups for grp in [grp0, grp1]: self.assertEqual(grp.src_interdep, 'indep') self.assertEqual(grp.rup_interdep, 'indep') self.assertEqual( repr(csm.gsim_lt), '''\ <GsimLogicTree Active Shallow Crust,b1,[SadighEtAl1997],w=0.5 Active Shallow Crust,b2,[ChiouYoungs2008],w=0.5 Subduction Interface,b3,[SadighEtAl1997],w=1.0>''') [rlz] = csm.full_lt.get_realizations() self.assertEqual( csm.full_lt.gsim_by_trt(rlz), { 'Subduction Interface': '[SadighEtAl1997]', 'Active Shallow Crust': '[ChiouYoungs2008]' }) self.assertEqual(rlz.ordinal, 0) self.assertEqual(rlz.sm_lt_path, ('b1', 'b5', 'b7')) self.assertEqual(rlz.gsim_lt_path, ('b2', 'b3')) self.assertEqual(rlz.weight['default'], 1.)
def test_many_rlzs(self): oqparam = tests.get_oqparam('classical_job.ini') oqparam.number_of_logic_tree_samples = 0 sitecol = readinput.get_site_collection(oqparam) csm = readinput.get_composite_source_model(oqparam, sitecol) self.assertEqual(len(csm), 9) # the smlt example has 1 x 3 x 3 paths; # there are 2 distinct tectonic region types, so 18 trt_models rlzs_assoc = csm.get_rlzs_assoc() rlzs = rlzs_assoc.realizations self.assertEqual(len(rlzs), 18) # the gsimlt has 1 x 2 paths self.assertEqual([1, 584, 1, 584, 1, 584, 1, 582, 1, 582, 1, 582, 1, 582, 1, 582, 1, 582], map(len, csm.trt_models)) # test the method csm_info.get_col_ids col_ids_first = rlzs_assoc.csm_info.get_col_ids(rlzs[0]) self.assertEqual(col_ids_first, set([0, 1])) col_ids_last = rlzs_assoc.csm_info.get_col_ids(rlzs[-1]) self.assertEqual(col_ids_last, set([16, 17])) # removing 9 trt_models out of 18 for trt_model in csm.trt_models: if trt_model.trt == 'Active Shallow Crust': # no ruptures trt_model.num_ruptures = 0 assoc = csm.get_rlzs_assoc() expected_assoc = """\ <RlzsAssoc(18) 0,SadighEtAl1997: ['<0,b1_b3_b6,@_b3,w=0.04>'] 1,SadighEtAl1997: ['<0,b1_b3_b6,@_b3,w=0.04>'] 2,SadighEtAl1997: ['<1,b1_b3_b7,@_b3,w=0.12>'] 3,SadighEtAl1997: ['<1,b1_b3_b7,@_b3,w=0.12>'] 4,SadighEtAl1997: ['<2,b1_b3_b8,@_b3,w=0.04>'] 5,SadighEtAl1997: ['<2,b1_b3_b8,@_b3,w=0.04>'] 6,SadighEtAl1997: ['<3,b1_b4_b6,@_b3,w=0.12>'] 7,SadighEtAl1997: ['<3,b1_b4_b6,@_b3,w=0.12>'] 8,SadighEtAl1997: ['<4,b1_b4_b7,@_b3,w=0.36>'] 9,SadighEtAl1997: ['<4,b1_b4_b7,@_b3,w=0.36>'] 10,SadighEtAl1997: ['<5,b1_b4_b8,@_b3,w=0.12>'] 11,SadighEtAl1997: ['<5,b1_b4_b8,@_b3,w=0.12>'] 12,SadighEtAl1997: ['<6,b1_b5_b6,@_b3,w=0.04>'] 13,SadighEtAl1997: ['<6,b1_b5_b6,@_b3,w=0.04>'] 14,SadighEtAl1997: ['<7,b1_b5_b7,@_b3,w=0.12>'] 15,SadighEtAl1997: ['<7,b1_b5_b7,@_b3,w=0.12>'] 16,SadighEtAl1997: ['<8,b1_b5_b8,@_b3,w=0.04>'] 17,SadighEtAl1997: ['<8,b1_b5_b8,@_b3,w=0.04>']>""" self.assertEqual(str(assoc), expected_assoc) self.assertEqual(len(assoc.realizations), 9) # removing all trt_models for trt_model in csm.trt_models: if trt_model.trt == 'Subduction Interface': # no ruptures trt_model.num_ruptures = 0 self.assertEqual(csm.get_rlzs_assoc().realizations, [])
def test_many_rlzs(self): oqparam = tests.get_oqparam('classical_job.ini') oqparam.number_of_logic_tree_samples = 0 csm = readinput.get_composite_source_model(oqparam) self.assertEqual(len(csm.sm_rlzs), 9) # example with 1 x 3 x 3 paths # there are 2 distinct tectonic region types, so 2 src_groups self.assertEqual(sum(1 for tm in csm.src_groups), 2) rlzs = csm.full_lt.get_realizations() self.assertEqual(len(rlzs), 18) # the gsimlt has 1 x 2 paths # counting the sources in each TRT model (after splitting) self.assertEqual([9, 18], list(map(len, csm.src_groups)))
def test_many_rlzs(self): oqparam = tests.get_oqparam('classical_job.ini') oqparam.number_of_logic_tree_samples = 0 sitecol = readinput.get_site_collection(oqparam) csm = readinput.get_composite_source_model(oqparam, sitecol) self.assertEqual(len(csm), 9) # the smlt example has 1 x 3 x 3 paths; # there are 2 distinct tectonic region types, so 18 trt_models self.assertEqual(sum(1 for tm in csm.trt_models), 18) rlzs_assoc = csm.info.get_rlzs_assoc() rlzs = rlzs_assoc.realizations self.assertEqual(len(rlzs), 18) # the gsimlt has 1 x 2 paths # counting the sources in each TRT model (unsplit) self.assertEqual( [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2], list(map(len, csm.trt_models))) # test the method extract assoc = rlzs_assoc.extract([1, 5], csm.info) self.assertEqual( str(assoc), """\ <RlzsAssoc(size=4, rlzs=2) 0,SadighEtAl1997(): ['<1,b1_b3_b6~b2_b3,w=0.5>'] 1,ChiouYoungs2008(): ['<1,b1_b3_b6~b2_b3,w=0.5>'] 4,SadighEtAl1997(): ['<5,b1_b3_b8~b2_b3,w=0.5>'] 5,ChiouYoungs2008(): ['<5,b1_b3_b8~b2_b3,w=0.5>']>""") # removing 9 trt_models out of 18 def count_ruptures(trt_model): if trt_model.trt == 'Active Shallow Crust': # no ruptures return 0 else: return 1 assoc = csm.info.get_rlzs_assoc(count_ruptures) expected_assoc = """\ <RlzsAssoc(size=9, rlzs=9) 0,SadighEtAl1997(): ['<0,b1_b3_b6~@_b3,w=0.04>'] 2,SadighEtAl1997(): ['<1,b1_b3_b7~@_b3,w=0.12>'] 4,SadighEtAl1997(): ['<2,b1_b3_b8~@_b3,w=0.04>'] 6,SadighEtAl1997(): ['<3,b1_b4_b6~@_b3,w=0.12>'] 8,SadighEtAl1997(): ['<4,b1_b4_b7~@_b3,w=0.36>'] 10,SadighEtAl1997(): ['<5,b1_b4_b8~@_b3,w=0.12>'] 12,SadighEtAl1997(): ['<6,b1_b5_b6~@_b3,w=0.04>'] 14,SadighEtAl1997(): ['<7,b1_b5_b7~@_b3,w=0.12>'] 16,SadighEtAl1997(): ['<8,b1_b5_b8~@_b3,w=0.04>']>""" self.assertEqual(str(assoc), expected_assoc) self.assertEqual(len(assoc.realizations), 9) # removing all trt_models self.assertEqual(csm.info.get_rlzs_assoc(lambda t: 0).realizations, [])
def test_many_rlzs(self): oqparam = tests.get_oqparam('classical_job.ini') oqparam.number_of_logic_tree_samples = 0 sitecol = readinput.get_site_collection(oqparam) csm = readinput.get_composite_source_model(oqparam, sitecol) self.assertEqual(len(csm), 9) # the smlt example has 1 x 3 x 3 paths; # there are 2 distinct tectonic region types, so 18 trt_models self.assertEqual(sum(1 for tm in csm.trt_models), 18) rlzs_assoc = csm.info.get_rlzs_assoc() rlzs = rlzs_assoc.realizations self.assertEqual(len(rlzs), 18) # the gsimlt has 1 x 2 paths # counting the sources in each TRT model (unsplit) self.assertEqual( [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2], list(map(len, csm.trt_models))) # test the method extract assoc = rlzs_assoc.extract([1, 5]) self.assertEqual(str(assoc), """\ <RlzsAssoc(size=4, rlzs=2) 0,SadighEtAl1997: ['<1,b1_b3_b6,b2_b3,w=0.5>'] 1,ChiouYoungs2008: ['<1,b1_b3_b6,b2_b3,w=0.5>'] 4,SadighEtAl1997: ['<5,b1_b3_b8,b2_b3,w=0.5>'] 5,ChiouYoungs2008: ['<5,b1_b3_b8,b2_b3,w=0.5>']>""") # removing 9 trt_models out of 18 def count_ruptures(trt_model): if trt_model.trt == 'Active Shallow Crust': # no ruptures return 0 else: return 1 assoc = csm.info.get_rlzs_assoc(count_ruptures) expected_assoc = """\ <RlzsAssoc(size=9, rlzs=9) 0,SadighEtAl1997: ['<0,b1_b3_b6,@_b3,w=0.04>'] 2,SadighEtAl1997: ['<1,b1_b3_b7,@_b3,w=0.12>'] 4,SadighEtAl1997: ['<2,b1_b3_b8,@_b3,w=0.04>'] 6,SadighEtAl1997: ['<3,b1_b4_b6,@_b3,w=0.12>'] 8,SadighEtAl1997: ['<4,b1_b4_b7,@_b3,w=0.36>'] 10,SadighEtAl1997: ['<5,b1_b4_b8,@_b3,w=0.12>'] 12,SadighEtAl1997: ['<6,b1_b5_b6,@_b3,w=0.04>'] 14,SadighEtAl1997: ['<7,b1_b5_b7,@_b3,w=0.12>'] 16,SadighEtAl1997: ['<8,b1_b5_b8,@_b3,w=0.04>']>""" self.assertEqual(str(assoc), expected_assoc) self.assertEqual(len(assoc.realizations), 9) # removing all trt_models self.assertEqual(csm.info.get_rlzs_assoc(lambda t: 0).realizations, [])
def test_many_rlzs(self): oqparam = tests.get_oqparam('classical_job.ini') oqparam.number_of_logic_tree_samples = 0 sitecol = readinput.get_site_collection(oqparam) csm = readinput.get_composite_source_model(oqparam, sitecol) self.assertEqual(len(csm), 9) # the smlt example has 1 x 3 x 3 paths; # there are 2 distinct tectonic region types, so 18 trt_models rlzs_assoc = csm.get_rlzs_assoc() rlzs = rlzs_assoc.realizations self.assertEqual(len(rlzs), 18) # the gsimlt has 1 x 2 paths self.assertEqual( [1, 14, 1, 14, 1, 14, 1, 12, 1, 12, 1, 12, 1, 12, 1, 12, 1, 12], list(map(len, csm.trt_models))) # test the method get_col_ids col_ids_first = rlzs_assoc.get_col_ids(rlzs[0]) self.assertEqual(col_ids_first, set([0, 1])) col_ids_last = rlzs_assoc.get_col_ids(rlzs[-1]) self.assertEqual(col_ids_last, set([16, 17])) # removing 9 trt_models out of 18 for trt_model in csm.trt_models: if trt_model.trt == 'Active Shallow Crust': # no ruptures trt_model.num_ruptures = 0 assoc = csm.get_rlzs_assoc() expected_assoc = """\ <RlzsAssoc(9) 0,SadighEtAl1997: ['<0,b1_b3_b6,@_b3,w=0.04>'] 2,SadighEtAl1997: ['<1,b1_b3_b7,@_b3,w=0.12>'] 4,SadighEtAl1997: ['<2,b1_b3_b8,@_b3,w=0.04>'] 6,SadighEtAl1997: ['<3,b1_b4_b6,@_b3,w=0.12>'] 8,SadighEtAl1997: ['<4,b1_b4_b7,@_b3,w=0.36>'] 10,SadighEtAl1997: ['<5,b1_b4_b8,@_b3,w=0.12>'] 12,SadighEtAl1997: ['<6,b1_b5_b6,@_b3,w=0.04>'] 14,SadighEtAl1997: ['<7,b1_b5_b7,@_b3,w=0.12>'] 16,SadighEtAl1997: ['<8,b1_b5_b8,@_b3,w=0.04>']>""" self.assertEqual(str(assoc), expected_assoc) self.assertEqual(len(assoc.realizations), 9) # removing all trt_models for trt_model in csm.trt_models: if trt_model.trt == 'Subduction Interface': # no ruptures trt_model.num_ruptures = 0 self.assertEqual(csm.get_rlzs_assoc().realizations, [])
def test_many_rlzs(self): oqparam = tests.get_oqparam('classical_job.ini') oqparam.number_of_logic_tree_samples = 0 csm = readinput.get_composite_source_model(oqparam) self.assertEqual(len(csm), 9) # the smlt example has 1 x 3 x 3 paths; # there are 2 distinct tectonic region types, so 18 src_groups self.assertEqual(sum(1 for tm in csm.src_groups), 18) rlzs_assoc = csm.info.get_rlzs_assoc() rlzs = rlzs_assoc.realizations self.assertEqual(len(rlzs), 18) # the gsimlt has 1 x 2 paths # counting the sources in each TRT model (after splitting) self.assertEqual( [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2], list(map(len, csm.src_groups))) # removing 9 src_groups out of 18 def count_ruptures(src_group_id): if src_group_id % 2 == 1: # Active Shallow Crust return 0 else: return 1 csm.info.update_eff_ruptures(count_ruptures) assoc = csm.info.get_rlzs_assoc() expected_assoc = """\ <RlzsAssoc(size=9, rlzs=9) 0,'[SadighEtAl1997]': [0] 2,'[SadighEtAl1997]': [1] 4,'[SadighEtAl1997]': [2] 6,'[SadighEtAl1997]': [3] 8,'[SadighEtAl1997]': [4] 10,'[SadighEtAl1997]': [5] 12,'[SadighEtAl1997]': [6] 14,'[SadighEtAl1997]': [7] 16,'[SadighEtAl1997]': [8]>""" self.assertEqual(str(assoc), expected_assoc) self.assertEqual(len(assoc.realizations), 9) # removing all src_groups csm.info.update_eff_ruptures(lambda t: 0) self.assertEqual(csm.info.get_rlzs_assoc().realizations, [])
def test_many_rlzs(self): oqparam = tests.get_oqparam('classical_job.ini') oqparam.number_of_logic_tree_samples = 0 sitecol = readinput.get_site_collection(oqparam) csm = readinput.get_composite_source_model(oqparam, sitecol) self.assertEqual(len(csm), 9) # the smlt example has 1 x 3 x 3 paths; # there are 2 distinct tectonic region types, so 18 src_groups self.assertEqual(sum(1 for tm in csm.src_groups), 18) rlzs_assoc = csm.info.get_rlzs_assoc() rlzs = rlzs_assoc.realizations self.assertEqual(len(rlzs), 18) # the gsimlt has 1 x 2 paths # counting the sources in each TRT model (unsplit) self.assertEqual( [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2], list(map(len, csm.src_groups))) # removing 9 src_groups out of 18 def count_ruptures(src_group_id): if src_group_id % 2 == 1: # Active Shallow Crust return 0 else: return 1 assoc = csm.info.get_rlzs_assoc(count_ruptures) expected_assoc = """\ <RlzsAssoc(size=9, rlzs=9) 0,SadighEtAl1997(): [0] 2,SadighEtAl1997(): [1] 4,SadighEtAl1997(): [2] 6,SadighEtAl1997(): [3] 8,SadighEtAl1997(): [4] 10,SadighEtAl1997(): [5] 12,SadighEtAl1997(): [6] 14,SadighEtAl1997(): [7] 16,SadighEtAl1997(): [8]>""" self.assertEqual(str(assoc), expected_assoc) self.assertEqual(len(assoc.realizations), 9) # removing all src_groups self.assertEqual(csm.info.get_rlzs_assoc(lambda t: 0).realizations, [])