예제 #1
0
def read_range(cat, amin, amax):
    """ Read a portion of the lightcone between two red shift ranges

        The lightcone from FastPM is sorted in Aemit and an index is built.
        So we make use of that.

        CrowCanyon is z > 0; We paste the mirror image to form a full sky.
    """
    edges = cat.attrs['aemitIndex.edges']
    offsets = cat.attrs['aemitIndex.offset']
    start, end = edges.searchsorted([amin, amax])
    if cat.comm.rank == 0:
        cat.logger.info("Range of index is %d to %d" % ((start + 1, end + 1)))
    start = offsets[start + 1]
    end = offsets[end + 1]
    cat = cat.query_range(start, end)
    cat1 = cat.copy()
    cat1['Position'] = cat1['Position'] * [1, 1, -1.]
    cat3 = ConcatenateSources(cat, cat1)
    if cat1.csize > 0:
        cat3['RA'], cat3['DEC'] = CartesianToEquatorial(cat3['Position'],
                                                        frame='galactic')
    else:
        cat3['RA'] = 0
        cat3['DEC'] = 0
    return cat3
예제 #2
0
def read_range(cat, amin, amax):
    """ Read a portion of the lightcone between two red shift ranges
        The lightcone from FastPM is sorted in Aemit and an index is built.
        So we make use of that.
        CrowCanyon new runs are full sky
    """
    edges = cat.attrs['aemitIndex.edges']
    offsets = cat.attrs['aemitIndex.offset']
    start, end = edges.searchsorted([amin, amax])
    if cat.comm.rank == 0:
        cat.logger.info("Range of index is %d to %d" %(( start + 1, end + 1)))
    start = offsets[start + 1]
    end = offsets[end + 1]

    cat =  cat.query_range(start, end)
    if cat.csize > 0:
        cat['RA'], cat['DEC'] = CartesianToEquatorial(cat['Position'], frame='galactic')
    else:
        cat['RA'] = 0
        cat['DEC'] = 0
    return cat
예제 #3
0
    def run(self):
        """
        Calculate the pair counts in a simulation box.
        This adds the following attributes to the class:

        - :attr:`SimulationBoxPairCount.pairs`

        Attributes
        ----------
        pairs : :class:`~nbodykit.binned_statistic.BinnedStatistic`
            a BinnedStatistic object holding the pair count results.
            The coordinate grid will be ``(r,)``, ``(r,mu)``, ``(rp, pi)``,
            or ``(theta,)`` when ``mode`` is '1d', '2d', 'projected', 'angular',
            respectively.

            The BinnedStatistic stores the following variables:

            - ``r``, ``rp``, or ``theta`` : the mean separation value in the bin
            - ``npairs``: the number of pairs in the bin
            - ``weightavg``: the average weight value in the bin; each pair
              contributes the product of the individual weight values
        """
        # setup
        mode = self.attrs['mode']
        BoxSize = self.attrs['BoxSize']
        first, second = self.first, self.second
        attrs = self.attrs.copy()

        # determine the axes order
        # NOTE: LOS axis should be final column
        los = attrs['los']
        axes_order = [i for i in [0, 1, 2] if i != los] + [los]

        # compute the max cartesian distance for smoothing
        smoothing = numpy.max(attrs['edges'])
        if mode == 'projected':
            smoothing = numpy.sqrt(smoothing**2 + attrs['pimax']**2)
        elif mode == 'angular':
            smoothing = 2 * numpy.sin(0.5 * numpy.deg2rad(smoothing))

        # if not angular, decompose sim box data (x,y,z)
        if mode != 'angular':
            from .domain import decompose_box_data

            # domain decompose the data
            (pos1, w1), (pos2,
                         w2) = decompose_box_data(first, second, attrs,
                                                  self.logger, smoothing)

            # reorder to make LOS last column
            pos1 = pos1[:, axes_order]
            pos2 = pos2[:, axes_order]

        # NOTE: if doing angular, shift observer to box center and use RA, DEC
        # go from (x,y,z) to (ra,dec), using observer in the middle of the box
        else:
            from nbodykit.transform import CartesianToEquatorial
            from nbodykit.utils import get_data_bounds
            from .domain import decompose_survey_data

            # make sure Position is shifted to an observer at box center
            # and then convert to RA,DEC
            pos1 = shift_to_box_center(first['Position'], BoxSize, self.comm)
            first['ra'], first['dec'] = CartesianToEquatorial(pos1)

            # do the same thing for second source
            if second is not None and second is not first:
                pos2 = shift_to_box_center(second['Position'], BoxSize,
                                           self.comm)
                second['ra'], second['dec'] = CartesianToEquatorial(pos2)

            # domain decompose the data
            attrs['ra'], attrs['dec'] = 'ra', 'dec'
            (pos1, w1), (pos2, w2) = decompose_survey_data(first,
                                                           second,
                                                           attrs,
                                                           self.logger,
                                                           smoothing,
                                                           angular=True)

        # get the Corrfunc callable based on mode
        kws = {k: attrs[k] for k in ['periodic', 'BoxSize', 'show_progress']}
        if attrs['mode'] == '1d':
            from .corrfunc.theory import DD
            func = DD(attrs['edges'], **kws)

        elif attrs['mode'] == '2d':
            from .corrfunc.theory import DDsmu
            func = DDsmu(attrs['edges'], attrs['Nmu'], **kws)

        elif attrs['mode'] == 'projected':
            from .corrfunc.theory import DDrppi
            func = DDrppi(attrs['edges'], attrs['pimax'], **kws)

        elif attrs['mode'] == 'angular':
            from .corrfunc.mocks import DDtheta_mocks
            func = DDtheta_mocks(attrs['edges'],
                                 show_progress=attrs['show_progress'])

        # do the calculation
        self.pairs = func(pos1, w1, pos2, w2, **attrs['config'])