def _generate_timestep_pairs(self): logger.info("generating pairs of timesteps") base_sim = db.sim_query_from_name_list(self.args.sims) pairs = [] for x in base_sim: ts = self.session.query(tangos.core.timestep.TimeStep).filter_by( simulation_id=x.id, available=True).order_by( tangos.core.timestep.TimeStep.redshift.desc()).all() for a, b in zip(ts[:-1], ts[1:]): pairs.append((a, b)) if self.args.backwards: pairs = pairs[::-1] return pairs
def run_calculation_loop(self): simulations = db.sim_query_from_name_list(self.options.sims) for simulation in simulations: logger.info("Processing %s", simulation) for ts in simulation.timesteps: ts_prev = ts.previous # ahf merger tree tool goes back in time if ts_prev is not None: #additionally check if this is the first snapshot tree = at.AHFTree( os.path.join(config.base, simulation.basename), ts) self.create_links(ts_prev, ts, tree.get_links_for_snapshot())
def timelink_bh(sims, session): query = db.sim_query_from_name_list(sims, session) for sim in query.all(): pairs = list(zip(sim.timesteps[:-1], sim.timesteps[1:])) fname = glob.glob(db.config.base + "/" + sim.basename + "/*.BHmergers") if len(fname) == 0: logger.error("No merger file for " + sim.basename) return elif len(fname) > 1: logger.error("Can't work out which is the merger file for " + sim.basename) logger.error("Found: %s", fname) return with session.no_autoflush: generate_halolinks(session, fname, pairs)
def run(): session = db.core.get_default_session() args = get_parser_object().parse_args(sys.argv[1:]) query = db.sim_query_from_name_list(args.sims, session) files = db.core.get_default_session().query(tangos.core.timestep.TimeStep).filter( tangos.core.timestep.TimeStep.simulation_id.in_([q.id for q in query.all()])). \ order_by(tangos.core.timestep.TimeStep.time_gyr).all() if args.backwards: files = files[::-1] parallel_tasks.database.synchronize_creator_object(session) if not args.link_only: scan_for_BHs(files, session) timelink_bh(args.sims, session)
def run_calculation_loop(self): simulations = db.sim_query_from_name_list(self.options.sims) for simulation in simulations: logger.info("Processing %s", simulation) tree = ct.ConsistentTrees( os.path.join(config.base, simulation.basename)) for ts in simulation.timesteps: snapnum = self.filename_to_snapnum(ts.extension) ts_next = ts.next if self.options.with_ids: self.store_ids( ts, tree.get_finder_id_to_tree_id_for_snapshot(snapnum)) if ts_next is not None: n_phantoms = tree.get_num_phantoms_in_snapshot(snapnum + 1) self.create_phantoms(ts_next, n_phantoms) self.create_links(ts, ts_next, tree.get_links_for_snapshot(snapnum))