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

gh-272: add tests for glass.points #372

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

Saransh-cpp
Copy link
Member

@Saransh-cpp Saransh-cpp commented Oct 16, 2024

Add tests and bump coverage to ~97 for glass.points.

Closes: #272

@Saransh-cpp Saransh-cpp added the maintenance Maintenance: refactoring, typos, etc. label Oct 16, 2024
@Saransh-cpp Saransh-cpp self-assigned this Oct 16, 2024
@Saransh-cpp Saransh-cpp marked this pull request as ready for review October 17, 2024 13:59
@Saransh-cpp
Copy link
Member Author

I can't seem to hit the following lines -

glass/glass/points.py

Lines 227 to 230 in c020f18

if size + q[-1] < min(batch, count):
# no, we need the next group of pixels to fill the batch
stop += step
size += q[-1]

@ntessore do you have a specific case in mind that'll hit these lines. Every combination of arguments I have tried results in q[-1] == count, size is always 0, and putting these values in, it does not matter what batch is, the condition is never met.

tests/test_points.py Outdated Show resolved Hide resolved
@ntessore
Copy link
Collaborator

@ntessore do you have a specific case in mind that'll hit these lines. Every combination of arguments I have tried results in q[-1] == count, size is always 0, and putting these values in, it does not matter what batch is, the condition is never met.

Ah, good catch. The reason is that the batching processes 1000 pixels at a time, but we are using HEALPix maps with only 12 pixels as inputs.

Solution: use a higher number of pixels (npix) and replace all uses of 12 with npix, and add another case where some of the visibility is zero (hence it needs many batches of empty pixels until it finds enough points).

def test_positions_from_delta():  # type: ignore[no-untyped-def]

    # create maps that saturate the batching in the function
    nside = 128
    npix = 12 * nside**2

    # case: single-dimensional input

    ngal = 1e-3
    delta = np.zeros(npix)
    bias = 0.8
    vis = np.ones(npix)

    ...

    # case: only the southern hemisphere is visible

    vis[:vis.size//2] = 0.0

    lon, lat, cnt = catpos(positions_from_delta(ngal, delta, bias, vis))  # type: ignore[no-untyped-call]

    assert cnt.shape == (3, 2)
    assert lon.shape == (cnt.sum(),)
    assert lat.shape == (cnt.sum(),)

@Saransh-cpp
Copy link
Member Author

Saransh-cpp commented Oct 18, 2024

I see, thanks for the detailed suggestion, @ntessore! I will apply this to the tests.

Copy link
Member

@paddyroddy paddyroddy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change the upstream to #368 and fix the typing here?

@Saransh-cpp Saransh-cpp changed the base branch from main to paddy/issue-358 November 5, 2024 11:46
Base automatically changed from paddy/issue-358 to main November 7, 2024 10:32
# case: negative delta

lon, lat, cnt = catpos(
positions_from_delta(ngal, np.linspace(-1, -1, 196608), None, vis)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not npix here and below?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, updated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Maintenance: refactoring, typos, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add/review tests for glass.points
3 participants