use of org.yamcs.studio.data.vtype.ListDouble in project yamcs-studio by yamcs.
the class ArrayOfNumberFormulaFunction method calculate.
@Override
public Object calculate(List<Object> args) {
ListDouble data = new ListDouble() {
@Override
public double getDouble(int index) {
var number = (VNumber) args.get(index);
if (number == null || number.getValue() == null) {
return Double.NaN;
} else {
return number.getValue().doubleValue();
}
}
@Override
public int size() {
return args.size();
}
};
VNumber firstNonNull = null;
for (var object : args) {
if (object != null) {
firstNonNull = (VNumber) object;
}
}
var display = displayNone();
if (firstNonNull != null) {
if (ValueUtil.displayHasValidDisplayLimits(firstNonNull)) {
display = firstNonNull;
} else {
var stats = StatisticsUtil.statisticsOf(data);
display = newDisplay(stats.getRange().getMinimum(), stats.getRange().getMinimum(), stats.getRange().getMinimum(), "", NumberFormats.toStringFormat(), stats.getRange().getMaximum(), stats.getRange().getMaximum(), stats.getRange().getMaximum(), stats.getRange().getMinimum(), stats.getRange().getMaximum());
}
}
return ValueFactory.newVNumberArray(data, highestSeverityOf(args, false), latestValidTimeOrNowOf(args), display);
}
use of org.yamcs.studio.data.vtype.ListDouble in project yamcs-studio by yamcs.
the class DftFormulaFunction method calculate.
@Override
public Object calculate(List<Object> args) {
var 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
var fft = ListMath.dft(array.getData(), new ArrayDouble(new double[array.getData().size()]));
var real = fft.get(0);
var imaginary = fft.get(1);
ListNumber modulus = new ListDouble() {
@Override
public double getDouble(int index) {
var x = real.getDouble(index);
var 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) {
var x = real.getDouble(index);
var 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));
}
Aggregations