Search in sources :

Example 16 with Range

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

the class NetCDFUtilities method getAttributesAsString.

/**
 * Return the value of a NetCDF {@code Attribute} instance as a
 * {@code String}. The {@code isUnsigned} parameter allow to handle byte
 * attributes as unsigned, in order to represent values in the range
 * [0,255].
 */
public static String getAttributesAsString(Attribute attr, final boolean isUnsigned) {
    String[] values = null;
    if (attr != null) {
        final int nValues = attr.getLength();
        values = new String[nValues];
        final DataType datatype = attr.getDataType();
        // TODO: Improve the unsigned management
        if (datatype == DataType.BYTE) {
            if (isUnsigned)
                for (int i = 0; i < nValues; i++) {
                    byte val = attr.getNumericValue(i).byteValue();
                    int myByte = (0x000000FF & ((int) val));
                    short anUnsignedByte = (short) myByte;
                    values[i] = Short.toString(anUnsignedByte);
                }
            else {
                for (int i = 0; i < nValues; i++) {
                    byte val = attr.getNumericValue(i).byteValue();
                    values[i] = Byte.toString(val);
                }
            }
        } else if (datatype == DataType.SHORT) {
            for (int i = 0; i < nValues; i++) {
                short val = attr.getNumericValue(i).shortValue();
                values[i] = Short.toString(val);
            }
        } else if (datatype == DataType.INT) {
            for (int i = 0; i < nValues; i++) {
                int val = attr.getNumericValue(i).intValue();
                values[i] = Integer.toString(val);
            }
        } else if (datatype == DataType.LONG) {
            for (int i = 0; i < nValues; i++) {
                long val = attr.getNumericValue(i).longValue();
                values[i] = Long.toString(val);
            }
        } else if (datatype == DataType.DOUBLE) {
            for (int i = 0; i < nValues; i++) {
                double val = attr.getNumericValue(i).doubleValue();
                values[i] = Double.toString(val);
            }
        } else if (datatype == DataType.FLOAT) {
            for (int i = 0; i < nValues; i++) {
                float val = attr.getNumericValue(i).floatValue();
                values[i] = Float.toString(val);
            }
        } else if (datatype == DataType.STRING) {
            for (int i = 0; i < nValues; i++) {
                values[i] = attr.getStringValue(i);
            }
        } else {
            if (LOGGER.isLoggable(Level.WARNING))
                LOGGER.warning("Unhandled Attribute datatype " + attr.getDataType().getClassType().toString());
        }
    }
    String value = "";
    if (values != null) {
        StringBuffer sb = new StringBuffer();
        int j = 0;
        for (; j < values.length - 1; j++) {
            sb.append(values[j]).append(",");
        }
        sb.append(values[j]);
        value = sb.toString();
    }
    return value;
}
Also used : DataType(ucar.ma2.DataType)

Example 17 with Range

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

the class WindowProcessorTest method testDenseWindow.

@Test
public void testDenseWindow() {
    for (String text : new String[] { "from 2 hours ago to 30 minutes ago", "starting from 2 hours until 30 minutes", "starting from 2 hours ago until 30 minutes ago", "starting from 30 minutes ago until 2 hours ago", "from 30 minutes ago to 2 hours ago " }) {
        Window w = WindowProcessor.process(text);
        /*
    A dense window starting 2 hour ago and continuing until 30 minutes ago
     */
        Date now = new Date();
        List<Range<Long>> intervals = w.toIntervals(now.getTime());
        assertEquals(1, intervals.size());
        assertTimeEquals(now.getTime() - TimeUnit.HOURS.toMillis(2), intervals.get(0).getMinimum());
        assertTimeEquals(now.getTime() - TimeUnit.MINUTES.toMillis(30), intervals.get(0).getMaximum());
    }
}
Also used : Range(org.apache.commons.lang3.Range) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 18 with Range

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

the class WindowProcessorTest method testRepeatWithConflictingExclusionInclusion.

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

Example 19 with Range

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

the class WindowProcessorTest method testDateDaySpecifier.

