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);
}
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;
}
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));
}
Aggregations