Search in sources :

Example 6 with ArrayInt

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

the class ValueFactory method newVNumberArray.

/**
 * Creates a new VNumberArray based on the type of the data.
 *
 * @param data the array data
 * @param alarm the alarm
 * @param time the time
 * @param display the display
 * @return a new value
 */
public static VNumberArray newVNumberArray(final ListNumber data, final Alarm alarm, final Time time, final Display display) {
    ListInt sizes = new ArrayInt(data.size());
    List<ArrayDimensionDisplay> dimensionDisplay = ValueUtil.defaultArrayDisplay(sizes);
    return newVNumberArray(data, sizes, dimensionDisplay, alarm, time, display);
}
Also used : ListInt(org.diirt.util.array.ListInt) ArrayInt(org.diirt.util.array.ArrayInt)

Example 7 with ArrayInt

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

the class HistogramOfFormulaFunction method calculate.

@Override
public Object calculate(List<Object> args) {
    VNumberArray numberArray = (VNumberArray) args.get(0);
    if (numberArray == null) {
        return null;
    }
    // If no change, return previous
    if (previousValue == numberArray) {
        return previousResult;
    }
    Statistics stats = StatisticsUtil.statisticsOf(numberArray.getData());
    int nBins = 100;
    Range aggregatedRange = Ranges.aggregateRange(stats.getRange(), previousXRange);
    Range xRange;
    if (Ranges.overlap(aggregatedRange, stats.getRange()) >= 0.75) {
        xRange = aggregatedRange;
    } else {
        xRange = stats.getRange();
    }
    IteratorNumber newValues = numberArray.getData().iterator();
    double minValueRange = xRange.getMinimum();
    double maxValueRange = xRange.getMaximum();
    ListNumber xBoundaries = ListNumbers.linearListFromRange(minValueRange, maxValueRange, nBins + 1);
    String unit = numberArray.getUnits();
    int[] binData = new int[nBins];
    double maxCount = 0;
    while (newValues.hasNext()) {
        double value = newValues.nextDouble();
        // Check value in range
        if (xRange.contains(value)) {
            int bin = (int) Math.floor(xRange.normalize(value) * nBins);
            if (bin == nBins) {
                bin--;
            }
            binData[bin]++;
            if (binData[bin] > maxCount) {
                maxCount = binData[bin];
            }
        }
    }
    if (previousMaxCount > maxCount && previousMaxCount < maxCount * 2.0) {
        maxCount = previousMaxCount;
    }
    previousMaxCount = maxCount;
    previousXRange = xRange;
    previousValue = numberArray;
    previousResult = newVNumberArray(new ArrayInt(binData), new ArrayInt(nBins), Arrays.asList(newDisplay(xBoundaries, unit)), numberArray, numberArray, newDisplay(0.0, 0.0, 0.0, "count", NumberFormats.format(0), maxCount, maxCount, maxCount, Double.NaN, Double.NaN));
    return previousResult;
}
Also used : VNumberArray(org.diirt.vtype.VNumberArray) ListNumber(org.diirt.util.array.ListNumber) Range(org.diirt.util.Range) ArrayInt(org.diirt.util.array.ArrayInt) Statistics(org.diirt.util.Statistics) IteratorNumber(org.diirt.util.array.IteratorNumber)

Example 8 with ArrayInt

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

the class Square2DWaveform method nextValue.

@Override
VDoubleArray nextValue() {
    if (initialReference == null) {
        initialReference = lastTime;
    }
    double t = initialReference.until(lastTime, ChronoUnit.SECONDS);
    double omega = 2 * Math.PI / periodInSeconds;
    double k = 2 * Math.PI / wavelengthInSamples;
    double min = -1.0;
    double max = 1.0;
    double range = 0.0;
    return (VDoubleArray) ValueFactory.newVNumberArray(generateNewValue(omega, t, k), new ArrayInt(ySamples, xSamples), ValueUtil.defaultArrayDisplay(new ArrayInt(ySamples, xSamples)), alarmNone(), newTime(lastTime), newDisplay(min, min + range * 0.1, min + range * 0.2, "", Constants.DOUBLE_FORMAT, min + range * 0.8, min + range * 0.9, max, min, max));
}
Also used : VDoubleArray(org.diirt.vtype.VDoubleArray) ArrayInt(org.diirt.util.array.ArrayInt)

Aggregations

ArrayInt (org.diirt.util.array.ArrayInt)8 ArrayList (java.util.ArrayList)2 Range (org.diirt.util.Range)2 Statistics (org.diirt.util.Statistics)2 ListInt (org.diirt.util.array.ListInt)2 ListNumber (org.diirt.util.array.ListNumber)2 VDoubleArray (org.diirt.vtype.VDoubleArray)2 VString (org.diirt.vtype.VString)2 VTable (org.diirt.vtype.VTable)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 IntensityGraphModel (org.csstudio.opibuilder.widgets.model.IntensityGraphModel)1 AxisProperty (org.csstudio.opibuilder.widgets.model.IntensityGraphModel.AxisProperty)1 IntensityGraphFigure (org.csstudio.swt.widgets.figures.IntensityGraphFigure)1 IPixelInfoListener (org.csstudio.swt.widgets.figures.IntensityGraphFigure.IPixelInfoListener)1 IProfileDataChangeLisenter (org.csstudio.swt.widgets.figures.IntensityGraphFigure.IProfileDataChangeLisenter)1 PixelInfo (org.csstudio.swt.widgets.figures.IntensityGraphFigure.PixelInfo)1 ArrayDouble (org.diirt.util.array.ArrayDouble)1 IteratorNumber (org.diirt.util.array.IteratorNumber)1