ucar.ma2.ArrayDouble Java Examples

The following examples show how to use ucar.ma2.ArrayDouble. 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: AtmosSigma.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Get the 3D vertical coordinate array for this time step.
 *
 * @param timeIndex the time index. Ignored if !isTimeDependent().
 * @return vertical coordinate array
 * @throws IOException problem reading data
 * @throws InvalidRangeException _more_
 */
public ArrayDouble.D3 getCoordinateArray(int timeIndex) throws IOException, InvalidRangeException {
  Array ps = readArray(psVar, timeIndex);
  Index psIndex = ps.getIndex();

  int nz = sigma.length;
  int[] shape2D = ps.getShape();
  int ny = shape2D[0];
  int nx = shape2D[1];

  ArrayDouble.D3 result = new ArrayDouble.D3(nz, ny, nx);

  for (int y = 0; y < ny; y++) {
    for (int x = 0; x < nx; x++) {
      double psVal = ps.getDouble(psIndex.set(y, x));
      for (int z = 0; z < nz; z++) {
        result.set(z, y, x, ptop + sigma[z] * (psVal - ptop));
      }
    }
  }

  return result;
}
 
Example #3
Source File: AtmosSigma.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
 * 
 * (needds test!!!)
 * 
 * @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 {

  Array ps = readArray(psVar, timeIndex);
  Index psIndex = ps.getIndex();
  int nz = sigma.length;
  ArrayDouble.D1 result = new ArrayDouble.D1(nz);

  double psVal = ps.getDouble(psIndex.set(yIndex, xIndex));
  for (int z = 0; z < nz; z++) {
    result.set(z, ptop + sigma[z] * (psVal - ptop));
  }

  return result;

}
 
Example #4
Source File: FmrcDataset.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private VariableDS makeOffsetCoordinate(NetcdfDataset result, Group group, String dimName, CalendarDate base,
    double[] values) {
  DataType dtype = DataType.DOUBLE;
  VariableDS timeVar = new VariableDS(result, group, null, dimName + "_offset", dtype, dimName, null, null); // LOOK
                                                                                                             // could
                                                                                                             // just
                                                                                                             // make a
                                                                                                             // CoordinateAxis1D
  timeVar.addAttribute(new Attribute(CDM.LONG_NAME, "offset hour from start of run for coordinate = " + dimName));
  timeVar.addAttribute(new ucar.nc2.Attribute("standard_name", "forecast_period"));
  timeVar.addAttribute(new ucar.nc2.Attribute(CF.CALENDAR, base.getCalendar().name()));
  timeVar.addAttribute(new ucar.nc2.Attribute(CDM.UNITS, "hours since " + base));
  timeVar.addAttribute(new ucar.nc2.Attribute(CDM.MISSING_VALUE, Double.NaN));

  // construct the values
  int ntimes = values.length;
  ArrayDouble.D1 timeCoordVals = (ArrayDouble.D1) Array.factory(DataType.DOUBLE, new int[] {ntimes}, values);
  timeVar.setCachedData(timeCoordVals);
  group.addVariable(timeVar);

  return timeVar;
}
 
Example #5
Source File: WriterCFPointDataset.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private int writeCoordinates(double lat, double lon, double alt, Date time) {
  int count = 0;

  // time
  ArrayDouble.D0 tdata = new ArrayDouble.D0();
  double secs = (double) (time.getTime() / 1000.);
  tdata.set(secs);
  Variable v = recordVars.get(count++);
  v.setCachedData(tdata, false);

  // lat
  ArrayDouble.D0 latData = new ArrayDouble.D0();
  latData.set(lat);
  v = recordVars.get(count++);
  v.setCachedData(latData, false);

  // lon
  ArrayDouble.D0 lonData = new ArrayDouble.D0();
  lonData.set(lon);
  v = recordVars.get(count++);
  v.setCachedData(lonData, false);

  // alt
  if (useAlt) {
    ArrayDouble.D0 altData = new ArrayDouble.D0();
    altData.set(alt);
    v = recordVars.get(count++);
    v.setCachedData(altData, false);
  }

  return count;
}
 
Example #6
Source File: VerticalTransformSubset.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public ArrayDouble.D3 getCoordinateArray(int subsetIndex) throws IOException, InvalidRangeException {
  int orgIndex = subsetIndex;
  if (isTimeDependent() && (t_range != null)) {
    orgIndex = t_range.element(subsetIndex);
  }

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

  return (ArrayDouble.D3) data.sectionNoReduce(subsetList);
}
 
Example #7
Source File: TestDtWithCoverageReadingP.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static void readAllRuntimes(Coverage cover, GridDatatype dt, CoordinateAxis1DTime runtimeAxis,
    CoordinateAxis1D ensAxis, CoordinateAxis1D vertAxis) {
  GridCoordSystem csys = dt.getCoordinateSystem();
  CoordinateAxis1DTime timeAxis1D = csys.getTimeAxis1D();
  CoordinateAxis timeAxis = csys.getTimeAxis();
  CoordinateAxis2D timeAxis2D = (timeAxis instanceof CoordinateAxis2D) ? (CoordinateAxis2D) timeAxis : null;

  if (runtimeAxis == null)
    readAllTimes1D(cover, dt, null, -1, timeAxis1D, ensAxis, vertAxis);

  else if (timeAxis2D == null) { // 1D time or no time
    for (int i = 0; i < runtimeAxis.getSize(); i++)
      readAllTimes1D(cover, dt, runtimeAxis.getCalendarDate(i), i, timeAxis1D, ensAxis, vertAxis);

  } else { // 2D time
    TimeHelper helper = TimeHelper.factory(timeAxis.getUnitsString(), timeAxis.attributes());

    if (timeAxis2D.isInterval()) {
      ArrayDouble.D3 bounds = timeAxis2D.getCoordBoundsArray();
      for (int i = 0; i < runtimeAxis.getSize(); i++)
        readAllTimes2D(cover, dt, runtimeAxis.getCalendarDate(i), i, helper, bounds.slice(0, i), ensAxis, vertAxis);

    } else {
      ArrayDouble.D2 coords = timeAxis2D.getCoordValuesArray();
      for (int i = 0; i < runtimeAxis.getSize(); i++)
        readAllTimes2D(cover, dt, runtimeAxis.getCalendarDate(i), i, helper, coords.slice(0, i), ensAxis, vertAxis);
    }
  }
}
 
Example #8
Source File: FmrcDataset.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private VariableDS makeRunTimeCoordinate(NetcdfDataset result, Group group, String dimName, CalendarDate base,
    double[] values) {
  DataType dtype = DataType.DOUBLE;
  VariableDS timeVar = new VariableDS(result, group, null, dimName + "_run", dtype, dimName, null, null); // LOOK
                                                                                                          // could
                                                                                                          // just make
                                                                                                          // a
                                                                                                          // CoordinateAxis1D
  timeVar.addAttribute(new Attribute(CDM.LONG_NAME, "run times for coordinate = " + dimName));
  timeVar.addAttribute(new ucar.nc2.Attribute("standard_name", "forecast_reference_time"));
  timeVar.addAttribute(new ucar.nc2.Attribute(CF.CALENDAR, base.getCalendar().name()));
  // timeVar.addAttribute(new ucar.nc2.Attribute(CDM.UNITS, "hours since " + base));
  timeVar.addAttribute(new ucar.nc2.Attribute(CDM.UNITS, "hours since " + base.getTimeUnits()));

  timeVar.addAttribute(new ucar.nc2.Attribute(CDM.MISSING_VALUE, Double.NaN));
  timeVar.addAttribute(new ucar.nc2.Attribute(_Coordinate.AxisType, AxisType.RunTime.toString())); // if theres
                                                                                                   // already a time
                                                                                                   // coord, dont put
                                                                                                   // in coordSys -
                                                                                                   // too complicated

  // construct the values
  int ntimes = values.length;
  ArrayDouble.D1 timeCoordVals = (ArrayDouble.D1) Array.factory(DataType.DOUBLE, new int[] {ntimes}, values);
  timeVar.setCachedData(timeCoordVals);
  group.addVariable(timeVar);

  return timeVar;
}
 
