[no commit message]

This commit is contained in:
Alexander Nozik 2016-02-17 15:08:21 +03:00
parent 1d1c2698c7
commit ecf91cb442
43 changed files with 419 additions and 519 deletions

View File

@ -1,6 +1,6 @@
apply plugin: 'application'
version = "0.2.5"
version = "0.3.0"
if (!hasProperty('mainClass')) {
ext.mainClass = 'inr.numass.control.magnet.fx.MagnetControllerApp'

View File

@ -13,34 +13,34 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package inr.numass.control.magnet;
import hep.dataforge.control.ports.PortHandler;
import hep.dataforge.control.ports.ComPortHandler;
import jssc.SerialPortException;
/**
*
* @author Alexander Nozik
*/
public class SetCurrent {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws SerialPortException {
if (args.length < 3) {
throw new IllegalArgumentException("Wrong number of parameters");
}
String comName = args[0];
int lambdaaddress = Integer.valueOf(args[1]);
double current = Double.valueOf(args[2]);
PortHandler handler = new ComPortHandler(comName);
MagnetController controller = new MagnetController(handler, lambdaaddress);
controller.startUpdateTask(current, 500);
}
}
package inr.numass.control.magnet;
import hep.dataforge.control.ports.ComPortHandler;
import hep.dataforge.control.ports.PortHandler;
import jssc.SerialPortException;
/**
*
* @author Alexander Nozik
*/
public class SetCurrent {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws SerialPortException {
if (args.length < 3) {
throw new IllegalArgumentException("Wrong number of parameters");
}
String comName = args[0];
int lambdaaddress = Integer.valueOf(args[1]);
double current = Double.valueOf(args[2]);
PortHandler handler = new ComPortHandler(comName);
MagnetController controller = new MagnetController(handler, lambdaaddress);
controller.startUpdateTask(current, 500);
}
}

View File

@ -13,168 +13,168 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package inr.numass.control.magnet;
import hep.dataforge.meta.Meta;
import hep.dataforge.control.ports.VirtualPort;
import hep.dataforge.exceptions.PortException;
import java.time.Duration;
import java.util.HashMap;
import java.util.Map;
import org.slf4j.LoggerFactory;
/**
*
* @author Alexander Nozik
*/
public class VirtualLambdaPort extends VirtualPort {
private static final Duration latency = Duration.ofMillis(50);
private volatile int currentAddress = -1;
private Map<Integer, VirtualMagnetStatus> magnets = new HashMap<>();
public VirtualLambdaPort(String portName, Map<Integer, Double> magnets) {
super(portName);
magnets.entrySet().stream().forEach((entry) -> {
this.magnets.put(entry.getKey(), new VirtualMagnetStatus(entry.getValue()));
});
}
public VirtualLambdaPort(String portName, int... magnets) {
super(portName);
for (int magnet : magnets) {
this.magnets.put(magnet, new VirtualMagnetStatus(0.01));
}
}
@Override
protected void evaluateRequest(String request) {
String comand;
String value = "";
String[] split = request.split(" ");
if (split.length == 1) {
comand = request;
} else {
comand = split[0];
value = split[1];
}
try {
evaluateRequest(comand.trim(), value.trim());
} catch (RuntimeException ex) {
recievePhrase("FAIL");//TODO какая команда правильная?
LoggerFactory.getLogger(getClass()).error("Request evaluation failure", ex);
}
}
private void sendOK() {
planResponse("OK", latency);
}
private void evaluateRequest(String comand, String value) {
switch (comand) {
case "ADR":
int address = Integer.parseInt(value);
if (magnets.containsKey(address)) {
currentAddress = address;
sendOK();
}
return;
case "ADR?":
planResponse(Integer.toString(currentAddress), latency);
return;
case "OUT":
int state = Integer.parseInt(value);
currentMagnet().out = (state == 1);
sendOK();
return;
case "OUT?":
boolean out = currentMagnet().out;
if (out) {
planResponse("ON", latency);
} else {
planResponse("OFF", latency);
}
return;
case "PC":
double current = Double.parseDouble(value);
if (current < 0.5) {
current = 0;
}
currentMagnet().current = current;
sendOK();
return;
case "PC?":
planResponse(Double.toString(currentMagnet().current), latency);
return;
case "MC?":
planResponse(Double.toString(currentMagnet().current), latency);
return;
case "PV?":
planResponse(Double.toString(currentMagnet().voltage()), latency);
return;
case "MV?":
planResponse(Double.toString(currentMagnet().voltage()), latency);
return;
default:
LoggerFactory.getLogger(getClass()).warn("Unknown comand {}", comand);
}
}
private VirtualMagnetStatus currentMagnet() {
if (currentAddress < 0) {
throw new RuntimeException();
}
return magnets.get(currentAddress);
}
@Override
public void close() throws Exception {
}
@Override
public void open() throws PortException {
}
@Override
public boolean isOpen() {
return true;
}
@Override
public Meta meta() {
return Meta.buildEmpty("virtualPort");
}
private class VirtualMagnetStatus {
public VirtualMagnetStatus(double resistance) {
this.resistance = resistance;
this.on = true;
this.out = false;
this.current = 0;
}
public VirtualMagnetStatus(double resistance, boolean on, boolean out, double current) {
this.resistance = resistance;
this.on = on;
this.out = out;
this.current = current;
}
private final double resistance;
private boolean on;
private boolean out;
private double current;
public double voltage() {
return current * resistance;
}
}
}
package inr.numass.control.magnet;
import hep.dataforge.control.ports.VirtualPort;
import hep.dataforge.exceptions.PortException;
import hep.dataforge.meta.Meta;
import java.time.Duration;
import java.util.HashMap;
import java.util.Map;
import org.slf4j.LoggerFactory;
/**
*
* @author Alexander Nozik
*/
public class VirtualLambdaPort extends VirtualPort {
private static final Duration latency = Duration.ofMillis(50);
private volatile int currentAddress = -1;
private Map<Integer, VirtualMagnetStatus> magnets = new HashMap<>();
public VirtualLambdaPort(String portName, Map<Integer, Double> magnets) {
super(portName);
magnets.entrySet().stream().forEach((entry) -> {
this.magnets.put(entry.getKey(), new VirtualMagnetStatus(entry.getValue()));
});
}
public VirtualLambdaPort(String portName, int... magnets) {
super(portName);
for (int magnet : magnets) {
this.magnets.put(magnet, new VirtualMagnetStatus(0.01));
}
}
@Override
protected void evaluateRequest(String request) {
String comand;
String value = "";
String[] split = request.split(" ");
if (split.length == 1) {
comand = request;
} else {
comand = split[0];
value = split[1];
}
try {
evaluateRequest(comand.trim(), value.trim());
} catch (RuntimeException ex) {
recievePhrase("FAIL");//TODO какая команда правильная?
LoggerFactory.getLogger(getClass()).error("Request evaluation failure", ex);
}
}
private void sendOK() {
planResponse("OK", latency);
}
private void evaluateRequest(String comand, String value) {
switch (comand) {
case "ADR":
int address = Integer.parseInt(value);
if (magnets.containsKey(address)) {
currentAddress = address;
sendOK();
}
return;
case "ADR?":
planResponse(Integer.toString(currentAddress), latency);
return;
case "OUT":
int state = Integer.parseInt(value);
currentMagnet().out = (state == 1);
sendOK();
return;
case "OUT?":
boolean out = currentMagnet().out;
if (out) {
planResponse("ON", latency);
} else {
planResponse("OFF", latency);
}
return;
case "PC":
double current = Double.parseDouble(value);
if (current < 0.5) {
current = 0;
}
currentMagnet().current = current;
sendOK();
return;
case "PC?":
planResponse(Double.toString(currentMagnet().current), latency);
return;
case "MC?":
planResponse(Double.toString(currentMagnet().current), latency);
return;
case "PV?":
planResponse(Double.toString(currentMagnet().voltage()), latency);
return;
case "MV?":
planResponse(Double.toString(currentMagnet().voltage()), latency);
return;
default:
LoggerFactory.getLogger(getClass()).warn("Unknown comand {}", comand);
}
}
private VirtualMagnetStatus currentMagnet() {
if (currentAddress < 0) {
throw new RuntimeException();
}
return magnets.get(currentAddress);
}
@Override
public void close() throws Exception {
}
@Override
public void open() throws PortException {
}
@Override
public boolean isOpen() {
return true;
}
@Override
public Meta meta() {
return Meta.buildEmpty("virtualPort");
}
private class VirtualMagnetStatus {
public VirtualMagnetStatus(double resistance) {
this.resistance = resistance;
this.on = true;
this.out = false;
this.current = 0;
}
public VirtualMagnetStatus(double resistance, boolean on, boolean out, double current) {
this.resistance = resistance;
this.on = on;
this.out = out;
this.current = current;
}
private final double resistance;
private boolean on;
private boolean out;
private double current;
public double voltage() {
return current * resistance;
}
}
}

View File

@ -32,7 +32,6 @@ import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import org.slf4j.ILoggerFactory;
import org.slf4j.LoggerFactory;
/**

View File

@ -15,7 +15,6 @@
*/
package inr.numass.control.msp;
import hep.dataforge.context.Context;
import hep.dataforge.control.connections.Roles;
import hep.dataforge.control.connections.StorageConnection;
import hep.dataforge.control.devices.SingleMeasurementDevice;

View File

@ -1,6 +1,6 @@
apply plugin: 'application'
version = "0.3.1"
version = "0.4.0-SNAPSHOT"
if (!hasProperty('mainClass')) {
ext.mainClass = 'inr.numass.readvac.Main'

View File

@ -15,11 +15,11 @@
*/
package inr.numass.readvac;
import hep.dataforge.meta.Meta;
import hep.dataforge.context.Context;
import hep.dataforge.context.GlobalContext;
import static hep.dataforge.context.GlobalContext.out;
import hep.dataforge.io.MetaFileReader;
import hep.dataforge.meta.Meta;
import hep.dataforge.storage.api.Storage;
import hep.dataforge.storage.commons.StorageManager;
import java.io.File;

View File

@ -15,9 +15,9 @@
*/
package inr.numass.readvac;
import hep.dataforge.meta.Meta;
import hep.dataforge.data.DataPoint;
import hep.dataforge.data.MapDataPoint;
import hep.dataforge.meta.Meta;
import hep.dataforge.values.Value;
import java.math.BigDecimal;
import java.math.RoundingMode;

View File

@ -16,9 +16,9 @@
package inr.numass.readvac;
import hep.dataforge.data.DataFormatBuilder;
import hep.dataforge.meta.Meta;
import hep.dataforge.data.DataPoint;
import hep.dataforge.exceptions.StorageException;
import hep.dataforge.meta.Meta;
import hep.dataforge.storage.api.PointLoader;
import hep.dataforge.storage.api.Storage;
import hep.dataforge.storage.commons.LoaderFactory;

View File

@ -5,15 +5,13 @@
*/
package inr.numass.readvac.devices;
import hep.dataforge.context.Context;
import hep.dataforge.control.measurements.SimpleMeasurement;
import hep.dataforge.control.measurements.Measurement;
import hep.dataforge.control.measurements.Sensor;
import hep.dataforge.control.measurements.SimpleMeasurement;
import hep.dataforge.control.ports.ComPortHandler;
import hep.dataforge.control.ports.PortHandler;
import hep.dataforge.description.ValueDef;
import hep.dataforge.exceptions.ControlException;
import hep.dataforge.meta.Meta;
/**
*

View File

@ -5,15 +5,13 @@
*/
package inr.numass.readvac.devices;
import hep.dataforge.context.Context;
import hep.dataforge.control.measurements.SimpleMeasurement;
import hep.dataforge.control.measurements.Measurement;
import hep.dataforge.control.measurements.Sensor;
import hep.dataforge.control.measurements.SimpleMeasurement;
import hep.dataforge.control.ports.ComPortHandler;
import hep.dataforge.control.ports.PortHandler;
import hep.dataforge.description.ValueDef;
import hep.dataforge.exceptions.ControlException;
import hep.dataforge.meta.Meta;
import hep.dataforge.values.Value;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

View File

@ -5,15 +5,13 @@
*/
package inr.numass.readvac.devices;
import hep.dataforge.context.Context;
import hep.dataforge.control.measurements.SimpleMeasurement;
import hep.dataforge.control.measurements.Measurement;
import hep.dataforge.control.measurements.Sensor;
import hep.dataforge.control.measurements.SimpleMeasurement;
import hep.dataforge.control.ports.ComPortHandler;
import hep.dataforge.control.ports.PortHandler;
import hep.dataforge.description.ValueDef;
import hep.dataforge.exceptions.ControlException;
import hep.dataforge.meta.Meta;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.regex.Matcher;

View File

@ -5,7 +5,6 @@
*/
package inr.numass.readvac.test;
import hep.dataforge.context.GlobalContext;
import hep.dataforge.control.measurements.Sensor;
import hep.dataforge.control.virtual.SensorFactory;
import hep.dataforge.control.virtual.Virtual;
@ -13,13 +12,10 @@ import hep.dataforge.meta.MetaBuilder;
import inr.numass.readvac.devices.VacCollectorDevice;
import inr.numass.readvac.fx.VacCollectorController;
import java.time.Duration;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;
import org.slf4j.LoggerFactory;
/**
*

View File

@ -11,7 +11,6 @@ import hep.dataforge.data.DataPoint;
import hep.dataforge.data.DataSet;
import hep.dataforge.data.ListDataSet;
import hep.dataforge.data.MapDataPoint;
import hep.dataforge.description.TypedActionDef;
import hep.dataforge.io.log.Logable;
import hep.dataforge.meta.Meta;

View File

@ -16,12 +16,12 @@
package inr.numass.actions;
import hep.dataforge.actions.OneToOneAction;
import hep.dataforge.meta.Meta;
import hep.dataforge.description.ValueDef;
import hep.dataforge.description.TypedActionDef;
import hep.dataforge.context.Context;
import hep.dataforge.description.TypedActionDef;
import hep.dataforge.description.ValueDef;
import hep.dataforge.exceptions.ContentException;
import hep.dataforge.io.log.Logable;
import hep.dataforge.meta.Meta;
import inr.numass.data.RawNMFile;
import inr.numass.data.RawNMPoint;
import inr.numass.debunch.DebunchReport;

View File

@ -16,12 +16,12 @@
package inr.numass.actions;
import hep.dataforge.actions.OneToOneAction;
import hep.dataforge.meta.Meta;
import hep.dataforge.description.TypedActionDef;
import hep.dataforge.context.Context;
import hep.dataforge.description.TypedActionDef;
import hep.dataforge.exceptions.ContentException;
import hep.dataforge.io.ColumnedDataWriter;
import hep.dataforge.io.log.Logable;
import hep.dataforge.meta.Meta;
import inr.numass.data.NMFile;
import inr.numass.data.NMPoint;
import java.io.OutputStream;

View File

@ -16,18 +16,18 @@
package inr.numass.actions;
import hep.dataforge.actions.ManyToOneAction;
import hep.dataforge.meta.Meta;
import hep.dataforge.content.NamedGroup;
import hep.dataforge.content.GroupBuilder;
import hep.dataforge.description.NodeDef;
import hep.dataforge.description.TypedActionDef;
import hep.dataforge.content.NamedGroup;
import hep.dataforge.context.Context;
import hep.dataforge.data.DataPoint;
import hep.dataforge.data.DataSet;
import hep.dataforge.data.ListDataSet;
import hep.dataforge.data.MapDataPoint;
import hep.dataforge.description.NodeDef;
import hep.dataforge.description.TypedActionDef;
import hep.dataforge.io.ColumnedDataWriter;
import hep.dataforge.io.log.Logable;
import hep.dataforge.meta.Meta;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.LinkedHashMap;

View File

@ -17,17 +17,17 @@ package inr.numass.actions;
import hep.dataforge.actions.ActionResult;
import hep.dataforge.actions.OneToOneAction;
import hep.dataforge.meta.Meta;
import hep.dataforge.context.Context;
import hep.dataforge.data.DataPoint;
import hep.dataforge.data.DataSet;
import hep.dataforge.data.ListDataSet;
import hep.dataforge.data.MapDataPoint;
import hep.dataforge.description.ValueDef;
import hep.dataforge.description.TypedActionDef;
import hep.dataforge.description.ValueDef;
import hep.dataforge.exceptions.ContentException;
import hep.dataforge.io.ColumnedDataWriter;
import hep.dataforge.io.log.Logable;
import hep.dataforge.meta.Meta;
import hep.dataforge.values.Value;
import java.io.OutputStream;
import java.time.LocalDateTime;

View File

@ -16,19 +16,19 @@
package inr.numass.actions;
import hep.dataforge.actions.OneToOneAction;
import hep.dataforge.meta.Meta;
import hep.dataforge.description.ValueDef;
import hep.dataforge.description.TypedActionDef;
import hep.dataforge.context.Context;
import hep.dataforge.data.DataFormat;
import hep.dataforge.data.DataPoint;
import hep.dataforge.data.DataSet;
import hep.dataforge.data.ListDataSet;
import hep.dataforge.data.MapDataPoint;
import hep.dataforge.description.TypedActionDef;
import hep.dataforge.description.ValueDef;
import hep.dataforge.exceptions.ContentException;
import hep.dataforge.io.ColumnedDataWriter;
import hep.dataforge.io.XMLMetaWriter;
import hep.dataforge.io.log.Logable;
import hep.dataforge.meta.Meta;
import inr.numass.data.NMFile;
import inr.numass.data.NMPoint;
import inr.numass.data.RawNMPoint;

View File

@ -16,14 +16,14 @@
package inr.numass.actions;
import hep.dataforge.actions.OneToOneAction;
import hep.dataforge.meta.Meta;
import hep.dataforge.description.NodeDef;
import hep.dataforge.description.ValueDef;
import hep.dataforge.description.TypedActionDef;
import hep.dataforge.context.Context;
import hep.dataforge.data.FileData;
import hep.dataforge.description.NodeDef;
import hep.dataforge.description.TypedActionDef;
import hep.dataforge.description.ValueDef;
import hep.dataforge.exceptions.ContentException;
import hep.dataforge.io.log.Logable;
import hep.dataforge.meta.Meta;
import static inr.numass.NumassIO.getNumassData;
import inr.numass.data.NMFile;
import inr.numass.data.RawNMFile;

View File

@ -19,10 +19,10 @@ import hep.dataforge.actions.OneToOneAction;
import hep.dataforge.context.Context;
import hep.dataforge.description.TypedActionDef;
import hep.dataforge.exceptions.ContentException;
import hep.dataforge.plots.fx.FXPlotUtils;
import hep.dataforge.io.ColumnedDataWriter;
import hep.dataforge.io.log.Logable;
import hep.dataforge.meta.Meta;
import hep.dataforge.plots.fx.FXPlotUtils;
import hep.dataforge.plots.jfreechart.JFreeChartFrame;
import inr.numass.data.ESpectrum;
import inr.numass.data.NMFile;

View File

@ -16,20 +16,20 @@
package inr.numass.actions;
import hep.dataforge.actions.ManyToOneAction;
import hep.dataforge.meta.Meta;
import hep.dataforge.content.NamedGroup;
import hep.dataforge.content.GroupBuilder;
import hep.dataforge.description.TypedActionDef;
import hep.dataforge.content.NamedGroup;
import hep.dataforge.context.Context;
import hep.dataforge.data.DataFormat;
import hep.dataforge.data.DataPoint;
import hep.dataforge.data.DataSet;
import hep.dataforge.data.ListDataSet;
import hep.dataforge.data.MapDataPoint;
import hep.dataforge.values.Value;
import hep.dataforge.datafitter.FitState;
import hep.dataforge.description.TypedActionDef;
import hep.dataforge.io.ColumnedDataWriter;
import hep.dataforge.io.log.Logable;
import hep.dataforge.meta.Meta;
import hep.dataforge.values.Value;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.List;

View File

@ -18,11 +18,11 @@ package inr.numass.data;
import hep.dataforge.data.DataFormat;
import hep.dataforge.data.ListDataSet;
import hep.dataforge.data.MapDataPoint;
import hep.dataforge.io.ColumnedDataWriter;
import hep.dataforge.values.Value;
import hep.dataforge.values.ValueFormat;
import hep.dataforge.values.ValueFormatFactory;
import hep.dataforge.values.ValueType;
import hep.dataforge.io.ColumnedDataWriter;
import java.io.OutputStream;
import static java.lang.String.format;
import java.util.ArrayList;
@ -30,9 +30,6 @@ import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import static java.lang.String.format;
import static java.lang.String.format;
import static java.lang.String.format;
/**
*

View File

@ -20,10 +20,10 @@ import hep.dataforge.data.MapDataPoint;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import static java.util.Arrays.sort;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import static java.util.Arrays.sort;
/**
*

View File

@ -16,12 +16,12 @@
package inr.numass.data;
import hep.dataforge.data.DataAdapter;
import hep.dataforge.meta.Meta;
import hep.dataforge.data.DataPoint;
import hep.dataforge.data.MapDataPoint;
import hep.dataforge.data.XYDataAdapter;
import hep.dataforge.exceptions.DataFormatException;
import hep.dataforge.exceptions.NameNotFoundException;
import hep.dataforge.meta.Meta;
import hep.dataforge.meta.MetaBuilder;
import hep.dataforge.values.Value;

View File

@ -27,7 +27,6 @@ import java.util.Iterator;
import org.apache.commons.math3.random.JDKRandomGenerator;
import org.apache.commons.math3.random.RandomDataGenerator;
import org.apache.commons.math3.random.RandomGenerator;
import static java.lang.Double.isNaN;
/**
* Генератор наборов данных для спектров. На входе требуется набор данных,

View File

@ -21,9 +21,6 @@ import static java.lang.Math.max;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import static java.lang.Math.max;
import static java.lang.Math.max;
import static java.lang.Math.max;
/**
*

View File

@ -15,12 +15,10 @@
*/
package inr.numass.models;
import hep.dataforge.context.GlobalContext;
import hep.dataforge.functions.AbstractParametricFunction;
import static hep.dataforge.functions.FunctionUtils.getSpectrumDerivativeFunction;
import static hep.dataforge.functions.FunctionUtils.getSpectrumFunction;
import hep.dataforge.functions.ParametricFunction;
import hep.dataforge.io.log.Logable;
import hep.dataforge.maths.NamedDoubleArray;
import hep.dataforge.maths.NamedDoubleSet;
import hep.dataforge.names.AbstractNamedSet;

View File

@ -13,173 +13,172 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package inr.numass.models;
import hep.dataforge.actions.ActionResult;
import hep.dataforge.actions.RunManager;
import hep.dataforge.meta.Meta;
import hep.dataforge.context.Context;
import hep.dataforge.context.Context;
import hep.dataforge.data.DataPoint;
import hep.dataforge.data.DataSet;
import hep.dataforge.io.ColumnedDataReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.math3.analysis.UnivariateFunction;
import org.apache.commons.math3.analysis.interpolation.LinearInterpolator;
/**
*
* @author darksnake
*/
public class TransmissionInterpolator implements UnivariateFunction {
public static TransmissionInterpolator fromFile(Context context, String path, String xName, String yName, int nSmooth, double w, double border) {
try {
File dataFile = context.io().getFile(path);
ColumnedDataReader reader = new ColumnedDataReader(dataFile);
return new TransmissionInterpolator(reader, xName, yName, nSmooth, w, border);
} catch (FileNotFoundException ex) {
throw new RuntimeException(ex);
}
}
@SuppressWarnings("unchecked")
public static TransmissionInterpolator fromAction(Context context, Meta actionAnnotation, String xName, String yName, int nSmooth, double w, double border) throws InterruptedException {
ActionResult<DataSet> pack = RunManager.executeAction(context, actionAnnotation);
DataSet data = pack.iterator().next().get();
return new TransmissionInterpolator(data, xName, yName, nSmooth, w, border);
}
UnivariateFunction func;
double[] x;
double[] y;
private double xmax;
private double xmin;
private TransmissionInterpolator(Iterable<DataPoint> data, String xName, String yName, int nSmooth, double w, double border) {
prepareXY(data, xName, yName);
double[] smoothed = smoothXY(x, y, w, border);
//Циклы сглаживания
for (int i = 1; i < nSmooth; i++) {
smoothed = smoothXY(x, smoothed, w, border);
}
this.func = new LinearInterpolator().interpolate(x, smoothed);
}
public double[] getX() {
return x;
}
/**
* @return the xmax
*/
public double getXmax() {
return xmax;
}
/**
* @return the xmin
*/
public double getXmin() {
return xmin;
}
public double[] getY() {
return y;
}
/**
* Prepare and normalize data for interpolation
*
* @param data
* @param xName
* @param yName
*/
private void prepareXY(Iterable<DataPoint> data, String xName, String yName) {
List<DataPoint> points = new ArrayList<>();
for (DataPoint dp : data) {
points.add(dp);
}
x = new double[points.size()];
y = new double[points.size()];
xmin = Double.POSITIVE_INFINITY;
xmax = Double.NEGATIVE_INFINITY;
double ymin = Double.POSITIVE_INFINITY;
double ymax = Double.NEGATIVE_INFINITY;
for (int i = 0; i < points.size(); i++) {
x[i] = points.get(i).getDouble(xName);
y[i] = points.get(i).getDouble(yName);
if (x[i] < xmin) {
xmin = x[i];
}
if (x[i] > xmax) {
xmax = x[i];
}
if (y[i] < ymin) {
ymin = y[i];
}
if (y[i] > ymax) {
ymax = y[i];
}
}
// ymax = y[0]-ymin;
for (int i = 0; i < y.length; i++) {
y[i] = (y[i] - ymin) / (ymax - ymin);
}
}
private static double[] smoothXY(double x[], double[] y, double w, double border) {
int max = y.length - 1;
double[] yUp = new double[y.length];
double[] yDown = new double[y.length];
/* экспоненциальное скользящее среднее
/https://ru.wikipedia.org/wiki/%D0%A1%D0%BA%D0%BE%D0%BB%D1%8C%D0%B7%D1%8F%D1%89%D0%B0%D1%8F_%D1%81%D1%80%D0%B5%D0%B4%D0%BD%D1%8F%D1%8F
/ \textit{EMA}_t = \alpha \cdot p_t + (1-\alpha) \cdot \textit{EMA}_{t-1},
*/
yUp[0] = y[0];
for (int i = 1; i < y.length; i++) {
if (x[i] < border) {
yUp[i] = w * y[i] + (1 - w) * yUp[i - 1];
} else {
yUp[i] = y[i];
}
}
yDown[max] = y[max];
for (int i = max - 1; i >= 0; i--) {
if (x[i] < border) {
yDown[i] = w * y[i] + (1 - w) * yUp[i + 1];
} else {
yDown[i] = y[i];
}
}
double[] res = new double[y.length];
for (int i = 0; i < x.length; i++) {
res[i] = (yUp[i] + yDown[i]) / 2;
}
return res;
}
@Override
public double value(double x) {
if (x <= getXmin()) {
return 1d;
}
if (x >= getXmax()) {
return 0;
}
return func.value(x);
}
}
package inr.numass.models;
import hep.dataforge.actions.ActionResult;
import hep.dataforge.actions.RunManager;
import hep.dataforge.context.Context;
import hep.dataforge.data.DataPoint;
import hep.dataforge.data.DataSet;
import hep.dataforge.io.ColumnedDataReader;
import hep.dataforge.meta.Meta;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.math3.analysis.UnivariateFunction;
import org.apache.commons.math3.analysis.interpolation.LinearInterpolator;
/**
*
* @author darksnake
*/
public class TransmissionInterpolator implements UnivariateFunction {
public static TransmissionInterpolator fromFile(Context context, String path, String xName, String yName, int nSmooth, double w, double border) {
try {
File dataFile = context.io().getFile(path);
ColumnedDataReader reader = new ColumnedDataReader(dataFile);
return new TransmissionInterpolator(reader, xName, yName, nSmooth, w, border);
} catch (FileNotFoundException ex) {
throw new RuntimeException(ex);
}
}
@SuppressWarnings("unchecked")
public static TransmissionInterpolator fromAction(Context context, Meta actionAnnotation, String xName, String yName, int nSmooth, double w, double border) throws InterruptedException {
ActionResult<DataSet> pack = RunManager.executeAction(context, actionAnnotation);
DataSet data = pack.iterator().next().get();
return new TransmissionInterpolator(data, xName, yName, nSmooth, w, border);
}
UnivariateFunction func;
double[] x;
double[] y;
private double xmax;
private double xmin;
private TransmissionInterpolator(Iterable<DataPoint> data, String xName, String yName, int nSmooth, double w, double border) {
prepareXY(data, xName, yName);
double[] smoothed = smoothXY(x, y, w, border);
//Циклы сглаживания
for (int i = 1; i < nSmooth; i++) {
smoothed = smoothXY(x, smoothed, w, border);
}
this.func = new LinearInterpolator().interpolate(x, smoothed);
}
public double[] getX() {
return x;
}
/**
* @return the xmax
*/
public double getXmax() {
return xmax;
}
/**
* @return the xmin
*/
public double getXmin() {
return xmin;
}
public double[] getY() {
return y;
}
/**
* Prepare and normalize data for interpolation
*
* @param data
* @param xName
* @param yName
*/
private void prepareXY(Iterable<DataPoint> data, String xName, String yName) {
List<DataPoint> points = new ArrayList<>();
for (DataPoint dp : data) {
points.add(dp);
}
x = new double[points.size()];
y = new double[points.size()];
xmin = Double.POSITIVE_INFINITY;
xmax = Double.NEGATIVE_INFINITY;
double ymin = Double.POSITIVE_INFINITY;
double ymax = Double.NEGATIVE_INFINITY;
for (int i = 0; i < points.size(); i++) {
x[i] = points.get(i).getDouble(xName);
y[i] = points.get(i).getDouble(yName);
if (x[i] < xmin) {
xmin = x[i];
}
if (x[i] > xmax) {
xmax = x[i];
}
if (y[i] < ymin) {
ymin = y[i];
}
if (y[i] > ymax) {
ymax = y[i];
}
}
// ymax = y[0]-ymin;
for (int i = 0; i < y.length; i++) {
y[i] = (y[i] - ymin) / (ymax - ymin);
}
}
private static double[] smoothXY(double x[], double[] y, double w, double border) {
int max = y.length - 1;
double[] yUp = new double[y.length];
double[] yDown = new double[y.length];
/* экспоненциальное скользящее среднее
/https://ru.wikipedia.org/wiki/%D0%A1%D0%BA%D0%BE%D0%BB%D1%8C%D0%B7%D1%8F%D1%89%D0%B0%D1%8F_%D1%81%D1%80%D0%B5%D0%B4%D0%BD%D1%8F%D1%8F
/ \textit{EMA}_t = \alpha \cdot p_t + (1-\alpha) \cdot \textit{EMA}_{t-1},
*/
yUp[0] = y[0];
for (int i = 1; i < y.length; i++) {
if (x[i] < border) {
yUp[i] = w * y[i] + (1 - w) * yUp[i - 1];
} else {
yUp[i] = y[i];
}
}
yDown[max] = y[max];
for (int i = max - 1; i >= 0; i--) {
if (x[i] < border) {
yDown[i] = w * y[i] + (1 - w) * yUp[i + 1];
} else {
yDown[i] = y[i];
}
}
double[] res = new double[y.length];
for (int i = 0; i < x.length; i++) {
res[i] = (yUp[i] + yDown[i]) / 2;
}
return res;
}
@Override
public double value(double x) {
if (x <= getXmin()) {
return 1d;
}
if (x >= getXmax()) {
return 0;
}
return func.value(x);
}
}

View File

@ -15,15 +15,10 @@
*/
package inr.numass.models;
import hep.dataforge.context.GlobalContext;
import hep.dataforge.functions.ParametricFunction;
import hep.dataforge.io.log.Logable;
import hep.dataforge.maths.NamedDoubleArray;
import hep.dataforge.maths.NamedDoubleSet;
import static java.lang.Math.abs;
import static java.lang.Math.abs;
import static java.lang.Math.abs;
import static java.lang.Math.abs;
import org.slf4j.LoggerFactory;
/**

View File

@ -23,8 +23,8 @@ import inr.numass.data.SpectrumDataAdapter;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Locale;
import java.util.Scanner;
import static java.util.Locale.setDefault;
import java.util.Scanner;
/**
*

View File

@ -18,13 +18,10 @@ package inr.numass.utils;
import hep.dataforge.data.DataPoint;
import hep.dataforge.data.ListDataSet;
import inr.numass.data.SpectrumDataAdapter;
import static java.lang.Math.abs;
import static java.lang.Math.exp;
import static java.lang.Math.sqrt;
import org.apache.commons.math3.analysis.UnivariateFunction;
import static java.lang.Math.abs;
import static java.lang.Math.abs;
import static java.lang.Math.abs;
import static java.lang.Math.abs;
/**
*

View File

@ -5,8 +5,8 @@
*/
package inr.numass.workbench;
import hep.dataforge.plots.fx.PlotContainer;
import hep.dataforge.meta.Meta;
import hep.dataforge.plots.fx.PlotContainer;
import hep.dataforge.plots.jfreechart.JFreeChartFrame;
public class PlotOutputTab extends OutputTab {

View File

@ -24,69 +24,6 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.util.Locale;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
/**
*

View File

@ -25,7 +25,6 @@ import hep.dataforge.datafitter.ParamSet;
import hep.dataforge.datafitter.models.HistogramGenerator;
import hep.dataforge.datafitter.models.HistogramModel;
import hep.dataforge.functions.ParametricFunction;
import hep.dataforge.io.log.Log;
import hep.dataforge.maths.MatrixOperations;
import hep.dataforge.maths.RandomUtils;
import inr.numass.models.BetaSpectrum;

View File

@ -16,7 +16,6 @@
package inr.numass.prop.ar;
import hep.dataforge.actions.OneToOneAction;
import hep.dataforge.meta.Meta;
import hep.dataforge.context.Context;
import hep.dataforge.data.DataPoint;
import hep.dataforge.data.DataSet;
@ -28,12 +27,12 @@ import hep.dataforge.datafitter.FitState;
import hep.dataforge.datafitter.ParamSet;
import hep.dataforge.datafitter.models.Model;
import hep.dataforge.datafitter.models.XYModel;
import hep.dataforge.description.ValueDef;
import hep.dataforge.description.TypedActionDef;
import hep.dataforge.description.ValueDef;
import hep.dataforge.io.ColumnedDataWriter;
import hep.dataforge.io.log.Log;
import hep.dataforge.io.log.Logable;
import hep.dataforge.values.ValueType;
import hep.dataforge.meta.Meta;
import inr.numass.prop.PoissonAdapter;
import inr.numass.prop.SplitNormalSpectrum;
import java.io.OutputStream;

View File

@ -15,8 +15,8 @@
*/
package inr.numass.prop.ar;
import hep.dataforge.meta.Meta;
import hep.dataforge.content.NamedMetaHolder;
import hep.dataforge.meta.Meta;
import java.util.Iterator;
import java.util.List;

View File

@ -15,15 +15,15 @@
*/
package inr.numass.prop.ar;
import hep.dataforge.meta.Meta;
import hep.dataforge.meta.MetaBuilder;
import hep.dataforge.content.NamedMetaHolder;
import hep.dataforge.description.NodeDef;
import hep.dataforge.description.ValueDef;
import hep.dataforge.data.DataPoint;
import hep.dataforge.data.DataSet;
import hep.dataforge.data.ListDataSet;
import hep.dataforge.data.MapDataPoint;
import hep.dataforge.description.NodeDef;
import hep.dataforge.description.ValueDef;
import hep.dataforge.meta.Meta;
import hep.dataforge.meta.MetaBuilder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;

View File

@ -16,11 +16,11 @@
package inr.numass.prop.ar;
import hep.dataforge.actions.OneToOneAction;
import hep.dataforge.meta.Meta;
import hep.dataforge.context.Context;
import hep.dataforge.description.ValueDef;
import hep.dataforge.description.TypedActionDef;
import hep.dataforge.description.ValueDef;
import hep.dataforge.io.log.Logable;
import hep.dataforge.meta.Meta;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

View File

@ -16,19 +16,18 @@
package inr.numass.prop.ar;
import hep.dataforge.actions.OneToOneAction;
import hep.dataforge.meta.Meta;
import hep.dataforge.meta.MetaBuilder;
import hep.dataforge.context.Context;
import hep.dataforge.data.DataPoint;
import hep.dataforge.data.DataSet;
import hep.dataforge.data.FileData;
import hep.dataforge.description.ValueDef;
import hep.dataforge.description.TypedActionDef;
import hep.dataforge.description.ValueDef;
import hep.dataforge.exceptions.ContentException;
import hep.dataforge.io.ColumnedDataReader;
import hep.dataforge.io.IOUtils;
import hep.dataforge.io.log.Logable;
import hep.dataforge.values.ValueType;
import hep.dataforge.meta.Meta;
import hep.dataforge.meta.MetaBuilder;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;

View File

@ -15,12 +15,12 @@
*/
package inr.numass.prop;
import hep.dataforge.meta.MetaBuilder;
import hep.dataforge.context.GlobalContext;
import hep.dataforge.data.DataSet;
import hep.dataforge.data.FileData;
import hep.dataforge.datafitter.MINUITPlugin;
import hep.dataforge.io.ColumnedDataWriter;
import hep.dataforge.meta.MetaBuilder;
import inr.numass.prop.ar.FitJNAData;
import inr.numass.prop.ar.JNAEpisode;
import inr.numass.prop.ar.ReadJNADataAction;

View File

@ -15,17 +15,17 @@
*/
package inr.numass.prop;
import hep.dataforge.meta.Meta;
import hep.dataforge.meta.MetaBuilder;
import hep.dataforge.context.GlobalContext;
import hep.dataforge.data.FileData;
import hep.dataforge.data.XYDataAdapter;
import hep.dataforge.meta.Meta;
import hep.dataforge.meta.MetaBuilder;
import hep.dataforge.plots.PlotFrame;
import hep.dataforge.plots.data.PlottableData;
import hep.dataforge.plots.fx.FXPlotUtils;
import inr.numass.prop.ar.JNAEpisode;
import inr.numass.prop.ar.JNASpectrum;
import inr.numass.prop.ar.ReadJNADataAction;
import hep.dataforge.plots.PlotFrame;
import hep.dataforge.plots.data.PlottableData;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Map;

View File

@ -5,10 +5,7 @@
*/
package inr.numass.server;
import hep.dataforge.exceptions.StorageException;
import hep.dataforge.storage.api.Loader;
import hep.dataforge.storage.api.StateLoader;
import hep.dataforge.storage.api.Storage;
import hep.dataforge.values.Value;
/**