New SHG (spectroheliography) software available now for testing

The place for all your solar software; capture, stacking, post processing, ancillaries etc. It's all up for discussion here!
Post Reply
thesmiths
Im an EXPERT!
Im an EXPERT!
Posts: 302
Joined: Mon Jun 04, 2012 8:13 pm
Has thanked: 7 times
Been thanked: 124 times

New SHG (spectroheliography) software available now for testing

Post by thesmiths »

Dear Spectroheliographers:

The Smiths (I and my college student son) have just pushed an English language version of Valerie's Solex_ser_recon software to our GitHub:

https://github.com/thelondonsmiths/Solex_ser_recon_EN

Our version has more flexibility in switching between automatic and manual geometric corrections; and turning off and on which files are to be saved. It is also significantly faster -- generally 5x and sometimes 10x faster, depending on the data.

The GUI is quite simple and is shown in the screenshot below:

GUI for SHG software
GUI for SHG software
SHG GUI.JPG (38.25 KiB) Viewed 252 times
Simply chose the file or files to be processed. Batch processing is allowed; the program will execute each file sequentially.

The check box "Show images" shows the frame-by-frame construction of the image and is quite interesting to watch (at least the first few times). The final image files also pop up briefly and give a glimpse of the result. In general, it's better to not check this box as it increases the processing time.

All the intermediate files can be saved in FITS format if the "Save .fit files" box is checked. In general, I have not found these files to be essential but they are interesting to examine (at least initially) to understand the processing steps the programme takes. Normally, I keep this box unchecked.

The program creates a final series of pre-processed PNG images with varying contrast and brightness. One of them (with the suffix _protus) has the brightness boosted to show the presence of prominences. The file (with the suffix _clahe) on which the programme has performed "Contrast Limited Adaptive Histogram Equalization" shows the most generally useful image. Therefore, there is an option to only have the program save the CLAHE file. This is very useful in the situation during acquisition where a quick view of a single reconstructed image helps improve the observational parameters.

The original program from Valerie would try to do a circularization of the image and would often fail if a full (or almost full) disk was not visible. Our version allows a manual override to input an "Y/X ratio" corresponding to over sampling (Y/X < 1) or under sampling (Y/X > 1). Normally, the frame rate (FPS) should be high enough to generate sufficient horizontal lines to match the number of pixels in the vertical direction. If the FPS is too low vs the scanning rate (in sidereal rate), then Y/X should be set greater than 1. If the scanning rate is too low versus the FPS, then Y/X should be set less than 1. If the box is left blank, the programme will attempt to figure out the correct ratio.

The "Slant angle" is to correct for the geometric error when the SHG slit is not perfectly perpendicular to the scanning direction. The program will typically do a good job of calculating this if the Y/X ratio is approximately correct. So I find a common situation is the one shown in the GUI above where the Y/X ratio is manually inputted and the slant angle is allowed to run in auto mode. If the image comes out looking obviously wrong, then it's best to put in a slant angle of zero to turn off the feature.

The program takes an average over many frames to create a "mean" spectral line (saved as the _mean FITS file). It then makes a polynomial approximation to this line (as there is typically some tilt and curvature to the line due to distortions in the system). It then finds the darkest segment in this line and assumes this is the wavelength of interest. The "Pixel offset" box allows displacing the measurement to examine slightly longer or shorter wavelengths (to look at, for example, Doppler shifts). With a large displacement, the image will look like "white light".

Below is a jpg version of the CLAHE file created by the program from a 2.83GB (2890 frame) SER file. Not additional processing of the PNG output file was done, only a resize and conversion to jpg. The data was taken with my "foam board SHG" with an ASI 178MM using FireCapture 2.7beta. The frame rate was 153 FPS while the scanning rate was 8x sidereal rate. This resulted in significant undersampling so the Y/X ratio was set to 1.5 (this ratio can be calculated approximately a priori). The program did a fairly good job of find the correct slant angle. In general, the slant angle can be reduced to near zero with careful experimental technique. Good technique would attempt to have the Y/X ratio to be around 0.8 or so.

