Skip to content

Commit

Permalink
Add magnitude filter to plate solver
Browse files Browse the repository at this point in the history
  • Loading branch information
kylecorry31 committed Dec 22, 2024
1 parent cc7acdb commit cb8ffff
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -678,9 +678,10 @@ object Astronomy : IAstronomyService {
approximateLocation: Coordinate?,
tolerance: Float,
minMatches: Int,
numNeighbors: Int
numNeighbors: Int,
minMagnitude: Float
): List<DetectedStar> {
return PlateSolver(tolerance, minMatches, numNeighbors).solve(
return PlateSolver(tolerance, minMatches, numNeighbors, minMagnitude).solve(
readings,
time,
approximateLocation ?: Time.getLocationFromTimeZone(time.zone)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ interface IStarService {
approximateLocation: Coordinate? = null,
tolerance: Float = 0.04f,
minMatches: Int = 5,
numNeighbors: Int = 3
numNeighbors: Int = 3,
minMagnitude: Float = 4f
): List<DetectedStar>

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import com.kylecorry.sol.time.Time
import com.kylecorry.sol.units.Coordinate
import java.time.ZonedDateTime
import kotlin.math.absoluteValue
import kotlin.math.max

internal class PlateSolver(
private val tolerance: Float = 0.04f,
private val minMatches: Int = 5,
private val numNeighbors: Int = 3
private val numNeighbors: Int = 3,
private val minMagnitude: Float = 4f
) {

fun solve(
Expand Down Expand Up @@ -85,7 +87,8 @@ internal class PlateSolver(

// Remove stars that are way below the horizon
// TODO: Also remove stars that are way out of sight based on the input readings
val starReadings = stars.map {
// NOTE: Magnitude is inverted, so lower is brighter
val starReadings = stars.filter { it.magnitude <= minMagnitude }.map {
it to AltitudeAzimuth(
Astronomy.getStarAltitude(it, time, approximateLocation, true),
Astronomy.getStarAzimuth(it, time, approximateLocation).value
Expand Down Expand Up @@ -168,7 +171,7 @@ internal class PlateSolver(

private fun getConfidence(v1: FloatArray, v2: FloatArray): Float {
val percentDifferences = v1.zip(v2).map { (a, b) ->
(a - b).absoluteValue / ((a + b) / 2)
(a - b).absoluteValue / max(a, b)
}

return 1 - percentDifferences.max()
Expand Down

0 comments on commit cb8ffff

Please sign in to comment.