Ejemplo n.º 1
0
    def get_poles(self, scaled=True):
        """
        Return a dictionary holding the configuration space galaxy spectrum
        multipoles in redshift space, as measured by nbodykit
        """
        tag = '_scaled' if scaled else '_unscaled'
        name = '_poles' + tag
        try:
            return getattr(self, name)
        except AttributeError:

            basename = 'poles_challenge_box{box}%s.dat' %tag
            d = os.path.join(self.root, 'corr_poles')
                        
            loader = io.load_correlation
            kwargs = {'sum_only':['RR', 'N'], 'force_index_match':True}
            poles = SpectraSet.from_files(loader, d, basename, [self.boxes], ['box'], args=('1d',), kwargs=kwargs)
            
            # reindex and add the errors
            poles = self.reindex(poles, 'r_cen', self.dr, weights='N')

            # now convert
            ells = [('corr_0',0), ('corr_2', 2), ('corr_4', 4)]
            poles = tools.unstack_multipoles(poles, ells, 'corr')
            setattr(self, name, poles)
            return poles
Ejemplo n.º 2
0
    def get_shifted_poles(self, name, tag="", average=None, subtract_shot_noise=True):
        """
        Return the N-series multipoles in redshift space, which haven been shifted in
        space (and computed with Bianchi algorithm)
        """
        if name not in ["boss_like", "plane_parallel"]:
            raise ValueError("please choose a name from 'boss_like' or 'plane_parallel'")

        tag_ = "_" + tag if tag else ""
        if tag:
            name += tag_

        if average is not None:
            if isinstance(average, str):
                average = [average]
        else:
            average = []

        name_ = name
        if len(average):
            name_ += "_" + "_".join(average)

        try:
            return getattr(self, "shifted_poles_%s" % name_)
        except AttributeError:

            # load the data from file
            basename = "poles_challenge_boxN{box}_shifted_unscaled_shift{shift}_%s.dat" % name
            coords = [self.boxes, [0, 1, 2]]
            d = os.path.join(self.root, "poles")

            loader = io.load_power
            mapcols = {"power_0.real": "mono", "power_2.real": "quad", "power_4.real": "hexadec"}
            usecols = ["k", "mono", "quad", "hexadec", "modes"]
            kwargs = {"usecols": usecols, "mapcols": mapcols}
            poles = SpectraSet.from_files(loader, d, basename, coords, ["box", "shift"], args=("1d",), kwargs=kwargs)

            # reindex and add the errors
            poles = self.reindex(poles, "k_cen", self.dk, weights="modes")

            # now convert
            ells = [("mono", 0), ("quad", 2), ("hexadec", 4)]
            poles = tools.unstack_multipoles(poles, ells, "power")

            if subtract_shot_noise:
                for key in poles.ndindex():
                    if key["ell"] == 0:
                        p = poles.loc[key].get()
                        p["power"] = p["power"] - p.attrs["shot_noise"]

            # average?
            if len(average):
                poles = poles.average(axis=average, weights="modes")

            setattr(self, name, poles)
            return poles
Ejemplo n.º 3
0
 def get_poles(self, average=None):
     """
     Return the cutsky galaxy multipoles in redshift space
     """
     if average is not None:
         if isinstance(average, str):
             average = [average]
     else:
         average = []
     
     name = '_poles'
     if len(average):
         name += '_' + '_'.join(average)
         
     try:
         return getattr(self, name)
     except AttributeError:
     
         # form the filename and load the data
         basename = 'bianchips_qpmdr12_TSC_{box:04d}.dat'
         
         # read in the data
         loader = io.read_cutsky_power_poles
         kwargs = {'skiprows' : 31, 'sum_only':['modes'], 'force_index_match':True}
         poles = SpectraSet.from_files(loader, self.root, basename, [self.boxes], ['box'], kwargs=kwargs)
     
         # reindex
         poles = self.reindex(poles, 'k_cen', self.dk, weights='modes')
                     
         # unstack the poles
         ells = [('mono',0), ('quad', 2), ('hexadec', 4)]
         poles = tools.unstack_multipoles(poles, ells, 'power')
     
         if len(average):
             poles = poles.average(axis=average, weights='modes')
     
         setattr(self, name, poles)
         return poles
Ejemplo n.º 4
0
    def get_florian_poles(self, scaled=True, average=False):
        """
        Return the cutsky galaxy multipoles in redshift space, as
        measured by Florian's code
        """
        scaled_tag = 'scaled' if scaled else 'unscaled'
        name = '_poles_florian_' + scaled_tag
        if average: name += '_mean'
        
        try:
            return getattr(self, name)         
        except AttributeError:
        
            # form the filename and load the data
            d = os.path.join(self.root, 'data', scaled_tag)
            if scaled:
                basename = 'bianchips_cutsky_TSC_0.7_{box:d}.dat'
            else:
                basename = 'bianchips_Ncutsky_{box:02d}.dat'

            # read in the data
            loader = io.read_cutsky_power_poles
            kwargs = {'skiprows' : 31, 'sum_only':['modes'], 'force_index_match':True}
            poles = SpectraSet.from_files(loader, d, basename, [self.boxes], ['box'], kwargs=kwargs)
        
            # reindex
            poles = self.reindex(poles, 'k_cen', self.dk, weights='modes')
            
            # unstack the poles
            ells = [('mono',0), ('quad', 2), ('hexadec', 4)]
            poles = tools.unstack_multipoles(poles, ells, 'power')
            
            if average:
                poles = poles.average(axis='box', weights='modes')
        
            setattr(self, name, poles)
            return poles
