Java Code Examples for ucar.nc2.dataset.NetcdfDataset#getCoordinateAxes()

The following examples show how to use ucar.nc2.dataset.NetcdfDataset#getCoordinateAxes() . 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: 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 2
Source File: PointDatasetStandardFactory.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Check if this is a POINT datatype. If so, a TableAnalyser is used to analyze its structure.
 * The TableAnalyser is reused when the dataset is opened.
 * <ol>
 * <li>Can handle ANY_POINT FeatureType.
 * <li>Must have time, lat, lon axis (from CoordSysBuilder)
 * <li>Call TableAnalyzer.factory() to create a TableAnalyzer
 * <li>TableAnalyzer must agree it can handle the requested FeatureType
 * </ol>
 *
 * @param wantFeatureType desired feature type, null means FeatureType.ANY_POINT
 * @param ds analyse this dataset
 * @param errlog log error messages here (may not be null)
 * @return if successful, return non-null. This object is then passed back into open(), so analysis can be reused.
 */
@Override
public Object isMine(FeatureType wantFeatureType, NetcdfDataset ds, Formatter errlog) {
  if (wantFeatureType == null)
    wantFeatureType = FeatureType.ANY_POINT;
  if (wantFeatureType != FeatureType.ANY_POINT) {
    if (!wantFeatureType.isPointFeatureType())
      return null;
  }

  TableConfigurer tc = TableAnalyzer.getTableConfigurer(wantFeatureType, ds);

  // if no explicit tc, then check whatever we can before expensive analysis)
  if (tc == null) {
    boolean hasTime = false;
    boolean hasLat = false;
    boolean hasLon = false;
    for (CoordinateAxis axis : ds.getCoordinateAxes()) {
      if (axis.getAxisType() == AxisType.Time) // && (axis.getRank() == 1))
        hasTime = true;
      if (axis.getAxisType() == AxisType.Lat) // && (axis.getRank() == 1))
        hasLat = true;
      if (axis.getAxisType() == AxisType.Lon) // && (axis.getRank() == 1))
        hasLon = true;
    }

    // minimum we need
    if (!(hasTime && hasLon && hasLat)) {
      errlog.format("PointDataset must have lat,lon,time");
      return null;
    }
  } else if (showTables) {
    System.out.printf("TableConfigurer = %s%n", tc.getClass().getName());
  }

  try {
    // gotta do some work
    TableAnalyzer analyser = TableAnalyzer.factory(tc, wantFeatureType, ds);
    if (analyser == null)
      return null;

    if (!analyser.featureTypeOk(wantFeatureType, errlog)) {
      return null;
    }
    return analyser;

  } catch (Throwable t) {
    return null;
  }
}
 
Example 3
Source File: NestedTable.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
NestedTable(NetcdfDataset ds, TableConfig config, Formatter errlog) {
  this.ds = ds;
  this.errlog = errlog;

  this.leaf = Table.factory(ds, config);
  this.root = getRoot();

  // use the featureType from the highest level table
  nlevels = 0;
  Table t = leaf;
  while (t != null) {
    if (t.getFeatureType() != null)
      featureType = t.getFeatureType();
    t = t.parent;
    // if (!(t instanceof Table.TableTop)) // LOOK using nlevels is fishy
    nlevels++;
  }
  if (featureType == null)
    featureType = FeatureDatasetFactoryManager.findFeatureType(ds);

  /*
   * find joins with extra variables
   * t = leaf;
   * while (t != null) {
   * if (t.extraJoins != null) {
   * for (Join j : t.extraJoins) {
   * addExtraVariable(j.getExtraVariable());
   * }
   * }
   * t = t.parent; // recurse upwards
   * }
   */

  // will find the first one, starting at the leaf and going up
  timeVE = findCoordinateAxis(Table.CoordName.Time, leaf, 0);
  latVE = findCoordinateAxis(Table.CoordName.Lat, leaf, 0);
  lonVE = findCoordinateAxis(Table.CoordName.Lon, leaf, 0);
  altVE = findCoordinateAxis(Table.CoordName.Elev, leaf, 0);
  nomTimeVE = findCoordinateAxis(Table.CoordName.TimeNominal, leaf, 0);

  // search for station info
  stnVE = findCoordinateAxis(Table.CoordName.StnId, leaf, 0);
  stnDescVE = findCoordinateAxis(Table.CoordName.StnDesc, leaf, 0);
  wmoVE = findCoordinateAxis(Table.CoordName.WmoId, leaf, 0);
  stnAltVE = findCoordinateAxis(Table.CoordName.StnAlt, leaf, 0);

  missingVE = findCoordinateAxis(Table.CoordName.MissingVar, leaf, 0);
  idVE = findCoordinateAxis(Table.CoordName.FeatureId, root, nlevels - 1); // LOOK start at root ??

  // LOOK: Major kludge
  if (featureType == null) {
    if (nlevels == 1)
      featureType = FeatureType.POINT;
    if (nlevels == 2)
      featureType = FeatureType.STATION;
    if (nlevels == 3)
      featureType = FeatureType.STATION_PROFILE;
  }

  // find coordinates that are not part of the extras
  for (CoordinateAxis axis : ds.getCoordinateAxes()) {
    if (!isCoordinate(axis) && !isExtra(axis) && axis.getDimensionsAll().size() <= 1) // Only permit 0-D and 1-D axes
                                                                                      // as extra variables.
      addExtraVariable(axis);
  }

  /*
   * check for singleton
   * if (((nlevels == 1) && (featureType == FeatureType.STATION) || (featureType == FeatureType.PROFILE) ||
   * (featureType == FeatureType.TRAJECTORY)) ||
   * ((nlevels == 2) && (featureType == FeatureType.STATION_PROFILE) || (featureType ==
   * FeatureType.TRAJECTORY_PROFILE))) {
   * 
   * // singleton. use file name as feature name, so aggregation will work
   * StructureData sdata = StructureDataFactory.make(featureVariableName, ds.getLocation());
   * TableConfig parentConfig = new TableConfig(Table.Type.Singleton, featureType.toString());
   * parentConfig.sdata = sdata;
   * root = Table.factory(ds, parentConfig);
   * 
   * nlevels++;
   * } //
   */
}