final CLAHE image
final CLAHE image
160451_clahe.jpg (172.23 KiB) Viewed 278 times
The total time to process the SER file into the final image was about 6 seconds. Valerie's original code was sped up by a factor of 5-10x using simple but clever use of the vectorisation functions in the NumPy library. The two time consuming processes turned out to be the image construction (as might be expected) and the slant correction (less obvious).
Last edited by thesmiths on Thu Jul 15, 2021 1:55 am, edited 3 times in total.


thesmiths
Im an EXPERT!
Im an EXPERT!
Posts: 302
Joined: Mon Jun 04, 2012 8:13 pm
Has thanked: 7 times
Been thanked: 124 times

New SHG (spectroheliography) software -- output log file

Post by thesmiths »

The program also saves a _log file in .txt format. This contains the inputted and calculated parameters, along with some specialised coefficients that can be used in further processing steps. The _log data for the image above is shown below:
Width, Height : 2504 200
Number of frames : 2890
Vertical limits y1, y2 : 253 1970
Coeff A0, A1, A12 : -1.6441816823180675e-05 0.010860624121223376 119.08128171220991
X-position of left and right solar limb, x1, x2 : 131 2570
Y-position of top and bottom solar limb, y1, y2 : 1482 1247
Centre of circle x0, y0 and diametre : 2025 1482 2218
Ratio Y/X : 1.500
Slant angle : +3.87 degrees
Last edited by thesmiths on Thu Jul 15, 2021 12:48 am, edited 1 time in total.


thesmiths
Im an EXPERT!
Im an EXPERT!
Posts: 302
Joined: Mon Jun 04, 2012 8:13 pm
Has thanked: 7 times
Been thanked: 124 times

New SHG (spectroheliography) software -- installation procedure

Post by thesmiths »

The README file in the GitHub contains an explanation how to install and run the program. The program was originally written by Valerie in Python, which is not an entirely straightforward environment.
Solar disk reconstruction from SHG (spectroheliography) SER files
Install the most recent version of Python from python.org. During Windows installation, check the box to update the PATH.
For Windows, double click the windows_setup file to install the needed Python libraries.
Usage: launch SHG_MAIN (by double clicking under Windows).
The windows_setup batch file installs the necessary Python libraries automatically:
pip install scipy
pip install matplotlib
pip install PySimpleGUI
pip install astropy
pip install opencv-python
The easiest way to run the program is to create a desktop shortcut of SHG_MAIN and double click on the shortcut when you want to run the program [right mouse button, Send to --> Desktop (create shortcut)].


thesmiths
Im an EXPERT!
Im an EXPERT!
Posts: 302
Joined: Mon Jun 04, 2012 8:13 pm
Has thanked: 7 times
Been thanked: 124 times

New SHG (spectroheliography) software -- improvements and future features

Post by thesmiths »

There a no known "bugs" but if you find any, please send me a Private Message. Valerie's code went through a few iterations so appears to be quite stable.

I translated most of the output messages into English but don't be surprised by the rare instance of a message in French.

I would like to implement a feature to specify the destination folder for the output files (currently they are saved to the same folder as the input file).

There is currently no way to change the "bandwidth" of the image reconstruction -- the default is two pixels. It may be useful to add the option for larger bandwidths, although generally speaking, the best looking images are ones with the smallest possible bandwidth.


thesmiths
Im an EXPERT!
Im an EXPERT!
Posts: 302
Joined: Mon Jun 04, 2012 8:13 pm
Has thanked: 7 times
Been thanked: 124 times

New SHG (spectroheliography) software -- final example

Post by thesmiths »

