kammerje / spaceKLIP

Pipeline for reducing JWST high-contrast imaging data. Published in Kammerer et al. 2022 and Carter et al. 2022.
https://ui.adsabs.harvard.edu/abs/2022SPIE12180E..3NK/abstract
MIT License
16 stars 11 forks source link

[minor] stage 3 prep: consider padding before aligning #118

Open mperrin opened 11 months ago

mperrin commented 11 months ago

The example/tutorial notebook calls imageTools.align_frames before imageTools.pad_frames. I'd like to suggest flipping the order of those would better handle pixels at the edge of the array. Doing the alignment shift first results in wrapping pixels around the array from one side to the other, unphysically:

Screenshot 2023-12-12 at 10 19 40 AM

Padding before wrapping would avoid this, and thus better handle the edge pixels.

I don't see any reason not to just change the order of steps in the tutorial notebook for this? Will test this later.

This issue is relatively low priority, since the outer handful of pixels aren't the interesting area for science in general.

kammerje commented 11 months ago

At least if you want to pad with nans, then the re-centering/alignment steps will not work anymore since the SciPy functions cannot handle images with nans.

mperrin commented 11 months ago

Good point. Maybe this would have to be combined in one step that does both the alignment shift and the padding, with appropriate careful handling of the NaNs etc.

I'll set this idea aside for now. Like I said, low priority (especially compared to the other PRs!)

kammerje commented 11 months ago

We could also move away from scipy.ndimage.fftshift and use pyKLIP's nanrotate function, which can shift/rotate images with nans correctly. However, I'm not sure if it is using Fourier techniques or spline interpolation.

kammerje commented 4 months ago

@4ndyJ Marshall and I have been talking about padding and alignment a while ago. I think your current solution is already great, but I think the cleanest way to do it would be to first only compute all required shifts (using the unpadded data), then pad the data with nans, and only then apply all shifts in a final step using pyKLIP's klip.rotate function which can handle nans. This would require splitting the current spaceKLIP alignment function into separate identify_shifts and apply_shifts functions.