Example #9
Source File: M3IOConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void makeZCoordAxis(String dimName, String levelsName, String unitName) {
  Dimension dimz = rootGroup.findDimension(dimName).get();
  int nz = dimz.getLength();
  ArrayDouble.D1 dataLev = new ArrayDouble.D1(nz);
  ArrayDouble.D1 dataLayers = new ArrayDouble.D1(nz + 1);

  // layer values are a numeric global attribute array !!
  Attribute layers = rootGroup.getAttributeContainer().findAttribute(levelsName);
  for (int i = 0; i <= nz; i++)
    dataLayers.set(i, layers.getNumericValue(i).doubleValue());

  for (int i = 0; i < nz; i++) {
    double midpoint = (dataLayers.get(i) + dataLayers.get(i + 1)) / 2;
    dataLev.set(i, midpoint);
  }

  CoordinateAxis.Builder v = CoordinateAxis1D.builder().setName("level").setDataType(DataType.DOUBLE)
      .setParentGroupBuilder(rootGroup).setDimensionsByName(dimName).setUnits(unitName)
      .setDesc("synthesized coordinate from " + levelsName + " global attributes");
  v.setCachedData(dataLev, true);
  v.addAttribute(new Attribute("positive", "down"));
  v.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.GeoZ.toString()));

  // layer edges
  String edge_name = "layer";
  Dimension lay_edge = new Dimension(edge_name, nz + 1);
  rootGroup.addDimension(lay_edge);
  CoordinateAxis.Builder vedge = CoordinateAxis1D.builder().setName(edge_name).setDataType(DataType.DOUBLE)
      .setParentGroupBuilder(rootGroup).setDimensionsByName(edge_name).setUnits(unitName)
      .setDesc("synthesized coordinate from " + levelsName + " global attributes");
  vedge.setCachedData(dataLayers, true);
  v.setBoundary(edge_name);

  datasetBuilder.replaceCoordinateAxis(rootGroup, v);
  datasetBuilder.replaceCoordinateAxis(rootGroup, vedge);
}
 
Example #10
Source File: WRFEta.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Get the 3D vertical coordinate array for this time step.
 *
 * @param timeIndex the time index. Ignored if !isTimeDependent().
 * @return vertical coordinate array
 * @throws IOException problem reading data
 */
public ArrayDouble.D3 getCoordinateArray(int timeIndex) throws IOException {
  ArrayDouble.D3 array;

  Array pertArray = getTimeSlice(pertVar, timeIndex);
  Array baseArray = getTimeSlice(baseVar, timeIndex);

  // ADD: use MAMath?
  // ADD: use IndexIterator from getIndexIteratorFast?
  int[] shape = pertArray.getShape();
  // ADD: assert that rank = 3
  // ADD: assert that both arrays are same shape
  int ni = shape[0];
  int nj = shape[1];
  int nk = shape[2];

  array = new ArrayDouble.D3(ni, nj, nk);
  Index index = array.getIndex();

  for (int i = 0; i < ni; i++) {
    for (int j = 0; j < nj; j++) {
      for (int k = 0; k < nk; k++) {
        index.set(i, j, k);
        double d = pertArray.getDouble(index) + baseArray.getDouble(index);
        if (isZStag) {
          d = d / 9.81; // convert geopotential to height
        }
        array.setDouble(index, d);
      }
    }
  }

  if (isXStag) {
    array = addStagger(array, 2); // assuming x dim index is 2
  }
  if (isYStag) {
    array = addStagger(array, 1); // assuming y dim index is 1
  }

  return array;
}
 
Example #11
Source File: NetcdfDataObject.java    From OpenDA with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Writes all data for the given exchangeItems to the given netcdfFile.
 * Only executed when this.lazyWriting = true
    *
 * @param netcdfFileWriter
 * @param exchangeItems to write.
 */
//TODO remove. This is only used for SWAN state files (see SwanStateNetcdfFileTest.testSwanNetcdfStateFile_1). AK
private void writeData(NetcdfFileWriter netcdfFileWriter, List<IExchangeItem> exchangeItems) {
	for (IExchangeItem exchangeItem : exchangeItems){
		if (exchangeItem.getGeometryInfo() == null){
			//TODO Julius: please remove this hack for SWAN state files. AK
               //TODO: replace this SWAN specific implementation with the above generic ones.
			String exchangeItemId = exchangeItem.getId();
			//TODO: add netcdf writers for various data type / exchangeitems.
			//For SWAN state file, only wave_spectrum is modified and rewritten.
			if (exchangeItemId.equalsIgnoreCase("wave_spectrum")){
				double[] dblValues = exchangeItem.getValuesAsDoubles();
				int my=31;
				int mx=61;
				int wave_frequency=25;
				int wave_direction=18;
				// get dimensions:
				// TODO: in the future, dimensions should be available in the exchangeItem as part of meta data
				// This will avoid having to read the netcdf file for obtaining the dimensions.
				List<Dimension> dimensions = netcdfFileWriter.getNetcdfFile().getDimensions();
				int nDim = dimensions.size();
				for (Dimension dimension : dimensions) {
					if ("my".equalsIgnoreCase(dimension.getShortName())) {
						my = dimension.getLength();
					} else if ("mx".equalsIgnoreCase(dimension.getShortName())) {
						mx = dimension.getLength();
					} else if ("wave_frequency".equalsIgnoreCase(dimension.getShortName())) {
						wave_frequency = dimension.getLength();
					} else if ("wave_direction".equalsIgnoreCase(dimension.getShortName())) {
						wave_direction = dimension.getLength();
					} else {
						continue;
					}
				}
				ArrayDouble.D4 values = new ArrayDouble.D4(my,mx,wave_frequency,wave_direction);
				int iVal = 0;
				for (int iy=0; iy<my; iy++){
					for (int ix=0; ix<mx; ix++){
						for (int iwf=0; iwf<wave_frequency; iwf++){
							for (int iwd=0; iwd<wave_direction; iwd++){
								values.set(iy,ix,iwf,iwd,dblValues[iVal]);
								iVal++;
							}
						}
					}
				}
				try {
					Variable myVar = netcdfFileWriter.findVariable("wave_spectrum");
					netcdfFileWriter.write(myVar,values);
				} catch (IOException | InvalidRangeException e) {
					e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
				}
			}
		}
	}
}
 
