示例#1
0
 def get_shape(self, idx, sub_idx=-1):
     """
     Returns:
     -> -1 if i) the halo has no subhalos ii) either b/a or c/a are 0 or 1
     -> else return a pynbody shape object
     """
     if sub_idx<0:
         with centering_com(self._halos[idx]):
             shape = pn.analysis.halo.halo_shape(self._halos[idx], 
                                                 N=1, bins='lin')
     else:
         if len(self._subhalos[idx])==0:
             warnings.warn('This halo has no subhalos!')
             return -1
         with centering_com(self._subhalos[idx][sub_idx][1], 
                            r=self._halos[idx].properties['Halo_R_Crit200'].in_units('kpc')):
             shape = pn.analysis.halo.halo_shape(self._subhalos[idx][sub_idx][1], 
                                                N=1, bins='lin')
     if shape[1]>1e-5 and shape[2]>1e-5 and shape[1]<.99999 and shape[2]<.99999:
         return shape
     else:
         return -1
示例#2
0
 def is_relaxed(self, halo_idx, sub_idx=-1):
     if sub_idx < 0:
         _h = self._halos[halo_idx]
     else:
         if len(self._subhalos[halo_idx])==0:
             warnings.warn('This halo has no subhalos!')
             return -1
         _h = self._subhalos[halo_idx][sub_idx][1]
     with centering_com(_h, r=self._halos[halo_idx].properties['Halo_R_Crit200'].in_units('kpc')): 
         #_com = pn.analysis.halo.center_of_mass(_h)
         _com = pn.analysis.halo.shrink_sphere_center(_h, 
                                 r=self._halos[halo_idx].properties['Halo_R_Crit200'].in_units('kpc'))
         _r200 = self._get_r200(halo_idx)
         _dist = np.sqrt( np.power(_h[0]['pos']-_com,2).sum() )
         #The minimum potential point is obtained with:
         #halo[halo_index].subhalo[subhalo_index][0]['pos']
     return bool(_dist < 0.07*_r200)
st = FLAGS.sim_types
addition = '' 
if FLAGS.sim_sizes==['128']: addition='.hdf5'
path_first = ['/fred/oz071/aduffy/Smaug/'+st[i]+'_L010N0'+FLAGS.sim_sizes[0] +'/data' for i in range(len(st))]
path1 = [os.path.join(path_first[i], 'subhalos_103/subhalo_103') for i in range(len(st))]
path2 = [os.path.join(path_first[i], 'snapshot_103/snap_103'+addition) for i in range(len(st))]

h = [Halos(path1[i], min_size=FLAGS.sim_min_particle_number) for i in range(len(st))]
N = [h[i].get_number_halos() for i in range(len(st))]

c, M200, res, rel = ([[] for _ in range(len(st))] for i in range(4))

for isim in range(len(st)):
    for i in range(N[isim]):
        with centering_com(h[isim].get_halo(i)):
            print(h[isim].get_halo(i))
            isres = h[isim].is_resolved(i, sub_idx=0)        
            isrel = h[isim].is_relaxed(i, sub_idx=0)
            relax_tmp = h[isim].concentration_200(idx=i, sub_idx=0)
            s_tmp = h[isim].get_shape(i, 0)
            if s_tmp!=-1 and isres!=-1 and relax_tmp!=-1 and isrel!=-1:
                M200[isim].append(h[isim].get_mass200(i))
                res[isim].append(isres)     
                rel[isim].append(isrel)
                c[isim].append(relax_tmp)
    wf('file'+str(isim)+'.txt', c[isim], M200[isim], res, rel)