Ejemplo n.º 5
0
    def get_poles(self, spacing="dk005", scaled=False, Nmu=100):
        """
        Return the total galaxy spectrum multipoles in redshift space
        """
        _spacing = spacing
        tag = "unscaled" if not scaled else "scaled"
        if spacing:
            spacing = "_" + spacing
        name = "_poles%s_%s" % (spacing, tag)
        try:
            return getattr(self, name)
        except AttributeError:

            # load the data from file
            basename = "poles_challenge_box{box}_%s%s_Nmu%d.dat" % (tag, spacing, Nmu)
            coords = [self.boxes]
            d = os.path.join(self.root, "poles")

            loader = io.load_power
            columns = ["k", "mono", "quad", "hexadec", "modes"]
            kwargs = {"sum_only": ["modes"], "force_index_match": True, "columns": columns}
            poles = SpectraSet.from_files(loader, d, basename, coords, ["box"], args=("1d",), kwargs=kwargs)

            # reindex and add the errors
            poles = self.reindex(poles, "k_cen", self.dk, weights="modes")

            # now convert
            ells = [("mono", 0), ("quad", 2), ("hexadec", 4)]
            toret = tools.unstack_multipoles(poles, ells, "power")

            # add the errors
            pkmu = self.get_Pgal(scaled=scaled, spacing=_spacing, Nmu=Nmu)
            toret.add_power_pole_errors(pkmu)

            setattr(self, name, toret)
            return toret
Ejemplo n.º 6
0
    def get_my_poles(self, space='redshift', scaled=False, average=False, tag="", 
                        subtract_shot_noise=True):
        """
        Return the cutsky galaxy multipoles in redshift space, measured
        for my 84 box realizations
        """ 
        if space not in ['real', 'redshift']:
            raise ValueError("`space` should be 'real' or 'redshift'")
        
        scaled_tag = 'scaled' if scaled else 'unscaled'
        name = '_my_poles_%s_%s' %(space, scaled_tag)
        if average: name += '_mean'
    
        if tag: 
            tag = '_'+tag
            name += tag
        
        try:
            return getattr(self, name)         
        except AttributeError:
        
            # form the filename and load the data
            d = os.path.join(self.root, 'nbodykit/poles')
            if space == 'redshift':
                basename = 'poles_my_cutskyN{box:d}_%s_no_fkp_dk005%s.dat' %(scaled_tag, tag)
            else:
                basename = 'poles_my_cutskyN{box:d}_real_%s_no_fkp_dk005%s.dat' %(scaled_tag, tag)

            # read in the data
            loader = io.load_power
            mapcols = {'power_0.real':'mono', 'power_2.real':'quad', 'power_4.real':'hexadec'}
            usecols = ['k', 'mono', 'quad', 'hexadec', 'modes']
            kwargs = {'usecols':usecols, 'mapcols':mapcols}
            poles = SpectraSet.from_files(loader, d, basename, [self.boxes], ['box'], args=('1d',), kwargs=kwargs, ignore_missing=True)

            # remove null
            valid_boxes = []
            for key, p in poles.nditer():
                if not p.isnull():
                    valid_boxes.append(key['box'])
            poles = poles.sel(box=valid_boxes)
        
            # reindex
            poles = self.reindex(poles, 'k_cen', self.dk, weights='modes')
            
            # unstack the poles
            ells = [('mono',0), ('quad', 2), ('hexadec', 4)]
            poles = tools.unstack_multipoles(poles, ells, 'power')
            
            # compute errors
            errs = {}
            for ell in poles['ell'].values:
                data = []
                for box in poles['box'].values:
                    p = poles.sel(box=box, ell=ell).get()
                    data.append(p['power'])

                errs[ell] = np.diag(np.cov(np.asarray(data).T))**0.5
                if average:
                    errs[ell] /= (len(self.boxes))**0.5
            
            if subtract_shot_noise:
                for key in poles.ndindex():
                    if key['ell'] == 0:
                        p = poles.loc[key].get()
                        p['power'] = p['power'] - p.attrs['shot_noise']
            
            # average?
            if average:
                poles = poles.average(axis='box')
                
            # add the errors
            for key in poles.ndindex():
                p = poles.loc[key].get()
                p['error'] = errs[key['ell']]
        
            setattr(self, name, poles)
            return poles