@Test
public void testDateDaySpecifier() throws ParseException {
    for (String text : new String[] { "30 minute window every 24 hours from 14 days ago including date:20171225:yyyyMMdd", "30 minute window every 24 hours from 14 days ago including date:2017-12-25:yyyy-MM-dd", "30 minute window every 24 hours from 14 days ago including date:2017/12/25" }) {
        Window w = WindowProcessor.process(text);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm");
        Date now = sdf.parse("2017/12/26 12:00");
        List<Range<Long>> intervals = w.toIntervals(now.getTime());
        assertEquals(1, intervals.size());
        Date includedDate = new Date(intervals.get(0).getMinimum());
        SimpleDateFormat equalityFormat = new SimpleDateFormat("yyyyMMdd");
        assertEquals("20171225", equalityFormat.format(includedDate));
    }
    {
        Window w = WindowProcessor.process("30 minute window every 24 hours from 14 days ago excluding date:2017/12/25");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm");
        Date now = sdf.parse("2017/12/26 12:00");
        List<Range<Long>> intervals = w.toIntervals(now.getTime());
        assertEquals(13, intervals.size());
    }
    {
        Window w = WindowProcessor.process("30 minute window every 24 hours from 14 days ago including date:2017/12/25, date:2017/12/24");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm");
        Date now = sdf.parse("2017/12/26 12:00");
        List<Range<Long>> intervals = w.toIntervals(now.getTime());
        assertEquals(2, intervals.size());
        {
            Date includedDate = new Date(intervals.get(0).getMinimum());
            SimpleDateFormat equalityFormat = new SimpleDateFormat("yyyyMMdd");
            assertEquals("20171224", equalityFormat.format(includedDate));
        }
        {
            Date includedDate = new Date(intervals.get(1).getMinimum());
            SimpleDateFormat equalityFormat = new SimpleDateFormat("yyyyMMdd");
            assertEquals("20171225", equalityFormat.format(includedDate));
        }
    }
}
Also used : List(java.util.List) Range(org.apache.commons.lang3.Range) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 20 with Range

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

the class AbstractSunburstGUI method style.

/**
 * Style menu.
 */
protected void style() {
    final Group ctrl = mControlP5.addGroup("menu", 15, 25, 35);
    ctrl.setColorLabel(mParent.color(255));
    ctrl.setColorBackground(mParent.color(100));
    ctrl.close();
    mParent.colorMode(PConstants.RGB, 255, 255, 255);
    final int backgroundColor = 0x99ffffff;
    int i = 0;
    for (final Slider slider : mSliders) {
        slider.setGroup(ctrl);
        slider.setId(i);
        final Label label = slider.getCaptionLabel();
        label.toUpperCase(true);
        label.setColor(mParent.color(0));
        label.setColorBackground(backgroundColor);
        final ControllerStyle style = label.getStyle();
        style.padding(4, 0, 1, 3);
        style.marginTop = -4;
        style.marginLeft = 0;
        style.marginRight = -14;
        slider.plugTo(mControl);
        i++;
    }
    i = 0;
    for (final Range range : mRanges) {
        range.setGroup(ctrl);
        range.setId(i);
        final Label label = range.getCaptionLabel();
        label.toUpperCase(true);
        label.setColor(mParent.color(0));
        label.setColorBackground(backgroundColor);
        final ControllerStyle style = label.getStyle();
        style.padding(4, 0, 1, 3);
        style.marginTop = -4;
        range.plugTo(mControl);
        i++;
    }
    i = 0;
    for (final Toggle toggle : mToggles) {
        toggle.setGroup(ctrl);
        toggle.setId(i);
        final Label label = toggle.getCaptionLabel();
        label.setColor(mParent.color(0));
        label.setColorBackground(backgroundColor);
        final ControllerStyle style = label.getStyle();
        style.padding(4, 3, 1, 3);
        style.marginTop = -19;
        style.marginLeft = 18;
        style.marginRight = 5;
        toggle.plugTo(mControl);
        i++;
    }
    mParent.colorMode(PConstants.HSB, 360, 100, 100);
    mParent.textLeading(14);
    mParent.textAlign(PConstants.LEFT, PConstants.TOP);
    mParent.cursor(PConstants.CROSS);
}
Also used : Group(controlP5.Group) ControllerStyle(controlP5.ControllerStyle) Slider(controlP5.Slider) Toggle(controlP5.Toggle) Label(controlP5.Label) Range(controlP5.Range)

Aggregations

Range (org.apache.commons.lang3.Range)11 Date (java.util.Date)9 Test (org.junit.jupiter.api.Test)9 Variable (ucar.nc2.Variable)9 Array (ucar.ma2.Array)8 Range (ucar.ma2.Range)8 InvalidRangeException (ucar.ma2.InvalidRangeException)7 Attribute (ucar.nc2.Attribute)6 Point (java.awt.Point)5 HashMap (java.util.HashMap)5 IOException (java.io.IOException)4 ArrayFloat (ucar.ma2.ArrayFloat)4 ArrayShort (ucar.ma2.ArrayShort)4 DataType (ucar.ma2.DataType)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