Java Code Examples for ucar.nc2.constants.AxisType#Pressure

The following examples show how to use ucar.nc2.constants.AxisType#Pressure . 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: 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 2
Source File: CoverageCoordSys.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public CoverageCoordAxis getZAxis() {
  for (String axisName : getAxisNames()) {
    CoverageCoordAxis axis = dataset.findCoordAxis(axisName);
    if (axis == null)
      throw new IllegalStateException("Cant find axis with name " + axisName);
    if (axis.getAxisType() == AxisType.GeoZ || axis.getAxisType() == AxisType.Height
        || axis.getAxisType() == AxisType.Pressure)
      return axis;
  }
  return null;
}
 
Example 3
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 4
Source File: GridCoordSys.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * true if increasing z coordinate values means "up" in altitude
 */
@Override
public boolean isZPositive() {
  if (vertZaxis == null)
    return false;
  if (vertZaxis.getPositive() != null) {
    return vertZaxis.getPositive().equalsIgnoreCase(ucar.nc2.constants.CF.POSITIVE_UP);
  }
  if (vertZaxis.getAxisType() == AxisType.Height)
    return true;
  return vertZaxis.getAxisType() != AxisType.Pressure;
}
 
Example 5
Source File: ADASConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected AxisType getAxisType(VariableDS.Builder vb) {
  String vname = vb.shortName;

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

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

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

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

  if (vname.equalsIgnoreCase("z") || vname.equalsIgnoreCase("z_stag"))
    return AxisType.GeoZ;

  if (vname.equalsIgnoreCase("Z"))
    return AxisType.Height;

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

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

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


  return null;
}
 
Example 6
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;
}
 
Example 7
Source File: WRFConvention.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") || vname.equalsIgnoreCase("x_stag"))
    return AxisType.GeoX;

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

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

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

  if (vname.equalsIgnoreCase("z") || vname.equalsIgnoreCase("z_stag"))
    return AxisType.GeoZ;

  if (vname.equalsIgnoreCase("Z"))
    return AxisType.Height;

  if (vname.equalsIgnoreCase("time") || vname.equalsIgnoreCase("times"))
    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;
  }


  return null;
}
 
Example 8
Source File: WRFConvention.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") || vname.equalsIgnoreCase("x_stag"))
    return AxisType.GeoX;

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

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

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

  if (vname.equalsIgnoreCase("z") || vname.equalsIgnoreCase("z_stag"))
    return AxisType.GeoZ;

  if (vname.equalsIgnoreCase("Z"))
    return AxisType.Height;

  if (vname.equalsIgnoreCase("time") || vname.equalsIgnoreCase("times"))
    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 null;
}
 
Example 9
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 10
Source File: CoordSystemBuilder.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Turn the variable into a coordinate axis.
 * Add to the dataset, replacing variable if needed.
 *
 * @return coordinate axis
 */
protected CoordinateAxis.Builder makeIntoCoordinateAxis() {
  if (axis != null) {
    return axis;
  }

  if (vb instanceof CoordinateAxis.Builder) {
    axis = (CoordinateAxis.Builder) vb;
  } else {
    // Create a CoordinateAxis out of this variable.
    vb = axis = CoordinateAxis.fromVariableDS(vb);
  }

  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));
    }
  }
  coords.replaceCoordinateAxis(axis);
  if (axis.getParentStructureBuilder() != null) {
    axis.getParentStructureBuilder().replaceMemberVariable(axis);
  } else {
    gb.replaceVariable(axis);
  }
  return axis;
}
 
Example 11
Source File: ADASConvention.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") || vname.equalsIgnoreCase("x_stag"))
    return AxisType.GeoX;

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

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

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

  if (vname.equalsIgnoreCase("z") || vname.equalsIgnoreCase("z_stag"))
    return AxisType.GeoZ;

  if (vname.equalsIgnoreCase("Z"))
    return AxisType.Height;

  if (vname.equalsIgnoreCase("time"))
    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 null;
}
 
Example 12
Source File: NUWGConvention.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("lat"))
    return AxisType.Lat;

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

  if (vname.equalsIgnoreCase(xaxisName))
    return AxisType.GeoX;

  if (vname.equalsIgnoreCase(yaxisName))
    return AxisType.GeoY;

  if (vname.equalsIgnoreCase("record"))
    return AxisType.Time;
  Dimension dim = v.getDimension(0);
  if ((dim != null) && dim.getShortName().equalsIgnoreCase("record")) { // wow thats bad!
    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;

    if (SimpleUnit.isCompatible("sec", unit))
      return null;
  }

  return AxisType.GeoZ; // AxisType.GeoZ;
}
 
