Search in sources :

Example 1 with ListDouble

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);
}
Also used : ListDouble(org.yamcs.studio.data.vtype.ListDouble) VNumber(org.yamcs.studio.data.vtype.VNumber)

Example 2 with ListDouble

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));
}
Also used : VNumberArray(org.yamcs.studio.data.vtype.VNumberArray) ListNumber(org.yamcs.studio.data.vtype.ListNumber) ArrayDouble(org.yamcs.studio.data.vtype.ArrayDouble) ListDouble(org.yamcs.studio.data.vtype.ListDouble)

Aggregations

ListDouble (org.yamcs.studio.data.vtype.ListDouble)2 ArrayDouble (org.yamcs.studio.data.vtype.ArrayDouble)1 ListNumber (org.yamcs.studio.data.vtype.ListNumber)1 VNumber (org.yamcs.studio.data.vtype.VNumber)1 VNumberArray (org.yamcs.studio.data.vtype.VNumberArray)1