diff --git a/build.gradle.kts b/build.gradle.kts index 34aa5ed..c582615 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -12,7 +12,7 @@ allprojects { version = "0.1.0-dev-1" } -val dataforgeVersion by extra("0.5.2-dev-4") +val dataforgeVersion by extra("0.5.2") val kmathVersion by extra("0.3.0-dev-17") val plotlyVersion: String by extra("0.5.0") diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 83b31b1..2f0a5a8 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -11,5 +11,5 @@ repositories { dependencies { api("com.squareup.wire:wire-gradle-plugin:3.7.1") - api("ru.mipt.npm:gradle-tools:0.10.8-kotlin-1.6.0") + api("ru.mipt.npm:gradle-tools:0.10.7") } diff --git a/numass-analysis/build.gradle.kts b/numass-analysis/build.gradle.kts index e30b106..bc40184 100644 --- a/numass-analysis/build.gradle.kts +++ b/numass-analysis/build.gradle.kts @@ -12,6 +12,7 @@ kotlin.sourceSets { commonMain { dependencies { api(project(":numass-data-model")) + api("space.kscience:dataforge-io:$dataforgeVersion") api("space.kscience:tables-kt:0.1.1-dev-2") api("space.kscience:kmath-complex:$kmathVersion") api("space.kscience:kmath-stat:$kmathVersion") diff --git a/numass-data-proto/src/main/kotlin/ru/inr/mass/data/proto/ProtoNumassPoint.kt b/numass-data-proto/src/main/kotlin/ru/inr/mass/data/proto/ProtoNumassPoint.kt index f3f0507..f9faf3c 100644 --- a/numass-data-proto/src/main/kotlin/ru/inr/mass/data/proto/ProtoNumassPoint.kt +++ b/numass-data-proto/src/main/kotlin/ru/inr/mass/data/proto/ProtoNumassPoint.kt @@ -30,6 +30,7 @@ import space.kscience.dataforge.meta.* import java.io.ByteArrayInputStream import java.io.ByteArrayOutputStream import java.io.InputStream +import java.nio.ByteOrder import java.util.zip.Inflater import kotlin.time.Duration import kotlin.time.Duration.Companion.milliseconds @@ -46,11 +47,19 @@ internal class ProtoNumassPoint( val point: Point by lazy(protoBuilder) - override fun flowBlocks() = point.channels.flatMap { channel -> - channel.blocks - .map { block -> ProtoNumassBlock(channel.id.toInt(), block, this) } - .sortedBy { it.startTime } - }.asFlow() + override fun flowBlocks(): Flow { + val frameByteOrder = if (meta["tqdc"] != null) { + ByteOrder.LITTLE_ENDIAN + } else { + ByteOrder.BIG_ENDIAN + } + + return point.channels.flatMap { channel -> + channel.blocks + .map { block -> ProtoNumassBlock(channel.id.toInt(), block, this, frameByteOrder) } + .sortedBy { it.startTime } + }.asFlow() + } override suspend fun getChannels(): Map = point.channels.groupBy { it.id.toInt() }.mapValues { entry -> @@ -120,10 +129,12 @@ internal class ProtoNumassPoint( } public fun fromEnvelope(envelope: Envelope): ProtoNumassPoint? { - val proto = envelope.useData { - Point.ADAPTER.decode(it) + if (envelope.data == null) return null + return ProtoNumassPoint(envelope.meta) { + envelope.useData { + Point.ADAPTER.decode(it) + } ?: error("Data is empty") } - return proto?.let { ProtoNumassPoint(envelope.meta) { it } } } } } @@ -133,6 +144,7 @@ public class ProtoNumassBlock( override val channel: Int, private val block: Point.Channel.Block, private val parent: NumassPoint? = null, + private val frameByteOrder: ByteOrder = ByteOrder.BIG_ENDIAN, ) : NumassBlock { override val startTime: Instant @@ -176,7 +188,9 @@ public class ProtoNumassBlock( } private fun ByteString.toShortArray(): ShortArray { - val shortBuffer = asByteBuffer().asShortBuffer() + val shortBuffer = asByteBuffer().apply { + order(frameByteOrder) + }.asShortBuffer() return if (shortBuffer.hasArray()) { shortBuffer.array() } else { diff --git a/numass-workspace/src/main/kotlin/ru/inr/mass/scripts/run_2021_11.kt b/numass-workspace/src/main/kotlin/ru/inr/mass/scripts/run_2021_11.kt new file mode 100644 index 0000000..f202f94 --- /dev/null +++ b/numass-workspace/src/main/kotlin/ru/inr/mass/scripts/run_2021_11.kt @@ -0,0 +1,54 @@ +package ru.inr.mass.scripts + +import kotlinx.coroutines.flow.toList +import kotlinx.html.code +import kotlinx.html.h2 +import kotlinx.html.p +import kotlinx.serialization.json.Json +import ru.inr.mass.workspace.readNumassDirectory +import space.kscience.dataforge.io.JsonMetaFormat +import space.kscience.dataforge.io.toString +import space.kscience.dataforge.meta.MetaSerializer +import space.kscience.plotly.* + +suspend fun main() { + //val repo: DataTree = readNumassRepository("D:\\Work\\numass-data\\") + val directory = readNumassDirectory("D:\\Work\\numass-data\\set_3\\") + val point = directory.points.first() + + val frames = point.frames.toList() + Plotly.page { + p { +"${frames.size} frames" } + h2 { +"Random frames" } + plot { + val random = kotlin.random.Random(1234) + + repeat(10) { + val frame = frames.random(random) + scatter { + y.numbers = frame.signal.map { it.toUShort().toInt() - Short.MAX_VALUE } + } + } + } + h2 { +"Analysis" } + plot { + histogram { + name="max" + x.numbers = frames.map { frame -> frame.signal.maxOf { it.toUShort().toInt() - Short.MAX_VALUE } } + } + + histogram { + name="max-min" + xbins{ + size = 2.0 + } + x.numbers = frames.map { frame -> + frame.signal.maxOf { it.toUShort().toInt() - Short.MAX_VALUE } - + frame.signal.minOf { it.toUShort().toInt() - Short.MAX_VALUE } + } + } + } + h2 { +"Meta" } + p { +Json.encodeToString(MetaSerializer, point.meta) } + }.makeFile() +} \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index fefa4b8..1a94292 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -10,7 +10,7 @@ dependencyResolutionManagement { versionCatalogs { create("npm") { - from("ru.mipt.npm:version-catalog:0.10.8-kotlin-1.6.0") + from("ru.mipt.npm:version-catalog:0.10.7") } } }