From c34097e1cc571203825ad716ba7c99ab698e4a7a Mon Sep 17 00:00:00 2001 From: Kyle Corry Date: Fri, 20 Dec 2024 20:03:57 -0500 Subject: [PATCH] Add plate solving Signed-off-by: Kyle Corry --- .../celestial_navigation/StarFinderTest.kt | 40 ++++++++++++++++++- .../domain/SimpleStarFinder.kt | 2 +- .../ui/CelestialNavigationFragment.kt | 19 +++++++++ gradle/libs.versions.toml | 2 +- 4 files changed, 60 insertions(+), 3 deletions(-) diff --git a/app/src/androidTest/java/com/kylecorry/trail_sense/tools/celestial_navigation/StarFinderTest.kt b/app/src/androidTest/java/com/kylecorry/trail_sense/tools/celestial_navigation/StarFinderTest.kt index 2ddc2fdbd..795147dcd 100644 --- a/app/src/androidTest/java/com/kylecorry/trail_sense/tools/celestial_navigation/StarFinderTest.kt +++ b/app/src/androidTest/java/com/kylecorry/trail_sense/tools/celestial_navigation/StarFinderTest.kt @@ -3,10 +3,16 @@ package com.kylecorry.trail_sense.tools.celestial_navigation import android.graphics.BitmapFactory import androidx.test.platform.app.InstrumentationRegistry import com.kylecorry.andromeda.files.AssetFileSystem +import com.kylecorry.sol.science.astronomy.Astronomy +import com.kylecorry.sol.science.astronomy.stars.AltitudeAzimuth +import com.kylecorry.sol.science.astronomy.stars.Star import com.kylecorry.trail_sense.tools.celestial_navigation.domain.DifferenceOfGaussiansStarFinder -import com.kylecorry.trail_sense.tools.celestial_navigation.domain.PercentOfMaxStarFinder import kotlinx.coroutines.runBlocking +import org.junit.Assert.assertEquals +import org.junit.Assert.assertTrue import org.junit.Test +import java.time.ZoneId +import java.time.ZonedDateTime class StarFinderTest { @@ -18,6 +24,20 @@ class StarFinderTest { "stars/20241215_020631.jpg", ) + val expectedStars = listOf( + emptyList(), + emptyList(), + listOf( + Star.Alnilam, + Star.Mintaka, + Star.Alnitak, + Star.Betelgeuse, + Star.Rigel, + Star.Bellatrix, + Star.Saiph + ) + ) + for (file in images) { val assets = AssetFileSystem(InstrumentationRegistry.getInstrumentation().context) val image = assets.stream(file).use { @@ -28,6 +48,24 @@ class StarFinderTest { // val stars = StandardDeviationStarFinder(5f).findStars(image) val stars = DifferenceOfGaussiansStarFinder(0.3f).findStars(image) assert(stars.isNotEmpty()) + val starReadings = stars.map { + val xAngle = ((it.x - image.width / 2) / image.width.toFloat()) * 8.566184f + val yAngle = -((it.y - image.height / 2) / image.height.toFloat()) * 6.77276f + AltitudeAzimuth(yAngle, xAngle) + } + + val plate = + Astronomy.plateSolve( + starReadings, + ZonedDateTime.of(2024, 12, 15, 2, 0, 0, 0, ZoneId.of("America/New_York")), + tolerance = 0.1f + ) + + val expected = expectedStars[images.indexOf(file)] + if (expected.isNotEmpty()) { + assertEquals(expected.size, plate.size) + assertTrue(plate.map { it.second }.containsAll(expected)) + } } } diff --git a/app/src/main/java/com/kylecorry/trail_sense/tools/celestial_navigation/domain/SimpleStarFinder.kt b/app/src/main/java/com/kylecorry/trail_sense/tools/celestial_navigation/domain/SimpleStarFinder.kt index 267f4897f..df0913109 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/tools/celestial_navigation/domain/SimpleStarFinder.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/tools/celestial_navigation/domain/SimpleStarFinder.kt @@ -14,7 +14,7 @@ class SimpleStarFinder(private val threshold: Float = 200f) : StarFinder { val yScale = resized.height.toFloat() / image.height try { - val pointFinder = GrayscalePointFinder(threshold, 0.5f, Range(0.5f, 1.5f)) + val pointFinder = GrayscalePointFinder(threshold, 0.5f, Range(0.5f, 2f)) return pointFinder.getPoints(resized).map { PixelCoordinate(it.center.x / xScale, it.center.y / yScale) } diff --git a/app/src/main/java/com/kylecorry/trail_sense/tools/celestial_navigation/ui/CelestialNavigationFragment.kt b/app/src/main/java/com/kylecorry/trail_sense/tools/celestial_navigation/ui/CelestialNavigationFragment.kt index 22d9dc98e..e86348ebf 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/tools/celestial_navigation/ui/CelestialNavigationFragment.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/tools/celestial_navigation/ui/CelestialNavigationFragment.kt @@ -29,6 +29,7 @@ import com.kylecorry.sol.math.SolMath.deltaAngle import com.kylecorry.sol.math.SolMath.map import com.kylecorry.sol.math.SolMath.square import com.kylecorry.sol.science.astronomy.Astronomy +import com.kylecorry.sol.science.astronomy.stars.AltitudeAzimuth import com.kylecorry.sol.science.astronomy.stars.Star import com.kylecorry.sol.science.astronomy.stars.StarReading import com.kylecorry.sol.time.Time @@ -265,6 +266,24 @@ class CelestialNavigationFragment : BoundFragment