ucar.nc2.constants.AxisType Java Examples

The following examples show how to use ucar.nc2.constants.AxisType. 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: WRFConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private CoordinateAxis makeLonCoordAxis(NetcdfDataset ds, String axisName, Dimension dim) {
  if (dim == null)
    return null;
  double dx = 4 * findAttributeDouble(ds, "DX");
  int nx = dim.getLength();
  double startx = centerX - dx * (nx - 1) / 2;

  CoordinateAxis v = new CoordinateAxis1D(ds, null, axisName, DataType.DOUBLE, dim.getShortName(), "degrees_east",
      "synthesized longitude coordinate");
  v.setValues(nx, startx, dx);
  v.addAttribute(new Attribute(_Coordinate.AxisType, "Lon"));
  if (!axisName.equals(dim.getShortName()))
    v.addAttribute(new Attribute(_Coordinate.AliasForDimension, dim.getShortName()));

  return v;
}
 
Example #2
Source File: DapperDataset.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static PointObsDataset factory(NetcdfDataset ds) throws IOException {
  Variable latVar = null, timeVar = null;

  // identify key variables
  List axes = ds.getCoordinateAxes();
  for (int i = 0; i < axes.size(); i++) {
    CoordinateAxis axis = (CoordinateAxis) axes.get(i);
    if (axis.getAxisType() == AxisType.Lat)
      latVar = axis;
    if (axis.getAxisType() == AxisType.Time)
      timeVar = axis;
  }

  // lat, lon are always in the outer; gotta use name to fetch wrapping variable
  Structure outerSequence = getWrappingParent(ds, latVar);

  // depth may be in inner or outer
  boolean isProfile = getWrappingParent(ds, timeVar) == outerSequence;
  if (isProfile)
    return new DapperPointDataset(ds);
  else
    return new DapperStationDataset(ds);
}
 
Example #3
Source File: M3IOConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected AxisType getAxisType(NetcdfDataset ds, VariableEnhanced ve) {
  Variable v = (Variable) ve;
  String vname = v.getShortName();

  if (vname.equalsIgnoreCase("x"))
    return AxisType.GeoX;

  if (vname.equalsIgnoreCase("y"))
    return AxisType.GeoY;

  if (vname.equalsIgnoreCase("lat"))
    return AxisType.Lat;

  if (vname.equalsIgnoreCase("lon"))
    return AxisType.Lon;

  if (vname.equalsIgnoreCase("time"))
    return AxisType.Time;

  if (vname.equalsIgnoreCase("level"))
    return AxisType.GeoZ;

  return null;
}
 
Example #4
Source File: WRFConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
protected void assignCoordinateTransforms() {
  super.assignCoordinateTransforms();

  if (rootGroup.findVariableLocal("PH").isPresent() && rootGroup.findVariableLocal("PHB").isPresent()
      && rootGroup.findVariableLocal("P").isPresent() && rootGroup.findVariableLocal("PB").isPresent()) {

    // public Optional<CoordinateAxis.Builder> findZAxis(CoordinateSystem.Builder csys) {
    // any cs with a vertical coordinate with no units gets one
    for (CoordinateSystem.Builder cs : coords.coordSys) {
      coords.findAxisByType(cs, AxisType.GeoZ).ifPresent(axis -> {
        String units = axis.getUnits();
        if ((units == null) || (units.trim().isEmpty())) {
          // LOOK each cs might have seperate ct; but they might be identical....
          VerticalCTBuilder vctb = new WRFEtaTransformBuilder(coords, cs);
          coords.addVerticalCTBuilder(vctb);
          cs.addCoordinateTransformByName(vctb.getTransformName());
          parseInfo.format("***Added WRFEtaTransformBuilderto '%s'%n", cs.coordAxesNames);
        }
      });
    }
  }
}
 
