Search in sources :

Example 1 with ArrayDouble

use of org.diirt.util.array.ArrayDouble in project yamcs-studio by yamcs.

the class VTableFactory method extractColumnData.

private static Object extractColumnData(Object columnData, int... rows) {
    if (columnData instanceof List) {
        List<Object> data = new ArrayList<>(rows.length);
        for (int i = 0; i < rows.length; i++) {
            int j = rows[i];
            data.add(((List<?>) columnData).get(j));
        }
        return data;
    } else if (columnData instanceof ListNumber) {
        double[] data = new double[rows.length];
        for (int i = 0; i < rows.length; i++) {
            int j = rows[i];
            data[i] = ((ListNumber) columnData).getDouble(j);
        }
        return new ArrayDouble(data);
    }
    return null;
}
Also used : ListNumber(org.diirt.util.array.ListNumber) ArrayDouble(org.diirt.util.array.ArrayDouble) ArrayList(java.util.ArrayList) AbstractList(java.util.AbstractList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with ArrayDouble

use of org.diirt.util.array.ArrayDouble 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 ArrayDouble

use of org.diirt.util.array.ArrayDouble 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 ArrayDouble

use of org.diirt.util.array.ArrayDouble in project yamcs-studio by yamcs.

the class ValueFactory method wrapValue.

/**
 * Takes a java objects and wraps it into a vType. All numbers are wrapped
 * as VDouble. String is wrapped as VString. double[] and ListDouble are wrapped as
 * VDoubleArray. A List of String is wrapped to a VStringArray. Alarms
 * are alarm, time are timeNow() and display are displayNone();
 *
 * @param value the value to wrap
 * @param alarm the alarm for the value
 * @return the wrapped value
 * @deprecated use {@link #toVType(java.lang.Object, org.diirt.vtype.Alarm, org.diirt.vtype.Time, org.diirt.vtype.Display) }
 */
@Deprecated
public static VType wrapValue(Object value, Alarm alarm) {
    if (value instanceof Number) {
        // Special support for numbers
        return newVDouble(((Number) value).doubleValue(), alarm, timeNow(), displayNone());
    } else if (value instanceof String) {
        // Special support for strings
        return newVString(((String) value), alarm, timeNow());
    } else if (value instanceof double[]) {
        return newVDoubleArray(new ArrayDouble((double[]) value), alarm, timeNow(), displayNone());
    } else if (value instanceof ListDouble) {
        return newVDoubleArray((ListDouble) value, alarm, timeNow(), displayNone());
    } else if (value instanceof List) {
        boolean matches = true;
        List list = (List) value;
        for (Object object : list) {
            if (!(object instanceof String)) {
                matches = false;
            }
        }
        if (matches) {
            @SuppressWarnings("unchecked") List<String> newList = (List<String>) list;
            return newVStringArray(Collections.unmodifiableList(newList), alarm, timeNow());
        } else {
            throw new UnsupportedOperationException("Type " + value.getClass().getName() + " contains non Strings");
        }
    } else {
        // TODO: need to implement all the other arrays
        throw new UnsupportedOperationException("Type " + value.getClass().getName() + "  is not yet supported");
    }
}
Also used : ListNumber(org.diirt.util.array.ListNumber) ArrayDouble(org.diirt.util.array.ArrayDouble) ListDouble(org.diirt.util.array.ListDouble) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with ArrayDouble

use of org.diirt.util.array.ArrayDouble in project yamcs-studio by yamcs.

the class VTableFactory method valueNumberTable.

private static VTable valueNumberTable(List<String> names, List<? extends VType> values) {
    double[] data = new double[values.size()];
    List<String> severity = new ArrayList<>();
    List<String> status = new ArrayList<>();
    for (int i = 0; i < values.size(); i++) {
        VNumber vNumber = (VNumber) values.get(i);
        data[i] = vNumber.getValue().doubleValue();
        severity.add(vNumber.getAlarmSeverity().name());
        status.add(vNumber.getAlarmName());
    }
    if (names == null) {
        return newVTable(column("Value", newVDoubleArray(new ArrayDouble(data), alarmNone(), timeNow(), displayNone())), column("Severity", newVStringArray(severity, alarmNone(), timeNow())), column("Status", newVStringArray(status, alarmNone(), timeNow())));
    } else {
        return newVTable(column("Name", newVStringArray(names, alarmNone(), timeNow())), column("Value", newVDoubleArray(new ArrayDouble(data), alarmNone(), timeNow(), displayNone())), column("Severity", newVStringArray(severity, alarmNone(), timeNow())), column("Status", newVStringArray(status, alarmNone(), timeNow())));
    }
}
Also used : ArrayDouble(org.diirt.util.array.ArrayDouble) ArrayList(java.util.ArrayList) VNumber(org.diirt.vtype.VNumber) VString(org.diirt.vtype.VString)

Aggregations

ArrayDouble (org.diirt.util.array.ArrayDouble)9 ListNumber (org.diirt.util.array.ListNumber)6 ArrayList (java.util.ArrayList)3 VNumberArray (org.diirt.vtype.VNumberArray)3 List (java.util.List)2 ListDouble (org.diirt.util.array.ListDouble)2 VType (org.diirt.vtype.VType)2 Test (org.junit.Test)2 AbstractList (java.util.AbstractList)1 VNumber (org.diirt.vtype.VNumber)1 VString (org.diirt.vtype.VString)1 ValueFactory.newVNumberArray (org.diirt.vtype.ValueFactory.newVNumberArray)1