use of org.diirt.vtype.VNumberArray in project yamcs-studio by yamcs.
the class AbstractVNumberVNumberArrayToVNumberArrayFormulaFunction method calculate.
@Override
public final Object calculate(List<Object> args) {
if (NullUtils.containsNull(args)) {
return null;
}
VNumber arg1 = (VNumber) args.get(0);
VNumberArray arg2 = (VNumberArray) args.get(1);
return newVNumberArray(calculate(arg1.getValue().doubleValue(), arg2.getData()), highestSeverityOf(args, false), latestValidTimeOrNowOf(args), displayNone());
}
use of org.diirt.vtype.VNumberArray in project yamcs-studio by yamcs.
the class ArrayRangeOfFormulaFunction method calculate.
@Override
public Object calculate(List<Object> args) {
if (NullUtils.containsNull(args)) {
return null;
}
VNumberArray numberArray = (VNumberArray) args.get(0);
double min = numberArray.getDimensionDisplay().get(0).getCellBoundaries().getDouble(0);
double max = numberArray.getDimensionDisplay().get(0).getCellBoundaries().getDouble(numberArray.getSizes().getInt(0));
return newVNumberArray(new ArrayDouble(min, max), highestSeverityOf(args, false), latestValidTimeOrNowOf(args), displayNone());
}
use of org.diirt.vtype.VNumberArray in project yamcs-studio by yamcs.
the class DftFormulaFunction method calculate.
@Override
public Object calculate(final List<Object> args) {
VNumberArray array = (VNumberArray) args.get(0);
if (array == null) {
return null;
}
if (array.getSizes().size() != 1) {
throw new IllegalArgumentException("Only 1D array supported for DFT");
}
// TODO: no need to allocate empty array
List<ListNumber> fft = ListMath.dft(array.getData(), new ArrayDouble(new double[array.getData().size()]));
final ListNumber real = fft.get(0);
final ListNumber imaginary = fft.get(1);
ListNumber modulus = new ListDouble() {
@Override
public double getDouble(int index) {
double x = real.getDouble(index);
double y = imaginary.getDouble(index);
if (x != 0 || y != 0) {
return Math.sqrt(x * x + y * y);
} else {
return 0.0;
}
}
@Override
public int size() {
return real.size();
}
};
ListNumber phase = new ListDouble() {
@Override
public double getDouble(int index) {
double x = real.getDouble(index);
double y = imaginary.getDouble(index);
return Math.atan2(y, x);
}
@Override
public int size() {
return real.size();
}
};
return ValueFactory.newVTable(Arrays.<Class<?>>asList(double.class, double.class, double.class, double.class), Arrays.asList("x", "y", "mod", "phase"), Arrays.<Object>asList(real, imaginary, modulus, phase));
}
use of org.diirt.vtype.VNumberArray in project yamcs-studio by yamcs.
the class RescaleArrayFormulaFunction method calculate.
@Override
public Object calculate(final List<Object> args) {
if (NullUtils.containsNull(args)) {
return null;
}
VNumberArray arg1 = (VNumberArray) args.get(0);
VNumber arg2 = (VNumber) args.get(1);
VNumber arg3 = (VNumber) args.get(2);
return newVNumberArray(ListMath.rescale(arg1.getData(), arg2.getValue().doubleValue(), arg3.getValue().doubleValue()), highestSeverityOf(args, false), latestValidTimeOrNowOf(args), displayNone());
}
use of org.diirt.vtype.VNumberArray in project yamcs-studio by yamcs.
the class SubArrayFormulaFunction method calculate.
/*
* (non-Javadoc)
*
* @see
* org.epics.pvmanager.formula.FormulaFunction#calculate(java.util.List)
*/
@Override
public Object calculate(List<Object> args) {
if (NullUtils.containsNull(args)) {
return null;
}
VNumberArray numberArray = (VNumberArray) args.get(0);
int fromIndex = ((VNumber) args.get(1)).getValue().intValue();
int toIndex = ((VNumber) args.get(2)).getValue().intValue();
return newVNumberArray(ListMath.limit(numberArray.getData(), fromIndex, toIndex), highestSeverityOf(args, false), latestValidTimeOrNowOf(args), displayNone());
}
Aggregations