Fix to task generics.

This commit is contained in:
Alexander Nozik 2018-07-15 19:29:28 +03:00
parent 57650d6512
commit d6b93d67e5
16 changed files with 84 additions and 67 deletions

View File

@ -18,7 +18,7 @@ package inr.numass.control.dante
import hep.dataforge.context.Context import hep.dataforge.context.Context
import hep.dataforge.context.Global 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.configure
import hep.dataforge.kodex.nullable import hep.dataforge.kodex.nullable
import hep.dataforge.meta.KMetaBuilder 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 lo = meta.optNumber("window.lo").nullable?.toInt()
val up = meta.optNumber("window.up").nullable?.toInt() val up = meta.optNumber("window.up").nullable?.toInt()
val data = SimpleAnalyzer().getAmplitudeSpectrum(this, meta.getMetaOrEmpty("spectrum")).withBinning(binning, lo, up) val data = SimpleAnalyzer().getAmplitudeSpectrum(this, meta.getMetaOrEmpty("spectrum")).withBinning(binning, lo, up)
context.display( context.displayPlot {
chart { chart {
val valueAxis = if (meta.getBoolean("normalize", false)) { val valueAxis = if (meta.getBoolean("normalize", false)) {
NumassAnalyzer.COUNT_RATE_KEY NumassAnalyzer.COUNT_RATE_KEY
} else { } else {
NumassAnalyzer.COUNT_KEY 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)
} }
) plots.configure {
"connectionType" to "step"
"thickness" to 2
"showLine" to true
"showSymbol" to false
"showErrors" to false
}.setType<DataPlot>()
val plot = DataPlot.plot(
plotName,
data,
Adapters.buildXYAdapter(NumassAnalyzer.CHANNEL_KEY, valueAxis)
)
plot.configure(meta)
add(plot)
}
}
} }

View File

@ -70,7 +70,8 @@ class NumassPlugin : BasicPlugin() {
transformTask, transformTask,
filterTask, filterTask,
fitTask, fitTask,
plotFitTask plotFitTask,
histogramTask
) )
@Provides(Task.TASK_TARGET) @Provides(Task.TASK_TARGET)

View File

@ -68,7 +68,7 @@ object PlotFitResultAction : OneToOneAction<FitResult, FitResult>() {
StreamSupport.stream(data.spliterator(), false) StreamSupport.stream(data.spliterator(), false)
.map { dp -> Adapters.getXValue(adapter, dp).double }.sorted().forEach{ fit.calculateIn(it) } .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 return input
} }

View File

@ -18,13 +18,13 @@ package inr.numass.data
import hep.dataforge.context.Context import hep.dataforge.context.Context
import hep.dataforge.context.Global 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.configure
import hep.dataforge.kodex.nullable import hep.dataforge.kodex.nullable
import hep.dataforge.meta.KMetaBuilder import hep.dataforge.meta.KMetaBuilder
import hep.dataforge.meta.buildMeta import hep.dataforge.meta.buildMeta
import hep.dataforge.plots.data.DataPlot import hep.dataforge.plots.data.DataPlot
import hep.dataforge.plots.jfreechart.JFreeChartFrame import hep.dataforge.plots.jfreechart.chart
import hep.dataforge.tables.Adapters import hep.dataforge.tables.Adapters
import inr.numass.data.analyzers.NumassAnalyzer import inr.numass.data.analyzers.NumassAnalyzer
import inr.numass.data.analyzers.SmartAnalyzer 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 lo = meta.optNumber("window.lo").nullable?.toInt()
val up = meta.optNumber("window.up").nullable?.toInt() val up = meta.optNumber("window.up").nullable?.toInt()
val data = SmartAnalyzer().getAmplitudeSpectrum(this, meta.getMetaOrEmpty("spectrum")).withBinning(binning, lo, up) val data = SmartAnalyzer().getAmplitudeSpectrum(this, meta.getMetaOrEmpty("spectrum")).withBinning(binning, lo, up)
context.display { context.displayPlot {
JFreeChartFrame().apply { chart {
val valueAxis = if (meta.getBoolean("normalize", false)) { val valueAxis = if (meta.getBoolean("normalize", false)) {
NumassAnalyzer.COUNT_RATE_KEY NumassAnalyzer.COUNT_RATE_KEY
} else { } else {
@ -55,8 +55,8 @@ fun NumassBlock.plotAmplitudeSpectrum(plotName: String = "spectrum", frameName:
val plot = DataPlot.plot( val plot = DataPlot.plot(
plotName, plotName,
Adapters.buildXYAdapter(NumassAnalyzer.CHANNEL_KEY, valueAxis), data,
data Adapters.buildXYAdapter(NumassAnalyzer.CHANNEL_KEY, valueAxis)
) )
plot.configure(meta) plot.configure(meta)
add(plot) add(plot)

View File

@ -1,7 +1,7 @@
package inr.numass.models.mc package inr.numass.models.mc
import hep.dataforge.context.Global 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.maths.chain.Chain
import hep.dataforge.meta.buildMeta import hep.dataforge.meta.buildMeta
import hep.dataforge.plots.XYFunctionPlot import hep.dataforge.plots.XYFunctionPlot
@ -47,7 +47,7 @@ fun main(args: Array<String>) {
50 * distribution.density(18600.0 - it) 50 * distribution.density(18600.0 - it)
} }
Global.display { Global.displayPlot {
chart { chart {
add(spectrumPlot) add(spectrumPlot)
add(distributionPlot) add(distributionPlot)

View File

@ -72,8 +72,8 @@ fun main(args: Array<String>) {
val point = set.optPoint(hv).get() val point = set.optPoint(hv).get()
frame.add(DataPlot.plot("raw", AMPLITUDE_ADAPTER, analyzer.getAmplitudeSpectrum(point, meta).withBinning(20))) frame.add(DataPlot.plot("raw", analyzer.getAmplitudeSpectrum(point, meta).withBinning(20), AMPLITUDE_ADAPTER))
frame.add(DataPlot.plot("filtered", AMPLITUDE_ADAPTER, analyzer.getAmplitudeSpectrum(point, metaForChain).withBinning(20))) frame.add(DataPlot.plot("filtered", analyzer.getAmplitudeSpectrum(point, metaForChain).withBinning(20), AMPLITUDE_ADAPTER))
frame.add(DataPlot.plot("invertedFilter", AMPLITUDE_ADAPTER, analyzer.getAmplitudeSpectrum(point, metaForChainInverted).withBinning(20))) frame.add(DataPlot.plot("invertedFilter", analyzer.getAmplitudeSpectrum(point, metaForChainInverted).withBinning(20), AMPLITUDE_ADAPTER))
} }
} }

View File

@ -51,8 +51,8 @@ fun main(args: Array<String>) {
this.plots.configureValue("showLine", true) this.plots.configureValue("showLine", true)
} }
frame.add(DataPlot.plot("raw", AMPLITUDE_ADAPTER, analyzer.getAmplitudeSpectrum(point, meta).withBinning(80))) frame.add(DataPlot.plot("raw", analyzer.getAmplitudeSpectrum(point, meta).withBinning(80), AMPLITUDE_ADAPTER))
frame.add(DataPlot.plot("filtered", AMPLITUDE_ADAPTER, analyzer.getAmplitudeSpectrum(point, metaForChain).withBinning(80))) frame.add(DataPlot.plot("filtered", analyzer.getAmplitudeSpectrum(point, metaForChain).withBinning(80), AMPLITUDE_ADAPTER))
frame.add(DataPlot.plot("invertedFilter", AMPLITUDE_ADAPTER, analyzer.getAmplitudeSpectrum(point, metaForChainInverted).withBinning(80))) frame.add(DataPlot.plot("invertedFilter", analyzer.getAmplitudeSpectrum(point, metaForChainInverted).withBinning(80), AMPLITUDE_ADAPTER))
} }

View File

@ -81,9 +81,9 @@ fun main(args: Array<String>) {
val norm = res.getColumn(COUNT_RATE_KEY).stream().mapToDouble { it.double }.sum() 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))
} }
} }
} }

View File

