Java Code Examples for ucar.ma2.Array#reduce()

The following examples show how to use ucar.ma2.Array#reduce() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WRFEta.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Get the 1D vertical coordinate array for this time step and point
 * 
 * @param timeIndex the time index. Ignored if !isTimeDependent().
 * @param xIndex the x index
 * @param yIndex the y index
 * @return vertical coordinate array
 * @throws java.io.IOException problem reading data
 * @throws ucar.ma2.InvalidRangeException _more_
 */
public D1 getCoordinateArray1D(int timeIndex, int xIndex, int yIndex) throws IOException, InvalidRangeException {
  ArrayDouble.D3 data = getCoordinateArray(timeIndex);

  int[] origin = new int[3];
  int[] shape = new int[3];

  origin[0] = 0;
  origin[1] = yIndex;
  origin[2] = xIndex;

  shape[0] = data.getShape()[0];
  shape[1] = 1;
  shape[2] = 1;

  Array tmp = data.section(origin, shape);
  return (ArrayDouble.D1) tmp.reduce();
}
 
Example 2
Source File: WRFConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private Array convertToDegrees(Variable.Builder<?> vb) {
  VariableDS.Builder<?> vds = (VariableDS.Builder<?>) vb;
  Variable v = vds.orgVar;
  Array data;
  try {
    data = v.read();
    data = data.reduce();
  } catch (IOException ioe) {
    throw new RuntimeException("data read failed on " + v.getFullName() + "=" + ioe.getMessage());
  }
  IndexIterator ii = data.getIndexIterator();
  while (ii.hasNext()) {
    ii.setDoubleCurrent(Math.toDegrees(ii.getDoubleNext()));
  }
  return data;
}
 
Example 3
Source File: ReduceReader.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Array reallyRead(Variable client, CancelTask cancelTask) throws IOException {
  Array data = orgClient._read();

  for (int i = dims.size() - 1; i >= 0; i--)
    data = data.reduce(dims.get(i)); // highest first
  return data;
}
 
Example 4
Source File: ReduceReader.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Array reallyRead(Variable client, Section section, CancelTask cancelTask)
    throws IOException, InvalidRangeException {
  Section.Builder orgSection = Section.builder().appendRanges(section.getRanges());
  for (int dim : dims) {
    orgSection.insertRange(dim, Range.ONE); // lowest first
  }

  Array data = orgClient._read(orgSection.build());
  for (int i = dims.size() - 1; i >= 0; i--)
    data = data.reduce(dims.get(i)); // highest first

  return data;
}
 
Example 5
Source File: VerticalTransformSubset.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * Get the 1D vertical coordinate array for this time step and point
 * 
 * @param timeIndex the time index. Ignored if !isTimeDependent().
 * @param xIndex the x index
 * @param yIndex the y index
 * @return vertical coordinate array
 * @throws java.io.IOException problem reading data
 * @throws ucar.ma2.InvalidRangeException _more_
 */
public D1 getCoordinateArray1D(int timeIndex, int xIndex, int yIndex) throws IOException, InvalidRangeException {


  ArrayDouble.D3 data = original.getCoordinateArray(timeIndex);

  int[] origin = new int[3];
  int[] shape = new int[3];

  shape[0] = subsetList.get(0).length();
  shape[1] = 1;
  shape[2] = 1;

  origin[0] = timeIndex;
  if (isTimeDependent() && (t_range != null)) {
    origin[0] = t_range.element(timeIndex);
  }

  origin[1] = yIndex;
  origin[2] = xIndex;

  Array section = data.section(origin, shape);

  return (ArrayDouble.D1) section.reduce();


}