Plots structure update

This commit is contained in:
Alexander Nozik 2017-10-13 10:04:03 +03:00
parent 7ba31edb13
commit 4d1e02cd77
13 changed files with 42 additions and 313 deletions

View File

@ -6,7 +6,9 @@ import hep.dataforge.control.measurements.MeasurementListener
import hep.dataforge.fx.fragments.FXFragment
import hep.dataforge.fx.fragments.FragmentWindow
import hep.dataforge.fx.fragments.LogFragment
import hep.dataforge.kodex.fx.plots.PlotContainer
import hep.dataforge.meta.Meta
import hep.dataforge.plots.PlotFrame
import hep.dataforge.plots.PlotUtils
import hep.dataforge.plots.data.TimePlot
import hep.dataforge.plots.data.TimePlottableGroup
@ -140,7 +142,7 @@ class PKT8ViewConnection : DeviceViewConnection<PKT8Device>(), MeasurementListen
inner class CryoPlotView : View("PKT8 temperature plot") {
val plotFrameMeta: Meta = device.meta.getMetaOrEmpty("plotConfig")
val plotFrame: FXPlotFrame by lazy {
val plotFrame: PlotFrame by lazy {
JFreeChartFrame(plotFrameMeta).apply {
PlotUtils.setXAxis(this, "timestamp", null, "time")
}
@ -153,7 +155,7 @@ class PKT8ViewConnection : DeviceViewConnection<PKT8Device>(), MeasurementListen
override val root: Parent = borderpane {
prefWidth = 800.0
prefHeight = 600.0
PlotContainer.centerIn(this).plot = plotFrame
center = PlotContainer(plotFrame).root
top {
toolbar {
rawDataButton = togglebutton("Raw data") {

View File

@ -21,8 +21,10 @@ import hep.dataforge.control.devices.PortSensor
import hep.dataforge.control.devices.Sensor
import hep.dataforge.fx.fragments.FragmentWindow
import hep.dataforge.fx.fragments.LogFragment
import hep.dataforge.kodex.fx.plots.PlotContainer
import hep.dataforge.meta.Meta
import hep.dataforge.meta.MetaBuilder
import hep.dataforge.plots.PlotFrame
import hep.dataforge.plots.PlotUtils
import hep.dataforge.plots.data.TimePlot
import hep.dataforge.plots.data.TimePlottableGroup
@ -71,7 +73,7 @@ class MspViewConnection() : DeviceViewConnection<MspDevice>(), DeviceListener, N
inner class MspView : View("Numass mass-spectrometer measurement") {
val plotFrameMeta: Meta = device.meta().getMeta("plotConfig", device.meta)
val plotFrame: FXPlotFrame by lazy {
val plotFrame: PlotFrame by lazy {
val basePlotConfig = MetaBuilder("plotFrame")
.setNode(MetaBuilder("yAxis")
.setValue("type", "log")
@ -177,7 +179,7 @@ class MspViewConnection() : DeviceViewConnection<MspDevice>(), DeviceListener, N
}
}
}
PlotContainer.centerIn(this).plot = plotFrame
center = PlotContainer(plotFrame).root
}
init {

View File

@ -1,6 +1,7 @@
package inr.numass.control
import hep.dataforge.kodex.KMetaBuilder
import hep.dataforge.kodex.fx.plots.PlotContainer
import hep.dataforge.plots.Plot
import hep.dataforge.plots.PlotFrame
import hep.dataforge.plots.jfreechart.JFreeChartFrame
@ -143,6 +144,6 @@ fun BorderPane.plot(plottables: Iterable<Plot> = Collections.emptyList(), metaTr
metaTransform?.invoke(meta)
val plot = JFreeChartFrame(meta)
plot.addAll(plottables)
PlotContainer.centerIn(this).plot = plot
center = PlotContainer(plot).root
return plot;
}

View File

@ -33,6 +33,7 @@ dependencies {
compile "hep.dataforge:dataforge-minuit" //project(':dataforge-stat:dataforge-minuit')
compile "hep.dataforge:grind-terminal" //project(':dataforge-grind:grind-terminal')
compile "hep.dataforge:kmath"
compile "hep.dataforge:kodex-fx"
}
task repl(dependsOn: classes, type: JavaExec) {

View File

@ -19,11 +19,11 @@ import hep.dataforge.actions.ActionManager;
import hep.dataforge.context.BasicPlugin;
import hep.dataforge.context.Context;
import hep.dataforge.context.PluginDef;
import hep.dataforge.kodex.fx.plots.PlotContainer;
import hep.dataforge.maths.MathPlugin;
import hep.dataforge.meta.Meta;
import hep.dataforge.plotfit.PlotFitResultAction;
import hep.dataforge.plots.PlotDataAction;
import hep.dataforge.plots.fx.FXPlotUtils;
import hep.dataforge.plots.jfreechart.JFreeChartFrame;
import hep.dataforge.stat.fit.FitManager;
import hep.dataforge.stat.models.ModelManager;
@ -57,15 +57,14 @@ public class NumassPlugin extends BasicPlugin {
* @return
*/
public static JFreeChartFrame displayJFreeChart(String title, double width, double height, Meta meta) {
PlotContainer container = FXPlotUtils.displayContainer(title, width, height);
JFreeChartFrame frame = new JFreeChartFrame(meta);
frame.configureValue("title", title);
container.setPlot(frame);
PlotContainer.Companion.display(frame,title,width,height);
return frame;
}
public static JFreeChartFrame displayJFreeChart(String title, Meta meta) {
return displayJFreeChart(title, 800, 600, meta);
public static JFreeChartFrame displayJFreeChart(String title) {
return displayJFreeChart(title, 800, 600, Meta.empty());
}

View File

@ -36,6 +36,6 @@ public class PlotScatter {
+ "'ionW' = 11.33 ± 0.43\n"
+ "'exIonRatio' = 4.83 ± 0.36"
);
LossCalculator.plotScatter(NumassPlugin.displayJFreeChart("Loss function", null), pars);
LossCalculator.plotScatter(NumassPlugin.displayJFreeChart("Loss function"), pars);
}
}

View File

@ -32,7 +32,7 @@ public class TestNeLossParametrisation {
* @param args the command line arguments
*/
public static void main(String[] args) {
PlotFrame frame = NumassPlugin.displayJFreeChart("Loss parametrisation test", null);
PlotFrame frame = NumassPlugin.displayJFreeChart("Loss parametrisation test");
//JFreeChartFrame.drawFrame("Loss parametrisation test", null);
UnivariateFunction oldFunction = LossCalculator.getSingleScatterFunction();
UnivariateFunction newFunction = getSingleScatterFunction(12.86, 16.78, 1.65, 12.38, 4.79);

View File

@ -28,12 +28,12 @@ import inr.numass.NumassPlugin;
public class TransmissionInterpolatorTest {
public static void main(String[] args) {
JFreeChartFrame frame = NumassPlugin.displayJFreeChart("TransmissionInterpolatorTest", null);
JFreeChartFrame frame = NumassPlugin.displayJFreeChart("TransmissionInterpolatorTest");
//JFreeChartFrame.drawFrame("TransmissionInterpolatorTest", null);
TransmissionInterpolator interpolator = TransmissionInterpolator.fromFile(Global.instance(),
"d:\\sterile-new\\loss2014-11\\.dataforge\\merge\\empty_sum.onComplete", "Uset", "CR", 15, 0.8, 19002d);
frame.add(PlotData.plot("data", interpolator.getX(), interpolator.getY()));
frame.add(PlotXYFunction.plotFunction("interpolated", x->interpolator.value(x), interpolator.getXmin(), interpolator.getXmax(), 2000));
frame.add(PlotXYFunction.plotFunction("interpolated", interpolator::value, interpolator.getXmin(), interpolator.getXmax(), 2000));
// PrintFunction.printFuntionSimple(new PrintWriter(System.onComplete), interpolator, interpolator.getXmin(), interpolator.getXmax(), 500);
}

View File

@ -1,254 +0,0 @@
/*
* Copyright 2015 Alexander Nozik.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package inr.numass.viewer;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import hep.dataforge.context.Context;
import hep.dataforge.context.Encapsulated;
import hep.dataforge.names.AlphanumComparator;
import hep.dataforge.names.Name;
import hep.dataforge.plots.PlotUtils;
import hep.dataforge.plots.data.PlotDataUtils;
import hep.dataforge.plots.data.XYPlot;
import hep.dataforge.plots.jfreechart.JFreeChartFrame;
import hep.dataforge.storage.api.PointLoader;
import hep.dataforge.storage.api.Storage;
import hep.dataforge.storage.commons.StorageUtils;
import hep.dataforge.tables.ValueMap;
import hep.dataforge.values.Value;
import hep.dataforge.values.Values;
import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* FXML Controller class
*
* @author darksnake
*/
public class MspViewController implements Encapsulated {
private final Context context;
private BorderPane root = new BorderPane();
@FXML
private AnchorPane mspPlotPane;
public MspViewController(Context context) {
this.context = context;
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/MspView.fxml"));
loader.setController(this);
loader.setRoot(root);
try {
loader.load();
} catch (IOException e) {
throw new Error(e);
}
}
public BorderPane getRoot() {
return root;
}
@Override
public Context getContext() {
return context;
}
/**
* update detector pane with new data
*/
private void updateMspPane(Iterable<? extends XYPlot> mspData) {
JFreeChartFrame frame = new JFreeChartFrame();
PlotUtils.setYAxis(frame, "partial pressure", "mbar", "log");
frame.getConfig().setValue("yAxis.range.lower", 1e-10);
frame.getConfig().setValue("yAxis.range.upper", 1e-3);
PlotUtils.setXAxis(frame, "time", null, "time");
// StreamSupport.stream(mspData.spliterator(), false)
// .sorted((XYPlot o1, XYPlot o2)
// -> Integer.valueOf(o1.getName()).compareTo(Integer.valueOf(o2.getName()))).forEach((pl) -> frame.add(pl));
frame.addAll(mspData);
Platform.runLater(() -> {
mspPlotPane.getChildren().clear();
PlotContainer container = PlotContainer.anchorTo(mspPlotPane);
container.setPlot(frame);
});
}
public List<PointLoader> listMspLoaders(Storage rootStorage) {
return StorageUtils.loaderStream(rootStorage)
.filter(pair -> Name.of(pair.getKey()).getLast().toString().startsWith("msp"))
.map(pair -> pair.getValue())
.filter(loader -> PointLoader.POINT_LOADER_TYPE.equals(loader.getType()))
.map(loader -> (PointLoader) loader)
.collect(Collectors.toList());
}
public void plotData(List<PointLoader> loaders) {
// TimePlottableGroup getPlottables = new TimePlottableGroup();
// loaders.stream()
// .flatMap(loader -> getLoaderData(loader))
// .distinct()
// .forEach(point -> {
// for (String name : point.names()) {
// if (!name.equals("timestamp")) {
// if (!getPlottables.has(name)) {
// getPlottables.addPlottable(new TimePlot(name, name));
// }
// }
// }
// getPlottables.put(point);
// }
// );
Collection<String> names = joinNames(loaders);
Stream<Values> stream = loaders.stream().flatMap(loader -> getLoaderData(loader));
updateMspPane(PlotDataUtils.buildGroup("timestamp", names, stream));
}
/**
* Combine names of different point loaders
*
* @param loaders
* @return
*/
private Collection<String> joinNames(List<PointLoader> loaders) {
Set<String> nameSet = new TreeSet<>(new AlphanumComparator());
for (PointLoader loader : loaders) {
nameSet.addAll(loader.getFormat().getNames().asList());
}
return nameSet;
}
private Stream<Values> getLoaderData(PointLoader loader) {
try {
loader.open();
List<Values> points = new ArrayList<>();
// callback.updateStatus("Loading mass spectrometer data from " + loader.getName());
Values last = null;
for (Values dp : loader) {
points.add(dp);
last = dp;
}
if (last != null) {
points.add(terminatorPoint(last));
}
return points.stream();
} catch (Exception ex) {
LoggerFactory.getLogger(getClass()).error("Can't read msp loader data", ex);
return Stream.empty();
}
}
public void fillMspData(Storage rootStorage) {
plotData(listMspLoaders(rootStorage));
}
// public void fillMspData(Storage rootStorage) {
// if (rootStorage != null) {
// context.taskManager().submit("viewer.msp.fill", (TaskCallback callback) -> {
// // callback.updateTitle("Fill msp data (" + rootStorage.getName() + ")");
//
// callback.updateTitle("Load msp data (" + rootStorage.getName() + ")");
//
// List<DataPoint> mspData = new ArrayList<>();
//
// StorageUtils.loaderStream(rootStorage)
// .filter(pair -> pair.getValue() instanceof PointLoader)
// .filter(pair -> Name.of(pair.getKey()).getLast().toString().startsWith("msp"))
// .map(pair -> pair.getValue())
// .filter(loader -> PointLoader.POINT_LOADER_TYPE.equals(loader.getType()))
// .forEach(loader -> {
// try {
// PointLoader mspLoader = (PointLoader) loader;
// mspLoader.open();
// callback.updateStatus("Loading mass spectrometer data from " + mspLoader.getName());
// DataPoint last = null;
// for (DataPoint dp : mspLoader) {
// mspData.add(dp);
// last = dp;
// }
// if (last != null) {
// mspData.add(terminatorPoint(last));
// }
// } catch (Exception ex) {
// LoggerFactory.getLogger(getClass()).error("Can't read msp loader data", ex);
// }
// });
// callback.updateStatus("Loading msp data finished");
//// return mspData;
//// List<DataPoint> mspData = (List<DataPoint>) loadProcess.getTask().get();
//
// if (!mspData.isEmpty()) {
// TimePlottableGroup getPlottables = new TimePlottableGroup();
//
// for (DataPoint point : mspData) {
// for (String name : point.names()) {
// if (!name.equals("timestamp")) {
// if (!getPlottables.has(name)) {
// getPlottables.add(new TimePlot(name, name));
// }
// }
// }
// getPlottables.put(point);
// }
//
// updateMspPane(getPlottables);
// }
// });
// }
// }
/**
* Create a null value point to terminate msp series
*
* @param last
* @return
*/
private Values terminatorPoint(Values last) {
ValueMap.Builder p = new ValueMap.Builder();
p.putValue("timestamp", last.getValue("timestamp").timeValue().plusMillis(10));
for (String name : last.namesAsArray()) {
if (!name.equals("timestamp")) {
p.putValue(name, Value.NULL);
}
}
return p.build();
}
}

View File

@ -4,6 +4,7 @@ import hep.dataforge.context.Context
import hep.dataforge.context.Global
import hep.dataforge.io.ColumnedDataWriter
import hep.dataforge.kodex.buildMeta
import hep.dataforge.kodex.fx.plots.PlotContainer
import hep.dataforge.meta.Meta
import hep.dataforge.meta.MetaBuilder
import hep.dataforge.plots.XYPlotFrame
@ -64,9 +65,11 @@ class NumassLoaderView : View() {
private val hvPane: BorderPane by fxid();
private val spectrumExportButton: Button by fxid();
private val detectorPlot: PlotContainer = PlotContainer.centerIn(detectorPlotPane)
private val spectrumPlot: PlotContainer = PlotContainer.centerIn(spectrumPlotPane)
private val hvPlot: PlotContainer = PlotContainer.centerIn(hvPane)
// private val detectorPlot: PlotContainer = PlotContainer.centerIn(detectorPlotPane)
// private val spectrumPlot: PlotContainer = PlotContainer.centerIn(spectrumPlotPane)
// private val hvPlot: PlotContainer = PlotContainer.centerIn(hvPane)
private val detectorBinningSelector: ChoiceBox<Int> = ChoiceBox(FXCollections.observableArrayList(1, 2, 5, 10, 20, 50))
private val detectorNormalizeSwitch: CheckBox = CheckBox("Normalize")
private val detectorDataExportButton: Button = Button("Export")
@ -109,6 +112,10 @@ class NumassLoaderView : View() {
.build()
private val detectorPlot: PlotContainer = PlotContainer(detectorPlotFrame);
private lateinit var spectrumPlot: PlotContainer;
private lateinit var hvPlot: PlotContainer;
init {
//setup detector pane plot and sidebar
val l = Label("Bin size:")
@ -119,14 +126,14 @@ class NumassLoaderView : View() {
detectorNormalizeSwitch.isSelected = true
detectorNormalizeSwitch.padding = Insets(5.0)
detectorPlot.plot = detectorPlotFrame
detectorPlotPane.center = detectorPlot.root
detectorPlot.addToSideBar(0, l, detectorBinningSelector, detectorNormalizeSwitch, Separator(Orientation.HORIZONTAL))
detectorDataExportButton.maxWidth = java.lang.Double.MAX_VALUE
detectorDataExportButton.onAction = EventHandler { this.onExportButtonClick(it) }
detectorPlot.addToSideBar(detectorDataExportButton)
detectorPlot.setSideBarPosition(0.7)
detectorPlot.sideBarPoistion = 0.7
//setup spectrum pane
spectrumExportButton.onAction = EventHandler { this.onSpectrumExportClick(it) }
@ -137,9 +144,8 @@ class NumassLoaderView : View() {
.setValue("yAxis.axisTitle", "count rate")
.setValue("yAxis.axisUnits", "Hz")
.setValue("legend.show", false)
spectrumPlot.plot = JFreeChartFrame(spectrumPlotMeta).apply {
add(spectrumData)
}
spectrumPlot = PlotContainer(JFreeChartFrame(spectrumPlotMeta).apply { add(spectrumData) })
spectrumPlotPane.center = spectrumPlot.root
lowChannelField.textProperty().bindBidirectional(channelSlider.lowValueProperty(), NumberStringConverter())
upChannelField.textProperty().bindBidirectional(channelSlider.highValueProperty(), NumberStringConverter())
@ -192,7 +198,8 @@ class NumassLoaderView : View() {
.setValue("xAxis.axisTitle", "time")
.setValue("xAxis.type", "time")
.setValue("yAxis.axisTitle", "HV")
hvPlot.plot = JFreeChartFrame(hvPlotMeta)
hvPlot = PlotContainer(JFreeChartFrame(hvPlotMeta))
hvPane.center = hvPlot.root
dataProperty.addListener { observable, oldValue, newData ->
//clearing spectra cache
@ -278,7 +285,7 @@ class NumassLoaderView : View() {
data.points.map { point ->
val count = NumassAnalyzer.countInWindow(getSpectrum(point), loChannel, upChannel);
val seconds = point.length.toMillis() / 1000.0;
spectrumPlot.setProgress(-1.0);
spectrumPlot.progress = -1.0;
ValueMap.ofMap(
mapOf(
XYAdapter.X_AXIS to point.voltage,
@ -289,7 +296,7 @@ class NumassLoaderView : View() {
}.collect(Collectors.toList())
} ui { points ->
spectrumData.fillData(points)
spectrumPlot.setProgress(1.0)
spectrumPlot.progress = 1.0
spectrumExportButton.isDisable = false
}
}
@ -318,7 +325,7 @@ class NumassLoaderView : View() {
}
runAsync {
Platform.runLater { detectorPlot.progressProperty().bind(progressProperty()) }
Platform.runLater { detectorPlot.progressProperty.bind(progressProperty()) }
val totalCount = data.points.count();
val index = AtomicInteger(0);
data.points.map { point ->

View File

@ -2,6 +2,7 @@ package inr.numass.viewer
import hep.dataforge.kodex.buildMeta
import hep.dataforge.kodex.configure
import hep.dataforge.kodex.fx.plots.PlotContainer
import hep.dataforge.meta.Meta
import hep.dataforge.plots.Plot
import hep.dataforge.plots.data.PlotData
@ -26,7 +27,7 @@ class SlowControlView : View("My View") {
val plot = JFreeChartFrame(plotMeta)
override val root = borderpane {
PlotContainer.centerIn(this).plot = plot
center = PlotContainer(plot).root
}
fun load(loader: PointLoader) {

View File

@ -1,5 +1,6 @@
package inr.numass.viewer.test
import hep.dataforge.kodex.fx.plots.PlotContainer
import hep.dataforge.plots.data.PlotData
import hep.dataforge.plots.jfreechart.JFreeChartFrame
import hep.dataforge.tables.ValueMap
@ -14,7 +15,6 @@ class JFCTest : View("My View") {
val rnd = Random();
val plot = JFreeChartFrame();
val container = PlotContainer();
val data = PlotData("data");
val button = button("test") {
@ -28,10 +28,7 @@ class JFCTest : View("My View") {
};
override val root = borderpane {
center {
container.plot = plot
add(container.pane)
}
center = PlotContainer(plot).root
bottom {
add(button)
}

View File

@ -1,27 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2015 Alexander Nozik.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<fx:root type="BorderPane" xmlns="http://javafx.com/javafx/8.0.76-ea" xmlns:fx="http://javafx.com/fxml/1">
<center>
<AnchorPane fx:id="mspPlotPane" BorderPane.alignment="CENTER"/>
</center>
</fx:root>