ucar.nc2.dataset.VariableEnhanced Java Examples

The following examples show how to use ucar.nc2.dataset.VariableEnhanced. 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: Jason2Convention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * _more_
 *
 * @param ncDataset _more_
 * @param v _more_
 *
 * @return _more_
 */
protected AxisType getAxisType(NetcdfDataset ncDataset, VariableEnhanced v) {
  String name = v.getShortName();
  if (name.equals("time")) {
    return AxisType.Time;
  }
  if (name.equals("lat")) {
    return AxisType.Lat;
  }
  if (name.equals("lon")) {
    return AxisType.Lon;
  }
  // if (name.equals("xLeo") ) return AxisType.GeoX;
  // if (name.equals("yLeo") ) return AxisType.GeoY;
  if (name.equals("alt")) {
    return AxisType.Height;
  }
  return null;
}
 
Example #2
Source File: Cosmic1Convention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected AxisType getAxisType(NetcdfDataset ncDataset, VariableEnhanced v) {
  String name = v.getShortName();
  if (name.equals("time")) {
    return AxisType.Time;
  }
  if (name.equals("Lat") || name.equals("GEO_lat")) {
    return AxisType.Lat;
  }
  if (name.equals("Lon") || name.equals("GEO_lon")) {
    return AxisType.Lon;
  }
  // if (name.equals("xLeo") ) return AxisType.GeoX;
  // if (name.equals("yLeo") ) return AxisType.GeoY;
  if (name.equals("MSL_alt")) {
    return AxisType.Height;
  }
  return null;
}
 
Example #3
Source File: Aggregation.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected Variable findVariable(NetcdfFile ncfile, Variable mainV) {
  Variable v = ncfile.findVariable(mainV.getFullNameEscaped());
  if (v == null) { // might be renamed
    VariableEnhanced ve = (VariableEnhanced) mainV;
    v = ncfile.findVariable(ve.getOriginalName()); // LOOK not escaped
  }
  return v;
}
 
Example #4
Source File: Aggregation.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected Variable findVariable(NetcdfFile ncfile, Variable mainV) {
  Variable v = ncfile.findVariable(mainV.getFullNameEscaped());
  if (v == null) { // might be renamed
    VariableEnhanced ve = (VariableEnhanced) mainV;
    v = ncfile.findVariable(ve.getOriginalName()); // LOOK not escaped
  }
  return v;
}
 
Example #5
Source File: AWIPSConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 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("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;
  Dimension dim = v.getDimension(0);
  if ((dim != null) && dim.getShortName().equalsIgnoreCase("record"))
    return AxisType.Time;

  String unit = ve.getUnitsString();
  if (unit != null) {
    if (SimpleUnit.isCompatible("millibar", unit))
      return AxisType.Pressure;

    if (SimpleUnit.isCompatible("m", unit))
      return AxisType.Height;
  }


  return AxisType.GeoZ;
}
 
Example #6
Source File: Suomi.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected AxisType getAxisType(NetcdfDataset ncDataset, VariableEnhanced v) {
  String name = v.getShortName();
  if (name.equals("time_offset"))
    return AxisType.Time;
  if (name.equals("lat"))
    return AxisType.Lat;
  if (name.equals("lon"))
    return AxisType.Lon;
  if (name.equals("height"))
    return AxisType.Height;
  return null;
}
 
Example #7
Source File: AggProxyReader.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected Variable findVariable(NetcdfFile ncfile, Variable mainV) {
  Variable v = ncfile.findVariable(mainV.getFullNameEscaped());
  if (v == null) { // might be renamed
    VariableEnhanced ve = (VariableEnhanced) mainV;
    v = ncfile.findVariable(ve.getOriginalName()); // LOOK not escaped
  }
  return v;
}
 
Example #8
Source File: FmrcDataset.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected Variable findVariable(NetcdfFile ncfile, Variable client) {
  Variable v = ncfile.findVariable(client.getFullNameEscaped());
  if (v == null) { // might be renamed
    VariableEnhanced ve = (VariableEnhanced) client;
    v = ncfile.findVariable(ve.getOriginalName());
  }
  return v;
}
 
Example #9
Source File: VariableWrapper.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new variable wrapping the given netCDF interface.
 */
VariableWrapper(final Decoder decoder, VariableIF v) {
    super(decoder);
    variable = v;
    if (v instanceof VariableEnhanced) {
        v = ((VariableEnhanced) v).getOriginalVariable();
        if (v == null) {
            v = variable;
        }
    }
    raw = v;
}
 
Example #10
Source File: CSBuilderFallback.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Identifies what kind of axis the given variable is.
 */
@Override
protected AxisType getAxisType(final NetcdfDataset ds, final VariableEnhanced variable) {
    final String name = variable.getShortName();
    if (CharSequences.startsWith(name, "Longitude", true)) return AxisType.Lon;
    if (CharSequences.startsWith(name, "Latitude",  true)) return AxisType.Lat;
    return super.getAxisType(ds, variable);
}
 
