Search in sources :

Example 21 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)

Example 22 with Range

use of ucar.ma2.Range in project TechReborn by TechReborn.

the class BuiltContainer method transferStackInSlot.

@Override
public ItemStack transferStackInSlot(final EntityPlayer player, final int index) {
    ItemStack originalStack = ItemStack.EMPTY;
    final Slot slot = this.inventorySlots.get(index);
    if (slot != null && slot.getHasStack()) {
        final ItemStack stackInSlot = slot.getStack();
        originalStack = stackInSlot.copy();
        boolean shifted = false;
        for (final Range<Integer> range : this.playerSlotRanges) if (range.contains(index)) {
            if (this.shiftToTile(stackInSlot))
                shifted = true;
            break;
        }
        if (!shifted)
            for (final Range<Integer> range : this.tileSlotRanges) if (range.contains(index)) {
                if (this.shiftToPlayer(stackInSlot))
                    shifted = true;
                break;
            }
        slot.onSlotChange(stackInSlot, originalStack);
        if (stackInSlot.getCount() <= 0)
            slot.putStack(ItemStack.EMPTY);
        else
            slot.onSlotChanged();
        if (stackInSlot.getCount() == originalStack.getCount())
            return ItemStack.EMPTY;
        slot.onTake(player, stackInSlot);
    }
    return originalStack;
}
Also used : ItemStack(net.minecraft.item.ItemStack) Range(org.apache.commons.lang3.Range)

Example 23 with Range

use of ucar.ma2.Range in project libSBOLj by SynBioDex.

the class SequenceAnnotationTest method test_locationMethods.

@Test
public void test_locationMethods() throws SBOLValidationException {
    Cut promoter_cut = promoter_SA.addCut("promoter_cut", 1);
    assertTrue(gRNA_b_gene.getSequenceAnnotation("promoter_SA").getLocation("promoter_cut").equals(promoter_cut));
    promoter_cut.unsetOrientation();
    assertNull(promoter_cut.getOrientation());
    Location test = promoter_cut;
    assertNotNull(test.toString());
    Cut terminator_cut = terminator_SA.addCut("terminator_cut", 100);
    assertTrue(gRNA_b_gene.getSequenceAnnotation("terminator_SA").getLocation("terminator_cut").equals(terminator_cut));
    Cut gene_cut = gene_SA.addCut("gene_cut", 50, OrientationType.INLINE);
    assertTrue(gRNA_b_gene.getSequenceAnnotation("gene_SA").getLocation("gene_cut").equals(gene_cut));
    gene_SA.removeLocation(gene_cut);
    assertNull(gene_SA.getLocation("gene_cut"));
    Range gene_range = gene_SA.addRange("gene_range", 50, 99);
    assertTrue(gRNA_b_gene.getSequenceAnnotation("gene_SA").getLocation("gene_range").equals(gene_range));
    gene_range.unsetOrientation();
    assertNull(gene_range.getOrientation());
    promoter_SA.removeLocation(promoter_cut);
    assertNull(promoter_SA.getLocation(promoter_cut.getIdentity()));
    GenericLocation promoter_glocation = promoter_SA.addGenericLocation("promoter_glocation");
    assertTrue(gRNA_b_gene.getSequenceAnnotation("promoter_SA").getLocation("promoter_glocation").equals(promoter_glocation));
    terminator_SA.removeLocation(terminator_cut);
    assertNull(terminator_SA.getLocation("terminator_cut"));
    GenericLocation terminator_glocation = terminator_SA.addGenericLocation("terminator_glocation", OrientationType.INLINE);
    assertTrue(gRNA_b_gene.getSequenceAnnotation("terminator_SA").getLocation("terminator_glocation").equals(terminator_glocation));
}
Also used : Cut(org.sbolstandard.core2.Cut) GenericLocation(org.sbolstandard.core2.GenericLocation) Range(org.sbolstandard.core2.Range) GenericLocation(org.sbolstandard.core2.GenericLocation) Location(org.sbolstandard.core2.Location) Test(org.junit.Test)

