From d6b93d67e56c1c569274afc391162a899e55e791 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 15 Jul 2018 19:29:28 +0300 Subject: [PATCH] Fix to task generics. --- .../inr/numass/control/dante/DanteTest.kt | 49 ++++++++++--------- .../main/kotlin/inr/numass/NumassPlugin.kt | 3 +- .../inr/numass/actions/PlotFitResultAction.kt | 2 +- .../kotlin/inr/numass/data/Visualization.kt | 12 ++--- .../inr/numass/models/mc/BetaSampler.kt | 4 +- .../inr/numass/scripts/InversedChain.kt | 6 +-- .../inr/numass/scripts/InversedChainProto.kt | 6 +-- .../scripts/models/DifferentialSpectrum.kt | 4 +- .../numass/tasks/NumassFitScanSummaryTask.kt | 2 +- .../inr/numass/tasks/NumassFitScanTask.kt | 2 +- .../inr/numass/tasks/NumassFitSummaryTask.kt | 2 +- .../kotlin/inr/numass/tasks/NumassTasks.kt | 43 ++++++++++------ .../java/inr/numass/models/PlotScatter.java | 3 +- .../models/TestNeLossParametrisation.java | 3 +- .../kotlin/inr/numass/viewer/AmplitudeView.kt | 8 +-- .../inr/numass/viewer/SlowControlView.kt | 2 +- 16 files changed, 84 insertions(+), 67 deletions(-) diff --git a/numass-control/dante/src/main/kotlin/inr/numass/control/dante/DanteTest.kt b/numass-control/dante/src/main/kotlin/inr/numass/control/dante/DanteTest.kt index 4b2901ac..17125e7e 100644 --- a/numass-control/dante/src/main/kotlin/inr/numass/control/dante/DanteTest.kt +++ b/numass-control/dante/src/main/kotlin/inr/numass/control/dante/DanteTest.kt @@ -18,7 +18,7 @@ package inr.numass.control.dante import hep.dataforge.context.Context import hep.dataforge.context.Global -import hep.dataforge.fx.plots.display +import hep.dataforge.fx.plots.displayPlot import hep.dataforge.kodex.configure import hep.dataforge.kodex.nullable import hep.dataforge.meta.KMetaBuilder @@ -79,29 +79,30 @@ fun NumassBlock.plotAmplitudeSpectrum(plotName: String = "spectrum", frameName: val lo = meta.optNumber("window.lo").nullable?.toInt() val up = meta.optNumber("window.up").nullable?.toInt() val data = SimpleAnalyzer().getAmplitudeSpectrum(this, meta.getMetaOrEmpty("spectrum")).withBinning(binning, lo, up) - context.display( - chart { - val valueAxis = if (meta.getBoolean("normalize", false)) { - NumassAnalyzer.COUNT_RATE_KEY - } else { - NumassAnalyzer.COUNT_KEY - } - plots.configure { - "connectionType" to "step" - "thickness" to 2 - "showLine" to true - "showSymbol" to false - "showErrors" to false - }.setType(DataPlot::class) - - val plot = DataPlot.plot( - plotName, - Adapters.buildXYAdapter(NumassAnalyzer.CHANNEL_KEY, valueAxis), - data - ) - plot.configure(meta) - add(plot) + context.displayPlot { + chart { + val valueAxis = if (meta.getBoolean("normalize", false)) { + NumassAnalyzer.COUNT_RATE_KEY + } else { + NumassAnalyzer.COUNT_KEY } - ) + plots.configure { + "connectionType" to "step" + "thickness" to 2 + "showLine" to true + "showSymbol" to false + "showErrors" to false + }.setType() + + val plot = DataPlot.plot( + plotName, + data, + Adapters.buildXYAdapter(NumassAnalyzer.CHANNEL_KEY, valueAxis) + ) + plot.configure(meta) + add(plot) + } + } + } \ No newline at end of file diff --git a/numass-main/src/main/kotlin/inr/numass/NumassPlugin.kt b/numass-main/src/main/kotlin/inr/numass/NumassPlugin.kt index 42a6ab78..2115b61a 100644 --- a/numass-main/src/main/kotlin/inr/numass/NumassPlugin.kt +++ b/numass-main/src/main/kotlin/inr/numass/NumassPlugin.kt @@ -70,7 +70,8 @@ class NumassPlugin : BasicPlugin() { transformTask, filterTask, fitTask, - plotFitTask + plotFitTask, + histogramTask ) @Provides(Task.TASK_TARGET) diff --git a/numass-main/src/main/kotlin/inr/numass/actions/PlotFitResultAction.kt b/numass-main/src/main/kotlin/inr/numass/actions/PlotFitResultAction.kt index 114d685b..09aa7e13 100644 --- a/numass-main/src/main/kotlin/inr/numass/actions/PlotFitResultAction.kt +++ b/numass-main/src/main/kotlin/inr/numass/actions/PlotFitResultAction.kt @@ -68,7 +68,7 @@ object PlotFitResultAction : OneToOneAction() { StreamSupport.stream(data.spliterator(), false) .map { dp -> Adapters.getXValue(adapter, dp).double }.sorted().forEach{ fit.calculateIn(it) } - context.plot(listOf(fit,DataPlot.plot("data", adapter, data)), this.name, name) + context.plot(listOf(fit,DataPlot.plot("data", data, adapter)), this.name, name) return input } diff --git a/numass-main/src/main/kotlin/inr/numass/data/Visualization.kt b/numass-main/src/main/kotlin/inr/numass/data/Visualization.kt index f51c4966..0202b097 100644 --- a/numass-main/src/main/kotlin/inr/numass/data/Visualization.kt +++ b/numass-main/src/main/kotlin/inr/numass/data/Visualization.kt @@ -18,13 +18,13 @@ package inr.numass.data import hep.dataforge.context.Context import hep.dataforge.context.Global -import hep.dataforge.fx.plots.display +import hep.dataforge.fx.plots.displayPlot import hep.dataforge.kodex.configure import hep.dataforge.kodex.nullable import hep.dataforge.meta.KMetaBuilder import hep.dataforge.meta.buildMeta import hep.dataforge.plots.data.DataPlot -import hep.dataforge.plots.jfreechart.JFreeChartFrame +import hep.dataforge.plots.jfreechart.chart import hep.dataforge.tables.Adapters import inr.numass.data.analyzers.NumassAnalyzer import inr.numass.data.analyzers.SmartAnalyzer @@ -38,8 +38,8 @@ fun NumassBlock.plotAmplitudeSpectrum(plotName: String = "spectrum", frameName: val lo = meta.optNumber("window.lo").nullable?.toInt() val up = meta.optNumber("window.up").nullable?.toInt() val data = SmartAnalyzer().getAmplitudeSpectrum(this, meta.getMetaOrEmpty("spectrum")).withBinning(binning, lo, up) - context.display { - JFreeChartFrame().apply { + context.displayPlot { + chart { val valueAxis = if (meta.getBoolean("normalize", false)) { NumassAnalyzer.COUNT_RATE_KEY } else { @@ -55,8 +55,8 @@ fun NumassBlock.plotAmplitudeSpectrum(plotName: String = "spectrum", frameName: val plot = DataPlot.plot( plotName, - Adapters.buildXYAdapter(NumassAnalyzer.CHANNEL_KEY, valueAxis), - data + data, + Adapters.buildXYAdapter(NumassAnalyzer.CHANNEL_KEY, valueAxis) ) plot.configure(meta) add(plot) diff --git a/numass-main/src/main/kotlin/inr/numass/models/mc/BetaSampler.kt b/numass-main/src/main/kotlin/inr/numass/models/mc/BetaSampler.kt index 6e404965..531129ba 100644 --- a/numass-main/src/main/kotlin/inr/numass/models/mc/BetaSampler.kt +++ b/numass-main/src/main/kotlin/inr/numass/models/mc/BetaSampler.kt @@ -1,7 +1,7 @@ package inr.numass.models.mc import hep.dataforge.context.Global -import hep.dataforge.fx.plots.display +import hep.dataforge.fx.plots.displayPlot import hep.dataforge.maths.chain.Chain import hep.dataforge.meta.buildMeta import hep.dataforge.plots.XYFunctionPlot @@ -47,7 +47,7 @@ fun main(args: Array) { 50 * distribution.density(18600.0 - it) } - Global.display { + Global.displayPlot { chart { add(spectrumPlot) add(distributionPlot) diff --git a/numass-main/src/main/kotlin/inr/numass/scripts/InversedChain.kt b/numass-main/src/main/kotlin/inr/numass/scripts/InversedChain.kt index 3bbc9dec..d2aefb8a 100644 --- a/numass-main/src/main/kotlin/inr/numass/scripts/InversedChain.kt +++ b/numass-main/src/main/kotlin/inr/numass/scripts/InversedChain.kt @@ -72,8 +72,8 @@ fun main(args: Array) { val point = set.optPoint(hv).get() - frame.add(DataPlot.plot("raw", AMPLITUDE_ADAPTER, analyzer.getAmplitudeSpectrum(point, meta).withBinning(20))) - frame.add(DataPlot.plot("filtered", AMPLITUDE_ADAPTER, analyzer.getAmplitudeSpectrum(point, metaForChain).withBinning(20))) - frame.add(DataPlot.plot("invertedFilter", AMPLITUDE_ADAPTER, analyzer.getAmplitudeSpectrum(point, metaForChainInverted).withBinning(20))) + frame.add(DataPlot.plot("raw", analyzer.getAmplitudeSpectrum(point, meta).withBinning(20), AMPLITUDE_ADAPTER)) + frame.add(DataPlot.plot("filtered", analyzer.getAmplitudeSpectrum(point, metaForChain).withBinning(20), AMPLITUDE_ADAPTER)) + frame.add(DataPlot.plot("invertedFilter", analyzer.getAmplitudeSpectrum(point, metaForChainInverted).withBinning(20), AMPLITUDE_ADAPTER)) } } diff --git a/numass-main/src/main/kotlin/inr/numass/scripts/InversedChainProto.kt b/numass-main/src/main/kotlin/inr/numass/scripts/InversedChainProto.kt index e6fdc90c..ea324a49 100644 --- a/numass-main/src/main/kotlin/inr/numass/scripts/InversedChainProto.kt +++ b/numass-main/src/main/kotlin/inr/numass/scripts/InversedChainProto.kt @@ -51,8 +51,8 @@ fun main(args: Array) { this.plots.configureValue("showLine", true) } - frame.add(DataPlot.plot("raw", AMPLITUDE_ADAPTER, analyzer.getAmplitudeSpectrum(point, meta).withBinning(80))) - frame.add(DataPlot.plot("filtered", AMPLITUDE_ADAPTER, analyzer.getAmplitudeSpectrum(point, metaForChain).withBinning(80))) - frame.add(DataPlot.plot("invertedFilter", AMPLITUDE_ADAPTER, analyzer.getAmplitudeSpectrum(point, metaForChainInverted).withBinning(80))) + frame.add(DataPlot.plot("raw", analyzer.getAmplitudeSpectrum(point, meta).withBinning(80), AMPLITUDE_ADAPTER)) + frame.add(DataPlot.plot("filtered", analyzer.getAmplitudeSpectrum(point, metaForChain).withBinning(80), AMPLITUDE_ADAPTER)) + frame.add(DataPlot.plot("invertedFilter", analyzer.getAmplitudeSpectrum(point, metaForChainInverted).withBinning(80), AMPLITUDE_ADAPTER)) } diff --git a/numass-main/src/main/kotlin/inr/numass/scripts/models/DifferentialSpectrum.kt b/numass-main/src/main/kotlin/inr/numass/scripts/models/DifferentialSpectrum.kt index dba51c4d..59327499 100644 --- a/numass-main/src/main/kotlin/inr/numass/scripts/models/DifferentialSpectrum.kt +++ b/numass-main/src/main/kotlin/inr/numass/scripts/models/DifferentialSpectrum.kt @@ -81,9 +81,9 @@ fun main(args: Array) { val norm = res.getColumn(COUNT_RATE_KEY).stream().mapToDouble { it.double }.sum() - integralFrame.add(DataPlot.plot("point_$hv", AMPLITUDE_ADAPTER, spectrum0)) + integralFrame.add(DataPlot.plot("point_$hv", spectrum0, AMPLITUDE_ADAPTER)) - frame.add(DataPlot.plot("point_$hv", AMPLITUDE_ADAPTER, res.replaceColumn(COUNT_RATE_KEY) { getDouble(COUNT_RATE_KEY) / norm })) + frame.add(DataPlot.plot("point_$hv", res.replaceColumn(COUNT_RATE_KEY) { getDouble(COUNT_RATE_KEY) / norm }, AMPLITUDE_ADAPTER)) } } } \ No newline at end of file diff --git a/numass-main/src/main/kotlin/inr/numass/tasks/NumassFitScanSummaryTask.kt b/numass-main/src/main/kotlin/inr/numass/tasks/NumassFitScanSummaryTask.kt index 247325ee..ab69ecd6 100644 --- a/numass-main/src/main/kotlin/inr/numass/tasks/NumassFitScanSummaryTask.kt +++ b/numass-main/src/main/kotlin/inr/numass/tasks/NumassFitScanSummaryTask.kt @@ -25,7 +25,7 @@ import inr.numass.NumassUtils * @author Alexander Nozik */ object NumassFitScanSummaryTask : AbstractTask(Table::class.java) { - override fun run(model: TaskModel, data: DataNode<*>): DataNode
{ + override fun run(model: TaskModel, data: DataNode): DataNode
{ val builder = DataSet.edit(Table::class) val action = FitSummaryAction() val input = data.checked(FitResult::class.java) diff --git a/numass-main/src/main/kotlin/inr/numass/tasks/NumassFitScanTask.kt b/numass-main/src/main/kotlin/inr/numass/tasks/NumassFitScanTask.kt index 97471e34..945289a7 100644 --- a/numass-main/src/main/kotlin/inr/numass/tasks/NumassFitScanTask.kt +++ b/numass-main/src/main/kotlin/inr/numass/tasks/NumassFitScanTask.kt @@ -24,7 +24,7 @@ import hep.dataforge.workspace.tasks.TaskModel */ object NumassFitScanTask : AbstractTask(FitResult::class.java) { - override fun run(model: TaskModel, data: DataNode<*>): DataNode { + override fun run(model: TaskModel, data: DataNode): DataNode { val config = model.meta val scanParameter = config.getString("parameter", "msterile2") diff --git a/numass-main/src/main/kotlin/inr/numass/tasks/NumassFitSummaryTask.kt b/numass-main/src/main/kotlin/inr/numass/tasks/NumassFitSummaryTask.kt index c387e731..a682aa0d 100644 --- a/numass-main/src/main/kotlin/inr/numass/tasks/NumassFitSummaryTask.kt +++ b/numass-main/src/main/kotlin/inr/numass/tasks/NumassFitSummaryTask.kt @@ -30,7 +30,7 @@ import inr.numass.actions.SummaryAction object NumassFitSummaryTask : AbstractTask
(Table::class.java) { override val name: String = "summary" - override fun run(model: TaskModel, data: DataNode<*>): DataNode { + override fun run(model: TaskModel, data: DataNode): DataNode
{ val actionMeta = model.meta.getMeta("summary") val checkedData = data.getCheckedNode("fit", FitState::class.java) return SummaryAction.run(model.context, checkedData, actionMeta) diff --git a/numass-main/src/main/kotlin/inr/numass/tasks/NumassTasks.kt b/numass-main/src/main/kotlin/inr/numass/tasks/NumassTasks.kt index db43f66c..77e0251a 100644 --- a/numass-main/src/main/kotlin/inr/numass/tasks/NumassTasks.kt +++ b/numass-main/src/main/kotlin/inr/numass/tasks/NumassTasks.kt @@ -4,9 +4,6 @@ import hep.dataforge.data.CustomDataFilter import hep.dataforge.data.DataSet import hep.dataforge.data.DataTree import hep.dataforge.data.DataUtils -import hep.dataforge.description.Description -import hep.dataforge.description.ValueDef -import hep.dataforge.description.ValueDefs import hep.dataforge.io.output.stream import hep.dataforge.io.render import hep.dataforge.kodex.nullable @@ -44,9 +41,13 @@ import java.io.PrintWriter import java.util.* import java.util.concurrent.atomic.AtomicLong import java.util.stream.StreamSupport +import kotlin.collections.set + -@Description("Select data from initial data pool") val selectTask = task("select") { + descriptor { + info = "Select data from initial data pool" + } model { meta -> data("*") configure(meta.getMetaOrEmpty("data")) @@ -59,8 +60,10 @@ val selectTask = task("select") { } } -@Description("Count the number of events for each voltage and produce a table with the results") val analyzeTask = task("analyze") { + descriptor { + info = "Count the number of events for each voltage and produce a table with the results" + } model { meta -> dependsOn(selectTask, meta); configure(MetaUtils.optEither(meta, "analyzer", "prepare").orElse(Meta.empty())) @@ -73,11 +76,11 @@ val analyzeTask = task("analyze") { } } -@ValueDefs( - ValueDef(key = "showPlot", type = [ValueType.BOOLEAN], info = "Show plot after complete"), - ValueDef(key = "monitorVoltage", type = [ValueType.NUMBER], info = "The voltage for monitor point") -) val monitorTableTask = task("monitor") { + descriptor { + value("showPlot", types = listOf(ValueType.BOOLEAN), info = "Show plot after complete") + value("monitorVoltage", types = listOf(ValueType.NUMBER), info = "The voltage for monitor point") + } model { meta -> dependsOn(selectTask, meta) configure(meta.getMetaOrEmpty("monitor")) @@ -99,7 +102,7 @@ val monitorTableTask = task("monitor") { ).build() if (meta.getBoolean("showPlot", true)) { - val plot = DataPlot.plot(name, Adapters.buildXYAdapter("timestamp", "cr", "crErr"), res) + val plot = DataPlot.plot(name, res, Adapters.buildXYAdapter("timestamp", "cr", "crErr")) context.plot(plot, "numass.monitor", name) { "xAxis.title" to "time" "xAxis.type" to "time" @@ -259,7 +262,7 @@ val plotFitTask = task("plotFit") { StreamSupport.stream(data.spliterator(), false) .map { dp -> Adapters.getXValue(adapter, dp).double }.sorted().forEach { fit.calculateIn(it) } - val dataPlot = DataPlot.plot("data", adapter, data) + val dataPlot = DataPlot.plot("data", data, adapter) context.plot(listOf(fit, dataPlot), "numass.plotFit", name) @@ -267,10 +270,11 @@ val plotFitTask = task("plotFit") { } } -@Description(""" - Combine amplitude spectra from multiple sets, but with the same U. -""") val histogramTask = task("histogram") { + descriptor { + value("plot",types = listOf(ValueType.BOOLEAN), defaultValue = false, info = "Show plot of the spectra") + info = "Combine amplitude spectra from multiple sets, but with the same U" + } model { meta -> dependsOn(selectTask, meta) configure(meta.getMetaOrEmpty("histogram")) @@ -314,10 +318,19 @@ val histogramTask = task("histogram") { row(values) } } + //TODO increase binning context.output.render(table, stage = "numass.histogram", name = name, meta = meta) - //TODO add plot + if (meta.getBoolean("plot", false)) { + context.plot("$name.plot", stage = "numass.histogram") { + plots.setType() + table.format.names.filter { it != "channel" }.forEach { + +DataPlot.plot(it, table, adapter = Adapters.buildXYAdapter("channel", it)) + } + } + } + return@join table } diff --git a/numass-main/src/test/java/inr/numass/models/PlotScatter.java b/numass-main/src/test/java/inr/numass/models/PlotScatter.java index 6d42421d..9d9dde39 100644 --- a/numass-main/src/test/java/inr/numass/models/PlotScatter.java +++ b/numass-main/src/test/java/inr/numass/models/PlotScatter.java @@ -17,6 +17,7 @@ package inr.numass.models; import hep.dataforge.stat.fit.ParamSet; import inr.numass.NumassPluginKt; +import inr.numass.models.misc.LossCalculator; /** * @@ -36,6 +37,6 @@ public class PlotScatter { + "'ionW' = 11.33 ± 0.43\n" + "'exIonRatio' = 4.83 ± 0.36" ); - LossCalculator.plotScatter(NumassPluginKt.displayChart("Loss function"), pars); + LossCalculator.INSTANCE.plotScatter(NumassPluginKt.displayChart("Loss function"), pars); } } diff --git a/numass-main/src/test/java/inr/numass/models/TestNeLossParametrisation.java b/numass-main/src/test/java/inr/numass/models/TestNeLossParametrisation.java index ef0624a4..a9bee707 100644 --- a/numass-main/src/test/java/inr/numass/models/TestNeLossParametrisation.java +++ b/numass-main/src/test/java/inr/numass/models/TestNeLossParametrisation.java @@ -19,6 +19,7 @@ import hep.dataforge.maths.integration.GaussRuleIntegrator; import hep.dataforge.plots.PlotFrame; import hep.dataforge.plots.XYFunctionPlot; import inr.numass.NumassPluginKt; +import inr.numass.models.misc.LossCalculator; import org.apache.commons.math3.analysis.UnivariateFunction; /** @@ -34,7 +35,7 @@ public class TestNeLossParametrisation { public static void main(String[] args) { PlotFrame frame = NumassPluginKt.displayChart("Loss parametrisation test"); //JFreeChartFrame.drawFrame("Loss parametrisation test", null); - UnivariateFunction oldFunction = LossCalculator.getSingleScatterFunction(); + UnivariateFunction oldFunction = LossCalculator.INSTANCE.getSingleScatterFunction(); UnivariateFunction newFunction = getSingleScatterFunction(12.86, 16.78, 1.65, 12.38, 4.79); Double norm = new GaussRuleIntegrator(200).integrate(0d, 100d, newFunction); diff --git a/numass-viewer/src/main/kotlin/inr/numass/viewer/AmplitudeView.kt b/numass-viewer/src/main/kotlin/inr/numass/viewer/AmplitudeView.kt index 21a3db7e..67df6269 100644 --- a/numass-viewer/src/main/kotlin/inr/numass/viewer/AmplitudeView.kt +++ b/numass-viewer/src/main/kotlin/inr/numass/viewer/AmplitudeView.kt @@ -138,16 +138,16 @@ class AmplitudeView : View(title = "Numass amplitude spectrum plot", icon = Imag return@runGoal if (channels.size == 1) { DataPlot.plot( key, - adapter, - channels.values.first().withBinning(binning) + channels.values.first().withBinning(binning), + adapter ) } else { val group = PlotGroup.typed(key) channels.forEach { key, spectrum -> val plot = DataPlot.plot( key.toString(), - adapter, - spectrum.withBinning(binning) + spectrum.withBinning(binning), + adapter ) group.add(plot) } diff --git a/numass-viewer/src/main/kotlin/inr/numass/viewer/SlowControlView.kt b/numass-viewer/src/main/kotlin/inr/numass/viewer/SlowControlView.kt index b32d249a..4eb72392 100644 --- a/numass-viewer/src/main/kotlin/inr/numass/viewer/SlowControlView.kt +++ b/numass-viewer/src/main/kotlin/inr/numass/viewer/SlowControlView.kt @@ -54,7 +54,7 @@ class SlowControlView : View(title = "Numass slow control view", icon = ImageVie names.forEach { val adapter = Adapters.buildXYAdapter("timestamp", it); - val plot = DataPlot.plot(it, adapter, plotData).configure { + val plot = DataPlot.plot(it, plotData, adapter).configure { "showLine" to true "showSymbol" to false "showErrors" to false