gammapy/maps/hpx.py
def _create_lookup(self, region):
        """Create local-to-global pixel lookup table."""
        if isinstance(region, str):
            ipix = [
                self.get_index_list(nside, self._nest, region)
                for nside in self._nside.flat
            ]
            self._ibnd = np.concatenate(
                [i * np.ones_like(p, dtype="int16") for i, p in enumerate(ipix)]
            )
            self._ipix = [
                ravel_hpx_index((p, i * np.ones_like(p)), np.ravel(self._maxpix))
                for i, p in enumerate(ipix)
            ]
            self._region = region
            self._indxschm = "EXPLICIT"
            self._npix = np.array([len(t) for t in self._ipix])
            if self.nside.ndim > 1:
                self._npix = self._npix.reshape(self.nside.shape)
            self._ipix = np.concatenate(self._ipix)

        elif isinstance(region, tuple):

            region = [np.asarray(t) for t in region]
            m = np.any(np.stack([t >= 0 for t in region]), axis=0)
            region = [t[m] for t in region]

            self._ipix = ravel_hpx_index(region, self._maxpix)
            self._ipix = np.unique(self._ipix)
            region = unravel_hpx_index(self._ipix, self._maxpix)
            self._region = "explicit"
            self._indxschm = "EXPLICIT"
            if len(region) == 1:
                self._npix = np.array([len(region[0])])
            else:
                self._npix = np.zeros(self.shape_axes, dtype=int)
                idx = np.ravel_multi_index(region[1:], self.shape_axes)
                cnt = np.unique(idx, return_counts=True)
                self._npix.flat[cnt[0]] = cnt[1]

        elif region is None:
            self._region = None
            self._indxschm = "IMPLICIT"
            self._npix = self._maxpix

        else:
            raise ValueError(f"Invalid region string: {region!r}")
Create local-to-global pixel lookup table.
Create local-to-global pixel lookup table.
Create local - to - global pixel lookup table .
def _create_lookup(self, region):
        if isinstance(region, str):
            ipix = [
                self.get_index_list(nside, self._nest, region)
                for nside in self._nside.flat
            ]
            self._ibnd = np.concatenate(
                [i * np.ones_like(p, dtype="int16") for i, p in enumerate(ipix)]
            )
            self._ipix = [
                ravel_hpx_index((p, i * np.ones_like(p)), np.ravel(self._maxpix))
                for i, p in enumerate(ipix)
            ]
            self._region = region
            self._indxschm = "EXPLICIT"
            self._npix = np.array([len(t) for t in self._ipix])
            if self.nside.ndim > 1:
                self._npix = self._npix.reshape(self.nside.shape)
            self._ipix = np.concatenate(self._ipix)
        elif isinstance(region, tuple):
            region = [np.asarray(t) for t in region]
            m = np.any(np.stack([t >= 0 for t in region]), axis=0)
            region = [t[m] for t in region]
            self._ipix = ravel_hpx_index(region, self._maxpix)
            self._ipix = np.unique(self._ipix)
            region = unravel_hpx_index(self._ipix, self._maxpix)
            self._region = "explicit"
            self._indxschm = "EXPLICIT"
            if len(region) == 1:
                self._npix = np.array([len(region[0])])
            else:
                self._npix = np.zeros(self.shape_axes, dtype=int)
                idx = np.ravel_multi_index(region[1:], self.shape_axes)
                cnt = np.unique(idx, return_counts=True)
                self._npix.flat[cnt[0]] = cnt[1]
        elif region is None:
            self._region = None
            self._indxschm = "IMPLICIT"
            self._npix = self._maxpix
        else:
            raise ValueError(f"Invalid region string: {region!r}")
def _create_lookup ( self , region ) : if isinstance ( region , str ) : ipix = [ self . get_index_list ( nside , self . _nest , region ) for nside in self . _nside . flat ] self . _ibnd = np . concatenate ( [ i * np . ones_like ( p , dtype = "int16" ) for i , p in enumerate ( ipix ) ] ) self . _ipix = [ ravel_hpx_index ( ( p , i * np . ones_like ( p ) ) , np . ravel ( self . _maxpix ) ) for i , p in enumerate ( ipix ) ] self . _region = region self . _indxschm = "EXPLICIT" self . _npix = np . array ( [ len ( t ) for t in self . _ipix ] ) if self . nside . ndim > 1 : self . _npix = self . _npix . reshape ( self . nside . shape ) self . _ipix = np . concatenate ( self . _ipix ) elif isinstance ( region , tuple ) : region = [ np . asarray ( t ) for t in region ] m = np . any ( np . stack ( [ t >= 0 for t in region ] ) , axis = 0 ) region = [ t [ m ] for t in region ] self . _ipix = ravel_hpx_index ( region , self . _maxpix ) self . _ipix = np . unique ( self . _ipix ) region = unravel_hpx_index ( self . _ipix , self . _maxpix ) self . _region = "explicit" self . _indxschm = "EXPLICIT" if len ( region ) == 1 : self . _npix = np . array ( [ len ( region [ 0 ] ) ] ) else : self . _npix = np . zeros ( self . shape_axes , dtype = int ) idx = np . ravel_multi_index ( region [ 1 : ] , self . shape_axes ) cnt = np . unique ( idx , return_counts = True ) self . _npix . flat [ cnt [ 0 ] ] = cnt [ 1 ] elif region is None : self . _region = None self . _indxschm = "IMPLICIT" self . _npix = self . _maxpix else : raise ValueError ( f"Invalid region string: {region!r}" )
Create local-to-global pixel lookup table.
Create local - to - global pixel lookup table .
"""Create local-to-global pixel lookup table."""
self
region