### Install TreeCorr with pip (user or sudo) Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/docs/overview.md Alternative pip installation methods for systems with restricted write permissions. '--user' installs to the user's local directory, while 'sudo' installs globally. ```bash sudo pip install treecorr ``` ```bash pip install treecorr --user ``` -------------------------------- ### Install Test Requirements Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/docs/_build/html/overview.html Installs the necessary packages for running unit tests. ```bash pip install -r test_requirements.txt ``` -------------------------------- ### HdfReader.__init__ Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/docs/_build/html/_modules/treecorr/reader.html Initializes the HdfReader with a file name. Requires the h5py library to be installed. ```APIDOC ## HdfReader.__init__ ### Description Initializes the HdfReader with a file name. Requires the h5py library to be installed. ### Method __init__ ### Parameters #### Path Parameters - **file_name** (str) - Required - The file name. - **logger** (object) - Optional - A logger object for error reporting. ``` -------------------------------- ### Install TreeCorr with Pip (User Install) Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/README.rst Install TreeCorr for the current user only. This is useful if you don't have system-wide write permissions. ```bash pip install treecorr --user ``` -------------------------------- ### Install TreeCorr from Local Distribution Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/README.rst Installs TreeCorr from a local distribution using pip. Use the --user flag if write permission is an issue. ```bash pip install . ``` ```bash pip install . --user ``` -------------------------------- ### Install Dependencies with Pip Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/docs/_build/html/overview.html Install all required dependencies for TreeCorr using the requirements.txt file. ```bash pip install -r requirements.txt ``` -------------------------------- ### Install TreeCorr with Pip (Custom Prefix) Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/README.rst Install TreeCorr to a custom prefix directory. This allows control over installation locations for executables and modules. ```bash pip install treecorr --install-option="--prefix=PREFIX" ``` -------------------------------- ### Initialize FitsReader with Fitsio Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/docs/_build/html/_modules/treecorr/reader.html Initializes the FitsReader, requiring the 'fitsio' library. It includes an assertion to ensure a compatible version of 'fitsio' is installed. ```python import fitsio # There is a bug in earlier fitsio versions that prevents slicing. # If you hit this assert, upgrade your fitsio version. assert fitsio.__version__ > '1.0.6' self._file = None # Only works inside a with block. # record file name to know what to open when entering self.file_name = file_name ``` -------------------------------- ### Initialize HDFReader Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/docs/_build/html/_modules/treecorr/reader.html Initializes the HdfReader with a file name. Requires the h5py library to be installed. An optional logger can be provided for error messages. ```python def __init__(self, file_name, *, logger=None): """ Parameters: file_name (str): The file name. """ try: import h5py except ImportError: if logger: logger.error("Unable to import h5py. Cannot read %s"%file_name) raise self._file = None # Only works inside a with block. self.file_name = file_name ``` -------------------------------- ### Overriding Configuration Parameters on Command Line Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/docs/scripts.md These examples show how to specify or override parameters directly on the command line when running the corr2 executable. ```bash corr2 config.yaml file_name=file1.dat gg_file_name=file1.out corr2 config.yaml file_name=file2.dat gg_file_name=file2.out ... ``` -------------------------------- ### Get File Extension Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/docs/_build/html/_modules/treecorr/catalog.html Retrieves the file extension from the configuration, falling back to a default if not specified. This is part of the initial file processing setup. ```python with reader: # get the vanilla "ext" parameter ext = get_from_list(self.config, 'ext', num, str, reader.default_ext) ``` -------------------------------- ### Initialize Catalog with Configuration Dictionary Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/docs/_build/html/_modules/treecorr/catalog.html Pass a configuration dictionary containing file reading parameters as an argument after the file name. ```python >>> config = { 'ra_col' : 'ALPHA2000', ... 'dec_col' : 'DELTA2000', ... 'g1_col' : 'E1', ... 'g2_col' : 'E2', ... 'ra_units' : 'deg', ... 'dec_units' : 'deg' } >>> cat = treecorr.Catalog(file_name, config) ``` -------------------------------- ### Install TreeCorr with Conda Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/README.rst Install the TreeCorr package using conda. This is an alternative installation method. ```bash conda install -c conda-forge treecorr ``` -------------------------------- ### treecorr.config.setup_logger Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/docs/_build/html/scripts.html Sets up and returns a logger object based on verbosity level and an optional log file. ```APIDOC ## treecorr.config.setup_logger ### Description Parse the integer verbosity level from the command line args into a logging_level string. ### Parameters * **verbose** (int) - An integer indicating what verbosity level to use. * **log_file** (str, optional) - If given, a file name to which to write the logging output. If omitted or None, then output to stdout. * **name** (str, optional) - The name of the logger. ### Returns * logging.Logger - The logging.Logger object to use. ``` -------------------------------- ### Setup Logging Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/docs/_build/html/_modules/treecorr/config.html Configures a logger with a specified verbosity level and optional log file output. Handles mapping integer verbosity to logging levels. ```python import logging import sys def setup_logger(verbose, log_file=None, name=None): """Parse the integer verbosity level from the command line args into a logging_level string :param verbose: An integer indicating what verbosity level to use. :param log_file: If given, a file name to which to write the logging output. If omitted or None, then output to stdout. :returns: The logging.Logger object to use. """ logging_levels = { 0: logging.CRITICAL, 1: logging.WARNING, 2: logging.INFO, 3: logging.DEBUG } logging_level = logging_levels[int(verbose)] # Setup logging to go to sys.stdout or (if requested) to an output file if name is None: name = 'treecorr' if log_file is not None: name += '_' + log_file logger = logging.getLogger(name) if len(logger.handlers) == 0: # only add handler once! if log_file is None: handle = logging.StreamHandler(stream=sys.stdout) else: handle = logging.FileHandler(log_file) formatter = logging.Formatter('%(message)s') # Simple text output handle.setFormatter(formatter) logger.addHandler(handle) logger.setLevel(logging_level) return logger ``` -------------------------------- ### Install TreeCorr with conda Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/docs/overview.md Install the TreeCorr package using conda from the conda-forge channel. Use the update command to upgrade an existing installation. ```bash conda install -c conda-forge treecorr ``` ```bash conda update -c conda-forge treecorr ``` -------------------------------- ### Catalog Initialization Parameters Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/docs/_build/html/_modules/treecorr/catalog.html Illustrates the various parameters available during the initialization of a Catalog object, including data columns, configuration options, and processing controls. ```python def __init__(self, file_name=None, config=None, *, num=0, logger=None, is_rand=False, x=None, y=None, z=None, ra=None, dec=None, r=None, w=None, wpos=None, flag=None, k=None, z1=None, z2=None, v1=None, v2=None, g1=None, g2=None, t1=None, t2=None, q1=None, q2=None, patch=None, patch_centers=None, rng=None, **kwargs): self.config = merge_config(config, kwargs, Catalog._valid_params, Catalog._aliases) self.orig_config = config.copy() if config is not None else {} if config and kwargs: self.orig_config.update(kwargs) self._num = num self._is_rand = is_rand if logger is not None: self.logger = logger self._logger_name = logger.name else: self._logger_name = 'treecorr.Catalog' self.logger = setup_logger(get(self.config,'verbose',int,1), self.config.get('log_file',None), self._logger_name) # Start with everything set to None. Overwrite as appropriate. self._x = None self._y = None self._z = None self._ra = None self._dec = None self._r = None self._w = None self._wpos = None self._flag = None self._k = None self._z1 = None self._z2 = None self._v1 = None self._v2 = None self._g1 = None self._g2 = None self._t1 = None self._t2 = None self._q1 = None self._q2 = None self._patch = None self._field = lambda : None self._nontrivial_w = None self._single_patch = None self._nobj = None self._sumw = None self._sumw2 = None self._vark = None self._varz = None self._varv = None self._varg = None self._vart = None self._varq = None self._patches = None self._centers = None self._computed_centers = None self._rng = rng first_row = get_from_list(self.config,'first_row',num,int,1) if first_row < 1: raise ValueError("first_row should be >= 1") last_row = get_from_list(self.config,'last_row',num,int,-1) if last_row > 0 and last_row < first_row: raise ValueError("last_row should be >= first_row") if last_row > 0: self.end = last_row else: self.end = None if first_row > 1: self.start = first_row-1 else: self.start = 0 self.every_nth = get_from_list(self.config,'every_nth',num,int,1) if self.every_nth < 1: raise ValueError("every_nth should be >= 1") try: self._single_patch = int(patch) except TypeError: pass else: patch = None if patch_centers is None and 'patch_centers' in self.config: # file name version may be in a config dict, rather than kwarg. patch_centers = get(self.config,'patch_centers',str) if patch_centers is not None: if patch is not None or self.config.get('patch_col',0) not in (0,'0'): raise ValueError("Cannot provide both patch and patch_centers") if isinstance(patch_centers, np.ndarray): self._centers = patch_centers else: self._centers = self.read_patch_centers(patch_centers) self._npatch = self._centers.shape[0] if self.config.get('npatch', self._npatch) != self._npatch: raise ValueError("npatch is incompatible with provided centers") ``` -------------------------------- ### Catalog Initialization with Configuration Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/docs/_build/html/_modules/treecorr/catalog.html Initializes a Catalog object, processing configuration options for various statistical quantities like vark, varz, varv, varg, vart, and varq. These options allow for pre-setting or calculating these variance measures. ```python if self.config.get('vark', None) is not None: self._vark = self.config['vark'] self._meank = 0. self._altmeank = 0. if self.config.get('varz', None) is not None: self._varz = self._varz1 = self._varz2 = self.config['varz'] self._meanz1 = self._meanz2 = 0. self._altmeanz1 = self._altmeanz2 = 0. if self.config.get('varv', None) is not None: self._varv = self._varv1 = self._varv2 = self.config['varv'] self._meanv1 = self._meanv2 = 0. self._altmeanv1 = self._altmeanv2 = 0. if self.config.get('varg', None) is not None: self._varg = self._varg1 = self._varg2 = self.config['varg'] self._meang1 = self._meang2 = 0. self._altmeang1 = self._altmeang2 = 0. if self.config.get('vart', None) is not None: self._vart = self._vart1 = self._vart2 = self.config['vart'] self._meant1 = self._meant2 = 0. self._altmeant1 = self._altmeant2 = 0. if self.config.get('varq', None) is not None: self._varq = self._varq1 = self._varq2 = self.config['varq'] self._meanq1 = self._meanq2 = 0. self._altmeanq1 = self._altmeanq2 = 0. ``` -------------------------------- ### Install Requirements Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/README.rst Installs all required dependencies for TreeCorr using pip or conda. ```bash pip install -r requirements.txt ``` ```bash conda install -c conda-forge treecorr --only-deps ``` -------------------------------- ### Initialize Catalog with Configuration Dictionary Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/docs/_build/html/catalog.html Use a configuration dictionary to specify catalog parameters like column names and units. This is useful for encapsulating TreeCorr options for repeated use. ```python config = { 'ra_col' : 'ALPHA2000', 'dec_col' : 'DELTA2000', 'g1_col' : 'E1', 'g2_col' : 'E2', 'ra_units' : 'deg', 'dec_units' : 'deg' } cat = treecorr.Catalog(file_name, config) ``` -------------------------------- ### Running corr3 with a configuration file Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/docs/_build/html/_sources/scripts.rst.txt Execute the corr3 script by providing a configuration file as a command-line argument. ```bash corr3 config.yaml ``` -------------------------------- ### Install Dependencies with Conda Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/docs/_build/html/overview.html Install only the dependencies for TreeCorr using conda from the conda-forge channel. ```bash conda install -c conda-forge treecorr --only-deps ``` -------------------------------- ### Corr2Base Initialization Parameters Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/docs/_build/html/_modules/treecorr/corr2base.html Illustrates the various configuration parameters available during the initialization of the Corr2Base class. These parameters control aspects like binning, variance calculation, and threading. ```python 'xperiod': (float, False, None, None, 'The period to use for the x direction for the Periodic metric'), 'yperiod': (float, False, None, None, 'The period to use for the y direction for the Periodic metric'), 'zperiod': (float, False, None, None, 'The period to use for the z direction for the Periodic metric'), 'var_method': (str, False, 'shot', ['shot', 'jackknife', 'sample', 'bootstrap', 'marked_bootstrap'], 'The method to use for estimating the variance'), 'num_bootstrap': (int, False, 500, None, 'How many bootstrap samples to use for the var_method=bootstrap and ' 'marked_bootstrap'), 'cross_patch_weight': (str, False, None, ['simple', 'mean', 'match', 'geom'], 'How to weight pairs that cross between a selected and unselected patch'), 'num_threads' : (int, False, None, None, 'How many threads should be used. num_threads <= 0 means auto based on num cores.'), } def __init__(self, config=None, *, logger=None, rng=None, **kwargs): self._corr = None # Do this first to make sure we always have it for __del__ self.config = merge_config(config,kwargs,Corr2._valid_params) if logger is None: self._logger_name = 'treecorr.Corr2' self.logger = setup_logger(get(self.config,'verbose',int,1), self.config.get('log_file',None), self._logger_name) else: self.logger = logger self._logger_name = logger.name # We'll make a bunch of attributes here, which we put into a namespace called _ro. # These are the core attributes that won't ever be changed after construction. # This is an efficiency optimization (both memory and flops), since it will allow # copy() to just copy a pointer to the _ro namespace without having to copy each # individual attribute separately. # The access of these attributes are all via read-only properties. self._ro = Namespace() if 'output_dots' in self.config: self._ro.output_dots = get(self.config,'output_dots',bool) else: self._ro.output_dots = get(self.config,'verbose',int,1) >= 2 self._ro.bin_type = self.config.get('bin_type', 'Log') self._ro.sep_units = self.config.get('sep_units','') self._ro._sep_units = get(self.config,'sep_units',str,'radians') self._ro._log_sep_units = math.log(self._sep_units) if self.config.get('nbins', None) is None: if self.config.get('max_sep', None) is None: raise TypeError("Missing required parameter max_sep") if self.config.get('min_sep', None) is None and self.bin_type != 'TwoD': raise TypeError("Missing required parameter min_sep") if self.config.get('bin_size', None) is None: raise TypeError("Missing required parameter bin_size") self._ro.min_sep = float(self.config.get('min_sep',0)) self._ro.max_sep = float(self.config['max_sep']) if self.min_sep >= self.max_sep: raise ValueError("max_sep must be larger than min_sep") self._ro.bin_size = float(self.config['bin_size']) self._ro.nbins = None elif self.config.get('bin_size', None) is None: if self.config.get('max_sep', None) is None: raise TypeError("Missing required parameter max_sep") if self.config.get('min_sep', None) is None and self.bin_type != 'TwoD': raise TypeError("Missing required parameter min_sep") self._ro.min_sep = float(self.config.get('min_sep',0)) self._ro.max_sep = float(self.config['max_sep']) if self.min_sep >= self.max_sep: raise ValueError("max_sep must be larger than min_sep") self._ro.nbins = int(self.config['nbins']) self._ro.bin_size = None elif self.config.get('max_sep', None) is None: if self.config.get('min_sep', None) is None and self.bin_type != 'TwoD': raise TypeError("Missing required parameter min_sep") self._ro.min_sep = float(self.config.get('min_sep',0)) self._ro.nbins = int(self.config['nbins']) self._ro.bin_size = float(self.config['bin_size']) self._ro.max_sep = None else: if self.bin_type == 'TwoD': raise TypeError("Only 2 of max_sep, bin_size, nbins are allowed " ``` -------------------------------- ### Install Optional Modules Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/README.rst Installs optional modules that provide additional functionality for TreeCorr. ```bash pip install fitsio ``` ```bash pip install pandas ``` ```bash pip install pyarrow ``` ```bash pip install h5py ``` ```bash pip install mpi4py ``` -------------------------------- ### Install TreeCorr with Pip Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/README.rst Install the TreeCorr package using pip. This is the recommended method for most users. ```bash pip install treecorr ``` -------------------------------- ### Catalog Initialization with Configuration and Kwargs Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/docs/_build/html/_modules/treecorr/catalog.html Initialize a Catalog object using a configuration dictionary and overriding/adding parameters with keyword arguments. This is useful for encapsulating TreeCorr options and can simplify configuration management. ```python cat1 = treecorr.Catalog(file_name, config, flip_g1=True) ``` -------------------------------- ### Corr3 Initialization and Algorithm Selection Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/docs/_build/html/_modules/treecorr/corr3base.html Demonstrates how to initialize the Corr3 class and select the accumulation algorithm. The 'algo' parameter determines whether to use 'triangle' or 'multipole' methods, with defaults based on 'bin_type'. ```python import math if algo is None: multipole = (self.bin_type != 'LogRUV') else: if algo not in ['triangle', 'multipole']: ``` -------------------------------- ### Install TreeCorr with pip (sudo) Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/docs/_build/html/overview.html Use this command if you have write permission issues with your Python distribution and need to install TreeCorr system-wide with sudo. ```bash sudo pip install treecorr ``` -------------------------------- ### Custom Statistic Function Example Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/docs/_build/html/_modules/treecorr/corr2base.html Example of using a lambda function to compute the covariance of the imaginary part of an NGCorrelation's xi statistic. ```python >>> func = lambda ng: ng.xi_im ``` -------------------------------- ### Initialize Catalog with NumPy Arrays Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/docs/_build/html/catalog.html Create a Catalog object by passing numpy arrays for positions, weights, and other quantities. Ensure all arrays are of the same size. ```python cat = treecorr.Catalog(x=x, y=y, k=k, w=w) ``` -------------------------------- ### KQCorrelation Usage Example Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/docs/_build/html/_modules/treecorr/kqcorrelation.html Demonstrates the typical workflow for using the KQCorrelation class: initializing, processing data, and writing results. Accessing correlation values directly is also shown. ```python >>> kq = treecorr.KQCorrelation(config) >>> kq.process(cat1, cat2) # Compute the cross-correlation. >>> kq.write(file_name) # Write out to a file. >>> xi, xi_im = kq.xi, kq.xi_im # Or access the correlation function directly. ``` -------------------------------- ### Example TreeCorr Configuration (YAML) Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/tests/Tutorial.ipynb An example YAML configuration file for TreeCorr. It defines input data files, column mappings for astronomical coordinates and lensing observables, separation binning, and output file names for shear-shear correlations. ```yaml # The file with the data to be correlated: # (available from https://github.com/rmjarvis/TreeCorr/wiki/Aardvark.fit) file_name: data/Aardvark.fit # What are the names of the columns for ra, dec and what kind of values do they have: ra_col: RA # The column name for RA values in the input file dec_col: DEC # The column name for Dec values in the input file ra_units: degrees # The units of the RA values dec_units: degrees # The units of the Dec values # What are the names of the columns for the lensing observables to be correlated g1_col: GAMMA1 # The column name of the g1 component of shear g2_col: GAMMA2 # The column name of the g2 component of shear k_col: KAPPA # The column name of kappa # Note: k_col can be used for any scalar field, not just lensing kappa. # Define the binning. Binning in TreeCorr uses bins that are equally spaced in log(r). # (i.e. Natural log, not log10.) There are four parameters of which you may specify any 3. min_sep: 1 # The minimum separation that you want included. max_sep: 400 # The maximum separation that you want included. nbins: 100 # The number of bins #bin_size: 0.06 # The width of the bins in log(r). In this case automatically calculated # to be bin_size = log(max_sep/min_sep) / nbins ~= 0.06 sep_units: arcmin # The units of min_sep, max_sep # The name of the output file: # Here, because this field is called gg_file_name, it implies that a GG (i.e. shear-shear) # correlation should be performed and written out to this file. gg_file_name: output/Aardvark.out # Set the level of verbosity that you want. # 0 prints nothing unless there is an error. # 1 is the default, which prints warnings and a few progress lines. ``` -------------------------------- ### Initialize Catalog with Numpy Arrays Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/docs/_build/html/_modules/treecorr/catalog.html Create a Catalog object by passing numpy arrays for position and other quantities. Ensure all arrays have the same size. ```python >>> cat = treecorr.Catalog(x=x, y=y, k=k, w=w) ``` -------------------------------- ### get_patch_file_names Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/docs/_build/html/catalog.html Get the names of the files to use for reading/writing patches in save_patch_dir. ```APIDOC ## get_patch_file_names ### Description Get the names of the files to use for reading/writing patches in save_patch_dir. ### Method (Not specified, likely a Python method call) ### Parameters #### Path Parameters * **save_patch_dir** (str) - The directory where patches are saved. ### Returns (Not specified) ``` -------------------------------- ### Running corr2 with a configuration file Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/docs/_build/html/_sources/scripts.rst.txt Execute the corr2 script by providing a configuration file as a command-line argument. ```bash corr2 config.yaml ``` -------------------------------- ### Writing Catalog to File Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/docs/_build/html/_modules/treecorr/catalog.html Demonstrates how to write a Catalog object to a file. It shows how to specify file type and precision, and how to manage coordinate units for output. ```python def write(self, file_name, *, file_type=None, precision=None): """Write the catalog to a file. The position columns are output using the same units as were used when building the Catalog. If you want to use a different unit, you can set the catalog's units directly before writing. e.g.: >>> cat = treecorr.Catalog('cat.dat', ra=ra, dec=dec, ra_units='hours', dec_units='degrees') >>> cat.ra_units = coord.degrees >>> cat.write('new_cat.dat') The output file will include some of the following columns (those for which the corresponding attribute is not None): ``` -------------------------------- ### Get variance of gamma3 Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/docs/_build/html/_modules/treecorr/nggcorrelation.html Returns the variance of gamma3, which is equivalent to the variance of gamma0. ```python @property def vargam3(self): return self.vargam0 ``` -------------------------------- ### Get variance of gamma2 Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/docs/_build/html/_modules/treecorr/nggcorrelation.html Returns the variance of gamma2, which is equivalent to the variance of gamma1. ```python @property def vargam2(self): return self.vargam1 ``` -------------------------------- ### Initialize AsciiReader Context Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/docs/_build/html/_modules/treecorr/reader.html Sets up the AsciiReader by determining the number of comment rows at the beginning of the file and performing a trivial read to get initial column information. ```python def __enter__(self): # See how many comment rows there are at the start self.comment_rows = 0 with open(self.file_name, 'r') as fid: for line in fid: # pragma: no branch if line.startswith(self.comment_marker): self.comment_rows += 1 else: break # Do a trivial read of 1 row, just to get basic info about columns self.ncols = None if self.comment_rows >= 1: try: data = np.genfromtxt(self.file_name, comments=self.comment_marker, delimiter=self.delimiter, names=True, ``` -------------------------------- ### General Binning and Configuration Properties Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/docs/_build/html/_modules/treecorr/corr3base.html Access general properties related to binning, splitting methods, and various configuration parameters like slop, periodicity, and variance estimation methods. ```python @property def _bintype(self): return self._ro._bintype @property def _nbins(self): return self._ro._nbins @property def _min_sep(self): return self._ro._min_sep @property def _max_sep(self): return self._ro._max_sep @property def _bin_size(self): return self._ro._bin_size @property def split_method(self): return self._ro.split_method @property def min_top(self): return self._ro.min_top @property def max_top(self): return self._ro.max_top @property def bin_slop(self): return self._ro.bin_slop @property def angle_slop(self): return self._ro.angle_slop @property def b(self): return self._ro.b @property def brute(self): return self._ro.brute @property def min_rpar(self): return self._ro.min_rpar @property def max_rpar(self): return self._ro.max_rpar @property def xperiod(self): return self._ro.xperiod @property def yperiod(self): return self._ro.yperiod @property def zperiod(self): return self._ro.zperiod @property def var_method(self): return self._ro.var_method @property def num_bootstrap(self): return self._ro.num_bootstrap @property def cross_patch_weight(self): return self._ro.cross_patch_weight ``` -------------------------------- ### Patch Processing Setup Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/docs/_build/html/_modules/treecorr/corr3base.html Initializes patch counts and MPI job indices for cross-correlation. ```python # Setup for deciding when this is my job. n1 = self.npatch1 n2 = self.npatch2 n3 = self.npatch3 if comm: size = comm.Get_size() rank = comm.Get_rank() n = max(n1,n2,n3) my_indices = np.arange(n * rank // size, n * (rank+1) // size) self.logger.info("Rank %d: My indices are %s",rank,my_indices) else: my_indices = None ``` -------------------------------- ### QQCorrelation Usage Example Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/docs/_build/html/_modules/treecorr/qqcorrelation.html Demonstrates the typical usage pattern for QQCorrelation, including initialization, processing auto/cross-correlations, writing results, and accessing correlation functions. ```python >>> qq = treecorr.QQCorrelation(config) >>> qq.process(cat) # Compute the auto-correlation. >>> # qq.process(cat1, cat2) # ... or the cross-correlation. >>> qq.write(file_name) # Write out to a file. >>> xip, xim = qq.xip, qq.xim # Or access the correlation functions directly. ``` -------------------------------- ### Read YAML Configuration Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/docs/_build/html/_modules/treecorr/config.html Loads configuration from a YAML file. Ensure the PyYAML library is installed. ```python import yaml def _read_yaml_file(file_name): with open(file_name) as fin: config = yaml.safe_load(fin.read()) return config ``` -------------------------------- ### Low Memory Auto-Correlation Example Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/docs/_build/html/_sources/patches.rst.txt Demonstrates setting up and processing a large shear catalog for auto-correlation using low memory mode. Requires defining patch centers and a temporary directory for patch files. ```python small_cat = treecorr.Catalog(cat_file, config, every_nth=100, npatch=N) small_cat.write_patch_centers(cen_file) del small_cat full_cat = treecorr.Catalog(cat_file, config, patch_centers=cen_file, save_patch_dir=tmp_dir) gg = treecorr.GGCorrelation(ggconfig) gg.process(full_cat, low_mem=True) ``` -------------------------------- ### treecorr.config.get_from_list Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/docs/scripts.md A helper function to get a key from config that is allowed to be a list, returning the specified element. ```APIDOC ## treecorr.config.get_from_list(config, key, num, value_type=str, default=None) ### Description A helper function to get a key from config that is allowed to be a list. Some of the config values are allowed to be lists of values, in which case we take the `num` item from the list. If they are not a list, then the given value is used for all values of `num`. ### Parameters * **config** (dict) – The configuration dict from which to get the key value. * **key** (str) – What key to get from config. * **num** (int) – Which number element to use if the item is a list. * **value_type** (type, optional) – What type should the value be converted to. Defaults to str. * **default** (any, optional) – What value should be used if the key is not in the config dict, or the value corresponding to the key is None. Defaults to None. ### Returns The specified value, converted as needed. ``` -------------------------------- ### Initialize ParquetReader with Pandas Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/docs/_build/html/_modules/treecorr/reader.html Initializes the ParquetReader, requiring pandas to be installed. It raises an error if pandas is not available. ```python import pandas self.file_name = file_name self._df = None ``` -------------------------------- ### Initialize LogRUV Binning Arrays Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/docs/_build/html/_modules/treecorr/corr3base.html Sets up 1D arrays for u and v bins (u1d, v1d) and then tiles them to create 3D arrays for logr, u, and v. It also calculates the nominal radial distances (rnom) and sets the total number of bins and data shape. ```python if self.bin_type == 'LogRUV': self._ro.u1d = np.linspace(start=0, stop=self.nubins*self.ubin_size, num=self.nubins, endpoint=False) self._ro.u1d += self.min_u + 0.5*self.ubin_size self._ro.v1d = np.linspace(start=0, stop=self.nvbins*self.vbin_size, num=self.nvbins, endpoint=False) self._ro.v1d += self.min_v + 0.5*self.vbin_size self._ro.v1d = np.concatenate([-self.v1d[::-1],self.v1d]) self._ro.logr = np.tile(self.logr1d[:, np.newaxis, np.newaxis], (1, self.nubins, 2*self.nvbins)) self._ro.u = np.tile(self.u1d[np.newaxis, :, np.newaxis], (self.nbins, 1, 2*self.nvbins)) self._ro.v = np.tile(self.v1d[np.newaxis, np.newaxis, :], (self.nbins, self.nubins, 1)) self._ro.rnom = np.exp(self.logr) self._ro.rnom1d = np.exp(self.logr1d) self._ro._nbins = len(self._ro.logr.ravel()) self.data_shape = self._ro.logr.shape self.meanu = np.zeros(self.data_shape, dtype=float) self.meanv = np.zeros(self.data_shape, dtype=float) ``` -------------------------------- ### Upgrade TreeCorr with Conda Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/README.rst Upgrade an existing TreeCorr installation to the latest released version using conda. ```bash conda update -c conda-forge treecorr ``` -------------------------------- ### Running corr2 and corr3 command-line tools Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/README.rst Executables corr2 and corr3 require a configuration file. Parameters can also be specified on the command line. ```bash corr2 config_file corr3 config_file ``` ```bash corr2 config_file file_name=file1.dat gg_file_name=file1.out corr2 config_file file_name=file2.dat gg_file_name=file2.out ``` -------------------------------- ### Upgrade TreeCorr with Pip Source: https://github.com/rmjarvis/treecorr/blob/releases/5.1/README.rst Upgrade an existing TreeCorr installation to the latest released version using pip. ```bash pip install treecorr --upgrade ```