Ejemplo n.º 7
0
    def get_subbox_poles(self, which, average=False, subtract_shot_noise=True):
        """
        Return the cutsky galaxy multipoles in redshift space, measured
        for the subboxes
        """ 
        name = '_my_poles_subboxes_%s_Mpch' %(which)
        if average: name += '_mean'
        
        try:
            return getattr(self, name)         
        except AttributeError:
        
            # form the filename and load the data
            d = self.root
            basename = 'poles_my_cutskyN1_subbox{box:d}_%s_Mpch_unscaled_no_fkp_dk005.dat' %which

            # read in the data
            loader = io.load_power
            mapcols = {'power_0.real':'mono', 'power_2.real':'quad', 'power_4.real':'hexadec'}
            usecols = ['k', 'mono', 'quad', 'hexadec', 'modes']
            kwargs = {'usecols':usecols, 'mapcols':mapcols}
            
            if which == '300':
                boxes = list(range(94))
            else:
                boxes = list(range(24))
            poles = SpectraSet.from_files(loader, d, basename, [boxes], ['box'], args=('1d',), kwargs=kwargs, ignore_missing=True)

            # remove null
            valid_boxes = []
            for key, p in poles.nditer():
                if not p.isnull():
                    valid_boxes.append(key['box'])
            poles = poles.sel(box=valid_boxes)
        
            # reindex
            poles = self.reindex(poles, 'k_cen', self.dk, weights='modes')
            
            # unstack the poles
            ells = [('mono',0), ('quad', 2), ('hexadec', 4)]
            poles = tools.unstack_multipoles(poles, ells, 'power')
            
            # compute errors
            errs = {}
            for ell in poles['ell'].values:
                data = []
                for box in poles['box'].values:
                    p = poles.sel(box=box, ell=ell).get()
                    data.append(p['power'])

                errs[ell] = np.diag(np.cov(np.asarray(data).T))**0.5
                if average:
                    errs[ell] /= (len(boxes))**0.5
            
            if subtract_shot_noise:
                for key in poles.ndindex():
                    if key['ell'] == 0:
                        p = poles.loc[key].get()
                        p['power'] = p['power'] - p.attrs['shot_noise']
            
            # average?
            if average:
                poles = poles.average(axis='box')
                
            # add the errors
            for key in poles.ndindex():
                p = poles.loc[key].get()
                p['error'] = errs[key['ell']]
        
            setattr(self, name, poles)
            return poles
Ejemplo n.º 8
0
    def get_poles(
        self,
        space="redshift",
        subtract_shot_noise=True,
        spacing="dk005",
        Nmu=100,
        scaled=False,
        average=None,
        tag="",
        include_tetrahex=False,
    ):
        """
        Return the N-series multipoles in redshift space
        """
        if space not in ["redshift", "real"]:
            raise ValueError("`space` must be real' or 'redshift'")

        if average is not None:
            if isinstance(average, str):
                average = [average]
        else:
            average = []

        # determine the tag
        scaled_tag = "scaled" if scaled else "unscaled"
        _spacing = spacing
        if spacing:
            spacing = "_" + spacing
        name = "_nseries_poles_%s_%s%s" % (space, scaled_tag, spacing)
        if len(average):
            name += "_" + "_".join(average)

        tag_ = "_" + tag if tag else ""
        if tag:
            name += tag_

        try:
            return getattr(self, name)
        except AttributeError:

            # load the data from file
            if space == "redshift":
                basename = "poles_challenge_boxN{box}_%s%s_Nmu%d_{los}los%s.dat" % (scaled_tag, spacing, Nmu, tag_)
                coords = [self.los, self.boxes]
                dims = ["los", "box"]
            else:
                basename = "poles_challenge_boxN{box}_real_%s%s_Nmu100%s.dat" % (scaled_tag, spacing, tag_)
                coords = [self.boxes]
                dims = ["box"]
            d = os.path.join(self.root, "poles")

            loader = io.load_power
            mapcols = {"power_0.real": "mono", "power_2.real": "quad", "power_4.real": "hexadec"}
            usecols = ["k", "mono", "quad", "hexadec", "modes"]
            if include_tetrahex:
                mapcols["power_6.real"] = "tetrahex"
                usecols.append("tetrahex")
            kwargs = {"usecols": usecols, "mapcols": mapcols}
            poles = SpectraSet.from_files(loader, d, basename, coords, dims, args=("1d",), kwargs=kwargs)

            # reindex and add the errors
            poles = self.reindex(poles, "k_cen", self.dk, weights="modes")

            # now convert
            ells = [("mono", 0), ("quad", 2), ("hexadec", 4)]
            if include_tetrahex:
                ells.append(("tetrahex", 6))
            poles = tools.unstack_multipoles(poles, ells, "power")

            if subtract_shot_noise:
                for key in poles.ndindex():
                    if key["ell"] == 0:
                        p = poles.loc[key].get()
                        p["power"] = p["power"] - p.attrs["volume"] / p.attrs["N1"]

            # average?
            if len(average):
                poles = poles.average(axis=average, weights="modes")

            # add the errors
            pkmu = self.get_Pgal(space=space, spacing=_spacing, Nmu=Nmu, average=average, scaled=scaled, tag=tag)
            poles.add_power_pole_errors(pkmu)

            setattr(self, name, poles)
            return poles