Is it possible to subtract one image in a stack from all the others?
Otherwise, is there a way to make sure two images, opened separately, are actually aligned, before doing the subtraction?
I'm interested in trying to get AIJ to be able to subtract galaxy templates, for photometry of SN. I know this is not going to be "great" - maybe some kind of PSF or other modeling is "better" - but just wanna get something better than what we do now (pretend the galaxy isn't there....).
So what I can do is take an image of the galaxy without the SN in it (say, 6 months later, all images with WCS), and load it up in a stack with the SN images. I can then align them all, and do it virtually so they are saved in their own folder. Now, I can open the aligned comparison image and create a template:
1. Determine background value
2. Copy galaxy region with the circle tool thing
3. zero out the entire image (math -> set)
4. copy the region back in.
The result looks kinda reasonable to me. But, I can't quite get the subtraction. I can't seem to subtract one image in a stack from another....I can subtract an image from an entire stack, but even when those images *were* aligned, the subtraction doesn't happen in the right place - it's the same place in every image, but the separate image is not aligned with the stack, so the subtraction isn't in the right place.
So, that's where those questions come from. Thoughts?
I think I'm following what you have tried. I think the only thing that you may need to do differently is to include the reference image maybe at the beginning or end of the stack you are wanting to subtract it from (so that it gets aligned with all of the other images). Using virtual stack is a good idea, as you have done, so that you can then deal with the images on disk, and exact the aligned reference image back out of the aligned stack folder and save it somewhere else.
Next open the aligned stack (this time in memory) and then open the aligned reference image into a different AIJ image display window.
Then use the Image_Display > Process > "Image/stack calculator" to subtract the reference image from all slices in the stack with a single subtract operation.
Let us know if we're missing something on where you are running into trouble.
Ok great, I figured it out based on what you said.
I did exactly your process (one difference to what I was doing being after creating the template, I opened the stack IN memory, instead of virtual...not sure that matters), but it still didn't work.
I thought it might be the "cut and pasting" of the region, so what I actually did this time was
1. Subtract off the background
2. Circle the galaxy
3. Choose "clear outside"
and use that as a template, and it worked! (Oh, I also did the Process -> "Image/stack calculator" in the "main AIJ window", and not the window that held either my stack or the template - not sure what you meant there, just being complete.)
I still have to work out normalizing the images first (since the galaxy brightness is different in all of them), and the fact that subtracting out the average background leaves some negative pixels in the template image - if anyone has suggestions about that, I'll take them, but my main question has been answered, thanks!
I thought I would add some here, as I've been trying to tackle this problem with no success.
The technical aspects of the image subtraction does not seem to be the problem - I found that aligning via image stabilization was better than WCS, and the virtual stack was not necessary - just saving as a stack worked fine. The creation of the template as we outlined above worked fine as well - meaning to blank out everything outside of a particular region around the galaxy.
However, the subtraction was never satisfactory because of the normalization. I tried removing the background across the entire image (typically with options "sliding paraboloid" and "disable smoothing", otherwise the background level went below zero), and then normalizing the stack, but the normalization never made sense - the brightness of the galaxy was different across the images, so the subtraction didn't work. The same appeared to be true of a few random stars I checked, and the closest I got was by individually scaling each image so the galaxy brightness was consistent - not feasible for more than a few images in the stack, although I was eventually able to extract a light curve from one particular target.
So perhaps a way to fix this would be to have options in the normalization window - scale to brightest stars, or within a set of apertures, so then you could pick what objects you wanted to have consistent brightness in the image.
Also missing in this particular task would be a way of dealing with the different seeing - I think the usual thing to do is smooth with a Gaussian to match the worst seeing in the stack, but it doesn't seem like that is possible in AIJ. I have to say, I don't know how critical this smoothing step is to this kind of task. Possibly just including the normalization option would at least open up this avenue.
So I think this remains a task for, i.e., AstroPy. Thanks for all the advice here!
If the size of the galaxy on the detector is large enough compared to the stellar PSF, maybe try forcing the sky background annulus to be restricted to within the galaxy so that the brightness of the galaxy (plus sky) will be subtracted from the pixels within the photometric aperture. Since the galaxy brightness wouldn't be perfectly smooth, the subtraction wouldn't be precise, but might be better than attempting to subtract a version of the galaxy from another image. The small background annulus size might cause more noise than would be acceptable though.