Author Topic: Return star array from StarDetector  (Read 5296 times)

Offline dave_galera

  • PixInsight Addict
  • ***
  • Posts: 261
    • QDigital Astro
Return star array from StarDetector
« on: 2020 January 17 12:48:45 »
I am trying to get the background for stars as derived from StarDetector but only the pos, radius and flux are being return in the array as per this example:

{"position":{},"radius":4,"flux":0.01169074873905629}

It seems as if bkg is not available for some reason using the following code:

var barycenters = new Array;
var stars = starDetector.stars(imageWindow.mainView.image);
.
.
.
barycenters.push({
                  position: stars.pos,
                  radius: Math.max(3, Math.ceil(Math.sqrt(stars.size))),
                  flux: stars.flux,
                  bkg: stars.bkg
               });

Has anybody any ideas why this element should not present in the array?

PS, This question was originally posted in general
Dave

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: Return star array from StarDetector
« Reply #1 on: 2020 January 18 10:46:11 »
Hi Dave,

The Star object, which is defined in the standard pjsr/StarDetector.jsh file, only provides pos, flux and size properties. Here is an excerpt of code starting in line #104 of StarDetector.jsh:

Code: [Select]
function Star( pos, flux, size )
{
   // Centroid position in pixels, image coordinates.
   this.pos = new Point( pos.x, pos.y );
   // Total flux, normalized intensity units.
   this.flux = flux;
   // Area of detected star structure in square pixels.
   this.size = size;
}

The local background estimate for each star is not stored in Star objects, although it is computed in the StarDetector.starParameters() method. You can modify StarDetector.jsh very easily to include local background estimates in Star objects. Replace the Star object constructor as follows from line #104:

Code: [Select]
function Star( pos, flux, size, bkg )
{
   // Centroid position in pixels, image coordinates.
   this.pos = new Point( pos.x, pos.y );
   // Total flux, normalized intensity units.
   this.flux = flux;
   // Area of detected star structure in square pixels.
   this.size = size;
   // Local background estimate.
   this.bkg = bkg;
}

Then replace line #578:

Code: [Select]
                                    S.push( new Star( p.pos, p.flux, p.size ) );
as follows:

Code: [Select]
                                    S.push( new Star( p.pos, p.flux, p.size, p.bkg ) );
Now you get an array of Star objects with background estimates returned by the StarDetector.stars() method. Let me know if this helps.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline dave_galera

  • PixInsight Addict
  • ***
  • Posts: 261
    • QDigital Astro
Re: Return star array from StarDetector
« Reply #2 on: 2020 January 18 11:38:47 »
Brilliant (as usual), perfecto..........thanks Juan.
Dave