Example 13
Source File: DefaultConventions.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Nullable
private AxisType getAxisTypeCoards(VariableDS.Builder vb) {
  String unit = vb.getUnits();
  if (unit == null) {
    return null;
  }

  if (unit.equalsIgnoreCase("degrees_east") || unit.equalsIgnoreCase("degrees_E") || unit.equalsIgnoreCase("degreesE")
      || unit.equalsIgnoreCase("degree_east") || unit.equalsIgnoreCase("degree_E")
      || unit.equalsIgnoreCase("degreeE")) {
    return AxisType.Lon;
  }

  if (unit.equalsIgnoreCase("degrees_north") || unit.equalsIgnoreCase("degrees_N")
      || unit.equalsIgnoreCase("degreesN") || unit.equalsIgnoreCase("degree_north")
      || unit.equalsIgnoreCase("degree_N") || unit.equalsIgnoreCase("degreeN")) {
    return AxisType.Lat;
  }

  if (SimpleUnit.isDateUnit(unit)) // || SimpleUnit.isTimeUnit(unit)) removed dec 18, 2008
  {
    return AxisType.Time;
  }

  // look for other z coordinate
  // if (SimpleUnit.isCompatible("m", unit))
  // return AxisType.Height;
  if (SimpleUnit.isCompatible("mbar", unit)) {
    return AxisType.Pressure;
  }
  if (unit.equalsIgnoreCase("level") || unit.equalsIgnoreCase("layer") || unit.equalsIgnoreCase("sigma_level")) {
    return AxisType.GeoZ;
  }

  String positive = vb.getAttributeContainer().findAttributeString("positive", null);
  if (positive != null) {
    if (SimpleUnit.isCompatible("m", unit)) {
      return AxisType.Height;
    } else {
      return AxisType.GeoZ;
    }
  }
  return null;
}
 
Example 14
Source File: Vis5DIosp.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Create a vertical dimension variable based on the info. Based on
 * visad.data.vis5d.Vis5DVerticalSystem.
 *
 * @param vert_sys the vertical system id
 * @param n_levels the number of levels
 * @param vert_args the vertical system arguments
 * @return the vertical dimesion variable
 * @throws IOException problem reading the file or creating the data
 */
private Variable makeVerticalVariable(int vert_sys, int n_levels, float[] vert_args) throws IOException {

  String vert_unit;
  String vert_type;
  ArrayFloat.D1 data = new ArrayFloat.D1(n_levels);
  AxisType axisType = null;

  switch (vert_sys) {

    case (0):
      vert_unit = null;
      vert_type = "height";
      break;

    case (1):
    case (2):
      vert_unit = "km";
      vert_type = "altitude";
      axisType = AxisType.Height;
      break;

    case (3):
      vert_unit = "mbar";
      vert_type = "pressure";
      axisType = AxisType.Pressure;
      break;

    default:
      throw new IOException("vert_sys unknown");
  }

  Variable vertVar = new Variable(ncfile, null, null, vert_type);
  vertVar.setDimensions(LEVEL);
  vertVar.setDataType(DataType.FLOAT);
  if (vert_unit != null) {
    vertVar.addAttribute(new Attribute(CDM.UNITS, vert_unit));
  }
  if (axisType != null) {
    vertVar.addAttribute(new Attribute(_Coordinate.AxisType, axisType.toString()));
  }

  switch (vert_sys) {

    case (0):
    case (1):
      for (int i = 0; i < n_levels; i++) {
        data.set(i, vert_args[0] + vert_args[1] * i);
      }
      break;

    case (2): // Altitude in km - non-linear
      for (int i = 0; i < n_levels; i++) {
        data.set(i, vert_args[i]);
      }
      break;

    case (3): // heights of pressure surfaces in km - non-linear
      try {
        Vis5DVerticalSystem.Vis5DVerticalCoordinateSystem vert_cs =
            new Vis5DVerticalSystem.Vis5DVerticalCoordinateSystem();
        float[][] pressures = new float[1][n_levels];
        System.arraycopy(vert_args, 0, pressures[0], 0, n_levels);
        for (int i = 0; i < n_levels; i++) {
          pressures[0][i] *= 1000; // km->m
        }
        pressures = vert_cs.fromReference(pressures); // convert to pressures
        for (int i = 0; i < n_levels; i++) {
          data.set(i, pressures[0][i]);
        }
      } catch (VisADException ve) {
        throw new IOException("unable to make vertical system");
      }
      break;
  }
  vertVar.setCachedData(data, false);
  return vertVar;
}
 
