Skip to content

boss_mask_utils

multiprobe_framework.boss_mask_utils

perturb_radec(Nside, ra, dec)

An issue with Mangle is that when a ra,dec is exactly on top of a mangle pixelization line, then polyid fails. This typically happens for healpix pixels in EQU as the Mangle simple pixelization basically lies on top of some of the healpix pixel centers. This function thus slightly perturbs the given radec (typically those of the hpx center). add a random value to the ra, generated from a Gaussian with sigma = size of the hpxpixel/ 100. (From https://github.com/aurelienbl/pylib/blob/master/Man2Hpx/m_utils.py )

Source code in src/multiprobe_framework/boss_mask_utils.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
def perturb_radec(Nside, ra, dec):
    """
    An issue with Mangle is that when a ra,dec is exactly on top of a mangle
    pixelization line, then polyid fails. This typically happens for healpix
    pixels in EQU as the Mangle simple pixelization basically lies on top of
    some of the healpix pixel centers. This function thus slightly perturbs the
    given radec (typically those of the hpx center). add a random value to the
    ra, generated from a Gaussian with sigma = size of the hpxpixel/ 100.
    (From https://github.com/aurelienbl/pylib/blob/master/Man2Hpx/m_utils.py )
    """
    lensize = (hp.nside2resol(Nside, arcmin=1) / 60) / 100
    N = len(ra)

    ra_ = ra + lensize * np.random.rand(N)
    ra_ = np.mod(ra_, 360.0)

    return ra_, dec

get_hp_coord_radec(Nside, Nest)

Gets the coords of the center of Healpix pixels given a certain Nside.

Source code in src/multiprobe_framework/boss_mask_utils.py
25
26
27
28
29
30
31
32
33
34
def get_hp_coord_radec(Nside, Nest):
    """
    Gets the coords of the center of Healpix pixels given a certain Nside.
    """
    theta, phi = hp.pix2ang(Nside, np.arange(12 * (Nside**2)), nest=bool(Nest))
    theta = (np.pi / 2) - theta

    ra = (phi * 180) / np.pi
    dec = (theta * 180) / np.pi
    return ra, dec

make_mask_EQU(Mangle_File, Nside, Nest)

Converts the mangle file to a healpix map in Equatorial coordinates

Source code in src/multiprobe_framework/boss_mask_utils.py
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
def make_mask_EQU(Mangle_File, Nside, Nest):
    """
    Converts the mangle file to a healpix map in Equatorial coordinates
    """
    # 1) get the coordinates of the healpix pixels centers:
    # Apply rotation
    print("Inside the make_mask_EQ")
    # Get healpix galactic coords
    l, b = get_hp_coord_radec(Nside, Nest)

    # find corresponding celestial coords and perturb positions slightly
    ra, dec = transform_gal_to_cel(l, b)
    ra, dec = perturb_radec(Nside, ra, dec)

    # 2) Load the Mangle file:
    print("About to read the file ")
    MangMask = pm.Mangle(Mangle_File)
    print("Read the file")

    # 3) Use PolyID:
    pID = MangMask.polyid_and_weight(ra, dec)
    print("PolyID now...")

    # 4) Creates the Healpix maps:
    idx_unseen = np.where(pID[0] == -1)
    idx_seen = np.where(pID[0] != -1)

    HP_mask = np.zeros(12 * np.power(Nside, 2), dtype=float)
    print("Creating mask...")
    HP_mask[idx_unseen[0]] = hp.UNSEEN
    HP_mask[idx_seen[0]] = pID[1][idx_seen]
    print("Mask Done...")
    return HP_mask

gen(MIN, MAX)

get the Nsides

Source code in src/multiprobe_framework/boss_mask_utils.py
78
79
80
81
82
83
84
85
def gen(MIN, MAX):
    """
    get the Nsides
    """
    i = MIN
    while i <= MAX:
        yield i
        i <<= 1

unseen2zeros(mask)

Simple function to turn an input mask into a binary mask.

Parameters:

Name Type Description Default
mask

the input mask

required

Returns:

Type Description

a binary version of the input mask

Source code in src/multiprobe_framework/boss_mask_utils.py
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
def unseen2zeros(mask):
    """
    Simple function to turn an input mask into a binary mask.

    :param mask: the input mask

    :return: a binary version of the input mask
    """
    unseen = np.where(mask == hp.UNSEEN)[0]

    mask_out = mask

    mask_out[unseen] = 0

    return mask_out