To conclude, here is an example with a shorter focal length telescope (480mm vs 700mm). In this case, the FPS (which was about the same in both cases, around 155 FPS), was a much better match to the scan rate (in both cases, 8x sidereal). Since 700/480 = 1.46, the Y/X ratio this time was close to 1. The misorientation of the instrument versus the scan direction was also much less so the slant angle was small (0.5 degree vs almost 4 degrees previously).

SHG UI
SHG UI
SHG UI.JPG (42.5 KiB) Viewed 246 times
480mm final CLAHE image
480mm final CLAHE image
170116_clahe.jpg (96.42 KiB) Viewed 246 times
Here is the _log file showing the parameters. The program took slightly more than 5 seconds to produce the fully processed image.
Vertical limits y1, y2 : 426 2145
Coeff A0, A1, A12 : -1.6642423389558653e-05 0.00905936321842637 135.6015848430828
Width, Height : 2504 200
Number of frames : 2916
X-position of left and right solar limb, x1, x2 : 243 2710
Y-position of top and bottom solar limb, y1, y2 : 1308 1328
Centre of circle x0, y0 and diametre : 1550 1308 1782
Ratio Y/X : 1.050
Slant angle : -0.53 degrees


thesmiths
Im an EXPERT!
Im an EXPERT!
Posts: 302
Joined: Mon Jun 04, 2012 8:13 pm
Has thanked: 7 times
Been thanked: 124 times

New SHG (spectroheliography) software -- feedback from Valerie

Post by thesmiths »

The author of the original code on which ours is based has tested our version and given it the stamp approval:
valerie desnoux

To the Smiths family… this is brilliant !!

The improvement using vectors for the line intensity extraction is incredible. It illustrates the Python rule I’m relearning every day, “no for loop”, and the power of arrays in NumPy.

Really impressive.

Soon I will release a new version which will include your code and also a change to have an automatic scaling even with a partial disk, using ellipse fitting.

Big bravo

Valerie


mconsidine
The Sun?
The Sun?
Posts: 17
Joined: Sun Aug 21, 2016 10:57 pm
Been thanked: 1 time

Re: New SHG (spectroheliography) software available now for testing

Post by mconsidine »

Hi,
Thanks for the updates on this code. I've got an ellipse fitting routine in R that was doing the calcs for me for input into ISIS. I could send that, but if Valerie is working on ellipse fitting already that may not make sense.

Do you have the settings file from the ZWO run that you could post for the SER file that you used as an example? I get the 155 FPS metric, but I was wondering if that reflects exposure rate or interval?

I have Valerie's python code running on my own machine, so it will be straightforward to have yours running too. Me and my friend Dave Groski, along with Jim Daley, are working on getting better imaging done with a 1930's Hale-style spectrohelioscope that we have installed at Stellafane.

Best regards,
Matt

PS How did you estimate that you had oversampled your video?


mconsidine
The Sun?
The Sun?
Posts: 17
Joined: Sun Aug 21, 2016 10:57 pm
Been thanked: 1 time

Re: New SHG (spectroheliography) software available now for testing

Post by mconsidine »

By the way, I can confirm your code runs as expected on a Linux Mint laptop...
Matt


mconsidine
The Sun?
The Sun?
Posts: 17
Joined: Sun Aug 21, 2016 10:57 pm
Been thanked: 1 time

Re: New SHG (spectroheliography) software available now for testing

Post by mconsidine »

An example of taking the output, cutting out the disk and rebalancing the image to get at the proms, which would otherwise be underexposed.
Matt
Image
Attachments
16_33_15_clahe_proms.png
16_33_15_clahe_proms.png (2.54 MiB) Viewed 173 times


thesmiths
Im an EXPERT!
Im an EXPERT!
Posts: 302
Joined: Mon Jun 04, 2012 8:13 pm
Has thanked: 7 times
Been thanked: 124 times

Re: New SHG (spectroheliography) software available now for testing

Post by thesmiths »

Hi Matt, the program actually will create a PNG file called _protus where the levels are set to view prominences. This file is, of course, only written if the box "Save CLAHE image only" is unchecked. This is what it looks like (with no further processing) for the SER file above:

PNG _protus file
PNG _protus file
170116_protus.jpg (64.66 KiB) Viewed 169 times
Paul (PDB) has confirmed the code runs on Ubuntu with minimal problems.

With regards to over sampling vs under sampling, you need to do the following calculation. The diameter of the Sun on the slit will be approximately the focal length of telescope in mm divided by 109. This diameter will be magnified by the ratio of the camera lens to the collimator lens when it projects on the sensor. Divide this projected diameter by the pixel size. For example, 480/109 x 125/80 =6.88mm. Assuming 2.4 micron pixel size implies the solar diameter along the slit will be 2867 pixels.

In the scanning direction (perpendicular to the slit direction), you need to calculate the time it takes to scan across the solar diameter and multiply this by the FPS to get the number of images of the spectral line that will be acquired. For example, if the scanning speed is 8x sidereal rate, the time to scan across the solar diameter will be approximately 120/8 = 15 seconds. If the camera is taking 200 FPS, then the number of images will be 3000, so there will be a slight over sampling (which is preferred) and the Y/X ratio will be around 2967/3000 = 0.96.


mconsidine
The Sun?
The Sun?
Posts: 17
Joined: Sun Aug 21, 2016 10:57 pm
Been thanked: 1 time

Re: New SHG (spectroheliography) software available now for testing

Post by mconsidine »

Hi,
Thanks for the reply. Yes, I've seen the prom output but believe it can be improved. I'll post a pull request for the code tomorrow. The circle/ellipse fitting can be better,but I'll hold off on that since Valerie's seems to be working on it.

I am working with a non-SolEx instrument, fwiw. And as I understand it, the AVI standard does not incorporate 16 bit images. Which leaves you with - in this case - SER as the available format that yields the best quality. However, they are not hard to read in other software, eg R, which is what I am working on a port of the code for.

Matt


User avatar
Merlin66
Librarian
Librarian
Posts: 3726
Joined: Tue Dec 13, 2011 1:23 pm
Location: St Leonards, Australia
Has thanked: 50 times
Been thanked: 148 times
Contact:

Re: New SHG (spectroheliography) software available now for testing

Post by Merlin66 »

Matt, et al,
The SimSpec SHG spreadsheet may help to clarify the possible/ probable outcome of various collimator/ imaging lens and slit widths combined with different camera chip and pixel sizes.
I attach two versions - the general version and one setup for the Sol'Ex parameters.
SimSpec SHG V1_3.xls
(60 KiB) Downloaded 3 times
SimSpec SHG V1_3_solex.xls
(60 KiB) Downloaded 2 times


"Astronomical Spectroscopy - The Final Frontier" - to boldly go where few amateurs have gone before
https://groups.io/g/astronomicalspectroscopy  
http://astronomicalspectroscopy.com
"Astronomical Spectroscopy for Amateurs" and
"Imaging Sunlight - using a digital spectroheliograph" - Springer
mconsidine
The Sun?
The Sun?
Posts: 17
Joined: Sun Aug 21, 2016 10:57 pm
Been thanked: 1 time

Re: New SHG (spectroheliography) software available now for testing

Post by mconsidine »

Hi,
Thanks for the spreadsheet. On your other question, I think the AVI spec only handles 8-bit and not 16-bit, which is why I suspect ZWO offers both formats, but only SER if you want to save 16-bit.

I'll try to get a pull request set up in a few hours for an improved prom image, rather than the current blown out one.

Matt


thesmiths
Im an EXPERT!
Im an EXPERT!
Posts: 302
Joined: Mon Jun 04, 2012 8:13 pm
Has thanked: 7 times
Been thanked: 124 times

Re: New SHG (spectroheliography) software available now for testing

Post by thesmiths »

I discovered in our initial version of the program, there was a bug such that the "pixel offset" was not working correctly -- in fact not working at all! It is now fixed (I think) and gives varying images depending on the numerical value of the pixel offset.

