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; }
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; }
public float getMeanElevation() {// degrees from horisontal earth tangent, towards zenith int[] shapeRadial = new int[1]; shapeRadial[0] = nrays; Array data = Array.factory(DataType.FLOAT, shapeRadial, elev); meanElevation = MAMath.sumDouble(data) / data.getSize(); return (float) meanElevation; }
private void setMeanElevation() { if (Double.isNaN(meanElevation)) { try { Variable sp = ds.findVariable("elevation"); Array spData = sp.read(); sp.setCachedData(spData, false); meanElevation = MAMath.sumDouble(spData) / spData.getSize(); } catch (IOException e) { e.printStackTrace(); meanElevation = 0.0; } } }
private void setMeanElevation() { if (Double.isNaN(meanElevation)) { try { Variable sp = ds.findVariable("elevation"); Array spData = sp.read(); sp.setCachedData(spData, false); meanElevation = MAMath.sumDouble(spData) / spData.getSize(); } catch (IOException e) { e.printStackTrace(); meanElevation = 0.0; } } }
private void setMeanElevation() { Array spData = null; if (Double.isNaN(meanElevation)) { try { Variable sp = ds.findVariable("elevation"); spData = sp.read(); sp.setCachedData(spData, false); } catch (IOException e) { e.printStackTrace(); meanElevation = 0.0; } meanElevation = MAMath.sumDouble(spData) / spData.getSize(); } }
private void setMeanAzimuth() { if (getType() != null) { Array spData = null; try { Variable sp = ds.findVariable("azimuth"); spData = sp.read(); sp.setCachedData(spData, false); } catch (IOException e) { e.printStackTrace(); meanAzimuth = 0.0; } meanAzimuth = MAMath.sumDouble(spData) / spData.getSize(); } else meanAzimuth = 0.0; }
private void setMeanAzimuth() { if (getType() != null) { Array spData = null; try { Variable sp = ds.findVariable("azimuth"); spData = sp.read(); sp.setCachedData(spData, false); } catch (IOException e) { e.printStackTrace(); meanAzimuth = 0.0; } meanAzimuth = MAMath.sumDouble(spData) / spData.getSize(); } else meanAzimuth = 0.0; }
private void setMeanAzimuth() { if (getType() != null) { Array spData = null; try { Variable sp = ds.findVariable("azimuth"); spData = sp.read(); sp.setCachedData(spData, false); } catch (IOException e) { e.printStackTrace(); meanAzimuth = 0.0; } meanAzimuth = MAMath.sumDouble(spData) / spData.getSize(); } else meanAzimuth = 0.0; }
@Test public void testUnsigned2() { int nz = 1; int ny = 2030; int nx = 1354; int size = nz * ny * nx; short[] vals = new short[size]; for (int i = 0; i < size; i++) vals[i] = (short) i; Array data = Array.factory(DataType.USHORT, new int[]{nz, ny, nx}, vals); double sum = MAMath.sumDouble(data); double sumReduce = MAMath.sumDouble(data.reduce(0)); Assert2.assertNearlyEquals(sum, sumReduce); }
public void openFileProblem() throws IOException { long start = System.currentTimeMillis(); // String filename = "B:/rdavm/ds083.2/grib1/ds083.2_Aggregation-grib1.ncx4"; String filename = TestDir.cdmUnitTestDir + "gribCollections/gfs_2p5deg/gfs_2p5deg.ncx4"; try (GridDataset gds = GridDataset.open(filename)) { GridDatatype gdt = gds.findGridByName("TwoD/Latent_heat_net_flux_surface_Mixed_intervals_Average"); assert gdt != null; int n = 5; int first = 17; double sum = 0; for (int time = first; time < first + n; time++) { Array data = gdt.readDataSlice(0, -0, time, 0, -1, -1); sum += MAMath.sumDouble(data); } System.out.printf("sum = %s%n", sum); long took = System.currentTimeMillis() - start; float r = ((float) took) / n; System.out.printf("%n that took %d secs total, %d records %f msecs per record%n", took / 1000, n, r); } }
@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); } }
public void problem() throws IOException { long start = System.currentTimeMillis(); // String filename = "B:/rdavm/ds083.2/grib1/ds083.2_Aggregation-grib1.ncx4"; String filename = TestDir.cdmUnitTestDir + "gribCollections/gfs_2p5deg/gfs_2p5deg.ncx4"; try (GridDataset gds = GridDataset.open(filename)) { GridDatatype gdt = gds.findGridByName("TwoD/Latent_heat_net_flux_surface_Mixed_intervals_Average"); assert gdt != null; int n = 22; int first = 23; double sum = 0; for (int time=first; time < first+n; time++) { Array data = gdt.readDataSlice(0, -0, time, 0, -1, -1); sum += MAMath.sumDouble(data); } System.out.printf("sum = %s%n", sum); long took = System.currentTimeMillis() - start; float r = ((float) took) / n; System.out.printf("%n that took %d secs total, %d records %f msecs per record%n", took / 1000, n, r); } }
private void setMeanAzi(String aziName, int swpNumber) { Array aziData = null; if (getType() != null) { try { Array data = ds.findVariable(aziName).read(); int [] aziOrigin = new int[2]; aziOrigin[0] = swpNumber; aziOrigin[1] = 0; //shape[1] - getRadialNumber(); int [] aziShape = {1, getRadialNumber()}; aziData = data.section(aziOrigin, aziShape); meanAzimuth = MAMath.sumDouble( aziData) / aziData.getSize(); } catch (IOException e) { e.printStackTrace(); meanAzimuth = 0.0; } catch (ucar.ma2.InvalidRangeException e) { e.printStackTrace(); } } else meanAzimuth = 0.0; }
private void setMeanAzi(String aziName, int swpNumber) { Array aziData = null; if (getType() != null) { try { Array data = ds.findVariable(aziName).read(); int [] aziOrigin = new int[2]; aziOrigin[0] = swpNumber; aziOrigin[1] = 0; //shape[1] - getRadialNumber(); int [] aziShape = {1, getRadialNumber()}; aziData = data.section(aziOrigin, aziShape); meanAzimuth = MAMath.sumDouble( aziData) / aziData.getSize(); } catch (IOException e) { e.printStackTrace(); meanAzimuth = 0.0; } catch (ucar.ma2.InvalidRangeException e) { e.printStackTrace(); } } else meanAzimuth = 0.0; }
private void setMeanAzi(String aziName, int swpNumber) { if (getType() != null) { try { Array data = ds.findVariable(aziName).read(); int [] aziOrigin = new int[2]; aziOrigin[0] = swpNumber; aziOrigin[1] = 0; //shape[1] - getRadialNumber(); int [] aziShape = {1, getRadialNumber()}; Array aziData = data.section(aziOrigin, aziShape); meanAzimuth = MAMath.sumDouble( aziData) / aziData.getSize(); } catch (IOException e) { e.printStackTrace(); meanAzimuth = 0.0; } catch (ucar.ma2.InvalidRangeException e) { e.printStackTrace(); } } else { meanAzimuth = 0.0; } }
private void setMeanAzi(String aziName, int swpNumber) { Array aziData = null; if (getType() != null) { try { Array data = ds.findVariable(aziName).read(); int [] aziOrigin = new int[2]; aziOrigin[0] = swpNumber; aziOrigin[1] = 0; //shape[1] - getRadialNumber(); int [] aziShape = {1, getRadialNumber()}; aziData = data.section(aziOrigin, aziShape); meanAzimuth = MAMath.sumDouble( aziData) / aziData.getSize(); } catch (IOException e) { e.printStackTrace(); meanAzimuth = 0.0; } catch (ucar.ma2.InvalidRangeException e) { e.printStackTrace(); } } else meanAzimuth = 0.0; }
private void setMeanAzi(String aziName, int swpNumber) { if (getType() != null) { try { Array data = ds.findVariable(aziName).read(); int [] aziOrigin = new int[2]; aziOrigin[0] = swpNumber; aziOrigin[1] = 0; //shape[1] - getRadialNumber(); int [] aziShape = {1, getRadialNumber()}; Array aziData = data.section(aziOrigin, aziShape); meanAzimuth = MAMath.sumDouble( aziData) / aziData.getSize(); } catch (IOException e) { e.printStackTrace(); meanAzimuth = 0.0; } catch (ucar.ma2.InvalidRangeException e) { e.printStackTrace(); } } else { meanAzimuth = 0.0; } }
private void setMeanAzi(String aziName, int swpNumber) { Array aziData = null; if (getType() != null) { try { Array data = ds.findVariable(aziName).read(); int [] aziOrigin = new int[2]; aziOrigin[0] = swpNumber; aziOrigin[1] = 0; //shape[1] - getRadialNumber(); int [] aziShape = {1, getRadialNumber()}; aziData = data.section(aziOrigin, aziShape); meanAzimuth = MAMath.sumDouble( aziData) / aziData.getSize(); } catch (IOException e) { e.printStackTrace(); meanAzimuth = 0.0; } catch (ucar.ma2.InvalidRangeException e) { e.printStackTrace(); } } else meanAzimuth = 0.0; }
@Test public void testSectionIterator() throws InvalidRangeException, IOException { Array data = A; Section section = new Section("1,:,:"); Array datasection = data.sectionNoReduce(section.getRanges()); double sum = MAMath.sumDouble(datasection); assert sum == 663.0; }