From 014628f2fd56d2942915cf0107596756d1ed7c0d Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Mon, 17 May 2021 16:53:51 +0300 Subject: [PATCH] Plots update --- .../ru/inr/mass/scripts/sterileSpectrum.kt | 8 ++-- .../kotlin/ru/inr/mass/workspace/plots.kt | 46 +++++++++++++------ 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/numass-workspace/src/main/kotlin/ru/inr/mass/scripts/sterileSpectrum.kt b/numass-workspace/src/main/kotlin/ru/inr/mass/scripts/sterileSpectrum.kt index da263a3..5ed2175 100644 --- a/numass-workspace/src/main/kotlin/ru/inr/mass/scripts/sterileSpectrum.kt +++ b/numass-workspace/src/main/kotlin/ru/inr/mass/scripts/sterileSpectrum.kt @@ -4,10 +4,11 @@ import inr.numass.models.sterile.NumassBeta.e0 import inr.numass.models.sterile.NumassBeta.mnu2 import inr.numass.models.sterile.NumassBeta.msterile2 import inr.numass.models.sterile.NumassBeta.u2 +import inr.numass.models.sterile.NumassTransmission.Companion.thickness import inr.numass.models.sterile.SterileNeutrinoSpectrum +import ru.inr.mass.workspace.buffer import space.kscience.kmath.misc.Symbol import space.kscience.kmath.real.step -import space.kscience.kmath.structures.asIterable import space.kscience.plotly.Plotly import space.kscience.plotly.makeFile import space.kscience.plotly.models.ScatterMode @@ -19,12 +20,13 @@ fun main() { mnu2 to 0.0, e0 to 18575.0, msterile2 to 1e6, - u2 to 1e-2 + u2 to 1e-2, + thickness to 0.2 ) Plotly.plot { scatter { mode = ScatterMode.lines - x.numbers = (14000.0..18600.0 step 1.0).asIterable() + x.buffer = 14000.0..18600.0 step 10.0 y.numbers = x.numbers.map { spectrum(it.toDouble(), args) } } }.makeFile() diff --git a/numass-workspace/src/main/kotlin/ru/inr/mass/workspace/plots.kt b/numass-workspace/src/main/kotlin/ru/inr/mass/workspace/plots.kt index 44d4ff0..71d76e4 100644 --- a/numass-workspace/src/main/kotlin/ru/inr/mass/workspace/plots.kt +++ b/numass-workspace/src/main/kotlin/ru/inr/mass/workspace/plots.kt @@ -5,11 +5,17 @@ import kotlinx.html.h2 import ru.inr.mass.data.api.NumassPoint import ru.inr.mass.data.proto.HVEntry import ru.inr.mass.data.proto.NumassDirectorySet +import space.kscience.dataforge.values.asValue +import space.kscience.dataforge.values.double import space.kscience.kmath.histogram.UnivariateHistogram import space.kscience.kmath.histogram.center import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.DoubleBuffer +import space.kscience.kmath.structures.asIterable import space.kscience.plotly.* import space.kscience.plotly.models.Trace +import space.kscience.plotly.models.TraceValues @OptIn(UnstableKMathAPI::class) fun Trace.fromSpectrum(histogram: UnivariateHistogram) { @@ -40,24 +46,34 @@ fun Plot.hvData(data: List): Trace = scatter { y.numbers = data.map { it.value } } -fun Plotly.numassDirectory(set: NumassDirectorySet, binSize: Int = 20, range: IntRange = 0..2000): PlotlyPage = Plotly.page { - h1 { - +"Numass point set ${set.path}" - } - h2 { - +"Amplitude spectrum" - } - plot { - set.points.sortedBy { it.index }.forEach { - amplitudeSpectrum(it, binSize, range) +fun Plotly.numassDirectory(set: NumassDirectorySet, binSize: Int = 20, range: IntRange = 0..2000): PlotlyPage = + Plotly.page { + h1 { + +"Numass point set ${set.path}" } - } - set.getHvData()?.let { entries -> h2 { - +"HV" + +"Amplitude spectrum" } plot { - hvData(entries) + set.points.sortedBy { it.index }.forEach { + amplitudeSpectrum(it, binSize, range) + } + } + set.getHvData()?.let { entries -> + h2 { + +"HV" + } + plot { + hvData(entries) + } } } -} \ No newline at end of file + +/** + * Add a number buffer accessor for Plotly trace values + */ +public var TraceValues.buffer: Buffer + get() = value?.list?.let { list -> DoubleBuffer(list.size) { list[it].double } } ?: DoubleBuffer() + set(value) { + this.value = value.asIterable().map { it.asValue() }.asValue() + } \ No newline at end of file