Example 15
Source File: AWIPSsatConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
protected AxisType getAxisType(NetcdfDataset ds, VariableEnhanced ve) {
  Variable v = (Variable) ve;
  String vname = v.getShortName();
  String units = v.getUnitsString();

  if (units.equalsIgnoreCase(CDM.LON_UNITS))
    return AxisType.Lon;

  if (units.equalsIgnoreCase(CDM.LAT_UNITS))
    return AxisType.Lat;


  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 16
Source File: CoardsConventions.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
@Nullable
protected AxisType getAxisType(VariableDS.Builder vb) {
  String unit = vb.getUnits();
  if (unit == null) {
    return null;
  }
  unit = unit.trim();

  if (unit.equalsIgnoreCase("degrees_east") || unit.equalsIgnoreCase("degrees_E") || unit.equalsIgnoreCase("degreesE")
      || unit.equalsIgnoreCase("degree_east") || unit.equalsIgnoreCase("degree_E")
      || unit.equalsIgnoreCase("degreeE")) {
    return AxisType.Lon;
  }

  if (unit.equalsIgnoreCase("degrees_north") || unit.equalsIgnoreCase("degrees_N")
      || unit.equalsIgnoreCase("degreesN") || unit.equalsIgnoreCase("degree_north")
      || unit.equalsIgnoreCase("degree_N") || unit.equalsIgnoreCase("degreeN")) {
    return AxisType.Lat;
  }

  if (SimpleUnit.isDateUnit(unit)) {
    return AxisType.Time;
  }
  // look for other z coordinate
  if (SimpleUnit.isCompatible("mbar", unit)) {
    return AxisType.Pressure;
  }
  if (unit.equalsIgnoreCase("level") || unit.equalsIgnoreCase("layer") || unit.equalsIgnoreCase("sigma_level")) {
    return AxisType.GeoZ;
  }

  String positive = vb.getAttributeContainer().findAttributeString(CF.POSITIVE, null);
  if (positive != null) {
    if (SimpleUnit.isCompatible("m", unit)) {
      return AxisType.Height;
    } else {
      return AxisType.GeoZ;
    }
  }

  // a bad idea, but CDC SST relies on it :
  // :Source = "NOAA/National Climatic Data Center";
  // :Contact = "Dick Reynolds, email: [email protected] & Chunying Liu, email: [email protected]";
  // :netcdf_Convention = "COARDS";
  // if (checkForMeter && SimpleUnit.isCompatible("m", unit))
  // return AxisType.Height;

  return null;
}
 
Example 17
Source File: HdfEos.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private AxisType addAxisType(Variable.Builder v) {
  String name = v.shortName;
  if (name.equalsIgnoreCase("Latitude") || name.equalsIgnoreCase("GeodeticLatitude")) {
    v.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Lat.toString()));
    v.addAttribute(new Attribute(CDM.UNITS, CDM.LAT_UNITS));
    return AxisType.Lat;

  } else if (name.equalsIgnoreCase("Longitude")) {
    v.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Lon.toString()));
    v.addAttribute(new Attribute(CDM.UNITS, CDM.LON_UNITS));
    return AxisType.Lon;

  } else if (name.equalsIgnoreCase("Time")) {
    v.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Time.toString()));
    if (v.getAttributeContainer().findAttribute(CDM.UNITS) == null) {
      /*
       * from http://newsroom.gsfc.nasa.gov/sdptoolkit/hdfeosfaq.html
       * HDF-EOS uses the TAI93 (International Atomic Time) format. This means that time is stored as the number of
       * elapsed seconds since January 1, 1993 (negative values represent times prior to this date).
       * An 8 byte floating point number is used, producing microsecond accuracy from 1963 (when leap second records
       * became available electronically) to 2100. The SDP Toolkit provides conversions from other date formats to and
       * from TAI93. Other representations of time can be entered as ancillary data, if desired.
       * For lists and descriptions of other supported time formats, consult the Toolkit documentation or write to
       * [email protected].
       */
      v.addAttribute(new Attribute(CDM.UNITS, "seconds since 1993-01-01T00:00:00Z"));
      v.addAttribute(new Attribute(CF.CALENDAR, "TAI"));
      /*
       * String tit = ncfile.findAttValueIgnoreCase(v, "Title", null);
       * if (tit != null && tit.contains("TAI93")) {
       * // Time is given in the TAI-93 format, i.e. the number of seconds passed since 01-01-1993, 00:00 UTC.
       * v.addAttribute(new Attribute(CDM.UNITS, "seconds since 1993-01-01T00:00:00Z"));
       * v.addAttribute(new Attribute(CF.CALENDAR, "TAI"));
       * } else { // who the hell knows ??
       * v.addAttribute(new Attribute(CDM.UNITS, "seconds since 1970-01-01T00:00:00Z"));
       * }
       */
    }
    return AxisType.Time;

  } else if (name.equalsIgnoreCase("Pressure")) {
    v.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Pressure.toString()));
    return AxisType.Pressure;

  } else if (name.equalsIgnoreCase("Altitude")) {
    v.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Height.toString()));
    v.addAttribute(new Attribute(CF.POSITIVE, CF.POSITIVE_UP)); // probably
    return AxisType.Height;
  }

  return null;
}
 
