Skip to content

Commit

Permalink
[api][desktop]: Determinate parity from Plate solution CD matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagohm committed Oct 24, 2024
1 parent 4c6a0e6 commit 878c2dc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
3 changes: 3 additions & 0 deletions api/src/main/kotlin/nebulosa/api/image/ImageSolved.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package nebulosa.api.image

import nebulosa.math.*
import nebulosa.platesolver.Parity
import nebulosa.platesolver.PlateSolution

data class ImageSolved(
Expand All @@ -12,6 +13,7 @@ data class ImageSolved(
@JvmField val width: Double = 0.0,
@JvmField val height: Double = 0.0,
@JvmField val radius: Double = 0.0,
@JvmField val parity: Parity = Parity.NORMAL,
) {

constructor(solution: PlateSolution) : this(
Expand All @@ -22,6 +24,7 @@ data class ImageSolved(
solution.declination.formatSignedDMS(),
solution.width.toArcmin, solution.height.toArcmin,
solution.radius.toDegrees,
solution.parity,
)

companion object {
Expand Down
4 changes: 4 additions & 0 deletions desktop/src/shared/types/image.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export type ImageFilterType = 'LUMINANCE' | 'RED' | 'GREEN' | 'BLUE' | 'MONO' |

export type BayerPattern = 'RGGB' | 'BGGR' | 'GBRG' | 'GRBG' | 'GRGB' | 'GBGR' | 'RGBG' | 'BGRG'

export type Parity = 'NORMAL' | 'FLIPPED'

export type ImageMousePosition = Point

export interface Image {
Expand Down Expand Up @@ -85,6 +87,7 @@ export interface ImageSolved extends EquatorialCoordinateJ2000 {
width: number
height: number
radius: number
parity: Parity
}

export interface CoordinateInterpolation {
Expand Down Expand Up @@ -363,6 +366,7 @@ export const DEFAULT_IMAGE_SOLVED: ImageSolved = {
radius: 0,
rightAscensionJ2000: '00h00m00s',
declinationJ2000: '+000°00\'00"',
parity: 'NORMAL',
}

export const DEFAULT_IMAGE_STRETCH: ImageStretch = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,19 @@ data class PlateSolution(
fun from(header: ReadableHeader): PlateSolution? {
val crval1 = header.getDoubleOrNull(FitsKeyword.CRVAL1)?.deg ?: return null
val crval2 = header.getDoubleOrNull(FitsKeyword.CRVAL2)?.deg ?: return null
val (cd11, cd12, _, cd22) = header.computeCdMatrix()
val (cd11, cd12, cd21, cd22) = header.computeCdMatrix()
val crota2 = header.getDoubleOrNull(FitsKeyword.CROTA2)?.deg ?: atan2(cd12, cd11).rad
// https://danmoser.github.io/notes/gai_fits-imgs.html
val cdelt1 = header.getDoubleOrNull(FitsKeyword.CDELT1)?.deg ?: (cd11 / cos(crota2)).deg
val cdelt2 = header.getDoubleOrNull(FitsKeyword.CDELT2)?.deg ?: (cd22 / cos(crota2)).deg
val width = header.getIntOrNull(FitsKeyword.NAXIS1) ?: header.getInt("IMAGEW", 0)
val height = header.getIntOrNull(FitsKeyword.NAXIS2) ?: header.getInt("IMAGEH", 0)
val parity = if ((cd11 * cd22 - cd12 * cd21) >= 0.0) Parity.NORMAL else Parity.FLIPPED

LOG.d("solution from {}: ORIE={}, SCALE={}, RA={}, DEC={}", header, crota2.formatSignedDMS(), cdelt2.toArcsec, crval1.formatHMS(), crval2.formatSignedDMS())
LOG.d("solution from {}: ORIE={}, SCALE={}, RA={}, DEC={}, PARITY={}", header, crota2, cdelt2, crval1, crval2, parity)

return PlateSolution(
true, crota2, cdelt2, crval1, crval2, abs(cdelt1 * width), abs(cdelt2 * height),
true, crota2, cdelt2, crval1, crval2, abs(cdelt1 * width), abs(cdelt2 * height), parity,
widthInPixels = width.toDouble(), heightInPixels = height.toDouble(), header = header
)
}
Expand Down

0 comments on commit 878c2dc

Please sign in to comment.