Example 24 with Range

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

the class INGVConverter method run.

private void run(String fileNameIn, String fileNameOut) {
    try {
        final File fileIn = new File(fileNameIn);
        final NetcdfFile ncFileIn = NetcdfFile.open(fileNameIn);
        final File fileOut = new File(fileNameOut);
        // keep original name
        final File outputFile = File.createTempFile(fileIn.getName(), ".tmp");
        final NetcdfFileWriteable ncFileOut = NetcdfFileWriteable.createNew(outputFile.getAbsolutePath());
        boolean hasDepth = false;
        // input dimensions
        String timeName = "time_counter";
        Dimension timeOriginalDim = ncFileIn.findDimension(timeName);
        if (timeOriginalDim == null) {
            timeOriginalDim = ncFileIn.findDimension("time");
            timeName = "time";
        }
        final Dimension yDim = ncFileIn.findDimension("y");
        final Dimension xDim = ncFileIn.findDimension("x");
        // input VARIABLES
        final Variable timeOriginalVar = ncFileIn.findVariable(timeName);
        final Array timeOriginalData = timeOriginalVar.read();
        final DataType timeDataType = timeOriginalVar.getDataType();
        final Variable navLat = ncFileIn.findVariable(NAV_LAT);
        final DataType navLatDataType = navLat.getDataType();
        final Variable navLon = ncFileIn.findVariable(NAV_LON);
        final DataType navLonDataType = navLon.getDataType();
        final int nLat = yDim.getLength();
        final int nLon = xDim.getLength();
        final int nTimes = timeOriginalDim.getLength();
        final Array latOriginalData = navLat.read("0:" + (nLat - 1) + ":1, 0:0:1").reduce();
        final Array lonOriginalData = navLon.read("0:0:1, 0:" + (nLon - 1) + ":1").reduce();
        // //
        // 
        // Depth related vars
        // 
        // //
        Array depthOriginalData = null;
        DataType depthDataType = null;
        int nDepths = 0;
        Array depthDestData = null;
        Dimension depthDim = null;
        String depthName = "depth";
        Variable depthOriginalVar = null;
        int dName = 0;
        while (depthOriginalVar == null) {
            if (dName == depthNames.length)
                break;
            String name = depthNames[dName++];
            // Depth
            depthOriginalVar = ncFileIn.findVariable(name);
        }
        if (depthOriginalVar != null) {
            depthName = depthNames[dName - 1];
            nDepths = depthOriginalVar.getDimension(0).getLength();
            depthOriginalData = depthOriginalVar.read();
            hasDepth = true;
        }
        Dimension timeDim = ncFileOut.addDimension("time", nTimes);
        Dimension latDim = ncFileOut.addDimension(NetCDFUtilities.LAT, nLat);
        Dimension lonDim = ncFileOut.addDimension(NetCDFUtilities.LON, nLon);
        if (hasDepth)
            depthDim = ncFileOut.addDimension(NetCDFUtilities.DEPTH, nDepths);
        // writing file
        NetCDFConverterUtilities.copyGlobalAttributes(ncFileOut, ncFileIn.getGlobalAttributes());
        // //
        // 
        // Time requires a special Management
        // 
        // //
        // time Variable
        Variable timeVar = ncFileOut.addVariable(NetCDFUtilities.TIME, timeDataType, new Dimension[] { timeDim });
        NetCDFConverterUtilities.setVariableAttributes(timeOriginalVar, ncFileOut, NetCDFUtilities.TIME);
        // Dimensions
        ncFileOut.addVariable(NetCDFUtilities.LAT, navLatDataType, new Dimension[] { latDim });
        NetCDFConverterUtilities.setVariableAttributes(navLat, ncFileOut, NetCDFUtilities.LAT);
        ncFileOut.addVariable(NetCDFUtilities.LON, navLonDataType, new Dimension[] { lonDim });
        NetCDFConverterUtilities.setVariableAttributes(navLon, ncFileOut, NetCDFUtilities.LON);
        Array lat1Data = NetCDFConverterUtilities.getArray(nLat, navLatDataType);
        NetCDFConverterUtilities.setData1D(latOriginalData, lat1Data, navLatDataType, nLat, true);
        // lon Variable
        Array lon1Data = NetCDFConverterUtilities.getArray(nLon, navLonDataType);
        NetCDFConverterUtilities.setData1D(lonOriginalData, lon1Data, navLonDataType, nLon, false);
        if (hasDepth) {
            depthDataType = depthOriginalVar.getDataType();
            ncFileOut.addVariable(NetCDFUtilities.DEPTH, depthDataType, new Dimension[] { depthDim });
            NetCDFConverterUtilities.setVariableAttributes(depthOriginalVar, ncFileOut, NetCDFUtilities.DEPTH);
        }
        if (hasDepth) {
            // depth level Variable
            depthDestData = NetCDFConverterUtilities.getArray(nDepths, depthDataType);
            NetCDFConverterUtilities.setData1D(depthOriginalData, depthDestData, depthDataType, nDepths, false);
        }
        // {} Variables
        final ArrayList<String> variables = new ArrayList<String>(5);
        final HashMap<String, String> updatingValidRange = new HashMap<String, String>(5);
        final HashMap<String, String> updatingFilLValue = new HashMap<String, String>(5);
        int numVars = 0;
        for (int i = 0; i < NUMVARS; i++) {
            String varName = (String) VARIABLES.get(i);
            Variable var = ncFileIn.findVariable(varName);
            if (var != null) {
                variables.add(varName);
                boolean hasLocalDepth = NetCDFConverterUtilities.hasThisDimension(var, depthName);
                if (hasDepth && hasLocalDepth)
                    ncFileOut.addVariable(varName, var.getDataType(), new Dimension[] { timeDim, depthDim, latDim, lonDim });
                else
                    ncFileOut.addVariable(varName, var.getDataType(), new Dimension[] { timeDim, latDim, lonDim });
                // //
                // 
                // Check for updating valid range
                // 
                // //
                boolean hasMinMax = false;
                Attribute validMax = var.findAttribute(NetCDFUtilities.DatasetAttribs.VALID_MAX);
                Attribute validMin = var.findAttribute(NetCDFUtilities.DatasetAttribs.VALID_MIN);
                Attribute fillValue = var.findAttribute(NetCDFUtilities.DatasetAttribs.FILL_VALUE);
                boolean hasMissingValue = false;
                boolean hasFillValue = true;
                if (fillValue == null) {
                    hasFillValue = false;
                    fillValue = var.findAttribute(NetCDFUtilities.DatasetAttribs.MISSING_VALUE);
                    if (fillValue != null)
                        hasMissingValue = true;
                }
                Attribute validRange = var.findAttribute(NetCDFUtilities.DatasetAttribs.VALID_RANGE);
                boolean hasValidRange = false;
                boolean rewriteAttribute = false;
                if (validMin != null && validMax != null && fillValue != null) {
                    rewriteAttribute = !NetCDFConverterUtilities.isFillValueOutsideValidRange(validMax, validMin, fillValue, var.getDataType());
                    hasMinMax = true;
                } else if (validRange != null && fillValue != null) {
                    rewriteAttribute = !NetCDFConverterUtilities.isFillValueOutsideValidRange(validRange, fillValue, var.getDataType());
                    hasValidRange = true;
                } else {
                    rewriteAttribute = true;
                }
                if (rewriteAttribute) {
                    updatingValidRange.put(varName, "");
                    DataType varDatatype = var.getDataType();
                    Array range = NetCDFConverterUtilities.getRangeArray(varDatatype);
                    ncFileOut.addVariableAttribute(varName, NetCDFUtilities.DatasetAttribs.VALID_RANGE, range);
                    if (hasMissingValue && !hasFillValue) {
                        updatingFilLValue.put(varName, "");
                        Number fillVal = NetCDFConverterUtilities.getNumber(varDatatype);
                        ncFileOut.addVariableAttribute(varName, NetCDFUtilities.DatasetAttribs.FILL_VALUE, fillVal);
                    }
                }
                String[] exceptions = null;
                if (hasMinMax) {
                    if (hasMissingValue)
                        exceptions = new String[] { NetCDFUtilities.DatasetAttribs.VALID_MAX, NetCDFUtilities.DatasetAttribs.VALID_MIN, NetCDFUtilities.DatasetAttribs.MISSING_VALUE };
                    else
                        exceptions = new String[] { NetCDFUtilities.DatasetAttribs.VALID_MAX, NetCDFUtilities.DatasetAttribs.VALID_MIN };
                } else if (hasValidRange) {
                    if (hasMissingValue)
                        exceptions = new String[] { NetCDFUtilities.DatasetAttribs.VALID_RANGE, NetCDFUtilities.DatasetAttribs.MISSING_VALUE };
                    else
                        exceptions = new String[] { NetCDFUtilities.DatasetAttribs.VALID_RANGE };
                } else if (hasMissingValue)
                    exceptions = new String[] { NetCDFUtilities.DatasetAttribs.MISSING_VALUE };
                NetCDFConverterUtilities.setVariableAttributes(var, ncFileOut, exceptions);
                numVars++;
            }
        }
        // writing bin data ...
        ncFileOut.create();
        Array timeData = NetCDFConverterUtilities.getArray(nTimes, timeDataType);
        NetCDFConverterUtilities.setData1D(timeOriginalData, timeData, timeDataType, nTimes, false);
        ncFileOut.write("time", timeData);
        timeVar = ncFileOut.findVariable("time");
        timeDim.addCoordinateVariable(timeVar);
        ncFileOut.write(NetCDFUtilities.LAT, lat1Data);
        ncFileOut.write(NetCDFUtilities.LON, lon1Data);
        if (hasDepth) {
            Variable depthVar = ncFileOut.findVariable("depth");
            depthDim.addCoordinateVariable(depthVar);
            ncFileOut.write(NetCDFUtilities.DEPTH, depthDestData);
        }
        for (int i = 0; i < numVars; i++) {
            String varName = (String) variables.get(i);
            Variable var = ncFileIn.findVariable(varName);
            final boolean hasLocalDepth = NetCDFConverterUtilities.hasThisDimension(var, depthName);
            Array originalVarArray = var.read();
            DataType varDataType = var.getDataType();
            Array destArray = null;
            int[] dimensions = null;
            final boolean setDepth = hasDepth && hasLocalDepth;
            if (setDepth) {
                dimensions = new int[] { timeDim.getLength(), depthDim.getLength(), latDim.getLength(), lonDim.getLength() };
            } else {
                dimensions = new int[] { timeDim.getLength(), latDim.getLength(), lonDim.getLength() };
            }
            destArray = NetCDFConverterUtilities.getArray(dimensions, varDataType);
            boolean findNewRange = updatingValidRange.containsKey(varName);
            boolean updateFillValue = updatingFilLValue.containsKey(varName);
            final int[] loopLengths;
            if (setDepth)
                loopLengths = new int[] { nTimes, nDepths, nLat, nLon };
            else
                loopLengths = new int[] { nTimes, nLat, nLon };
            NetCDFConverterUtilities.writeData(ncFileOut, varName, var, originalVarArray, destArray, findNewRange, updateFillValue, loopLengths, true);
        }
        ncFileOut.close();
        outputFile.renameTo(fileOut);
    } catch (Exception e) {
        // something bad happened
        if (NetCDFConverterUtilities.LOGGER.isLoggable(Level.INFO))
            NetCDFConverterUtilities.LOGGER.log(Level.INFO, e.getLocalizedMessage(), e);
    }
}
Also used : NetcdfFileWriteable(ucar.nc2.NetcdfFileWriteable) Variable(ucar.nc2.Variable) HashMap(java.util.HashMap) Attribute(ucar.nc2.Attribute) ArrayList(java.util.ArrayList) Dimension(ucar.nc2.Dimension) IOException(java.io.IOException) NetcdfFile(ucar.nc2.NetcdfFile) Array(ucar.ma2.Array) DataType(ucar.ma2.DataType) NetcdfFile(ucar.nc2.NetcdfFile) File(java.io.File)

