def reset_global_particle_IDs(obj): ''' Maps particle lists from currently loaded ID's to the ID's corresponding to the full snapshot ''' # determine full particle numbers in snapshot from caesar.property_manager import has_ptype, get_property offset = np.zeros(len(obj.data_manager.ptypes) + 1, dtype=np.int64) for ip, p in enumerate(obj.data_manager.ptypes): if not has_ptype(obj, p): continue count = len(get_property(obj, 'mass', p)) if p == 'gas': offset[ip + 1] = offset[ip] + obj.simulation.ngas obj.simulation.ngas = count elif p == 'star': offset[ip + 1] = offset[ip] + obj.simulation.nstar obj.simulation.nstar = count elif p == 'bh': offset[ip + 1] = offset[ip] + obj.simulation.nbh obj.simulation.nbh = count elif p == 'dust': offset[ip + 1] = offset[ip] + obj.simulation.ndust obj.simulation.ndust = count elif p == 'dm': offset[ip + 1] = offset[ip] + obj.simulation.ndm obj.simulation.ndm = count elif p == 'dm2': offset[ip + 1] = offset[ip] + obj.simulation.ndm2 obj.simulation.ndm2 = count elif p == 'dm3': offset[ip + 1] = offset[ip] + obj.simulation.ndm3 obj.simulation.ndm3 = count # reset lists for group_type in obj.group_types: group_list = 'obj.%s_list' % group_type for ip, p in enumerate(obj.data_manager.ptypes): if not has_ptype(obj, p): continue for group in eval(group_list): part_list = 'group.%s' % plist_dict[p] mylist = eval(part_list) mylist = obj.data_manager.indexes[mylist + offset[ip]] if p == 'gas': group.glist = mylist if p == 'star': group.slist = mylist if p == 'bh': group.bhlist = mylist if p == 'dust': group.dlist = mylist if p == 'dm': group.dmlist = mylist if p == 'dm2': group.dm2list = mylist if p == 'dm3': group.dm3list = mylist return
def load_global_lists(obj): # initialize global particle lists from caesar.property_manager import has_ptype for group_type in obj.group_types: glist = np.full(obj.simulation.ngas, -1, dtype=np.int32) slist = np.full(obj.simulation.nstar, -1, dtype=np.int32) bhlist = np.full(obj.simulation.nbh, -1, dtype=np.int32) dlist = np.full(obj.simulation.ndust, -1, dtype=np.int32) dmlist = np.full(obj.simulation.ndm, -1, dtype=np.int32) dm2list = np.full(obj.simulation.ndm2, -1, dtype=np.int32) group_list = 'obj.%s_list' % group_type for group in eval(group_list): for ip, p in enumerate(obj.data_manager.ptypes): if not has_ptype(obj, p): continue part_list = 'group.%s' % plist_dict[p] if p == 'gas': glist[eval(part_list)] = group.GroupID if p == 'star': slist[eval(part_list)] = group.GroupID if p == 'bh': bhlist[eval(part_list)] = group.GroupID if p == 'dust': dlist[eval(part_list)] = group.GroupID if p == 'dm': dmlist[eval(part_list)] = group.GroupID if p == 'dm2': dm2list[eval(part_list)] = group.GroupID setattr(obj.global_particle_lists, '%s_glist' % group_type, glist) setattr(obj.global_particle_lists, '%s_slist' % group_type, slist) setattr(obj.global_particle_lists, '%s_bhlist' % group_type, bhlist) setattr(obj.global_particle_lists, '%s_dlist' % group_type, dlist) setattr(obj.global_particle_lists, '%s_dmlist' % group_type, dmlist) setattr(obj.global_particle_lists, '%s_dm2list' % group_type, dm2list) return
def create_attributes(self, obj): """After loading in a yt dataset, store local attributes here.""" ds = obj.yt_dataset self.cosmological_simulation = ds.cosmological_simulation self.XH = 0.76 self.redshift = ds.current_redshift self.scale_factor = 1.0 / (1.0 + self.redshift) self.time = ds.current_time self.omega_matter = ds.omega_matter self.omega_lambda = ds.omega_lambda self.fullpath = ds.fullpath self.basename = ds.basename self.hubble_constant = ds.hubble_constant self.parameters = ds.parameters if not self.cosmological_simulation: # correct for NON comoving coordinates in non-cosmo sims if obj.units['length'].endswith( 'cm') and obj.units['length'] != 'cm': obj.units['length'] = obj.units['length'][:-2] self.boxsize = ds.domain_width[0].to(obj.units['length']) self.boxsize_units = str(self.boxsize.units) sru = 'kpc' if self.cosmological_simulation: sru += 'cm' self.search_radius = ds.quan(500.0, sru).to(obj.units['length']) H0 = self.hubble_constant * 100.0 if self.cosmological_simulation: Om_0 = ds.cosmology.omega_matter Ol_0 = ds.cosmology.omega_lambda Ok_0 = ds.cosmology.omega_curvature self.E_z = np.sqrt(Ol_0 + Ok_0 * (1.0 + self.redshift)**2 + Om_0 * (1.0 + self.redshift)**3) self.Om_z = Om_0 * (1.0 + self.redshift)**3 / self.E_z**2 H_z = H0 * self.E_z else: H_z = H0 if hasattr(ds, 'cosmology') and hasattr(ds.cosmology, 'omega_matter'): self.Om_z = ds.cosmology.omega_matter else: self.Om_z = 0.3 self.H_z = ds.quan(H_z * 3.24077929e-20, '1/s') self.G = ds.quan(4.51691362044e-39, 'kpc**3/(Msun * s**2)') ## kpc^3 / (Msun s^2) self.critical_density = ds.quan( (3.0 * self.H_z.d**2) / (8.0 * np.pi * self.G.d), 'Msun / kpc**3') #Kitayama & Suto 1996 v.469, p.480 fomega = self.Om_z * (1. + self.redshift)**3 / ( self.Om_z * (1. + self.redshift)**3 + (1. - self.Om_z - Ol_0) * (1. + self.redshift)**2 + Ol_0) virial_density = (177.65287921960845 * (1. + 0.4093 * (1. / fomega - 1.)**0.9052) - 1.) * self.Om_z #18*pi*pi self.Densities = np.array([ virial_density * self.critical_density.to('Msun/kpc**3').d, 200. * self.critical_density.to('Msun/kpc**3').d, 500. * self.critical_density.to('Msun/kpc**3').d, 2500. * self.critical_density.to('Msun/kpc**3').d ]) self.Densities = ds.arr(self.Densities, 'Msun/kpc**3') from caesar.property_manager import has_ptype self.baryons_present = False if has_ptype(obj, 'gas') or has_ptype(obj, 'star'): self.baryons_present = True
def get_mean_interparticle_separation(obj): """Calculate the mean interparticle separation and Omega Baryon. Parameters ---------- obj : :class:`main.CAESAR` Main caesar object. Returns ------- mips : float Mean inter-particle separation used for calculating FOF's b parameter. """ if hasattr(obj.simulation, 'mean_interparticle_separation'): return obj.simulation.mean_interparticle_separation if obj.yt_dataset.cosmological_simulation == 0: mylog.info( 'Non-cosmological data set detected -- setting units as specified in fubar.py' ) UT = obj.yt_dataset.current_time.to('s/h') UL = obj.yt_dataset.length_unit.to('cm/h') GRAV = obj.yt_dataset.quan(6.672e-8, 'cm**3/(g*s**2)') else: UT = obj.yt_dataset.time_unit.to('s/h') / obj.yt_dataset.scale_factor UL = obj.yt_dataset.length_unit.to('cmcm/h') GRAV = obj.yt_dataset.quan(6.672e-8, 'cmcm**3/(g*s**2)') UM = obj.yt_dataset.mass_unit.to('g/h') G = GRAV / UL**3 * UM * UT**2 ## to system units Hubble = obj.yt_dataset.quan(3.2407789e-18, 'h/s') * UT dmmass = get_property(obj, 'mass', 'dm').to('code_mass') ndm = len(dmmass) dmmass = np.sum(dmmass) # Only need this when the second family (not low res one!) of dark matter particles is presented. # if 'dm2' in obj.data_manager.ptypes: # dmmass2 = get_property(obj, 'mass', 'dm2').to('code_mass') # ndm += len(dmmass2) # dmmass += np.sum(dmmass2) gmass = obj.yt_dataset.arr(np.array([0.0]), 'code_mass') smass = obj.yt_dataset.arr(np.array([0.0]), 'code_mass') bhmass = obj.yt_dataset.arr(np.array([0.0]), 'code_mass') dustmass = obj.yt_dataset.arr(np.array([0.0]), 'code_mass') from caesar.property_manager import has_ptype if has_ptype(obj, 'gas'): gmass = get_property(obj, 'mass', 'gas').to('code_mass') if has_ptype(obj, 'star'): smass = get_property(obj, 'mass', 'star').to('code_mass') if obj.data_manager.blackholes and has_ptype(obj, 'bh'): bhmass = get_property(obj, 'mass', 'bh').to('code_mass') if obj.data_manager.dust and has_ptype(obj, 'dust'): dustmass = get_property(obj, 'mass', 'dust').to('code_mass') bmass = np.sum(gmass) + np.sum(smass) + np.sum(bhmass) + np.sum(dustmass) """ DM = obj.data_manager dmmass = DM.mass[DM.dmlist] gmass = DM.mass[DM.glist] smass = DM.mass[DM.slist] bhmass = DM.mass[DM.bhlist] ndm = len(dmmass) dmmass = obj.yt_dataset.quan(np.sum(dmmass), obj.units['mass']).to('code_mass') bmass = obj.yt_dataset.quan(np.sum(gmass) + np.sum(smass) + np.sum(bhmass), obj.units['mass']).to('code_mass') """ #if its an idealized simulation, then there's no cosmology and we just take z=0 Planck15 values if obj.yt_dataset.cosmological_simulation == 0: from astropy.cosmology import Planck15 Om = Planck15.Om0 Ob = Planck15.Ob0 else: Om = obj.yt_dataset.cosmology.omega_matter Ob = (bmass / (bmass + dmmass) * Om).d rhodm = ((Om - Ob) * 3.0 * Hubble**2 / (8.0 * np.pi * G)).d rhodm = obj.yt_dataset.quan(rhodm, 'code_mass/code_length**3') mips = ((dmmass / ndm / rhodm)**(1. / 3.)).to(obj.units['length']) efres = int(obj.simulation.boxsize.d / mips.d) obj.simulation.omega_baryon = float(Ob) obj.simulation.effective_resolution = efres obj.simulation.mean_interparticle_separation = mips mylog.info('Calculated Omega_Baryon=%g and %d^3 effective resolution' % (Ob, efres)) return obj.simulation.mean_interparticle_separation
def create_attributes(self, obj): """After loading in a yt dataset, store local attributes here.""" ds = obj.yt_dataset self.cosmological_simulation = ds.cosmological_simulation self.XH = 0.76 self.redshift = ds.current_redshift self.scale_factor = 1.0 / (1.0 + self.redshift) self.time = ds.current_time self.omega_matter = ds.omega_matter self.omega_lambda = ds.omega_lambda self.fullpath = ds.fullpath self.basename = ds.basename self.hubble_constant = ds.hubble_constant self.parameters = ds.parameters if not self.cosmological_simulation: # correct for NON comoving coordinates in non-cosmo sims if obj.units['length'].endswith('cm') and obj.units['length'] != 'cm': obj.units['length'] = obj.units['length'][:-2] self.boxsize = ds.domain_width[0].to(obj.units['length']) self.boxsize_units = str(self.boxsize.units) sru = 'kpc' if self.cosmological_simulation: sru += 'cm' self.search_radius = ds.arr([300,1000,3000], sru).to(obj.units['length']) # default values H0 = ds.quan(self.hubble_constant * 100.0 * 3.24077929e-20, '1/s') if self.cosmological_simulation: Om_0 = ds.cosmology.omega_matter Ol_0 = ds.cosmology.omega_lambda Ok_0 = ds.cosmology.omega_curvature self.E_z = np.sqrt( Ol_0 + Ok_0 * (1.0 + self.redshift)**2 + Om_0 * (1.0 + self.redshift)**3 ) self.Om_z = Om_0 * (1.0 + self.redshift)**3 / self.E_z**2 H_z = H0 * self.E_z #Kitayama & Suto 1996 v.469, p.480 fomega = Om_0*(1.+self.redshift)**3 / self.E_z**2 if fomega >=1.0: mylog.warning('fomega out of bounds! fomega=%g %g %g %g'%(fomega,self.Om_z,self.redshift,Ol_0)) else: H_z = H0 if hasattr(ds, 'cosmology') and hasattr(ds.cosmology, 'omega_matter'): self.Om_z = ds.cosmology.omega_matter else: self.Om_z = 0.3 fomega = self.Om_z self.H_z = H_z self.G = ds.quan(4.51691362044e-39, 'kpc**3/(Msun * s**2)') ## kpc^3 / (Msun s^2) self.critical_density = ds.quan( (3.0 * H_z**2) / (8.0 * np.pi * self.G.d), 'Msun / kpc**3' ) virial_density = (177.65287921960845*(1. + 0.4093*(1./fomega - 1.)**0.9052) - 1.)*self.Om_z #Kitayama & Suto 1996 v.469, p.480 #print(self.critical_density, self.critical_density.to('g/cm**3'),self.H_z.to('1/s'),(3.0 * H0.d**2) / (8.0 * np.pi * self.G.d)) # Romeel: Removed virial density, because the FOF with b=0.2*MIS # only finds contour enclosing ~200, so halos do not have all the particles they # need to compute spherical ~100xrhocrit. #self.Densities = np.array([virial_density*self.critical_density.to('Msun/kpc**3').d, self.Densities = np.array([ 200.*self.critical_density.to('Msun/kpc**3').d, 500.*self.critical_density.to('Msun/kpc**3').d, 2500.*self.critical_density.to('Msun/kpc**3').d]) self.Densities = ds.arr(self.Densities, 'Msun/kpc**3') from caesar.property_manager import has_ptype self.baryons_present = False if has_ptype(obj, 'gas') or has_ptype(obj, 'star'): self.baryons_present = True