Search in sources :

Example 6 with Range

use of ucar.ma2.Range in project metron by apache.

the class WindowProcessorTest method testRepeatWithWeekendExclusion.

@Test
public void testRepeatWithWeekendExclusion() {
    Window w = WindowProcessor.process("30 minute window every 24 hours from 7 days ago excluding weekends");
    Date now = new Date();
    // avoid DST impacts if near Midnight
    now.setHours(6);
    List<Range<Long>> intervals = w.toIntervals(now.getTime());
    assertEquals(5, intervals.size());
}
Also used : Range(org.apache.commons.lang3.Range) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 7 with Range

use of ucar.ma2.Range in project metron by apache.

the class WindowLookbackTest method test.

public State test(String windowSelector, Date now, Optional<Map<String, Object>> config, Assertions... assertions) {
    List<Range<Long>> windowIntervals = WindowProcessor.process(windowSelector).toIntervals(now.getTime());
    String stellarStatement = "PROFILE_WINDOW('" + windowSelector + "', now" + (config.isPresent() ? ", config" : "") + ")";
    Map<String, Object> variables = new HashMap<>();
    variables.put("now", now.getTime());
    if (config.isPresent()) {
        variables.put("config", config.get());
    }
    StellarProcessor stellar = new StellarProcessor();
    List<ProfilePeriod> periods = (List<ProfilePeriod>) stellar.parse(stellarStatement, new DefaultVariableResolver(k -> variables.get(k), k -> variables.containsKey(k)), resolver, context);
    State state = new State(windowIntervals, periods);
    for (Assertions assertion : assertions) {
        assertTrue(assertion.test(state), assertion.name());
    }
    return state;
}
Also used : StellarProcessor(org.apache.metron.stellar.common.StellarProcessor) ProfilePeriod(org.apache.metron.profiler.ProfilePeriod) Range(org.apache.commons.lang3.Range) Assertions(org.junit.jupiter.api.Assertions) DefaultVariableResolver(org.apache.metron.stellar.dsl.DefaultVariableResolver)

Example 8 with Range

use of ucar.ma2.Range in project sirix by sirixdb.

the class AbstractSunburstControl method controlEvent.

/**
 * Called on every change of the GUI.
 *
 * @param paramControlEvent
 *          the {@link ControlEvent}
 */
@Override
public void controlEvent(final ControlEvent paramControlEvent) {
    assert paramControlEvent != null;
    if (paramControlEvent.isController()) {
        if (paramControlEvent.getController().getId() == 50) {
            mModel.evaluateXPath(paramControlEvent.getController().getStringValue());
        } else {
            if (paramControlEvent.getController() instanceof Toggle) {
                final Toggle toggle = (Toggle) paramControlEvent.getController();
                switch(paramControlEvent.getController().getId()) {
                    case 0:
                        mGUI.setShowArcs(toggle.getState());
                        break;
                    case 1:
                        mGUI.setShowLines(toggle.getState());
                        break;
                    case 2:
                        mGUI.setUseBezierLine(toggle.getState());
                        break;
                }
            } else if (paramControlEvent.getController() instanceof Slider) {
                switch(paramControlEvent.getController().getId()) {
                    case 0:
                        mGUI.setInnerNodeArcScale(paramControlEvent.getController().getValue());
                        break;
                    case 1:
                        mGUI.setLeafArcScale(paramControlEvent.getController().getValue());
                        break;
                    case 2:
                        mGUI.setModificationWeight(paramControlEvent.getController().getValue());
                        break;
                    case 3:
                        mGUI.setDotSize(paramControlEvent.getController().getValue());
                        break;
                    case 4:
                        mGUI.setDotBrightness(paramControlEvent.getController().getValue());
                        break;
                    case 5:
                        mGUI.setBackgroundBrightness(paramControlEvent.getController().getValue());
                        break;
                }
            } else if (paramControlEvent.getController() instanceof Range) {
                final float[] f = paramControlEvent.getController().getArrayValue();
                switch(paramControlEvent.getController().getId()) {
                    case 0:
                        mGUI.setHueStart(f[0]);
                        mGUI.setHueEnd(f[1]);
                        break;
                    case 1:
                        mGUI.setSaturationStart(f[0]);
                        mGUI.setSaturationEnd(f[1]);
                        break;
                    case 2:
                        mGUI.setBrightnessStart(f[0]);
                        mGUI.setBrightnessEnd(f[1]);
                        break;
                    case 3:
                        mGUI.setInnerNodeBrightnessStart(f[0]);
                        mGUI.setInnerNodeBrightnessEnd(f[1]);
                        break;
                    case 4:
                        mGUI.setInnerNodeStrokeBrightnessStart(f[0]);
                        mGUI.setInnerNodeStrokeBrightnessEnd(f[1]);
                        break;
                    case 5:
                        mGUI.setStrokeWeightStart(f[0]);
                        mGUI.setStrokeWeightEnd(f[1]);
                        break;
                }
            }
            mGUI.update(EResetZoomer.YES);
        }
    }
}
Also used : Slider(controlP5.Slider) Toggle(controlP5.Toggle) Range(controlP5.Range)

