def prepare_catalogues(self,
                        path_input,
                        path_randoms,
                        ic=None,
                        rwidth=2.,
                        redges=None,
                        nside=32,
                        seed=42,
                        ncuts=20,
                        share='counts',
                        downsample=2.,
                        additional_bins=[]):
     catalogue = Catalogue.load(path_input)
     modes = path_randoms.keys()
     self.params['ic'] = self.ic
     catalogues = self.normalize_catalogue(
         {mode: catalogue.deepcopy()
          for mode in modes},
         ic=self.ic,
         rwidth=rwidth,
         redges=redges,
         nside=nside,
         seed=seed,
         additional_bins=additional_bins)
     if isinstance(downsample, float):
         downsample = {mode: downsample for mode in modes}
     for mode in modes:
         catalogues[mode] = catalogues[mode].downsample(downsample[mode])
     if self.ic in ['angular', 'radial']:
         catalogues = self.slice_catalogues(catalogues,
                                            ncuts=ncuts,
                                            share=share)
     for mode, catalogue in catalogues.items():
         catalogue.save(path_randoms[mode])
    def set_multipoles(self, icut=0, icut1=0, ncuts=1, losn=0, modes=None):

        catalogues = [
            Catalogue.load(self.params['path_randoms'][mode])
            for mode in self.modes
        ]

        icutibins = catalogues[1].attrs['icutibins'][icut]
        assert (icutibins == catalogues[2].attrs['icutibins'][icut]).all()
        icutnbins = len(icutibins)
        naddbins = catalogues[0].attrs['naddbins']
        assert (naddbins == catalogues[1].attrs['naddbins']) and (
            naddbins == catalogues[2].attrs['naddbins'])

        catalogue1 = catalogues[0].slice(icut1, ncuts)

        pyreal3pcf = PyReal3PCF(**self.params)
        pyreal3pcf.set_grid()

        self.result = 0
        for iaddbin in range(naddbins):
            mask2 = catalogues[1]['iaddbin'] == iaddbin
            mask3 = catalogues[2]['iaddbin'] == iaddbin
            for ibin, bin in enumerate(icutibins):
                self.logger.info(
                    'Correlating slice {:d} ({:d}/{:d}) of cut {:d}/{:d}.'.
                    format(bin, ibin + 1, icutnbins, iaddbin + 1, naddbins))
                catalogue2 = catalogues[1][mask2
                                           & (catalogues[1]['ibin'] == bin)]
                catalogue3 = catalogues[2][mask3
                                           & (catalogues[2]['ibin'] == bin)]
                if not catalogue2 or not catalogue3: continue
                self.result += pyreal3pcf.copy().run(catalogue1, catalogue2,
                                                     catalogue3)
