Search in sources :

Example 1 with VNumberArray

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());
}
Also used : ValueFactory.newVNumberArray(org.diirt.vtype.ValueFactory.newVNumberArray) VNumberArray(org.diirt.vtype.VNumberArray) VNumber(org.diirt.vtype.VNumber)

Example 2 with VNumberArray

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());
}
Also used : ValueFactory.newVNumberArray(org.diirt.vtype.ValueFactory.newVNumberArray) VNumberArray(org.diirt.vtype.VNumberArray) ArrayDouble(org.diirt.util.array.ArrayDouble)

Example 3 with VNumberArray

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));
}
Also used : VNumberArray(org.diirt.vtype.VNumberArray) ListNumber(org.diirt.util.array.ListNumber) ArrayDouble(org.diirt.util.array.ArrayDouble) ListDouble(org.diirt.util.array.ListDouble)

Example 4 with VNumberArray

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());
}
Also used : ValueFactory.newVNumberArray(org.diirt.vtype.ValueFactory.newVNumberArray) VNumberArray(org.diirt.vtype.VNumberArray) VNumber(org.diirt.vtype.VNumber)

Example 5 with VNumberArray

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());
}
Also used : ValueFactory.newVNumberArray(org.diirt.vtype.ValueFactory.newVNumberArray) VNumberArray(org.diirt.vtype.VNumberArray)

Aggregations

VNumberArray (org.diirt.vtype.VNumberArray)30 ListNumber (org.diirt.util.array.ListNumber)13 VNumber (org.diirt.vtype.VNumber)10 VString (org.diirt.vtype.VString)6 ValueFactory.newVNumberArray (org.diirt.vtype.ValueFactory.newVNumberArray)6 VEnumArray (org.diirt.vtype.VEnumArray)5 VType (org.diirt.vtype.VType)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 ArrayDouble (org.diirt.util.array.ArrayDouble)4 ListInt (org.diirt.util.array.ListInt)4 VStringArray (org.diirt.vtype.VStringArray)4 VEnum (org.diirt.vtype.VEnum)3 VTable (org.diirt.vtype.VTable)3 Background (javafx.scene.layout.Background)2 BackgroundFill (javafx.scene.layout.BackgroundFill)2 ListDouble (org.diirt.util.array.ListDouble)2 ArrayDimensionDisplay (org.diirt.vtype.ArrayDimensionDisplay)2 VBoolean (org.diirt.vtype.VBoolean)2 VDoubleArray (org.diirt.vtype.VDoubleArray)2