示例#1
0
    def inFootprint(self, pixels, nside=None):
        """
        Open each valid filename for the set of pixels and determine the set 
        of subpixels with valid data.
        """
        if np.isscalar(pixels): pixels = np.array([pixels])
        if nside is None: nside = self.nside_likelihood

        inside = np.zeros(len(pixels), dtype='bool')
        if not self.nside_catalog:
            catalog_pix = [0]
        else:
            catalog_pix = superpixel(pixels, nside, self.nside_catalog)
            catalog_pix = np.intersect1d(catalog_pix, self.catalog_pixels)

        for filenames in self.filenames[catalog_pix]:
            # ADW: Need to replace with healpix functions...
            #logger.debug("Loading %s"%filenames['mask_1'])
            #subpix_1,val_1 = ugali.utils.skymap.readSparseHealpixMap(filenames['mask_1'],'MAGLIM',construct_map=False)
            _n, subpix_1, val_1 = read_partial_map(filenames['mask_1'],
                                                   'MAGLIM',
                                                   fullsky=False)
            #logger.debug("Loading %s"%filenames['mask_2'])
            #subpix_2,val_2 = ugali.utils.skymap.readSparseHealpixMap(filenames['mask_2'],'MAGLIM',construct_map=False)
            _n, subpix_2, val_2 = read_partial_map(filenames['mask_2'],
                                                   'MAGLIM',
                                                   fullsky=False)
            subpix = np.intersect1d(subpix_1, subpix_2)
            superpix = np.unique(superpixel(subpix, self.nside_pixel, nside))
            inside |= np.in1d(pixels, superpix)

        return inside
示例#2
0
文件: skymap.py 项目: kadrlica/ugali
def inFootprint(config, pixels, nside=None):
    """
    Open each valid filename for the set of pixels and determine the set 
    of subpixels with valid data.

    Parameters
    ----------
    config : config
        Configuration (file or object)
    pixels : array or int
        List of pixels to create footprint for
    nside  : int, optional
        Healpix nside
        
    Returns
    -------
    inside : array
        Boolean array of whether pixel is in footprint
    """
    logger.info("Calculating survey footprint...")

    config = Config(config)
    nside_catalog = config['coords']['nside_catalog']
    nside_likelihood = config['coords']['nside_likelihood']
    nside_pixel = config['coords']['nside_pixel']

    if np.isscalar(pixels): pixels = np.array([pixels])
    if nside is None: nside = nside_likelihood

    filenames = config.getFilenames()
    catalog_pixels = filenames['pix'].compressed()

    inside = np.zeros(len(pixels), dtype=bool)
    if not nside_catalog:
        catalog_pix = [0]
    else:
        catalog_pix = superpixel(pixels, nside, nside_catalog)
        catalog_pix = np.intersect1d(catalog_pix, catalog_pixels)

    fnames = filenames[catalog_pix]

    # Load the first mask
    logger.debug("Loading %s" % fnames['mask_1'])
    _nside, subpix1, val1 = read_partial_map(fnames['mask_1'],
                                             'MAGLIM',
                                             fullsky=False,
                                             multiproc=8)
    # Load the second mask
    logger.debug("Loading %s" % fnames['mask_2'])
    _nside, subpix2, val2 = read_partial_map(fnames['mask_2'],
                                             'MAGLIM',
                                             fullsky=False,
                                             multiproc=8)
    # Run the subpixels
    subpix = np.intersect1d(subpix1, subpix2)
    superpix = np.unique(superpixel(subpix, nside_pixel, nside))
    inside |= np.in1d(pixels, superpix)

    return inside
