Skip to content

Commit

Permalink
[api][desktop]: Remove Stacker
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagohm committed Oct 15, 2024
1 parent b1b7278 commit f4d035b
Show file tree
Hide file tree
Showing 43 changed files with 71 additions and 1,327 deletions.
2 changes: 1 addition & 1 deletion api/src/main/kotlin/nebulosa/api/Nebulosa.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import io.javalin.Javalin
import io.javalin.http.Context
import io.javalin.http.HttpStatus.BAD_REQUEST
import io.javalin.json.JavalinJackson
import nebulosa.api.converters.modules.DeviceModule
import nebulosa.api.converters.DeviceModule
import nebulosa.api.core.ErrorResponse
import nebulosa.api.inject.*
import nebulosa.json.PathModule
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package nebulosa.api.cameras

import nebulosa.api.calibration.CalibrationFrameProvider
import nebulosa.api.image.ImageFilterType
import nebulosa.api.livestacker.LiveStackingRequest
import nebulosa.api.stacker.StackerGroupType
import nebulosa.fits.*
import nebulosa.image.format.ImageHdu
import nebulosa.livestacker.LiveStacker
Expand All @@ -20,7 +20,7 @@ data class CameraLiveStackingManager(
private val calibrationFrameProvider: CalibrationFrameProvider? = null,
) : AutoCloseable {

private val liveStackers = EnumMap<StackerGroupType, LiveStacker>(StackerGroupType::class.java)
private val liveStackers = EnumMap<ImageFilterType, LiveStacker>(ImageFilterType::class.java)
private val workingDirectories = HashSet<Path>()

@Volatile private var referencePath: Path? = null
Expand All @@ -29,7 +29,7 @@ data class CameraLiveStackingManager(
fun start(request: CameraStartCaptureRequest, path: Path): Boolean {
if (request.stackerGroupType in liveStackers) {
return true
} else if (request.stackerGroupType != StackerGroupType.NONE && request.liveStacking.enabled) {
} else if (request.stackerGroupType != ImageFilterType.NONE && request.liveStacking.enabled) {
try {
val workingDirectory = Files.createTempDirectory("ls-${request.stackerGroupType}-")
workingDirectories.add(workingDirectory)
Expand All @@ -50,7 +50,7 @@ data class CameraLiveStackingManager(

@Synchronized
fun stack(request: CameraStartCaptureRequest, path: Path?): Path? {
if (path == null || request.stackerGroupType == StackerGroupType.NONE) return null
if (path == null || request.stackerGroupType == ImageFilterType.NONE) return null

val stackerGroupType = request.stackerGroupType
val liveStacker = liveStackers[stackerGroupType] ?: return null
Expand All @@ -65,10 +65,10 @@ data class CameraLiveStackingManager(
}

val combinedPath = Path.of("${path.parent}", "STACKED.fits")
val luminancePath = liveStackers[StackerGroupType.LUMINANCE]?.stackedPath
val redPath = liveStackers[StackerGroupType.RED]?.stackedPath
val greenPath = liveStackers[StackerGroupType.GREEN]?.stackedPath
val bluePath = liveStackers[StackerGroupType.BLUE]?.stackedPath
val luminancePath = liveStackers[ImageFilterType.LUMINANCE]?.stackedPath
val redPath = liveStackers[ImageFilterType.RED]?.stackedPath
val greenPath = liveStackers[ImageFilterType.GREEN]?.stackedPath
val bluePath = liveStackers[ImageFilterType.BLUE]?.stackedPath

if (stackerGroupType.isLRGB && (luminancePath != null || redPath != null || greenPath != null || bluePath != null)) {
if (stacker.combineLRGB(combinedPath, luminancePath, redPath, greenPath, bluePath)) {
Expand All @@ -77,7 +77,7 @@ data class CameraLiveStackingManager(
} else if (luminancePath != null) {
stacker.align(luminancePath, stackedPath, stackedPath)

if (stacker.combineLuminance(combinedPath, luminancePath, stackedPath, stackerGroupType == StackerGroupType.MONO)) {
if (stacker.combineLuminance(combinedPath, luminancePath, stackedPath, stackerGroupType == ImageFilterType.MONO)) {
stackedPath = combinedPath
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package nebulosa.api.cameras

import nebulosa.api.converters.time.DurationUnit
import nebulosa.api.guiding.DitherAfterExposureRequest
import nebulosa.api.image.ImageFilterType
import nebulosa.api.livestacker.LiveStackingRequest
import nebulosa.api.stacker.StackerGroupType
import nebulosa.api.validators.*
import nebulosa.indi.device.camera.FrameType
import java.nio.file.Path
Expand Down Expand Up @@ -35,7 +35,7 @@ data class CameraStartCaptureRequest(
@JvmField val dither: DitherAfterExposureRequest = DitherAfterExposureRequest.DISABLED,
// Stacking.
@JvmField val liveStacking: LiveStackingRequest = LiveStackingRequest.DISABLED,
@JvmField val stackerGroupType: StackerGroupType = StackerGroupType.MONO,
@JvmField val stackerGroupType: ImageFilterType = ImageFilterType.MONO,
// Filter Wheel.
@JvmField val filterPosition: Int = 0,
@JvmField val shutterPosition: Int = 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nebulosa.api.converters.modules
package nebulosa.api.converters

import com.fasterxml.jackson.databind.module.SimpleDeserializers
import com.fasterxml.jackson.databind.module.SimpleModule
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package nebulosa.api.stacker
package nebulosa.api.image

import nebulosa.fits.*
import nebulosa.image.format.ReadableHeader
import nebulosa.indi.device.camera.FrameType
import nebulosa.indi.device.camera.FrameType.Companion.frameType

data class AnalyzedTarget(
data class ImageAnalyzed(
@JvmField val width: Int,
@JvmField val height: Int,
@JvmField val binX: Int,
@JvmField val binY: Int,
@JvmField val gain: Double,
@JvmField val exposureTime: Long,
@JvmField val type: FrameType,
@JvmField val group: StackerGroupType,
@JvmField val filter: ImageFilterType,
) {

constructor(header: ReadableHeader) : this(
header.width, header.height, header.binX, header.binY, header.gain, header.exposureTimeInMicroseconds,
header.frameType ?: FrameType.LIGHT, StackerGroupType.from(header)
header.frameType ?: FrameType.LIGHT, ImageFilterType.from(header)
)
}
6 changes: 6 additions & 0 deletions api/src/main/kotlin/nebulosa/api/image/ImageController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ImageController(
app.post("image", ::openImage)
app.delete("image", ::closeImage)
app.put("image/save-as", ::saveImageAs)
app.put("image/analyze", ::analyze)
app.put("image/annotations", ::annotations)
app.get("image/coordinate-interpolation", ::coordinateInterpolation)
app.get("image/histogram", ::histogram)
Expand All @@ -47,6 +48,11 @@ class ImageController(
imageService.saveImageAs(path, save)
}

private fun analyze(ctx: Context) {
val path = ctx.queryParam("path").notNull().path().exists()
imageService.analyze(path)?.also(ctx::json)
}

private fun annotations(ctx: Context) {
val path = ctx.queryParam("path").notNull().path().exists()
val request = ctx.bodyAsClass<AnnotateImageRequest>()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package nebulosa.api.stacker
package nebulosa.api.image

import nebulosa.fits.filter
import nebulosa.fits.naxis
import nebulosa.image.format.ReadableHeader

enum class StackerGroupType {
enum class ImageFilterType {
NONE,
LUMINANCE,
RED,
Expand Down
16 changes: 16 additions & 0 deletions api/src/main/kotlin/nebulosa/api/image/ImageService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import nebulosa.image.Image
import nebulosa.image.algorithms.computation.Histogram
import nebulosa.image.algorithms.computation.Statistics
import nebulosa.image.algorithms.transformation.*
import nebulosa.image.format.ImageHdu
import nebulosa.image.format.ImageModifier
import nebulosa.indi.device.camera.Camera
import nebulosa.log.*
Expand All @@ -31,6 +32,8 @@ import nebulosa.time.UTC
import nebulosa.wcs.WCS
import nebulosa.wcs.WCSException
import nebulosa.xisf.XisfFormat
import nebulosa.xisf.isXisf
import nebulosa.xisf.xisf
import okio.sink
import java.net.URI
import java.nio.file.Path
Expand All @@ -39,6 +42,8 @@ import java.util.*
import java.util.concurrent.CompletableFuture
import java.util.concurrent.ExecutorService
import javax.imageio.ImageIO
import kotlin.io.path.exists
import kotlin.io.path.isRegularFile
import kotlin.io.path.outputStream
import kotlin.math.roundToInt

Expand Down Expand Up @@ -299,6 +304,17 @@ class ImageService(
}
}

fun analyze(path: Path): ImageAnalyzed? {
if (!path.exists() || !path.isRegularFile()) return null

val image = if (path.isFits()) path.fits()
else if (path.isXisf()) path.xisf()
else return null

return image.use { it.firstOrNull { hdu -> hdu is ImageHdu }?.header }
?.let(::ImageAnalyzed)
}

fun frame(
rightAscension: Angle, declination: Angle,
width: Int, height: Int, fov: Angle,
Expand Down
4 changes: 0 additions & 4 deletions api/src/main/kotlin/nebulosa/api/inject/Inject.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ import nebulosa.api.rotators.RotatorService
import nebulosa.api.sequencer.SequencerController
import nebulosa.api.sequencer.SequencerExecutor
import nebulosa.api.sequencer.SequencerService
import nebulosa.api.stacker.StackerController
import nebulosa.api.stacker.StackerService
import nebulosa.api.stardetector.StarDetectionController
import nebulosa.api.stardetector.StarDetectionService
import nebulosa.api.wheels.WheelController
Expand Down Expand Up @@ -303,7 +301,6 @@ fun servicesModule() = module {
single { AutoFocusExecutor(get(), get(), get()) }
single { AutoFocusService(get()) }
single { LiveStackingService() }
single { StackerService(get()) }
single { FramingService(get(), get()) }
single { INDIService(get()) }
single { DARVExecutor(get(), get(), get()) }
Expand Down Expand Up @@ -341,7 +338,6 @@ fun controllersModule() = module(true) {
single { StarDetectionController(get(), get()) }
single { AutoFocusController(get(), get(), get()) }
single { LiveStackingController(get(), get(), get()) }
single { StackerController(get(), get()) }
single { FramingController(get(), get(), get()) }
single { INDIController(get(), get(), get()) }
single { PolarAlignmentController(get(), get(), get()) }
Expand Down
41 changes: 0 additions & 41 deletions api/src/main/kotlin/nebulosa/api/stacker/StackerController.kt

This file was deleted.

18 changes: 0 additions & 18 deletions api/src/main/kotlin/nebulosa/api/stacker/StackerEvent.kt

This file was deleted.

Loading

0 comments on commit f4d035b

Please sign in to comment.