rlancaste / stellarsolver

GNU General Public License v3.0
88 stars 47 forks source link

Save FITS with WCS header #109

Closed 1212Lupus closed 2 years ago

1212Lupus commented 2 years ago

Hi!

During the solving with local astrometry.net StellarSolver now useing "--new-fits none", as a result there is no new FITS file containing the WCS header in TEMP directory (.new files, as described at http://astrometry.net/doc/readme.html). Is it possible to add option in program to save new FITS with WCS hiders -- as in works at nova.astrometry.net?

rlancaste commented 2 years ago

Hi there, what is your use case exactly? If you are planning to plate solve images and then use the images with WCS headers inserted, and you are planning to use the local astrometry.net solver, then I would probably just use astrometry.net without stellarsolver. If you are using KStars, after you plate solve, the WCS information is inserted in every image it captures after that point. Is it that you are trying to use this library to process astronomical data due to its faster speed due to parallel processing and optimizations? Or is there something else?

The primary purpose of StellarSolver is to get an internal library for use of programs like KStars which just need to get the star extraction and solution information internal into the program. It is frequently used on a Raspberry Pi. The creation of all these files on something like the raspberry pi will majorly degrade the SD card, so a major goal of mine is to make as few files as possible. Another issue is that astrometry.net creates all these files in the same directory as the original image by default so that is why I make sure all the files it does make go into the temp directory so they don't pollute the original image directory.

If your goal is to process astronomical data, I have some future ideas in mind about how we could use this library in a data processing program or programs. With my library, I could easily make a program that loads a bunch of images, plate solves them, puts WCS information into their headers and then saves them all in a directory of your choosing for your future use. Would that be what you are looking for? Another idea of mine (which is a little harder) is to make a program that loads a bunch of images, does data calibration using darks, flats, and biases, does star extraction, then uses Standard Stars to calibrate the magnitudes, and then generates light curves based on the images loaded. Are one of these more like your use case?

Thanks,

Rob

1212Lupus commented 2 years ago

Rob, thank you for detailed answer.

I used astrometry.net for artificial satellite astrometry. RAW-photos from Canon I convert in FITS files (another problem, now I use ASTAP for this, although the program itself is much powerfull, but I still did not understand how to use astrometry.net in it), and after that I use StellarSolver to solve each photo. Ideally, I'd like to be able to save the file with the WCS header, because then I open this file in Alladin Sky Atlas and with WCS calibration its possible to overlay various star catalogues with filters (select required stars with B-V indexes etc.). And I can to determine the beginning/end of the satellite track with the mouse cursor (track astrometry against the background of point stars requires specialized methods and programs, I have not yet found such software in the public domain).

I would probably just use astrometry.net without stellarsolver.

Yes, but now we use Windows applications, and I'm looking for a ready-made solution without using scripts with long commands and keys :)

Is it that you are trying to use this library to process astronomical data due to its faster speed due to parallel processing and optimizations?

Standard solving time of my 4.4x6 deg photos -- 3-4 seconds in StellarSolver, it's quite fast.

With my library, I could easily make a program that loads a bunch of images, plate solves them, puts WCS information into their headers and then saves them all in a directory of your choosing for your future use. Would that be what you are looking for?

This is exactly the solution I'm looking for -- GUI for plate solving and saving new FITS files with WCS headers!

Vitaly.

rlancaste commented 2 years ago

I did add a save feature in the most recent tester program. But I am not sure yet that I have perfected all the fits header saving yet. There were other priorities at the time. You can try it to see if it works.

1212Lupus commented 2 years ago

But I am not sure yet that I have perfected all the fits header saving yet.

After solving and saving FITS hasn't WCS in header:

https://imagizer.imageshack.com/img923/9766/h7bM2n.jpg

(left -- before solving, right -- after)

P.S. By the way, EXPTIME, JD, CCD-TEMP and GAIN hiaders disappeared after saving.

rlancaste commented 2 years ago

Ok I did a bunch of work today on making a simple program that would batch solve and save the fits files with the solutions and also export the star table. It isn't perfected yet, but it already does all that. I put it in a branch and I will need to work on it some more.

For the EXPTIME, in the current code it was getting set to 1, but it shouldn't have disappeared. I have just corrected it so it should keep the original one. I will have to look at the others to see what is up with them. I suspect that the release happened and then later I added the features for the fits headers, so maybe some of that just didn't get in the build.

rlancaste commented 2 years ago

Ok, can you see if this program works for you? It is a little rough around the edges, but should plate solve a bunch of images and save both the files and star lists if you enable that option. You can also view the images too.

https://drive.google.com/file/d/1NiIll4yk5yLvrEDY7JTa7xnpF_0wwe2Q/view?usp=sharing

1212Lupus commented 2 years ago

Thank you very much!

The program works quickly, the output files with WCS:

https://imagizer.imageshack.com/img923/8485/4uyi47.png

But in Aladin Sky Atlas (https://aladin.u-strasbg.fr/) WCS don't work:

https://imagizer.imageshack.com/img922/8186/Jvp8Q1.png

Also some problems with solved FITS image -- some region is mirrored.

So far, some FITS headers disappeared, but this is not very critical.

By the way, I see WCS headers only when open FITS in text editor (like Notepad++), but not in FITS-viwer software like "fv" (https://heasarc.gsfc.nasa.gov/docs/software/ftools/fv/fv_download.html)

INITIAL FITS HEADER:


SIMPLE  =                    T / FITS header                                    
BITPIX  =                   16 / Bits per entry                                 
NAXIS   =                    2 / Number of dimensions                           
NAXIS1  =                 5202                                                  
NAXIS2  =                 3464                                                  
EXPTIME = 00000000000000000002                                                  
JD      =        2459657.29569                                                  
CCD-TEMP= 00000000000000000010                                                  
GAIN    = 00000000000000003200                                                  
DATAMAX =                16383                                                  
DATAMAX2= 00000000000000016383                                                  
DATAMAX3= 00000000000000016383                                                  
DATAMAX4= 00000000000000016383                                                  
APERTURE= 000000000000000001.4                                                  
FOCALLEN= 00000000000000000055                                                  
CAMMAKER= 'Canon'                                                               
INSTRUME= 'EOS 60D'                                                             
TELESCOP= '55-55mm'                                                             
FILT-PAT= 'GBRGGBRGGBRGGBRG'   / Filter pattern                                 
BAYERPAT= 'GBRG'               / Bayer color pattern                            
IMG_FLIP= 00000000000000000000                                                  
COMMENT raw conversion by LibRaw-with-16-bit-FITS-support. www.hnsky.org        
BZERO   =                32768 / physical_value = BZERO + BSCALE * array_value  
BSCALE  =                    1 / physical_value = BZERO + BSCALE * array_value  
DATAMIN =                    0 / Minimum data value                             
CBLACK  =                 1869 / Indicates the black point used when displaying 
CWHITE  =                 3738 / indicates the white point used when displaying 
END

SOLVED FITS HEADER:


SIMPLE  =                    T / file does conform to FITS standard             
BITPIX  =                   16 / number of bits per data pixel                  
NAXIS   =                    2 / number of data axes                            
NAXIS1  =                 5202 / length of data axis 1                          
NAXIS2  =                 3464 / length of data axis 2                          
EXTEND  =                    T / FITS dataset may contain extensions            
COMMENT   FITS (Flexible Image Transport System) format is defined in 'Astronomy
COMMENT   and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H 
BZERO   =                32768 / offset data range to that of unsigned short    
BSCALE  =                    1 / default scaling factor                         
DATAMAX2=                16383                                                  
DATAMAX3=                16383                                                  
DATAMAX4=                16383                                                  
APERTURE=                  1.4                                                  
FOCALLEN=                   55                                                  
CAMMAKER= 'Canon   '                                                            
INSTRUME= 'EOS 60D '                                                            
TELESCOP= '55-55mm '                                                            
FILT-PAT= 'GBRGGBRGGBRGGBRG'   / Filter pattern                                 
BAYERPAT= 'GBRG    '           / Bayer color pattern                            
IMG_FLIP=                    0                                                  
COMMENT = '        '           / raw conversion by LibRaw-with-16-bit-FITS-suppo
BZERO   =                32768 / physical_value                                 
BSCALE  =                    1 / physical_value                                 
DATAMIN =                    0 / Minimum data value                             
CBLACK  =                 1869 / Indicates the black point used when displaying 
CWHITE  =                 3738 / indicates the white point used when displaying
END                                                                                                                                                                    

CRPIX1  =                2601. / CRPIX1                                         
CRPIX2  =                1732. / CRPIX2                                         
SECPIX1 =     4.43844542651096 / SECPIX1                                        
SECPIX2 =     4.43844542651096 / SECPIX2                                        
CDELT1  =  0.00123290150736416 / CDELT1                                         
CDELT2  =  0.00123290150736416 / CDELT2                                         
CROTA1  =     171.821677207845 / CROTA1                                         
CROTA2  =     171.821677207845 / CROTA2                                         
DATE    = '2022-03-31T12:13:10' / file creation date (YYYY-MM-DDThh:mm:ss UT)   
END
1212Lupus commented 2 years ago

You can donload 3 my FITS for tests from here: https://cernbox.cern.ch/index.php/s/1SyENGlNsdHmPmd

1212Lupus commented 2 years ago

Also here I upload the same FITS with WCS after nova.astromerty.net solving, that correct open in Aladin Sky Atlas: https://cernbox.cern.ch/index.php/s/hXXb7Rrcz6HrGf3

Screenshot: https://imagizer.imageshack.com/img922/7003/PfEjAd.jpg

rlancaste commented 2 years ago

I studied this problem for awhile this evening. Apparently this is an issue that exists already in KStars. It is caused by the fact that KStars and now StellarSolver expected the first 10 fits headers to be the standard ones written by CFITSIO. Unfortunately your FITS headers did not have all those keywords and they were not all at the top. You had 5 of the required ones at the top, but then two more way near the bottom. So to accommodate this, I tried changing the code a bit. I actually found a couple of other issues too and I think I fixed them, so now the FITS Header should be better preserved. See if this works for you.

https://drive.google.com/file/d/1R_sGTl-9YPylUU11JrSxwJcXMp37xwLe/view?usp=sharing

1212Lupus commented 2 years ago

I uninstalled the previous version of stellarbatchsolver and installed a new one - unfortunately, the WCS don't appear in Aladin Sky Atlas:

https://imagizer.imageshack.com/img924/1302/8peXBS.png

rlancaste commented 2 years ago

Ok you were correct, my changes accidentally were copying the "END" header in the middle of the FITS header. This should fix that

https://drive.google.com/file/d/1_fA8cjuWIWAItNcOcQqNdHnW4RXEcLZ4/view?usp=sharing

1212Lupus commented 2 years ago

I tested the latest version of StellarBatchSolver on 70 FITS - everything seems to work correctly.

Rob, thank you very much for the program!

rlancaste commented 2 years ago

Very good then! I will keep working on these things, and next release I will include it.