Example #11
Source File: Nimbus.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void augmentDataset(NetcdfDataset ds, CancelTask cancelTask) throws IOException {
  ds.addAttribute(null, new Attribute("cdm_data_type", ucar.nc2.constants.FeatureType.TRAJECTORY.name())); // deprecated
  ds.addAttribute(null, new Attribute(CF.FEATURE_TYPE, ucar.nc2.constants.FeatureType.TRAJECTORY.name()));

  if (!setAxisType(ds, "LATC", AxisType.Lat))
    if (!setAxisType(ds, "LAT", AxisType.Lat))
      setAxisType(ds, "GGLAT", AxisType.Lat);

  if (!setAxisType(ds, "LONC", AxisType.Lon))
    if (!setAxisType(ds, "LON", AxisType.Lon))
      setAxisType(ds, "GGLON", AxisType.Lon);

  if (!setAxisType(ds, "PALT", AxisType.Height))
    setAxisType(ds, "GGALT", AxisType.Height);

  boolean hasTime = setAxisType(ds, "Time", AxisType.Time);
  if (!hasTime)
    hasTime = setAxisType(ds, "time", AxisType.Time);

  // do we need to version this ?
  // String version = ds.findAttValueIgnoreCase(null, "version", null);

  if (!hasTime) {
    Variable time = ds.findVariable("time_offset");
    if (time != null) {
      Variable base = ds.findVariable("base_time");
      int base_time = base.readScalarInt();
      try {
        DateUnit dunit = new DateUnit("seconds since 1970-01-01 00:00");
        String time_units = "seconds since " + dunit.makeStandardDateString(base_time);
        time.addAttribute(new Attribute(CDM.UNITS, time_units));
        time.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Time.name()));
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }

  // look for coordinates
  String coordinates = ds.findAttValueIgnoreCase(null, "coordinates", null);
  if (coordinates != null) {
    String[] vars = coordinates.split(" ");
    for (String vname : vars) {
      Variable v = ds.findVariable(vname);
      if (v != null) {
        AxisType atype = getAxisType(ds, (VariableEnhanced) v);
        if (atype != null)
          v.addAttribute(new Attribute(_Coordinate.AxisType, atype.name()));
      }
    }
  }

}
 
Example #12
Source File: CompareNetcdf.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private boolean compareVariables(Variable org, Variable copy, boolean compareData, Formatter f) {
  boolean ok = true;

  if (showCompare)
    f.format("compare Variable %s to %s %n", org.getFullName(), copy.getFullName());
  if (!org.getFullName().equals(copy.getFullName())) {
    f.format(" ** names are different %s != %s %n", org.getFullName(), copy.getFullName());
    ok = false;
  }

  // dimensions
  ok &= checkAll(org.getDimensions(), copy.getDimensions(), null, f);

  // attributes
  ok &= checkAll(org.getAttributes(), copy.getAttributes(), null, f);

  // coord sys
  if ((org instanceof VariableEnhanced) && (copy instanceof VariableEnhanced)) {
    VariableEnhanced orge = (VariableEnhanced) org;
    VariableEnhanced copye = (VariableEnhanced) copy;
    ok &= checkAll(orge.getCoordinateSystems(), copye.getCoordinateSystems(), null, f);
  }

  // data !!
  if (compareData) {
    try {
      compareVariableData(org, copy, showCompare, f);

    } catch (IOException e) {
      ByteArrayOutputStream bos = new ByteArrayOutputStream(10000);
      e.printStackTrace(new PrintStream(bos));
      f.format("%s", bos.toString());
    }
  }

  // nested variables
  if (org instanceof Structure) {
    assert (copy instanceof Structure);
    Structure orgS = (Structure) org;
    Structure ncmlS = (Structure) copy;

    List vars = new ArrayList();
    ok &= checkAll(orgS.getVariables(), ncmlS.getVariables(), vars, f);
    for (int i = 0; i < vars.size(); i += 2) {
      Variable orgV = (Variable) vars.get(i);
      Variable ncmlV = (Variable) vars.get(i + 1);
      ok &= compareVariables(orgV, ncmlV, false, f);
    }
  }

  return ok;
}
 
Example #13
Source File: CompareNetcdf.java    From tds with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private boolean compareVariables(Variable org, Variable copy, boolean compareData, Formatter f) {
  boolean ok = true;

  if (showCompare)
    f.format("compare Variable %s to %s %n", org.getFullName(), copy.getFullName());
  if (!org.getFullName().equals(copy.getFullName())) {
    f.format(" ** names are different %s != %s %n", org.getFullName(), copy.getFullName());
    ok = false;
  }

  // dimensions
  ok &= checkAll(org.getDimensions(), copy.getDimensions(), null, f);

  // attributes
  ok &= checkAll(org.getAttributes(), copy.getAttributes(), null, f);

  // coord sys
  if ((org instanceof VariableEnhanced) && (copy instanceof VariableEnhanced)) {
    VariableEnhanced orge = (VariableEnhanced) org;
    VariableEnhanced copye = (VariableEnhanced) copy;
    ok &= checkAll(orge.getCoordinateSystems(), copye.getCoordinateSystems(), null, f);
  }

  // data !!
  if (compareData) {
    try {
      compareVariableData(org, copy, showCompare, f);

    } catch (IOException e) {
      ByteArrayOutputStream bos = new ByteArrayOutputStream(10000);
      e.printStackTrace(new PrintStream(bos));
      f.format("%s", bos.toString());
    }
  }

  // nested variables
  if (org instanceof Structure) {
    assert (copy instanceof Structure);
    Structure orgS = (Structure) org;
    Structure ncmlS = (Structure) copy;

    List vars = new ArrayList();
    ok &= checkAll(orgS.getVariables(), ncmlS.getVariables(), vars, f);
    for (int i = 0; i < vars.size(); i += 2) {
      Variable orgV = (Variable) vars.get(i);
      Variable ncmlV = (Variable) vars.get(i + 1);
      ok &= compareVariables(orgV, ncmlV, false, f);
    }
  }

  return ok;
}