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

feat: move slow jumps and jumpfix to so3g #1081

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

skhrg
Copy link
Member

@skhrg skhrg commented Dec 26, 2024

Relies on simonsobs/so3g#196
This is a direct rewrite for the most part, no algorithmic changes.

@skhrg skhrg requested review from kwolz and mmccrackan January 8, 2025 23:34
Copy link

@kwolz kwolz left a comment

Choose a reason for hiding this comment

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

I've looked into the changes. I have only two small comments for my ease of understanding, otherwise it looks good to me.

if isinstance(jumps, np.ndarray):
jumps = RangesMatrix.from_mask(np.atleast_2d(jumps))
elif isinstance(jumps, Ranges):
jumps = RangesMatrix.from_mask(np.atleast_2d(jumps.mask()))
if not isinstance(jumps, RangesMatrix):
raise TypeError("jumps not RangesMatrix or convertable to RangesMatrix")
jumps = cast(RangesMatrix, jumps)
Copy link

Choose a reason for hiding this comment

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

This seems redundant to me, but it probably isn't. Why?

Copy link
Member Author

Choose a reason for hiding this comment

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

Honestly that was just to make my typechecker shut up...

Copy link

Choose a reason for hiding this comment

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

Fair enough!

@@ -310,6 +311,10 @@ def test_jumpfinder(self):
heights = heights[heights.nonzero()].ravel()
self.assertTrue(np.all(np.abs(np.array([10, -13, -8]) - np.round(heights)) < 3))

# Check fixing
ptp_fix = np.ptp(fixed.ravel()[~jumps.buffer(10).mask().ravel()])
self.assertTrue(ptp_fix < 1.1*ptp_orig)
Copy link

Choose a reason for hiding this comment

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

Is this really checking the jump fixing? It seems to me this is just checking that the fixed matrix is not messed up in the places where there were no jumps in the first place...

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah so the jump fixing assumes everything within the jump range is the jump so you end up with an offset still inside the jump range (which we ignore since we gapfill those ranges anyways).
The ptp checks if we fixed because after the jump there is a DC offset that will be gone in the fixed TOD.

See below for an example (blue is before fixing, orange after):
image

If we wanted to not have the errors within the jump ranges in the fixed TOD you just need to lower the buffer size for the ranges matrix (but then your jump could be not in the range). The current range is set by the window size used for jump finding to give a reasonable margin of error.

Copy link

@kwolz kwolz Jan 13, 2025

Choose a reason for hiding this comment

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

Right, thanks for the visual explanation, the ptp matter is clear now. Just for my understanding: is jumps.buffer(10).mask() flagging the jump regions plus a buffer region covering the 10 samples before and the 10 samples after the respective jump region?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup, upped the buffer in the test to be conservative so that things never fail in CI. But also I set the PRNG key so I think that is unneeded.

Copy link
Contributor

@mmccrackan mmccrackan left a comment

Choose a reason for hiding this comment

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

I think this looks fine other than the failing checks.

@skhrg
Copy link
Member Author

skhrg commented Jan 15, 2025

simonsobs/so3g#196 is now merged so this should be good to go very soon

from scipy.sparse import csr_array
from skimage.restoration import denoise_tv_chambolle
from so3g import (
matched_jumps,
matched_jumps64,
block_minmax,
Copy link
Member

Choose a reason for hiding this comment

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

One way to create some backwards-compatibility is to not import these by name. Just import so3g. Then the code will crash when you try to use those functions, rather than when you try to import them.

As written now, everyone's installation will break, if they try to use anything from sotodlib.tod_ops, unless they've updated so3g.

@skhrg skhrg force-pushed the more_jump_speedups branch from 7aa611f to c6dc69c Compare January 30, 2025 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants