Java Code Examples for ucar.nc2.constants.FeatureType#POINT

The following examples show how to use ucar.nc2.constants.FeatureType#POINT . 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: UnidataPointObs.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public boolean isMine(FeatureType wantFeatureType, NetcdfDataset ds) {
  if ((wantFeatureType != FeatureType.ANY_POINT) && (wantFeatureType != FeatureType.STATION)
      && (wantFeatureType != FeatureType.POINT))
    return false;

  FeatureType ft = FeatureDatasetFactoryManager.findFeatureType(ds);
  if (((ft != FeatureType.STATION) && (ft != FeatureType.POINT)))
    return false;

  String conv = ds.getRootGroup().findAttributeString(CDM.CONVENTIONS, null);
  if (conv == null)
    return false;

  StringTokenizer stoke = new StringTokenizer(conv, ",");
  while (stoke.hasMoreTokens()) {
    String toke = stoke.nextToken().trim();
    if (toke.equalsIgnoreCase("Unidata Observation Dataset v1.0"))
      return true;
  }

  return false;
}
 
Example 2
Source File: GempakCdm.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public TableConfig getConfig(FeatureType wantFeatureType, NetcdfDataset ds, Formatter errlog) {

    CF.FeatureType ftype = CF.FeatureType.getFeatureTypeFromGlobalAttribute(ds);
    if (ftype == null)
      ftype = CF.FeatureType.point;

    switch (ftype) {
      case point:
        return null; // use default handler
      case timeSeries:
        if (wantFeatureType == FeatureType.POINT)
          return getStationAsPointConfig(ds, errlog);
        else
          return getStationConfig(ds, errlog);
      case timeSeriesProfile:
        return getStationProfileConfig(ds, errlog);
      default:
        throw new IllegalStateException("unimplemented feature ftype= " + ftype);
    }
  }
 
Example 3
Source File: CFpointObs.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected TableConfig getPointConfig(NetcdfDataset ds, EncodingInfo info, Formatter errlog) {
  if (info.time.getRank() != 1) {
    errlog.format("CFpointObs type=point: coord time must have rank 1, coord var= %s %n",
        info.time.getNameAndDimensions());
    return null;
  }
  Dimension obsDim = info.time.getDimension(0);

  TableConfig obsTable = makeSingle(ds, obsDim, errlog);
  obsTable.featureType = FeatureType.POINT;
  return obsTable;
}
 
Example 4
Source File: Madis.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public boolean isMine(FeatureType wantFeatureType, NetcdfDataset ds) {
  if ((wantFeatureType != FeatureType.ANY_POINT) && (wantFeatureType != FeatureType.STATION)
      && (wantFeatureType != FeatureType.POINT) && (wantFeatureType != FeatureType.STATION_PROFILE))
    return false;

  if (!ds.hasUnlimitedDimension())
    return false;
  if (ds.findDimension("recNum") == null)
    return false;

  if (ds.findVariable("staticIds") == null)
    return false;
  if (ds.findVariable("nStaticIds") == null)
    return false;
  if (ds.findVariable("lastRecord") == null)
    return false;
  if (ds.findVariable("prevRecord") == null)
    return false;

  VNames vn = getVariableNames(ds, null);
  if (ds.findVariable(vn.lat) == null)
    return false;
  if (ds.findVariable(vn.lon) == null)
    return false;
  return ds.findVariable(vn.obsTime) != null;

}
 
Example 5
Source File: TableAnalyzer.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void checkIfTrajectory(TableConfig st) {
  // deal with possible trajectory - only do this if dataset has metadata
  FeatureType ft = FeatureDatasetFactoryManager.findFeatureType(ds);
  if (ft == FeatureType.TRAJECTORY) {
    st.featureType = FeatureType.TRAJECTORY;
    TableConfig pc = new TableConfig(Table.Type.Top, "single");
    st.parent = pc;
    pc.addChild(st);
  } else
    st.featureType = FeatureType.POINT;
}
 
Example 6
Source File: BufrConfig.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private FeatureType guessFeatureType(StandardFields.StandardFieldsFromMessage standardFields) {
  if (standardFields.hasStation())
    return FeatureType.STATION;
  if (standardFields.hasTime())
    return FeatureType.POINT;
  return FeatureType.ANY;
}
 
Example 7
Source File: TestConventionFeatureTypes.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testFeatureDatasets() throws IOException {
  for (File f : getAllFilesInDirectoryStandardFilter(dir)) {
    logger.debug("Open FeatureDataset {}", f.getPath());
    try (FeatureDataset fd = FeatureDatasetFactoryManager.open(type, f.getPath(), null, new Formatter())) {
      Assert.assertNotNull(f.getPath(), fd);
      if (type == FeatureType.GRID)
        Assert.assertTrue(f.getPath(), fd.getFeatureType().isCoverageFeatureType());
      else if (type == FeatureType.POINT)
        Assert.assertTrue(f.getPath(), fd.getFeatureType().isPointFeatureType());
    }
  }
}
 
Example 8
Source File: PointFeatureDatasetViewer.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void subset(LatLonRect geoRegion, DateRange dateRange) throws IOException {
  PointFeatureCollection pc = null;
  CalendarDateRange cdr = CalendarDateRange.of(dateRange);

  if (selectedType == FeatureType.POINT) {
    PointFeatureCollection ptCollection = (PointFeatureCollection) selectedCollection;
    pc = ptCollection.subset(geoRegion, cdr);

  } else if (selectedType == FeatureType.STATION) {
    StationTimeSeriesFeatureCollection stationCollection = (StationTimeSeriesFeatureCollection) selectedCollection;
    /*
     * if (geoRegion != null) {
     * StationTimeSeriesFeatureCollection stationSubset = stationCollection.subset(geoRegion);
     * setStations( stationSubset);
     * return;
     * } else {
     */
    pc = stationCollection.flatten(geoRegion, cdr);
    // } LOOK
  }
  /*
   * else if (selectedType == FeatureType.STATION_PROFILE) {
   * StationProfileFeatureCollection stationProfileCollection = (StationProfileFeatureCollection) selectedCollection;
   * pc = stationProfileCollection.flatten(geoRegion, cdr);
   * }
   */

  if (null != pc) {
    setObservations(pc);
  }
}
 
Example 9
Source File: NcssPointController.java    From tds with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@RequestMapping("**")
public void handleRequest(HttpServletRequest req, HttpServletResponse res, @Valid NcssPointParamsBean params,
    BindingResult validationResult) throws Exception {
  if (validationResult.hasErrors())
    throw new BindException(validationResult);

  String datasetPath = getDatasetPath(req);
  try (FeatureDatasetPoint fdp = TdsRequestedDataset.getPointDataset(req, res, datasetPath)) {
    if (fdp == null)
      return;

    Formatter errs = new Formatter();
    if (!params.intersectsTime(fdp.getCalendarDateRange(), errs)) {
      handleValidationErrorMessage(res, HttpServletResponse.SC_BAD_REQUEST, errs.toString());
      return;
    }

    FeatureType ft = fdp.getFeatureType();
    if (ft != FeatureType.POINT && ft != FeatureType.STATION) {
      throw new NcssException("Dataset Feature Type is " + ft.toString() + " but request is for Points or Stations");
    }

    SubsetParams ncssParams = params.makeSubset();
    SupportedFormat format = getSupportedOperation(fdp).getSupportedFormat(params.getAccept());

    DsgSubsetWriter pds =
        DsgSubsetWriterFactory.newInstance(fdp, ncssParams, ncssDiskCache, res.getOutputStream(), format);
    setResponseHeaders(res, pds.getHttpHeaders(datasetPath, format.isStream()));
    pds.respond(res, fdp, datasetPath, ncssParams, format);
  }
}
 
Example 10
Source File: PointObsDatasetImpl.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public FeatureType getScientificDataType() {
  return FeatureType.POINT;
}
 
Example 11
Source File: MetadataExtractor.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Extract a list of data variables (and their canonical names if possible) from the dataset.
 * 
 * @param threddsDataset open this dataset
 * @return ThreddsMetadata.Variables, or null if unable.
 * @throws IOException on read error
 */
public static ThreddsMetadata.Variables extractVariables(InvDatasetImpl threddsDataset) throws IOException {
  ThreddsDataFactory.Result result = null;

  try {
    result = new ThreddsDataFactory().openFeatureDataset(threddsDataset, null);
    if (result.fatalError) {
      System.out.println(" openDatatype errs=" + result.errLog);
      return null;
    }

    if (result.featureType == FeatureType.GRID) {
      // System.out.println(" extractVariables GRID=" + result.location);
      GridDataset gridDataset = (GridDataset) result.featureDataset;
      return extractVariables(threddsDataset, gridDataset);

    } else if ((result.featureType == FeatureType.STATION) || (result.featureType == FeatureType.POINT)) {
      PointObsDataset pobsDataset = (PointObsDataset) result.featureDataset;
      ThreddsMetadata.Variables vars = new ThreddsMetadata.Variables("CF-1.0");
      for (VariableSimpleIF vs : pobsDataset.getDataVariables()) {
        ThreddsMetadata.Variable v = new ThreddsMetadata.Variable();
        vars.addVariable(v);

        v.setName(vs.getShortName());
        v.setDescription(vs.getDescription());
        v.setUnits(vs.getUnitsString());

        ucar.nc2.Attribute att = vs.findAttributeIgnoreCase("standard_name");
        if (att != null)
          v.setVocabularyName(att.getStringValue());
      }
      vars.sort();
      return vars;
    }

  } finally {
    try {
      if ((result != null) && (result.featureDataset != null))
        result.featureDataset.close();
    } catch (IOException ioe) {
      logger.error("Closing dataset " + result.featureDataset, ioe);
    }
  }

  return null;
}
 
Example 12
Source File: HdfEos.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Amend the given NetcdfFile with metadata from HDF-EOS structMetadata
 *
 * @param rootg Amend this
 * @param structMetadata structMetadata as String
 */
private void amendFromODL(Group.Builder rootg, String structMetadata) {
  ODLparser parser = new ODLparser();
  Element root = parser.parseFromString(structMetadata); // now we have the ODL in JDOM elements
  FeatureType featureType = null;

  // SWATH
  Element swathStructure = root.getChild("SwathStructure");
  if (swathStructure != null) {
    List<Element> swaths = swathStructure.getChildren();
    for (Element elemSwath : swaths) {
      Element swathNameElem = elemSwath.getChild("SwathName");
      if (swathNameElem == null) {
        log.warn("No SwathName element in {} {} ", elemSwath.getName(), location);
        continue;
      }
      String swathName = NetcdfFiles.makeValidCdmObjectName(swathNameElem.getText().trim());
      Group.Builder swathGroup = findGroupNested(rootg, swathName);
      // if (swathGroup == null)
      // swathGroup = findGroupNested(rootg, HdfHeaderIF.createValidObjectName(swathName));

      if (swathGroup != null) {
        featureType = amendSwath(elemSwath, swathGroup);
      } else {
        log.warn("Cant find swath group {} {}", swathName, location);
      }
    }
  }

  // GRID
  Element gridStructure = root.getChild("GridStructure");
  if (gridStructure != null) {
    List<Element> grids = gridStructure.getChildren();
    for (Element elemGrid : grids) {
      Element gridNameElem = elemGrid.getChild("GridName");
      if (gridNameElem == null) {
        log.warn("No GridName element in {} {} ", elemGrid.getName(), location);
        continue;
      }
      String gridName = NetcdfFiles.makeValidCdmObjectName(gridNameElem.getText().trim());
      Group.Builder gridGroup = findGroupNested(rootg, gridName);
      // if (gridGroup == null)
      // gridGroup = findGroupNested(rootg, HdfHeaderIF.createValidObjectName(gridName));
      if (gridGroup != null) {
        featureType = amendGrid(elemGrid, gridGroup, location);
      } else {
        log.warn("Cant find Grid group {} {}", gridName, location);
      }
    }
  }

  // POINT - NOT DONE YET
  Element pointStructure = root.getChild("PointStructure");
  if (pointStructure != null) {
    List<Element> pts = pointStructure.getChildren();
    for (Element elem : pts) {
      Element nameElem = elem.getChild("PointName");
      if (nameElem == null) {
        log.warn("No PointName element in {} {}", elem.getName(), location);
        continue;
      }
      String name = nameElem.getText().trim();
      Group.Builder ptGroup = findGroupNested(rootg, name);
      // if (ptGroup == null)
      // ptGroup = findGroupNested(rootg, HdfHeaderIF.createValidObjectName(name));
      if (ptGroup != null) {
        featureType = FeatureType.POINT;
      } else {
        log.warn("Cant find Point group {} {}", name, location);
      }
    }
  }

  if (featureType != null) {
    if (showWork) {
      log.debug("***EOS featureType= {}", featureType);
    }
    rootg.addAttribute(new Attribute(CF.FEATURE_TYPE, featureType.toString()));
    // rootg.addAttribute(new Attribute(CDM.CONVENTIONS, "HDFEOS"));
  }

}
 
Example 13
Source File: PointDatasetStandardFactory.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
PointDatasetStandard(FeatureType wantFeatureType, TableAnalyzer analyser, NetcdfDataset ds, Formatter errlog) {
  super(ds, null);
  parseInfo.format(" PointFeatureDatasetImpl=%s%n", getClass().getName());
  this.analyser = analyser;

  List<DsgFeatureCollection> featureCollections = new ArrayList<>();
  for (NestedTable flatTable : analyser.getFlatTables()) { // each flat table becomes a "feature collection"

    CalendarDateUnit timeUnit;
    try {
      timeUnit = flatTable.getTimeUnit();
    } catch (Exception e) {
      if (null != errlog)
        errlog.format("%s%n", e.getMessage());
      timeUnit = CalendarDateUnit.unixDateUnit;
    }

    String altUnits = flatTable.getAltUnits();

    // create member variables
    dataVariables = new ArrayList<>(flatTable.getDataVariables());

    featureType = flatTable.getFeatureType(); // hope they're all the same
    if (flatTable.getFeatureType() == FeatureType.POINT)
      featureCollections.add(new StandardPointCollectionImpl(flatTable, timeUnit, altUnits));

    else if (flatTable.getFeatureType() == FeatureType.PROFILE)
      featureCollections.add(new StandardProfileCollectionImpl(flatTable, timeUnit, altUnits));

    else if (flatTable.getFeatureType() == FeatureType.STATION)
      featureCollections.add(new StandardStationCollectionImpl(flatTable, timeUnit, altUnits));

    else if (flatTable.getFeatureType() == FeatureType.STATION_PROFILE)
      featureCollections.add(new StandardStationProfileCollectionImpl(flatTable, timeUnit, altUnits));

    else if (flatTable.getFeatureType() == FeatureType.TRAJECTORY_PROFILE)
      featureCollections.add(new StandardSectionCollectionImpl(flatTable, timeUnit, altUnits));

    else if (flatTable.getFeatureType() == FeatureType.TRAJECTORY)
      featureCollections.add(new StandardTrajectoryCollectionImpl(flatTable, timeUnit, altUnits));
  }

  if (featureCollections.isEmpty())
    throw new IllegalStateException("No feature collections found");

  setPointFeatureCollection(featureCollections);
}
 
Example 14
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++;
   * } //
   */
}
 
Example 15
Source File: GempakCdm.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
protected TableConfig getStationAsPointConfig(NetcdfDataset ds, Formatter errlog) {
  boolean needFinish = false;

  // find lat coord
  Variable lat = CoordSysEvaluator.findCoordByType(ds, AxisType.Lat);
  if (lat == null) {
    errlog.format("GempakCdm: Must have a Latitude coordinate");
    return null;
  }

  // find lon coord
  Variable lon = CoordSysEvaluator.findCoordByType(ds, AxisType.Lon);
  if (lon == null) {
    errlog.format("GempakCdm: Must have a Longitude coordinate");
    return null;
  }

  if (lat.getRank() != lon.getRank()) {
    errlog.format("GempakCdm: Lat and Lon coordinate must have same rank");
    return null;
  }

  // check dimensions
  boolean stnIsScalar = (lat.getRank() == 0);
  boolean stnIsSingle = (lat.getRank() == 1) && (lat.getSize() == 1);
  Dimension stationDim = null;

  if (!stnIsScalar) {
    if (lat.getDimension(0) != lon.getDimension(0)) {
      errlog.format("Lat and Lon coordinate must have same size");
      return null;
    }
    stationDim = lat.getDimension(0);
  }

  // optional alt coord
  Variable alt = CoordSysEvaluator.findCoordByType(ds, AxisType.Height);

  // obs table
  VariableDS time = CoordSysEvaluator.findCoordByType(ds, AxisType.Time);
  if (time == null) {
    errlog.format("GempakCdm: Must have a Time coordinate");
    return null;
  }
  Dimension obsDim = time.getDimension(time.getRank() - 1); // may be time(time) or time(stn, obs)

  Table.Type obsTableType = Table.Type.Structure;
  Structure multidimStruct = Evaluator.findStructureWithDimensions(ds, stationDim, obsDim);

  if (multidimStruct == null) {
    errlog.format("GempakCdm: Cannot figure out StationAsPoint table structure");
    return null;
  }

  TableConfig obs = new TableConfig(obsTableType, obsDim.getShortName());
  obs.dimName = obsDim.getShortName();
  obs.structName = multidimStruct.getFullName();
  obs.structureType = TableConfig.StructureType.Structure;
  obs.featureType = FeatureType.POINT;

  obs.lat = lat.getFullName();
  obs.lon = lon.getFullName();
  obs.time = time.getFullName();
  if (alt != null)
    obs.elev = alt.getFullName();

  List<String> vars = new ArrayList<>(30);
  for (Variable v : ds.getVariables()) {
    if ((v.getDimension(0) == stationDim)
        && ((v.getRank() == 1) || ((v.getRank() == 2) && (v.getDataType() == DataType.CHAR))))
      vars.add(v.getShortName());
  }

  StructureDS s = new StructurePseudoDS(ds, null, "stnStruct", vars, stationDim);
  obs.addJoin(new JoinMuiltdimStructure(s, obsDim.getLength()));
  obs.addJoin(new JoinArray(time, JoinArray.Type.modulo, obsDim.getLength()));

  if (needFinish)
    ds.finish();
  return obs;
}
 
Example 16
Source File: PointCollectionImpl.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Nonnull
@Override
public FeatureType getCollectionFeatureType() {
  return FeatureType.POINT;
}