There is also now a line in the _log file which specifies what the pixel offset was. Also, a minor bug where a few lines in the _log were duplicated has been corrected.

For the pixel offset, there is no additional suffix added to the files (this would be preferred, of course). So you must be careful about overwriting files. Unfortunately, at the moment, this requires moving the output files into a subfolder (e.g. 0, +5, -5) in order to not be overwritten. The _log file will also be overwritten so you need to move that also. A typical _log file is shown below:
Using pixel shift: 5
Width, Height : 2200 80
Number of frames : 4461
Vertical limits y1, y2 : 33 2030
Coeff A0, A1, A12 : 1.8300459068268992e-05 -0.0492757269337263 55.958269734463585
X-position of left and right solar limb, x1, x2 : 552 4137
Y-position of top and bottom solar limb, y1, y2 : 740 1058
Centre of circle x0, y0 and diametre : 1487 740 2274
Ratio Y/X : 0.634
Slant angle : -7.98 degree


User avatar
Merlin66
Librarian
Librarian
Posts: 3726
Joined: Tue Dec 13, 2011 1:23 pm
Location: St Leonards, Australia
Has thanked: 50 times
Been thanked: 148 times
Contact:

Re: New SHG (spectroheliography) software available now for testing

Post by Merlin66 »

Doug,
Found a SER SHG file to trial the updated version of INTI.
Whoooo!!
It certainly does what it says on the box. Lightning fast, and very capable.
I’m impressed.
Previous comments about viewing the intermediate image files are correct; the ability to “click” to move from one to another would be a good addition.
Next opportunity I’ll change over to SER files and continue to evaluate INTI.


"Astronomical Spectroscopy - The Final Frontier" - to boldly go where few amateurs have gone before
https://groups.io/g/astronomicalspectroscopy  
http://astronomicalspectroscopy.com
"Astronomical Spectroscopy for Amateurs" and
"Imaging Sunlight - using a digital spectroheliograph" - Springer
thesmiths
Im an EXPERT!
Im an EXPERT!
Posts: 302
Joined: Mon Jun 04, 2012 8:13 pm
Has thanked: 7 times
Been thanked: 124 times

Re: New SHG (spectroheliography) software available now for testing

Post by thesmiths »

Valerie has incorporated our speed up technique into her newest version on her GitHub and included a better way to convert an ellipse into a circle. There are a few bugs still in the way the ellipse conversion works, which I have pointed out to her. Once she gets that ironed out, I will probably update our code as well to keep the two versions more or less parallel (her version remains with a French UI). Her version also currently does not deal with "edited" SER files (for example, it you cut a longer file into smaller segments) but I pointed out to her how to get around that (since I often take a double scan then create a pair of single scan files using SER Player).


mconsidine
The Sun?
The Sun?
Posts: 17
Joined: Sun Aug 21, 2016 10:57 pm
Been thanked: 1 time

Re: New SHG (spectroheliography) software available now for testing

Post by mconsidine »

FWIW, I'll be putting the finishing touches on a version of Valerie's code that also handles AVI files. The quality of the result is not great, given the lower bit depth. But I've put the initial code up on github in the event anyone wants to get a taste of the output. One caveat is that it runs into problems with the current approach to ellipse fitting (to avoid this and viewed the skewed images, set the ratio to 1 or some number that makes sense that is not 0). I'll be taking a different approach on that fitting issue, which will hopefully be satisfactory.
Matt
https://github.com/mconsidine/Solex_ser_recon_AVI


mconsidine
The Sun?
The Sun?
Posts: 17
Joined: Sun Aug 21, 2016 10:57 pm
Been thanked: 1 time

Re: New SHG (spectroheliography) software available now for testing

Post by mconsidine »

The code that I posted on github has now been fixed to deal with the remaining AVI issue. (Turns out I missed some hardcoded values, which work nicely for 16bit data but not-so-nicely for 8bit data).

Matt


Post Reply