示例#3
0
    def set_multipoles(self, s, ic=['global', 'global'], iaddbins=None):

        catalogue = Catalogue.load(self.params['path_randoms'])
        radials, densities, weights = self.get_radial_density(
            catalogue,
            iaddbins=[iaddbins] * 2,
            density=[False, True],
            power_weight=[2 if 'radial' in ic else 1, 1])

        pyanalytic2pcf = PyAnalytic2PCF(**self.params)
        if ('global' in ic) or (('radial' in ic) and ('angular' in ic)):
            typewin = 'global'
        else:
            typewin = ic[0]
        if typewin == 'angular':
            angular_s = None
            angular_window = None
        else:
            angular_s = self.angular.s
            angular_window = self.angular.window[0]
        self.result = pyanalytic2pcf.run(s,
                                         angular_s,
                                         angular_window,
                                         radials,
                                         densities,
                                         typewin=typewin)
        self.result.weight_tot = scipy.sum(weights[-1]**2)
        self.result.rescale()
    def set_multipoles(self, icut=0, losn=0, modes=None):

        catalogues = [
            Catalogue.load(self.params['path_randoms'][mode])
            for mode in self.modes
        ]

        icutibins = catalogues[0].attrs['icutibins'][icut]
        assert (icutibins == catalogues[2].attrs['icutibins'][icut]).all()
        icutnbins = len(icutibins)
        naddbins = catalogues[0].attrs['naddbins']
        assert (naddbins == catalogues[1].attrs['naddbins']) and (
            naddbins == catalogues[2].attrs['naddbins']) and (
                naddbins == catalogues[3].attrs['naddbins'])

        pyreal4pcf = PyReal4PCFBinned(**self.params)
        pyreal4pcf.set_grid(binsize=catalogues[-1].attrs['nbins'])

        self.result = 0
        for iaddbin1 in range(naddbins):
            catalogue2 = catalogues[1][catalogues[1]['iaddbin'] == iaddbin1]
            catalogue4 = catalogues[3][catalogues[3]['iaddbin'] == iaddbin1]
            for iaddbin2 in range(naddbins):
                mask1 = catalogues[0]['iaddbin'] == iaddbin2
                mask3 = catalogues[2]['iaddbin'] == iaddbin2
                for ibin, bin in enumerate(icutibins):
                    self.logger.info(
                        'Correlating {}x{} slice {:d} ({:d}/{:d}) of cut {:d}/{:d} and {:d}/{:d}.'
                        .format(self.modes[2], self.modes[3], bin, ibin + 1,
                                icutnbins, iaddbin1 + 1, naddbins,
                                iaddbin2 + 1, naddbins))
                    catalogue1 = catalogues[0][mask1 &
                                               (catalogues[0]['ibin'] == bin)]
                    catalogue3 = catalogues[2][mask3 &
                                               (catalogues[2]['ibin'] == bin)]
                    if not catalogue1 or not catalogue3: continue
                    self.result += pyreal4pcf.copy().run(catalogue1,
                                                         catalogue2,
                                                         catalogue3,
                                                         catalogue4,
                                                         tobin=[2, 4])
                    if self.modes[2] != self.modes[3]:
                        #if True:
                        self.logger.info(
                            'Correlating {}x{} slice {:d} ({:d}/{:d}) of cut {:d}/{:d} and {:d}/{:d}.'
                            .format(self.modes[3], self.modes[2], bin,
                                    ibin + 1, icutnbins, iaddbin1 + 1,
                                    naddbins, iaddbin2 + 1, naddbins))
                        self.result += pyreal4pcf.copy().run(
                            catalogue2,
                            catalogue1,
                            catalogue4,
                            catalogue3,
                            tobin=[1, 3])  # beware: twice the normalisation
        if self.result and self.modes[2] != self.modes[3]:
            self.result.weight_tot /= 2.
    def to_4pcfsn(self, iaddbins=None, path_ref=None):

        new = Real4PCFBinnedShotNoise(**self.params)

        if path_ref is None: path_ref = self.params['path_randoms'].values()[0]
        randoms = Catalogue.load(path_ref)
        if iaddbins is not None:
            weights = randoms['Weight'][randoms['iaddbin'] == iaddbins[0]]
        else:
            weights = randoms['Weight']
        weight = (weights**2).sum() / weights.sum()**2

        new.result = self.result * weight

        return new
示例#6
0
    def set_multipoles(self, s, ic='global', iaddbins=None):

        catalogue = Catalogue.load(self.params['path_randoms'])
        radials, densities, weights = self.get_radial_density(
            catalogue, iaddbins=iaddbins, density=[False, True, True])

        pyanalytic3pcf = PyAnalytic3PCF(**self.params)
        self.result = pyanalytic3pcf.run(s,
                                         self.angular.s,
                                         self.angular.window[0],
                                         radials,
                                         densities,
                                         typewin='{}-dlos'.format(ic))
        self.result.weight_tot = scipy.prod(map(scipy.sum, weights[:2]))
        self.result.rescale()
    def set_multipoles(self, losn=0, modes=None, iaddbins=[None, None]):

        meshs = []
        for imode, mode in enumerate(self.modes):
            path = self.params['path_randoms'][mode]
            catalogue = Catalogue.load(path)
            if iaddbins[imode] is not None:
                catalogue = catalogue[catalogue['iaddbin'] == iaddbins[imode]]
            if imode == 0:
                catalogue = catalogue['Weight'] / catalogue.distance()**losn
            meshs.append(
                get_mesh(catalogue.to_nbodykit(),
                         position='Position',
                         weight='Weight',
                         mesh=self.params['mesh']))

        self.result = PyFFT2PCF(meshs[0], poles=self.params['ells'], kmin=0.)
示例#8
0
    def set_multipoles(self, s, ic='global', iaddbins=None):

        catalogue = Catalogue.load(self.params['path_randoms'])
        radials, densities, weights = self.get_radial_density(
            catalogue,
            iaddbins=[iaddbins] * 2,
            density=[False, True],
            power_weight=[2, 1])

        pyanalytic2pcf = PyAnalytic2PCF(**self.params)
        self.result = pyanalytic2pcf.run(s,
                                         self.angular.s,
                                         self.angular.window[0],
                                         radials,
                                         densities,
                                         typewin=ic)
        self.result.weight_tot = scipy.sum(weights[-1]**2)
        self.result.rescale()