Example #12
Source File: WRFConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Nullable
private CoordinateAxis.Builder makeZCoordAxis(String axisName, String dimName) {
  Optional<Dimension> dimOpt = rootGroup.findDimension(dimName);
  if (!dimOpt.isPresent()) {
    return null;
  }
  Dimension dim = dimOpt.get();

  String fromWhere = axisName.endsWith("stag") ? "ZNW" : "ZNU";

  CoordinateAxis.Builder v =
      CoordinateAxis1D.builder().setName(axisName).setDataType(DataType.DOUBLE).setParentGroupBuilder(rootGroup)
          .setDimensionsByName(dim.getShortName()).setUnits("").setDesc("eta values from variable " + fromWhere);
  v.addAttribute(new Attribute(CF.POSITIVE, CF.POSITIVE_DOWN)); // eta coordinate is 1.0 at bottom, 0 at top
  v.setAxisType(AxisType.GeoZ);
  v.addAttribute(new Attribute(_Coordinate.AxisType, "GeoZ"));
  if (!axisName.equals(dim.getShortName()))
    v.addAttribute(new Attribute(_Coordinate.AliasForDimension, dim.getShortName()));

  // create eta values from file variables: ZNU, ZNW
  // But they are a function of time though the values are the same in the sample file
  // NOTE: Use first time sample assuming all are the same!!
  Optional<Variable.Builder<?>> etaVarOpt = rootGroup.findVariableLocal(fromWhere);
  if (!etaVarOpt.isPresent()) {
    return makeFakeCoordAxis(axisName, dim);
  } else {
    VariableDS.Builder<?> etaVarDS = (VariableDS.Builder<?>) etaVarOpt.get();
    Variable etaVar = etaVarDS.orgVar;
    int n = etaVar.getShape(1); // number of eta levels
    int[] origin = {0, 0};
    int[] shape = {1, n};
    try {
      Array array = etaVar.read(origin, shape);// read first time slice
      ArrayDouble.D1 newArray = new ArrayDouble.D1(n);
      IndexIterator it = array.getIndexIterator();
      int count = 0;
      while (it.hasNext()) {
        double d = it.getDoubleNext();
        newArray.set(count++, d);
      }
      v.setCachedData(newArray, true);
    } catch (Exception e) {
      e.printStackTrace();
    } // ADD: error?

    return v;
  }
}
 
Example #13
Source File: CEDRICRadarConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void augmentDataset(NetcdfDataset ncDataset, CancelTask cancelTask) throws IOException {
  /*
   * float lat = 40.45f;
   * float lon = -104.64f;
   * ProjectionImpl projection = new FlatEarth(lat, lon);
   * 
   * Variable ct = new Variable( ncDataset, null, null, projection.getClassName());
   * ct.setDataType( DataType.CHAR);
   * ct.setDimensions( "");
   * 
   * ct.addAttribute( new Attribute("grid_mapping_name", "flat_earth"));
   * ct.addAttribute( new Attribute(_Coordinate.TransformType, "Projection"));
   * ct.addAttribute( new Attribute(_Coordinate.Axes, "GeoX GeoY"));
   * ncDataset.addVariable(null, ct);
   */
  NcMLReader.wrapNcMLresource(ncDataset, CoordSysBuilder.resourcesDir + "CEDRICRadar.ncml", cancelTask);
  Variable lat = ncDataset.findVariable("radar_latitude");
  Variable lon = ncDataset.findVariable("radar_longitude");
  float latv = (float) lat.readScalarDouble();
  float lonv = (float) lon.readScalarDouble();
  Variable pv = ncDataset.findVariable("Projection");
  pv.addAttribute(new Attribute("longitude_of_projection_origin", lonv));
  pv.addAttribute(new Attribute("latitude_of_projection_origin", latv));

  Variable tvar = ncDataset.findVariable("time");
  /*
   * Date dt = null;
   * Variable sdate = ncDataset.findVariable("start_date");
   * Variable stime = ncDataset.findVariable("start_time");
   * String dateStr = sdate.readScalarString();
   * String timeStr = stime.readScalarString();
   * try {
   * dt = DateUtil.parse(dateStr + " " + timeStr);
   * } catch (Exception e) {}
   */

  int nt = 1;

  ArrayDouble.D1 data = new ArrayDouble.D1(nt);

  // fake
  data.setDouble(0, 0);
  // data.setDouble(0, dt.getTime()/1000);

  tvar.setCachedData(data, false);

  super.augmentDataset(ncDataset, cancelTask);
}
 
