Skip to content

Commit

Permalink
[api][desktop]: Support Siril Star Detector
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagohm committed Jun 13, 2024
1 parent dfc2a74 commit 6682e5c
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 37 deletions.
28 changes: 19 additions & 9 deletions desktop/src/app/image/image.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -921,8 +921,8 @@ export class ImageComponent implements AfterViewInit, OnDestroy {
}
}

this.solver.focalLength ||= imagePreference.solverFocalLength || 0
this.solver.pixelSize ||= imagePreference.solverPixelSize || 0
this.solver.focalLength ||= imagePreference.solver?.focalLength || 0
this.solver.pixelSize ||= imagePreference.solver?.pixelSize || 0
}

imageClicked(event: MouseEvent, contextMenu: boolean) {
Expand Down Expand Up @@ -1275,8 +1275,10 @@ export class ImageComponent implements AfterViewInit, OnDestroy {

private loadPreference() {
const preference = this.preference.imagePreference.get()
this.solver.radius = preference.solverRadius ?? this.solver.radius
this.solver.type = preference.solverType ?? 'ASTAP'
this.solver.radius = preference.solver?.radius ?? this.solver.radius
this.solver.type = preference.solver?.type ?? 'ASTAP'
this.solver.focalLength = preference.solver?.focalLength ?? 0
this.solver.pixelSize = preference.solver?.pixelSize ?? 0
this.starDetection.type = preference.starDetection?.type ?? this.starDetection.type
this.starDetection.minSNR = preference.starDetection?.minSNR ?? this.preference.starDetectionRequest(this.starDetection.type).get().minSNR ?? this.starDetection.minSNR
this.starDetection.maxStars = preference.starDetection?.maxStars ?? this.starDetection.maxStars
Expand All @@ -1287,11 +1289,19 @@ export class ImageComponent implements AfterViewInit, OnDestroy {

private savePreference() {
const preference = this.preference.imagePreference.get()
preference.solverRadius = this.solver.radius
preference.solverType = this.solver.type
preference.solverPixelSize = this.solver.pixelSize
preference.solverFocalLength = this.solver.focalLength
preference.starDetection = this.starDetection

preference.solver = {
type: this.solver.type,
focalLength: this.solver.focalLength,
pixelSize: this.solver.pixelSize,
radius: this.solver.radius,
}
preference.starDetection = {
type: this.starDetection.type,
maxStars: this.starDetection.maxStars,
minSNR: this.starDetection.minSNR,
}

this.preference.imagePreference.set(preference)
}

Expand Down
37 changes: 20 additions & 17 deletions desktop/src/shared/types/image.types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Point, Size } from 'electron'
import { Angle, AstronomicalObject, DeepSkyObject, EquatorialCoordinateJ2000, Star } from './atlas.types'
import { Camera, CameraStartCapture } from './camera.types'
import { PlateSolverType, StarDetectionRequest, StarDetectorType } from './settings.types'
import { PlateSolverRequest, StarDetectionRequest } from './settings.types'

export type ImageChannel = 'RED' | 'GREEN' | 'BLUE' | 'GRAY'

Expand Down Expand Up @@ -111,18 +111,28 @@ export interface ImageStatistics {
maximum: number
}

export interface StarDetectionImagePreference extends Pick<StarDetectionRequest, 'type' | 'minSNR' | 'maxStars'> {
}

export interface PlateSolverImagePreference extends Pick<PlateSolverRequest, 'type'> {
radius: number
focalLength: number
pixelSize: number
}

export interface ImagePreference {
solverRadius?: number
solverType?: PlateSolverType
solverFocalLength?: number
solverPixelSize?: number
savePath?: string
starDetection?: Pick<StarDetectionRequest, 'type' | 'minSNR' | 'maxStars'>
solver?: PlateSolverImagePreference
starDetection?: StarDetectionImagePreference
}

export const EMPTY_IMAGE_PREFERENCE: ImagePreference = {
solverRadius: 4,
solverType: 'ASTAP',
solver: {
type: 'ASTAP',
radius: 4,
focalLength: 0,
pixelSize: 0,
},
starDetection: {
type: 'ASTAP',
minSNR: 0,
Expand Down Expand Up @@ -213,17 +223,13 @@ export interface ImageStretchDialog {
midtone: number
}

export interface ImageSolverDialog {
export interface ImageSolverDialog extends PlateSolverImagePreference {
showDialog: boolean
running: boolean
blind: boolean
centerRA: Angle
centerDEC: Angle
radius: number
focalLength: number
pixelSize: number
readonly solved: ImageSolved
type: PlateSolverType
}

export interface ImageFOVDialog extends FOV {
Expand Down Expand Up @@ -284,12 +290,9 @@ export interface ROISelected {
height: number
}

export interface StarDetectionDialog {
export interface StarDetectionDialog extends StarDetectionImagePreference {
showDialog: boolean
running: boolean
type: StarDetectorType
minSNR: number
maxStars: number
visible: boolean
stars: DetectedStar[]
computed: Omit<DetectedStar, 'x' | 'y' | 'flux'> & { minFlux: number, maxFlux: number }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ data class CommandLine internal constructor(
}
}
} catch (e: InterruptedException) {
LOG.error("command line interrupted")
LOG.warn("command line interrupted")
} catch (e: Throwable) {
LOG.error("command line failed: {}", e.message)
LOG.warn("command line exited: {}", e.message)
} finally {
completable.complete(Unit)
reader.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,16 @@ data class FindStar(
if (line.startsWith('#')) continue

val columns = line.split('\t')
val x = columns[5].trim().toDouble()
val y = columns[6].trim().toDouble()
val fwhmx = columns[7].trim().toDouble()
val fwhmy = columns[8].trim().toDouble()
val flux = columns[3].trim().toDouble() // A ???
val x = columns[5].trim().toDouble() // X
val y = columns[6].trim().toDouble() // Y
val fwhmx = columns[7].trim().toDouble() // FWHMx [px]
val fwhmy = columns[8].trim().toDouble() // FWHMy [px]
val snr = columns[12].trim().toDouble() // RMSE ???
val fwhm = (fwhmx + fwhmy) / 2.0
val hfd = fwhm / FWHM

stars.add(Star(x, height - y, hfd, 0.0, 0.0))
stars.add(Star(x, height - y, hfd, snr, flux))
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package nebulosa.siril.command

/**
* @see <a href="https://siril.readthedocs.io/en/stable/Commands.html">Commands</a>
*/
sealed interface SirilCommand<out T> {

fun write(commandLine: SirilCommandLine): T
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import nebulosa.stardetector.StarDetector
import nebulosa.stardetector.StarPoint
import java.nio.file.Path

// https://gitlab.com/free-astro/siril/-/blob/master/src/algos/star_finder.c

data class SirilStarDetector(
private val executablePath: Path,
private val maxStars: Int = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import kotlin.io.path.copyTo
import kotlin.io.path.listDirectoryEntries

@EnabledIf(NonGitHubOnlyCondition::class)
class SirilLiveStackerTest : AbstractFitsAndXisfTest() {
class SirilTest : AbstractFitsAndXisfTest() {

init {
val executablePath = Path.of("siril-cli")
Expand Down Expand Up @@ -62,9 +62,21 @@ class SirilLiveStackerTest : AbstractFitsAndXisfTest() {
}
"star detector" {
val detector = SirilStarDetector(executablePath)
val stars = detector.detect(PI_01_LIGHT)
stars shouldHaveSize 126
println(stars)

with(detector.detect(PI_FOCUS_0)) {
this shouldHaveSize 307
map { it.hfd }.average() shouldBe (7.9 plusOrMinus 1e-1)
}

with(detector.detect(PI_FOCUS_30000)) {
this shouldHaveSize 258
map { it.hfd }.average() shouldBe (1.1 plusOrMinus 1e-1)
}

with(detector.detect(PI_FOCUS_100000)) {
this shouldHaveSize 82
map { it.hfd }.average() shouldBe (22.4 plusOrMinus 1e-1)
}
}
}
}

0 comments on commit 6682e5c

Please sign in to comment.