Example #5
Source File: CFpointObs.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private TableConfig makeSingle(NetcdfDataset ds, Dimension obsDim, Formatter errlog) {

    Table.Type obsTableType = Table.Type.Structure;
    TableConfig obsTable = new TableConfig(obsTableType, "single");
    obsTable.dimName = obsDim.getShortName();

    obsTable.lat = matchAxisTypeAndDimension(ds, AxisType.Lat, obsDim);
    obsTable.lon = matchAxisTypeAndDimension(ds, AxisType.Lon, obsDim);
    obsTable.elev = matchAxisTypeAndDimension(ds, AxisType.Height, obsDim);
    if (obsTable.elev == null)
      obsTable.elev = matchAxisTypeAndDimension(ds, AxisType.Pressure, obsDim);
    if (obsTable.elev == null)
      obsTable.elev = matchAxisTypeAndDimension(ds, AxisType.GeoZ, obsDim);
    obsTable.time = matchAxisTypeAndDimension(ds, AxisType.Time, obsDim);

    makeStructureInfo(obsTable, ds, null, obsDim);
    return obsTable;
  }
 
Example #6
Source File: WRFConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Nullable
private CoordinateAxis.Builder makeLonCoordAxis(String axisName, Dimension dim) {
  if (dim == null)
    return null;
  double dx = 4 * findAttributeDouble("DX");
  int nx = dim.getLength();
  double startx = centerX - dx * (nx - 1) / 2;

  CoordinateAxis.Builder v = CoordinateAxis1D.builder().setName(axisName).setDataType(DataType.DOUBLE)
      .setDimensionsByName(dim.getShortName()).setUnits("degrees_east").setDesc("synthesized longitude coordinate");
  v.setAutoGen(startx, dx);
  v.setAxisType(AxisType.Lon);
  v.addAttribute(new Attribute(_Coordinate.AxisType, "Lon"));
  if (!axisName.equals(dim.getShortName()))
    v.addAttribute(new Attribute(_Coordinate.AliasForDimension, dim.getShortName()));

  return v;
}
 
Example #7
Source File: GribIosp.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void makeEnsembleCoordinate(NetcdfFile ncfile, Group g, CoordinateEns ec) {
  int n = ec.getSize();
  String ecName = ec.getName().toLowerCase();
  ncfile.addDimension(g, new Dimension(ecName, n));

  Variable v = new Variable(ncfile, g, null, ecName, DataType.INT, ecName);
  ncfile.addVariable(g, v);
  v.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Ensemble.toString()));

  int[] data = new int[n];
  int count = 0;
  for (EnsCoordValue ecc : ec.getEnsSorted()) {
    data[count++] = ecc.getEnsMember();
  }
  v.setCachedData(Array.factory(DataType.INT, new int[] {n}, data));
}
 
Example #8
Source File: WRFConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private CoordinateAxis makeYCoordAxis(NetcdfDataset ds, String axisName, Dimension dim) {
  if (dim == null)
    return null;
  double dy = findAttributeDouble(ds, "DY") / 1000.0;
  int ny = dim.getLength();
  double starty = centerY - dy * (ny - 1) / 2; // - dy/2; // ya just gotta know

  CoordinateAxis v = new CoordinateAxis1D(ds, null, axisName, DataType.DOUBLE, dim.getShortName(), "km",
      "synthesized GeoY coordinate from DY attribute");
  v.setValues(ny, starty, dy);
  v.addAttribute(new Attribute(_Coordinate.AxisType, "GeoY"));
  if (!axisName.equals(dim.getShortName()))
    v.addAttribute(new Attribute(_Coordinate.AliasForDimension, dim.getShortName()));

  if (gridE)
    v.addAttribute(new Attribute(_Coordinate.Stagger, CDM.ARAKAWA_E));
  return v;
}
 
Example #9
Source File: CSMConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void augmentDataset(NetcdfDataset ds, CancelTask cancelTask) throws IOException {
  List<Variable> vars = ds.getVariables();
  for (Variable var : vars) {
    String unit = var.getUnitsString();
    if (unit != null) {
      if (unit.equalsIgnoreCase("hybrid_sigma_pressure") || unit.equalsIgnoreCase("sigma_level")) {
        // both a coordinate axis and transform
        var.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.GeoZ.toString()));
        var.addAttribute(new Attribute(_Coordinate.TransformType, TransformType.Vertical.toString()));
        var.addAttribute(new Attribute(_Coordinate.Axes, var.getFullName()));
      }
    }
  }

}
 
Example #10
Source File: CFpointObs.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private TableConfig makeRaggedIndexChildTable(NetcdfDataset ds, Dimension parentDim, Dimension childDim,
    Variable ragged_parentIndex, Formatter errlog) {
  TableConfig childTable = new TableConfig(Table.Type.ParentIndex, childDim.getShortName());
  childTable.dimName = childDim.getShortName();

  childTable.lat = matchAxisTypeAndDimension(ds, AxisType.Lat, childDim);
  childTable.lon = matchAxisTypeAndDimension(ds, AxisType.Lon, childDim);
  childTable.elev = matchAxisTypeAndDimension(ds, AxisType.Height, childDim);
  if (childTable.elev == null)
    childTable.elev = matchAxisTypeAndDimension(ds, AxisType.Pressure, childDim);
  if (childTable.elev == null)
    childTable.elev = matchAxisTypeAndDimension(ds, AxisType.GeoZ, childDim);
  childTable.time = matchAxisTypeAndDimension(ds, AxisType.Time, childDim);

  makeStructureInfo(childTable, ds, ragged_parentIndex.getParentStructure(), childDim);
  childTable.parentIndex = ragged_parentIndex.getFullName();

  return childTable;
}
 
Example #11
Source File: Time2DCoordSys.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private CoverageCoordAxis makeScalarTimeCoord(double val, CoverageCoordAxis1D runAxisSubset) {
  String name = "constantForecastTime";
  String desc = "forecast time";
  AttributeContainerMutable atts = new AttributeContainerMutable(name);
  atts.addAttribute(new Attribute(CDM.UNITS, runAxisSubset.getUnits()));
  atts.addAttribute(new Attribute(CF.STANDARD_NAME, CF.TIME));
  atts.addAttribute(new Attribute(CDM.LONG_NAME, desc));
  atts.addAttribute(new Attribute(CF.CALENDAR, runAxisSubset.getCalendar().toString()));

  CoverageCoordAxisBuilder builder = new CoverageCoordAxisBuilder(name, runAxisSubset.getUnits(), desc,
      DataType.DOUBLE, AxisType.Time, atts, CoverageCoordAxis.DependenceType.scalar, null,
      CoverageCoordAxis.Spacing.regularPoint, 1, val, val, 0.0, null, null);
  builder.setIsSubset(true);

  return new CoverageCoordAxis1D(builder);
}
 
Example #12
Source File: WRFEtaTransformBuilder.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public VerticalCT makeVerticalCT(NetcdfDataset ds) {
  VerticalCT.Type type = VerticalCT.Type.WRFEta;
  List<Parameter> params = new ArrayList<>();
  params.add(new Parameter("height formula", "height(x,y,z) = (PH(x,y,z) + PHB(x,y,z)) / 9.81"));
  params.add(new Parameter(WRFEta.PerturbationGeopotentialVariable, "PH"));
  params.add(new Parameter(WRFEta.BaseGeopotentialVariable, "PHB"));
  params.add(new Parameter("pressure formula", "pressure(x,y,z) = P(x,y,z) + PB(x,y,z)"));
  params.add(new Parameter(WRFEta.PerturbationPressureVariable, "P"));
  params.add(new Parameter(WRFEta.BasePressureVariable, "PB"));

  if (coords.findAxisByType(cs, AxisType.GeoX).isPresent())
    params.add(new Parameter(WRFEta.IsStaggeredX, "" + isStaggered(AxisType.GeoX)));
  else
    params.add(new Parameter(WRFEta.IsStaggeredX, "" + isStaggered2(AxisType.Lon, 1)));

  if (coords.findAxisByType(cs, AxisType.GeoY).isPresent())
    params.add(new Parameter(WRFEta.IsStaggeredY, "" + isStaggered(AxisType.GeoY)));
  else
    params.add(new Parameter(WRFEta.IsStaggeredY, "" + isStaggered2(AxisType.Lat, 0)));

  params.add(new Parameter(WRFEta.IsStaggeredZ, "" + isStaggered(AxisType.GeoZ)));
  coords.findAxisByType(cs, AxisType.GeoZ).ifPresent(a -> params.add(new Parameter("eta", "" + a.getFullName())));

  return new WRFEtaTransform(getTransformName(), type.toString(), type, params);
}
 
