Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create single-resolution maps from MOCs #37

Open
ntessore opened this issue Mar 22, 2024 · 1 comment
Open

Create single-resolution maps from MOCs #37

ntessore opened this issue Mar 22, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@ntessore
Copy link
Owner

Add a function to create single-resolution maps from MOCs, along the following lines:

def moc2map(nside, moc, uniq=False): ...

where uniq is a flag for using NUNIQ or RANGE indexing.

@ntessore ntessore added the enhancement New feature or request label Mar 22, 2024
@ntessore
Copy link
Owner Author

Here's a proof-of-concept implementation using RANGE indexing:

def moc2map(nside, moc):
    order = nside.bit_length() - 1
    max_order = 29
    shift = 2 * (max_order - order)
    if shift < 0:
        raise ValueError(f"maximum NSIDE is 2^{max_order}")
    fact = 1 << shift
    ipix, jpix = np.divmod(moc, fact)
    m = np.zeros(12 * nside**2)
    for (i1, i2), (j1, j2) in zip(ipix.reshape(-1, 2), jpix.reshape(-1, 2)):
        if i1 == i2:
            m[i1] += (j2 - j1) / fact
        else:
            m[i1 : i1 + 1] += 1.0 - j1 / fact
            m[i1 + 1 : i2 - 1] += 1.0
            m[i2 : i2 + 1] += j2 / fact
    return m

The inner loop could be done in C on an array allocated at the Python layer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant