How to take advantage of distortion correction info on stacking substacks

Oops, accidentally hit delete on the last post attempt:

I use a script that stacks my data into chuncks (about 100 at a time) to create “sub-stacks”. I then stack these substacks with a final stacking program that understands that these are now debayered 32-bit RGB Fits.

Here is a snippet of the code that uses platesolving for creating of a single substack:

#platesolve the lights
seqplatesolve pp_light1 -disto=distortionFile

# Align lights
# First doing: register pp_light1 -2pass -nostarlist
register pp_light1   -2pass -nostarlist -disto=file ./distortionFile
# Now doing: seqapplyreg pp_light1 -framing=max
seqapplyreg  pp_light1 -framing=max

This works well, The question is, how do I take advantage of the distortion information in the .FITS header when I stack these substacks together.

If I do nothing, I get this note in the console:

12:57:12: Processing all images in the sequence (87)
**12:57:12: Distortion was found in reference image astrometry but you did not include distortion correction when registering the images**
12:57:12: Apply registration: with the current memory and thread limits, up to 27 thread(s) can be used

So it sees the distortion information, but if I put this in my stacking command line:

# Align lights
# First doing: register
register pp_light -2pass -disto=image -nostarlist
# Now doing: seqapplyreg pp_light -framing=max
seqapplyreg  pp_light  -framing=max

It says:

13:01:46: You have selected undistortion from current image but it is not platesolved, perform astrometry first or disable distortion
13:01:46: Error in line 25 (‘register’): invalid arguments.

Do I need to re-platesolve these substacks? I tried but it says they are already platesolved so it creates no distortion file and that then also fails.

How do I accomplish distortion correction using the platesolving that is done on these substacks? I see in the .FITS header it appears to have all the distortion information.

Hello steven,

if you undistort the first sequence pp_light1_, the distortion information should be gone in the images r_pp_light1_ (because they’ve been undistorted when being mapped for the alignment). So your process is correct, you should not undistort twice.

So I’m not sure why it detects distortion again when you gather the substacks in pp_light sequence. In particular the contradiction between we found distortion that you should apply and then there's no distortion in the reference image.
Can you try a command disto on an image of r_pp_light1_ and on your r_pp_light1_ stacked image, just to check the outputs in the console?