Example #13
Source File: WRFConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Nullable
private CoordinateAxis.Builder makeXCoordAxis(String axisName, String dimName) {
  Optional<Dimension> dimOpt = rootGroup.findDimension(dimName);
  if (!dimOpt.isPresent()) {
    return null;
  }
  Dimension dim = dimOpt.get();
  double dx = findAttributeDouble("DX") / 1000.0; // km ya just gotta know
  int nx = dim.getLength();
  double startx = centerX - dx * (nx - 1) / 2; // ya just gotta know

  CoordinateAxis.Builder v = CoordinateAxis1D.builder().setName(axisName).setDataType(DataType.DOUBLE)
      .setParentGroupBuilder(rootGroup).setDimensionsByName(dim.getShortName()).setUnits("km")
      .setDesc("synthesized GeoX coordinate from DX attribute");
  v.setAutoGen(startx, dx);
  v.setAxisType(AxisType.GeoX);
  v.addAttribute(new Attribute(_Coordinate.AxisType, "GeoX"));
  if (!axisName.equals(dim.getShortName()))
    v.addAttribute(new Attribute(_Coordinate.AliasForDimension, dim.getShortName()));

  if (gridE)
    v.addAttribute(new Attribute(_Coordinate.Stagger, CDM.ARAKAWA_E));
  return v;
}
 
Example #14
Source File: CFGridCoverageWriter.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void addLatLon2D(CoverageCollection subsetDataset, Group.Builder group) {
  HorizCoordSys horizCoordSys = subsetDataset.getHorizCoordSys();
  CoverageCoordAxis1D xAxis = horizCoordSys.getXAxis();
  CoverageCoordAxis1D yAxis = horizCoordSys.getYAxis();

  Dimension xDim = group.findDimension(xAxis.getName())
      .orElseThrow(() -> new IllegalStateException("We should've added X dimension in addDimensions()."));
  Dimension yDim = group.findDimension(yAxis.getName())
      .orElseThrow(() -> new IllegalStateException("We should've added Y dimension in addDimensions()."));

  List<Dimension> dims = Arrays.asList(yDim, xDim);

  Variable.Builder latVar = Variable.builder().setName("lat").setDataType(DataType.DOUBLE).setDimensions(dims);
  latVar.addAttribute(new Attribute(CDM.UNITS, CDM.LAT_UNITS));
  latVar.addAttribute(new Attribute(CF.STANDARD_NAME, CF.LATITUDE));
  latVar.addAttribute(new Attribute(CDM.LONG_NAME, "latitude coordinate"));
  latVar.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Lat.toString()));
  group.addVariable(latVar);

  Variable.Builder lonVar = Variable.builder().setName("lon").setDataType(DataType.DOUBLE).setDimensions(dims);
  lonVar.addAttribute(new Attribute(CDM.UNITS, CDM.LON_UNITS));
  lonVar.addAttribute(new Attribute(CF.STANDARD_NAME, CF.LONGITUDE));
  lonVar.addAttribute(new Attribute(CDM.LONG_NAME, "longitude coordinate"));
  lonVar.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Lon.toString()));
  group.addVariable(lonVar);
}
 
Example #15
Source File: CoordSysBuilder.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Turn the variable into a coordinate axis, if not already. Add to the dataset, replacing variable if needed.
 *
 * @return variable as a coordinate axis
 */
