Java Code Examples for ucar.nc2.dataset.CoordinateAxis#Builder

The following examples show how to use ucar.nc2.dataset.CoordinateAxis#Builder . 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: HdfEosModisConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private boolean addTimeCoordinate() {
  // add time coordinate by parsing the filename, of course.
  CalendarDate cd = parseFilenameForDate(datasetBuilder.orgFile.getLocation());
  if (cd == null) {
    return false;
  }

  rootGroup.addAttribute(new Attribute("_MODIS_Date", cd.toString()));

  // add the time dimension
  rootGroup.addDimension(new Dimension(TIME_NAME, 1));

  // add the coordinate variable
  String units = "seconds since " + cd;
  CoordinateAxis.Builder timeCoord = CoordinateAxis1D.builder().setName(TIME_NAME).setDataType(DataType.DOUBLE)
      .setParentGroupBuilder(rootGroup).setDimensionsByName("").setUnits(units).setDesc("time coordinate");
  timeCoord.setAutoGen(0, 0);
  timeCoord.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Time.toString()));
  datasetBuilder.replaceCoordinateAxis(rootGroup, timeCoord);

  return true;
}
 
Example 2
Source File: AWIPSConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private CoordinateAxis.Builder makeLatCoordAxis(int n, String name) {
  double min = findAttributeDouble("yMin");
  double max = findAttributeDouble("yMax");
  double d = findAttributeDouble("dy");
  if (Double.isNaN(min) || Double.isNaN(max) || Double.isNaN(d))
    return null;

  CoordinateAxis1D.Builder v = CoordinateAxis1D.builder().setName(name).setDataType(DataType.DOUBLE)
      .setParentGroupBuilder(rootGroup).setDimensionsByName(name).setUnits(CDM.LAT_UNITS).setDesc("latitude");
  v.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Lat.toString()));
  v.setAutoGen(min, d);

  double maxCalc = min + d * n;
  parseInfo.format("Created Lat Coordinate Axis (max calc= %f should be = %f)%n", maxCalc, max);
  return v;
}
 
Example 3
Source File: CoordinatesHelper.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
String makeCanonicalName(VariableDS.Builder<?> vb, String axesNames) {
  Preconditions.checkNotNull(axesNames);
  List<CoordinateAxis.Builder> axes = new ArrayList<>();
  StringTokenizer stoker = new StringTokenizer(axesNames);
  while (stoker.hasMoreTokens()) {
    String vname = stoker.nextToken();
    Optional<CoordinateAxis.Builder> vbOpt = findAxisByFullName(vname);
    if (!vbOpt.isPresent()) {
      vbOpt = findAxisByVerticalSearch(vb, vname);
    }
    if (vbOpt.isPresent()) {
      axes.add(vbOpt.get());
    } else {
      // TODO this should fail, leaving it here to match current behavior.
      log.warn("No axis named {}", vname);
      // throw new IllegalArgumentException("Cant find axis " + vname);
    }
  }
  return makeCanonicalName(axes);
}
 
Example 4
Source File: CoordSystemBuilder.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Does this axis "fit" this variable. True if all of the dimensions in the axis also appear in
 * the variable. If char variable, last dimension is left out.
 *
 * @param axis check if this axis is ok for the given variable
 * @param vp the given variable
 * @return true if all of the dimensions in the axis also appear in the variable.
 */
protected boolean isCoordinateAxisForVariable(CoordinateAxis.Builder<?> axis, VarProcess vp) {
  ImmutableList<Dimension> varDims = vp.vb.getDimensions();
  ImmutableList<Dimension> axisDims = axis.getDimensions();

  // a CHAR variable must really be a STRING, so leave out the last (string length) dimension
  int checkDims = axisDims.size();
  if (axis.dataType == DataType.CHAR)
    checkDims--;

  for (int i = 0; i < checkDims; i++) {
    Dimension axisDim = axisDims.get(i);
    if (!varDims.contains(axisDim)) {
      return false;
    }
  }
  return true;
}
 