Example 9 with Range

use of ucar.ma2.Range in project sirix by sirixdb.

the class AbstractSunburstGUI method setupGUI.

/**
 * Initial setup of the GUI.
 */
private void setupGUI() {
    mParent.textFont(mFont);
    mParent.smooth();
    mParent.background(255f);
    final int activeColor = mParent.color(0, 130, 164);
    mControlP5.setColorActive(activeColor);
    mControlP5.setColorBackground(mParent.color(170));
    mControlP5.setColorForeground(mParent.color(50));
    mControlP5.setColorLabel(mParent.color(50));
    mControlP5.setColorValue(mParent.color(255));
    final int len = 300;
    final Range hueRange = mControlP5.addRange("leaf node hue range", 0, 360, getHueStart(), getHueEnd(), LEFT, TOP + mPosY + 0, len, 15);
    mRanges.add(hueRange);
    final Range saturationRange = mControlP5.addRange("leaf node saturation range", 0, 100, getSaturationStart(), getSaturationEnd(), LEFT, TOP + mPosY + 20, len, 15);
    mRanges.add(saturationRange);
    final Range brightnessRange = mControlP5.addRange("leaf node brightness range", 0, 100, getBrightnessStart(), getBrightnessEnd(), LEFT, TOP + mPosY + 40, len, 15);
    mRanges.add(brightnessRange);
    mPosY += 70;
    final Range innerNodebrightnessRange = mControlP5.addRange("inner node brightness range", 0, 100, getInnerNodeBrightnessStart(), getInnerNodeBrightnessEnd(), LEFT, TOP + mPosY + 0, len, 15);
    mRanges.add(innerNodebrightnessRange);
    final Range innerNodeStrokeBrightnessRange = mControlP5.addRange("inner node stroke brightness range", 0, 100, getInnerNodeStrokeBrightnessStart(), getInnerNodeStrokeBrightnessEnd(), LEFT, TOP + mPosY + 20, len, 15);
    mRanges.add(innerNodeStrokeBrightnessRange);
    mPosY += 50;
    // name, minimum, maximum, default value (float), x, y, width, height
    final Slider innerNodeArcScale = mControlP5.addSlider("setInnerNodeArcScale", 0, 1, getInnerNodeArcScale(), LEFT, TOP + mPosY + 0, len, 15);
    innerNodeArcScale.setCaptionLabel("innerNodeArcScale");
    mSliders.add(innerNodeArcScale);
    final Slider leafNodeArcScale = mControlP5.addSlider("setLeafArcScale", 0, 1, getLeafArcScale(), LEFT, TOP + mPosY + 20, len, 15);
    leafNodeArcScale.setCaptionLabel("leafNodeArcScale");
    mSliders.add(leafNodeArcScale);
    mPosY += 50;
    final Slider modWeight = mControlP5.addSlider("setModificationWeight", 0, 1, getModificationWeight(), LEFT, TOP + mPosY + 0, len, 15);
    modWeight.setCaptionLabel("modification weight");
    mSliders.add(modWeight);
    mPosY += 50;
    final Range strokeWeight = mControlP5.addRange("stroke weight range", 0, 10, getStrokeWeightStart(), getStrokeWeightEnd(), LEFT, TOP + mPosY + 0, len, 15);
    mRanges.add(strokeWeight);
    mPosY += 30;
    final Slider dotSize = mControlP5.addSlider("setDotSize", 0, 10, mDotSize, LEFT, TOP + mPosY + 0, len, 15);
    dotSize.setCaptionLabel("dot size");
    mSliders.add(dotSize);
    final Slider dotBrightness = mControlP5.addSlider("setDotBrightness", 0, 100, mDotBrightness, LEFT, TOP + mPosY + 20, len, 15);
    dotBrightness.setCaptionLabel("dot brightness");
    mSliders.add(dotBrightness);
    mPosY += 50;
    final Slider backgroundBrightness = mControlP5.addSlider("setBackgroundBrightness", 0, 100, getBackgroundBrightness(), LEFT, TOP + mPosY + 0, len, 15);
    backgroundBrightness.setCaptionLabel("background brightness");
    mSliders.add(backgroundBrightness);
    mPosY += 50;
    final Toggle showArcs = mControlP5.addToggle("isShowArcs", isShowArcs(), LEFT + 0, TOP + mPosY, 15, 15);
    showArcs.setCaptionLabel("show arcs");
    mToggles.add(showArcs);
    final Toggle showLines = mControlP5.addToggle("isShowLines", isShowLines(), LEFT + 0, TOP + mPosY + 20, 15, 15);
    showLines.setCaptionLabel("show lines");
    mToggles.add(showLines);
    final Toggle useBezier = mControlP5.addToggle("isUseBezierLine", isUseBezierLine(), LEFT + 0, TOP + mPosY + 40, 15, 15);
    useBezier.setCaptionLabel("Bezier / Line");
    mToggles.add(useBezier);
    setup();
    style();
}
Also used : Slider(controlP5.Slider) Toggle(controlP5.Toggle) Range(controlP5.Range)