public CoordinateAxis makeIntoCoordinateAxis() {
  if (axis != null)
    return axis;

  // if not a CoordinateAxis, will turn into one
  v = axis = ds.addCoordinateAxis((VariableDS) v);

  if (axisType != null) {
    axis.setAxisType(axisType);
    axis.addAttribute(new Attribute(_Coordinate.AxisType, axisType.toString()));

    if (((axisType == AxisType.Height) || (axisType == AxisType.Pressure) || (axisType == AxisType.GeoZ))
        && (positive != null)) {
      axis.setPositive(positive);
      axis.addAttribute(new Attribute(_Coordinate.ZisPositive, positive));
    }
  }
  return axis;
}
 
Example #16
Source File: AWIPSConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private CoordinateAxis makeLatCoordAxis(NetcdfDataset ds, int n, String xname) {
  double min = findAttributeDouble(ds, "yMin");
  double max = findAttributeDouble(ds, "yMax");
  double d = findAttributeDouble(ds, "dy");
  if (Double.isNaN(min) || Double.isNaN(max) || Double.isNaN(d))
    return null;

  CoordinateAxis v = new CoordinateAxis1D(ds, null, xname, DataType.DOUBLE, xname, CDM.LAT_UNITS, "latitude");
  v.setValues(n, min, d);
  v.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Lat.toString()));

  double maxCalc = min + d * n;
  parseInfo.format("Created Lat Coordinate Axis (max calc= %f should be = %f)%n", maxCalc, max);
  v.getNameAndDimensions(parseInfo, true, false);
  parseInfo.format("%n");

  return v;
}
 
Example #17
Source File: DefaultConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void augmentDataset(NetcdfDataset ds, CancelTask cancelTask) {
  projCT = makeProjectionCT(ds);
  if (projCT != null) {
    VariableDS v = makeCoordinateTransformVariable(ds, projCT);
    ds.addVariable(null, v);

    String xname = findCoordinateName(ds, AxisType.GeoX);
    String yname = findCoordinateName(ds, AxisType.GeoY);
    if (xname != null && yname != null)
      v.addAttribute(new Attribute(_Coordinate.Axes, xname + " " + yname));
  }
  ds.finish();
}
 
Example #18
Source File: TestGribCoverageBuilding.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testBestTimeCoordinates() throws IOException {
  String filename = TestDir.cdmUnitTestDir + "ncss/GFS/CONUS_80km/GFS_CONUS_80km.ncx4";
  String gridName = "Pressure_surface";

  try (FeatureDatasetCoverage cc = CoverageDatasetFactory.open(filename)) {
    Assert.assertNotNull(filename, cc);
    Assert.assertEquals(2, cc.getCoverageCollections().size());
    CoverageCollection cd = cc.findCoverageDataset(FeatureType.GRID);
    Assert.assertNotNull(FeatureType.GRID.toString(), cd);

    Coverage cov = cd.findCoverage(gridName);
    Assert.assertNotNull(gridName, cov);
    CoverageCoordSys csys = cov.getCoordSys();
    Assert.assertNotNull("CoverageCoordSys", csys);

    CoverageCoordAxis time = csys.getAxis(AxisType.Time);
    Assert.assertNotNull(AxisType.Time.toString(), time);
    Assert.assertTrue(time.getClass().getName(), time instanceof CoverageCoordAxis1D);
    Assert.assertEquals(CoverageCoordAxis.Spacing.irregularPoint, time.getSpacing());
    Assert.assertEquals(CoverageCoordAxis.DependenceType.independent, time.getDependenceType());
    Assert.assertEquals(CalendarDate.parseISOformat(null, "2012-02-27T00:00:00Z"), time.makeDate(0));
    Assert2.assertNearlyEquals(6.0, time.getResolution());
    Assert.assertEquals(false, csys.isTime2D(time));

    CoverageCoordAxis runtime = csys.getAxis(AxisType.RunTime);
    Assert.assertNotNull(AxisType.RunTime.toString(), runtime);
    Assert.assertTrue(runtime.getClass().getName(), runtime instanceof CoverageCoordAxis1D);
    Assert.assertEquals(CoverageCoordAxis.Spacing.irregularPoint, runtime.getSpacing());
    Assert.assertEquals(CoverageCoordAxis.DependenceType.dependent, runtime.getDependenceType());
    Assert.assertEquals(CalendarDate.parseISOformat(null, "2012-02-27T00:00:00Z"), runtime.makeDate(0));
  }
}
 