BTW, when you paste code here, in particular snippets of scripts, could you knidly enclose those code blocks between ```, Otherwise they get interpreted as markdown which is not good for readability…
Cheers,

Cecile

Thanks for taking a look at this Cecile.

Just so I make sure I conduct the correct test for you, I’ll restate what you want and you can tell me if I’m on the right track:

  1. First you want me to restack one of my “substacks” which I do with platesolving and then you want me to check one of my original registered lights used in this substack with the disto command.

  2. Also you want me to run disto on the resulting substack itself AFTER it is registered against the other substacks.

Did I get this right?

Finally, you noted " In particular the contradiction between we found distortion that you should apply and then there's no distortion in the reference image ."

However, I don’t actually see the console output that says “there’s not distortion in the reference image” in the quotes I gave you but perhaps I’m just not seeing it.

  • Steven

You’re right, it’s not written in your lines, it’s just me doing guess work. I’m assuming that you’ve loaded your substacks as a sequence (so it loads the reference image of this sequence) and then your log says:

13:01:46: You have selected undistortion from current image but it is not platesolved, perform astrometry first or disable distortion

Which is why I’ve have assumed the reference image was not platesolved.

Ok, now to solve your problem, could you share a small folder with 4 images and a mini script that:

  • register/stack the first 2
  • register/stack the other 2
  • register/stack the 2 substacks

In the mini-script, I need exactly all the commands you invoke to do that.
I’m busy with work the next days but I’ll try to get back to you next week-end

Cheers,

Cecile

Hi Cecil,

So I have a mini set of data with 2 biases, 2 flats, (no darks), 2 lights for set 1 and 2 lights for set 2 already placed in the directory structure starting with the main directory called “JobDir”

I have the script that stacks the data, but note the script expects this directory to be hard coded as “D:/AstroCapture/Deepsky/JobDir”, so you can modify the script as it’s one of the first lines that CDs to it (actually to the Biases subdirectory).

The second script just stacks the substacks and expects them to be in a “lights” directory with no calibration files.

It’s in a .ZIP compressed directory. You’ll see all of the image files are RICE compressed (I have NINA use RICE compression) and the exposure times are very short and, given the target isn’t too bright, they have very low SNR.

I’ve also included the console output produced on my system when I run each script.

  • Steven

I meant Cecile, sorry.

Hi Steven,

had some time to look at your images and scripts. In your second script, you are trying to undistort again images which have already been “flattened” in your first script. You can see quite clearly in a substack, the black borders are the result of the undistortion (showing substack_ByNoise_F40_N1.fit):

We can see in the logs as well, the undistortion was successfully applied:

11:18:11: Distortion data was found in the sequence file, undistortion will be applied

As your sequence was platesolved, an astrometric solution was copied over into the registered images and finally to the stacked image. And because you asked to undistort, the astrometric solution that got into your stack is the solution of the reference image with the distortion part removed.

So each substack is now platesolved (with no distortion term). When in the second script, you ask for a seqplatesolve, even though you ask specifically for a distortion file, none could be created because:

  • it skips platesolved images (and all your substacks are platesolved)
  • None of the substacks had a distortion part anyway

So when you ask to use this distortion for the alignment, it fails because the distortion file does not exist:

13:49:01: FITS error: ./distortionFile
13:49:01: Could not load FITS image for distortion

Ok, so my first answer would be, you are trying to undistort twice, just don’t. But then, it triggers another comment, you’re extensively using seqplatesolve but you don’t take advantage of going through the hassle of platesolving. A valid second script could look like:

#calibrate lights
cd SubStacks
convert light -out=../processall
cd ../processall
calibrate light

#platesolve the lights
# They are not platesolved as such as they already were (they will be skipped)
# This step just collects their astrometric solutions and compute registration from that info
seqplatesolve pp_light

#and align with astrometry
seqapplyreg  pp_light -framing=max

#stack calibrated lights
stack r_pp_light rej 3 3 -maximize  -weight=noise -norm=addscale -feather=140 -out=../result

cd ..
close

It’s really important to inderstand that seqplatesolve is in itself a valid alignment method (just like register is). So after a seqplatesolve, you can directly shoot a seqapplyreg command.

This remark also extends to your first script. After seqplatesolve, don’t make a 2-pass alignment, because platesolving already did that. You don’t even need to save a distortion file, because each file holds its own distortion term. Just go straight to seqapplyreg.

And actually this goes even further… Why making all these substacks as a single script which:

  • calibrates all your lights (not one folder after the other, all of them into one single light folder)
  • seqplatesolve them (computes each distortion and registration in one go, even if they are far apart, that’s the beauty of using astrometry to register)
  • seqapplyreg to max
  • stack

Would do the job.
Your workflow is very similar to that of a smart telescope in fact, you can have a look at this part of the tutorial on mosaics: Siril - Mosaics
Use feathering during stack to reject the part where the images are very noisy (your flats go almost to zero on the borders…) and you should be done in one go.
Your images could also probably use a seqsubsky command which goes like seqsubsky sequencename 1 to remove the light polution gradient right after calibration.

Cheers,

Cecile

1 Like

Your changes worked like a charm, thank you!

Yes, my flats go almost to zero because I use a full frame camera with the Nexus Starizona reducer/corrector on my Newtonian and it’s designed for only an APS-C sized sensor, so I crop about 20% of the long edges, but I still get nearly 2x the FOV with the full frame, so it’s worth the complexity if I need the additional FOV.

Cheers,

Steven