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 142bcad commit dfc2a74
Show file tree
Hide file tree
Showing 19 changed files with 207 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import nebulosa.pixinsight.script.PixInsightIsRunning
import nebulosa.pixinsight.script.PixInsightScriptRunner
import nebulosa.pixinsight.script.PixInsightStartup
import nebulosa.pixinsight.stardetector.PixInsightStarDetector
import nebulosa.siril.stardetector.SirilStarDetector
import nebulosa.stardetector.StarDetector
import java.nio.file.Path
import java.time.Duration
Expand All @@ -15,11 +16,13 @@ data class StarDetectionRequest(
@JvmField val executablePath: Path? = null,
@JvmField val timeout: Duration = Duration.ZERO,
@JvmField val minSNR: Double = 0.0,
@JvmField val maxStars: Int = 0,
@JvmField val slot: Int = 1,
) : Supplier<StarDetector<Path>> {

override fun get() = when (type) {
StarDetectorType.ASTAP -> AstapStarDetector(executablePath!!, minSNR)
StarDetectorType.SIRIL -> SirilStarDetector(executablePath!!, maxStars)
StarDetectorType.PIXINSIGHT -> {
val runner = PixInsightScriptRunner(executablePath!!)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ package nebulosa.api.stardetector

enum class StarDetectorType {
ASTAP,
PIXINSIGHT
PIXINSIGHT,
SIRIL,
}
4 changes: 2 additions & 2 deletions desktop/src/app/alignment/alignment.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Angle } from '../../shared/types/atlas.types'
import { Camera, EMPTY_CAMERA, EMPTY_CAMERA_START_CAPTURE, ExposureTimeUnit, updateCameraStartCaptureFromCamera } from '../../shared/types/camera.types'
import { EMPTY_GUIDE_OUTPUT, GuideDirection, GuideOutput } from '../../shared/types/guider.types'
import { EMPTY_MOUNT, Mount } from '../../shared/types/mount.types'
import { EMPTY_PLATE_SOLVER_OPTIONS } from '../../shared/types/settings.types'
import { EMPTY_PLATE_SOLVER_REQUEST } from '../../shared/types/settings.types'
import { deviceComparator } from '../../shared/utils/comparators'
import { AppComponent } from '../app.component'
import { CameraComponent } from '../camera/camera.component'
Expand Down Expand Up @@ -40,7 +40,7 @@ export class AlignmentComponent implements AfterViewInit, OnDestroy, Pingable {

readonly tppaRequest: TPPAStart = {
capture: structuredClone(EMPTY_CAMERA_START_CAPTURE),
plateSolver: structuredClone(EMPTY_PLATE_SOLVER_OPTIONS),
plateSolver: structuredClone(EMPTY_PLATE_SOLVER_REQUEST),
startFromCurrentPosition: true,
stepDirection: 'EAST',
compensateRefraction: true,
Expand Down
9 changes: 8 additions & 1 deletion desktop/src/app/image/image.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -451,13 +451,20 @@
<label>Detector</label>
</span>
</div>
<div class="col-5 align-items-center">
<div class="col-5 align-items-center" *ngIf="starDetection.type !== 'SIRIL'">
<span class="p-float-label">
<p-inputNumber [min]="0" [max]="500" [step]="1" [showButtons]="true" class="w-full" styleClass="p-inputtext-sm border-0 w-full"
[(ngModel)]="starDetection.minSNR" locale="en" [allowEmpty]="false" scrollableNumber />
<label>Min SNR</label>
</span>
</div>
<div class="col-5 align-items-center" *ngIf="starDetection.type === 'SIRIL'">
<span class="p-float-label">
<p-inputNumber [min]="0" [max]="2000" [step]="1" [showButtons]="true" class="w-full" styleClass="p-inputtext-sm border-0 w-full"
[(ngModel)]="starDetection.maxStars" locale="en" [allowEmpty]="false" scrollableNumber />
<label>Max Stars</label>
</span>
</div>
<div class="col-12 mt-1">
<span class="font-bold text-sm">COMPUTED</span>
</div>
Expand Down
10 changes: 6 additions & 4 deletions desktop/src/app/image/image.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export class ImageComponent implements AfterViewInit, OnDestroy {
running: false,
type: 'ASTAP',
minSNR: 0,
maxStars: 0,
visible: false,
stars: [],
computed: {
Expand Down Expand Up @@ -799,6 +800,7 @@ export class ImageComponent implements AfterViewInit, OnDestroy {
async detectStars() {
const options = this.preference.starDetectionRequest(this.starDetection.type).get()
options.minSNR = this.starDetection.minSNR
options.maxStars = this.starDetection.maxStars

try {
this.starDetection.running = true
Expand Down Expand Up @@ -1275,8 +1277,9 @@ export class ImageComponent implements AfterViewInit, OnDestroy {
const preference = this.preference.imagePreference.get()
this.solver.radius = preference.solverRadius ?? this.solver.radius
this.solver.type = preference.solverType ?? 'ASTAP'
this.starDetection.type = preference.starDetectionType ?? this.starDetection.type
this.starDetection.minSNR = preference.starDetectionMinSNR ?? this.preference.starDetectionRequest(this.starDetection.type).get().minSNR ?? this.starDetection.minSNR
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

this.fov.fovs = this.preference.imageFOVs.get()
this.fov.fovs.forEach(e => { e.enabled = false; e.computed = undefined })
Expand All @@ -1288,8 +1291,7 @@ export class ImageComponent implements AfterViewInit, OnDestroy {
preference.solverType = this.solver.type
preference.solverPixelSize = this.solver.pixelSize
preference.solverFocalLength = this.solver.focalLength
preference.starDetectionType = this.starDetection.type
preference.starDetectionMinSNR = this.starDetection.minSNR
preference.starDetection = this.starDetection
this.preference.imagePreference.set(preference)
}

Expand Down
6 changes: 3 additions & 3 deletions desktop/src/app/settings/settings.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { PreferenceService } from '../../shared/services/preference.service'
import { PrimeService } from '../../shared/services/prime.service'
import { EMPTY_LOCATION, Location } from '../../shared/types/atlas.types'
import { LiveStackerType, LiveStackingRequest } from '../../shared/types/camera.types'
import { PlateSolverOptions, PlateSolverType, StarDetectionOptions, StarDetectorType } from '../../shared/types/settings.types'
import { PlateSolverRequest, PlateSolverType, StarDetectionRequest, StarDetectorType } from '../../shared/types/settings.types'
import { AppComponent } from '../app.component'

@Component({
Expand Down Expand Up @@ -40,10 +40,10 @@ export class SettingsComponent implements AfterViewInit, OnDestroy {
location: Location

plateSolverType: PlateSolverType = 'ASTAP'
readonly plateSolvers = new Map<PlateSolverType, PlateSolverOptions>()
readonly plateSolvers = new Map<PlateSolverType, PlateSolverRequest>()

starDetectorType: StarDetectorType = 'ASTAP'
readonly starDetectors = new Map<StarDetectorType, StarDetectionOptions>()
readonly starDetectors = new Map<StarDetectorType, StarDetectionRequest>()

liveStackerType: LiveStackerType = 'SIRIL'
readonly liveStackers = new Map<LiveStackerType, LiveStackingRequest>()
Expand Down
2 changes: 1 addition & 1 deletion desktop/src/shared/pipes/dropdown-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class DropdownOptionsPipe implements PipeTransform {

transform<K extends keyof DropdownOptions>(type: K): DropdownOptions[K] {
switch (type) {
case 'STAR_DETECTOR': return ['ASTAP', 'PIXINSIGHT'] as DropdownOptions[K]
case 'STAR_DETECTOR': return ['ASTAP', 'PIXINSIGHT', 'SIRIL'] as DropdownOptions[K]
case 'PLATE_SOLVER': return ['ASTAP', 'ASTROMETRY_NET_ONLINE', 'SIRIL'] as DropdownOptions[K]
case 'AUTO_FOCUS_FITTING_MODE': return ['TRENDLINES', 'PARABOLIC', 'TREND_PARABOLIC', 'HYPERBOLIC', 'TREND_HYPERBOLIC'] as DropdownOptions[K]
case 'AUTO_FOCUS_BACKLASH_COMPENSATION_MODE': return ['NONE', 'ABSOLUTE', 'OVERSHOOT'] as DropdownOptions[K]
Expand Down
6 changes: 3 additions & 3 deletions desktop/src/shared/services/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { CoordinateInterpolation, DetectedStar, FOVCamera, FOVTelescope, ImageAn
import { CelestialLocationType, Mount, MountRemoteControl, MountRemoteControlType, SlewRate, TrackMode } from '../types/mount.types'
import { Rotator } from '../types/rotator.types'
import { SequencePlan } from '../types/sequencer.types'
import { PlateSolverOptions, StarDetectionOptions } from '../types/settings.types'
import { PlateSolverRequest, StarDetectionRequest } from '../types/settings.types'
import { FilterWheel } from '../types/wheel.types'
import { HttpService } from './http.service'

Expand Down Expand Up @@ -563,7 +563,7 @@ export class ApiService {
return this.http.get<CoordinateInterpolation | null>(`image/coordinate-interpolation?${query}`)
}

detectStars(path: string, starDetector: StarDetectionOptions) {
detectStars(path: string, starDetector: StarDetectionRequest) {
const query = this.http.query({ path })
return this.http.put<DetectedStar[]>(`star-detection?${query}`, starDetector)
}
Expand Down Expand Up @@ -672,7 +672,7 @@ export class ApiService {
// SOLVER

solveImage(
solver: PlateSolverOptions, path: string, blind: boolean,
solver: PlateSolverRequest, path: string, blind: boolean,
centerRA: Angle, centerDEC: Angle, radius: Angle,
) {
const query = this.http.query({ path, blind, centerRA, centerDEC, radius })
Expand Down
6 changes: 3 additions & 3 deletions desktop/src/shared/services/preference.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Focuser, FocuserPreference } from '../types/focuser.types'
import { ConnectionDetails, Equipment, HomePreference } from '../types/home.types'
import { EMPTY_IMAGE_PREFERENCE, FOV, ImagePreference } from '../types/image.types'
import { Rotator, RotatorPreference } from '../types/rotator.types'
import { EMPTY_PLATE_SOLVER_OPTIONS, EMPTY_STAR_DETECTION_OPTIONS, PlateSolverOptions as PlateSolverRequest, PlateSolverType, StarDetectionOptions as StarDetectionRequest, StarDetectorType } from '../types/settings.types'
import { EMPTY_PLATE_SOLVER_REQUEST, EMPTY_STAR_DETECTION_REQUEST, PlateSolverRequest, PlateSolverType, StarDetectionRequest, StarDetectorType } from '../types/settings.types'
import { FilterWheel, WheelPreference } from '../types/wheel.types'
import { LocalStorageService } from './local-storage.service'

Expand Down Expand Up @@ -69,11 +69,11 @@ export class PreferenceService {
}

plateSolverRequest(type: PlateSolverType) {
return new PreferenceData<PlateSolverRequest>(this.storage, `plateSolver.${type}`, () => <PlateSolverRequest>{ ...EMPTY_PLATE_SOLVER_OPTIONS, type })
return new PreferenceData<PlateSolverRequest>(this.storage, `plateSolver.${type}`, () => <PlateSolverRequest>{ ...EMPTY_PLATE_SOLVER_REQUEST, type })
}

starDetectionRequest(type: StarDetectorType) {
return new PreferenceData<StarDetectionRequest>(this.storage, `starDetection.${type}`, () => <StarDetectionRequest>{ ...EMPTY_STAR_DETECTION_OPTIONS, type })
return new PreferenceData<StarDetectionRequest>(this.storage, `starDetection.${type}`, () => <StarDetectionRequest>{ ...EMPTY_STAR_DETECTION_REQUEST, type })
}

liveStackingRequest(type: LiveStackerType) {
Expand Down
4 changes: 2 additions & 2 deletions desktop/src/shared/types/alignment.types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Angle } from './atlas.types'
import { Camera, CameraCaptureEvent, CameraStartCapture } from './camera.types'
import { GuideDirection } from './guider.types'
import { PlateSolverOptions, PlateSolverType } from './settings.types'
import { PlateSolverRequest, PlateSolverType } from './settings.types'

export type Hemisphere = 'NORTHERN' | 'SOUTHERN'

Expand Down Expand Up @@ -52,7 +52,7 @@ export interface DARVEvent extends MessageEvent {

export interface TPPAStart {
capture: CameraStartCapture
plateSolver: PlateSolverOptions
plateSolver: PlateSolverRequest
startFromCurrentPosition: boolean
compensateRefraction: boolean
stopTrackingWhenDone: boolean
Expand Down
6 changes: 3 additions & 3 deletions desktop/src/shared/types/autofocus.type.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Point } from 'electron'
import { CameraCaptureEvent, CameraStartCapture } from './camera.types'
import { EMPTY_STAR_DETECTION_OPTIONS, StarDetectionOptions } from './settings.types'
import { EMPTY_STAR_DETECTION_REQUEST, StarDetectionRequest } from './settings.types'

export type AutoFocusState = 'IDLE' | 'MOVING' | 'EXPOSURING' | 'EXPOSURED' | 'ANALYSING' | 'ANALYSED' | 'CURVE_FITTED' | 'FAILED' | 'FINISHED'

Expand All @@ -22,7 +22,7 @@ export interface AutoFocusRequest {
initialOffsetSteps: number
stepSize: number
totalNumberOfAttempts: number
starDetector: StarDetectionOptions
starDetector: StarDetectionRequest
}

export interface AutoFocusPreference extends Omit<AutoFocusRequest, 'capture'> { }
Expand All @@ -38,7 +38,7 @@ export const EMPTY_AUTO_FOCUS_PREFERENCE: AutoFocusPreference = {
backlashIn: 0,
backlashOut: 0
},
starDetector: EMPTY_STAR_DETECTION_OPTIONS,
starDetector: EMPTY_STAR_DETECTION_REQUEST,
}

export interface Curve {
Expand Down
12 changes: 8 additions & 4 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, StarDetectorType } from './settings.types'
import { PlateSolverType, StarDetectionRequest, StarDetectorType } from './settings.types'

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

Expand Down Expand Up @@ -117,14 +117,17 @@ export interface ImagePreference {
solverFocalLength?: number
solverPixelSize?: number
savePath?: string
starDetectionType?: StarDetectorType
starDetectionMinSNR?: number
starDetection?: Pick<StarDetectionRequest, 'type' | 'minSNR' | 'maxStars'>
}

export const EMPTY_IMAGE_PREFERENCE: ImagePreference = {
solverRadius: 4,
solverType: 'ASTAP',
starDetectionType: 'ASTAP'
starDetection: {
type: 'ASTAP',
minSNR: 0,
maxStars: 0,
}
}

export interface ImageData {
Expand Down Expand Up @@ -286,6 +289,7 @@ export interface StarDetectionDialog {
running: boolean
type: StarDetectorType
minSNR: number
maxStars: number
visible: boolean
stars: DetectedStar[]
computed: Omit<DetectedStar, 'x' | 'y' | 'flux'> & { minFlux: number, maxFlux: number }
Expand Down
12 changes: 7 additions & 5 deletions desktop/src/shared/types/settings.types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export type PlateSolverType = 'ASTROMETRY_NET' | 'ASTROMETRY_NET_ONLINE' | 'ASTAP' | 'SIRIL'

export interface PlateSolverOptions {
export interface PlateSolverRequest {
type: PlateSolverType
executablePath: string
downsampleFactor: number
Expand All @@ -9,7 +9,7 @@ export interface PlateSolverOptions {
timeout: number
}

export const EMPTY_PLATE_SOLVER_OPTIONS: PlateSolverOptions = {
export const EMPTY_PLATE_SOLVER_REQUEST: PlateSolverRequest = {
type: 'ASTAP',
executablePath: '',
downsampleFactor: 0,
Expand All @@ -18,20 +18,22 @@ export const EMPTY_PLATE_SOLVER_OPTIONS: PlateSolverOptions = {
timeout: 300,
}

export type StarDetectorType = 'ASTAP' | 'PIXINSIGHT'
export type StarDetectorType = 'ASTAP' | 'PIXINSIGHT' | 'SIRIL'

export interface StarDetectionOptions {
export interface StarDetectionRequest {
type: StarDetectorType
executablePath: string
timeout: number
minSNR: number
maxStars: number
slot: number
}

export const EMPTY_STAR_DETECTION_OPTIONS: StarDetectionOptions = {
export const EMPTY_STAR_DETECTION_REQUEST: StarDetectionRequest = {
type: 'ASTAP',
executablePath: '',
timeout: 300,
minSNR: 0,
maxStars: 0,
slot: 1,
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import nebulosa.io.resource
import nebulosa.math.hours
import nebulosa.math.toDegrees

class ConstellationBoundary internal constructor(override val operand: PolygonFunction) : Region {
data class ConstellationBoundary(override val operand: PolygonFunction) : Region {

constructor(constellationName: String) : this(PolygonFunction(Region.ICRS, BOUNDARY[constellationName.uppercase()]))

Expand All @@ -15,17 +15,19 @@ class ConstellationBoundary internal constructor(override val operand: PolygonFu
private val BOUNDARY = HashMap<String, MutableList<NumericConstant>>(88)

init {
for (line in resource("constellations_bound_in_20.txt")!!.bufferedReader().lines()) {
if (line.isEmpty() || line.startsWith('#')) continue

val parts = line.split(" ")
val rightAscension = parts[0].hours.toDegrees
val declination = parts[1].toDouble()
val name = parts[2].trim()

with(BOUNDARY.getOrPut(name) { ArrayList(150) }) {
add(NumericConstant(rightAscension))
add(NumericConstant(declination))
resource("constellations_bound_in_20.txt")!!.use {
for (line in it.bufferedReader().lines()) {
if (line.isEmpty() || line.startsWith('#')) continue

val parts = line.split(" ")
val rightAscension = parts[0].hours.toDegrees
val declination = parts[1].toDouble()
val name = parts[2].trim()

with(BOUNDARY.getOrPut(name) { ArrayList(150) }) {
add(NumericConstant(rightAscension))
add(NumericConstant(declination))
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ data class CommandLine internal constructor(
} catch (e: InterruptedException) {
LOG.error("command line interrupted")
} catch (e: Throwable) {
LOG.error("command line failed", e)
LOG.error("command line failed: {}", e.message)
} finally {
completable.complete(Unit)
reader.close()
Expand Down
1 change: 1 addition & 0 deletions nebulosa-siril/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ dependencies {
api(project(":nebulosa-math"))
api(project(":nebulosa-livestacker"))
api(project(":nebulosa-platesolver"))
api(project(":nebulosa-stardetector"))
implementation(project(":nebulosa-log"))
testImplementation(project(":nebulosa-test"))
}
Expand Down
Loading

0 comments on commit dfc2a74

Please sign in to comment.