Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add (i *Indexer) GenerateQuadsForPixel() to index module in @observerly/skysolve #192

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions pkg/index/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ package index
/*****************************************************************************************************************/

import (
"github.com/observerly/skysolve/pkg/astrometry"
"github.com/observerly/skysolve/pkg/catalog"
"github.com/observerly/skysolve/pkg/healpix"
"github.com/observerly/skysolve/pkg/quad"
"github.com/observerly/skysolve/pkg/solve"
"github.com/observerly/skysolve/pkg/star"
)

/*****************************************************************************************************************/
Expand All @@ -35,3 +39,63 @@ func NewIndexer(
}

/*****************************************************************************************************************/

func (i *Indexer) GenerateQuadsForPixel(pixel int) ([]quad.Quad, error) {
// Convert the pixel index to the pixel's equatorial coordinate:
eq := i.HealPIX.ConvertPixelIndexToEquatorial(pixel)

// Get the radial extent of the pixel:
radius := i.HealPIX.GetPixelRadialExtent(pixel)

// Get the sources within the pixel's radial extent:
sources, err := i.Catalog.PerformRadialSearch(eq, radius)

// If we encounter an error, return it:
if err != nil {
return nil, err
}

// Convert the sources to stars:
stars := make([]star.Star, len(sources))

for _, source := range sources {
// For each source, we just need to sense check that the source is within the pixel:
eq := astrometry.ICRSEquatorialCoordinate{
RA: source.RA,
Dec: source.Dec,
}

pixelIndex := i.HealPIX.ConvertEquatorialToPixelIndex(eq)

// If the source is not within the pixel, skip it:
if pixelIndex != pixel {
continue
}

stars = append(stars, star.Star{
Designation: source.Designation,
X: source.RA,
Y: source.Dec,
RA: source.RA,
Dec: source.Dec,
Intensity: source.PhotometricGMeanFlux,
})
}

// We should have at least 5 sources to generate a quad:
if len(stars) < 5 {
return nil, nil
}

// Indexing the sources here involves storing the sources locally for future reference:
quads, err := solve.GenerateEuclidianStarQuads(stars, 5)

// If we encounter an error, return it:
if err != nil {
return nil, err
}

return quads, nil
}

/*****************************************************************************************************************/