Example 5
Source File: ADASConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void makeCoordAxis(String axisName) throws IOException {
  String name = axisName + "_stag";
  if (!rootGroup.findVariableLocal(name).isPresent()) {
    return;
  }
  VariableDS.Builder stagV = (VariableDS.Builder) rootGroup.findVariableLocal(name).get();
  Array data_stag = stagV.orgVar.read();
  int n = (int) data_stag.getSize() - 1;
  DataType dt = DataType.getType(data_stag);
  Array data = Array.factory(dt, new int[] {n});
  Index stagIndex = data_stag.getIndex();
  Index dataIndex = data.getIndex();
  for (int i = 0; i < n; i++) {
    double val = data_stag.getDouble(stagIndex.set(i)) + data_stag.getDouble(stagIndex.set(i + 1));
    data.setDouble(dataIndex.set(i), 0.5 * val);
  }

  DataType dtype = DataType.getType(data);
  String units = stagV.getAttributeContainer().findAttributeString(CDM.UNITS, "m");
  CoordinateAxis.Builder cb = CoordinateAxis1D.builder().setName(axisName).setDataType(dtype)
      .setParentGroupBuilder(rootGroup).setDimensionsByName(axisName).setUnits(units)
      .setDesc("synthesized non-staggered " + axisName + " coordinate");
  cb.setCachedData(data, true);
  datasetBuilder.replaceCoordinateAxis(rootGroup, cb);
}
 
Example 6
Source File: CoordinatesHelper.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public Optional<CoordinateAxis.Builder> findAxisByType(CoordinateSystem.Builder csys, AxisType type) {
  for (CoordinateAxis.Builder<?> axis : getAxesForSystem(csys)) {
    if (axis.axisType == type) {
      return Optional.of(axis);
    }
  }
  return Optional.empty();
}
 
Example 7
Source File: CoordinatesHelper.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public Builder addCoordinateAxis(CoordinateAxis.Builder axis) {
  if (axis == null) {
    return this;
  }
  coordAxes.add(axis);
  return this;
}
 
Example 8
Source File: CoordinatesHelper.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private boolean containsAxisTypes(List<CoordinateAxis.Builder<?>> axes, AxisType want) {
  for (CoordinateAxis.Builder axis : axes) {
    if (axis.axisType == want)
      return true;
  }
  return false;
}
 
Example 9
Source File: HdfEosOmiConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private CoordinateAxis.Builder makeLonCoordAxis(Group.Builder g2, int n, String dimName) {
  CoordinateAxis.Builder v = CoordinateAxis1D.builder().setName("lon").setDataType(DataType.FLOAT)
      .setParentGroupBuilder(g2).setDimensionsByName(dimName).setUnits(CDM.LON_UNITS).setDesc("longitude");

  double incr = 360.0 / n;
  v.setAutoGen(-180.0 + 0.5 * incr, incr);
  v.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Lon.toString()));
  return v;
}
 
Example 10
Source File: HdfEosModisConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private CoordinateAxis.Builder makeCoordAxis(Group.Builder dataG, String name, int n, double start, double end,
    boolean isX) {
  CoordinateAxis.Builder vb =
      CoordinateAxis1D.builder().setName(name).setDataType(DataType.DOUBLE).setParentGroupBuilder(dataG)
          .setDimensionsByName(name).setUnits("km").setDesc(isX ? "x coordinate" : "y coordinate");

  double incr = (end - start) / n;
  vb.setAutoGen(start * .001, incr * .001); // km
  vb.addAttribute(new Attribute(_Coordinate.AxisType, isX ? AxisType.GeoX.name() : AxisType.GeoY.name()));
  return vb;
}
 
Example 11
Source File: CoordinatesHelper.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private List<CoordinateAxis.Builder<?>> getAxesForSystem(CoordinateSystem.Builder cs) {
  Preconditions.checkNotNull(cs);
  List<CoordinateAxis.Builder<?>> axes = new ArrayList<>();
  StringTokenizer stoker = new StringTokenizer(cs.coordAxesNames);
  while (stoker.hasMoreTokens()) {
    String vname = stoker.nextToken();
    Optional<CoordinateAxis.Builder> vbOpt = findAxisByFullName(vname);
    if (vbOpt.isPresent()) {
      axes.add(vbOpt.get());
    } else {
      throw new IllegalArgumentException("Cant find axis " + vname);
    }
  }
  return axes;
}
 
