Working on script to count stars in an image

Scripts and programs to automate Astroart
Forum_2017
Posts: 275
Joined: 10 Dec 2018, 16:23

Working on script to count stars in an image

Post by Forum_2017 »

Hi
me again

when I use the following script (using simulator mode for image and guide camera)
I get no counts of stars.
If I uncomment the first 4 commands and use the find stars command on the hires.fit image
then rerun th script I get the same count as in the star table

How can I run the find stars command from a script on the image - what am I missing in my ignorant novice world!?

Code: Select all

Camera.Binning(1)
Camera.Start(1)
Camera.Wait
Image.Rename("Hires.fit")

wx, wy =  Image.FWHM
Image,Photometry
Image.Find()

Print wx
Print wy

wstars = Image.Stars.COUNT

Print wx,wy,wstars
I hope this makes some sense

Forum_2017
Posts: 275
Joined: 10 Dec 2018, 16:23

Re: Working on script to count stars in an image

Post by Forum_2017 »

Hi
just thought I might not have explained my intentions very well so here goes
Using the following basic script I would like to do something based on the number of stars. (I can explain later)

However using this code the stars count comes out as 0 for the simulator image - this should be 10

Code: Select all

Camera.Binning(1)
Camera.Start(1)
Camera.Wait

Image.SaveView("Hires.jpg")
Image.Close
Image.Open("Hires.jpg")

wx, wy =  Image.FWHM

wstars = Image.Stars.COUNT

Print wx,wy,wstars
So my issue is how to get the star table to be set up/created so the count is updated.
I am sure this is easy but can't find any examples of what or where to start!?

Have tried looking at macros which can be called from the script but see no way to use the find stars command in the macro
doh most frustrating - any help suggestions appreciated.

Forum_2017
Posts: 275
Joined: 10 Dec 2018, 16:23

Re: Working on script to count stars in an image

Post by Forum_2017 »

Hello, the function to find stars will be available in SP3 this autumn. By the way, you should have the pre-release, so the functions is:

Image.Stars.Find(10)

"Image.Stars.xxxxx" functions do work on selected stars, those marked on the image or listed in the Stars Window.
Instead, "Image.FWHM" does not work on selected stars, it operates on the whole image to find out the average FWHM of all stars.
Does this solve the problem?

Forum_2017
Posts: 275
Joined: 10 Dec 2018, 16:23

Re: Working on script to count stars in an image

Post by Forum_2017 »

Fabio
that is excellent - worked first time - as they say a little bit of knowledge is a dangerous thing
Thanks for tips re what functions scope is.

I'm really getting impressed with this software - seems to be flexible and powerful
not an easy combination to get right for software developers

many thanks

Keith

PS sorry to say I'm sure to pester you in the future as I get into this tool - keep up the great work

Forum_2017
Posts: 275
Joined: 10 Dec 2018, 16:23

Re: Working on script to count stars in an image

Post by Forum_2017 »

Hi again - didn't think i'd be back so quick but this is a follow up to the original question.
I have the following draft code which does not return what I would say is sensible data!?
As before I am using simulator for both cameras and telescope.

Code: Select all

SQREF(10,10)
'SQTest(10,10)

sub SQRef (exposure, Repeats)
  For i = 1 to Repeats
      Camera.Binning(1)
      Camera.Start(exposure)
      Camera.Wait
      Image.SaveView("Hires.jpg")
      Image.Close
      Image.Open("Hires.jpg")
      Image.Stars.Find(100)
      wx, wy =  Image.FWHM
      wstars = Image.Stars.COUNT
      Print wx,wy,wstars
      Image.Close
  next i
end sub
Typical results

0 0 40
3.904069185 3.8873353 52
3.540431023 4.141536236 43
0 0 49
0 0 50
3.973602057 4.277648926 50
4.126881599 4.441424847 50
3.688899755 3.670616627 56
3.77259922 3.825807095 39
3.621572495 4.132948875 49
0 0 65

what am I missing!? Is this an artifact of the simulator mode/timing issues/function issue !?!?

many thanks Keith

Forum_2017
Posts: 275
Joined: 10 Dec 2018, 16:23

Re: Working on script to count stars in an image

Post by Forum_2017 »

Hi, I suggest to remove the second Image.Close to find out what is happening.
Saving an image to JPEG (8 bit, compressed) and reopening it actually destroys most of the scientific content of the image, so the FWHM is probably wrong.
About the number of stars, a workaround could be to increase the Minimum S/N of detected stars (Preferences) to stop JPEG artifacts beeing detected as faint stars, or just use: Image.Find(10)

Forum_2017
Posts: 275
Joined: 10 Dec 2018, 16:23

Re: Working on script to count stars in an image

Post by Forum_2017 »

Hi thanks for reply
I have started saving files as fit - I assumme this does not destroy most of the scientific content of the image - correct me if this is wrong please.
I tried the Image.Find(10) approach again but this does not do what I require - I am after all the stars in the image above the threshhold set in the image capture.

I did find if I dont close the image I can achieve what I require - not convinced there isnt an interaction between timing and open and closing images - but as you say this may be because saving as jpeg loses data!?
I have arrived at the following draft code which appears to work

