Run 2021_11 reader
This commit is contained in:
parent
6b988f2849
commit
c73ada2c51
@ -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")
|
||||
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -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")
|
||||
|
@ -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 ->
|
||||
override fun flowBlocks(): Flow<ProtoNumassBlock> {
|
||||
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) }
|
||||
.map { block -> ProtoNumassBlock(channel.id.toInt(), block, this, frameByteOrder) }
|
||||
.sortedBy { it.startTime }
|
||||
}.asFlow()
|
||||
}
|
||||
|
||||
override suspend fun getChannels(): Map<Int, NumassBlock> =
|
||||
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 {
|
||||
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 {
|
||||
|
@ -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<NumassDirectorySet> = 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()
|
||||
}
|
@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user