def _load_gas_data(self): """If gas is present loads gas SFR/Metallicity/Temperatures.""" if self.obj.simulation.ngas == 0: return sfr_unit = '%s/%s' % (self.obj.units['mass'], self.obj.units['time']) dustmass_unit = '%s' % (self.obj.units['mass']) sfr = self.obj.yt_dataset.arr(np.zeros(self.obj.simulation.ngas), sfr_unit) gZ = self.obj.yt_dataset.arr(np.zeros(self.obj.simulation.ngas), '') gT = self.obj.yt_dataset.arr(np.zeros(self.obj.simulation.ngas), self.obj.units['temperature']) dustmass = self.obj.yt_dataset.arr(np.zeros(self.obj.simulation.ngas),'') #dustmass = self.obj.yt_dataset.arr(np.zeros(self.obj.simulation.ngas), '')#dustmass_unit) if has_property(self.obj, 'gas', 'sfr'): sfr = get_property(self.obj, 'sfr', 'gas').to(sfr_unit) if has_property(self.obj, 'gas', 'metallicity'): gZ = get_property(self.obj, 'metallicity', 'gas') if has_property(self.obj, 'gas', 'temperature'): gT = get_property(self.obj, 'temperature', 'gas').to(self.obj.units['temperature']) if has_property(self.obj, 'gas', 'dustmass'): dustmass = get_property(self.obj,'dustmass','gas') #dustmass = get_property(self.obj,'dustmass','gas'))#.to(dustmass_unit) self.gsfr = sfr self.gZ = gZ self.gT = gT self.dustmass = self.obj.yt_dataset.arr(dustmass,'code_mass').in_units('Msun')
def _load_bh_data(self, select='all'): """If blackholes are present, loads BH_Mdot""" if select is 'all': flag = [True]*self.obj.simulation.nbh else: flag = (select>=0) if has_property(self.obj, 'bh', 'bhmass'): self.bhmass = self.obj.yt_dataset.arr(get_property(self.obj, 'bhmass', 'bh').d[flag]*1e10, 'Msun/h').to(self.obj.units['mass']) # I don't know how to convert this automatically self.use_bhmass = True else: mylog.warning('No black holes found') self.use_bhmass = False if has_property(self.obj, 'bh', 'bhmdot') and self.use_bhmass: #units mutlitplied by ((All.UnitMass_in_g / SOLAR_MASS) / (All.UnitTime_in_s / SEC_PER_YEAR)) bhmdot_unit = '10.22465727143273*Msun/h/yr' #bhmdot_unit = '15.036260693283424*Msun/yr' #bhmdot_unit = '%s/%s' %(self.obj.units['mass'], self.obj.units['time']) bhmdot = get_property(self.obj, 'bhmdot', 'bh').d[flag] #of course it is dimentionless bhmdot = self.obj.yt_dataset.arr(bhmdot, bhmdot_unit).to('%s/%s' %(self.obj.units['mass'], self.obj.units['time'])) self.bhmdot = bhmdot #mylog.info('BH_Mdot available, units=%s'%bhmdot_unit) else: if self.use_bhmass: mylog.warning('Black holes are there, but BH_Mdot not available!')
def _load_star_data(self, select='all'): """If star is present load Metallicity if present""" if self.obj.simulation.nstar == 0: return if select is 'all': flag = [True]*self.obj.simulation.nstar else: flag = (select>=0) if has_property(self.obj, 'star', 'metallicity'): self.sZ = get_property(self.obj, 'metallicity', 'star')[flag] elif has_property(self.obj, 'star', 'met_tng'): # try Illustris/TNG alias self.sZ = get_property(self.obj, 'met_tng', 'star')[flag] #self.sZ = np.sum(self.sZ.T[2:],axis=0) # first two are H,He; the rest sum to give metallicity #self.sZ[self.sZ<0] = 0. # some (very small) negative values, set to 0 else: mylog.warning('Metallicity not found: setting all stars to solar=0.0134') self.sZ = 0.0134*np.ones(self.obj.simulation.nstar,dtype=MY_DTYPE) ds = self.obj.yt_dataset if has_property(self.obj, 'star', 'aform'): self.age = get_property(self.obj, 'aform', 'star')[flag] # a_exp at time of formation elif has_property(self.obj, 'star', 'aform_tng'): # try Illustris/TNG alias self.age = get_property(self.obj, 'aform_tng', 'star')[flag] self.age = abs(self.age) # some negative values here too; not sure what to do? else: self.age = np.zeros(self.obj.simulation.nstar,dtype=MY_DTYPE) mylog.warning('Stellar age not found -- photometry will be incorrect!') if ds.cosmological_simulation: from yt.utilities.cosmology import Cosmology co = Cosmology(hubble_constant=ds.hubble_constant, omega_matter=ds.omega_matter, omega_lambda=ds.omega_lambda) self.age = (ds.current_time - co.t_from_z(1./self.age-1.)).in_units('Gyr').astype(MY_DTYPE) # age at time of snapshot
def _load_star_data(self): """If star is present load Metallicity if present""" if self.obj.simulation.nstar == 0: return if has_property(self.obj, 'star', 'metallicity'): self.sZ = get_property(self.obj, 'metallicity', 'star')
def _load_bh_data(self): """If blackholes are present, loads BH_Mdot""" from yt.funcs import mylog if has_property(self.obj, 'bh', 'bhmass'): self.bhmass = self.obj.yt_dataset.arr(get_property(self.obj, 'bhmass', 'bh').d*1e10, 'Msun/h').to(self.obj.units['mass'])#I don't know how to convert this automatically self.use_bhmass = True mylog.info('BH_Mass available, units=1e10 Msun/h') mylog.info('Using BH_Mass instead of BH particle masses') else: mylog.info('Using BH particle mass') if has_property(self.obj, 'bh', 'bhmdot'): #units mutlitplied by ((All.UnitMass_in_g / SOLAR_MASS) / (All.UnitTime_in_s / SEC_PER_YEAR)) bhmdot_unit = '10.22465727143273*Msun/h/yr' #bhmdot_unit = '15.036260693283424*Msun/yr' #bhmdot_unit = '%s/%s' %(self.obj.units['mass'], self.obj.units['time']) bhmdot = get_property(self.obj, 'bhmdot', 'bh').d #of course it is dimentionless bhmdot = self.obj.yt_dataset.arr(bhmdot, bhmdot_unit).to('%s/%s' %(self.obj.units['mass'], self.obj.units['time'])) self.bhmdot = bhmdot mylog.info('BH_Mdot available, units=%s'%bhmdot_unit) else: mylog.warning('BH_Mdot not available')
def get_group_properties(self, grp_list): from caesar.group_funcs import get_group_overall_properties, get_group_gas_properties, get_group_star_properties, get_group_bh_properties get_group_overall_properties(self, grp_list) if 'gas' in self.obj.data_manager.ptypes: get_group_gas_properties(self, grp_list) if 'star' in self.obj.data_manager.ptypes: get_group_star_properties(self, grp_list) if (self.obj.data_manager.blackholes): if (self.obj.data_manager.blackholes) & has_property( self.obj, 'bh', 'bhmdot'): get_group_bh_properties(self, grp_list) from caesar.utils import calculate_local_densities calculate_local_densities(self.obj, grp_list) if self.obj_type == 'halo': sort_groups(grp_list, 'total') self.obj.halos = self.obj.halo_list self.obj.nhalos = len(self.obj.halo_list) if (self.obj_type == 'galaxy') and (len(grp_list) > 0): # compute some extra quantities for galaxies from caesar.hydrogen_mass_calc import get_HIH2_masses, _get_aperture_masses, _get_aperture_quan if 'aperture' in self.obj._kwargs: aperture = float(self.obj._kwargs['aperture']) else: aperture = 30 # this is the default in units of obj.units['length'] get_HIH2_masses(self, aperture=aperture) # _get_aperture_masses(self,aperture=aperture) _get_aperture_quan(self, aperture=aperture) if 'half_stellar_radius_property' in self.obj._kwargs: _get_aperture_quan(self, aperture=np.asarray([ i.radii['stellar_half_mass'].value for i in grp_list ]), aptname='stellar_half_mass_radius') # sort and load galaxies into list sort_groups(grp_list, 'stellar') self.obj.galaxies = self.obj.galaxy_list self.obj.ngalaxies = len(self.obj.galaxy_list) if self.obj_type == 'cloud': sort_groups(grp_list, 'gas') self.obj.clouds = self.obj.cloud_list self.obj.nclouds = len(self.obj.cloud_list) return
def _load_gas_data(self, select='all'): """If gas is present loads gas SFR, metallicities, temperatures, nH. If select is not 'all', return all particles with select>=0 """ if self.obj.simulation.ngas == 0: return sfr_unit = '%s/%s' % (self.obj.units['mass'], self.obj.units['time']) dustmass_unit = '%s' % (self.obj.units['mass']) gnh_unit = '1/%s**3' % (self.obj.units['length']) sfr = self.obj.yt_dataset.arr( np.zeros(self.obj.simulation.ngas, dtype=MY_DTYPE), sfr_unit) gZ = self.obj.yt_dataset.arr( np.zeros(self.obj.simulation.ngas, dtype=MY_DTYPE), '') gT = self.obj.yt_dataset.arr( np.zeros(self.obj.simulation.ngas, dtype=MY_DTYPE), self.obj.units['temperature']) gnh = self.obj.yt_dataset.arr( np.zeros(self.obj.simulation.ngas, dtype=MY_DTYPE), gnh_unit) dustmass = self.obj.yt_dataset.arr( np.zeros(self.obj.simulation.ngas, dtype=MY_DTYPE), '') gfHI = self.obj.yt_dataset.arr( np.zeros(self.obj.simulation.ngas, dtype=MY_DTYPE), '') gfH2 = self.obj.yt_dataset.arr( np.zeros(self.obj.simulation.ngas, dtype=MY_DTYPE), '') ghsml = self.obj.yt_dataset.arr( np.zeros(self.obj.simulation.ngas, dtype=MY_DTYPE), self.obj.units['length']) #dustmass = self.obj.yt_dataset.arr(np.zeros(self.obj.simulation.ngas), '')#dustmass_unit) if isinstance(select, str) and select == 'all': flag = [True] * self.obj.simulation.ngas else: flag = (select >= 0) if has_property(self.obj, 'gas', 'sfr'): sfr = get_property(self.obj, 'sfr', 'gas')[flag].to(sfr_unit) if has_property(self.obj, 'gas', 'metallicity'): gZ = get_property(self.obj, 'metallicity', 'gas')[flag] elif has_property(self.obj, 'gas', 'met_tng'): gZ = get_property(self.obj, 'met_tng', 'gas')[flag] # for Illustris, array of mets else: mylog.warning( 'Metallicity not found: setting all gas to solar=0.0134') gZ = 0.0134 * np.ones(self.obj.simulation.nstar, dtype=MY_DTYPE) if has_property(self.obj, 'gas', 'nh'): gfHI = get_property(self.obj, 'nh', 'gas')[flag] else: mylog.warning( 'HI fractions not found in snapshot, will compute later') if has_property(self.obj, 'gas', 'fh2'): gfH2 = get_property(self.obj, 'fh2', 'gas')[flag] else: mylog.warning( 'H2 fractions not found in snapshot, will compute later') if has_property(self.obj, 'gas', 'temperature'): gT = get_property(self.obj, 'temperature', 'gas')[flag].to(self.obj.units['temperature']) if has_property(self.obj, 'gas', 'hsml'): ghsml = get_property(self.obj, 'hsml', 'gas')[flag].to(self.obj.units['length']) if has_property(self.obj, 'gas', 'rho'): from astropy import constants as const from yt import YTQuantity redshift = self.obj.simulation.redshift m_p = YTQuantity.from_astropy(const.m_p) gnh = get_property(self.obj, 'rho', 'gas')[flag].in_cgs() * 0.76 / m_p.in_cgs() if has_property(self.obj, 'gas', 'dustmass'): dustmass = get_property(self.obj, 'dustmass', 'gas')[flag] else: mylog.warning('Dust masses not found in snapshot') self.gsfr = sfr self.gZ = gZ self.gT = gT self.gnh = gnh self.gfHI = gfHI self.gfH2 = gfH2 self.hsml = ghsml self.dustmass = self.obj.yt_dataset.arr(dustmass, 'code_mass').in_units('Msun') self.dustmass.dtype = MY_DTYPE