def set_stellar_grid(self): """Set up a grid around each halo containing the stellar column density """ self.sub_star_grid=np.zeros([self.nhalo, self.ngrid[0],self.ngrid[0]]) self.once=True #Now grid the HI for each halo files = hdfsim.get_all_files(self.snapnum, self.snap_dir) #Larger numbers seem to be towards the beginning files.reverse() for ff in files: f = h5py.File(ff,"r") print "Starting file ",ff bar=f["PartType4"] ipos=np.array(bar["Coordinates"]) #Get HI mass in internal units mass=np.array(bar["Masses"]) smooth = np.array(bar["SubfindHsml"]) [self.sub_gridize_single_file(ii,ipos,smooth,mass,self.sub_star_grid) for ii in xrange(0,self.nhalo)] f.close() #Explicitly delete some things. del ipos del mass del smooth #we calculated things in internal gadget /cell and we want atoms/cm^2 #So the conversion is mass/(cm/cell)^2 for ii in xrange(0,self.nhalo): massg=self.UnitMass_in_g/self.hubble*self.hy_mass/self.protonmass epsilon=2.*self.sub_radii[ii]/(self.ngrid[ii])*self.UnitLength_in_cm/self.hubble/(1+self.redshift) self.sub_star_grid[ii]*=(massg/epsilon**2) return
def set_nHI_grid(self, gas=False): """Set up the grid around each halo where the HI is calculated. """ self.once=True #Now grid the HI for each halo files = hdfsim.get_all_files(self.snapnum, self.snap_dir) #Larger numbers seem to be towards the beginning files.reverse() for ff in files: f = h5py.File(ff,"r") print "Starting file ",ff bar=f["PartType0"] ipos=np.array(bar["Coordinates"]) smooth = hsml.get_smooth_length(bar) [self.sub_gridize_single_file(ii,ipos,smooth,bar,self.sub_nHI_grid) for ii in xrange(0,self.nhalo)] f.close() #Explicitly delete some things. del ipos del smooth #Deal with zeros: 0.1 will not even register for things at 1e17. #Also fix the units: #we calculated things in internal gadget /cell and we want atoms/cm^2 #So the conversion is mass/(cm/cell)^2 for ii in xrange(0,self.nhalo): massg=self.UnitMass_in_g/self.hubble*self.hy_mass/self.protonmass epsilon=2.*self.sub_radii[ii]/(self.ngrid[ii])*self.UnitLength_in_cm/self.hubble/(1+self.redshift) self.sub_nHI_grid[ii]*=(massg/epsilon**2) self.sub_nHI_grid[ii]+=0.1 [np.log10(grid,grid) for grid in self.sub_nHI_grid] return
def set_zdir_grid(self, dlaind, gas=False, key="zpos", ion=-1): """Set up the grid around each halo where the HI is calculated. """ star=cold_gas.RahmatiRT(self.redshift, self.hubble, molec=self.molec) self.once=True #Now grid the HI for each halo files = hdfsim.get_all_files(self.snapnum, self.snap_dir) #Larger numbers seem to be towards the beginning files.reverse() self.xslab = np.zeros_like(dlaind[0], dtype=np.float64) try: start = self.load_fast_tmp(self.start, key) except IOError: start = self.start end = np.min([np.size(files),self.end]) for xx in xrange(start,end): ff = files[xx] f = h5py.File(ff,"r") print "Starting file ",ff bar=f["PartType0"] ipos=np.array(bar["Coordinates"]) #Get HI mass in internal units mass=np.array(bar["Masses"]) if not gas: #Hydrogen mass fraction try: mass *= np.array(bar["GFM_Metals"][:,0]) except KeyError: mass *= self.hy_mass nhi = star.get_reproc_HI(bar) ind = np.where(nhi > 1.e-3) ipos = ipos[ind,:][0] mass = mass[ind] #Get x * m for the weighted z direction if not gas: mass *= nhi[ind] if key == "zpos": mass*=ipos[:,0] elif key != "": mass *= self._get_secondary_array(ind,bar,key, ion) smooth = hsml.get_smooth_length(bar)[ind] for slab in xrange(self.nhalo): ind = np.where(dlaind[0] == slab) self.xslab[ind] += self.sub_list_grid_file(slab,ipos,smooth,mass,dlaind[1][ind], dlaind[2][ind]) f.close() #Explicitly delete some things. del ipos del mass del smooth self.save_fast_tmp(start,key) #Fix the units: #we calculated things in internal gadget /cell and we want atoms/cm^2 #So the conversion is mass/(cm/cell)^2 massg=self.UnitMass_in_g/self.hubble/self.protonmass epsilon=2.*self.sub_radii[0]/(self.ngrid[0])*self.UnitLength_in_cm/self.hubble/(1+self.redshift) self.xslab*=(massg/epsilon**2) return self.xslab
def set_nHI_grid(self, gas=False, start=0): """Set up the grid around each halo where the HI is calculated. """ star=cold_gas.RahmatiRT(self.redshift, self.hubble, molec=self.molec) self.cloudy_table = convert_cloudy.CloudyTable(self.redshift) self.once=True #Now grid the HI for each halo files = hdfsim.get_all_files(self.snapnum, self.snap_dir) #Larger numbers seem to be towards the beginning files.reverse() end = np.min([np.size(files),self.end]) for xx in xrange(start, end): ff = files[xx] f = h5py.File(ff,"r") print "Starting file ",ff bar=f["PartType0"] ipos=np.array(bar["Coordinates"]) #Get HI mass in internal units mass=np.array(bar["Masses"]) #Carbon mass fraction den = star.get_code_rhoH(bar) temp = star.get_temp(bar) mass_frac = np.array(bar["GFM_Metals"][:,2]) #Floor on the mass fraction of the metal ind = np.where(mass_frac > 1e-10) mass = mass[ind]*mass_frac[ind] #High densities will have no CIV anyway. den[np.where(den > 1e4)] = 9999. den[np.where(den < 1e-7)] = 1.01e-7 temp[np.where(temp > 3e8)] = 3e8 temp[np.where(temp < 1e3)] = 1e3 mass *= self.cloudy_table.ion("C", self.ion, den[ind], temp[ind]) smooth = hsml.get_smooth_length(bar)[ind] ipos = ipos[ind,:][0] [self.sub_gridize_single_file(ii,ipos,smooth,mass,self.sub_nHI_grid) for ii in xrange(0,self.nhalo)] f.close() #Explicitly delete some things. del ipos del mass del smooth #Deal with zeros: 0.1 will not even register for things at 1e17. #Also fix the units: #we calculated things in internal gadget /cell and we want atoms/cm^2 #So the conversion is mass/(cm/cell)^2 for ii in xrange(0,self.nhalo): massg=self.UnitMass_in_g/self.hubble/(self.protonmass*12.011) epsilon=2.*self.sub_radii[ii]/(self.ngrid[ii])*self.UnitLength_in_cm/self.hubble/(1+self.redshift) self.sub_nHI_grid[ii]*=(massg/epsilon**2) self.sub_nHI_grid[ii]+=0.1 np.log10(self.sub_nHI_grid[ii],self.sub_nHI_grid[ii]) return
def set_nHI_grid(self, gas=False, start=0): """Set up the grid around each halo where the HI is calculated. """ star=cold_gas.RahmatiRT(self.redshift, self.hubble, molec=self.molec) self.once=True #Now grid the HI for each halo files = hdfsim.get_all_files(self.snapnum, self.snap_dir) #Larger numbers seem to be towards the beginning files.reverse() restart = 10 end = np.min([np.size(files),self.end]) for xx in xrange(start, end): ff = files[xx] f = h5py.File(ff,"r") print "Starting file ",ff bar=f["PartType0"] ipos=np.array(bar["Coordinates"]) #Get HI mass in internal units mass=np.array(bar["Masses"]) if not gas: #Hydrogen mass fraction try: mass *= np.array(bar["GFM_Metals"][:,0]) except KeyError: mass *= self.hy_mass mass *= star.get_reproc_HI(bar) smooth = hsml.get_smooth_length(bar) [self.sub_gridize_single_file(ii,ipos,smooth,mass,self.sub_nHI_grid) for ii in xrange(0,self.nhalo)] f.close() #Explicitly delete some things. del ipos del mass del smooth if xx % restart == 0 or xx == end-1: self.save_tmp(xx) #Deal with zeros: 0.1 will not even register for things at 1e17. #Also fix the units: #we calculated things in internal gadget /cell and we want atoms/cm^2 #So the conversion is mass/(cm/cell)^2 for ii in xrange(0,self.nhalo): massg=self.UnitMass_in_g/self.hubble/self.protonmass epsilon=2.*self.sub_radii[ii]/(self.ngrid[ii])*self.UnitLength_in_cm/self.hubble/(1+self.redshift) self.sub_nHI_grid[ii]*=(massg/epsilon**2) np.log10(self.sub_nHI_grid[ii],self.sub_nHI_grid[ii]) return
def set_ZZ_grid(self, start=0): """Set up the mass * metallicity grid for the box Same as set_nHI_grid except mass is multiplied by GFM_Metallicity. """ self.once=True #Now grid the HI for each halo files = hdfsim.get_all_files(self.snapnum, self.snap_dir) #Larger numbers seem to be towards the beginning files.reverse() restart = 10 end = np.min([np.size(files),self.end]) for xx in xrange(start, end): ff = files[xx] f = h5py.File(ff,"r") print "Starting file ",ff bar=f["PartType0"] ipos=np.array(bar["Coordinates"]) #Get HI mass in internal units mass=np.array(bar["Masses"]) #Sometimes the metallicity is less than zero: fix that met = np.array(bar["GFM_Metallicity"]) met[np.where(met <=0)] = 1e-50 mass *= met smooth = hsml.get_smooth_length(bar) [self.sub_gridize_single_file(ii,ipos,smooth,mass,self.sub_ZZ_grid) for ii in xrange(0,self.nhalo)] f.close() #Explicitly delete some things. del ipos del mass del smooth if xx % restart == 0 or xx == end-1: self.save_met_tmp(xx) #Deal with zeros: 0.1 will not even register for things at 1e17. #Also fix the units: #we calculated things in internal gadget /cell and we want atoms/cm^2 #So the conversion is mass/(cm/cell)^2 for ii in xrange(0,self.nhalo): massg=self.UnitMass_in_g/self.hubble/self.protonmass epsilon=2.*self.sub_radii[ii]/(self.ngrid[ii])*self.UnitLength_in_cm/self.hubble/(1+self.redshift) self.sub_ZZ_grid[ii]*=(massg/epsilon**2) self.sub_ZZ_grid[ii]+=0.1 np.log10(self.sub_ZZ_grid[ii],self.sub_ZZ_grid[ii]) return
def set_stellar_grid(self): """Set up a grid around each halo containing the stellar column density """ self.sub_star_grid = np.zeros( [self.nhalo, self.ngrid[0], self.ngrid[0]]) self.once = True #Now grid the HI for each halo files = hdfsim.get_all_files(self.snapnum, self.snap_dir) #Larger numbers seem to be towards the beginning files.reverse() for ff in files: f = h5py.File(ff, "r") print "Starting file ", ff bar = f["PartType4"] ipos = np.array(bar["Coordinates"]) #Get HI mass in internal units mass = np.array(bar["Masses"]) smooth = np.array(bar["SubfindHsml"]) [ self.sub_gridize_single_file(ii, ipos, smooth, mass, self.sub_star_grid) for ii in xrange(0, self.nhalo) ] f.close() #Explicitly delete some things. del ipos del mass del smooth #we calculated things in internal gadget /cell and we want atoms/cm^2 #So the conversion is mass/(cm/cell)^2 for ii in xrange(0, self.nhalo): massg = self.UnitMass_in_g / self.hubble * self.hy_mass / self.protonmass epsilon = 2. * self.sub_radii[ii] / ( self.ngrid[ii]) * self.UnitLength_in_cm / self.hubble / ( 1 + self.redshift) self.sub_star_grid[ii] *= (massg / epsilon**2) return
def set_zdir_grid(self, dlaind, gas=False, key="zpos", ion=-1): """Set up the grid around each halo where the HI is calculated. """ star = cold_gas.RahmatiRT(self.redshift, self.hubble, molec=self.molec) self.once = True #Now grid the HI for each halo files = hdfsim.get_all_files(self.snapnum, self.snap_dir) #Larger numbers seem to be towards the beginning files.reverse() self.xslab = np.zeros_like(dlaind[0], dtype=np.float64) try: start = self.load_fast_tmp(self.start, key) except IOError: start = self.start end = np.min([np.size(files), self.end]) for xx in xrange(start, end): ff = files[xx] f = h5py.File(ff, "r") print "Starting file ", ff bar = f["PartType0"] ipos = np.array(bar["Coordinates"]) #Get HI mass in internal units mass = np.array(bar["Masses"]) if not gas: #Hydrogen mass fraction try: mass *= np.array(bar["GFM_Metals"][:, 0]) except KeyError: mass *= self.hy_mass nhi = star.get_reproc_HI(bar) ind = np.where(nhi > 1.e-3) ipos = ipos[ind, :][0] mass = mass[ind] #Get x * m for the weighted z direction if not gas: mass *= nhi[ind] if key == "zpos": mass *= ipos[:, 0] elif key != "": mass *= self._get_secondary_array(ind, bar, key, ion) smooth = hsml.get_smooth_length(bar)[ind] for slab in xrange(self.nhalo): ind = np.where(dlaind[0] == slab) self.xslab[ind] += self.sub_list_grid_file( slab, ipos, smooth, mass, dlaind[1][ind], dlaind[2][ind]) f.close() #Explicitly delete some things. del ipos del mass del smooth self.save_fast_tmp(start, key) #Fix the units: #we calculated things in internal gadget /cell and we want atoms/cm^2 #So the conversion is mass/(cm/cell)^2 massg = self.UnitMass_in_g / self.hubble / self.protonmass epsilon = 2. * self.sub_radii[0] / ( self.ngrid[0]) * self.UnitLength_in_cm / self.hubble / ( 1 + self.redshift) self.xslab *= (massg / epsilon**2) return self.xslab