Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# number of subpixels in each superpixel
npix = np.array((nside_subpix // nside_superpix) ** 2, ndmin=1)
x = np.arange(np.max(npix), dtype=int)
idx = idx * npix
if not np.all(npix[0] == npix):
x = np.broadcast_to(x, idx.shape + x.shape)
idx = idx[..., None] + x
idx[x >= np.broadcast_to(npix[..., None], x.shape)] = INVALID_INDEX.int
else:
idx = idx[..., None] + x
if not nest:
m = idx == INVALID_INDEX.int
idx[m] = 0
idx = hp.nest2ring(nside_subpix[..., None], idx)
idx[m] = INVALID_INDEX.int
return idx
"""
import healpy as hp
tokens = re.split('\(|\)|,', region)
if tokens[0] == 'DISK':
vec = coords_to_vec(float(tokens[1]), float(tokens[2]))
ilist = hp.query_disc(nside, vec[0], np.radians(float(tokens[3])),
inclusive=False, nest=nest)
elif tokens[0] == 'DISK_INC':
vec = coords_to_vec(float(tokens[1]), float(tokens[2]))
ilist = hp.query_disc(nside, vec[0], np.radians(float(tokens[3])),
inclusive=True, fact=int(tokens[4]),
nest=nest)
elif tokens[0] == 'HPX_PIXEL':
nside_pix = int(tokens[2])
if tokens[1] == 'NESTED':
ipix_ring = hp.nest2ring(nside_pix, int(tokens[3]))
elif tokens[1] == 'RING':
ipix_ring = int(tokens[3])
else:
raise Exception(
"Did not recognize ordering scheme %s" % tokens[1])
ilist = match_hpx_pixel(nside, nest, nside_pix, ipix_ring)
else:
raise Exception(
"HPX.get_index_list did not recognize region type %s" % tokens[0])
return ilist
import healpy as hp
hpx_out = self.geom.to_swapped()
map_out = self.__class__(hpx_out)
idx = list(self.geom.get_idx())
vals = self.get_by_idx(idx)
msk = vals > 0
idx = [t[msk] for t in idx]
vals = vals[msk]
if self.geom.nside.size > 1:
nside = self.geom.nside[idx[1:]]
else:
nside = self.geom.nside
if self.geom.nest:
idx_new = tuple([hp.nest2ring(nside, idx[0])] + idx[1:])
else:
idx_new = tuple([hp.ring2nest(nside, idx[0])] + idx[1:])
map_out.set_by_pix(idx_new, vals)
return map_out
lon, lat = float(tokens[1]), float(tokens[2])
radius = np.radians(float(tokens[3]))
vec = coords_to_vec(lon, lat)[0]
ilist = hp.query_disc(nside, vec, radius, inclusive=False, nest=nest)
elif reg_type == "DISK_INC":
lon, lat = float(tokens[1]), float(tokens[2])
radius = np.radians(float(tokens[3]))
vec = coords_to_vec(lon, lat)[0]
fact = int(tokens[4])
ilist = hp.query_disc(
nside, vec, radius, inclusive=True, nest=nest, fact=fact
)
elif reg_type == "HPX_PIXEL":
nside_pix = int(tokens[2])
if tokens[1] == "NESTED":
ipix_ring = hp.nest2ring(nside_pix, int(tokens[3]))
elif tokens[1] == "RING":
ipix_ring = int(tokens[3])
else:
raise ValueError(f"Invalid ordering scheme: {tokens[1]!r}")
ilist = match_hpx_pix(nside, nest, nside_pix, ipix_ring)
else:
raise ValueError(f"Invalid region type: {reg_type!r}")
return ilist
from ..bayestar.sky_map import derasterize
if not m.meta['nest']:
m = m[hp.nest2ring(nside, np.arange(npix))]
m = derasterize(m)
m.meta.pop('nest', None)
if 'UNIQ' not in m.colnames:
npix = len(m)
nside = hp.npix2nside(npix)
if nest is None:
pass
elif m.meta['nest'] and not nest:
m = m[hp.ring2nest(nside, np.arange(npix))]
elif not m.meta['nest'] and nest:
m = m[hp.nest2ring(nside, np.arange(npix))]
if moc:
return m
elif distances:
return tuple(
np.asarray(m[name]) for name in DEFAULT_NESTED_NAMES), m.meta
else:
return np.asarray(m[DEFAULT_NESTED_NAMES[0]]), m.meta
for row in rows:
key, _, _, _, from_fits = row
if from_fits is not None:
m.meta[key] = from_fits(value)
if 'UNIQ' not in m.colnames:
m = Table([col.ravel() for col in m.columns.values()], meta=m.meta)
if 'UNIQ' in m.colnames and not moc:
from ..bayestar.sky_map import rasterize
m = rasterize(m)
m.meta['nest'] = True
elif 'UNIQ' not in m.colnames and moc:
from ..bayestar.sky_map import derasterize
if not m.meta['nest']:
m = m[hp.nest2ring(nside, np.arange(npix))]
m = derasterize(m)
m.meta.pop('nest', None)
if 'UNIQ' not in m.colnames:
npix = len(m)
nside = hp.npix2nside(npix)
if nest is None:
pass
elif m.meta['nest'] and not nest:
m = m[hp.ring2nest(nside, np.arange(npix))]
elif not m.meta['nest'] and nest:
m = m[hp.nest2ring(nside, np.arange(npix))]
if moc:
return m
"""
tokens = parse_hpxregion(region)
if tokens[0] == 'DISK':
vec = coords_to_vec(float(tokens[1]), float(tokens[2]))
ilist = hp.query_disc(nside, vec[0], np.radians(float(tokens[3])),
inclusive=False, nest=nest)
elif tokens[0] == 'DISK_INC':
vec = coords_to_vec(float(tokens[1]), float(tokens[2]))
ilist = hp.query_disc(nside, vec[0], np.radians(float(tokens[3])),
inclusive=True, fact=int(tokens[4]),
nest=nest)
elif tokens[0] == 'HPX_PIXEL':
nside_pix = int(tokens[2])
if tokens[1] == 'NESTED':
ipix_ring = hp.nest2ring(nside_pix, int(tokens[3]))
elif tokens[1] == 'RING':
ipix_ring = int(tokens[3])
else:
raise Exception(
"Did not recognize ordering scheme %s" % tokens[1])
ilist = match_hpx_pixel(nside, nest, nside_pix, ipix_ring)
else:
raise Exception(
"HPX.get_index_list did not recognize region type %s" % tokens[0])
return ilist