How to use the treecorr.config.get_from_list 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 / treecorr / catalog.py View on Github external
def _apply_units(self):
        # Apply units to x,y,ra,dec
        if self._ra is not None:
            self.ra_units = treecorr.config.get_from_list(self.config,'ra_units',self._num)
            self.dec_units = treecorr.config.get_from_list(self.config,'dec_units',self._num)
            self._ra *= self.ra_units
            self._dec *= self.dec_units
        else:
            self.x_units = treecorr.config.get_from_list(self.config,'x_units',self._num,str,'radians')
            self.y_units = treecorr.config.get_from_list(self.config,'y_units',self._num,str,'radians')
            self._x *= self.x_units
            self._y *= self.y_units
github rmjarvis / TreeCorr / treecorr / catalog.py View on Github external
def _finish_input(self):
        # Finish processing the data based on given inputs.

        # Apply flips if requested
        flip_g1 = treecorr.config.get_from_list(self.config,'flip_g1',self._num,bool,False)
        flip_g2 = treecorr.config.get_from_list(self.config,'flip_g2',self._num,bool,False)
        if flip_g1:
            self.logger.info("   Flipping sign of g1.")
            self._g1 = -self._g1
        if flip_g2:
            self.logger.info("   Flipping sign of g2.")
            self._g2 = -self._g2

        # Convert the flag to a weight
        if self._flag is not None:
            if 'ignore_flag' in self.config:
                ignore_flag = treecorr.config.get_from_list(self.config,'ignore_flag',self._num,int)
            else:
                ok_flag = treecorr.config.get_from_list(self.config,'ok_flag',self._num,int,0)
                ignore_flag = ~ok_flag
            # If we don't already have a weight column, make one with all values = 1.
github rmjarvis / TreeCorr / treecorr / catalog.py View on Github external
# Just check the consistency of the various column numbers so we can fail fast.
        try:
            import fitsio
        except ImportError:
            self.logger.error("Unable to import fitsio.  Cannot read catalog %s"%file_name)
            raise

        # Get the column names
        x_col = treecorr.config.get_from_list(self.config,'x_col',num,str,'0')
        y_col = treecorr.config.get_from_list(self.config,'y_col',num,str,'0')
        z_col = treecorr.config.get_from_list(self.config,'z_col',num,str,'0')
        ra_col = treecorr.config.get_from_list(self.config,'ra_col',num,str,'0')
        dec_col = treecorr.config.get_from_list(self.config,'dec_col',num,str,'0')
        r_col = treecorr.config.get_from_list(self.config,'r_col',num,str,'0')
        w_col = treecorr.config.get_from_list(self.config,'w_col',num,str,'0')
        wpos_col = treecorr.config.get_from_list(self.config,'wpos_col',num,str,'0')
        flag_col = treecorr.config.get_from_list(self.config,'flag_col',num,str,'0')
        g1_col = treecorr.config.get_from_list(self.config,'g1_col',num,str,'0')
        g2_col = treecorr.config.get_from_list(self.config,'g2_col',num,str,'0')
        k_col = treecorr.config.get_from_list(self.config,'k_col',num,str,'0')
        patch_col = treecorr.config.get_from_list(self.config,'patch_col',num,str,'0')
        allow_xyz = self.config.get('allow_xyz', False)

        if x_col != '0' or y_col != '0':
            if x_col == '0':
                raise ValueError("x_col missing for file %s"%file_name)
            if y_col == '0':
                raise ValueError("y_col missing for file %s"%file_name)
            if ra_col != '0' and not allow_xyz:
                raise ValueError("ra_col not allowed in conjunction with x/y cols")
            if dec_col != '0' and not allow_xyz:
                raise ValueError("dec_col not allowed in conjunction with x/y cols")