Example 10 with Range

use of ucar.ma2.Range in project imageio-ext by geosolutions-it.

the class GRIB1ImageReader method read.

/**
 * @see javax.imageio.ImageReader#read(int, javax.imageio.ImageReadParam)
 */
@Override
public BufferedImage read(int imageIndex, ImageReadParam param) throws IOException {
    BufferedImage image = null;
    Variable variable = null;
    Range indexRange = null;
    GribVariableWrapper wrapper = null;
    for (Range range : indexMap.keySet()) {
        if (range.contains(imageIndex) && range.first() <= imageIndex && imageIndex < range.last()) {
            wrapper = indexMap.get(range);
            indexRange = range;
            break;
        }
    }
    variable = wrapper.getVariable();
    /*
         * Fetches the parameters that are not already processed by utility
         * methods like 'getDestination' or 'computeRegions' (invoked below).
         */
    final int strideX, strideY;
    final int[] srcBands, dstBands;
    if (param != null) {
        strideX = param.getSourceXSubsampling();
        strideY = param.getSourceYSubsampling();
        srcBands = param.getSourceBands();
        dstBands = param.getDestinationBands();
    } else {
        strideX = 1;
        strideY = 1;
        srcBands = null;
        dstBands = null;
    }
    final int rank = wrapper.getRank();
    final int bandDimension = rank - NetCDFUtilities.Z_DIMENSION;
    /*
         * Gets the destination image of appropriate size. We create it now
         * since it is a convenient way to get the number of destination bands.
         */
    final int width = wrapper.getWidth();
    final int height = wrapper.getHeight();
    /*
         * Computes the source region (in the NetCDF file) and the destination
         * region (in the buffered image). Copies those informations into UCAR
         * Range structure.
         */
    final Rectangle srcRegion = new Rectangle();
    final Rectangle destRegion = new Rectangle();
    computeRegions(param, width, height, null, srcRegion, destRegion);
    // flipVertically(param, height, srcRegion);
    int destWidth = destRegion.x + destRegion.width;
    int destHeight = destRegion.y + destRegion.height;
    final List<Range> ranges = new LinkedList<Range>();
    for (int i = 0; i < rank; i++) {
        final int first, length, stride;
        switch(rank - i) {
            case NetCDFUtilities.X_DIMENSION:
                {
                    first = srcRegion.x;
                    length = srcRegion.width;
                    stride = strideX;
                    break;
                }
            case NetCDFUtilities.Y_DIMENSION:
                {
                    first = srcRegion.y;
                    length = srcRegion.height;
                    stride = strideY;
                    break;
                }
            default:
                {
                    if (i == bandDimension) {
                        first = NetCDFUtilities.getZIndex(variable, indexRange, imageIndex);
                    } else {
                        first = NetCDFUtilities.getTIndex(variable, indexRange, imageIndex);
                    }
                    length = 1;
                    stride = 1;
                    break;
                }
        }
        try {
            ranges.add(new Range(first, first + length - 1, stride));
        } catch (InvalidRangeException e) {
        }
    }
    final Section sections = new Section(ranges);
    /*
         * Setting SampleModel and ColorModel.
         */
    SampleModel sampleModel = wrapper.getSampleModel().createCompatibleSampleModel(destWidth, destHeight);
    ColorModel colorModel = ImageIOUtilities.createColorModel(sampleModel);
    /*
         * Reads the requested sub-region only.
         */
    final int numDstBands = 1;
    final int size = destHeight * destWidth * numDstBands;
    for (int zi = 0; zi < numDstBands; zi++) {
        final int dstBand = (dstBands == null) ? zi : dstBands[zi];
        final Array array;
        try {
            array = variable.read(sections);
            DataBuffer dataBuffer = null;
            if (array instanceof ArrayByte) {
                dataBuffer = new DataBufferByte((byte[]) array.get1DJavaArray(byte.class), size);
            } else if (array instanceof ArrayShort) {
                dataBuffer = new DataBufferShort((short[]) array.get1DJavaArray(short.class), size);
            } else if (array instanceof ArrayInt) {
                dataBuffer = new DataBufferInt((int[]) array.get1DJavaArray(int.class), size);
            } else if (array instanceof ArrayFloat) {
                dataBuffer = new DataBufferFloat((float[]) array.get1DJavaArray(float.class), size);
            } else if (array instanceof ArrayDouble) {
                dataBuffer = new DataBufferDouble((double[]) array.get1DJavaArray(double.class), size);
            }
            WritableRaster raster = Raster.createWritableRaster(sampleModel, dataBuffer, new Point(0, 0));
            image = new BufferedImage(colorModel, raster, colorModel.isAlphaPremultiplied(), null);
        } catch (InvalidRangeException e) {
        }
    }
    return image;
}
Also used : DataBufferDouble(java.awt.image.DataBufferDouble) Variable(ucar.nc2.Variable) Rectangle(java.awt.Rectangle) ArrayFloat(ucar.ma2.ArrayFloat) DataBufferInt(java.awt.image.DataBufferInt) DataBufferByte(java.awt.image.DataBufferByte) BufferedImage(java.awt.image.BufferedImage) DataBufferShort(java.awt.image.DataBufferShort) ArrayDouble(ucar.ma2.ArrayDouble) ColorModel(java.awt.image.ColorModel) WritableRaster(java.awt.image.WritableRaster) ArrayByte(ucar.ma2.ArrayByte) ArrayShort(ucar.ma2.ArrayShort) DataBuffer(java.awt.image.DataBuffer) InvalidRangeException(ucar.ma2.InvalidRangeException) Point(java.awt.Point) Range(ucar.ma2.Range) Section(ucar.ma2.Section) Point(java.awt.Point) LinkedList(java.util.LinkedList) Array(ucar.ma2.Array) SampleModel(java.awt.image.SampleModel) BandedSampleModel(java.awt.image.BandedSampleModel) ArrayInt(ucar.ma2.ArrayInt) DataBufferFloat(java.awt.image.DataBufferFloat)

Aggregations

Range (org.apache.commons.lang3.Range)14 Date (java.util.Date)11 Variable (ucar.nc2.Variable)10 Test (org.junit.jupiter.api.Test)9 Array (ucar.ma2.Array)9 InvalidRangeException (ucar.ma2.InvalidRangeException)8 Range (ucar.ma2.Range)8 IOException (java.io.IOException)6 HashMap (java.util.HashMap)6 Attribute (ucar.nc2.Attribute)6 Point (java.awt.Point)5 DataType (ucar.ma2.DataType)5 ArrayFloat (ucar.ma2.ArrayFloat)4 ArrayShort (ucar.ma2.ArrayShort)4 NetcdfDataset (ucar.nc2.dataset.NetcdfDataset)4 Range (controlP5.Range)3 Slider (controlP5.Slider)3 Toggle (controlP5.Toggle)3 Rectangle (java.awt.Rectangle)3 BandedSampleModel (java.awt.image.BandedSampleModel)3