Code: Select all

MasterSQRef = 0
TestSQRef = 0
SQexp = 1
SQRpt = 3
If SQRpt <= 10 then
   SQExpRpt = 1
else
    SQExpRpt = 10
end if

MasterSQRef = SQREF(SQexp,SQRpt)
TestSQRef = SQTest(SQexp,(SQRpt/SQExpRpt))
Print MasterSQRef,TestSQRef
if TestSQRef > MasterSQREf then
   Print "Carry On Imaging"
else
   Print "Stop Imaging"
end if

sub SQRef (exposure, Repeats)
  Print " Start SQRef --> "
  Image.Close
  SQRefAvg = 0
  For i = 1 to Repeats
      Camera.Binning(1)
      Camera.Start(exposure)
      Camera.Wait
      Image.Save("Hires.fit")
      Image.Stars.Find(exposure*100)
      'Image.Stars.Find(10)
      wx, wy = Image.FWHM
      wstars = Image.Stars.COUNT
      Print i,wx,wy,wstars
      SQRefAvg = SQRefAvg+wstars
      Image.Close
  next i
  SQRefAvg = SQRefAvg/(i-1)
  Return SQRefAvg
end sub

sub SQTest (exposure, Repeats)
Print " Start SQTEST -->"
  Image.Close
  SQTestAvg = 0
  For i = 1 to Repeats
      Camera.Binning(1)
      Camera.Start(exposure)
      Camera.Wait
      Image.Save("Hires.fit")
      Image.Stars.Find(exposure*100)
      'Image.Stars.Find(10)
      wx, wy =  Image.FWHM
      wstars = Image.Stars.COUNT
      Print i,wx,wy,wstars
      SQTestAvg = SQTestAvg+wstars
      Image.Close
  next i
  SQTestAvg = SQTestAvg/(i-1)
  Return SQTestAvg
end sub
I still have a way to go but with your help will get there :-)

Forum_2017
Posts: 275
Joined: 10 Dec 2018, 16:23

Re: Working on script to count stars in an image

Post by Forum_2017 »

Hi
another clarification

the function Image.FWHM Measures image average star FWHMX and Y
and returns 2 values Wx,wy = Image.FWHM

How does this relate to FWHM measurement as mentioned in the User Manual section 9.10

What I would like to do is cv seeing from a reference set of images to a test set before doing an imageing run and
make a decision as to whether to continue or pause till better seeing

Any help/comments/insight appreciated

Forum_2017
Posts: 275
Joined: 10 Dec 2018, 16:23

Re: Working on script to count stars in an image

Post by Forum_2017 »

Have just found this in a forum entry

FWHM = sqrt(FWHMx * FWHMy)

is that correct!?

Forum_2017
Posts: 275
Joined: 10 Dec 2018, 16:23

Re: Working on script to count stars in an image

Post by Forum_2017 »

Hello, it's the same thing of chapter 9.10.

Maybe it's = Sqrt(x^2+y^2) ? By the way, I think that it does not matter. Actually I usually use the Minimum value of X and Y to evalute focus, since X can be affected by imprecise tracking:

I wouldn't pause for bad seeing, who knows, a discover could happen there, and disk space is cheap. I would choose between ending the session or not(!)

Forum_2017
Posts: 275
Joined: 10 Dec 2018, 16:23

Re: Working on script to count stars in an image

Post by Forum_2017 »

Fabio
had a think about your last reply and think if FWHMX and FWHMY are measurements of star x and y radii then a ratio of 1 is what to aim for if the star is in focus
and the closer to one the better the focus - is that a safe assumption to make!? or have I gone too far :-)

One other thing re new function inputbutton
I am using it in the following way

Code: Select all

InfoMess = "----->REFERENCE-->Number of Stars-->"+str$(GetSQRef)+crlf$()+"Star Shape Ratio-->"+str$(GetFWHMRef)+"NELM value-->"+str$(GetSQMRef)
if ContinueOn(InfoMess) = "No" then End
and

Code: Select all

sub ContinueOn(ShowInfo)
   InputButton("Carry On ?"+ShowInfo,"Yes","No")
end sub
resulting in the following
Attachment 253

I realise this is probably a no no but is there anything that can be done re spacing of the prompt -

again thanks for your assistance

Forum_2017
Posts: 275
Joined: 10 Dec 2018, 16:23

Re: Working on script to count stars in an image

Post by Forum_2017 »

Hello,
yes, FWHM is just a measurement of the radius of the star, in pixel.
A FWHM X or Y of 1 would be very bad (undersampling, ccd structure problems).

A good FWHM is usually 2.5 - 3.5. By the way, there is not an optimal FWHM.
FWHM is not so imporant, it's only a relative value, it depends mainly on the camera and telescope.

For example, if my telescope and camera gives a FWHM of 3.2 in optimal conditions, and one day I get 4.5, this only means that I'm not working in optimal conditions (bad seeing? bad focus?). It's all relative.
For photometry, a higher FWHM would be even desirable.

Post Reply