Example #19
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 #20
Source File: CFpointObs.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private TableConfig makeStructTableTestTraj(NetcdfDataset ds, FeatureType ftype, EncodingInfo info,
    Formatter errlog) {
  Table.Type tableType = Table.Type.Structure;
  if (info.encoding == Encoding.single)
    tableType = Table.Type.Top;
  if (info.encoding == Encoding.flat)
    tableType = Table.Type.ParentId;

  String name = (info.parentDim == null) ? " single" : info.parentDim.getShortName();
  TableConfig tableConfig = new TableConfig(tableType, name);
  tableConfig.lat = CoordSysEvaluator.findCoordNameByType(ds, AxisType.Lat);
  tableConfig.lon = CoordSysEvaluator.findCoordNameByType(ds, AxisType.Lon);
  tableConfig.elev = CoordSysEvaluator.findCoordNameByType(ds, AxisType.Height);
  if (tableConfig.elev == null)
    tableConfig.elev = CoordSysEvaluator.findCoordNameByType(ds, AxisType.Pressure);
  if (tableConfig.elev == null)
    tableConfig.elev = CoordSysEvaluator.findCoordNameByType(ds, AxisType.GeoZ);
  tableConfig.time = CoordSysEvaluator.findCoordNameByType(ds, AxisType.Time);
  tableConfig.featureType = ftype;

  if (info.encoding != Encoding.single && info.parentDim != null) {
    tableConfig.dimName = name;
    makeStructureInfo(tableConfig, ds, null, info.parentDim);
  }

  return tableConfig;
}
 
Example #21
Source File: CoordSysEvaluator.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * search for Dimension used by axis of given by Type.
 * 
 * @param ds search in this dataset's "Best" coordinate system.
 * @param atype search for this type of CoordinateAxis. takes the first one it finds.
 * @return the found CoordinateAxis' first Dimension, or null if none or scalar
 */
public static Dimension findDimensionByType(NetcdfDataset ds, AxisType atype) {
  CoordinateAxis axis = findCoordByType(ds, atype);
  if (axis == null)
    return null;
  if (axis.isScalar())
    return null;
  return axis.getDimension(0);
}
 
Example #22
Source File: GDVConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void augmentDataset(NetcdfDataset ds, CancelTask cancelTask) {

    projCT = makeProjectionCT(ds);
    if (projCT != null) {
      VariableDS v = makeCoordinateTransformVariable(ds, projCT);
      ds.addVariable(null, v);

      String xname = findCoordinateName(ds, AxisType.GeoX);
      String yname = findCoordinateName(ds, AxisType.GeoY);
      if (xname != null && yname != null)
        v.addAttribute(new Attribute(_Coordinate.Axes, xname + " " + yname));
    }

    ds.finish();
  }
 