github rmjarvis / TreeCorr / treecorr / catalog.py View on Github external
skip_header=start, max_rows=max_rows)
                data = data[::self.every_nth]

        # If only one row, and not using pands, then the shape comes in as one-d.  Reshape it:
        if len(data.shape) == 1:
            data = data.reshape(1,-1)
        ncols = data.shape[1]

        self.logger.debug('read data from %s, num=%d',file_name,num)
        self.logger.debug('data shape = %s',str(data.shape))

        # Get the column numbers
        x_col = treecorr.config.get_from_list(self.config,'x_col',num,int,0)
        y_col = treecorr.config.get_from_list(self.config,'y_col',num,int,0)
        z_col = treecorr.config.get_from_list(self.config,'z_col',num,int,0)
        ra_col = treecorr.config.get_from_list(self.config,'ra_col',num,int,0)
        dec_col = treecorr.config.get_from_list(self.config,'dec_col',num,int,0)
        r_col = treecorr.config.get_from_list(self.config,'r_col',num,int,0)
        w_col = treecorr.config.get_from_list(self.config,'w_col',num,int,0)
        wpos_col = treecorr.config.get_from_list(self.config,'wpos_col',num,int,0)
        flag_col = treecorr.config.get_from_list(self.config,'flag_col',num,int,0)
        g1_col = treecorr.config.get_from_list(self.config,'g1_col',num,int,0)
        g2_col = treecorr.config.get_from_list(self.config,'g2_col',num,int,0)
        k_col = treecorr.config.get_from_list(self.config,'k_col',num,int,0)
        patch_col = treecorr.config.get_from_list(self.config,'patch_col',num,int,0)

        # Read x,y or ra,dec
        if x_col != 0:
            # NB. astype always copies, even if the type is already correct.
            # We actually want this, since it makes the result contiguous in memory,
            # which we will need.
            self._x = data[:,x_col-1].astype(float)
github rmjarvis / TreeCorr / treecorr / catalog.py View on Github external
def _check_fits(self, file_name, num=0, is_rand=False):
        # Just check the consistency of the various column numbers so we can fail fast.
        try:
            import fitsio
        except ImportError:
            self.logger.error("Unable to import fitsio.  Cannot read catalog %s"%file_name)
            raise

        # Get the column names
        x_col = treecorr.config.get_from_list(self.config,'x_col',num,str,'0')
        y_col = treecorr.config.get_from_list(self.config,'y_col',num,str,'0')
        z_col = treecorr.config.get_from_list(self.config,'z_col',num,str,'0')
        ra_col = treecorr.config.get_from_list(self.config,'ra_col',num,str,'0')
        dec_col = treecorr.config.get_from_list(self.config,'dec_col',num,str,'0')
        r_col = treecorr.config.get_from_list(self.config,'r_col',num,str,'0')
        w_col = treecorr.config.get_from_list(self.config,'w_col',num,str,'0')
        wpos_col = treecorr.config.get_from_list(self.config,'wpos_col',num,str,'0')
        flag_col = treecorr.config.get_from_list(self.config,'flag_col',num,str,'0')
        g1_col = treecorr.config.get_from_list(self.config,'g1_col',num,str,'0')
        g2_col = treecorr.config.get_from_list(self.config,'g2_col',num,str,'0')
        k_col = treecorr.config.get_from_list(self.config,'k_col',num,str,'0')
        patch_col = treecorr.config.get_from_list(self.config,'patch_col',num,str,'0')
        allow_xyz = self.config.get('allow_xyz', False)

        if x_col != '0' or y_col != '0':
            if x_col == '0':
                raise ValueError("x_col missing for file %s"%file_name)
            if y_col == '0':
