Fix bugs
This commit is contained in:
parent
7623007bdf
commit
792670c301
@ -5,20 +5,23 @@ import hep.dataforge.meta.get
|
||||
import hep.dataforge.meta.string
|
||||
import kotlinx.datetime.Instant
|
||||
import kotlinx.datetime.toInstant
|
||||
import kotlinx.io.text.forEachUtf8Line
|
||||
import kotlinx.io.asInputStream
|
||||
|
||||
public data class HVEntry(val timestamp: Instant, val value: Double, val channel: Int = 1) {
|
||||
public companion object {
|
||||
public fun readString(line: String): HVEntry {
|
||||
val (timeStr, channelStr, valueStr) = line.split(' ')
|
||||
return HVEntry(timeStr.toInstant(), valueStr.toDouble(), channelStr.toInt())
|
||||
return HVEntry((timeStr+"Z").toInstant(), valueStr.toDouble(), channelStr.toInt())
|
||||
}
|
||||
|
||||
public fun readEnvelope(envelope: Envelope): List<HVEntry> {
|
||||
check(envelope.meta["type"].string == "voltage"){"Expecting voltage type envelope"}
|
||||
return buildList {
|
||||
envelope.data?.read {
|
||||
forEachUtf8Line { str -> add(readString(str)) }
|
||||
//Some problems with readLines
|
||||
asInputStream().bufferedReader().lines().forEach { str->
|
||||
add(readString(str))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ public class NumassDirectorySet internal constructor(
|
||||
}
|
||||
|
||||
@OptIn(DFExperimental::class)
|
||||
public val hvData: List<HVEntry>? get(){
|
||||
public fun getHvData(): List<HVEntry>? {
|
||||
val hvFile = path / "voltage"
|
||||
return if (hvFile.exists()) {
|
||||
val envelope = context.io.readEnvelopeFile(hvFile)
|
||||
|
@ -11,7 +11,8 @@
|
||||
"*mavenLocal",
|
||||
"https://dl.bintray.com/mipt-npm/dataforge",
|
||||
"https://dl.bintray.com/mipt-npm/kscience",
|
||||
"https://dl.bintray.com/mipt-npm/dev"
|
||||
"https://dl.bintray.com/mipt-npm/dev",
|
||||
"https://kotlin.bintray.com/kotlinx"
|
||||
],
|
||||
"properties": {
|
||||
"v": "0.1.0-SNAPSHOT"
|
||||
@ -29,6 +30,6 @@
|
||||
"kscience.plotly.Plot": "HTML(JupyterPlotly.renderPlot($it))",
|
||||
"kscience.plotly.PlotlyFragment": "HTML(JupyterPlotly.renderFragment($it))",
|
||||
"kscience.plotly.PlotlyPage": "HTML(JupyterPlotly.renderPage($it), true)",
|
||||
"ru.inr.mass.data.proto.NumassDirectorySet": "HTML(JupyterPlotly.renderPage(${it.plotlyPage}), true)"
|
||||
"ru.inr.mass.data.proto.NumassDirectorySet": "HTML(JupyterPlotly.renderPage(${it.plotlyPage()}), true)"
|
||||
}
|
||||
}
|
11
numass-workspace/src/main/kotlin/ru/inr/mass/scripts/demo.kt
Normal file
11
numass-workspace/src/main/kotlin/ru/inr/mass/scripts/demo.kt
Normal file
@ -0,0 +1,11 @@
|
||||
package ru.inr.mass.workspace
|
||||
|
||||
import kscience.plotly.makeFile
|
||||
import ru.inr.mass.data.proto.readNumassDirectory
|
||||
import java.nio.file.Path
|
||||
|
||||
fun main() {
|
||||
val dataPath = Path.of("D:\\Work\\Numass\\data\\2018_04\\Adiabacity_19\\set_4\\")
|
||||
val testSet = NUMASS.context.readNumassDirectory(dataPath)
|
||||
testSet.plotlyPage().makeFile()
|
||||
}
|
@ -14,7 +14,7 @@ import ru.inr.mass.data.api.NumassPoint
|
||||
fun NumassPoint.spectrum(): UnivariateHistogram =
|
||||
UnivariateHistogram.uniform(1.0) {
|
||||
runBlocking {
|
||||
events.collect { put(it.channel.toDouble()) }
|
||||
events.collect { put(it.amplitude.toDouble()) }
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,7 +26,7 @@ fun Collection<NumassPoint>.spectrum(): UnivariateHistogram {
|
||||
return UnivariateHistogram.uniform(1.0) {
|
||||
runBlocking {
|
||||
this@spectrum.forEach { point ->
|
||||
point.events.collect { put(it.channel.toDouble()) }
|
||||
point.events.collect { put(it.amplitude.toDouble()) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -41,6 +41,6 @@ fun UnivariateHistogram.reShape(
|
||||
): UnivariateHistogram = UnivariateHistogram.uniform(binSize.toDouble()) {
|
||||
this@reShape.filter { it.position.toInt() in channelRange }.forEach { bin ->
|
||||
if(bin.size > binSize.toDouble()) error("Can't reShape the spectrum with increased binning")
|
||||
putMany(bin.position, bin.value.toLong())
|
||||
putMany(bin.position, bin.value.toInt())
|
||||
}
|
||||
}
|
@ -5,8 +5,6 @@ import kotlinx.html.h2
|
||||
import kscience.kmath.histogram.UnivariateHistogram
|
||||
import kscience.kmath.misc.UnstableKMathAPI
|
||||
import kscience.plotly.*
|
||||
import kscience.plotly.models.Bar
|
||||
import kscience.plotly.models.Scatter
|
||||
import kscience.plotly.models.Trace
|
||||
import ru.inr.mass.data.api.NumassPoint
|
||||
import ru.inr.mass.data.proto.HVEntry
|
||||
@ -18,28 +16,30 @@ fun Trace.fromSpectrum(histogram: UnivariateHistogram) {
|
||||
y.numbers = histogram.map { it.value }
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@OptIn(UnstableKMathAPI::class)
|
||||
fun Plot.spectrum(name: String, histogram: UnivariateHistogram): Bar = bar {
|
||||
fun Plot.spectrum(name: String, histogram: UnivariateHistogram): Trace = scatter {
|
||||
this.name = name
|
||||
fromSpectrum(histogram)
|
||||
}
|
||||
|
||||
fun Plot.amplitudeSpectrum(point: NumassPoint, binSize: Int = 20, range: IntRange = 0..4096, name: String = point.toString()): Bar = bar {
|
||||
fun Plot.amplitudeSpectrum(
|
||||
point: NumassPoint,
|
||||
binSize: Int = 20,
|
||||
range: IntRange = 0..2000,
|
||||
name: String = point.toString(),
|
||||
): Trace = scatter {
|
||||
spectrum(name, point.spectrum().reShape(binSize, range))
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a plot from hv data
|
||||
*/
|
||||
fun Plot.hvData(data: List<HVEntry>): Scatter = scatter {
|
||||
fun Plot.hvData(data: List<HVEntry>): Trace = scatter {
|
||||
x.strings = data.map { it.timestamp.toString() }
|
||||
y.numbers = data.map { it.value }
|
||||
}
|
||||
|
||||
fun NumassDirectorySet.plotlyPage(binSize: Int = 20, range: IntRange = 0..4096): PlotlyPage = Plotly.page {
|
||||
fun NumassDirectorySet.plotlyPage(binSize: Int = 20, range: IntRange = 0..2000): PlotlyPage = Plotly.page {
|
||||
h1 {
|
||||
+"Numass point set $path"
|
||||
}
|
||||
@ -47,11 +47,11 @@ fun NumassDirectorySet.plotlyPage(binSize: Int = 20, range: IntRange = 0..4096):
|
||||
+"Amplitude spectrum"
|
||||
}
|
||||
plot {
|
||||
points.forEach {
|
||||
points.sortedBy { it.index }.forEach {
|
||||
amplitudeSpectrum(it, binSize, range)
|
||||
}
|
||||
}
|
||||
hvData?.let {entries->
|
||||
getHvData()?.let { entries ->
|
||||
h2 {
|
||||
+"HV"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user