NSNAPSEARCH = treedata['Header']['TreeBuilder']['Temporal_linking_length'] TREEDIRECTION = treedata['Header']['TreeBuilder']['Tree_direction'] #alias tree data to halo data as forest file will combine the data halodata = treedata #store number of halos, scalefactors numhalos = np.zeros(numsnaps, dtype=np.int64) scalefactors = np.zeros(numsnaps) #load halo properties file print('Loading halo properties ...') time1 = time.time() mp = -1 for i in range(numsnaps): fname = halocatalogdir + 'snap_%04d/snap_%04d.VELOCIraptor' % (i, i) halos, numhalos[i] = vpt.ReadPropertyFile(fname, RAWPROPFORMAT, 0, 0, requestedfields) scalefactors[i] = halos['SimulationInfo']['ScaleFactor'] if (numhalos[i] > 0 and mp == -1): mp = halos['Mass_tot'][0] / halos['npart'][0] if (ireducememfootprintflag and numhalos[i] > 0): for key in requestedfields: if (halos[key].dtype == np.float64): halos[key] = np.array(halos[key], dtype=np.float32) halodata[i].update(halos) print('Done', time.time() - time1) #given walkable tree, determine the largest difference in snapshots between an object and its head maxnsnapsearch = 0 for i in range(numsnaps): if (numhalos[i] == 0): continue headsnap = np.int64(halodata[i]['Head'] / TEMPORALHALOIDVAL)
def ReadVELOCIraptorTreeandHalodata(opt, inputfields): start = time.time() if (opt.iverbose): print("Reading the walkable tree") sys.stdout.flush() tree, numsnaps = VPT.ReadWalkableHDFTree(opt.inputtreefilename, False) if (opt.iverbose): print("Done reading the walkable tree in", time.time() - start) sys.stdout.flush() #Update the number of snapshots from the tree opt.update_numsnaps(numsnaps) #The fields that needs to be converted to physical physconvertfields = [ inputfields[field] for field in inputfields.keys() if field in ["X", "Y", "Z", "Radius", "Lx", "Ly", "Lz"] ] #Open up the filelist and extract all the filenames snapfilelist = open(opt.inputhalofilelistname, "r") snapfilenames = [line.strip() for line in snapfilelist] snapfilelist.close() #Check the number of files in the VELOCIraptor filelist is the same as whats reported by the walkable tree if (len(snapfilenames) != opt.numsnaps): raise IOError( "The number of input snapshots as reported by the walkable tree is not the same as the\n number of files in the input halo filelist, please correct this" ) #extract the desiredfields from the inputfields desiredfields = list(inputfields.values()) start = time.time() if (opt.iverbose): print("Reading in the halo catalog") sys.stdout.flush() numhalos = np.zeros(opt.numsnaps, dtype=np.uint64) halodata = [dict() for i in range(opt.numsnaps)] atime = np.zeros(opt.numsnaps) for i in range(opt.numsnaps): start1 = time.time() halodata[i], numhalos[i] = VPT.ReadPropertyFile( snapfilenames[i], 2, 0, 0, desiredfields) atime[i] = halodata[i]['SimulationInfo']['ScaleFactor'] for key in halodata[i].keys(): if (key == 'SimulationInfo' or key == 'UnitInfo' or key == 'ConfigurationInfo'): continue #Reduce the precision of the datasets since OrbWeaver is all in float32 if (halodata[i][key].dtype == np.float64): halodata[i][key].astype(np.float32, casting="same_kind", copy=False) #Lets convert fields to physical if required if ((key in physconvertfields) & (halodata[i]['UnitInfo']["Comoving_or_Physical"] == 1)): halodata[i][ key] *= atime[i] / halodata[i]["SimulationInfo"]["h_val"] #Set the flag to physical halodata[i]['UnitInfo']["Comoving_or_Physical"] = 0 if (opt.iverbose > 1): print('Snapshot', i, 'done in', time.time() - start1) sys.stdout.flush() if (opt.iverbose): print('Finished reading halo properties in', time.time() - start) sys.stdout.flush() VPT.AdjustforPeriod(opt.numsnaps, numhalos, halodata, tree) unitdata = halodata[0]["UnitInfo"] cosmodata = halodata[0]["SimulationInfo"] cosmodata["ComovingBoxSize"] = np.round( cosmodata["Period"] * cosmodata["h_val"] / cosmodata["ScaleFactor"], 1) #Now it has been loaded the dictionary keys needs to be updated in the halodata so they are compatible with OrbWeaver for i in range(opt.numsnaps): for field in inputfields.keys(): halodata[i][field] = halodata[i].pop(inputfields[field]) return atime, numhalos, halodata, tree, unitdata, cosmodata
#for hdf input produce file listing input files snaptreelist = open(basetreefname + '.snaptreelist.txt', 'w') for i in range(numsnaps): snaptreelist.write(basetreefname + '.snapshot_%03d.VELOCIraptor\n' % i) snaptreelist.close() rawtreedata = vpt.ReadHaloMergerTreeDescendant( basetreefname + '.snaptreelist.txt', False, RAWTREEFORMAT, 1, True) else: rawtreedata = vpt.ReadHaloMergerTreeDescendant(basetreefname, False, RAWTREEFORMAT, 0, True) print('Finished reading raw tree') numhalos = np.zeros(numsnaps, dtype=np.uint64) halodata = [dict() for i in range(numsnaps)] atime = np.zeros(numsnaps) for i in range(numsnaps): halodata[i], numhalos[i] = vpt.ReadPropertyFile( basepropfname + '%03d.VELOCIraptor' % i, 2, 0, 1, requestedfields) atime[i] = halodata[i]['SimulationInfo']['ScaleFactor'] for key in halodata[i].keys(): if (key == 'SimulationInfo' or key == 'UnitInfo' or key == "ConfigurationInfo"): continue if (halodata[i][key].dtype == np.float64): halodata[i][key] = np.array(halodata[i][key], dtype=np.float32) print('Finished reading halo properties') #produce head tail in ascending order start = time.clock() print("Building head/tail ") vpt.BuildTemporalHeadTailDescendant(numsnaps, rawtreedata, numhalos, halodata, TEMPORALHALOIDVAL) print("Finished head/tail ", time.clock() - start)
1, True) elif (TREEDIRECTION == 0): print( 'Warning, progenitor based trees are less useful when building halo merger trees for SAMs.' ) rawtreedata = vpt.ReadHaloMergerTree(fname, RAWTREEFORMAT, 1, True) else: print('Full graphs to walkable trees not implemented yet.') print('Finished reading raw tree') numhalos = np.zeros(numsnaps, dtype=np.uint64) halodata = [dict() for i in range(numsnaps)] atime = np.zeros(numsnaps) for i in range(numsnaps): halodata[i], numhalos[i] = vpt.ReadPropertyFile( halocatalogdir + '/snapshot_%03d.VELOCIraptor' % i, 2, 0, 1, requestedfields) atime[i] = halodata[i]['SimulationInfo']['ScaleFactor'] for key in halodata[i].keys(): if (key == 'SimulationInfo' or key == 'UnitInfo' or key == "ConfigurationInfo"): continue if (halodata[i][key].dtype == np.float64): halodata[i][key] = np.array(halodata[i][key], dtype=np.float32) print('Finished reading halo properties') #produce head tail in ascending order start = time.clock() print("Building head/tail ") vpt.BuildTemporalHeadTailDescendant(numsnaps, rawtreedata, numhalos, halodata, TEMPORALHALOIDVAL)