示例#9
0
    def set_multipoles(self, s, ic=['global,global'], iaddbins=None):

        catalogue = Catalogue.load(self.params['path_randoms'])
        radials, densities, weights = self.get_radial_density(
            catalogue, iaddbins=iaddbins, density=[False, True, False, True])

        pyanalytic4pcf = PyAnalytic4PCF(**self.params)
        pyanalytic4pcf.set_precision(calculation='costheta',
                                     n=10000,
                                     min=1.,
                                     max=-1.,
                                     integration='test')
        self.result = pyanalytic4pcf.run(s,
                                         self.angular.s,
                                         self.angular.window[0],
                                         radials,
                                         densities,
                                         typewin='-'.join(ic))
        self.result.weight_tot = scipy.prod(map(scipy.sum, weights[:2]))
        self.result.rescale()
示例#10
0
    def set_multipoles(self,
                       icut=0,
                       ncuts=1,
                       losn=0,
                       iaddbins=[None, None],
                       modes=None):

        catalogues = []
        for imode, mode in enumerate(self.modes):
            path = self.params['path_randoms'][mode]
            catalogue = Catalogue.load(path)
            if iaddbins[imode] is not None:
                catalogue = catalogue[catalogue['iaddbin'] == iaddbins[imode]]
                self.logger.info(
                    'Additional cut {:d} for {} randoms ({:d} objects).'.
                    format(iaddbins[imode], mode, catalogue.size))
            catalogues.append(catalogue)

        catalogues[0] = catalogues[0].slice(icut, ncuts)

        pyreal2pcf = PyReal2PCF(**self.params)
        pyreal2pcf.set_grid()
        self.result = pyreal2pcf.run(catalogues[0], catalogues[1])
示例#11
0
    def set_angular(self, icut=0, icut1=0, ncuts=1, iaddbins=None, modes=None):

        iaddbins = utils.tolist(iaddbins, n=3, value=None)

        catalogues = []
        for imode, mode in enumerate(self.modes):
            path = self.params['path_randoms'][mode]
            catalogue = Catalogue.load(path)
            if iaddbins[imode] is not None:
                catalogue = catalogue[catalogue['iaddbin'] == iaddbins[imode]]
                self.logger.info(
                    'Additional cut {:d} for {} randoms ({:d} objects).'.
                    format(iaddbins[imode], mode, catalogue.size))
            catalogue['Position'] /= catalogue.distance()[:, None]
            catalogues.append(catalogue)

        icutibins = catalogues[1].attrs['icutibins'][icut]
        assert (icutibins == catalogues[2].attrs['icutibins'][icut]).all()
        icutnbins = len(icutibins)

        catalogue1 = catalogues[0].slice(icut1, ncuts)

        pyreal3pcf = PyReal3PCF(ells=[0],
                                los='endpoint',
                                losn=0,
                                **self.params)
        pyreal3pcf.set_grid()

        self.result = 0
        for ibin, bin in enumerate(icutibins):
            self.logger.info('Correlating slice {:d} ({:d}/{:d}).'.format(
                bin, ibin + 1, icutnbins))
            catalogue2 = catalogues[1][catalogues[1]['ibin'] == bin]
            catalogue3 = catalogues[2][catalogues[2]['ibin'] == bin]
            if not catalogue2 or not catalogue3: continue
            self.result += pyreal3pcf.copy().run(catalogue1, catalogue2,
                                                 catalogue3)
示例#12
0
    def set_angular(self,
                    icut=0,
                    ncuts=1,
                    iaddbins=None,
                    power_weight=1,
                    modes=None):

        iaddbins = utils.tolist(iaddbins, n=2, value=None)
        power_weight = utils.tolist(power_weight, n=2, value=1)

        catalogues = []
        for imode, mode in enumerate(self.modes):
            path = self.params['path_randoms'][mode]
            catalogue = Catalogue.load(path)
            if iaddbins[imode] is not None:
                catalogue = catalogue[catalogue['iaddbin'] == iaddbins[imode]]
                self.logger.info(
                    'Additional cut {:d} for {} randoms ({:d} objects).'.
                    format(iaddbins[imode], mode, catalogue.size))
            catalogue['Position'] /= catalogue.distance()[:, None]
            power = power_weight[imode]
            if power != 1:
                self.logger.info('Raising weights {} to power {:.4f}.'.format(
                    mode, power))
                catalogue['Weight'] **= power
            catalogues.append(catalogue)

        catalogue1 = catalogues[0].slice(icut, ncuts)
        catalogue2 = catalogues[1]

        pyreal2pcf = PyReal2PCF(ells=[0],
                                los='endpoint',
                                losn=0,
                                **self.params)
        pyreal2pcf.set_grid()
        self.result = pyreal2pcf.run(catalogue1, catalogue2)
