def test_major_progenitor_from_minor_progenitor(): generator = tangos.testing.simulation_generator.TestSimulationGenerator( "sim3") ts1 = generator.add_timestep() generator.add_objects_to_timestep(4) ts2 = generator.add_timestep() generator.add_objects_to_timestep(3) generator.link_last_halos_using_mapping({ 1: 2, 2: 1, 3: 3, 4: 1 }, adjust_masses=True) # ts1->ts2: most massive and second most massive halos swap rank ordering by mass because of the # merger with ts1/h4. ts3 = generator.add_timestep() generator.add_objects_to_timestep(2) # ts2->ts3: there is a major merger of the most massive halos (ts2/h1+ts2/h2)->ts3/h1 generator.link_last_halos_using_mapping({ 1: 1, 2: 1, 3: 2 }, adjust_masses=True) # Check major progenitor correctly reported one step back by MultiSourceMultiHopStrategy progen_in_ts2 = halo_finding.MultiSourceMultiHopStrategy( tangos.get_items(["sim3/ts3/1"]), tangos.get_item("sim3/ts2")).all() testing.assert_halolists_equal(progen_in_ts2, ['sim3/ts2/1']) # Check major progenitor correctly reported two steps back by MultiHopMajorProgenitorsStrategy all_progenitors, weights = halo_finding.MultiHopMajorProgenitorsStrategy( tangos.get_item("sim3/ts3/1")).all_and_weights() testing.assert_halolists_equal(all_progenitors, ['sim3/ts2/1', 'sim3/ts1/2']) # Check major progenitor correctly reported two steps back by MultiSourceMultiHopStrategy # This is where a failure occurred in the past -- the behaviour was inequivalent to always choosing # the highest weight branch (which is what MultiHopMajorProgenitorsStrategy does). # # In the example constructed above, the mapping from ts3 halo 1 reaches: # ts1, h4 (weight 0.26) # ts1, h2 (weight 0.35) # ts1, h1 (weight 0.39) # # It looks from these weights like we ought to be picking ts1/h1. # # However the correct major progenitor is h2, because one identifies a major progenitor at each step. # In step ts2, h1 has weight 0.61 and h2 has weight 0.39. So ts2/h1 is the major progenitor. And then, # going back to ts3, ts1/h2 (weight 0.57) is the major progenitor to ts2/h1. progen_in_ts1 = halo_finding.MultiSourceMultiHopStrategy( tangos.get_items(["sim3/ts3/1"]), tangos.get_item("sim3/ts1")).all() testing.assert_halolists_equal(progen_in_ts1, ['sim3/ts1/2'])
def test_multisource_performance(): ts_targ = tangos.get_item("sim/ts1") sources = tangos.get_items(["sim/ts3/1", "sim/ts3/2", "sim/ts3/3"]) with testing.SqlExecutionTracker() as track: halo_finding.MultiSourceMultiHopStrategy(sources, ts_targ).all() assert track.count_statements_containing("select halos.") == 0
def test_multisource_across(): strategy = halo_finding.MultiSourceMultiHopStrategy( tangos.get_items(["sim/ts2/1", "sim/ts2/2", "sim/ts2/3"]), tangos.get_item("sim2")) results = strategy.all() testing.assert_halolists_equal(results, ["sim2/ts2/2", "sim2/ts2/1", None]) assert strategy._nhops_taken == 1
def test_multisource_preserves_order(): strategy = halo_finding.MultiSourceMultiHopStrategy( tangos.get_items(["sim/ts1/3", "sim/ts1/2", "sim/ts1/1", "sim/ts1/5"]), tangos.get_item("sim/ts3")) results = strategy.all() testing.assert_halolists_equal( results, ["sim/ts3/2", "sim/ts3/1", "sim/ts3/1", None])
def test_multisource_with_nones_as_temptable(): strategy = halo_finding.MultiSourceMultiHopStrategy( tangos.get_items(["sim/ts1/1", "sim/ts1/2", "sim/ts1/3", "sim/ts1/5"]), tangos.get_item("sim/ts3")) with strategy.temp_table() as table: results = thl.all_halos_with_duplicates(table) testing.assert_halolists_equal(results,["sim/ts3/1","sim/ts3/1","sim/ts3/2",None])
def test_multisource_with_nones(): strategy = halo_finding.MultiSourceMultiHopStrategy( tangos.get_items(["sim/ts1/1", "sim/ts1/2", "sim/ts1/3", "sim/ts1/5"]), tangos.get_item("sim/ts3")) results = strategy.all() testing.assert_halolists_equal(results,["sim/ts3/1","sim/ts3/1","sim/ts3/2",None]) assert strategy._nhops_taken==2 # despite not finding a match for ts1/5, the strategy should halt after 2 steps
def test_multisource_forwards(): sources = tangos.get_items(["sim/ts1/1","sim/ts1/2","sim/ts1/3","sim/ts1/4"]) results = halo_finding.MultiSourceMultiHopStrategy(sources, tangos.get_item("sim/ts3")).all() testing.assert_halolists_equal(results, ["sim/ts3/1", "sim/ts3/1", "sim/ts3/2", "sim/ts3/3"]) single_latest = [i.latest for i in sources] testing.assert_halolists_equal(single_latest, ["sim/ts3/1", "sim/ts3/1", "sim/ts3/2", "sim/ts3/3"])
def test_multisource_with_duplicates(): results = halo_finding.MultiSourceMultiHopStrategy( tangos.get_items(["sim/ts1/1", "sim/ts1/2", "sim/ts1/3"]), tangos.get_item("sim/ts3")).all() testing.assert_halolists_equal(results, ["sim/ts3/1", "sim/ts3/1", "sim/ts3/2"])