Skip to content

Commit

Permalink
[api][desktop]: Improve Astap Plate Solver
Browse files Browse the repository at this point in the history
* Use focal length and pixel size to calculate fov
  • Loading branch information
tiagohm committed Oct 24, 2024
1 parent 878c2dc commit 0c499b4
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import nebulosa.astrometrynet.nova.NovaAstrometryNetService
import nebulosa.astrometrynet.platesolver.LocalAstrometryNetPlateSolver
import nebulosa.astrometrynet.platesolver.NovaAstrometryNetPlateSolver
import nebulosa.math.Angle
import nebulosa.math.arcsec
import nebulosa.pixinsight.platesolver.PixInsightPlateSolver
import nebulosa.pixinsight.script.startPixInsight
import nebulosa.platesolver.PlateSolver
Expand Down Expand Up @@ -39,6 +40,8 @@ data class PlateSolverRequest(
@field:JsonDeserialize(using = RightAscensionDeserializer::class) @JvmField val centerRA: Angle = 0.0,
@field:JsonDeserialize(using = DeclinationDeserializer::class) @JvmField val centerDEC: Angle = 0.0,
@field:JsonDeserialize(using = DegreesDeserializer::class) @JvmField val radius: Angle = if (blind) 0.0 else 4.0,
@JvmField val width: Int = 0,
@JvmField val height: Int = 0,
) : Validatable, KoinComponent, Supplier<PlateSolver> {

override fun validate() {
Expand All @@ -55,7 +58,7 @@ data class PlateSolverRequest(

override fun get() = with(this) {
when (type) {
PlateSolverType.ASTAP -> AstapPlateSolver(executablePath!!)
PlateSolverType.ASTAP -> AstapPlateSolver(executablePath!!, height * PlateSolver.computeFOV(focalLength, pixelSize).arcsec)
PlateSolverType.ASTROMETRY_NET -> LocalAstrometryNetPlateSolver(executablePath!!, focalLength, pixelSize)
PlateSolverType.ASTROMETRY_NET_ONLINE -> {
val httpClient = get<OkHttpClient>(Named.defaultHttpClient)
Expand Down
68 changes: 33 additions & 35 deletions desktop/src/app/image/image.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -522,40 +522,38 @@
<label>Radius (°)</label>
</p-floatLabel>
</div>
@if (solver.request.type !== 'ASTAP') {
<div class="col-6 flex flex-row align-items-center">
<p-floatLabel>
<p-inputNumber
[min]="0"
[max]="10000"
styleClass="p-inputtext-sm border-0 w-full"
[showButtons]="true"
[(ngModel)]="solver.request.focalLength"
[allowEmpty]="false"
locale="en"
(ngModelChange)="savePreference()"
spinnableNumber />
<label>Focal length (mm)</label>
</p-floatLabel>
</div>
<div class="col-6 flex flex-row align-items-center">
<p-floatLabel>
<p-inputNumber
[min]="0"
[max]="100"
[step]="0.01"
[minFractionDigits]="1"
styleClass="p-inputtext-sm border-0 w-full"
[showButtons]="true"
[(ngModel)]="solver.request.pixelSize"
[allowEmpty]="false"
locale="en"
(ngModelChange)="savePreference()"
spinnableNumber />
<label>Pixel size (µm)</label>
</p-floatLabel>
</div>
}
<div class="col-6 flex flex-row align-items-center">
<p-floatLabel>
<p-inputNumber
[min]="0"
[max]="10000"
styleClass="p-inputtext-sm border-0 w-full"
[showButtons]="true"
[(ngModel)]="solver.request.focalLength"
[allowEmpty]="false"
locale="en"
(ngModelChange)="savePreference()"
spinnableNumber />
<label>Focal length (mm)</label>
</p-floatLabel>
</div>
<div class="col-6 flex flex-row align-items-center">
<p-floatLabel>
<p-inputNumber
[min]="0"
[max]="100"
[step]="0.01"
[minFractionDigits]="1"
styleClass="p-inputtext-sm border-0 w-full"
[showButtons]="true"
[(ngModel)]="solver.request.pixelSize"
[allowEmpty]="false"
locale="en"
(ngModelChange)="savePreference()"
spinnableNumber />
<label>Pixel size (µm)</label>
</p-floatLabel>
</div>
</div>
<ng-template pTemplate="footer">
<div class="grid pt-2">
Expand Down Expand Up @@ -767,7 +765,7 @@
severity="info"
(onClick)="restoreAutoStretchMeanBackground()"
pTooltip="Reset"
tooltipPosition="bottom"/>
tooltipPosition="bottom" />
</div>
</div>
<ng-template pTemplate="footer">
Expand Down
2 changes: 2 additions & 0 deletions desktop/src/app/image/image.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1171,6 +1171,8 @@ export class ImageComponent implements AfterViewInit, OnDestroy {
...this.solver.request,
...this.preferenceService.settings.get().plateSolver[this.solver.request.type],
type: this.solver.request.type,
width: this.imageInfo?.width ?? 0,
height: this.imageInfo?.height ?? 0,
}

const solved = await this.api.solverStart(request, path, this.solver.key)
Expand Down
4 changes: 4 additions & 0 deletions desktop/src/shared/types/platesolver.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export interface PlateSolverRequest extends PlateSolverSettings {
radius: Angle
pixelSize: number
focalLength: number
width: number
height: number
}

export const NOVA_ASTROMETRY_NET_URL = 'https://nova.astrometry.net/'
Expand All @@ -41,6 +43,8 @@ export const DEFAULT_PLATE_SOLVER_REQUEST: PlateSolverRequest = {
radius: 4,
focalLength: 0,
pixelSize: 0,
width: 0,
height: 0,
}

export function plateSolverSettingsWithDefault(settings?: Partial<PlateSolverSettings>, source: PlateSolverSettings = DEFAULT_PLATE_SOLVER_SETTINGS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ import kotlin.math.ceil
/**
* @see <a href="https://www.hnsky.org/astap.htm#astap_command_line">README</a>
*/
data class AstapPlateSolver(private val executablePath: Path) : PlateSolver {
data class AstapPlateSolver(
private val executablePath: Path,
private val fov: Angle = 0.0,
) : PlateSolver {

override fun solve(
path: Path?, image: Image?,
Expand All @@ -43,7 +46,7 @@ data class AstapPlateSolver(private val executablePath: Path) : PlateSolver {
"$executablePath",
"-o", "$outFile",
"-z", "$downsampleFactor",
"-fov", "0", // auto
"-fov", if (fov <= 0.0) "0" else "${fov.toDegrees}",
)

if (radius.toDegrees >= 0.1 && centerRA.isFinite() && centerDEC.isFinite()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ data class LocalAstrometryNetPlateSolver(
) : PlateSolver {

constructor(executablePath: Path, focalLength: Double, pixelSize: Double) :
this(executablePath, if (focalLength <= 0.0) 0.0 else (pixelSize / focalLength) * 206.265)
this(executablePath, PlateSolver.computeFOV(focalLength, pixelSize))

override fun solve(
path: Path?, image: Image?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ data class NovaAstrometryNetPlateSolver(
private val apiKey: String = "",
private val focalLength: Double = 0.0, // mm
private val pixelSize: Double = 0.0, // / µm
private val scale: Double = if (focalLength <= 0.0) 0.0 else (pixelSize / focalLength) * 206.265,
private val scale: Double = PlateSolver.computeFOV(focalLength, pixelSize),
) : PlateSolver {

@Volatile private var session: Session? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,14 @@ interface PlateSolver {
centerRA: Angle = 0.0, centerDEC: Angle = 0.0, radius: Angle = 0.0,
downsampleFactor: Int = 0, timeout: Duration = Duration.ZERO,
): PlateSolution

companion object {

/**
* Computes the FOV in arcsec/pixel from [focalLength] in mm and [pixelSize] in µm.
*/
fun computeFOV(focalLength: Double, pixelSize: Double): Double {
return if (focalLength <= 0.0) 0.0 else (pixelSize / focalLength) * 206.265
}
}
}

0 comments on commit 0c499b4

Please sign in to comment.