Example #23
Source File: WRFConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private CoordinateAxis makeZCoordAxis(NetcdfDataset ds, String axisName, Dimension dim) {
  if (dim == null)
    return null;

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

  CoordinateAxis v = new CoordinateAxis1D(ds, null, axisName, DataType.DOUBLE, dim.getShortName(), "",
      "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.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!
  Variable etaVar = ds.findVariable(fromWhere);
  if (etaVar == null)
    return makeFakeCoordAxis(ds, axisName, dim);

  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 #24
Source File: CdmrfReader.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static AxisType convertAxisType(CdmrFeatureProto.AxisType dtype) {
  switch (dtype) {
    case RunTime:
      return AxisType.RunTime;
    case Ensemble:
      return AxisType.Ensemble;
    case Time:
      return AxisType.Time;
    case GeoX:
      return AxisType.GeoX;
    case GeoY:
      return AxisType.GeoY;
    case GeoZ:
      return AxisType.GeoZ;
    case Lat:
      return AxisType.Lat;
    case Lon:
      return AxisType.Lon;
    case Height:
      return AxisType.Height;
    case Pressure:
      return AxisType.Pressure;
    case RadialAzimuth:
      return AxisType.RadialAzimuth;
    case RadialDistance:
      return AxisType.RadialDistance;
    case RadialElevation:
      return AxisType.RadialElevation;
    case Spectral:
      return AxisType.Spectral;
    case TimeOffset:
      return AxisType.TimeOffset;
  }
  throw new IllegalStateException("illegal data type " + dtype);
}
 
Example #25
Source File: CFpointObs.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private TableConfig makeStructTable(NetcdfDataset ds, FeatureType ftype, EncodingInfo info, Formatter errlog) {
  Table.Type tableType = Table.Type.Structure;
  if (info.encoding == Encoding.single)
    tableType = Table.Type.Top;
  if (info.encoding == Encoding.flat)
    tableType = Table.Type.ParentId;

  String name = (info.parentDim == null) ? " single" : info.parentDim.getShortName();
  TableConfig tableConfig = new TableConfig(tableType, name);
  tableConfig.lat = matchAxisTypeAndDimension(ds, AxisType.Lat, info.parentDim);
  tableConfig.lon = matchAxisTypeAndDimension(ds, AxisType.Lon, info.parentDim);
  tableConfig.elev = matchAxisTypeAndDimension(ds, AxisType.Height, info.parentDim);
  if (tableConfig.elev == null)
    tableConfig.elev = matchAxisTypeAndDimension(ds, AxisType.Pressure, info.parentDim);
  if (tableConfig.elev == null)
    tableConfig.elev = matchAxisTypeAndDimension(ds, AxisType.GeoZ, info.parentDim);
  tableConfig.time = matchAxisTypeAndDimension(ds, AxisType.Time, info.parentDim);
  tableConfig.featureType = ftype;

  if (info.encoding != Encoding.single && info.parentDim != null) {
    tableConfig.dimName = name;
    Structure parent = info.parentStruct;
    if (parent == null) {
      switch (info.encoding) {
        case raggedContiguous:
          parent = info.ragged_rowSize.getParentStructure();
          break;
        case raggedIndex:
          parent = info.ragged_parentIndex.getParentStructure();
          break;
      }
    }
    makeStructureInfo(tableConfig, ds, parent, info.parentDim);
  }

  return tableConfig;
}
 
Example #26
Source File: TestWcsServer.java    From tds with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testVert() throws IOException {
  String endpoint = TestOnLocalServer.withHttpPath(
      dataset1 + "&request=GetCoverage&COVERAGE=Temperature&TIME=2012-04-19T00:00:00Z&FORMAT=NetCDF3&vertical=800");
  byte[] content = TestOnLocalServer.getContent(endpoint, 200, null);

  // Open the binary response in memory
  try (NetcdfFile nf = NetcdfFiles.openInMemory("test_data.nc", content)) {
    DtCoverageDataset dt = getDtCoverageDataset(nf);
    Formatter errlog = new Formatter();
    FeatureDatasetCoverage cdc = DtCoverageAdapter.factory(dt, errlog);
    Assert.assertNotNull(errlog.toString(), cdc);
    Assert.assertEquals(1, cdc.getCoverageCollections().size());
    CoverageCollection cd = cdc.getCoverageCollections().get(0);
    assertNotNull(cd);

    Coverage cov = cd.findCoverage("Temperature");
    assertNotNull("Temperature", cov);

    CoverageCoordSys csys = cov.getCoordSys();
    assertNotNull("csys", csys);

    CoverageCoordAxis1D time = (CoverageCoordAxis1D) csys.getAxis(AxisType.Time);
    assertNotNull("time", time);
    Assert.assertEquals(1, time.getNcoords());
    CalendarDate date = time.makeDate(time.getCoordMidpoint(0));
    logger.debug("date = {}", date);
    Assert.assertEquals(date, CalendarDate.parseISOformat(null, "2012-04-19T00:00:00Z"));

    CoverageCoordAxis1D vert = (CoverageCoordAxis1D) csys.getZAxis();
    assertNotNull("vert", vert);
    Assert.assertEquals(1, vert.getNcoords());
    double vertCoord = vert.getCoordMidpoint(0);
    logger.debug("date = {}", date);
    Assert2.assertNearlyEquals(800.0, vertCoord);
  }
}
 
Example #27
Source File: DtCoverageAdapter.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static CoverageCoordAxis makeCoordAxisFromDimension(Dimension dim) {
  CoverageCoordAxisBuilder builder = new CoverageCoordAxisBuilder();
  builder.name = dim.getFullName();
  builder.dataType = DataType.INT;
  builder.axisType = AxisType.Dimension;
  builder.dependenceType = CoverageCoordAxis.DependenceType.dimension;
  builder.spacing = CoverageCoordAxis.Spacing.regularPoint;
  builder.ncoords = dim.getLength();
  builder.startValue = 0;
  builder.endValue = dim.getLength() - 1;
  builder.resolution = 1;

  return new CoverageCoordAxis1D(builder);
}
 
Example #28
Source File: CoordsSet.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private CoverageCoordAxis1D findDependent(CoverageCoordAxis independentAxis, AxisType axisType) {
  for (CoverageCoordAxis axis : axes) {
    if (axis.getDependenceType() == CoverageCoordAxis.DependenceType.dependent) {
      for (String axisName : axis.dependsOn) {
        if (axisName.equalsIgnoreCase(independentAxis.getName()) && axis.getAxisType() == axisType)
          return (CoverageCoordAxis1D) axis;
      }
    }
  }
  return null;
}
 
Example #29
Source File: HdfEosModisConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private CoordinateAxis.Builder makeLatLonCoordAxis(Group.Builder dataG, int n, double start, double end,
    boolean isLon) {
  String name = isLon ? AxisType.Lon.toString() : AxisType.Lat.toString();
  String dimName = isLon ? DIMX_NAME : DIMY_NAME;

  CoordinateAxis.Builder v = CoordinateAxis1D.builder().setName(name).setDataType(DataType.DOUBLE)
      .setParentGroupBuilder(dataG).setDimensionsByName(dimName).setUnits(isLon ? "degrees_east" : "degrees_north");

  double incr = (end - start) / n;
  v.setAutoGen(start, incr);
  v.addAttribute(new Attribute(_Coordinate.AxisType, name));
  return v;
}
 
Example #30
Source File: AWIPSConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
@Nullable
protected AxisType getAxisType(VariableDS.Builder v) {
  String vname = v.shortName;

  if (vname.equalsIgnoreCase("x"))
    return AxisType.GeoX;
  if (vname.equalsIgnoreCase("lon"))
    return AxisType.Lon;
  if (vname.equalsIgnoreCase("y"))
    return AxisType.GeoY;
  if (vname.equalsIgnoreCase("lat"))
    return AxisType.Lat;
  if (vname.equalsIgnoreCase("record"))
    return AxisType.Time;

  String dimName = v.getFirstDimensionName();
  if ((dimName != null) && dimName.equalsIgnoreCase("record"))
    return AxisType.Time;

  String unit = v.getUnits();
  if (unit != null) {
    if (SimpleUnit.isCompatible("millibar", unit))
      return AxisType.Pressure;
    if (SimpleUnit.isCompatible("m", unit))
      return AxisType.Height;
  }
  // otherwise guess
  return AxisType.GeoZ;
}