github rmjarvis / TreeCorr / treecorr / catalog.py View on Github external
# If only one row, and not using pands, then the shape comes in as one-d.  Reshape it:
        if len(data.shape) == 1:
            data = data.reshape(1,-1)
        ncols = data.shape[1]

        self.logger.debug('read data from %s, num=%d',file_name,num)
        self.logger.debug('data shape = %s',str(data.shape))

        # Get the column numbers
        x_col = treecorr.config.get_from_list(self.config,'x_col',num,int,0)
        y_col = treecorr.config.get_from_list(self.config,'y_col',num,int,0)
        z_col = treecorr.config.get_from_list(self.config,'z_col',num,int,0)
        ra_col = treecorr.config.get_from_list(self.config,'ra_col',num,int,0)
        dec_col = treecorr.config.get_from_list(self.config,'dec_col',num,int,0)
        r_col = treecorr.config.get_from_list(self.config,'r_col',num,int,0)
        w_col = treecorr.config.get_from_list(self.config,'w_col',num,int,0)
        wpos_col = treecorr.config.get_from_list(self.config,'wpos_col',num,int,0)
        flag_col = treecorr.config.get_from_list(self.config,'flag_col',num,int,0)
        g1_col = treecorr.config.get_from_list(self.config,'g1_col',num,int,0)
        g2_col = treecorr.config.get_from_list(self.config,'g2_col',num,int,0)
        k_col = treecorr.config.get_from_list(self.config,'k_col',num,int,0)
        patch_col = treecorr.config.get_from_list(self.config,'patch_col',num,int,0)

        # Read x,y or ra,dec
        if x_col != 0:
            # NB. astype always copies, even if the type is already correct.
            # We actually want this, since it makes the result contiguous in memory,
            # which we will need.
            self._x = data[:,x_col-1].astype(float)
            self.logger.debug('read x')
            self._y = data[:,y_col-1].astype(float)
            self.logger.debug('read y')
github rmjarvis / TreeCorr / treecorr / catalog.py View on Github external
def _apply_units(self):
        # Apply units to x,y,ra,dec
        if self._ra is not None:
            self.ra_units = treecorr.config.get_from_list(self.config,'ra_units',self._num)
            self.dec_units = treecorr.config.get_from_list(self.config,'dec_units',self._num)
            self._ra *= self.ra_units
            self._dec *= self.dec_units
        else:
            self.x_units = treecorr.config.get_from_list(self.config,'x_units',self._num,str,'radians')
            self.y_units = treecorr.config.get_from_list(self.config,'y_units',self._num,str,'radians')
            self._x *= self.x_units
            self._y *= self.y_units
github rmjarvis / TreeCorr / treecorr / catalog.py View on Github external
def _check_ascii(self, file_name, num=0, is_rand=False):
        # Just check the consistency of the various column numbers so we can fail fast.

        # Just read 1 row so we know how many columns there are.
        # Also will give an IO error if the file is unreadable.
        comment_marker = self.config.get('comment_marker','#')
        delimiter = self.config.get('delimiter',None)
        data = np.genfromtxt(file_name, comments=comment_marker, delimiter=delimiter, max_rows=1)
        if len(data.shape) != 1:  # pragma: no cover
            raise IOError('Unable to parse the input catalog as a numpy array')
        ncols = data.shape[0]

        # Get the column numbers or names
        x_col = treecorr.config.get_from_list(self.config,'x_col',num,int,0)
        y_col = treecorr.config.get_from_list(self.config,'y_col',num,int,0)
        z_col = treecorr.config.get_from_list(self.config,'z_col',num,int,0)
        ra_col = treecorr.config.get_from_list(self.config,'ra_col',num,int,0)
        dec_col = treecorr.config.get_from_list(self.config,'dec_col',num,int,0)
        r_col = treecorr.config.get_from_list(self.config,'r_col',num,int,0)
        w_col = treecorr.config.get_from_list(self.config,'w_col',num,int,0)
        wpos_col = treecorr.config.get_from_list(self.config,'wpos_col',num,int,0)
        flag_col = treecorr.config.get_from_list(self.config,'flag_col',num,int,0)
        g1_col = treecorr.config.get_from_list(self.config,'g1_col',num,int,0)
        g2_col = treecorr.config.get_from_list(self.config,'g2_col',num,int,0)
        k_col = treecorr.config.get_from_list(self.config,'k_col',num,int,0)
        patch_col = treecorr.config.get_from_list(self.config,'patch_col',num,int,0)
        allow_xyz = self.config.get('allow_xyz', False)

        # Read x,y or ra,dec
        if x_col != 0 or y_col != 0:
            if x_col <= 0 or x_col > ncols:
                raise TypeError("x_col missing or invalid for file %s"%file_name)