Example #14
Source File: WRFEta.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Add 1 to the size of the array for the given dimension.
 * Use linear average and interpolation to fill in the values.
 *
 * @param array use this array
 * @param dimIndex use this dimension
 * @return new array with stagger
 */
private ArrayDouble.D3 addStagger(ArrayDouble.D3 array, int dimIndex) {

  // ADD: assert 0<=dimIndex<=2

  int[] shape = array.getShape();
  int[] newShape = new int[3];
  System.arraycopy(shape, 0, newShape, 0, 3);

  newShape[dimIndex]++;
  int ni = newShape[0];
  int nj = newShape[1];
  int nk = newShape[2];
  ArrayDouble.D3 newArray = new ArrayDouble.D3(ni, nj, nk);
  // Index newIndex = newArray.getIndex();

  // extract 1d array to be extended
  int n = shape[dimIndex]; // length of extracted array
  double[] d = new double[n]; // tmp array to hold extracted values
  int[] eshape = new int[3]; // shape of extracted array
  int[] neweshape = new int[3]; // shape of new array slice to write into
  for (int i = 0; i < 3; i++) {
    eshape[i] = (i == dimIndex) ? n : 1;
    neweshape[i] = (i == dimIndex) ? n + 1 : 1;
  }
  int[] origin = new int[3];

  try {
    // loop through the other 2 dimensions and "extrapinterpolate" the other
    for (int i = 0; i < ((dimIndex == 0) ? 1 : ni); i++) {
      for (int j = 0; j < ((dimIndex == 1) ? 1 : nj); j++) {
        for (int k = 0; k < ((dimIndex == 2) ? 1 : nk); k++) {
          origin[0] = i;
          origin[1] = j;
          origin[2] = k;
          IndexIterator it = array.section(origin, eshape).getIndexIterator();
          for (int l = 0; l < n; l++) {
            d[l] = it.getDoubleNext(); // get the original values
          }
          double[] d2 = extrapinterpolate(d); // compute new values
          // define slice of new array to write into
          IndexIterator newit = newArray.section(origin, neweshape).getIndexIterator();
          for (int l = 0; l < n + 1; l++) {
            newit.setDoubleNext(d2[l]);
          }
        }
      }
    }
  } catch (InvalidRangeException e) {
    // ADD: report error?
    return null;
  }

  return newArray;
}
 
Example #15
Source File: TestVerticalTransformWithUnitsConversion.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
private double[] getVertTransformationForPoint(ProjectionPoint point, int timeIndex, GeoGrid grid)
    throws IOException, InvalidRangeException {

  VerticalTransform vt = grid.getCoordinateSystem().getVerticalTransform();
  // System.out.println(vt.isTimeDependent());
  int[] pointIndices = new int[] {0, 0};

  grid.getCoordinateSystem().findXYindexFromCoord(point.getX(), point.getY(), pointIndices);

  ArrayDouble.D1 dataArr = vt.getCoordinateArray1D(timeIndex, pointIndices[0], pointIndices[1]);

  return (double[]) dataArr.copyTo1DJavaArray();
}
 
Example #16
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();


}
 
Example #17
Source File: VerticalTransform.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Get the 1D vertical coordinate array for this time step and
 * the specified X,Y index for Lat-Lon 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_
 */
ArrayDouble.D1 getCoordinateArray1D(int timeIndex, int xIndex, int yIndex) throws IOException, InvalidRangeException;
 
Example #18
Source File: VerticalTransform.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Get the 3D vertical coordinate array for this time step.
 * Must be in "canonical order" : z, y, x.
 *
 * @param timeIndex the time index. Ignored if !isTimeDependent().
 *
 * @return vertical coordinate array
 *
 * @throws java.io.IOException problem reading the data
 * @throws ucar.ma2.InvalidRangeException timeIndex out of bounds
 */
ucar.ma2.ArrayDouble.D3 getCoordinateArray(int timeIndex) throws java.io.IOException, ucar.ma2.InvalidRangeException;