Example 25 with Range

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

the class NetCDFConverterUtilities method writeData.

public static void writeData(NetcdfFileWriteable ncFileOut, final String varName, Variable var, final Array originalVarData, final Array destArray, final boolean findNewRange, final boolean updateFillValue, final int[] loopLengths, final boolean flipY) throws IOException, InvalidRangeException {
    final int nestedLoops = loopLengths.length;
    final boolean setDepth = nestedLoops > 3;
    // timeDim
    final int timePositions = loopLengths[0];
    final int depthPositions;
    final int latPositions;
    final int lonPositions;
    if (setDepth) {
        depthPositions = loopLengths[1];
        latPositions = loopLengths[2];
        lonPositions = loopLengths[3];
    } else {
        depthPositions = -1;
        latPositions = loopLengths[1];
        lonPositions = loopLengths[2];
    }
    final DataType varDataType = var.getDataType();
    Attribute fv = null;
    if (updateFillValue)
        fv = var.findAttribute(NetCDFUtilities.DatasetAttribs.MISSING_VALUE);
    else
        fv = var.findAttribute(NetCDFUtilities.DatasetAttribs.FILL_VALUE);
    Index varIndex = originalVarData.getIndex();
    Index destIndex = destArray.getIndex();
    // //
    if (varDataType == DataType.FLOAT) {
        float min = Float.MAX_VALUE;
        float max = Float.MIN_VALUE;
        float fillValue = Float.MAX_VALUE;
        if (fv != null) {
            fillValue = (fv.getNumericValue()).floatValue();
        }
        if (setDepth) {
            for (int tPos = 0; tPos < timePositions; tPos++) {
                for (int levelPos = 0; levelPos < depthPositions; levelPos++) {
                    for (int yPos = 0; yPos < latPositions; yPos++) {
                        for (int xPos = 0; xPos < lonPositions; xPos++) {
                            float sVal = originalVarData.getFloat(varIndex.set(tPos, levelPos, yPos, xPos));
                            if (findNewRange) {
                                if (sVal >= max && sVal != fillValue)
                                    max = sVal;
                                if (sVal <= min && sVal != fillValue)
                                    min = sVal;
                            }
                            int newYpos = yPos;
                            // Flipping y
                            if (flipY) {
                                newYpos = latPositions - yPos - 1;
                            }
                            destArray.setFloat(destIndex.set(tPos, levelPos, newYpos, xPos), sVal);
                        }
                    }
                }
            }
        } else {
            for (int tPos = 0; tPos < timePositions; tPos++) {
                for (int yPos = 0; yPos < latPositions; yPos++) {
                    for (int xPos = 0; xPos < lonPositions; xPos++) {
                        float sVal = originalVarData.getFloat(varIndex.set(tPos, yPos, xPos));
                        if (findNewRange) {
                            if (sVal >= max && sVal != fillValue)
                                max = sVal;
                            if (sVal <= min && sVal != fillValue)
                                min = sVal;
                        }
                        // Flipping y
                        int newYpos = yPos;
                        // Flipping y
                        if (flipY) {
                            newYpos = latPositions - yPos - 1;
                        }
                        destArray.setFloat(destIndex.set(tPos, newYpos, xPos), sVal);
                    }
                }
            }
        }
        ncFileOut.write(varName, destArray);
        if (findNewRange) {
            Array range = NetCDFConverterUtilities.getRangeArray(varDataType);
            Index index = range.getIndex();
            range.setFloat(index.set(0), min);
            range.setFloat(index.set(1), max);
            ncFileOut.updateAttribute(ncFileOut.findVariable(varName), new Attribute(NetCDFUtilities.DatasetAttribs.VALID_RANGE, range));
        }
        if (updateFillValue) {
            ncFileOut.updateAttribute(ncFileOut.findVariable(varName), new Attribute(NetCDFUtilities.DatasetAttribs.FILL_VALUE, new Float(fillValue)));
        }
    // //
    // 
    // DOUBLE
    // 
    // //
    } else if (varDataType == DataType.DOUBLE) {
        double min = Double.MAX_VALUE;
        double max = Double.MIN_VALUE;
        double fillValue = Double.MAX_VALUE;
        if (fv != null) {
            fillValue = (fv.getNumericValue()).doubleValue();
        }
        if (setDepth) {
            for (int tPos = 0; tPos < timePositions; tPos++) {
                for (int levelPos = 0; levelPos < depthPositions; levelPos++) {
                    for (int yPos = 0; yPos < latPositions; yPos++) {
                        for (int xPos = 0; xPos < lonPositions; xPos++) {
                            double sVal = originalVarData.getDouble(varIndex.set(tPos, levelPos, yPos, xPos));
                            if (findNewRange) {
                                if (sVal >= max && sVal != fillValue)
                                    max = sVal;
                                if (sVal <= min && sVal != fillValue)
                                    min = sVal;
                            }
                            int newYpos = yPos;
                            // Flipping y
                            if (flipY) {
                                newYpos = latPositions - yPos - 1;
                            }
                            destArray.setDouble(destIndex.set(tPos, levelPos, newYpos, xPos), sVal);
                        }
                    }
                }
            }
        } else {
            for (int tPos = 0; tPos < timePositions; tPos++) {
                for (int yPos = 0; yPos < latPositions; yPos++) {
                    for (int xPos = 0; xPos < lonPositions; xPos++) {
                        double sVal = originalVarData.getDouble(varIndex.set(tPos, yPos, xPos));
                        if (findNewRange) {
                            if (sVal >= max && sVal != fillValue)
                                max = sVal;
                            if (sVal <= min && sVal != fillValue)
                                min = sVal;
                        }
                        // Flipping y
                        int newYpos = yPos;
                        // Flipping y
                        if (flipY) {
                            newYpos = latPositions - yPos - 1;
                        }
                        destArray.setDouble(destIndex.set(tPos, newYpos, xPos), sVal);
                    }
                }
            }
        }
        ncFileOut.write(varName, destArray);
        if (findNewRange) {
            Array range = NetCDFConverterUtilities.getRangeArray(varDataType);
            Index index = range.getIndex();
            range.setDouble(index.set(0), min);
            range.setDouble(index.set(1), max);
            ncFileOut.updateAttribute(ncFileOut.findVariable(varName), new Attribute(NetCDFUtilities.DatasetAttribs.VALID_RANGE, range));
        }
        if (updateFillValue) {
            ncFileOut.updateAttribute(ncFileOut.findVariable(varName), new Attribute(NetCDFUtilities.DatasetAttribs.FILL_VALUE, new Double(fillValue)));
        }
    // //
    // 
    // BYTE
    // 
    // //
    } else if (varDataType == DataType.BYTE) {
        byte min = Byte.MAX_VALUE;
        byte max = Byte.MIN_VALUE;
        byte fillValue = Byte.MAX_VALUE;
        if (fv != null) {
            fillValue = (fv.getNumericValue()).byteValue();
        }
        if (setDepth) {
            for (int tPos = 0; tPos < timePositions; tPos++) {
                for (int levelPos = 0; levelPos < depthPositions; levelPos++) {
                    for (int yPos = 0; yPos < latPositions; yPos++) {
                        for (int xPos = 0; xPos < lonPositions; xPos++) {
                            byte sVal = originalVarData.getByte(varIndex.set(tPos, levelPos, yPos, xPos));
                            if (findNewRange) {
                                if (sVal >= max && sVal != fillValue)
                                    max = sVal;
                                if (sVal <= min && sVal != fillValue)
                                    min = sVal;
                            }
                            int newYpos = yPos;
                            // Flipping y
                            if (flipY) {
                                newYpos = latPositions - yPos - 1;
                            }
                            destArray.setByte(destIndex.set(tPos, levelPos, newYpos, xPos), sVal);
                        }
                    }
                }
            }
        } else {
            for (int tPos = 0; tPos < timePositions; tPos++) {
                for (int yPos = 0; yPos < latPositions; yPos++) {
                    for (int xPos = 0; xPos < lonPositions; xPos++) {
                        byte sVal = originalVarData.getByte(varIndex.set(tPos, yPos, xPos));
                        if (findNewRange) {
                            if (sVal >= max && sVal != fillValue)
                                max = sVal;
                            if (sVal <= min && sVal != fillValue)
                                min = sVal;
                        }
                        // Flipping y
                        int newYpos = yPos;
                        // Flipping y
                        if (flipY) {
                            newYpos = latPositions - yPos - 1;
                        }
                        destArray.setByte(destIndex.set(tPos, newYpos, xPos), sVal);
                    }
                }
            }
        }
        ncFileOut.write(varName, destArray);
        if (findNewRange) {
            Array range = NetCDFConverterUtilities.getRangeArray(varDataType);
            Index index = range.getIndex();
            range.setByte(index.set(0), min);
            range.setByte(index.set(1), max);
            ncFileOut.updateAttribute(ncFileOut.findVariable(varName), new Attribute(NetCDFUtilities.DatasetAttribs.VALID_RANGE, range));
        }
        if (updateFillValue) {
            ncFileOut.updateAttribute(ncFileOut.findVariable(varName), new Attribute(NetCDFUtilities.DatasetAttribs.FILL_VALUE, new Byte(fillValue)));
        }
    // //
    // 
    // SHORT
    // 
    // //
    } else if (varDataType == DataType.SHORT) {
        short min = Short.MAX_VALUE;
        short max = Short.MIN_VALUE;
        short fillValue = Short.MAX_VALUE;
        if (fv != null) {
            fillValue = (fv.getNumericValue()).shortValue();
        }
        if (setDepth) {
            for (int tPos = 0; tPos < timePositions; tPos++) {
                for (int levelPos = 0; levelPos < depthPositions; levelPos++) {
                    for (int yPos = 0; yPos < latPositions; yPos++) {
                        for (int xPos = 0; xPos < lonPositions; xPos++) {
                            short sVal = originalVarData.getShort(varIndex.set(tPos, levelPos, yPos, xPos));
                            if (findNewRange) {
                                if (sVal >= max && sVal != fillValue)
                                    max = sVal;
                                if (sVal <= min && sVal != fillValue)
                                    min = sVal;
                            }
                            int newYpos = yPos;
                            // Flipping y
                            if (flipY) {
                                newYpos = latPositions - yPos - 1;
                            }
                            destArray.setShort(destIndex.set(tPos, levelPos, newYpos, xPos), sVal);
                        }
                    }
                }
            }
        } else {
            for (int tPos = 0; tPos < timePositions; tPos++) {
                for (int yPos = 0; yPos < latPositions; yPos++) {
                    for (int xPos = 0; xPos < lonPositions; xPos++) {
                        short sVal = originalVarData.getShort(varIndex.set(tPos, yPos, xPos));
                        if (findNewRange) {
                            if (sVal >= max && sVal != fillValue)
                                max = sVal;
                            if (sVal <= min && sVal != fillValue)
                                min = sVal;
                        }
                        // Flipping y
                        int newYpos = yPos;
                        // Flipping y
                        if (flipY) {
                            newYpos = latPositions - yPos - 1;
                        }
                        destArray.setShort(destIndex.set(tPos, newYpos, xPos), sVal);
                    }
                }
            }
        }
        ncFileOut.write(varName, destArray);
        if (findNewRange) {
            Array range = NetCDFConverterUtilities.getRangeArray(varDataType);
            Index index = range.getIndex();
            range.setShort(index.set(0), min);
            range.setShort(index.set(1), max);
            ncFileOut.updateAttribute(ncFileOut.findVariable(varName), new Attribute(NetCDFUtilities.DatasetAttribs.VALID_RANGE, range));
        }
        if (updateFillValue) {
            ncFileOut.updateAttribute(ncFileOut.findVariable(varName), new Attribute(NetCDFUtilities.DatasetAttribs.FILL_VALUE, new Short(fillValue)));
        }
    } else // //
    if (varDataType == DataType.INT) {
        int min = Integer.MAX_VALUE;
        int max = Integer.MIN_VALUE;
        int fillValue = Integer.MAX_VALUE;
        if (fv != null) {
            fillValue = (fv.getNumericValue()).intValue();
        }
        if (setDepth) {
            for (int tPos = 0; tPos < timePositions; tPos++) {
                for (int levelPos = 0; levelPos < depthPositions; levelPos++) {
                    for (int yPos = 0; yPos < latPositions; yPos++) {
                        for (int xPos = 0; xPos < lonPositions; xPos++) {
                            int sVal = originalVarData.getInt(varIndex.set(tPos, levelPos, yPos, xPos));
                            if (findNewRange) {
                                if (sVal >= max && sVal != fillValue)
                                    max = sVal;
                                if (sVal <= min && sVal != fillValue)
                                    min = sVal;
                            }
                            int newYpos = yPos;
                            // Flipping y
                            if (flipY) {
                                newYpos = latPositions - yPos - 1;
                            }
                            destArray.setInt(destIndex.set(tPos, levelPos, newYpos, xPos), sVal);
                        }
                    }
                }
            }
        } else {
            for (int tPos = 0; tPos < timePositions; tPos++) {
                for (int yPos = 0; yPos < latPositions; yPos++) {
                    for (int xPos = 0; xPos < lonPositions; xPos++) {
                        int sVal = originalVarData.getInt(varIndex.set(tPos, yPos, xPos));
                        if (findNewRange) {
                            if (sVal >= max && sVal != fillValue)
                                max = sVal;
                            if (sVal <= min && sVal != fillValue)
                                min = sVal;
                        }
                        // Flipping y
                        int newYpos = yPos;
                        // Flipping y
                        if (flipY) {
                            newYpos = latPositions - yPos - 1;
                        }
                        destArray.setInt(destIndex.set(tPos, newYpos, xPos), sVal);
                    }
                }
            }
        }
        ncFileOut.write(varName, destArray);
        if (findNewRange) {
            Array range = NetCDFConverterUtilities.getRangeArray(varDataType);
            Index index = range.getIndex();
            range.setInt(index.set(0), min);
            range.setInt(index.set(1), max);
            ncFileOut.updateAttribute(ncFileOut.findVariable(varName), new Attribute(NetCDFUtilities.DatasetAttribs.VALID_RANGE, range));
        }
        if (updateFillValue) {
            ncFileOut.updateAttribute(ncFileOut.findVariable(varName), new Attribute(NetCDFUtilities.DatasetAttribs.FILL_VALUE, new Integer(fillValue)));
        }
    } else
        throw new IllegalArgumentException("Unsupported DataType");
}
Also used : Attribute(ucar.nc2.Attribute) Index(ucar.ma2.Index) ArrayDouble(ucar.ma2.ArrayDouble) Array(ucar.ma2.Array) ArrayFloat(ucar.ma2.ArrayFloat) ArrayByte(ucar.ma2.ArrayByte) DataType(ucar.ma2.DataType) ArrayShort(ucar.ma2.ArrayShort)

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