Search in sources :

Example 1 with ListDouble

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

the class VNumbersToVNumberArrayConverter method readValue.

@Override
public VNumberArray readValue() {
    final List<VNumber> values = new ArrayList<VNumber>();
    Display meta = displayNone();
    for (ReadFunction<? extends VNumber> function : arguments) {
        VNumber number = function.readValue();
        values.add(number);
        if (meta == null && number != null)
            meta = number;
    }
    ListDouble data = new ListDouble() {

        @Override
        public double getDouble(int index) {
            VNumber number = values.get(index);
            if (number == null || number.getValue() == null)
                return Double.NaN;
            else
                return number.getValue().doubleValue();
        }

        @Override
        public int size() {
            return values.size();
        }
    };
    return ValueFactory.newVDoubleArray(data, alarmNone(), timeNow(), displayNone());
}
Also used : ArrayList(java.util.ArrayList) VNumber(org.diirt.vtype.VNumber) ListDouble(org.diirt.util.array.ListDouble) Display(org.diirt.vtype.Display)

Example 2 with ListDouble

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

the class VColumn method combineDoubleData.

private static Object combineDoubleData(final int size, final ListInt offsets, final List<VColumn> columns) {
    return new ListDouble() {

        @Override
        public double getDouble(int index) {
            int tableIndex = ListNumbers.binarySearchValueOrLower(offsets, index);
            if (columns.get(tableIndex) == null) {
                return Double.NaN;
            }
            int rowIndex = index - offsets.getInt(tableIndex);
            // TODO: mismatched type should be handled better
            if (!ListNumber.class.isInstance(columns.get(tableIndex).getData())) {
                return Double.NaN;
            }
            @SuppressWarnings("unchecked") ListNumber values = (ListNumber) columns.get(tableIndex).getData();
            if (rowIndex < values.size()) {
                return values.getDouble(rowIndex);
            } else {
                return Double.NaN;
            }
        }

        @Override
        public int size() {
            return size;
        }
    };
}
Also used : ListNumber(org.diirt.util.array.ListNumber) ListDouble(org.diirt.util.array.ListDouble)

Example 3 with ListDouble

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

the class ArrayOfNumberFormulaFunction method calculate.

@Override
public Object calculate(final List<Object> args) {
    ListDouble data = new ListDouble() {

        @Override
        public double getDouble(int index) {
            VNumber 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 (Object object : args) {
        if (object != null) {
            firstNonNull = (VNumber) object;
        }
    }
    Display display = displayNone();
    if (firstNonNull != null) {
        if (ValueUtil.displayHasValidDisplayLimits(firstNonNull)) {
            display = firstNonNull;
        } else {
            Statistics 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.diirt.util.array.ListDouble) VNumber(org.diirt.vtype.VNumber) Statistics(org.diirt.util.Statistics) ValueFactory.newDisplay(org.diirt.vtype.ValueFactory.newDisplay) Display(org.diirt.vtype.Display)

Example 4 with ListDouble

use of org.diirt.util.array.ListDouble 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 5 with ListDouble

use of org.diirt.util.array.ListDouble in project org.csstudio.display.builder by kasemir.

the class ValueUtil method getTable.

/**
 * Get a table from PV
 *
 *  <p>Ideally, the PV holds a {@link VTable},
 *  and the returned data is then the table's data.
 *
 *  <p>If the PV is a scalar, a table with a single cell is returned.
 *  <p>If the PV is an array, a table with one column is returned.
 *
 *  @param value Value of a PV
 *  @return List of rows, where each row contains either String or Number cells
 */
@SuppressWarnings("rawtypes")
public static List<List<Object>> getTable(final VType value) {
    final List<List<Object>> data = new ArrayList<>();
    if (value instanceof VTable) {
        final VTable table = (VTable) value;
        final int rows = table.getRowCount();
        final int cols = table.getColumnCount();
        // Extract 2D string matrix for data
        for (int r = 0; r < rows; ++r) {
            final List<Object> row = new ArrayList<>(cols);
            for (int c = 0; c < cols; ++c) {
                final Object col_data = table.getColumnData(c);
                if (col_data instanceof List)
                    row.add(Objects.toString(((List) col_data).get(r)));
                else if (col_data instanceof ListDouble)
                    row.add(((ListDouble) col_data).getDouble(r));
                else if (col_data instanceof ListNumber)
                    row.add(((ListNumber) col_data).getLong(r));
                else
                    row.add(Objects.toString(col_data));
            }
            data.add(row);
        }
    } else if (value instanceof VNumberArray) {
        final ListNumber numbers = ((VNumberArray) value).getData();
        final int num = numbers.size();
        for (int i = 0; i < num; ++i) data.add(Arrays.asList(numbers.getDouble(i)));
    } else if (value instanceof VNumber)
        data.add(Arrays.asList(((VNumber) value).getValue()));
    else
        data.add(Arrays.asList(Objects.toString(value)));
    return data;
}
Also used : VNumberArray(org.diirt.vtype.VNumberArray) ListNumber(org.diirt.util.array.ListNumber) VTable(org.diirt.vtype.VTable) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ListDouble(org.diirt.util.array.ListDouble) VNumber(org.diirt.vtype.VNumber)

Aggregations

ListDouble (org.diirt.util.array.ListDouble)7 ListNumber (org.diirt.util.array.ListNumber)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 VNumber (org.diirt.vtype.VNumber)3 ArrayDouble (org.diirt.util.array.ArrayDouble)2 Display (org.diirt.vtype.Display)2 VNumberArray (org.diirt.vtype.VNumberArray)2 VTable (org.diirt.vtype.VTable)2 Statistics (org.diirt.util.Statistics)1 ListInt (org.diirt.util.array.ListInt)1 VString (org.diirt.vtype.VString)1 ValueFactory.newDisplay (org.diirt.vtype.ValueFactory.newDisplay)1