How to use the treecorr.util.gen_write function in TreeCorr

To help you get started, we’ve selected a few TreeCorr examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rmjarvis / TreeCorr / tests / test_config.py View on Github external
# First some I/O sanity checks
    a = np.array([1,2,3])
    b = np.array([4,5,6])
    file_name = 'junk.out'
    with assert_raises(ValueError):
        treecorr.util.gen_write(file_name, ['a', 'b'], [a])
    with assert_raises(ValueError):
        treecorr.util.gen_write(file_name, ['a', 'b'], [a, b, a])
    with assert_raises(ValueError):
        treecorr.util.gen_write(file_name, ['a'], [a, b])
    with assert_raises(ValueError):
        treecorr.util.gen_write(file_name, [], [])
    with assert_raises(ValueError):
        treecorr.util.gen_write(file_name, ['a', 'b'], [a, b[:1]])
    with assert_raises(ValueError):
        treecorr.util.gen_write(file_name, ['a', 'b'], [a, b], file_type='Invalid')

    with assert_raises(ValueError):
        treecorr.util.gen_read(file_name, file_type='Invalid')

    # Now some places that do sanity checks for invalid coords or metrics which would already
    # be checked in normal operation.
    with assert_raises(ValueError):
        treecorr.util.parse_metric('Euclidean', 'invalid')
    with assert_raises(ValueError):
        treecorr.util.parse_metric('Invalid', 'flat')
    with assert_raises(ValueError):
        treecorr.util.coord_enum('invalid')
    with assert_raises(ValueError):
        treecorr.util.metric_enum('Invalid')
github rmjarvis / TreeCorr / treecorr / kgcorrelation.py View on Github external
Parameters:
            file_name (str):    The name of the file to write to.
            file_type (str):    The type of file to write ('ASCII' or 'FITS').  (default: determine
                                the type automatically from the extension of file_name.)
            precision (int):    For ASCII output catalogs, the desired precision. (default: 4;
                                this value can also be given in the constructor in the config dict.)
        """
        self.logger.info('Writing KG correlations to %s',file_name)
        if precision is None:
            precision = self.config.get('precision', 4)

        params = { 'coords' : self.coords, 'metric' : self.metric,
                   'sep_units' : self.sep_units, 'bin_type' : self.bin_type }

        treecorr.util.gen_write(
            file_name,
            ['r_nom','meanr','meanlogr','kgamT','kgamX','sigma','weight','npairs'],
            [ self.rnom, self.meanr, self.meanlogr,
              self.xi, self.xi_im, np.sqrt(self.varxi),
              self.weight, self.npairs ],
            params=params, precision=precision, file_type=file_type, logger=self.logger)
github rmjarvis / TreeCorr / treecorr / nkcorrelation.py View on Github external
if desired.  (default: None)
            file_type (str):    The type of file to write ('ASCII' or 'FITS').  (default: determine
                                the type automatically from the extension of file_name.)
            precision (int):    For ASCII output catalogs, the desired precision. (default: 4;
                                this value can also be given in the constructor in the config dict.)
        """
        self.logger.info('Writing NK correlations to %s',file_name)

        xi, varxi = self.calculateXi(rk)
        if precision is None:
            precision = self.config.get('precision', 4)

        params = { 'coords' : self.coords, 'metric' : self.metric,
                   'sep_units' : self.sep_units, 'bin_type' : self.bin_type }

        treecorr.util.gen_write(
            file_name,
            ['r_nom','meanr','meanlogr','kappa','sigma','weight','npairs'],
            [ self.rnom, self.meanr, self.meanlogr,
              xi, np.sqrt(varxi), self.weight, self.npairs ],
            params=params, precision=precision, file_type=file_type, logger=self.logger)
github rmjarvis / TreeCorr / treecorr / ngcorrelation.py View on Github external
self.logger.info('Writing Norm from NG correlations to %s',file_name)
        if R is None:
            R = self.rnom

        nmap, nmx, varnmap = self.calculateNMap(R=R, rg=rg, m2_uform=m2_uform)
        mapsq, mapsq_im, mxsq, mxsq_im, varmapsq = gg.calculateMapSq(R=R, m2_uform=m2_uform)
        nsq, varnsq = dd.calculateNapSq(R=R, rr=rr, dr=dr, m2_uform=m2_uform)

        nmnorm = nmap**2 / (nsq * mapsq)
        varnmnorm = nmnorm**2 * (4. * varnmap / nmap**2 + varnsq / nsq**2 + varmapsq / mapsq**2)
        nnnorm = nsq / mapsq
        varnnnorm = nnnorm**2 * (varnsq / nsq**2 + varmapsq / mapsq**2)
        if precision is None:
            precision = self.config.get('precision', 4)

        treecorr.util.gen_write(
            file_name,
            [ 'R',
              'NMap','NMx','sig_nmap',
              'Napsq','sig_napsq','Mapsq','sig_mapsq',
              'NMap_norm','sig_norm','Nsq_Mapsq','sig_nn_mm' ],
            [ R,
              nmap, nmx, np.sqrt(varnmap),
              nsq, np.sqrt(varnsq), mapsq, np.sqrt(varmapsq),
              nmnorm, np.sqrt(varnmnorm), nnnorm, np.sqrt(varnnnorm) ],
            precision=precision, file_type=file_type, logger=self.logger)
github rmjarvis / TreeCorr / treecorr / catalog.py View on Github external
It will write a FITS file if the file name ends with '.fits', otherwise an ASCII file.

        Parameters:
            file_name (str):    The name of the file to write to.
        """
        self.logger.info('Writing centers to %s',file_name)

        centers = self.patch_centers
        col_names = ['patch', 'x', 'y']
        if self.coords != 'flat':
            col_names.append('z')
        columns = [np.arange(centers.shape[0])]
        for i in range(centers.shape[1]):
            columns.append(centers[:,i])

        treecorr.util.gen_write(file_name, col_names, columns, precision=16, logger=self.logger)
github rmjarvis / TreeCorr / treecorr / nncorrelation.py View on Github external
col_names += ['DR','RD']
                columns += [ dr.weight * (self.tot/dr.tot), rd.weight * (self.tot/rd.tot) ]
            elif dr is not None or rd is not None:
                if dr is None: dr = rd
                col_names += ['DR']
                columns += [ dr.weight * (self.tot/dr.tot) ]
            col_names += [ 'npairs' ]
            columns += [ self.npairs ]

        if precision is None:
            precision = self.config.get('precision', 4)

        params = { 'tot' : self.tot, 'coords' : self.coords, 'metric' : self.metric,
                   'sep_units' : self.sep_units, 'bin_type' : self.bin_type }

        treecorr.util.gen_write(
            file_name, col_names, columns, params=params,
            precision=precision, file_type=file_type, logger=self.logger)