示例#13
0
    def set_multipoles(self, icut=0, modes=None):

        catalogues = [
            Catalogue.load(self.params['path_randoms'][mode])
            for mode in self.modes
        ]

        icutibins = catalogues[0].attrs['icutibins'][icut]
        assert (icutibins == catalogues[2].attrs['icutibins'][icut]).all()
        icutnbins = len(icutibins)
        naddbins = catalogues[0].attrs['naddbins']
        assert (naddbins == catalogues[1].attrs['naddbins']) and (
            naddbins == catalogues[2].attrs['naddbins']) and (
                naddbins == catalogues[3].attrs['naddbins'])
        assert scipy.allclose(catalogues[2]['Position'],
                              catalogues[3]['Position'],
                              rtol=1e-05,
                              atol=1e-05)
        catalogues[2]['Weight'] *= catalogues[3]['Weight']

        self.result = 0

        if self.modes[2] == self.modes[3]:
            pyreal2pcf = PyReal2PCF(**self.params)
            pyreal2pcf.set_grid()
            for iaddbin in range(naddbins):
                mask1 = catalogues[0]['iaddbin'] == iaddbin
                mask2 = catalogues[1]['iaddbin'] == iaddbin
                mask3 = catalogues[2]['iaddbin'] == iaddbin
                for ibin, bin in enumerate(icutibins):
                    self.logger.info(
                        'Correlating {}x{} slice {:d} ({:d}/{:d}) of cut {:d}/{:d}.'
                        .format(self.modes[2], self.modes[3], bin, ibin + 1,
                                icutnbins, iaddbin + 1, naddbins))
                    catalogue1 = catalogues[0][mask1 &
                                               (catalogues[0]['ibin'] == bin)]
                    catalogue2 = catalogues[1][mask2 &
                                               (catalogues[1]['ibin'] == bin)]
                    if not catalogue1 or not catalogue2: continue
                    weight = catalogues[2]['Weight'][
                        mask3 & (catalogues[2]['ibin'] == bin)].sum()
                    self.result += pyreal2pcf.copy().run(
                        catalogue1, catalogue2) * weight
        else:
            pyreal2pcf = PyReal2PCFBinned(**self.params)
            pyreal2pcf.set_grid(binsize=catalogues[-1].attrs['nbins'])
            for iaddbin in range(naddbins):
                mask1 = catalogues[0]['iaddbin'] == iaddbin
                mask2 = catalogues[1]['iaddbin'] == iaddbin
                mask3 = catalogues[2]['iaddbin'] == iaddbin
                catalogue2 = catalogues[1][mask2]
                for ibin, bin in enumerate(icutibins):
                    self.logger.info(
                        'Correlating {}x{} slice {:d} ({:d}/{:d}) of cut {:d}/{:d}.'
                        .format(self.modes[2], self.modes[3], bin, ibin + 1,
                                icutnbins, iaddbin + 1, naddbins, naddbins))
                    catalogue1 = catalogues[0][mask1 &
                                               (catalogues[0]['ibin'] == bin)]
                    if not catalogue1 or not catalogue2: continue
                    mask = mask3 & (catalogues[2]['ibin'] == bin)
                    weight = scipy.bincount(
                        catalogues[3]['ibin'][mask],
                        weights=catalogues[2]['Weight'][mask],
                        minlength=catalogues[3].attrs['nbins'])
                    self.result += pyreal2pcf.copy().run(
                        catalogue1, catalogue2, tobin=2) * weight
                    self.logger.info(
                        'Correlating {}x{} slice {:d} ({:d}/{:d}) of cut {:d}/{:d}.'
                        .format(self.modes[3], self.modes[2], bin, ibin + 1,
                                icutnbins, iaddbin + 1, naddbins))
                    self.result += pyreal2pcf.copy().run(
                        catalogue2, catalogue1, tobin=1) * weight
            if self.result: self.result.weight_tot /= 2.
示例#14
0
 def set_normalization(self, path_ref=None):
     if path_ref is None: path_ref = self.params['path_randoms'].values()[0]
     randoms = Catalogue.load(path_ref)
     self.normref = randoms.attrs['norm']
     self.norm = self.normref * self.weight_tot
     self.shotnoise = (randoms['Weight']**2).sum() / self.norm
示例#15
0
 def set_normalization(self, path_ref=None):
     if path_ref is None: path_ref = self.params['path_randoms']
     randoms = Catalogue.load(path_ref)
     self.normref = randoms.attrs['norm']
     self.weight_tot = self.result.integral()
     self.norm = self.normref * self.weight_tot