Plots update

This commit is contained in:
Alexander Nozik 2021-05-17 16:53:51 +03:00
parent 2f3e9357ff
commit 014628f2fd
2 changed files with 36 additions and 18 deletions

View File

@ -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()

View File

@ -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<HVEntry>): 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)
}
}
}
}
/**
* 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()
set(value) {
this.value = value.asIterable().map { it.asValue() }.asValue()
}