Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagohm committed Jun 13, 2024
2 parents bc81dd8 + 591e2b8 commit b122c89
Show file tree
Hide file tree
Showing 242 changed files with 6,030 additions and 1,324 deletions.
2 changes: 2 additions & 0 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ dependencies {
implementation(project(":nebulosa-log"))
implementation(project(":nebulosa-lx200-protocol"))
implementation(project(":nebulosa-nova"))
implementation(project(":nebulosa-pixinsight"))
implementation(project(":nebulosa-sbd"))
implementation(project(":nebulosa-simbad"))
implementation(project(":nebulosa-siril"))
implementation(project(":nebulosa-stellarium-protocol"))
implementation(project(":nebulosa-wcs"))
implementation(project(":nebulosa-xisf"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import nebulosa.indi.device.camera.Camera
import nebulosa.indi.device.camera.CameraEvent
import nebulosa.indi.device.camera.FrameType
import nebulosa.indi.device.guide.GuideOutput
import nebulosa.indi.device.mount.Mount
import nebulosa.log.loggerFor
import java.nio.file.Files
import java.time.Duration
Expand Down Expand Up @@ -64,7 +65,7 @@ data class DARVTask(
override fun execute(cancellationToken: CancellationToken) {
LOG.info("DARV started. camera={}, guideOutput={}, request={}", camera, guideOutput, request)

camera.snoop(listOf(guideOutput))
if (guideOutput is Mount) camera.snoop(camera.snoopedDevices.filter { it !is Mount } + guideOutput)

val task = SplitTask(listOf(cameraCaptureTask, Task.of(delayTask, forwardGuidePulseTask, backwardGuidePulseTask)), executor)
task.execute(cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import jakarta.validation.Valid
import jakarta.validation.constraints.NotNull
import nebulosa.api.cameras.CameraStartCaptureRequest
import nebulosa.api.solver.PlateSolverOptions
import nebulosa.api.platesolver.PlateSolverRequest
import nebulosa.guiding.GuideDirection
import org.hibernate.validator.constraints.time.DurationMin
import org.springframework.boot.convert.DurationUnit
Expand All @@ -13,7 +13,7 @@ import java.time.temporal.ChronoUnit

data class TPPAStartRequest(
@JsonIgnoreProperties("camera", "focuser", "wheel") @JvmField val capture: CameraStartCaptureRequest = CameraStartCaptureRequest.EMPTY,
@field:NotNull @Valid @JvmField val plateSolver: PlateSolverOptions = PlateSolverOptions.EMPTY,
@field:NotNull @Valid @JvmField val plateSolver: PlateSolverRequest = PlateSolverRequest.EMPTY,
@JvmField val startFromCurrentPosition: Boolean = true,
@JvmField val compensateRefraction: Boolean = false,
@JvmField val stopTrackingWhenDone: Boolean = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import nebulosa.log.loggerFor
import nebulosa.math.Angle
import nebulosa.math.formatHMS
import nebulosa.math.formatSignedDMS
import nebulosa.plate.solving.PlateSolver
import nebulosa.platesolver.PlateSolver
import java.nio.file.Files
import java.nio.file.Path
import java.time.Duration
Expand Down Expand Up @@ -84,7 +84,7 @@ data class TPPATask(
captureEvent = event

if (event.state == CameraCaptureState.EXPOSURE_FINISHED) {
savedImage = event.savePath!!
savedImage = event.savedPath!!
}

if (!finished.get()) {
Expand All @@ -110,7 +110,7 @@ data class TPPATask(
rightAscension = mount?.rightAscension ?: 0.0
declination = mount?.declination ?: 0.0

camera.snoop(listOf(mount))
camera.snoop(camera.snoopedDevices.filter { it !is Mount } + mount)

cancellationToken.listenToPause(this)

Expand Down
22 changes: 4 additions & 18 deletions api/src/main/kotlin/nebulosa/api/atlas/SatelliteRepository.kt
Original file line number Diff line number Diff line change
@@ -1,32 +1,18 @@
package nebulosa.api.atlas

import io.objectbox.Box
import io.objectbox.query.QueryBuilder.StringOrder.CASE_INSENSITIVE
import io.objectbox.query.QueryBuilder.StringOrder.CASE_SENSITIVE
import io.objectbox.query.QueryCondition
import nebulosa.api.repositories.BoxRepository
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.stereotype.Component

@Component
class SatelliteRepository(@Qualifier("satelliteBox") override val box: Box<SatelliteEntity>) : BoxRepository<SatelliteEntity>() {

fun search(text: String? = null, groups: List<SatelliteGroupType> = emptyList()): List<SatelliteEntity> {
val builder = box.query()
.also { if (!text.isNullOrBlank()) it.contains(SatelliteEntity_.name, text, CASE_INSENSITIVE) }
fun search(text: String? = null, groups: Iterable<SatelliteGroupType> = emptyList()): List<SatelliteEntity> {
val groupCondition = or(groups.map { SatelliteEntity_.groups.containsElement(it.name, CASE_SENSITIVE) })
val condition = and(if (text.isNullOrBlank()) null else SatelliteEntity_.name.containsInsensitive(text), groupCondition)

if (groups.isNotEmpty()) {
var condition: QueryCondition<SatelliteEntity> = SatelliteEntity_.groups.containsElement(groups[0].name, CASE_SENSITIVE)

for (i in 1 until groups.size) {
condition = condition.or(SatelliteEntity_.groups.containsElement(groups[i].name, CASE_SENSITIVE))
}

builder.apply(condition)
}

return builder
.build()
.use { it.findLazy() }
return (condition?.let(box::query) ?: box.query()).build().use { it.findLazy() }
}
}
43 changes: 16 additions & 27 deletions api/src/main/kotlin/nebulosa/api/atlas/SimbadEntityRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,38 @@ package nebulosa.api.atlas

import io.objectbox.Box
import io.objectbox.kotlin.equal
import io.objectbox.query.QueryBuilder.StringOrder.CASE_INSENSITIVE
import io.objectbox.query.QueryFilter
import nebulosa.api.repositories.BoxRepository
import nebulosa.math.Angle
import nebulosa.math.toDegrees
import nebulosa.nova.astrometry.Constellation
import nebulosa.skycatalog.SkyObject
import nebulosa.skycatalog.SkyObjectInsideCoordinate
import nebulosa.skycatalog.SkyObjectType
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.stereotype.Component

@Component
class SimbadEntityRepository(@Qualifier("simbadEntityBox") override val box: Box<SimbadEntity>) : BoxRepository<SimbadEntity>() {
class SimbadEntityRepository(@Qualifier("simbadBox") override val box: Box<SimbadEntity>) : BoxRepository<SimbadEntity>() {

fun find(
name: String? = null, constellation: Constellation? = null,
rightAscension: Angle = 0.0, declination: Angle = 0.0, radius: Angle = 0.0,
magnitudeMin: Double = SkyObject.MAGNITUDE_MIN, magnitudeMax: Double = SkyObject.MAGNITUDE_MAX,
type: SkyObjectType? = null,
): List<SimbadEntity> {
val useFilter = radius > 0.0 && radius.toDegrees > 0.1

return box.query()
.also {
if (magnitudeMin in SkyObject.MAGNITUDE_RANGE) it.greaterOrEqual(SimbadEntity_.magnitude, magnitudeMin)
if (magnitudeMax in SkyObject.MAGNITUDE_RANGE) it.lessOrEqual(SimbadEntity_.magnitude, magnitudeMax)
if (type != null) it.equal(SimbadEntity_.type, type.ordinal)
if (constellation != null) it.equal(SimbadEntity_.constellation, constellation.ordinal)

if (!name.isNullOrBlank()) {
it.contains(SimbadEntity_.name, name, CASE_INSENSITIVE)
}

if (useFilter) it.filter(object : QueryFilter<SimbadEntity> {
private val filter = SkyObjectInsideCoordinate(rightAscension, declination, radius)

override fun keep(entity: SimbadEntity) = filter.test(entity)
})

it.order(SimbadEntity_.magnitude)
}
.build()
.use { if (useFilter) it.find() else it.find(0, 5000) }
val useFilter = radius > 0.0 && radius.toDegrees in 0.1..90.0

val condition = and(
if (magnitudeMin in SkyObject.MAGNITUDE_RANGE) SimbadEntity_.magnitude.greaterOrEqual(magnitudeMin) else null,
if (magnitudeMax in SkyObject.MAGNITUDE_RANGE) SimbadEntity_.magnitude.lessOrEqual(magnitudeMax) else null,
if (type != null) SimbadEntity_.type equal type.ordinal else null,
if (constellation != null) SimbadEntity_.constellation equal constellation.ordinal else null,
if (name.isNullOrBlank()) null else SimbadEntity_.name containsInsensitive name,
)

return with(condition?.let(box::query) ?: box.query()) {
if (useFilter) filter(SkyObjectInsideCoordinate(rightAscension, declination, radius))
order(SimbadEntity_.magnitude)
build()
}.use { if (useFilter) it.find() else it.find(0, 5000) }
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package nebulosa.skycatalog
package nebulosa.api.atlas

import io.objectbox.query.QueryFilter
import nebulosa.math.Angle
import nebulosa.math.cos
import nebulosa.math.sin
Expand All @@ -11,12 +12,12 @@ data class SkyObjectInsideCoordinate(
private val rightAscension: Angle,
private val declination: Angle,
private val radius: Angle,
) : SkyObjectFilter {
) : QueryFilter<SimbadEntity> {

private val sinDEC = declination.sin
private val cosDEC = declination.cos

override fun test(o: SkyObject): Boolean {
override fun keep(o: SimbadEntity): Boolean {
return acos(sin(o.declinationJ2000) * sinDEC + cos(o.declinationJ2000) * cosDEC * cos(o.rightAscensionJ2000 - rightAscension)) <= radius
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package nebulosa.api.autofocus

import nebulosa.api.cameras.CameraStartCaptureRequest
import nebulosa.api.focusers.BacklashCompensation
import nebulosa.api.stardetection.StarDetectionOptions
import nebulosa.api.stardetector.StarDetectionRequest

data class AutoFocusRequest(
@JvmField val fittingMode: AutoFocusFittingMode = AutoFocusFittingMode.HYPERBOLIC,
Expand All @@ -12,5 +12,5 @@ data class AutoFocusRequest(
@JvmField val initialOffsetSteps: Int = 4,
@JvmField val stepSize: Int = 50,
@JvmField val totalNumberOfAttempts: Int = 1,
@JvmField val starDetector: StarDetectionOptions = StarDetectionOptions.EMPTY,
@JvmField val starDetector: StarDetectionRequest = StarDetectionRequest.EMPTY,
)
10 changes: 5 additions & 5 deletions api/src/main/kotlin/nebulosa/api/autofocus/AutoFocusTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import nebulosa.indi.device.camera.FrameType
import nebulosa.indi.device.focuser.Focuser
import nebulosa.indi.device.focuser.FocuserEvent
import nebulosa.log.loggerFor
import nebulosa.star.detection.ImageStar
import nebulosa.star.detection.StarDetector
import nebulosa.stardetector.StarDetector
import nebulosa.stardetector.StarPoint
import java.nio.file.Files
import java.nio.file.Path
import java.time.Duration
Expand Down Expand Up @@ -85,7 +85,7 @@ data class AutoFocusTask(
var numberOfAttempts = 0
val maximumFocusPoints = request.capture.exposureAmount * request.initialOffsetSteps * 10

// camera.snoop(listOf(focuser))
camera.snoop(camera.snoopedDevices.filter { it !is Focuser } + focuser)

while (!exited && !cancellationToken.isCancelled) {
numberOfAttempts++
Expand Down Expand Up @@ -220,7 +220,7 @@ data class AutoFocusTask(
if (event.state == CameraCaptureState.EXPOSURE_FINISHED) {
sendEvent(AutoFocusState.EXPOSURED, event)
sendEvent(AutoFocusState.ANALYSING)
val detectedStars = starDetection.detect(event.savePath!!)
val detectedStars = starDetection.detect(event.savedPath!!)
starCount = detectedStars.size
LOG.info("detected $starCount stars")
starHFD = detectedStars.measureDetectedStars()
Expand Down Expand Up @@ -401,7 +401,7 @@ data class AutoFocusTask(
}

@JvmStatic
private fun List<ImageStar>.measureDetectedStars(): Double {
private fun List<StarPoint>.measureDetectedStars(): Double {
return if (isEmpty()) 0.0
else if (size == 1) this[0].hfd
else if (size == 2) (this[0].hfd + this[1].hfd) / 2.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.module.SimpleModule
import com.fasterxml.jackson.databind.ser.std.StdSerializer
import com.fasterxml.jackson.module.kotlin.kotlinModule
import io.objectbox.BoxStore
import io.objectbox.kotlin.boxFor
import nebulosa.api.atlas.SatelliteEntity
import nebulosa.api.atlas.SimbadEntity
import nebulosa.api.calibration.CalibrationFrameEntity
Expand Down Expand Up @@ -170,16 +171,16 @@ class BeanConfiguration {
.build()!!

@Bean
fun calibrationFrameBox(boxStore: BoxStore) = boxStore.boxFor(CalibrationFrameEntity::class.java)!!
fun calibrationFrameBox(boxStore: BoxStore) = boxStore.boxFor<CalibrationFrameEntity>()

@Bean
fun preferenceBox(boxStore: BoxStore) = boxStore.boxFor(PreferenceEntity::class.java)!!
fun preferenceBox(boxStore: BoxStore) = boxStore.boxFor<PreferenceEntity>()

@Bean
fun satelliteBox(boxStore: BoxStore) = boxStore.boxFor(SatelliteEntity::class.java)!!
fun satelliteBox(boxStore: BoxStore) = boxStore.boxFor<SatelliteEntity>()

@Bean
fun simbadEntityBox(@Qualifier("simbadBoxStore") boxStore: BoxStore) = boxStore.boxFor(SimbadEntity::class.java)!!
fun simbadBox(@Qualifier("simbadBoxStore") boxStore: BoxStore) = boxStore.boxFor<SimbadEntity>()

@Bean
fun webMvcConfigurer(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package nebulosa.api.beans.converters.angle

class DeclinationDeserializer : AngleDeserializer(true)
class DeclinationDeserializer : AngleDeserializer(false)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package nebulosa.api.beans.converters.angle

class DegreesDeserializer : AngleDeserializer(false, defaultValue = 0.0)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package nebulosa.api.calibration

interface CalibrationFrameProvider {

fun findBestDarkFrames(
name: String, temperature: Double, width: Int, height: Int,
binX: Int, binY: Int = binX, exposureTimeInMicroseconds: Long = 0L,
gain: Double = 0.0,
): List<CalibrationFrameEntity>

fun findBestFlatFrames(
name: String, width: Int, height: Int,
binX: Int, binY: Int = binX, filter: String? = null
): List<CalibrationFrameEntity>

fun findBestBiasFrames(
name: String, width: Int, height: Int,
binX: Int, binY: Int = binX, gain: Double = 0.0,
): List<CalibrationFrameEntity>
}
Loading

0 comments on commit b122c89

Please sign in to comment.