This commit is contained in:
Alexander Nozik 2022-06-07 12:16:02 +03:00
parent 5d3e6948db
commit b911790238
No known key found for this signature in database
GPG Key ID: F7FCF2DD25C71357
7 changed files with 26 additions and 25 deletions

View File

@ -14,7 +14,7 @@ allprojects {
val dataforgeVersion by extra("0.5.2") val dataforgeVersion by extra("0.5.2")
val tablesVersion: String by extra("0.1.5") val tablesVersion: String by extra("0.1.5")
val kmathVersion by extra("0.3.0-dev-18") val kmathVersion by extra("0.3.0")
val plotlyVersion: String by extra("0.5.0") val plotlyVersion: String by extra("0.5.0")
ksciencePublish{ ksciencePublish{

View File

@ -1,12 +1,14 @@
package ru.inr.mass.data.analysis package ru.inr.mass.data.analysis
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.transform import kotlinx.coroutines.flow.transform
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import ru.inr.mass.data.api.NumassBlock import ru.inr.mass.data.api.NumassBlock
import ru.inr.mass.data.api.getTime import ru.inr.mass.data.api.getTime
import space.kscience.kmath.histogram.UnivariateHistogram import space.kscience.kmath.histogram.Histogram
import space.kscience.kmath.histogram.UniformHistogram1D
import space.kscience.kmath.histogram.uniform1D
import space.kscience.kmath.operations.DoubleField
import kotlin.math.max import kotlin.math.max
import kotlin.time.DurationUnit import kotlin.time.DurationUnit
@ -23,7 +25,7 @@ public fun <T, R> Flow<T>.zipWithNext(block: (l: T, r: T) -> R): Flow<R> {
public fun NumassBlock.timeHistogram( public fun NumassBlock.timeHistogram(
binSize: Double, binSize: Double,
extractor: NumassEventExtractor = NumassEventExtractor.EVENTS_ONLY, extractor: NumassEventExtractor = NumassEventExtractor.EVENTS_ONLY,
): UnivariateHistogram = UnivariateHistogram.uniform(binSize) { ): UniformHistogram1D<Double> = Histogram.uniform1D(DoubleField, binSize).produce {
runBlocking { runBlocking {
extractor.extract(this@timeHistogram).zipWithNext { l, r -> extractor.extract(this@timeHistogram).zipWithNext { l, r ->
if(l.owner == r.owner) { if(l.owner == r.owner) {

View File

@ -7,8 +7,8 @@ package ru.inr.mass.models
import space.kscience.kmath.expressions.Symbol import space.kscience.kmath.expressions.Symbol
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.PiecewisePolynomial
import space.kscience.kmath.functions.UnivariateFunction
import space.kscience.kmath.functions.asFunction import space.kscience.kmath.functions.asFunction
import space.kscience.kmath.integration.* import space.kscience.kmath.integration.*
import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.operations.DoubleField
@ -84,7 +84,7 @@ public class NumassTransmission(
public val trap: Symbol by symbol public val trap: Symbol by symbol
public val thickness: Symbol by symbol public val thickness: Symbol by symbol
private val cache = HashMap<Int, UnivariateFunction<Double>>() private val cache = HashMap<Int, Function1D<Double>>()
private const val ION_POTENTIAL = 15.4//eV private const val ION_POTENTIAL = 15.4//eV
@ -130,7 +130,7 @@ public class NumassTransmission(
return exp(-x) return exp(-x)
} }
private fun getCachedSpectrum(order: Int): UnivariateFunction<Double> { private fun getCachedSpectrum(order: Int): Function1D<Double> {
return when { return when {
order <= 0 -> error("Non-positive loss cache order") order <= 0 -> error("Non-positive loss cache order")
order == 1 -> singleScatterFunction order == 1 -> singleScatterFunction
@ -147,7 +147,7 @@ public class NumassTransmission(
* @param order * @param order
* @return * @return
*/ */
private fun getLoss(order: Int): UnivariateFunction<Double> = getCachedSpectrum(order) private fun getLoss(order: Int): Function1D<Double> = getCachedSpectrum(order)
private fun getLossProbDerivs(x: Double): List<Double> { private fun getLossProbDerivs(x: Double): List<Double> {
val res = ArrayList<Double>() val res = ArrayList<Double>()
@ -260,7 +260,7 @@ public class NumassTransmission(
* @return * @return
*/ */
@Synchronized @Synchronized
private fun getNextLoss(margin: Double, loss: UnivariateFunction<Double>): PiecewisePolynomial<Double> { private fun getNextLoss(margin: Double, loss: Function1D<Double>): PiecewisePolynomial<Double> {
val res = { x: Double -> val res = { x: Double ->
DoubleField.simpsonIntegrator.integrate(5.0..margin, IntegrandMaxCalls(200)) { y -> DoubleField.simpsonIntegrator.integrate(5.0..margin, IntegrandMaxCalls(200)) { y ->
loss(x - y) * singleScatterFunction(y) loss(x - y) * singleScatterFunction(y)
@ -324,7 +324,7 @@ public class NumassTransmission(
private val w1 = 1.85 private val w1 = 1.85
private val w2 = 12.5 private val w2 = 12.5
public val singleScatterFunction: UnivariateFunction<Double> = { eps: Double -> public val singleScatterFunction: Function1D<Double> = { eps: Double ->
when { when {
eps <= 0 -> 0.0 eps <= 0 -> 0.0
eps <= b -> { eps <= b -> {

View File

@ -1,15 +1,15 @@
package ru.inr.mass.models package ru.inr.mass.models
import space.kscience.kmath.functions.Function1D
import space.kscience.kmath.functions.PiecewisePolynomial import space.kscience.kmath.functions.PiecewisePolynomial
import space.kscience.kmath.functions.UnivariateFunction
import space.kscience.kmath.interpolation.SplineInterpolator import space.kscience.kmath.interpolation.SplineInterpolator
import space.kscience.kmath.interpolation.interpolatePolynomials import space.kscience.kmath.interpolation.interpolatePolynomials
import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.operations.DoubleField
import space.kscience.kmath.structures.DoubleBuffer import space.kscience.kmath.structures.DoubleBuffer
import kotlin.math.abs import kotlin.math.abs
public fun UnivariateFunction<Double>.cache( public fun Function1D<Double>.cache(
range: ClosedFloatingPointRange<Double>, range: ClosedFloatingPointRange<Double>,
numCachePoints: Int, numCachePoints: Int,
): PiecewisePolynomial<Double> { ): PiecewisePolynomial<Double> {

View File

@ -1,7 +1,5 @@
package ru.inr.mass.scripts package ru.inr.mass.scripts
import kotlinx.datetime.DateTimeUnit
import kotlinx.datetime.plus
import ru.inr.mass.data.api.NumassBlock import ru.inr.mass.data.api.NumassBlock
import ru.inr.mass.data.api.channels import ru.inr.mass.data.api.channels
import ru.inr.mass.workspace.Numass import ru.inr.mass.workspace.Numass
@ -29,8 +27,9 @@ fun main() {
channels.forEach { (key, block) -> channels.forEach { (key, block) ->
targetDir.resolve("channel-$key.csv").write { targetDir.resolve("channel-$key.csv").write {
block.listFrames().forEach { frame -> block.listFrames().forEach { frame ->
val frameTime = pointTime.plus(frame.timeOffset, DateTimeUnit.NANOSECOND) // val frameTime = pointTime.plus(frame.timeOffset, DateTimeUnit.NANOSECOND)
writeUtf8String("$frameTime,") // writeUtf8String("$frameTime,")
writeUtf8String("${frame.timeOffset},")
val line = frame.signal.joinToString(",", postfix = "\n" ) val line = frame.signal.joinToString(",", postfix = "\n" )
writeUtf8String(line) writeUtf8String(line)
} }

View File

@ -5,8 +5,8 @@ import space.kscience.kmath.functions.asFunction
import space.kscience.kmath.integration.integrate import space.kscience.kmath.integration.integrate
import space.kscience.kmath.integration.splineIntegrator import space.kscience.kmath.integration.splineIntegrator
import space.kscience.kmath.integration.value import space.kscience.kmath.integration.value
import space.kscience.kmath.interpolation.SplineInterpolator
import space.kscience.kmath.interpolation.interpolatePolynomials import space.kscience.kmath.interpolation.interpolatePolynomials
import space.kscience.kmath.interpolation.splineInterpolator
import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.operations.DoubleField
import space.kscience.kmath.real.step import space.kscience.kmath.real.step
import space.kscience.plotly.Plotly import space.kscience.plotly.Plotly
@ -28,7 +28,7 @@ fun main() {
Pair(e.toDouble(), p.toDouble()) Pair(e.toDouble(), p.toDouble())
}.toList() }.toList()
val interpolated = SplineInterpolator.double val interpolated = DoubleField.splineInterpolator
.interpolatePolynomials(backScatteringSpectrum) .interpolatePolynomials(backScatteringSpectrum)
.asFunction(DoubleField, 0.0) .asFunction(DoubleField, 0.0)

View File

@ -12,8 +12,8 @@ import ru.inr.mass.data.proto.HVData
import ru.inr.mass.data.proto.NumassDirectorySet import ru.inr.mass.data.proto.NumassDirectorySet
import space.kscience.dataforge.values.asValue import space.kscience.dataforge.values.asValue
import space.kscience.dataforge.values.double import space.kscience.dataforge.values.double
import space.kscience.kmath.histogram.UnivariateHistogram import space.kscience.kmath.domains.center
import space.kscience.kmath.histogram.center import space.kscience.kmath.histogram.Histogram1D
import space.kscience.kmath.misc.UnstableKMathAPI import space.kscience.kmath.misc.UnstableKMathAPI
import space.kscience.kmath.operations.asIterable import space.kscience.kmath.operations.asIterable
import space.kscience.kmath.structures.Buffer import space.kscience.kmath.structures.Buffer
@ -26,9 +26,9 @@ import kotlin.time.DurationUnit
* Plot a kmath histogram * Plot a kmath histogram
*/ */
@OptIn(UnstableKMathAPI::class) @OptIn(UnstableKMathAPI::class)
fun Plot.histogram(histogram: UnivariateHistogram, block: Scatter.() -> Unit = {}): Trace = scatter { fun Plot.histogram(histogram: Histogram1D<Double, Double>, block: Scatter.() -> Unit = {}): Trace = scatter {
x.numbers = histogram.bins.map { it.domain.center } x.numbers = histogram.bins.map { it.domain.center }
y.numbers = histogram.bins.map { it.value } y.numbers = histogram.bins.map { it.binValue }
line.shape = LineShape.hv line.shape = LineShape.hv
block() block()
} }
@ -58,7 +58,7 @@ fun Plotly.plotNumassBlock(
block: NumassBlock, block: NumassBlock,
amplitudeBinSize: UInt = 20U, amplitudeBinSize: UInt = 20U,
eventExtractor: NumassEventExtractor = NumassEventExtractor.EVENTS_ONLY, eventExtractor: NumassEventExtractor = NumassEventExtractor.EVENTS_ONLY,
splitChannels: Boolean = true splitChannels: Boolean = true,
): PlotlyFragment = Plotly.fragment { ): PlotlyFragment = Plotly.fragment {
plot { plot {
runBlocking { runBlocking {