Example 12
Source File: AWIPSSatConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private CoordinateAxis.Builder makeLonCoordAxis(String xname) {
  CoordinateAxis1D.Builder v = CoordinateAxis1D.builder().setName(xname).setDataType(DataType.DOUBLE)
      .setParentGroupBuilder(rootGroup).setDimensionsByName(xname).setUnits(CDM.LON_UNITS).setDesc("longitude");
  v.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Lon.toString()));
  v.setAutoGen(startx, dx);

  parseInfo.format("Created Lon Coordinate Axis = %s%n", xname);
  return v;
}
 
Example 13
Source File: AWIPSSatConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private CoordinateAxis.Builder makeLatCoordAxis(String yname) {
  CoordinateAxis1D.Builder v = CoordinateAxis1D.builder().setName(yname).setDataType(DataType.DOUBLE)
      .setParentGroupBuilder(rootGroup).setDimensionsByName(yname).setUnits(CDM.LAT_UNITS).setDesc("latitude");
  v.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Lat.toString()));
  v.setAutoGen(starty, dy);
  parseInfo.format("Created Lat Coordinate Axis = %s%n", yname);
  return v;
}
 
Example 14
Source File: AWIPSConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private String getZisPositive(CoordinateAxis.Builder v) {
  String attValue = v.getAttributeContainer().findAttributeString("positive", null);
  if (null != attValue) {
    return attValue.equalsIgnoreCase("up") ? "up" : "down";
  }

  String unit = v.getUnits();
  if ((unit != null) && SimpleUnit.isCompatible("millibar", unit))
    return "down";
  if ((unit != null) && SimpleUnit.isCompatible("m", unit))
    return "up";

  // dunno
  return null;
}
 
Example 15
Source File: CoordinatesHelper.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public int compare(CoordinateAxis.Builder c1, CoordinateAxis.Builder c2) {
  AxisType t1 = c1.axisType;
  AxisType t2 = c2.axisType;

  if ((t1 == null) && (t2 == null))
    return c1.getFullName().compareTo(c2.getFullName());
  if (t1 == null)
    return -1;
  if (t2 == null)
    return 1;

  return t1.axisOrder() - t2.axisOrder();
}
 
Example 16
Source File: AWIPSConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
CoordinateAxis.Builder makeYCoordAxis(String yname) {
  CoordinateAxis1D.Builder v = CoordinateAxis1D.builder().setName(yname).setDataType(DataType.DOUBLE)
      .setParentGroupBuilder(rootGroup).setDimensionsByName(yname).setUnits("km").setDesc("y on projection");
  v.setAutoGen(starty, dy);

  parseInfo.format("Created Y Coordinate Axis = %s%n", yname);
  return v;
}
 
Example 17
Source File: CoordinatesHelper.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public boolean containsAxisTypes(CoordinateSystem.Builder cs, List<AxisType> axisTypes) {
  Preconditions.checkNotNull(cs);
  Preconditions.checkNotNull(axisTypes);
  List<CoordinateAxis.Builder<?>> csAxes = getAxesForSystem(cs);
  for (AxisType axisType : axisTypes) {
    if (!containsAxisTypes(csAxes, axisType))
      return false;
  }
  return true;
}
 
Example 18
Source File: CoordinatesHelper.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public boolean replaceCoordinateAxis(CoordinateAxis.Builder<?> axis) {
  Optional<CoordinateAxis.Builder> want = findAxisByFullName(axis.getFullName());
  want.ifPresent(v -> coordAxes.remove(v));
  addCoordinateAxis(axis);
  return want.isPresent();
}
 
Example 19
Source File: CoordinatesHelper.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private Optional<CoordinateAxis.Builder> findAxisByFullName(String fullName) {
  return coordAxes.stream().filter(axis -> axis.getFullName().equals(fullName)).findFirst();
}
 
Example 20
Source File: CoordinatesHelper.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public boolean containsAxes(CoordinateSystem.Builder cs, List<CoordinateAxis.Builder> dataAxes) {
  Preconditions.checkNotNull(cs);
  Preconditions.checkNotNull(dataAxes);
  List<CoordinateAxis.Builder<?>> csAxes = getAxesForSystem(cs);
  return csAxes.containsAll(dataAxes);
}