示例#3
0
文件: mask.py 项目: scantu/ugali-IMF
    def __init__(self, infiles, roi):
        """
        Parameters:
        -----------
        infiles : list of sparse healpix mask files
        roi : roi object

        Returns:
        --------
        mask : MaskBand object
        """
        self.roi = roi
        self.config = self.roi.config

        # ADW: It's overkill to make the full map just to slim it
        # down, but we don't have a great way to go from map pixels to
        # roi pixels.
        nside, pixel, maglim = healpix.read_partial_map(infiles,
                                                        column='MAGLIM')
        self.nside = nside

        # Sparse maps of pixels in various ROI regions
        self.mask_roi_sparse = maglim[self.roi.pixels]

        # Try to get the detection fraction
        self.frac_roi_sparse = (self.mask_roi_sparse > 0)
        try:
            logger.debug("Reading FRACDET...")
            nside, pixel, frac = healpix.read_partial_map(infiles,
                                                          column='FRACDET')
            # This clipping might gloss over bugs...
            fractype = self.config['mask'].get('fractype', 'binary')
            fracmin = self.config['mask'].get('fracmin', 0.5)
            if fractype == 'binary':
                frac = np.where(frac < fracmin, 0.0, 1.0)
            elif fractype == 'full':
                frac = np.where(frac < fracmin, 0.0, frac)
            elif not fractype:
                pass
            else:
                msg = "Unrecognized fractype: %s" % fractype
                logger.warn(msg)

            self.frac_roi_sparse = np.clip(frac[self.roi.pixels], 0.0, 1.0)
        except ValueError as e:
            # No detection fraction present
            msg = "No 'FRACDET' column found in masks; assuming FRACDET = 1.0"
            logger.info(msg)

        # Explicitly zero the maglim of pixels with fracdet < fracmin
        self.mask_roi_sparse[self.frac_roi_sparse == 0] = 0.0
示例#4
0
    def __init__(self, infiles, roi):
        """
        Parameters:
        -----------
        infiles : list of sparse healpix mask files
        roi : roi object

        Returns:
        --------
        mask : MaskBand object
        """
        self.roi = roi
        self.config = self.roi.config

        # ADW: It's overkill to make the full map just to slim it
        # down, but we don't have a great way to go from map pixels to
        # roi pixels.
        nside,pixel,maglim = healpix.read_partial_map(infiles,column='MAGLIM')
        self.nside = nside

        # Sparse maps of pixels in various ROI regions
        self.mask_roi_sparse = maglim[self.roi.pixels] 

        # Try to get the detection fraction
        self.frac_roi_sparse = (self.mask_roi_sparse > 0)
        try: 
            logger.debug("Reading FRACDET...")
            nside,pixel,frac=healpix.read_partial_map(infiles,column='FRACDET')
            # This clipping might gloss over bugs...
            fractype = self.config['mask'].get('fractype','binary')
            fracmin = self.config['mask'].get('fracmin',0.5)
            if fractype == 'binary':
                frac = np.where(frac < fracmin, 0.0, 1.0)
            elif fractype == 'full':
                frac = np.where(frac < fracmin, 0.0, frac)
            elif not fractype:
                pass
            else:
                msg = "Unrecognized fractype: %s"%fractype
                logger.warn(msg)
                
            self.frac_roi_sparse = np.clip(frac[self.roi.pixels],0.0,1.0)
        except ValueError as e:
            # No detection fraction present
            msg = "No 'FRACDET' column found in masks; assuming FRACDET = 1.0"
            logger.info(msg)

        # Explicitly zero the maglim of pixels with fracdet < fracmin
        self.mask_roi_sparse[self.frac_roi_sparse == 0] = 0.0
示例#5
0
    def loadROI(self, filename=None):
        """Load the ROI parameter sparse healpix map.

        Parameters
        ----------
        filename : input filename for sparse healpix map (default: roifile)

        Returns
        -------
        None : sets attributes: `ninterior`, `nannulus`, `stellar`
        """
        if filename is None: filename = self.roifile

        self.ninterior = healpix.read_partial_map(filename, 'NINSIDE')[-1]
        self.nannulus = healpix.read_partial_map(filename, 'NANNULUS')[-1]
        self.stellar = healpix.read_partial_map(filename, 'STELLAR')[-1]
示例#6
0
    def loadROI(self, filename=None):
        if filename is None: filename = self.roifile

        self.ninterior = healpix.read_partial_map(filename, 'NINSIDE')[-1]
        self.nannulus = healpix.read_partial_map(filename, 'NANNULUS')[-1]
        self.stellar = healpix.read_partial_map(filename, 'STELLAR')[-1]
示例#7
0
    def loadROI(self,filename=None):
        if filename is None: filename = self.roifile

        self.ninterior = healpix.read_partial_map(filename,'NINSIDE')[-1]
        self.nannulus = healpix.read_partial_map(filename,'NANNULUS')[-1]
        self.stellar = healpix.read_partial_map(filename,'STELLAR')[-1]