@ -25,7 +25,7 @@ import inr.numass.NumassUtils
* @author Alexander Nozik * @author Alexander Nozik
*/ */
object NumassFitScanSummaryTask : AbstractTask<Table>(Table::class.java) { object NumassFitScanSummaryTask : AbstractTask<Table>(Table::class.java) {
override fun run(model: TaskModel, data: DataNode<*>): DataNode<Table> { override fun run(model: TaskModel, data: DataNode<Any>): DataNode<Table> {
val builder = DataSet.edit(Table::class) val builder = DataSet.edit(Table::class)
val action = FitSummaryAction() val action = FitSummaryAction()
val input = data.checked(FitResult::class.java) val input = data.checked(FitResult::class.java)

View File

@ -24,7 +24,7 @@ import hep.dataforge.workspace.tasks.TaskModel
*/ */
object NumassFitScanTask : AbstractTask<FitResult>(FitResult::class.java) { object NumassFitScanTask : AbstractTask<FitResult>(FitResult::class.java) {
override fun run(model: TaskModel, data: DataNode<*>): DataNode<FitResult> { override fun run(model: TaskModel, data: DataNode<Any>): DataNode<FitResult> {
val config = model.meta val config = model.meta
val scanParameter = config.getString("parameter", "msterile2") val scanParameter = config.getString("parameter", "msterile2")

View File

@ -30,7 +30,7 @@ import inr.numass.actions.SummaryAction
object NumassFitSummaryTask : AbstractTask<Table>(Table::class.java) { object NumassFitSummaryTask : AbstractTask<Table>(Table::class.java) {
override val name: String = "summary" override val name: String = "summary"
override fun run(model: TaskModel, data: DataNode<*>): DataNode<out Table> { override fun run(model: TaskModel, data: DataNode<Any>): DataNode<Table> {
val actionMeta = model.meta.getMeta("summary") val actionMeta = model.meta.getMeta("summary")
val checkedData = data.getCheckedNode("fit", FitState::class.java) val checkedData = data.getCheckedNode("fit", FitState::class.java)
return SummaryAction.run(model.context, checkedData, actionMeta) return SummaryAction.run(model.context, checkedData, actionMeta)

View File

@ -4,9 +4,6 @@ import hep.dataforge.data.CustomDataFilter
import hep.dataforge.data.DataSet import hep.dataforge.data.DataSet
import hep.dataforge.data.DataTree import hep.dataforge.data.DataTree
import hep.dataforge.data.DataUtils 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.output.stream
import hep.dataforge.io.render import hep.dataforge.io.render
import hep.dataforge.kodex.nullable import hep.dataforge.kodex.nullable
@ -44,9 +41,13 @@ import java.io.PrintWriter
import java.util.* import java.util.*
import java.util.concurrent.atomic.AtomicLong import java.util.concurrent.atomic.AtomicLong
import java.util.stream.StreamSupport import java.util.stream.StreamSupport
import kotlin.collections.set
@Description("Select data from initial data pool")
val selectTask = task("select") { val selectTask = task("select") {
descriptor {
info = "Select data from initial data pool"
}
model { meta -> model { meta ->
data("*") data("*")
configure(meta.getMetaOrEmpty("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") { val analyzeTask = task("analyze") {
descriptor {
info = "Count the number of events for each voltage and produce a table with the results"
}
model { meta -> model { meta ->
dependsOn(selectTask, meta); dependsOn(selectTask, meta);
configure(MetaUtils.optEither(meta, "analyzer", "prepare").orElse(Meta.empty())) 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") { 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 -> model { meta ->
dependsOn(selectTask, meta) dependsOn(selectTask, meta)
configure(meta.getMetaOrEmpty("monitor")) configure(meta.getMetaOrEmpty("monitor"))
@ -99,7 +102,7 @@ val monitorTableTask = task("monitor") {
).build() ).build()
if (meta.getBoolean("showPlot", true)) { 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) { context.plot(plot, "numass.monitor", name) {
"xAxis.title" to "time" "xAxis.title" to "time"
"xAxis.type" to "time" "xAxis.type" to "time"
@ -259,7 +262,7 @@ val plotFitTask = task("plotFit") {
StreamSupport.stream<Values>(data.spliterator(), false) StreamSupport.stream<Values>(data.spliterator(), false)
.map { dp -> Adapters.getXValue(adapter, dp).double }.sorted().forEach { fit.calculateIn(it) } .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) 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") { 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 -> model { meta ->
dependsOn(selectTask, meta) dependsOn(selectTask, meta)
configure(meta.getMetaOrEmpty("histogram")) configure(meta.getMetaOrEmpty("histogram"))
@ -314,10 +318,19 @@ val histogramTask = task("histogram") {
row(values) row(values)
} }
} }
//TODO increase binning
context.output.render(table, stage = "numass.histogram", name = name, meta = meta) 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<DataPlot>()
table.format.names.filter { it != "channel" }.forEach {
+DataPlot.plot(it, table, adapter = Adapters.buildXYAdapter("channel", it))
}
}
}
return@join table return@join table
} }

View File

@ -17,6 +17,7 @@ package inr.numass.models;
import hep.dataforge.stat.fit.ParamSet; import hep.dataforge.stat.fit.ParamSet;
import inr.numass.NumassPluginKt; import inr.numass.NumassPluginKt;
import inr.numass.models.misc.LossCalculator;
/** /**
* *
@ -36,6 +37,6 @@ public class PlotScatter {
+ "'ionW' = 11.33 ± 0.43\n" + "'ionW' = 11.33 ± 0.43\n"
+ "'exIonRatio' = 4.83 ± 0.36" + "'exIonRatio' = 4.83 ± 0.36"
); );
LossCalculator.plotScatter(NumassPluginKt.displayChart("Loss function"), pars); LossCalculator.INSTANCE.plotScatter(NumassPluginKt.displayChart("Loss function"), pars);
} }
} }

View File

@ -19,6 +19,7 @@ import hep.dataforge.maths.integration.GaussRuleIntegrator;
import hep.dataforge.plots.PlotFrame; import hep.dataforge.plots.PlotFrame;
import hep.dataforge.plots.XYFunctionPlot; import hep.dataforge.plots.XYFunctionPlot;
import inr.numass.NumassPluginKt; import inr.numass.NumassPluginKt;
import inr.numass.models.misc.LossCalculator;
import org.apache.commons.math3.analysis.UnivariateFunction; import org.apache.commons.math3.analysis.UnivariateFunction;
/** /**
@ -34,7 +35,7 @@ public class TestNeLossParametrisation {
public static void main(String[] args) { public static void main(String[] args) {
PlotFrame frame = NumassPluginKt.displayChart("Loss parametrisation test"); PlotFrame frame = NumassPluginKt.displayChart("Loss parametrisation test");
//JFreeChartFrame.drawFrame("Loss parametrisation test", null); //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); UnivariateFunction newFunction = getSingleScatterFunction(12.86, 16.78, 1.65, 12.38, 4.79);
Double norm = new GaussRuleIntegrator(200).integrate(0d, 100d, newFunction); Double norm = new GaussRuleIntegrator(200).integrate(0d, 100d, newFunction);

View File

@ -138,16 +138,16 @@ class AmplitudeView : View(title = "Numass amplitude spectrum plot", icon = Imag
return@runGoal if (channels.size == 1) { return@runGoal if (channels.size == 1) {
DataPlot.plot( DataPlot.plot(
key, key,
adapter, channels.values.first().withBinning(binning),
channels.values.first().withBinning(binning) adapter
) )
} else { } else {
val group = PlotGroup.typed<DataPlot>(key) val group = PlotGroup.typed<DataPlot>(key)
channels.forEach { key, spectrum -> channels.forEach { key, spectrum ->
val plot = DataPlot.plot( val plot = DataPlot.plot(
key.toString(), key.toString(),
adapter, spectrum.withBinning(binning),
spectrum.withBinning(binning) adapter
) )
group.add(plot) group.add(plot)
} }

View File

@ -54,7 +54,7 @@ class SlowControlView : View(title = "Numass slow control view", icon = ImageVie
names.forEach { names.forEach {
val adapter = Adapters.buildXYAdapter("timestamp", it); 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 "showLine" to true
"showSymbol" to false "showSymbol" to false
"showErrors" to false "showErrors" to false