private void findBounds() { if (lonMinMax != null) return; lonEdge = lonCoord.getXEdges(); latEdge = latCoord.getYEdges(); // assume missing values have been converted to NaNs latMinMax = MAMath.getMinMax(latEdge); lonMinMax = MAMath.getMinMax(lonEdge); if (debug) System.out.printf("Bounds (%d %d): lat= (%f,%f) lon = (%f,%f) %n", nrows, ncols, latMinMax.min, latMinMax.max, lonMinMax.min, lonMinMax.max); }
public float getMeanElevation() {// degrees from horisontal earth tangent, towards zenith int[] shapeRadial = new int[1]; shapeRadial[0] = nrays; Array data = Array.factory(Float.class, shapeRadial, elev); meanElevation = MAMath.sumDouble(data) / data.getSize(); return (float) meanElevation; }
/** * Check that two arrays are conformable. * * @param a operand * @param b operand * @return true if conformable */ public static boolean conformable(Array a, Array b) { return conformable(a.getShape(), b.getShape()); }
Class classType = a.getElementType(); if (classType == double.class) { copyDouble(result, a); } else if (classType == float.class) { copyFloat(result, a); } else if (classType == long.class) { copyLong(result, a); } else if (classType == int.class) { copyInt(result, a); } else if (classType == short.class) { copyShort(result, a); } else if (classType == char.class) { copyChar(result, a); } else if (classType == byte.class) { copyByte(result, a); } else if (classType == boolean.class) { copyBoolean(result, a); } else copyObject(result, a);
/** * Create a copy of this Array, copying the data so that physical order is the same as * logical order * * @return the new Array */ public Array copy() { Array newA = factory(getDataType(), getShape()); MAMath.copy(newA, this); return newA; }
/** * Get the minimum and the maximum data value of the previously read Array, * skipping missing values as defined by isMissingData(double val). * * @param a Array to get min/max values * @return both min and max value. */ public MAMath.MinMax getMinMaxSkipMissingData(Array a) { return MAMath.getMinMaxSkipMissingData(a, this); }
try { Array cacheArray = pv.read(mainv.getShapeAsSection(), cancelTask); return MAMath.convert(cacheArray, dtype); // // cache may keep data as different type for (int i = 0; i < n; ++i) { Result r = completionService.take().get(); r.data = MAMath.convert(r.data, dtype); // just in case it need to be converted if (r != null) { int size = (int) r.data.getSize(); if ((cancelTask != null) && cancelTask.isCancel()) return null; varData = MAMath.convert(varData, dtype); // just in case it need to be converted
@Test public void testSet() { try { MAMath.setDouble(A, 1.0); assert( MAMath.sumDouble(A) == ((double) m*n*p)); } catch (Exception e) { fail("testSet Exception" + e); } try { int mlen = (m2 - m1 + 1); assert( MAMath.sumDouble(secA) == ((double) mlen*n*p)); } catch (Exception e) { fail("testSet2 Exception" + e); } }
@Test public void testAdd() { int dim0 = 2; int dim1 = 3; int [] shape = {dim0, dim1}; ArrayDouble A = new ArrayDouble(shape); ArrayDouble B = new ArrayDouble(shape); try { MAMath.setDouble(A, 1.0); MAMath.setDouble(B, 22.0F); MAMath.addDouble(A, A, A); Array result = MAMath.add( A, B); IndexIterator iterR = result.getIndexIterator(); while (iterR.hasNext()) { double vala = iterR.getDoubleNext(); assert( vala == 24.0); } } catch (Exception e) { fail("testAdd Exception" + e); } }
public static Array convert2packed(Array unpacked, double missingValue, int nbits, boolean isUnsigned, DataType packedType) { MAMath.ScaleOffset scaleOffset = calcScaleOffsetSkipMissingData(unpacked, missingValue, nbits, isUnsigned); Array result = Array.factory(packedType, unpacked.getShape()); IndexIterator riter = result.getIndexIterator(); while (unpacked.hasNext()) { double uv = unpacked.nextDouble(); double pv = (uv - scaleOffset.offset) / scaleOffset.scale; riter.setDoubleNext( pv); } return result; }
/** * Add elements of two arrays together, allocating the result array. * The result type and the operation type are taken from the type of a. * * @param a add values from here * @param b add values from here * @return result = a + b * @throws IllegalArgumentException a and b are not conformable * @throws UnsupportedOperationException dont support this data type yet */ public static Array add(Array a, Array b) throws IllegalArgumentException { Array result = Array.factory(a.getElementType(), a.getShape()); if (a.getElementType() == double.class) { addDouble(result, a, b); } else throw new UnsupportedOperationException(); return result; }
so = MAMath.calcScaleOffsetSkipMissingData(unpacked, missingValue, nbits); ncfile.addVariable("unpacked", DataType.DOUBLE, "lat lon"); packed = MAMath.convert2packed(unpacked, missingValue, nbits, DataType.SHORT); ncfile.write("packed", packed); Array convertPacked = MAMath.convert2Unpacked(readPacked, so); nearlyEquals(packed, convertPacked, readEnhanced, 1.0 / so.scale);
Class classType = a.getElementType(); if (classType == double.class) { copyDouble(result, a); } else if (classType == float.class) { copyFloat(result, a); } else if (classType == long.class) { copyLong(result, a); } else if (classType == int.class) { copyInt(result, a); } else if (classType == short.class) { copyShort(result, a); } else if (classType == char.class) { copyChar(result, a); } else if (classType == byte.class) { copyByte(result, a); } else if (classType == boolean.class) { copyBoolean(result, a); } else copyObject(result, a);
/** * Create a copy of this Array, copying the data so that physical order is the same as * logical order * * @return the new Array */ public Array copy() { Array newA = factory(getElementType(), getShape()); MAMath.copy(newA, this); newA.setUnsigned(isUnsigned()); return newA; }
/** * Get the minimum and the maximum data value of the previously read Array, * skipping missing values as defined by isMissingData(double val). * * @param a Array to get min/max values * @return both min and max value. */ public MAMath.MinMax getMinMaxSkipMissingData(Array a) { return MAMath.getMinMaxSkipMissingData(a, this); }
try { Array cacheArray = pv.read(mainv.getShapeAsSection(), cancelTask); return MAMath.convert(cacheArray, dtype); // // cache may keep data as different type Result r = completionService.take().get(); if (r != null) { r.data = MAMath.convert(r.data, dtype); // just in case it needs to be converted int size = (int) r.data.getSize(); Array.arraycopy(r.data, 0, allData, size * r.index, size); if ((cancelTask != null) && cancelTask.isCancel()) return null; varData = MAMath.convert(varData, dtype); // just in case it need to be converted
public static Array convert2packed(Array unpacked, double missingValue, int nbits, boolean isUnsigned, DataType packedType) { MAMath.ScaleOffset scaleOffset = calcScaleOffsetSkipMissingData(unpacked, missingValue, nbits, isUnsigned); Array result = Array.factory(packedType, unpacked.getShape()); IndexIterator riter = result.getIndexIterator(); while (unpacked.hasNext()) { double uv = unpacked.nextDouble(); double pv = (uv - scaleOffset.offset) / scaleOffset.scale; riter.setDoubleNext( pv); } return result; }
/** * Add elements of two arrays together, allocating the result array. * The result type and the operation type are taken from the type of a. * * @param a add values from here * @param b add values from here * @return result = a + b * @throws IllegalArgumentException a and b are not conformable * @throws UnsupportedOperationException dont support this data type yet */ public static Array add(Array a, Array b) throws IllegalArgumentException { Array result = Array.factory(a.getDataType(), a.getShape()); if (a.getElementType() == double.class) { addDouble(result, a, b); } else throw new UnsupportedOperationException(); return result; }
Class classType = a.getElementType(); if (classType == double.class) { copyDouble(result, a); } else if (classType == float.class) { copyFloat(result, a); } else if (classType == long.class) { copyLong(result, a); } else if (classType == int.class) { copyInt(result, a); } else if (classType == short.class) { copyShort(result, a); } else if (classType == char.class) { copyChar(result, a); } else if (classType == byte.class) { copyByte(result, a); } else if (classType == boolean.class) { copyBoolean(result, a); } else copyObject(result, a);
private void findBounds() { if (lonMinMax != null) return; lonEdge = lonCoord.getEdges(); latEdge = latCoord.getEdges(); // assume missing values have been converted to NaNs latMinMax = MAMath.getMinMax(latEdge); lonMinMax = MAMath.getMinMax(lonEdge); if (debug) System.out.printf("Bounds (%d %d): lat= (%f,%f) lon = (%f,%f) %n", nrows, ncols, latMinMax.min, latMinMax.max, lonMinMax.min, lonMinMax.max); }