-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeviceCalibrationCurveConverter17092018_MS.java
More file actions
136 lines (99 loc) · 5.17 KB
/
Copy pathDeviceCalibrationCurveConverter17092018_MS.java
File metadata and controls
136 lines (99 loc) · 5.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package de.gsi.cs.co.ap.my_test_project.utils;
import cern.accsoft.commons.value.BoundedPolynomial;
import cern.accsoft.commons.value.BoundedPolynomialSequence;
import cern.accsoft.commons.value.Interval;
// import cern.accsoft.commons.value.Polynomial;
// import cern.accsoft.commons.value.operation.BoundedPolynomialOperations;
// import cern.accsoft.commons.value.operation.BoundedPolynomialSequenceOperations;
// import cern.accsoft.commons.value.operation.PolynomialOperations;
import cern.lsa.client.OpticService;
import cern.lsa.client.Services;
// import cern.lsa.domain.commons.BoundedFunction;
// import cern.lsa.domain.commons.CalibrationFunction;
import cern.lsa.domain.commons.spi.CalibrationFunctionWrapper;
// import cern.lsa.domain.devices.Device;
import cern.lsa.domain.optics.Calibration;
import cern.lsa.domain.optics.CalibrationFunctionTypes;
// for library loggers
// import org.slf4j.Logger;
// import org.slf4j.LoggerFactory;
// for application loggers
// import de.gsi.cs.co.ap.common.gui.elements.logger.AppLogger;
/**
* @author fschirru
*/
public class DeviceCalibrationCurveConverter {
// You can choose a logger (needed imports are given in the import section as comments):
// for libraries:
// private static final Logger LOGGER = LoggerFactory.getLogger(DeviceCalibrationCurveConverter.class);
// for applications:
// private static final AppLogger LOGGER = AppLogger.getLogger();
public DeviceCalibrationCurveConverter() {
}
private static final RegulaFalsiMethod rfm = RegulaFalsiMethod.getInstance();
private static final DeviceCalibrationCurveConverter INSTANCE = new DeviceCalibrationCurveConverter();
public static DeviceCalibrationCurveConverter getInstance() {
return INSTANCE;
}
public double getValueFromCalibrationCurve(final String logicalDeviceName, final double y, final String calType) {
double invertedValue = 0.0;
try {
final OpticService opticService = Services.getOpticService();
final Calibration calibration = opticService.findCalibrationByLogicalHardware(logicalDeviceName);
// Case of conversion current to bfield
if (calType.equals("current")) {
final CalibrationFunctionWrapper currentAsFunctionOfIntegralField = (CalibrationFunctionWrapper) calibration
.getCalibrationFunction(CalibrationFunctionTypes.MAG_INTFIELD2CURRENT);
final BoundedPolynomialSequence boundedPolynomialSequence = (BoundedPolynomialSequence) currentAsFunctionOfIntegralField
.getInterpolable();
final BoundedPolynomial polynomial = findBoundedPolynomial(boundedPolynomialSequence, y);
if (polynomial != null) {
invertedValue = rfm.findRoot(polynomial.getInterval().getLowerBound(),
polynomial.getInterval().getUpperBound(), 5E-8, 1000, polynomial, y);
} else {
invertedValue = 0.0;
}
}
// Case of conversion voltage to bfield
if (calType.equals("voltage")) {
/*
*
* final CalibrationFunctionWrapper voltageAsFunctionOfIntegralField = (CalibrationFunctionWrapper)
* calibration
* .getCalibrationFunction(CalibrationFunctionTypes.MAG_INTFIELD2VOLTAGE);
*
* // System.out.println(voltageAsFunctionOfIntegralField.getInterpolable());
* // System.exit(0);
*
* final BoundedPolynomialSequence boundedPolynomialSequence = (BoundedPolynomialSequence)
* voltageAsFunctionOfIntegralField
* .getInterpolable();
*
* final BoundedPolynomial polynomial = findBoundedPolynomial(boundedPolynomialSequence, y);
* invertedValue = PolynomialOperations.invert(polynomial, y);
*
* // System.out.println("Inverted Value " + invertedValue);
*/
}
} catch (final Exception e) {
System.out.println(e);
invertedValue = -0.5;
// System.exit(0);
}
return invertedValue;
}
private static BoundedPolynomial findBoundedPolynomial(final BoundedPolynomialSequence boundedPolynomialSequence,
final double y) {
final BoundedPolynomial[] boundedPolynomials = boundedPolynomialSequence.getBoundedPolynomials();
for (final BoundedPolynomial boundedPolynomial : boundedPolynomials) {
final double lowerBound = boundedPolynomial.getInterval().getLowerBound();
final double upperBound = boundedPolynomial.getInterval().getUpperBound();
final Interval interval = Interval.of(boundedPolynomial.interpolate(lowerBound),
boundedPolynomial.interpolate(upperBound));
if (interval.contains(y)) {
return boundedPolynomial;
}
}
return null;
}
}