Fix for number started xml name
This commit is contained in:
parent
84f043c77d
commit
cb2969a337
@ -19,7 +19,6 @@ import hep.dataforge.context.Context
|
|||||||
import hep.dataforge.data.DataNode
|
import hep.dataforge.data.DataNode
|
||||||
import hep.dataforge.data.DataSet
|
import hep.dataforge.data.DataSet
|
||||||
import hep.dataforge.data.binary.Binary
|
import hep.dataforge.data.binary.Binary
|
||||||
import hep.dataforge.fx.plots.plusAssign
|
|
||||||
import hep.dataforge.io.envelopes.DefaultEnvelopeType
|
import hep.dataforge.io.envelopes.DefaultEnvelopeType
|
||||||
import hep.dataforge.io.envelopes.Envelope
|
import hep.dataforge.io.envelopes.Envelope
|
||||||
import hep.dataforge.io.envelopes.EnvelopeBuilder
|
import hep.dataforge.io.envelopes.EnvelopeBuilder
|
||||||
@ -29,13 +28,7 @@ import hep.dataforge.io.markup.SimpleMarkupRenderer
|
|||||||
import hep.dataforge.kodex.nullable
|
import hep.dataforge.kodex.nullable
|
||||||
import hep.dataforge.meta.Meta
|
import hep.dataforge.meta.Meta
|
||||||
import hep.dataforge.meta.MetaBuilder
|
import hep.dataforge.meta.MetaBuilder
|
||||||
import hep.dataforge.plots.PlotUtils
|
|
||||||
import hep.dataforge.plots.XYFunctionPlot
|
|
||||||
import hep.dataforge.plots.data.DataPlot
|
|
||||||
import hep.dataforge.plots.jfreechart.JFreeChartFrame
|
import hep.dataforge.plots.jfreechart.JFreeChartFrame
|
||||||
import hep.dataforge.stat.fit.FitResult
|
|
||||||
import hep.dataforge.stat.models.XYModel
|
|
||||||
import hep.dataforge.tables.Adapters
|
|
||||||
import hep.dataforge.tables.ListTable
|
import hep.dataforge.tables.ListTable
|
||||||
import hep.dataforge.tables.Table
|
import hep.dataforge.tables.Table
|
||||||
import hep.dataforge.tables.ValueMap
|
import hep.dataforge.tables.ValueMap
|
||||||
@ -270,37 +263,37 @@ fun Values.unbox(): Map<String, Any?> {
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
fun FitResult.display(context: Context, stage: String = "fit") {
|
//fun FitResult.display(context: Context, stage: String = "fit") {
|
||||||
val model = optModel(context).get() as XYModel
|
// val model = optModel(context).get() as XYModel
|
||||||
|
//
|
||||||
val adapter = model.adapter
|
// val adapter = model.adapter
|
||||||
|
//
|
||||||
val frame = PlotUtils.getPlotManager(context)
|
// val frame = PlotUtils.getPlotManager(context)
|
||||||
.getPlotFrame(stage, "plot", Meta.empty())
|
// .getPlotFrame(stage, "plot", Meta.empty())
|
||||||
|
//
|
||||||
val func = { x: Double -> model.spectrum.value(x, parameters) }
|
// val func = { x: Double -> model.spectrum.value(x, parameters) }
|
||||||
|
//
|
||||||
val fit = XYFunctionPlot("fit", function = func)
|
// val fit = XYFunctionPlot("fit", function = func)
|
||||||
fit.density = 100
|
// fit.density = 100
|
||||||
// ensuring all data points are calculated explicitly
|
// // ensuring all data points are calculated explicitly
|
||||||
data.rows.map { dp -> Adapters.getXValue(adapter, dp).doubleValue() }.sorted().forEach { fit.calculateIn(it) }
|
// data.rows.map { dp -> Adapters.getXValue(adapter, dp).doubleValue() }.sorted().forEach { fit.calculateIn(it) }
|
||||||
|
//
|
||||||
frame.add(fit)
|
// frame.add(fit)
|
||||||
|
//
|
||||||
frame.add(DataPlot.plot("data", adapter, data))
|
// frame.add(DataPlot.plot("data", adapter, data))
|
||||||
|
//
|
||||||
val residualsFrame = PlotUtils.getPlotManager(context)
|
// val residualsFrame = PlotUtils.getPlotManager(context)
|
||||||
.getPlotFrame(stage, "residuals", Meta.empty())
|
// .getPlotFrame(stage, "residuals", Meta.empty())
|
||||||
|
//
|
||||||
val residual = DataPlot("residuals");
|
// val residual = DataPlot("residuals");
|
||||||
|
//
|
||||||
data.rows.forEach {
|
// data.rows.forEach {
|
||||||
val x = Adapters.getXValue(adapter, it).doubleValue()
|
// val x = Adapters.getXValue(adapter, it).doubleValue()
|
||||||
val y = Adapters.getYValue(adapter, it).doubleValue()
|
// val y = Adapters.getYValue(adapter, it).doubleValue()
|
||||||
val err = Adapters.optYError(adapter, it).orElse(1.0)
|
// val err = Adapters.optYError(adapter, it).orElse(1.0)
|
||||||
residual += Adapters.buildXYDataPoint(x, (y - func(x)) / err, 1.0)
|
// residual += Adapters.buildXYDataPoint(x, (y - func(x)) / err, 1.0)
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
residualsFrame.add(residual)
|
// residualsFrame.add(residual)
|
||||||
|
//
|
||||||
}
|
//}
|
||||||
|
@ -44,17 +44,19 @@ fun NumassBlock.plotAmplitudeSpectrum(plotName: String = "spectrum", frameName:
|
|||||||
} else {
|
} else {
|
||||||
NumassAnalyzer.COUNT_KEY
|
NumassAnalyzer.COUNT_KEY
|
||||||
}
|
}
|
||||||
val plot = DataPlot.plot(
|
plots.configure {
|
||||||
plotName,
|
|
||||||
Adapters.buildXYAdapter(NumassAnalyzer.CHANNEL_KEY, valueAxis),
|
|
||||||
data
|
|
||||||
).configure {
|
|
||||||
"connectionType" to "step"
|
"connectionType" to "step"
|
||||||
"thickness" to 2
|
"thickness" to 2
|
||||||
"showLine" to true
|
"showLine" to true
|
||||||
"showSymbol" to false
|
"showSymbol" to false
|
||||||
"showErrors" to false
|
"showErrors" to false
|
||||||
}
|
}.setType(DataPlot::class)
|
||||||
|
|
||||||
|
val plot = DataPlot.plot(
|
||||||
|
plotName,
|
||||||
|
Adapters.buildXYAdapter(NumassAnalyzer.CHANNEL_KEY, valueAxis),
|
||||||
|
data
|
||||||
|
)
|
||||||
plot.configure(meta)
|
plot.configure(meta)
|
||||||
add(plot)
|
add(plot)
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,30 @@
|
|||||||
|
package inr.numass.scripts.tristan
|
||||||
|
|
||||||
|
import hep.dataforge.kodex.toList
|
||||||
|
import inr.numass.data.api.MetaBlock
|
||||||
|
import inr.numass.data.api.NumassBlock
|
||||||
|
import inr.numass.data.api.NumassPoint
|
||||||
|
import inr.numass.data.channel
|
||||||
|
import inr.numass.data.plotAmplitudeSpectrum
|
||||||
|
import inr.numass.data.storage.ProtoNumassPoint
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
|
||||||
|
private fun NumassPoint.getChannels(): Map<Int, NumassBlock> {
|
||||||
|
return blocks.toList().groupBy { it.channel ?: 0 }.mapValues { entry ->
|
||||||
|
if (entry.value.size == 1) {
|
||||||
|
entry.value.first()
|
||||||
|
} else {
|
||||||
|
MetaBlock(entry.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun main(args: Array<String>) {
|
||||||
|
val file = File("D:\\Work\\Numass\\data\\17kV\\processed.df").toPath()
|
||||||
|
val point = ProtoNumassPoint.readFile(file)
|
||||||
|
println(point.meta)
|
||||||
|
point.getChannels().forEach{ num, block ->
|
||||||
|
block.plotAmplitudeSpectrum(plotName = num.toString())
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user