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

The following examples show how to use ucar.nc2.constants.FeatureType#GRID . 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: DtCoverageCSBuilder.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private FeatureType classify() {

    // now to classify
    boolean is2Dtime = (rtAxis != null) && (timeOffsetAxis != null || (timeAxis != null && timeAxis.getRank() == 2));
    if (is2Dtime) {
      return FeatureType.FMRC; // LOOK this would allow 2d horiz
    }

    boolean is2Dhoriz = isLatLon && (xaxis.getRank() == 2) && (yaxis.getRank() == 2);
    if (is2Dhoriz) {
      Set<Dimension> xyDomain = CoordinateSystem.makeDomain(Lists.newArrayList(xaxis, yaxis));
      if (timeAxis != null && CoordinateSystem.isSubset(timeAxis.getDimensionsAll(), xyDomain))
        return FeatureType.SWATH; // LOOK prob not exactly right
      else
        return FeatureType.CURVILINEAR;
    }

    // what makes it a grid?
    // each dimension must have its own coordinate variable
    Set<Dimension> indDimensions = CoordinateSystem.makeDomain(independentAxes);
    Set<Dimension> allDimensions = CoordinateSystem.makeDomain(allAxes);
    if (indDimensions.size() == allDimensions.size()) {
      return FeatureType.GRID;
    }

    // default
    return FeatureType.COVERAGE;
  }
 
Example 2
Source File: CdmrfReader.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static FeatureType convertCoverageType(CdmrFeatureProto.CoverageType type) {
  switch (type) {
    case General:
      return FeatureType.COVERAGE;
    case Curvilinear:
      return FeatureType.CURVILINEAR;
    case Grid:
      return FeatureType.GRID;
    case Swath:
      return FeatureType.SWATH;
    case Fmrc:
      return FeatureType.FMRC;
  }
  throw new IllegalStateException("illegal CoverageType " + type);
}
 
Example 3
Source File: FeatureDatasetFactoryManager.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Determine if factory type matches wanted feature type.
 *
 * @param want want this FeatureType
 * @param facType factory is of this type
 * @return true if match
 */
public static boolean featureTypeOk(FeatureType want, FeatureType facType) {
  if (want == null)
    return true;
  if (want == facType)
    return true;

  if (want == FeatureType.ANY_POINT) {
    return facType.isPointFeatureType();
  }

  if (facType == FeatureType.ANY_POINT) {
    return want.isPointFeatureType();
  }

  if (want == FeatureType.COVERAGE) {
    return facType.isCoverageFeatureType();
  }

  if (want == FeatureType.GRID) { // for backwards compatibility
    return facType.isCoverageFeatureType();
  }

  if (want == FeatureType.SIMPLE_GEOMETRY) {
    return facType.isCoverageFeatureType();
  }

  if (want == FeatureType.UGRID) {
    return facType.isUnstructuredGridFeatureType();
  }

  return false;
}
 
Example 4
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 5
Source File: TestConventionFeatureTypes.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testCoverageDatasets() throws IOException {
  if (type != FeatureType.GRID) {
    return;
  }
  for (File f : getAllFilesInDirectoryStandardFilter(dir)) {
    logger.debug("Open CoverageDataset {}", f.getPath());
    try (NetcdfDataset ds = NetcdfDatasets.openDataset(f.getPath())) {
      DtCoverageCSBuilder builder = DtCoverageCSBuilder.classify(ds, new Formatter());
      Assert.assertNotNull(builder);
    }
  }
}
 
Example 6
Source File: TestDtWithCoverageReadingP.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Ignore("takes too long")
@Test
public void testGridCoverageDataset() throws IOException {
  System.out.printf("Test Dataset %s%n", endpoint);

  try (FeatureDatasetCoverage cc = CoverageDatasetFactory.open(endpoint)) {
    Assert.assertNotNull(endpoint, cc);
    CoverageCollection gcs = cc.findCoverageDataset(expectType);
    Assert.assertNotNull(expectType.toString(), gcs);

    // check DtCoverageCS
    try (GridDataset ds = GridDataset.open(endpoint)) {
      for (GridDatatype dt : ds.getGrids()) {
        if (expectType == FeatureType.FMRC && !dt.getFullName().startsWith("TwoD"))
          continue;
        if (expectType == FeatureType.GRID && dt.getFullName().startsWith("TwoD"))
          continue;

        GridCoordSystem csys = dt.getCoordinateSystem();
        CoordinateAxis1DTime rtAxis = csys.getRunTimeAxis();
        CoordinateAxis1D ensAxis = csys.getEnsembleAxis();
        CoordinateAxis1D vertAxis = csys.getVerticalAxis();

        Coverage cover = gcs.findCoverage(dt.getShortName());
        if (cover == null) {
          System.out.printf("Cant find %s%n", dt.getFullName());
          continue;
        }
        System.out.printf(" Grid %s%n", dt.getFullName());

        readAllRuntimes(cover, dt, rtAxis, ensAxis, vertAxis);
      }
    }
  }
}
 
Example 7
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 8
Source File: GridDataset.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public FeatureType getFeatureType() {
  return FeatureType.GRID;
}
 
Example 9
Source File: GridDatasetStandardFactory.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public FeatureType[] getFeatureTypes() {
  return new FeatureType[] {FeatureType.GRID, FeatureType.FMRC, FeatureType.SWATH};
}