github rmjarvis / TreeCorr / treecorr / catalog.py View on Github external
delimiter = self.config.get('delimiter',None)
        data = np.genfromtxt(file_name, comments=comment_marker, delimiter=delimiter, max_rows=1)
        if len(data.shape) != 1:  # pragma: no cover
            raise IOError('Unable to parse the input catalog as a numpy array')
        ncols = data.shape[0]

        # Get the column numbers or names
        x_col = treecorr.config.get_from_list(self.config,'x_col',num,int,0)
        y_col = treecorr.config.get_from_list(self.config,'y_col',num,int,0)
        z_col = treecorr.config.get_from_list(self.config,'z_col',num,int,0)
        ra_col = treecorr.config.get_from_list(self.config,'ra_col',num,int,0)
        dec_col = treecorr.config.get_from_list(self.config,'dec_col',num,int,0)
        r_col = treecorr.config.get_from_list(self.config,'r_col',num,int,0)
        w_col = treecorr.config.get_from_list(self.config,'w_col',num,int,0)
        wpos_col = treecorr.config.get_from_list(self.config,'wpos_col',num,int,0)
        flag_col = treecorr.config.get_from_list(self.config,'flag_col',num,int,0)
        g1_col = treecorr.config.get_from_list(self.config,'g1_col',num,int,0)
        g2_col = treecorr.config.get_from_list(self.config,'g2_col',num,int,0)
        k_col = treecorr.config.get_from_list(self.config,'k_col',num,int,0)
        patch_col = treecorr.config.get_from_list(self.config,'patch_col',num,int,0)
        allow_xyz = self.config.get('allow_xyz', False)

        # Read x,y or ra,dec
        if x_col != 0 or y_col != 0:
            if x_col <= 0 or x_col > ncols:
                raise TypeError("x_col missing or invalid for file %s"%file_name)
            if y_col <= 0 or y_col > ncols:
                raise TypeError("y_col missing or invalid for file %s"%file_name)
            if z_col < 0 or z_col > ncols:
                raise TypeError("z_col is invalid for file %s"%file_name)
            if ra_col != 0 and not allow_xyz:
                raise TypeError("ra_col not allowed in conjunction with x/y cols")
github rmjarvis / TreeCorr / treecorr / catalog.py View on Github external
# Just read 1 row so we know how many columns there are.
        # Also will give an IO error if the file is unreadable.
        comment_marker = self.config.get('comment_marker','#')
        delimiter = self.config.get('delimiter',None)
        data = np.genfromtxt(file_name, comments=comment_marker, delimiter=delimiter, max_rows=1)
        if len(data.shape) != 1:  # pragma: no cover
            raise IOError('Unable to parse the input catalog as a numpy array')
        ncols = data.shape[0]

        # Get the column numbers or names
        x_col = treecorr.config.get_from_list(self.config,'x_col',num,int,0)
        y_col = treecorr.config.get_from_list(self.config,'y_col',num,int,0)
        z_col = treecorr.config.get_from_list(self.config,'z_col',num,int,0)
        ra_col = treecorr.config.get_from_list(self.config,'ra_col',num,int,0)
        dec_col = treecorr.config.get_from_list(self.config,'dec_col',num,int,0)
        r_col = treecorr.config.get_from_list(self.config,'r_col',num,int,0)
        w_col = treecorr.config.get_from_list(self.config,'w_col',num,int,0)
        wpos_col = treecorr.config.get_from_list(self.config,'wpos_col',num,int,0)
        flag_col = treecorr.config.get_from_list(self.config,'flag_col',num,int,0)
        g1_col = treecorr.config.get_from_list(self.config,'g1_col',num,int,0)
        g2_col = treecorr.config.get_from_list(self.config,'g2_col',num,int,0)
        k_col = treecorr.config.get_from_list(self.config,'k_col',num,int,0)
        patch_col = treecorr.config.get_from_list(self.config,'patch_col',num,int,0)
        allow_xyz = self.config.get('allow_xyz', False)

        # Read x,y or ra,dec
        if x_col != 0 or y_col != 0:
            if x_col <= 0 or x_col > ncols:
                raise TypeError("x_col missing or invalid for file %s"%file_name)
            if y_col <= 0 or y_col > ncols:
                raise TypeError("y_col missing or invalid for file %s"%file_name)
            if z_col < 0 or z_col > ncols: