Rachmanin0xFF / jwst-twitter-bot

Auto-process and upload JWST images to Twitter
22 stars 4 forks source link

align filters to each other #2

Open yuval-harpaz opened 1 year ago

yuval-harpaz commented 1 year ago

In order to get colored images composed of multiple filters images should be aligned. The task can be divided into two parts: detecting bad alignment, and correcting the issue. We may want the bot simply to avoid using badly aligned layers and stop there, no fixing. In order to proceed with this issue I applied an old code that I wrote for this on a badly aligned set of filters from SDSSJ1723+3411.
the function optimize_xy (see here) takes two layers, and shifts one layer N times each way (up, down, left, right). every time matrices are flattened, then Pearson's correlation is computed. The best shift is then reported as best x (0, 3, 3 for this example) and best y (0, 0, -1). for these three layers, red stays with 0 x and 0 y (because it is the reference), blue and green got to move 3 pix on x, and there is y shift of one pixel for blue only. image

yuval-harpaz commented 1 year ago

Since correlation is costly, I tried another approach. I find star centers using clustering and maximum value per cluster. I consulted with chatGPT about it so I called the function maxima_gpt. I later match stars on different filters and find the common shift. results are similar, however the clustering requires smoothing that might be costly again. see optimize_xy_clust, also in astro_utils. So we got two approaches that work more or less, in order to proceed I think we should check them on different targets, test memory efficiency, accuracy, and adjust parameters.

yuval-harpaz commented 1 year ago

I now face a dataset (NGC 5068) where the alignment changes midpicture. I can match some stars in different layers and estimate the necessary shift for each star. I'd like to take the median shift and apply it to the whole image but there is a shift zero for the top part and 6 pixels for the bottom half. The estimated glitches are plotted as green lines. image