c_obj = plot.Concentration(c, extra_var=M200, name='figs/Concentration.png')
c_obj.set_all_properties(model='concentration_mass')
c_obj.scatter_plot(0, (0,0), resolved_bools=res, relaxed_bools=rel)
示例#4
0
    def filter_(self, halo_idxs=0, sub_idx=-1, filter_str='Sphere_1.2', option=None, sim=True):
        """
        Arguments:

        -> halo_idxs: indexes of the halos to filter; if more than one, it must be a set
        -> sub_idx: index of the subhalo. If set to a negative number, the whole halo is filtered.
        -> filters:
           1. Sphere_radius, where radius is a number relative to r200. Example: Sphere_1
           2. BandPass_prop_min_max. Example: BandPass_y_1 kpc_2 kpc. It must have units.
        -> option: None, 'half1', 'half2' or 'all' to select halos faster.
           When option!=None 'halos_idxs' is ignored.
           By default only the largest halo is filtered.
        -> sim: Whether to filter the full simulation or just the specified halo.
           This is relevant because the full simulation also includes particles
           that were not bounded to any halo or subhalo.

        Note: The inputs for each filter are separated using the underscore '_' character.
              More filters can be added to 'filter_dict' in the same fashion with variable 
              number of arguments.
        """
        if self._sim==None and sim:
            ValueError('Using the simulation in the filtering requires defining the simulation'
                       'in the class constructor.')
        if type(halo_idxs) != int and type(halo_idxs) != set:
            raise TypeError('The introduced indexes have the wrong format')
        if type(halo_idxs) is int:
            halo_idxs = {halo_idxs}

        filter_dict = {'Sphere': lambda _r,_factors,_halo: 
                       pn.filt.Sphere(float(_factors[0])*_r, com(_halo)),
                       'BandPass': lambda _r,_factors,_halo: 
                       pn.filt.BandPass(_factors[0], _factors[1], _factors[2])}
        for item in filter_dict.keys():
            if item in filter_str:
                break
            else:
               if item==[*filter_dict.keys()][-1]:
                    raise ValueError('The specified filtering option is not supported.')
        _split = filter_str.split('_')
        _split_str = _split[0]
        _split_values = {i: s for i,s in enumerate(_split[1:])}
        print("---FILTER--- Type:", _split_str, "-- Parameters:", *_split_values.values())
        _filter_func = filter_dict[_split_str]

        if option=='all': halo_idxs=range(self._N) 
        elif option=='half1': halo_idxs=range(int(self._N/2))
        elif option=='half2': halo_idxs=range(int(self._N/2),self._N)
        elif option==None: pass
        else: raise ValueError('That option is not supported')

        for i in halo_idxs:
            _r200 = self._get_r200(i)
            print("filter ", i)
            with centering_com(self._halos[i]):
                if sub_idx < 0: #filter the halo
                    if not self._check_backup(i):
                        warnings.warn('This halo backup is already being used!')
                    self._halos_bak[i] = copy.copy(self._halos[i])

                    if sim:
                        self._halos[i] = self._sim[_filter_func(_r200, _split_values, 
                                                            self._halos[i])]
                    else: 
                        self._halos[i] = self._halos[i][_filter_func(_r200, _split_values, 
                                                                 self._halos[i])]
                else: #filter the halo but centered in the subhalo
                    if not self._check_backup(i):
                        warnings.warn('This subhalo backup is already being used!')
                    if self._subhalos[i][sub_idx][0] != sub_idx:
                        raise RuntimeError('Different subhalos are being mixed!')
                        self._subhalos_bak[i][sub_idx] = self._subhalos[i][sub_idx]
                
                    #with centering_com(self._subhalos[i][sub_idx][1]):
                    if sim:
                        _subhalo = self._sim[_filter_func(_r200, _split_values, 
                                                          self._subhalos[i][sub_idx][1])]
                    else:
                        _subhalo = self._halos[i][_filter_func(_r200, _split_values, 
                                                               self._subhalos[i][sub_idx][1])]
                        self._subhalos[i][sub_idx] = (sub_idx,_subhalo)
    
            mem()
示例#5
0
        return bool(_dist < 0.07*_r200)

    def is_resolved(self, halo_idx, sub_idx=-1, intersect_value=1.):
        """
        Return either a boolean or -1, when the density profile is zero somewhere in the middle.
        """
        if sub_idx < 0:
            _h = self._halos[halo_idx]
        else:
            if len(self._subhalos[halo_idx])==0:
                warnings.warn('This halo has no subhalos!')
                return -1
            _h = self._subhalos[halo_idx][sub_idx][1]

        _rrr = self._halos[halo_idx].properties['Halo_R_Crit200'].in_units('kpc')):
        with centering_com(_h, r=_rrr):
            _r200 = self._get_r200(halo_idx)
            bins = _r200*10**binning_using_binwidth(-1.25, 0., 0.078)
            _prof = self.get_profile(halo_idx, sub_idx, component='dm', bins=bins,
                                     bin_type='custom', normalize_x=False)
            _relax = self.relaxation(halo_idx, sub_idx, _prof, bins)
            if len(_relax[0])==1 and len(_relax[1])==1:
                return -1
            _inter = intersect(_relax[1], _relax[0], intersect_value=intersect_value)
            if _inter[1]==True:            
                return _inter[0] < _r200*np.power(10,-1.25)
            else:
                warning.warn('No intersection was found for this halo. The resolution criteria'
                             'cannot thus be checked. The halo is assumed to be relaxed.')
                return True 
示例#6
0
st = FLAGS.sim_types
addition = '' 
if FLAGS.sim_sizes==['128']: addition='.hdf5'
path_first = ['/fred/oz071/aduffy/Smaug/'+st[i]+'_L010N0'+FLAGS.sim_sizes[0] +'/data' for i in range(len(st))]
path1 = [os.path.join(path_first[i], 'subhalos_103/subhalo_103') for i in range(len(st))]
path2 = [os.path.join(path_first[i], 'snapshot_103/snap_103'+addition) for i in range(len(st))]

h = [Halos(path1[i], min_size=FLAGS.sim_min_particle_number) for i in range(len(st))]
N = [h[i].get_number_halos() for i in range(len(st))]

prof = []

bins1 = binning_using_binwidth(-1.25, 0, 0.078)
bins2 = binning_using_binwidth(-1.25, 0.2, 0.078)
halo_idx = 0
with centering_com(h[0].get_halo(halo_idx)):
    prof0 = h[0].get_profile(halo_idx, component='dm', bins=bins1,
                                bin_type='custom', normalize_x=True)
with centering_com(h[1].get_halo(halo_idx)):
    prof1 = h[1].get_profile(halo_idx, component='dm', bins=bins2,
                                bin_type='custom', normalize_x=True)

#prof0 will have index=0, prof1 will have index=1 and so on
p = plot.Profile([prof0, prof1], name='figs/DensityProfile.png')
p.set_all_properties(model='density_profile')

#current options are: radius, mass, enclosed mass, density and enclosed_density
p.plot_all(x_var='radius', y_var='density')

#fit all the profiles (NFW is currently the only option but the code can be easily expanded)
#p.fit_and_plot_all(function='nfw')