Example 18
Source File: CoordinateSystem.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
protected CoordinateSystem(Builder<?> builder, NetcdfDataset ncd, List<CoordinateAxis> axes,
    List<CoordinateTransform> allTransforms) {
  this.ds = ncd;
  this.isImplicit = builder.isImplicit;

  // find referenced coordinate axes
  List<CoordinateAxis> axesList = new ArrayList<>();
  StringTokenizer stoker = new StringTokenizer(builder.coordAxesNames);
  while (stoker.hasMoreTokens()) {
    String vname = stoker.nextToken();
    for (CoordinateAxis a : axes) {
      String aname = a.getFullName();
      if (aname.equals(vname)) {
        axesList.add(a);
      }
    }
  }
  this.coordAxes = axesList;

  // calculated
  this.name = makeName(coordAxes);

  for (CoordinateAxis axis : this.coordAxes) {
    // look for AxisType
    AxisType axisType = axis.getAxisType();
    if (axisType != null) {
      if (axisType == AxisType.GeoX)
        xAxis = lesserRank(xAxis, axis);
      if (axisType == AxisType.GeoY)
        yAxis = lesserRank(yAxis, axis);
      if (axisType == AxisType.GeoZ)
        zAxis = lesserRank(zAxis, axis);
      if (axisType == AxisType.Time)
        tAxis = lesserRank(tAxis, axis);
      if (axisType == AxisType.Lat)
        latAxis = lesserRank(latAxis, axis);
      if (axisType == AxisType.Lon)
        lonAxis = lesserRank(lonAxis, axis);
      if (axisType == AxisType.Height)
        hAxis = lesserRank(hAxis, axis);
      if (axisType == AxisType.Pressure)
        pAxis = lesserRank(pAxis, axis);
      if (axisType == AxisType.Ensemble)
        ensAxis = lesserRank(ensAxis, axis);

      if (axisType == AxisType.RadialAzimuth)
        aziAxis = lesserRank(aziAxis, axis);
      if (axisType == AxisType.RadialDistance)
        radialAxis = lesserRank(radialAxis, axis);
      if (axisType == AxisType.RadialElevation)
        elevAxis = lesserRank(elevAxis, axis);
    }
    // collect dimensions
    List<Dimension> dims = axis.getDimensionsAll();
    domain.addAll(dims);
  }

  // Find the named coordinate transforms in allTransforms.
  for (String wantTransName : builder.transNames) {
    CoordinateTransform got = allTransforms.stream()
        .filter(ct -> (wantTransName.equals(ct.getName())
            || ct.getAttributeContainer() != null && wantTransName.equals(ct.getAttributeContainer().getName())))
        .findFirst().orElse(null);
    if (got != null) {
      coordTrans.add(got);
    }

  }
}
 
Example 19
Source File: CoordinateSystem.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Constructor.
 * 
 * @param ds the containing dataset
 * @param axes Collection of type CoordinateAxis, must be at least one.
 * @param coordTrans Collection of type CoordinateTransform, may be empty or null.
 * @deprecated Use CoordinateSystem.builder()
 */
@Deprecated
public CoordinateSystem(NetcdfDataset ds, Collection<CoordinateAxis> axes,
    Collection<CoordinateTransform> coordTrans) {
  this.ds = ds;
  this.coordAxes = new ArrayList<>(axes);
  this.name = makeName(coordAxes);

  if (coordTrans != null)
    this.coordTrans = new ArrayList<>(coordTrans);

  for (CoordinateAxis axis : coordAxes) {
    // look for AxisType
    AxisType axisType = axis.getAxisType();
    if (axisType != null) {
      if (axisType == AxisType.GeoX)
        xAxis = lesserRank(xAxis, axis);
      if (axisType == AxisType.GeoY)
        yAxis = lesserRank(yAxis, axis);
      if (axisType == AxisType.GeoZ)
        zAxis = lesserRank(zAxis, axis);
      if (axisType == AxisType.Time)
        tAxis = lesserRank(tAxis, axis);
      if (axisType == AxisType.Lat)
        latAxis = lesserRank(latAxis, axis);
      if (axisType == AxisType.Lon)
        lonAxis = lesserRank(lonAxis, axis);
      if (axisType == AxisType.Height)
        hAxis = lesserRank(hAxis, axis);
      if (axisType == AxisType.Pressure)
        pAxis = lesserRank(pAxis, axis);
      if (axisType == AxisType.Ensemble)
        ensAxis = lesserRank(ensAxis, axis);

      if (axisType == AxisType.RadialAzimuth)
        aziAxis = lesserRank(aziAxis, axis);
      if (axisType == AxisType.RadialDistance)
        radialAxis = lesserRank(radialAxis, axis);
      if (axisType == AxisType.RadialElevation)
        elevAxis = lesserRank(elevAxis, axis);
    }

    // collect dimensions
    List<Dimension> dims = axis.getDimensionsAll();
    domain.addAll(dims);
  }
}
 
Example 20
Source File: GridCoordSys.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Add this coordinate system to the netCDF file
 *
 * @param ncfile the netCDF file
 * @param g the group to add to
 */
void addToNetcdfFile(NetcdfFile ncfile, Group g) {
  if (dontUseVertical) {
    return;
  }

  if (g == null) {
    g = ncfile.getRootGroup();
  }

  String dims = "time";
  if (!dontUseVertical) {
    dims = dims + " " + verticalName;
  }
  if (hcs.isLatLon()) {
    dims = dims + " lat lon";
  } else {
    dims = dims + " y x";
  }

  // Collections.sort( levels);
  int nlevs = levels.size();
  // ncfile.addDimension(g, new Dimension(verticalName, nlevs, true));

  // coordinate axis and coordinate system Variable
  Variable v = new Variable(ncfile, g, null, verticalName);
  v.setDataType(DataType.DOUBLE);

  v.addAttribute(new Attribute("long_name", lookup.getLevelDescription(record)));
  v.addAttribute(new Attribute("units", lookup.getLevelUnit(record)));

  // positive attribute needed for CF-1 Height and Pressure
  if (positive != null) {
    v.addAttribute(new Attribute("positive", positive));
  }

  if (units != null) {
    AxisType axisType;
    if (SimpleUnit.isCompatible("millibar", units)) {
      axisType = AxisType.Pressure;
    } else if (SimpleUnit.isCompatible("m", units)) {
      axisType = AxisType.Height;
    } else {
      axisType = AxisType.GeoZ;
    }

    v.addAttribute(new Attribute("grid_level_type", Integer.toString(record.getLevelType1())));

    v.addAttribute(new Attribute(_Coordinate.AxisType, axisType.toString()));
    v.addAttribute(new Attribute(_Coordinate.Axes, dims));
    if (!hcs.isLatLon()) {
      v.addAttribute(new Attribute(_Coordinate.Transforms, hcs.getGridName()));
    }
  }

  double[] data = new double[nlevs];
  for (int i = 0; i < levels.size(); i++) {
    Double d = levels.get(i);
    data[i] = d;
  }
  Array dataArray = Array.factory(DataType.DOUBLE, new int[] {nlevs}, data);

  v.setDimensions(verticalName);
  v.setCachedData(dataArray, false);

  ncfile.addVariable(g, v);

  // look for vertical transforms
  if (record.getLevelType1() == 109) {
    findCoordinateTransform(g, "Pressure", record.getLevelType1());
  }
}