Update code to be used with latest ecosystem versions.
This commit is contained in:
@@ -13,13 +13,13 @@ allprojects {
|
||||
}
|
||||
|
||||
group = "ru.inr.mass"
|
||||
version = "0.1.4-dev-3"
|
||||
version = "0.1.5"
|
||||
}
|
||||
|
||||
val dataforgeVersion by extra("0.6.2")
|
||||
val tablesVersion: String by extra("0.2.1")
|
||||
val kmathVersion by extra("0.3.1")
|
||||
val visionForgeVersion: String by rootProject.extra("0.3.0-dev-14")
|
||||
val dataforgeVersion by extra("0.10.1")
|
||||
val tablesVersion: String by extra("0.4.1")
|
||||
val kmathVersion by extra("0.4.2")
|
||||
val visionForgeVersion: String by rootProject.extra("0.4.2")
|
||||
|
||||
|
||||
ksciencePublish {
|
||||
@@ -27,7 +27,7 @@ ksciencePublish {
|
||||
useApache2Licence()
|
||||
useSPCTeam()
|
||||
}
|
||||
space("https://maven.pkg.jetbrains.space/spc/p/numass/maven")
|
||||
//space("https://maven.pkg.jetbrains.space/spc/p/numass/maven")
|
||||
//repository("spc","https://maven.sciprog.center/spc")
|
||||
}
|
||||
|
||||
|
||||
@@ -11,5 +11,5 @@ org.gradle.configureondemand=true
|
||||
org.gradle.parallel=true
|
||||
org.gradle.jvmargs=-XX:MaxMetaspaceSize=1G
|
||||
|
||||
toolsVersion=0.14.10-kotlin-1.9.0
|
||||
compose.version=1.5.3
|
||||
toolsVersion=0.16.1-kotlin-2.1.0
|
||||
compose.version=1.7.3
|
||||
|
||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
||||
@@ -52,7 +52,7 @@ public class NumassAnalyzerResult : Scheme() {
|
||||
|
||||
public var voltage: Double? by double(HV_KEY.asName())
|
||||
|
||||
public var parameters: NumassAnalyzerParameters by spec(NumassAnalyzerParameters)
|
||||
public var parameters: NumassAnalyzerParameters by scheme(NumassAnalyzerParameters)
|
||||
|
||||
public companion object : SchemeSpec<NumassAnalyzerResult>(::NumassAnalyzerResult)
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public class NumassAnalyzerParameters : Scheme() {
|
||||
public var deadTime: Double by double(0.0)
|
||||
public var window: UIntRange by uIntRange()
|
||||
|
||||
public var t0: TimeAnalyzerParameters by spec(TimeAnalyzerParameters)
|
||||
public var t0: TimeAnalyzerParameters by scheme(TimeAnalyzerParameters)
|
||||
|
||||
|
||||
public companion object : SchemeSpec<NumassAnalyzerParameters>(::NumassAnalyzerParameters)
|
||||
|
||||
@@ -16,14 +16,12 @@
|
||||
//
|
||||
package ru.inr.mass.data.analysis
|
||||
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.flow.*
|
||||
import ru.inr.mass.data.analysis.TimeAnalyzerParameters.AveragingMethod
|
||||
import ru.inr.mass.data.api.NumassBlock
|
||||
import ru.inr.mass.data.api.NumassEvent
|
||||
import ru.inr.mass.data.api.ParentBlock
|
||||
import space.kscience.kmath.streaming.asFlow
|
||||
import space.kscience.kmath.streaming.chunked
|
||||
import space.kscience.kmath.structures.Buffer
|
||||
import kotlin.math.*
|
||||
|
||||
|
||||
@@ -31,6 +29,7 @@ import kotlin.math.*
|
||||
* An analyzer which uses time information from events
|
||||
* Created by darksnake on 11.07.2017.
|
||||
*/
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
public open class TimeAnalyzer(
|
||||
override val extractor: NumassEventExtractor = NumassEventExtractor.EVENTS_ONLY,
|
||||
) : NumassAnalyzer() {
|
||||
@@ -60,7 +59,7 @@ public open class TimeAnalyzer(
|
||||
// }
|
||||
else -> block.flowFilteredEvents(parameters)
|
||||
.byPairs(parameters.t0.inverted)
|
||||
.chunked(chunkSize, Buffer.Companion::auto)
|
||||
.chunked(chunkSize)
|
||||
.map { it.asFlow().analyze(t0) }
|
||||
.toList()
|
||||
.combineResults(parameters.t0.averagingMethod)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
plugins {
|
||||
id("space.kscience.gradle.jvm")
|
||||
id("com.squareup.wire") version "4.9.1"
|
||||
id("com.squareup.wire") version "5.3.1"
|
||||
`maven-publish`
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
// Code generated by Wire protocol buffer compiler, do not edit.
|
||||
// Source: ru.inr.mass.data.proto.Point in numass-proto.proto
|
||||
@file:Suppress(
|
||||
"DEPRECATION",
|
||||
"RUNTIME_ANNOTATION_NOT_SUPPORTED",
|
||||
)
|
||||
|
||||
package ru.inr.mass.`data`.proto
|
||||
|
||||
import com.squareup.wire.*
|
||||
import com.squareup.wire.Syntax.PROTO_3
|
||||
import com.squareup.wire.internal.JvmField
|
||||
import com.squareup.wire.internal.immutableCopyOf
|
||||
import com.squareup.wire.internal.redactElements
|
||||
import okio.ByteString
|
||||
@@ -28,8 +32,7 @@ public class Point(
|
||||
message = "Shouldn't be used in Kotlin",
|
||||
level = DeprecationLevel.HIDDEN,
|
||||
)
|
||||
override fun newBuilder(): Nothing = throw
|
||||
AssertionError("Builders are deprecated and only available in a javaInterop build; see https://square.github.io/wire/wire_compiler/#kotlin")
|
||||
override fun newBuilder(): Nothing = throw AssertionError("Builders are deprecated and only available in a javaInterop build; see https://square.github.io/wire/wire_compiler/#kotlin")
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other === this) return true
|
||||
@@ -55,8 +58,7 @@ public class Point(
|
||||
return result.joinToString(prefix = "Point{", separator = ", ", postfix = "}")
|
||||
}
|
||||
|
||||
public fun copy(channels: List<Channel> = this.channels, unknownFields: ByteString =
|
||||
this.unknownFields): Point = Point(channels, unknownFields)
|
||||
public fun copy(channels: List<Channel> = this.channels, unknownFields: ByteString = this.unknownFields): Point = Point(channels, unknownFields)
|
||||
|
||||
public companion object {
|
||||
@JvmField
|
||||
@@ -139,8 +141,7 @@ public class Point(
|
||||
message = "Shouldn't be used in Kotlin",
|
||||
level = DeprecationLevel.HIDDEN,
|
||||
)
|
||||
override fun newBuilder(): Nothing = throw
|
||||
AssertionError("Builders are deprecated and only available in a javaInterop build; see https://square.github.io/wire/wire_compiler/#kotlin")
|
||||
override fun newBuilder(): Nothing = throw AssertionError("Builders are deprecated and only available in a javaInterop build; see https://square.github.io/wire/wire_compiler/#kotlin")
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other === this) return true
|
||||
@@ -187,13 +188,17 @@ public class Point(
|
||||
) {
|
||||
override fun encodedSize(`value`: Channel): Int {
|
||||
var size = value.unknownFields.size
|
||||
if (value.id != 0L) size += ProtoAdapter.UINT64.encodedSizeWithTag(1, value.id)
|
||||
if (value.id != 0L) {
|
||||
size += ProtoAdapter.UINT64.encodedSizeWithTag(1, value.id)
|
||||
}
|
||||
size += Block.ADAPTER.asRepeated().encodedSizeWithTag(2, value.blocks)
|
||||
return size
|
||||
}
|
||||
|
||||
override fun encode(writer: ProtoWriter, `value`: Channel) {
|
||||
if (value.id != 0L) ProtoAdapter.UINT64.encodeWithTag(writer, 1, value.id)
|
||||
if (value.id != 0L) {
|
||||
ProtoAdapter.UINT64.encodeWithTag(writer, 1, value.id)
|
||||
}
|
||||
Block.ADAPTER.asRepeated().encodeWithTag(writer, 2, value.blocks)
|
||||
writer.writeBytes(value.unknownFields)
|
||||
}
|
||||
@@ -201,7 +206,9 @@ public class Point(
|
||||
override fun encode(writer: ReverseProtoWriter, `value`: Channel) {
|
||||
writer.writeBytes(value.unknownFields)
|
||||
Block.ADAPTER.asRepeated().encodeWithTag(writer, 2, value.blocks)
|
||||
if (value.id != 0L) ProtoAdapter.UINT64.encodeWithTag(writer, 1, value.id)
|
||||
if (value.id != 0L) {
|
||||
ProtoAdapter.UINT64.encodeWithTag(writer, 1, value.id)
|
||||
}
|
||||
}
|
||||
|
||||
override fun decode(reader: ProtoReader): Channel {
|
||||
@@ -293,8 +300,7 @@ public class Point(
|
||||
message = "Shouldn't be used in Kotlin",
|
||||
level = DeprecationLevel.HIDDEN,
|
||||
)
|
||||
override fun newBuilder(): Nothing = throw
|
||||
AssertionError("Builders are deprecated and only available in a javaInterop build; see https://square.github.io/wire/wire_compiler/#kotlin")
|
||||
override fun newBuilder(): Nothing = throw AssertionError("Builders are deprecated and only available in a javaInterop build; see https://square.github.io/wire/wire_compiler/#kotlin")
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other === this) return true
|
||||
@@ -353,31 +359,54 @@ public class Point(
|
||||
) {
|
||||
override fun encodedSize(`value`: Block): Int {
|
||||
var size = value.unknownFields.size
|
||||
if (value.time != 0L) size += ProtoAdapter.UINT64.encodedSizeWithTag(1, value.time)
|
||||
if (value.time != 0L) {
|
||||
size += ProtoAdapter.UINT64.encodedSizeWithTag(1, value.time)
|
||||
}
|
||||
size += Frame.ADAPTER.asRepeated().encodedSizeWithTag(2, value.frames)
|
||||
if (value.events != null) size += Events.ADAPTER.encodedSizeWithTag(3, value.events)
|
||||
if (value.length != 0L) size += ProtoAdapter.UINT64.encodedSizeWithTag(4, value.length)
|
||||
if (value.bin_size != 0L) size += ProtoAdapter.UINT64.encodedSizeWithTag(5,
|
||||
value.bin_size)
|
||||
if (value.events != null) {
|
||||
size += Events.ADAPTER.encodedSizeWithTag(3, value.events)
|
||||
}
|
||||
if (value.length != 0L) {
|
||||
size += ProtoAdapter.UINT64.encodedSizeWithTag(4, value.length)
|
||||
}
|
||||
if (value.bin_size != 0L) {
|
||||
size += ProtoAdapter.UINT64.encodedSizeWithTag(5, value.bin_size)
|
||||
}
|
||||
return size
|
||||
}
|
||||
|
||||
override fun encode(writer: ProtoWriter, `value`: Block) {
|
||||
if (value.time != 0L) ProtoAdapter.UINT64.encodeWithTag(writer, 1, value.time)
|
||||
if (value.time != 0L) {
|
||||
ProtoAdapter.UINT64.encodeWithTag(writer, 1, value.time)
|
||||
}
|
||||
Frame.ADAPTER.asRepeated().encodeWithTag(writer, 2, value.frames)
|
||||
if (value.events != null) Events.ADAPTER.encodeWithTag(writer, 3, value.events)
|
||||
if (value.length != 0L) ProtoAdapter.UINT64.encodeWithTag(writer, 4, value.length)
|
||||
if (value.bin_size != 0L) ProtoAdapter.UINT64.encodeWithTag(writer, 5, value.bin_size)
|
||||
if (value.events != null) {
|
||||
Events.ADAPTER.encodeWithTag(writer, 3, value.events)
|
||||
}
|
||||
if (value.length != 0L) {
|
||||
ProtoAdapter.UINT64.encodeWithTag(writer, 4, value.length)
|
||||
}
|
||||
if (value.bin_size != 0L) {
|
||||
ProtoAdapter.UINT64.encodeWithTag(writer, 5, value.bin_size)
|
||||
}
|
||||
writer.writeBytes(value.unknownFields)
|
||||
}
|
||||
|
||||
override fun encode(writer: ReverseProtoWriter, `value`: Block) {
|
||||
writer.writeBytes(value.unknownFields)
|
||||
if (value.bin_size != 0L) ProtoAdapter.UINT64.encodeWithTag(writer, 5, value.bin_size)
|
||||
if (value.length != 0L) ProtoAdapter.UINT64.encodeWithTag(writer, 4, value.length)
|
||||
if (value.events != null) Events.ADAPTER.encodeWithTag(writer, 3, value.events)
|
||||
if (value.bin_size != 0L) {
|
||||
ProtoAdapter.UINT64.encodeWithTag(writer, 5, value.bin_size)
|
||||
}
|
||||
if (value.length != 0L) {
|
||||
ProtoAdapter.UINT64.encodeWithTag(writer, 4, value.length)
|
||||
}
|
||||
if (value.events != null) {
|
||||
Events.ADAPTER.encodeWithTag(writer, 3, value.events)
|
||||
}
|
||||
Frame.ADAPTER.asRepeated().encodeWithTag(writer, 2, value.frames)
|
||||
if (value.time != 0L) ProtoAdapter.UINT64.encodeWithTag(writer, 1, value.time)
|
||||
if (value.time != 0L) {
|
||||
ProtoAdapter.UINT64.encodeWithTag(writer, 1, value.time)
|
||||
}
|
||||
}
|
||||
|
||||
override fun decode(reader: ProtoReader): Block {
|
||||
@@ -447,8 +476,7 @@ public class Point(
|
||||
message = "Shouldn't be used in Kotlin",
|
||||
level = DeprecationLevel.HIDDEN,
|
||||
)
|
||||
override fun newBuilder(): Nothing = throw
|
||||
AssertionError("Builders are deprecated and only available in a javaInterop build; see https://square.github.io/wire/wire_compiler/#kotlin")
|
||||
override fun newBuilder(): Nothing = throw AssertionError("Builders are deprecated and only available in a javaInterop build; see https://square.github.io/wire/wire_compiler/#kotlin")
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other === this) return true
|
||||
@@ -495,24 +523,33 @@ public class Point(
|
||||
) {
|
||||
override fun encodedSize(`value`: Frame): Int {
|
||||
var size = value.unknownFields.size
|
||||
if (value.time != 0L) size += ProtoAdapter.UINT64.encodedSizeWithTag(1, value.time)
|
||||
if (value.data_ != ByteString.EMPTY) size += ProtoAdapter.BYTES.encodedSizeWithTag(2,
|
||||
value.data_)
|
||||
if (value.time != 0L) {
|
||||
size += ProtoAdapter.UINT64.encodedSizeWithTag(1, value.time)
|
||||
}
|
||||
if (value.data_ != okio.ByteString.EMPTY) {
|
||||
size += ProtoAdapter.BYTES.encodedSizeWithTag(2, value.data_)
|
||||
}
|
||||
return size
|
||||
}
|
||||
|
||||
override fun encode(writer: ProtoWriter, `value`: Frame) {
|
||||
if (value.time != 0L) ProtoAdapter.UINT64.encodeWithTag(writer, 1, value.time)
|
||||
if (value.data_ != ByteString.EMPTY) ProtoAdapter.BYTES.encodeWithTag(writer, 2,
|
||||
value.data_)
|
||||
if (value.time != 0L) {
|
||||
ProtoAdapter.UINT64.encodeWithTag(writer, 1, value.time)
|
||||
}
|
||||
if (value.data_ != okio.ByteString.EMPTY) {
|
||||
ProtoAdapter.BYTES.encodeWithTag(writer, 2, value.data_)
|
||||
}
|
||||
writer.writeBytes(value.unknownFields)
|
||||
}
|
||||
|
||||
override fun encode(writer: ReverseProtoWriter, `value`: Frame) {
|
||||
writer.writeBytes(value.unknownFields)
|
||||
if (value.data_ != ByteString.EMPTY) ProtoAdapter.BYTES.encodeWithTag(writer, 2,
|
||||
value.data_)
|
||||
if (value.time != 0L) ProtoAdapter.UINT64.encodeWithTag(writer, 1, value.time)
|
||||
if (value.data_ != okio.ByteString.EMPTY) {
|
||||
ProtoAdapter.BYTES.encodeWithTag(writer, 2, value.data_)
|
||||
}
|
||||
if (value.time != 0L) {
|
||||
ProtoAdapter.UINT64.encodeWithTag(writer, 1, value.time)
|
||||
}
|
||||
}
|
||||
|
||||
override fun decode(reader: ProtoReader): Frame {
|
||||
@@ -577,8 +614,7 @@ public class Point(
|
||||
message = "Shouldn't be used in Kotlin",
|
||||
level = DeprecationLevel.HIDDEN,
|
||||
)
|
||||
override fun newBuilder(): Nothing = throw
|
||||
AssertionError("Builders are deprecated and only available in a javaInterop build; see https://square.github.io/wire/wire_compiler/#kotlin")
|
||||
override fun newBuilder(): Nothing = throw AssertionError("Builders are deprecated and only available in a javaInterop build; see https://square.github.io/wire/wire_compiler/#kotlin")
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other === this) return true
|
||||
|
||||
@@ -5,7 +5,7 @@ import space.kscience.dataforge.context.AbstractPlugin
|
||||
import space.kscience.dataforge.context.Context
|
||||
import space.kscience.dataforge.context.PluginFactory
|
||||
import space.kscience.dataforge.context.PluginTag
|
||||
import space.kscience.dataforge.data.DataSource
|
||||
import space.kscience.dataforge.data.Data
|
||||
import space.kscience.dataforge.data.DataTree
|
||||
import space.kscience.dataforge.data.static
|
||||
import space.kscience.dataforge.io.EnvelopeFormatFactory
|
||||
@@ -53,7 +53,8 @@ public fun NumassProtoPlugin.readNumassDirectory(path: Path): NumassDirectorySet
|
||||
}
|
||||
|
||||
public fun NumassProtoPlugin.readNumassDirectory(path: String): NumassDirectorySet = readNumassDirectory(Path.of(path))
|
||||
public suspend fun NumassProtoPlugin.readRepository(path: Path): DataTree<NumassDirectorySet> = DataSource {
|
||||
|
||||
public suspend fun NumassProtoPlugin.readRepository(path: Path): DataTree<NumassDirectorySet> = DataTree.static {
|
||||
Files.walk(path).filter {
|
||||
it.isDirectory() && it.resolve("meta").exists()
|
||||
}.forEach { childPath ->
|
||||
@@ -61,7 +62,7 @@ public suspend fun NumassProtoPlugin.readRepository(path: Path): DataTree<Numass
|
||||
NameToken(segment.fileName.toString())
|
||||
})
|
||||
val value = readNumassDirectory(childPath)
|
||||
static(name, value, value.meta)
|
||||
data(name, Data(value, value.meta))
|
||||
}
|
||||
|
||||
//TODO add file watcher
|
||||
|
||||
@@ -16,13 +16,14 @@
|
||||
|
||||
package ru.inr.mass.data.proto
|
||||
|
||||
import io.ktor.utils.io.core.readBytes
|
||||
import kotlinx.coroutines.flow.*
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.datetime.Instant
|
||||
import kotlinx.datetime.LocalDateTime
|
||||
import kotlinx.datetime.TimeZone
|
||||
import kotlinx.datetime.toInstant
|
||||
import kotlinx.io.asInputStream
|
||||
import kotlinx.io.readByteArray
|
||||
import okio.ByteString
|
||||
import org.slf4j.LoggerFactory
|
||||
import ru.inr.mass.data.api.NumassBlock
|
||||
@@ -126,7 +127,7 @@ internal class ProtoNumassPoint(
|
||||
val inflater = Inflater()
|
||||
|
||||
val array: ByteArray = data?.read {
|
||||
readBytes()
|
||||
readByteArray()
|
||||
} ?: ByteArray(0)
|
||||
|
||||
inflater.setInput(array)
|
||||
|
||||
@@ -16,7 +16,10 @@
|
||||
|
||||
package ru.inr.mass.data.proto
|
||||
|
||||
import io.ktor.utils.io.core.*
|
||||
import kotlinx.io.*
|
||||
import kotlinx.io.bytestring.encodeToByteString
|
||||
import kotlinx.io.bytestring.endsWith
|
||||
import kotlinx.io.bytestring.startsWith
|
||||
import space.kscience.dataforge.context.Context
|
||||
import space.kscience.dataforge.context.invoke
|
||||
import space.kscience.dataforge.io.*
|
||||
@@ -25,21 +28,20 @@ import space.kscience.dataforge.meta.get
|
||||
import space.kscience.dataforge.meta.string
|
||||
import space.kscience.dataforge.names.Name
|
||||
import space.kscience.dataforge.names.parseAsName
|
||||
import java.util.*
|
||||
|
||||
|
||||
public class TaggedNumassEnvelopeFormat(private val io: IOPlugin) : EnvelopeFormat {
|
||||
|
||||
private fun Tag.toBinary() = Binary {
|
||||
writeRawString(START_SEQUENCE)
|
||||
writeRawString("DFNU")
|
||||
write(START_SEQUENCE.toByteArray())
|
||||
writeString("DFNU")
|
||||
writeShort(metaFormatKey)
|
||||
writeUInt(metaSize)
|
||||
writeUInt(dataSize.toUInt())
|
||||
writeRawString(END_SEQUENCE)
|
||||
write(END_SEQUENCE.toByteArray())
|
||||
}
|
||||
|
||||
override fun writeObject(output: Output, obj: Envelope) {
|
||||
override fun writeTo(output: Sink, obj: Envelope) {
|
||||
error("Don't write legacy formats")
|
||||
}
|
||||
|
||||
@@ -49,12 +51,12 @@ public class TaggedNumassEnvelopeFormat(private val io: IOPlugin) : EnvelopeForm
|
||||
* @param input an input to read from
|
||||
* @param formats a collection of meta formats to resolve
|
||||
*/
|
||||
override fun readObject(input: Input): Envelope {
|
||||
override fun readFrom(input: Source): Envelope {
|
||||
val tag = input.readTag()
|
||||
|
||||
val metaFormat = io.resolveMetaFormat(tag.metaFormatKey) ?: JsonMetaFormat
|
||||
|
||||
val meta: Meta = metaFormat.readObjectFrom(input.readBinary(tag.metaSize.toInt()))
|
||||
val meta: Meta = metaFormat.readFrom(input.readBinary(tag.metaSize.toInt()))
|
||||
|
||||
val data = input.readBinary(tag.dataSize.toInt())
|
||||
|
||||
@@ -88,8 +90,8 @@ public class TaggedNumassEnvelopeFormat(private val io: IOPlugin) : EnvelopeForm
|
||||
// }
|
||||
|
||||
public companion object : EnvelopeFormatFactory {
|
||||
private const val START_SEQUENCE = "#!"
|
||||
private const val END_SEQUENCE = "!#\r\n"
|
||||
private val START_SEQUENCE = "#!".encodeToByteString()
|
||||
private val END_SEQUENCE = "!#\r\n".encodeToByteString()
|
||||
|
||||
override val name: Name = "envelope.numass".parseAsName()
|
||||
|
||||
@@ -103,23 +105,23 @@ public class TaggedNumassEnvelopeFormat(private val io: IOPlugin) : EnvelopeForm
|
||||
return TaggedNumassEnvelopeFormat(io)
|
||||
}
|
||||
|
||||
private fun Input.readTag(): Tag {
|
||||
val start = readRawString(2)
|
||||
private fun Source.readTag(): Tag {
|
||||
val start = readByteString(2)
|
||||
if (start != START_SEQUENCE) error("The input is not an envelope")
|
||||
val versionString = readRawString(4)
|
||||
val versionString = readByteString(4)
|
||||
val junk1 = readInt()
|
||||
val metaFormatKey = readShort()
|
||||
val junk2 = readShort()
|
||||
val metaLength = readUInt()
|
||||
val dataLength: ULong = readULong()
|
||||
val end = readRawString(4)
|
||||
val end = readByteString(4)
|
||||
if (end != END_SEQUENCE) error("The input is not an envelope")
|
||||
return Tag(metaFormatKey, metaLength, dataLength)
|
||||
}
|
||||
|
||||
override fun peekFormat(io: IOPlugin, binary: Binary): EnvelopeFormat? = try {
|
||||
binary.read {
|
||||
val header = readRawString(30)
|
||||
val header = readByteString(30)
|
||||
if (header.startsWith(START_SEQUENCE) && header.endsWith(END_SEQUENCE)) {
|
||||
TaggedNumassEnvelopeFormat(io)
|
||||
} else {
|
||||
@@ -132,11 +134,11 @@ public class TaggedNumassEnvelopeFormat(private val io: IOPlugin) : EnvelopeForm
|
||||
|
||||
private val default by lazy { invoke() }
|
||||
|
||||
override fun writeObject(output: Output, obj: Envelope) {
|
||||
override fun writeTo(output: Sink, obj: Envelope) {
|
||||
error("Don't write legacy formats")
|
||||
}
|
||||
|
||||
|
||||
override fun readObject(input: Input): Envelope = default.readObject(input)
|
||||
override fun readFrom(input: Source): Envelope = default.readFrom(input)
|
||||
}
|
||||
}
|
||||
@@ -1,37 +1,37 @@
|
||||
package ru.inr.mass.data.proto
|
||||
|
||||
import io.ktor.utils.io.core.*
|
||||
import java.io.InputStream
|
||||
import kotlinx.io.Source
|
||||
|
||||
// TODO move to dataforge-io
|
||||
|
||||
/**
|
||||
* Sequentially read Utf8 lines from the input until it is exhausted
|
||||
*/
|
||||
public fun Input.lines(): Sequence<String> = sequence {
|
||||
while (!endOfInput) {
|
||||
readUTF8Line()?.let { yield(it) }
|
||||
}
|
||||
public fun Source.lines(): Sequence<String> = sequence {
|
||||
do {
|
||||
val line = readLine()
|
||||
if (line != null) yield(line)
|
||||
} while (line != null)
|
||||
}
|
||||
|
||||
private class InputAsInputStream(val input: Input) : InputStream() {
|
||||
|
||||
|
||||
override fun read(): Int = input.run {
|
||||
if (endOfInput) {
|
||||
-1
|
||||
} else {
|
||||
readUByte().toInt()
|
||||
}
|
||||
}
|
||||
|
||||
override fun readAllBytes(): ByteArray = input.readBytes()
|
||||
|
||||
override fun read(b: ByteArray): Int = input.readAvailable(b)
|
||||
|
||||
override fun close() {
|
||||
input.close()
|
||||
}
|
||||
}
|
||||
|
||||
public fun Input.asInputStream(): InputStream = InputAsInputStream(this)
|
||||
//private class InputAsInputStream(val input: Source) : InputStream() {
|
||||
//
|
||||
//
|
||||
// override fun read(): Int = input.run {
|
||||
// if (endOfInput) {
|
||||
// -1
|
||||
// } else {
|
||||
// readUByte().toInt()
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// override fun readAllBytes(): ByteArray = input.readBytes()
|
||||
//
|
||||
// override fun read(b: ByteArray): Int = input.readAvailable(b)
|
||||
//
|
||||
// override fun close() {
|
||||
// input.close()
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//public fun Source.asInputStream(): InputStream = InputAsInputStream(this)
|
||||
@@ -1,6 +1,7 @@
|
||||
plugins {
|
||||
id("space.kscience.gradle.mpp")
|
||||
id("org.jetbrains.compose")
|
||||
alias(spclibs.plugins.compose.compiler)
|
||||
alias(spclibs.plugins.compose.jb)
|
||||
`maven-publish`
|
||||
}
|
||||
|
||||
@@ -19,28 +20,32 @@ kscience {
|
||||
useContextReceivers()
|
||||
useKtor()
|
||||
|
||||
commonMain {
|
||||
dependencies {
|
||||
implementation(project(":numass-data-model"))
|
||||
implementation("space.kscience:visionforge-core:$visionForgeVersion")
|
||||
implementation("space.kscience:visionforge-plotly:$visionForgeVersion")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
kotlin{
|
||||
sourceSets{
|
||||
getByName("jvmMain"){
|
||||
commonMain {
|
||||
dependencies {
|
||||
api(compose.runtime)
|
||||
implementation(project(":numass-data-model"))
|
||||
implementation("space.kscience:visionforge-core:$visionForgeVersion")
|
||||
implementation("space.kscience:visionforge-plotly:$visionForgeVersion")
|
||||
}
|
||||
}
|
||||
|
||||
jvmMain{
|
||||
dependencies{
|
||||
implementation(compose.runtime)
|
||||
implementation(project(":numass-data-proto"))
|
||||
implementation("io.ktor:ktor-server-cio")
|
||||
implementation("io.ktor:ktor-server-html-builder")
|
||||
implementation("space.kscience:visionforge-plotly:$visionForgeVersion")
|
||||
}
|
||||
}
|
||||
getByName("jsMain"){
|
||||
|
||||
jsMain{
|
||||
dependencies{
|
||||
implementation("org.jetbrains.kotlin-wrappers:kotlin-extensions:1.0.1-pre.823")
|
||||
implementation(compose.html.core)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ public class NumassCommonPlugin(meta: Meta = Meta.EMPTY) : VisionPlugin(meta) {
|
||||
subclass(VisionOfNumassHv.serializer())
|
||||
subclass(VisionOfNumassPoint.serializer())
|
||||
subclass(VisionOfNumassSet.serializer())
|
||||
subclass(VisionOfNumassSetRef.serializer())
|
||||
subclass(VisionOfNumassRepository.serializer())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,10 @@ package ru.inr.mass.data.server
|
||||
import kotlinx.serialization.Serializable
|
||||
import ru.inr.mass.data.api.NumassSet
|
||||
import space.kscience.dataforge.data.DataTree
|
||||
import space.kscience.dataforge.data.DataTreeItem
|
||||
import space.kscience.dataforge.misc.Named
|
||||
import space.kscience.dataforge.data.await
|
||||
import space.kscience.dataforge.names.Name
|
||||
import space.kscience.dataforge.names.NameToken
|
||||
import space.kscience.dataforge.names.plus
|
||||
import space.kscience.visionforge.AbstractVision
|
||||
import space.kscience.visionforge.AbstractVisionGroup
|
||||
|
||||
@Serializable
|
||||
@@ -16,20 +14,15 @@ public class VisionOfNumassRepository : AbstractVisionGroup() {
|
||||
override fun createGroup(): VisionOfNumassRepository = VisionOfNumassRepository()
|
||||
}
|
||||
|
||||
@Serializable
|
||||
public class VisionOfNumassSetRef(
|
||||
override val name: Name,
|
||||
) : Named, AbstractVision()
|
||||
|
||||
public suspend fun VisionOfNumassRepository(
|
||||
repoName: Name,
|
||||
tree: DataTree<NumassSet>,
|
||||
): VisionOfNumassRepository = VisionOfNumassRepository().apply {
|
||||
tree.items.forEach { (key: NameToken, value) ->
|
||||
children[key] = when (value) {
|
||||
is DataTreeItem.Leaf -> VisionOfNumassSetRef(repoName + key)
|
||||
is DataTreeItem.Node -> VisionOfNumassRepository(repoName + key, value.tree)
|
||||
}
|
||||
tree.data?.let {
|
||||
VisionOfNumassSet(repoName, it.await())
|
||||
}
|
||||
tree.items.forEach { (key: NameToken, subtree) ->
|
||||
children[key] = VisionOfNumassRepository(repoName + key, subtree)
|
||||
}
|
||||
//TODO listen to changes
|
||||
}
|
||||
@@ -14,13 +14,15 @@ import space.kscience.plotly.models.LineShape
|
||||
import space.kscience.plotly.models.ScatterMode
|
||||
import space.kscience.plotly.plotDiv
|
||||
import space.kscience.plotly.scatter
|
||||
import space.kscience.visionforge.ElementVisionRenderer
|
||||
import space.kscience.visionforge.JsVisionClient
|
||||
import space.kscience.visionforge.Vision
|
||||
import space.kscience.visionforge.VisionClient
|
||||
import space.kscience.visionforge.html.ElementVisionRenderer
|
||||
import space.kscience.visionforge.html.JsVisionClient
|
||||
import space.kscience.visionforge.plotly.PlotlyPlugin
|
||||
|
||||
public class NumassJsPlugin : AbstractPlugin(), ElementVisionRenderer {
|
||||
override fun toString(): String = "NumassJsPlugin"
|
||||
|
||||
public val client: VisionClient by require(JsVisionClient)
|
||||
public val numassCommon: NumassCommonPlugin by require(NumassCommonPlugin)
|
||||
public val plotly: PlotlyPlugin by require(PlotlyPlugin)
|
||||
|
||||
@@ -4,7 +4,7 @@ import org.jetbrains.compose.web.dom.Div
|
||||
import org.jetbrains.compose.web.renderComposable
|
||||
import org.w3c.dom.Document
|
||||
import space.kscience.dataforge.context.Context
|
||||
import space.kscience.visionforge.Application
|
||||
import space.kscience.visionforge.html.Application
|
||||
|
||||
public class NumassViewerApplication : Application {
|
||||
private val context = Context("NumassViewer") {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package ru.inr.mass.data.server
|
||||
|
||||
import space.kscience.dataforge.misc.DFExperimental
|
||||
import space.kscience.visionforge.runVisionClient
|
||||
import space.kscience.visionforge.html.runVisionClient
|
||||
|
||||
|
||||
@DFExperimental
|
||||
|
||||
@@ -3,11 +3,10 @@ package ru.inr.mass.data.server
|
||||
import io.ktor.http.ContentType
|
||||
import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.server.application.Application
|
||||
import io.ktor.server.application.call
|
||||
import io.ktor.server.cio.CIO
|
||||
import io.ktor.server.engine.embeddedServer
|
||||
import io.ktor.server.html.respondHtml
|
||||
import io.ktor.server.http.content.resources
|
||||
import io.ktor.server.http.content.staticResources
|
||||
import io.ktor.server.response.respondText
|
||||
import io.ktor.server.routing.get
|
||||
import io.ktor.server.routing.routing
|
||||
@@ -20,9 +19,10 @@ import ru.inr.mass.data.proto.NumassDirectorySet
|
||||
import ru.inr.mass.data.proto.NumassProtoPlugin
|
||||
import ru.inr.mass.data.proto.readRepository
|
||||
import space.kscience.dataforge.context.Context
|
||||
import space.kscience.dataforge.context.fetch
|
||||
import space.kscience.dataforge.context.request
|
||||
import space.kscience.dataforge.data.DataTree
|
||||
import space.kscience.dataforge.data.await
|
||||
import space.kscience.dataforge.data.get
|
||||
import space.kscience.dataforge.names.Name
|
||||
import space.kscience.dataforge.names.NameToken
|
||||
import space.kscience.dataforge.names.cutLast
|
||||
@@ -41,15 +41,14 @@ public fun Application.numassModule(repositoryName: String = "D:\\Work\\Numass\\
|
||||
plugin(NumassCommonPlugin)
|
||||
}
|
||||
|
||||
val numassProto = context.fetch(NumassProtoPlugin)
|
||||
val numassCommon = context.fetch(NumassCommonPlugin)
|
||||
val numassProto = context.request(NumassProtoPlugin)
|
||||
val numassCommon = context.request(NumassCommonPlugin)
|
||||
|
||||
val visionManager = numassCommon.visionManager
|
||||
val repository: DataTree<NumassDirectorySet> = runBlocking { numassProto.readRepository(repositoryName) }
|
||||
|
||||
routing {
|
||||
resources()
|
||||
|
||||
staticResources("/","")
|
||||
get("/") {
|
||||
call.respondHtml {
|
||||
head {
|
||||
|
||||
@@ -4,7 +4,7 @@ import ru.inr.mass.data.api.NumassPoint
|
||||
import ru.inr.mass.data.proto.NumassProtoPlugin
|
||||
import ru.inr.mass.data.proto.readNumassPointFile
|
||||
import space.kscience.dataforge.context.Context
|
||||
import space.kscience.dataforge.context.fetch
|
||||
import space.kscience.dataforge.context.request
|
||||
import java.nio.file.Path
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ public suspend fun main() {
|
||||
plugin(NumassCommonPlugin)
|
||||
}
|
||||
|
||||
val numassProto = context.fetch(NumassProtoPlugin)
|
||||
val numassProto = context.request(NumassProtoPlugin)
|
||||
|
||||
val pointPath = Path.of("D:\\Work\\Numass\\data\\test\\set_7\\p120(30s)(HV1=13300)")
|
||||
val point: NumassPoint = numassProto.readNumassPointFile(pointPath)!!
|
||||
|
||||
@@ -5,15 +5,19 @@
|
||||
*/
|
||||
package ru.inr.mass.models
|
||||
|
||||
import space.kscience.dataforge.misc.ThreadSafe
|
||||
import space.kscience.kmath.expressions.Symbol
|
||||
import space.kscience.kmath.expressions.symbol
|
||||
import space.kscience.kmath.functions.Function1D
|
||||
import space.kscience.kmath.functions.PiecewisePolynomial
|
||||
import space.kscience.kmath.functions.asFunction
|
||||
import space.kscience.kmath.integration.*
|
||||
import space.kscience.kmath.integration.IntegrandMaxCalls
|
||||
import space.kscience.kmath.integration.integrate
|
||||
import space.kscience.kmath.integration.simpsonIntegrator
|
||||
import space.kscience.kmath.integration.value
|
||||
import space.kscience.kmath.operations.DoubleField
|
||||
import kotlin.jvm.Synchronized
|
||||
import kotlin.math.*
|
||||
import kotlin.math.exp
|
||||
import kotlin.math.ln
|
||||
|
||||
|
||||
/**
|
||||
@@ -54,8 +58,10 @@ public class NumassTransmission(
|
||||
}
|
||||
sum
|
||||
}
|
||||
|
||||
else -> null
|
||||
}
|
||||
|
||||
else -> null
|
||||
}
|
||||
|
||||
@@ -259,10 +265,13 @@ public class NumassTransmission(
|
||||
* @param loss
|
||||
* @return
|
||||
*/
|
||||
@Synchronized
|
||||
@ThreadSafe
|
||||
private fun getNextLoss(margin: Double, loss: Function1D<Double>): PiecewisePolynomial<Double> {
|
||||
val res = { x: Double ->
|
||||
DoubleField.simpsonIntegrator.integrate(5.0..margin, IntegrandMaxCalls(200)) { y ->
|
||||
DoubleField.simpsonIntegrator.integrate(
|
||||
5.0..margin,
|
||||
attributeBuilder = { IntegrandMaxCalls(200) }
|
||||
) { y ->
|
||||
loss(x - y) * singleScatterFunction(y)
|
||||
}.value
|
||||
}
|
||||
@@ -331,6 +340,7 @@ public class NumassTransmission(
|
||||
val z = eps - pos1
|
||||
A1 * exp(-2.0 * z * z / w1 / w1)
|
||||
}
|
||||
|
||||
else -> {
|
||||
val z = 4.0 * (eps - pos2) * (eps - pos2)
|
||||
A2 / (1 + z / w2 / w2)
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
package ru.inr.mass.models
|
||||
|
||||
import space.kscience.attributes.SafeType
|
||||
import space.kscience.attributes.safeTypeOf
|
||||
import space.kscience.kmath.expressions.Expression
|
||||
import space.kscience.kmath.expressions.SpecialDifferentiableExpression
|
||||
import space.kscience.kmath.expressions.Symbol
|
||||
|
||||
public fun interface Spectrum : Expression<Double> {
|
||||
override val type: SafeType<Double> get() = safeTypeOf<Double>()
|
||||
|
||||
public val abscissa: Symbol get() = Symbol.x
|
||||
|
||||
public operator fun invoke(x: Double, arguments: Map<Symbol, Double>): Double
|
||||
@@ -16,6 +20,7 @@ public fun interface Spectrum : Expression<Double> {
|
||||
public interface DifferentiableSpectrum : SpecialDifferentiableExpression<Double, Spectrum>, Spectrum
|
||||
|
||||
public fun interface Kernel : Expression<Double> {
|
||||
override val type: SafeType<Double> get() = safeTypeOf<Double>()
|
||||
public val x: Symbol get() = Symbol.x
|
||||
public val y: Symbol get() = Symbol.y
|
||||
|
||||
@@ -38,6 +43,6 @@ public fun Kernel.withFixedY(y: Double): Spectrum = Spectrum { x, arguments ->
|
||||
invoke(x, y, arguments)
|
||||
}
|
||||
|
||||
public fun <T> Expression<T>.withDefault(default: Map<Symbol, T>): Expression<T> = Expression { args ->
|
||||
public fun <T> Expression<T>.withDefault(default: Map<Symbol, T>): Expression<T> = Expression(type) { args ->
|
||||
invoke(default + args)
|
||||
}
|
||||
@@ -12,12 +12,11 @@ import ru.inr.mass.models.NumassBeta.msterile2
|
||||
import ru.inr.mass.models.NumassBeta.u2
|
||||
import ru.inr.mass.models.NumassTransmission.Companion.thickness
|
||||
import ru.inr.mass.models.NumassTransmission.Companion.trap
|
||||
import space.kscience.attributes.AttributesBuilder
|
||||
import space.kscience.kmath.UnstableKMathAPI
|
||||
import space.kscience.kmath.expressions.Symbol
|
||||
import space.kscience.kmath.expressions.derivative
|
||||
import space.kscience.kmath.integration.UnivariateIntegrandRanges
|
||||
import space.kscience.kmath.integration.gaussIntegrator
|
||||
import space.kscience.kmath.integration.integrate
|
||||
import space.kscience.kmath.integration.value
|
||||
import space.kscience.kmath.integration.*
|
||||
import space.kscience.kmath.operations.DoubleField
|
||||
import space.kscience.kmath.real.step
|
||||
import space.kscience.kmath.structures.toDoubleArray
|
||||
@@ -28,6 +27,7 @@ import space.kscience.kmath.structures.toDoubleArray
|
||||
* @param transmission variables:Ein,Eout; parameters: "A"
|
||||
* @param resolution variables:Eout,U; parameters: "X", "trap"
|
||||
*/
|
||||
@OptIn(UnstableKMathAPI::class)
|
||||
public class SterileNeutrinoSpectrum(
|
||||
public val source: DifferentiableKernel = NumassBeta,
|
||||
public val transmission: DifferentiableKernel = NumassTransmission(),
|
||||
@@ -54,9 +54,11 @@ public class SterileNeutrinoSpectrum(
|
||||
u2, msterile2, mnu2, e0 -> Spectrum { u, arguments ->
|
||||
convolute(u, source.derivative(symbols), transRes, arguments)
|
||||
}
|
||||
|
||||
thickness, trap -> Spectrum { u, arguments ->
|
||||
convolute(u, source, transRes.derivative(symbols), arguments)
|
||||
}
|
||||
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
@@ -94,14 +96,17 @@ public class SterileNeutrinoSpectrum(
|
||||
// }
|
||||
|
||||
return DoubleField.gaussIntegrator.integrate(
|
||||
u..eMax, generateRanges(
|
||||
u..eMax,
|
||||
u + 2.0,
|
||||
u + 7.0,
|
||||
u + 15.0,
|
||||
u + 30.0,
|
||||
*((u + 50)..(u + 6000) step 25.0).toDoubleArray()
|
||||
)
|
||||
range = u..eMax,
|
||||
attributeBuilder = {
|
||||
multiRange(
|
||||
u..eMax,
|
||||
u + 2.0,
|
||||
u + 7.0,
|
||||
u + 15.0,
|
||||
u + 30.0,
|
||||
*((u + 50)..(u + 6000) step 25.0).toDoubleArray()
|
||||
)
|
||||
}
|
||||
) { eIn ->
|
||||
sumByFSS(eIn, sourceFunction, arguments) * transResFunction(eIn, u, arguments)
|
||||
}.value
|
||||
@@ -138,14 +143,17 @@ public class SterileNeutrinoSpectrum(
|
||||
u: Double,
|
||||
arguments: Map<Symbol, Double>,
|
||||
): Double = DoubleField.gaussIntegrator.integrate(
|
||||
u..eIn, generateRanges(
|
||||
u..eIn,
|
||||
u + 2.0,
|
||||
u + 7.0,
|
||||
u + 15.0,
|
||||
u + 30.0,
|
||||
*((u + 50)..(u + 6000) step 30.0).toDoubleArray()
|
||||
)
|
||||
range = u..eIn,
|
||||
attributeBuilder = {
|
||||
multiRange(
|
||||
u..eIn,
|
||||
u + 2.0,
|
||||
u + 7.0,
|
||||
u + 15.0,
|
||||
u + 30.0,
|
||||
*((u + 50)..(u + 6000) step 30.0).toDoubleArray()
|
||||
)
|
||||
}
|
||||
) { eOut: Double ->
|
||||
transFunc(eIn, eOut, arguments) * resolution(eOut, u, arguments)
|
||||
}.value
|
||||
@@ -154,19 +162,25 @@ public class SterileNeutrinoSpectrum(
|
||||
public companion object
|
||||
}
|
||||
|
||||
|
||||
internal fun generateRanges(
|
||||
internal fun AttributesBuilder<UnivariateIntegrand<*>>.multiRange(
|
||||
range: ClosedFloatingPointRange<Double>,
|
||||
vararg borders: Double,
|
||||
points: Int = 5,
|
||||
): UnivariateIntegrandRanges {
|
||||
if (borders.isEmpty() || borders.first() > range.endInclusive) return UnivariateIntegrandRanges(range to points)
|
||||
val ranges = listOf(
|
||||
range.start,
|
||||
*borders.filter { it in range }.sorted().toTypedArray(),
|
||||
range.endInclusive
|
||||
).zipWithNext { l, r ->
|
||||
l..r to points
|
||||
) {
|
||||
val ranges: UnivariateIntegrandRanges = if (borders.isEmpty() || borders.first() > range.endInclusive) {
|
||||
UnivariateIntegrandRanges(range to points)
|
||||
} else {
|
||||
UnivariateIntegrandRanges(
|
||||
listOf(
|
||||
range.start,
|
||||
*borders.filter { it in range }.sorted().toTypedArray(),
|
||||
range.endInclusive
|
||||
).zipWithNext { l, r ->
|
||||
l..r to points
|
||||
}
|
||||
)
|
||||
}
|
||||
return UnivariateIntegrandRanges(ranges)
|
||||
UnivariateIntegrandRanges.invoke(
|
||||
ranges
|
||||
)
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import space.kscience.kmath.functions.PiecewisePolynomial
|
||||
import space.kscience.kmath.interpolation.SplineInterpolator
|
||||
import space.kscience.kmath.interpolation.interpolatePolynomials
|
||||
import space.kscience.kmath.operations.DoubleField
|
||||
import space.kscience.kmath.structures.DoubleBuffer
|
||||
import space.kscience.kmath.structures.Float64Buffer
|
||||
import kotlin.math.abs
|
||||
|
||||
public fun Function1D<Double>.cache(
|
||||
@@ -14,8 +14,8 @@ public fun Function1D<Double>.cache(
|
||||
numCachePoints: Int,
|
||||
): PiecewisePolynomial<Double> {
|
||||
val length = abs(range.endInclusive - range.start)
|
||||
val grid: DoubleBuffer = DoubleBuffer(numCachePoints) { range.start + length / (numCachePoints - 1) * it }
|
||||
val vals = DoubleBuffer(grid.size) { invoke(grid[it]) }
|
||||
val interpolator = SplineInterpolator(DoubleField, ::DoubleBuffer)
|
||||
val grid: Float64Buffer = Float64Buffer(numCachePoints) { range.start + length / (numCachePoints - 1) * it }
|
||||
val vals = Float64Buffer(grid.size) { invoke(grid[it]) }
|
||||
val interpolator = SplineInterpolator(DoubleField)
|
||||
return interpolator.interpolatePolynomials(grid, vals)
|
||||
}
|
||||
@@ -1,12 +1,18 @@
|
||||
package ru.inr.mass.models
|
||||
|
||||
import space.kscience.attributes.Attributes
|
||||
import space.kscience.kmath.integration.UnivariateIntegrand
|
||||
import space.kscience.kmath.integration.UnivariateIntegrandRanges
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
internal class TestGenerateRanges {
|
||||
@Test
|
||||
fun simpleRanges() {
|
||||
val ranges = generateRanges(0.0..100.0, 10.0, 55.0, 120.0)
|
||||
val attributes = Attributes<UnivariateIntegrand<*>>{
|
||||
multiRange(0.0..100.0, 10.0, 55.0, 120.0)
|
||||
}
|
||||
val ranges = attributes[UnivariateIntegrandRanges]!!
|
||||
assertEquals(3, ranges.ranges.size)
|
||||
assertEquals(55.0..100.0, ranges.ranges.last().first)
|
||||
assertEquals(10.0..55.0, ranges.ranges[1].first)
|
||||
|
||||
@@ -2,7 +2,7 @@ package ru.inr.mass.models
|
||||
|
||||
import space.kscience.kmath.real.div
|
||||
import space.kscience.kmath.real.sum
|
||||
import space.kscience.kmath.structures.DoubleBuffer
|
||||
import space.kscience.kmath.structures.Float64Buffer
|
||||
|
||||
private val defaultFss: FSS by lazy {
|
||||
val stream = FSS::class.java.getResourceAsStream("/data/FS.txt") ?: error("Default FS resource not found")
|
||||
@@ -11,8 +11,8 @@ private val defaultFss: FSS by lazy {
|
||||
val (e, p) = it.split("\t")
|
||||
e.toDouble() to p.toDouble()
|
||||
}.toList()
|
||||
val es = DoubleBuffer(data.size) { data[it].first }
|
||||
val ps = DoubleBuffer(data.size) { data[it].second }
|
||||
val es = Float64Buffer(data.size) { data[it].first }
|
||||
val ps = Float64Buffer(data.size) { data[it].second }
|
||||
FSS(es, ps / ps.sum())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ import ru.inr.mass.workspace.Numass
|
||||
import ru.inr.mass.workspace.plotNumassBlock
|
||||
import ru.inr.mass.workspace.plotNumassSet
|
||||
import space.kscience.dataforge.data.DataTree
|
||||
import space.kscience.dataforge.data.DataTreeItem
|
||||
import space.kscience.plotly.Plotly
|
||||
import space.kscience.plotly.scatter
|
||||
import space.kscience.plotly.toHTML
|
||||
@@ -76,10 +75,7 @@ private fun FlowContent.numassTree(tree: DataTree<NumassDirectorySet>) {
|
||||
tree.items.forEach { (token, treeItem) ->
|
||||
li {
|
||||
p { +token.toString() }
|
||||
when (treeItem) {
|
||||
is DataTreeItem.Leaf -> {}
|
||||
is DataTreeItem.Node -> numassTree(treeItem.tree)
|
||||
}
|
||||
numassTree(treeItem)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package ru.inr.mass.scripts
|
||||
|
||||
import kotlinx.io.writeString
|
||||
import ru.inr.mass.data.api.NumassBlock
|
||||
import ru.inr.mass.data.api.channels
|
||||
import ru.inr.mass.workspace.Numass
|
||||
import ru.inr.mass.workspace.listFrames
|
||||
import space.kscience.dataforge.io.write
|
||||
import space.kscience.dataforge.io.writeUtf8String
|
||||
import java.nio.file.Files
|
||||
import kotlin.io.path.createDirectories
|
||||
import kotlin.io.path.writeText
|
||||
@@ -29,9 +29,9 @@ fun main() {
|
||||
block.listFrames().forEach { frame ->
|
||||
// val frameTime = pointTime.plus(frame.timeOffset, DateTimeUnit.NANOSECOND)
|
||||
// writeUtf8String("$frameTime,")
|
||||
writeUtf8String("${frame.timeOffset},")
|
||||
writeString("${frame.timeOffset},")
|
||||
val line = frame.signal.joinToString(",", postfix = "\n" )
|
||||
writeUtf8String(line)
|
||||
writeString(line)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package ru.inr.mass.scripts
|
||||
|
||||
import ru.inr.mass.models.*
|
||||
import ru.inr.mass.workspace.buffer
|
||||
import ru.inr.mass.workspace.fitWith
|
||||
import ru.inr.mass.workspace.generate
|
||||
import ru.inr.mass.workspace.*
|
||||
import space.kscience.kmath.UnstableKMathAPI
|
||||
import space.kscience.kmath.expressions.Symbol
|
||||
import space.kscience.kmath.expressions.derivative
|
||||
@@ -49,8 +47,10 @@ suspend fun main() {
|
||||
optimizer = QowOptimizer,
|
||||
modelExpression = spectrum,
|
||||
startingPoint = args + mapOf(NBkgSpectrum.norm to 8.1e5),
|
||||
OptimizationParameters(NBkgSpectrum.norm, NBkgSpectrum.bkg, NumassBeta.e0),
|
||||
OptimizationIterations(20)
|
||||
attributesBuilder = {
|
||||
freeParameters(NBkgSpectrum.norm, NBkgSpectrum.bkg, NumassBeta.e0)
|
||||
iterations(20)
|
||||
}
|
||||
)
|
||||
|
||||
println("Chi squared/dof: ${fit.chiSquaredOrNull}/${fit.dof}")
|
||||
@@ -74,7 +74,7 @@ suspend fun main() {
|
||||
name = "Fit"
|
||||
mode = ScatterMode.lines
|
||||
x.buffer = 12000.0..18600.0 step 10.0
|
||||
y.numbers = x.doubles.map { spectrum(it, args + fit.resultPoint) }
|
||||
y.numbers = x.doubles.map { spectrum(it, args + fit.result) }
|
||||
}
|
||||
}.makeFile()
|
||||
}
|
||||
@@ -2,21 +2,19 @@ package ru.inr.mass.scripts
|
||||
|
||||
import ru.inr.mass.data.proto.NumassDirectorySet
|
||||
import ru.inr.mass.workspace.Numass.readRepository
|
||||
import space.kscience.dataforge.data.DataSource
|
||||
import space.kscience.dataforge.data.DataTree
|
||||
import space.kscience.dataforge.data.filter
|
||||
import space.kscience.dataforge.data.filterData
|
||||
import space.kscience.dataforge.data.forEach
|
||||
import space.kscience.dataforge.meta.Meta
|
||||
import space.kscience.dataforge.meta.get
|
||||
import space.kscience.dataforge.meta.string
|
||||
|
||||
suspend fun main() {
|
||||
val repo: DataTree<NumassDirectorySet> = readRepository("D:\\Work\\Numass\\data\\2018_04")
|
||||
val filtered: DataSource<NumassDirectorySet> = repo.filter { _, meta: Meta ->
|
||||
val operator by meta.string()
|
||||
operator?.startsWith("Vas") ?: false
|
||||
val filtered: DataTree<NumassDirectorySet> = repo.filterData { name, meta, type ->
|
||||
meta?.get("operator").string?.startsWith("Vas") == true
|
||||
}
|
||||
|
||||
filtered.forEach{
|
||||
filtered.forEach {
|
||||
println(it)
|
||||
}
|
||||
}
|
||||
@@ -1,36 +1,32 @@
|
||||
package ru.inr.mass.scripts
|
||||
|
||||
import org.apache.commons.csv.CSVFormat
|
||||
import ru.inr.mass.models.*
|
||||
import ru.inr.mass.workspace.Numass
|
||||
import ru.inr.mass.workspace.buffer
|
||||
import ru.inr.mass.workspace.fitWith
|
||||
import space.kscience.dataforge.meta.Value
|
||||
import space.kscience.dataforge.meta.double
|
||||
import ru.inr.mass.workspace.*
|
||||
import space.kscience.kmath.UnstableKMathAPI
|
||||
import space.kscience.kmath.data.XYErrorColumnarData
|
||||
import space.kscience.kmath.expressions.Symbol
|
||||
import space.kscience.kmath.optimization.*
|
||||
import space.kscience.kmath.real.map
|
||||
import space.kscience.kmath.real.step
|
||||
import space.kscience.kmath.structures.DoubleBuffer
|
||||
import space.kscience.kmath.structures.Float64Buffer
|
||||
import space.kscience.kmath.structures.indices
|
||||
import space.kscience.plotly.*
|
||||
import space.kscience.plotly.models.ScatterMode
|
||||
import space.kscience.tables.Column
|
||||
import space.kscience.tables.Table
|
||||
import space.kscience.tables.csv.readAsCsv
|
||||
import space.kscience.tables.csv.readCsv
|
||||
import space.kscience.tables.get
|
||||
import kotlin.math.pow
|
||||
|
||||
fun Column<Value>.toDoubleBuffer() = DoubleBuffer(size) { get(it).double }
|
||||
fun Column<String>.toDoubleBuffer() = Float64Buffer(size) { get(it).toDouble() }
|
||||
|
||||
@OptIn(UnstableKMathAPI::class)
|
||||
suspend fun main() {
|
||||
val input = Table.readAsCsv(
|
||||
val input = Table.readCsv(
|
||||
Numass::class.java.getResource("/data/2023_events.tsv")!!,
|
||||
csvFormat = CSVFormat.TDF
|
||||
)
|
||||
){
|
||||
delimiter = '\t'
|
||||
}
|
||||
|
||||
val timePerPoint = 30.0 * 129
|
||||
|
||||
@@ -58,8 +54,10 @@ suspend fun main() {
|
||||
optimizer = QowOptimizer,
|
||||
modelExpression = spectrum,
|
||||
startingPoint = args,
|
||||
OptimizationParameters(NBkgSpectrum.norm, NBkgSpectrum.bkg, NumassBeta.e0),
|
||||
OptimizationIterations(20)
|
||||
attributesBuilder = {
|
||||
freeParameters(NBkgSpectrum.norm, NBkgSpectrum.bkg, NumassBeta.e0)
|
||||
iterations(20)
|
||||
}
|
||||
)
|
||||
|
||||
println("Chi squared/dof: ${fit.chiSquaredOrNull}/${fit.dof}")
|
||||
@@ -78,7 +76,7 @@ suspend fun main() {
|
||||
name = "Fit"
|
||||
mode = ScatterMode.lines
|
||||
x.buffer = 12000.0..18600.0 step 10.0
|
||||
y.numbers = x.doubles.map { spectrum(it, args + fit.resultPoint) }
|
||||
y.numbers = x.doubles.map { spectrum(it, args + fit.result) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +86,7 @@ suspend fun main() {
|
||||
mode = ScatterMode.markers
|
||||
x.buffer = data.x
|
||||
y.numbers = data.x.indices.map {
|
||||
(data.y[it] - spectrum(data.x[it], args + fit.resultPoint))/data.yErr[it]
|
||||
(data.y[it] - spectrum(data.x[it], args + fit.result))/data.yErr[it]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import kotlinx.coroutines.runBlocking
|
||||
import ru.inr.mass.data.api.NumassBlock
|
||||
import ru.inr.mass.data.api.NumassPoint
|
||||
import ru.inr.mass.data.proto.*
|
||||
import space.kscience.dataforge.context.fetch
|
||||
import space.kscience.dataforge.context.request
|
||||
import space.kscience.dataforge.data.DataTree
|
||||
import space.kscience.dataforge.workspace.Workspace
|
||||
import java.nio.file.Path
|
||||
@@ -20,7 +20,7 @@ object Numass {
|
||||
|
||||
val context get() = workspace.context
|
||||
|
||||
val numassProto by lazy { context.fetch(NumassProtoPlugin) }
|
||||
val numassProto by lazy { context.request(NumassProtoPlugin) }
|
||||
|
||||
fun readPoint(path: Path): NumassPoint =
|
||||
numassProto.readNumassPointFile(path) ?: error("Can't read numass point at $path")
|
||||
|
||||
@@ -9,14 +9,13 @@ import ru.inr.mass.data.proto.NumassProtoPlugin
|
||||
import space.kscience.dataforge.context.Context
|
||||
import space.kscience.dataforge.context.PluginFactory
|
||||
import space.kscience.dataforge.context.PluginTag
|
||||
import space.kscience.dataforge.data.filterByType
|
||||
import space.kscience.dataforge.meta.*
|
||||
import space.kscience.dataforge.meta.descriptors.MetaDescriptor
|
||||
import space.kscience.dataforge.meta.descriptors.value
|
||||
import space.kscience.dataforge.names.Name
|
||||
import space.kscience.dataforge.workspace.WorkspacePlugin
|
||||
import space.kscience.dataforge.workspace.pipeFrom
|
||||
import space.kscience.dataforge.workspace.filterByType
|
||||
import space.kscience.dataforge.workspace.task
|
||||
import space.kscience.dataforge.workspace.transformEach
|
||||
import space.kscience.tables.Table
|
||||
|
||||
class NumassWorkspacePlugin : WorkspacePlugin() {
|
||||
@@ -26,37 +25,35 @@ class NumassWorkspacePlugin : WorkspacePlugin() {
|
||||
|
||||
val selectSets by task<NumassSet>(
|
||||
descriptor = MetaDescriptor {
|
||||
info = "Select data from workspace data pool"
|
||||
description = "Select data from workspace data pool"
|
||||
value("forward", ValueType.BOOLEAN) {
|
||||
info = "Select only forward or only backward sets"
|
||||
description = "Select only forward or only backward sets"
|
||||
}
|
||||
}
|
||||
) {
|
||||
val forward = meta["forward"]?.boolean
|
||||
val filtered = workspace.data.filterByType<NumassSet> { _, meta ->
|
||||
workspace.data.filterByType<NumassSet> { _, meta, _ ->
|
||||
when (forward) {
|
||||
true -> meta["iteration_info.reverse"]?.boolean?.not() ?: false
|
||||
false -> meta["iteration_info.reverse"]?.boolean ?: false
|
||||
else -> true
|
||||
}
|
||||
}
|
||||
|
||||
node(Name.EMPTY, filtered)
|
||||
}
|
||||
|
||||
|
||||
val analyzeSets by task<Table<Value>>(
|
||||
MetaDescriptor {
|
||||
info = "Count the number of events for each voltage and produce a table with the results"
|
||||
description = "Count the number of events for each voltage and produce a table with the results"
|
||||
}
|
||||
) {
|
||||
pipeFrom(selectSets) { set, name, meta ->
|
||||
transformEach(selectSets) {
|
||||
val res = TimeAnalyzer(NumassEventExtractor.EVENTS_ONLY).analyzeSet(
|
||||
set,
|
||||
value,
|
||||
NumassAnalyzerParameters.read(meta["analyzer"] ?: Meta.EMPTY)
|
||||
)
|
||||
val outputMeta = meta.toMutableMeta().apply {
|
||||
"data" put set.meta
|
||||
"data" put meta
|
||||
}
|
||||
// context.output.render(res, stage = "numass.analyze", name = name, meta = outputMeta)
|
||||
res
|
||||
|
||||
@@ -3,44 +3,95 @@
|
||||
package ru.inr.mass.workspace
|
||||
|
||||
import ru.inr.mass.models.Spectrum
|
||||
import space.kscience.attributes.Attributes
|
||||
import space.kscience.attributes.AttributesBuilder
|
||||
import space.kscience.kmath.UnstableKMathAPI
|
||||
import space.kscience.kmath.data.XYColumnarData
|
||||
import space.kscience.kmath.data.XYErrorColumnarData
|
||||
import space.kscience.kmath.expressions.AutoDiffProcessor
|
||||
import space.kscience.kmath.expressions.DifferentiableExpression
|
||||
import space.kscience.kmath.expressions.ExpressionAlgebra
|
||||
import space.kscience.kmath.expressions.Symbol
|
||||
import space.kscience.kmath.misc.FeatureSet
|
||||
import space.kscience.kmath.misc.Loggable
|
||||
import space.kscience.kmath.operations.ExtendedField
|
||||
import space.kscience.kmath.optimization.*
|
||||
import space.kscience.kmath.random.RandomGenerator
|
||||
import space.kscience.kmath.samplers.PoissonSampler
|
||||
import space.kscience.kmath.stat.next
|
||||
import space.kscience.kmath.structures.Float64
|
||||
import space.kscience.kmath.structures.asBuffer
|
||||
import kotlin.math.sqrt
|
||||
|
||||
//public suspend fun XYColumnarData<Double, Double, Double>.fitWith(
|
||||
// optimizer: Optimizer<Double, XYFit>,
|
||||
// modelExpression: DifferentiableExpression<Double>,
|
||||
// startingPoint: Map<Symbol, Double>,
|
||||
// vararg features: OptimizationFeature = emptyArray(),
|
||||
// xSymbol: Symbol = Symbol.x,
|
||||
// pointToCurveDistance: PointToCurveDistance = PointToCurveDistance.byY,
|
||||
// pointWeight: PointWeight = PointWeight.byYSigma,
|
||||
//): XYFit {
|
||||
// var actualFeatures = FeatureSet.of(*features, OptimizationStartPoint(startingPoint))
|
||||
//
|
||||
// if (actualFeatures.getFeature<OptimizationLog>() == null) {
|
||||
// actualFeatures = actualFeatures.with(OptimizationLog(Loggable.console))
|
||||
// }
|
||||
// val problem = XYFit(
|
||||
// this,
|
||||
// modelExpression,
|
||||
// actualFeatures,
|
||||
// pointToCurveDistance,
|
||||
// pointWeight,
|
||||
// xSymbol
|
||||
// )
|
||||
// return optimizer.optimize(problem)
|
||||
//}
|
||||
|
||||
public fun AttributesBuilder<OptimizationProblem<*>>.freeParameters(vararg symbols: Symbol) {
|
||||
OptimizationParameters(symbols.asList())
|
||||
}
|
||||
|
||||
public fun AttributesBuilder<OptimizationProblem<*>>.iterations(iterations: Int) {
|
||||
OptimizationIterations(iterations)
|
||||
}
|
||||
|
||||
public suspend fun XYColumnarData<Double, Double, Double>.fitWith(
|
||||
optimizer: Optimizer<Double, XYFit>,
|
||||
modelExpression: DifferentiableExpression<Double>,
|
||||
modelExpression: DifferentiableExpression<Float64>,
|
||||
startingPoint: Map<Symbol, Double>,
|
||||
vararg features: OptimizationFeature = emptyArray(),
|
||||
attributesBuilder: AttributesBuilder<XYFit>.() -> Unit,
|
||||
xSymbol: Symbol = Symbol.x,
|
||||
pointToCurveDistance: PointToCurveDistance = PointToCurveDistance.byY,
|
||||
pointWeight: PointWeight = PointWeight.byYSigma,
|
||||
): XYFit {
|
||||
var actualFeatures = FeatureSet.of(*features, OptimizationStartPoint(startingPoint))
|
||||
): XYFit = fitWith(
|
||||
optimizer = optimizer,
|
||||
modelExpression = modelExpression,
|
||||
startingPoint = startingPoint,
|
||||
attributes = Attributes<XYFit>(attributesBuilder),
|
||||
xSymbol = xSymbol,
|
||||
pointToCurveDistance = pointToCurveDistance,
|
||||
pointWeight = pointWeight
|
||||
)
|
||||
|
||||
if (actualFeatures.getFeature<OptimizationLog>() == null) {
|
||||
actualFeatures = actualFeatures.with(OptimizationLog(Loggable.console))
|
||||
}
|
||||
val problem = XYFit(
|
||||
this,
|
||||
modelExpression,
|
||||
actualFeatures,
|
||||
pointToCurveDistance,
|
||||
pointWeight,
|
||||
xSymbol
|
||||
)
|
||||
return optimizer.optimize(problem)
|
||||
}
|
||||
|
||||
public suspend fun <I : Any, A> XYColumnarData<Double, Double, Double>.fitWith(
|
||||
optimizer: Optimizer<Double, XYFit>,
|
||||
processor: AutoDiffProcessor<Double, I, A>,
|
||||
startingPoint: Map<Symbol, Double>,
|
||||
attributesBuilder: AttributesBuilder<XYFit>.() -> Unit,
|
||||
xSymbol: Symbol = Symbol.x,
|
||||
pointToCurveDistance: PointToCurveDistance = PointToCurveDistance.byY,
|
||||
pointWeight: PointWeight = PointWeight.byYSigma,
|
||||
model: A.(I) -> I,
|
||||
): XYFit where A : ExtendedField<I>, A : ExpressionAlgebra<Double, I> = fitWith(
|
||||
optimizer = optimizer,
|
||||
processor = processor,
|
||||
startingPoint = startingPoint,
|
||||
attributes = Attributes<XYFit>(attributesBuilder),
|
||||
xSymbol = xSymbol,
|
||||
pointToCurveDistance = pointToCurveDistance,
|
||||
pointWeight = pointWeight,
|
||||
model = model
|
||||
)
|
||||
|
||||
public suspend fun Spectrum.generate(
|
||||
strategy: Map<Double, Double>,
|
||||
|
||||
@@ -17,7 +17,7 @@ import space.kscience.kmath.domains.center
|
||||
import space.kscience.kmath.histogram.Histogram1D
|
||||
import space.kscience.kmath.operations.asIterable
|
||||
import space.kscience.kmath.structures.Buffer
|
||||
import space.kscience.kmath.structures.DoubleBuffer
|
||||
import space.kscience.kmath.structures.Float64Buffer
|
||||
import space.kscience.plotly.*
|
||||
import space.kscience.plotly.models.*
|
||||
import kotlin.time.DurationUnit
|
||||
@@ -141,7 +141,7 @@ fun Plotly.plotNumassSet(
|
||||
* Add a number buffer accessor for Plotly trace values
|
||||
*/
|
||||
public var TraceValues.buffer: Buffer<Number>
|
||||
get() = value?.list?.let { list -> DoubleBuffer(list.size) { list[it].double } } ?: DoubleBuffer()
|
||||
get() = value?.list?.let { list -> Float64Buffer(list.size) { list[it].double } } ?: Float64Buffer()
|
||||
set(value) {
|
||||
this.value = value.asIterable().map { it.asValue() }.asValue()
|
||||
}
|
||||
@@ -33,7 +33,7 @@ dependencyResolutionManagement {
|
||||
}
|
||||
|
||||
versionCatalogs {
|
||||
create("npmlibs") {
|
||||
create("spclibs") {
|
||||
from("space.kscience:version-catalog:$toolsVersion")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user