Skip to content

Commit

Permalink
[api]: Implement XISF read/write
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagohm committed Apr 1, 2024
1 parent b1817d6 commit d886ba7
Show file tree
Hide file tree
Showing 22 changed files with 336 additions and 309 deletions.
2 changes: 0 additions & 2 deletions api/src/main/kotlin/nebulosa/api/mounts/MountService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import nebulosa.nova.position.GeographicPosition
import nebulosa.nova.position.Geoid
import nebulosa.nova.position.ICRF
import nebulosa.time.CurrentTime
import nebulosa.time.TimeJD
import nebulosa.time.UTC
import nebulosa.wcs.WCS
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
Expand Down
9 changes: 5 additions & 4 deletions nebulosa-fits/src/main/kotlin/nebulosa/fits/FitsFormat.kt
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,15 @@ data object FitsFormat : ImageFormat {
Buffer().use { buffer ->
for (channel in 0 until data.numberOfChannels) {
for (i in 0 until data.numberOfPixels) {
buffer.writePixel(channels[0][i], bitpix)
buffer.writePixel(channels[channel][i], bitpix)

if (buffer.size >= 1024L) {
byteCount += buffer.readAll(sink)
}
}
}

byteCount += buffer.readAll(sink)
val remainingBytes = computeRemainingBytesToSkip(byteCount)

if (remainingBytes > 0) {
Expand Down Expand Up @@ -165,9 +166,9 @@ data object FitsFormat : ImageFormat {
internal fun Buffer.writePixel(pixel: Float, bitpix: Bitpix) {
when (bitpix) {
Bitpix.BYTE -> writeByte((pixel * 255f).toInt())
Bitpix.SHORT -> writeShort((pixel * 65535f).toInt())
Bitpix.INTEGER -> writeInt((pixel * 4294967295.0).toInt())
Bitpix.LONG -> TODO("Unsupported UInt64 sample format")
Bitpix.SHORT -> writeShort((pixel * 65535f).toInt() - 32768)
Bitpix.INTEGER -> writeInt(((pixel * 4294967295.0).toLong() - 2147483648L).toInt())
Bitpix.LONG -> TODO("Unsupported 64-bit format")
Bitpix.FLOAT -> writeFloat(pixel)
Bitpix.DOUBLE -> writeDouble(pixel.toDouble())
}
Expand Down
4 changes: 2 additions & 2 deletions nebulosa-fits/src/test/kotlin/FitsReadTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import nebulosa.fits.Bitpix
import nebulosa.fits.bitpix
import nebulosa.fits.fits
import nebulosa.image.format.ImageHdu
import nebulosa.test.FitsStringSpec
import nebulosa.test.AbstractFitsAndXisfTest

class FitsReadTest : FitsStringSpec() {
class FitsReadTest : AbstractFitsAndXisfTest() {

init {
"mono:8-bit" {
Expand Down
4 changes: 2 additions & 2 deletions nebulosa-fits/src/test/kotlin/FitsWriteTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import nebulosa.fits.fits
import nebulosa.image.format.ImageHdu
import nebulosa.io.sink
import nebulosa.io.source
import nebulosa.test.FitsStringSpec
import nebulosa.test.AbstractFitsAndXisfTest
import okio.ByteString.Companion.toByteString

class FitsWriteTest : FitsStringSpec() {
class FitsWriteTest : AbstractFitsAndXisfTest() {

init {
"mono" {
Expand Down
4 changes: 2 additions & 2 deletions nebulosa-image/src/test/kotlin/ComputationAlgorithmTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import nebulosa.image.Image
import nebulosa.image.algorithms.computation.MedianAbsoluteDeviation
import nebulosa.image.algorithms.computation.Statistics
import nebulosa.image.format.ImageChannel
import nebulosa.test.FitsStringSpec
import nebulosa.test.AbstractFitsAndXisfTest

class ComputationAlgorithmTest : FitsStringSpec() {
class ComputationAlgorithmTest : AbstractFitsAndXisfTest() {

init {
"mono:median absolute deviation" {
Expand Down
12 changes: 6 additions & 6 deletions nebulosa-image/src/test/kotlin/FitsTransformAlgorithmTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import nebulosa.image.Image
import nebulosa.image.algorithms.transformation.*
import nebulosa.image.algorithms.transformation.convolution.*
import nebulosa.image.format.ImageChannel
import nebulosa.test.FitsStringSpec
import nebulosa.test.AbstractFitsAndXisfTest

class FitsTransformAlgorithmTest : FitsStringSpec() {
class FitsTransformAlgorithmTest : AbstractFitsAndXisfTest() {

init {
"mono:raw" {
Expand Down Expand Up @@ -278,23 +278,23 @@ class FitsTransformAlgorithmTest : FitsStringSpec() {
nImage.save("fits-color-grayscale-y").second shouldBe "24dd4a7e0fa9e4be34c53c924a78a940"
}
"color:debayer" {
val mImage = Image.open(DEBAYER_FITS_PATH.fits())
val mImage = Image.open(DEBAYER_FITS.fits())
val nImage = mImage.transform(AutoScreenTransformFunction)
nImage.save("fits-color-debayer").second shouldBe "86b5bdd67dfd6bbf5495afae4bf2bc04"
}
"color:no-debayer" {
val mImage = Image.open(DEBAYER_FITS_PATH.fits(), false)
val mImage = Image.open(DEBAYER_FITS.fits(), false)
val nImage = mImage.transform(AutoScreenTransformFunction)
nImage.save("fits-color-no-debayer").second shouldBe "958ccea020deec1f0c075042a9ba37c3"
}
"color:reload" {
val mImage0 = Image.open(NGC3344_COLOR_32_FITS.fits())
var mImage1 = Image.open(DEBAYER_FITS_PATH.fits())
var mImage1 = Image.open(DEBAYER_FITS.fits())

mImage1.load(mImage0.hdu).shouldNotBeNull()
mImage1.save("fits-color-reload").second shouldBe "18fb83e240bc7a4cbafbc1aba2741db6"

mImage1 = Image.open(DEBAYER_FITS_PATH.fits(), false)
mImage1 = Image.open(DEBAYER_FITS.fits(), false)

mImage1.load(mImage0.hdu).shouldBeNull()
mImage0.load(mImage1.hdu).shouldBeNull()
Expand Down
7 changes: 4 additions & 3 deletions nebulosa-image/src/test/kotlin/HFDTest.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import io.kotest.matchers.floats.plusOrMinus
import io.kotest.matchers.shouldBe
import nebulosa.fits.fits
import nebulosa.image.Image
import nebulosa.image.algorithms.computation.hfd.HFD
import nebulosa.test.FitsStringSpec
import nebulosa.test.AbstractFitsAndXisfTest

class HFDTest : FitsStringSpec() {
class HFDTest : AbstractFitsAndXisfTest() {

init {
"focus" {
Expand All @@ -29,7 +30,7 @@ class HFDTest : FitsStringSpec() {
)

for ((first, second) in starFocus) {
val focusImage = Image.open(first)
val focusImage = Image.open(closeAfterEach(first.fits()))
val star = focusImage.compute(HFD(focusImage.width / 2, focusImage.height / 2, 50))
star.hfd shouldBe (second[0] plusOrMinus 0.1f)
star.snr shouldBe (second[1] plusOrMinus 0.1f)
Expand Down
12 changes: 6 additions & 6 deletions nebulosa-image/src/test/kotlin/XisfTransformAlgorithmTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import nebulosa.image.Image
import nebulosa.image.algorithms.transformation.*
import nebulosa.image.algorithms.transformation.convolution.*
import nebulosa.image.format.ImageChannel
import nebulosa.test.FitsStringSpec
import nebulosa.test.AbstractFitsAndXisfTest
import nebulosa.xisf.xisf

class XisfTransformAlgorithmTest : FitsStringSpec() {
class XisfTransformAlgorithmTest : AbstractFitsAndXisfTest() {

init {
"mono:raw" {
Expand Down Expand Up @@ -278,23 +278,23 @@ class XisfTransformAlgorithmTest : FitsStringSpec() {
nImage.save("xisf-color-grayscale-y").second shouldBe "7a2bef966d460742533a1c8c3a74f1c5"
}
"!color:debayer" {
val mImage = Image.open(DEBAYER_FITS_PATH.xisf())
val mImage = Image.open(DEBAYER_FITS.xisf())
val nImage = mImage.transform(AutoScreenTransformFunction)
nImage.save("xisf-color-debayer").second shouldBe "86b5bdd67dfd6bbf5495afae4bf2bc04"
}
"!color:no-debayer" {
val mImage = Image.open(DEBAYER_FITS_PATH.xisf(), false)
val mImage = Image.open(DEBAYER_FITS.xisf(), false)
val nImage = mImage.transform(AutoScreenTransformFunction)
nImage.save("xisf-color-no-debayer").second shouldBe "958ccea020deec1f0c075042a9ba37c3"
}
"!color:reload" {
val mImage0 = Image.open(M82_COLOR_32_XISF.xisf())
var mImage1 = Image.open(DEBAYER_FITS_PATH.xisf())
var mImage1 = Image.open(DEBAYER_FITS.xisf())

mImage1.load(mImage0.hdu).shouldNotBeNull()
mImage1.save("xisf-color-reload").second shouldBe "18fb83e240bc7a4cbafbc1aba2741db6"

mImage1 = Image.open(DEBAYER_FITS_PATH.xisf(), false)
mImage1 = Image.open(DEBAYER_FITS.xisf(), false)

mImage1.load(mImage0.hdu).shouldBeNull()
mImage0.load(mImage1.hdu).shouldBeNull()
Expand Down
5 changes: 4 additions & 1 deletion nebulosa-nova/src/test/kotlin/ICRFTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import io.kotest.matchers.shouldBe
import nebulosa.math.*
import nebulosa.nova.position.Geoid
import nebulosa.nova.position.ICRF
import nebulosa.time.*
import nebulosa.time.IERS
import nebulosa.time.IERSA
import nebulosa.time.TT
import nebulosa.time.TimeYMDHMS
import java.nio.file.Path
import kotlin.io.path.inputStream

Expand Down
Loading

0 comments on commit d886ba7

Please sign in to comment.