ucar.nc2.constants.CF Java Examples

The following examples show how to use ucar.nc2.constants.CF. 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: LambertCylindricalEqualArea.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public ProjectionCT makeCoordinateTransform(AttributeContainer ctv, String geoCoordinateUnits) {
  double par = readAttributeDouble(ctv, CF.STANDARD_PARALLEL, Double.NaN);

  readStandardParams(ctv, geoCoordinateUnits);

  // create spherical Earth obj if not created by readStandardParams w radii, flattening
  if (earth == null) {
    if (earth_radius > 0.) {
      // Earth radius obtained in readStandardParams is in km, but Earth object wants m
      earth = new Earth(earth_radius * 1000.);
    } else {
      earth = new Earth();
    }
  }

  ProjectionImpl proj = new CylindricalEqualAreaProjection(lon0, par, false_easting, false_northing, earth);

  return new ProjectionCT(ctv.getName(), "FGDC", proj);
}
 
Example #2
Source File: Ghcnm.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private Variable makeMember(Structure s, String shortName, DataType dataType, String dims, String longName,
    String units, String cfName, AxisType atype) {

  Variable v = new Variable(ncfile, null, s, shortName, dataType, dims);
  v.addAttribute(new Attribute(CDM.LONG_NAME, longName));
  if (cfName != null)
    v.addAttribute(new Attribute(CF.STANDARD_NAME, cfName));

  if (units != null)
    v.addAttribute(new Attribute(CDM.UNITS, units));

  if (atype != null)
    v.addAttribute(new Attribute(_Coordinate.AxisType, atype.toString()));

  s.addMemberVariable(v);

  return v;
}
 
Example #3
Source File: CF1Convention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Guess the value of ZisPositive based on z axis name and units
 *
 * @param zaxisName z coordinate axis name
 * @param vertCoordUnits z coordinate axis name
 * @return CF.POSITIVE_UP or CF.POSITIVE_DOWN
 */
public static String getZisPositive(String zaxisName, String vertCoordUnits) {
  if (vertCoordUnits == null) {
    return CF.POSITIVE_UP;
  }
  if (vertCoordUnits.isEmpty()) {
    return CF.POSITIVE_UP;
  }

  if (SimpleUnit.isCompatible("millibar", vertCoordUnits)) {
    return CF.POSITIVE_DOWN;
  }

  if (SimpleUnit.isCompatible("m", vertCoordUnits)) {
    return CF.POSITIVE_UP;
  }

  // dunno - make it up
  return CF.POSITIVE_UP;
}
 
Example #4
Source File: WriterCFTrajectoryProfileCollection.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void writeHeader(TrajectoryProfileFeature section, ProfileFeature profile, PointFeature obs)
    throws IOException {

  StructureData sectionData = section.getFeatureData();
  StructureData profileData = profile.getFeatureData();
  StructureData obsData = obs.getFeatureData();

  Formatter coordNames = new Formatter().format("%s %s %s", profileTimeName, latName, lonName);
  List<VariableSimpleIF> obsCoords = new ArrayList<>();
  if (useAlt) {
    obsCoords.add(VariableSimpleBuilder.makeScalar(altitudeCoordinateName, "obs altitude", altUnits, DataType.DOUBLE)
        .addAttribute(CF.STANDARD_NAME, "altitude")
        .addAttribute(CF.POSITIVE, CF1Convention.getZisPositive(altitudeCoordinateName, altUnits)).build());
    coordNames.format(" %s", altitudeCoordinateName);
  }

  super.writeHeader(obsCoords, sectionData, profileData, obsData, coordNames.toString());
}
 
Example #5
Source File: WriterCFTrajectoryProfileCollection.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void writeHeader(TrajectoryProfileFeature section, ProfileFeature profile, PointFeature obs)
    throws IOException {

  StructureData sectionData = section.getFeatureData();
  StructureData profileData = profile.getFeatureData();
  StructureData obsData = obs.getFeatureData();

  Formatter coordNames = new Formatter().format("%s %s %s", profileTimeName, latName, lonName);
  List<VariableSimpleIF> obsCoords = new ArrayList<>();
  if (useAlt) {
    obsCoords.add(VariableSimpleBuilder.makeScalar(altitudeCoordinateName, "obs altitude", altUnits, DataType.DOUBLE)
        .addAttribute(CF.STANDARD_NAME, "altitude")
        .addAttribute(CF.POSITIVE, CF1Convention.getZisPositive(altitudeCoordinateName, altUnits)).build());
    coordNames.format(" %s", altitudeCoordinateName);
  }

  super.writeHeader2(obsCoords, sectionData, profileData, obsData, coordNames.toString());
}
 
Example #6
Source File: FlatEarth.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Construct a FlatEarth Projection, two standard parellels.
 * For the one standard parellel case, set them both to the same value.
 *
 * @param lat0 lat origin of the coord. system on the projection plane
 * @param lon0 lon origin of the coord. system on the projection plane
 * @param rotAngle angle of rotation, in degrees
 * @param radius earth radius in km
 * @throws IllegalArgumentException if lat0, par1, par2 = +/-90 deg
 */
public FlatEarth(double lat0, double lon0, double rotAngle, double radius) {
  super("FlatEarth", false);

  this.lat0 = Math.toRadians(lat0);
  this.lon0 = Math.toRadians(lon0);
  this.rotAngle = Math.toRadians(rotAngle);
  this.radius = radius;

  precalculate();

  addParameter(CF.GRID_MAPPING_NAME, "flat_earth");
  addParameter(CF.LATITUDE_OF_PROJECTION_ORIGIN, lat0);
  addParameter(CF.LONGITUDE_OF_PROJECTION_ORIGIN, lon0);
  addParameter(ROTATIONANGLE, rotAngle);
  addParameter(CF.EARTH_RADIUS, radius * 1000);
}
 
Example #7
Source File: Stereographic.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Construct a Stereographic Projection.
 *
 * @param latt tangent point of projection, also origin of projection coord system
 * @param lont tangent point of projection, also origin of projection coord system
 * @param scale scale factor at tangent point, "normally 1.0 but may be reduced"
 * @param false_easting false easting in units of x coords
 * @param false_northing false northing in units of y coords
 * @param radius earth radius in km
 */
public Stereographic(double latt, double lont, double scale, double false_easting, double false_northing,
    double radius) {
  super("Stereographic", false);

  this.latt = Math.toRadians(latt);
  this.lont = Math.toRadians(lont);
  this.earthRadius = radius;
  this.scale = scale * earthRadius;
  this.falseEasting = false_easting;
  this.falseNorthing = false_northing;
  precalculate();

  addParameter(CF.GRID_MAPPING_NAME, CF.STEREOGRAPHIC);
  addParameter(CF.LONGITUDE_OF_PROJECTION_ORIGIN, lont);
  addParameter(CF.LATITUDE_OF_PROJECTION_ORIGIN, latt);
  addParameter(CF.SCALE_FACTOR_AT_PROJECTION_ORIGIN, scale);
  addParameter(CF.EARTH_RADIUS, earthRadius * 1000);

  if ((false_easting != 0.0) || (false_northing != 0.0)) {
    addParameter(CF.FALSE_EASTING, false_easting);
    addParameter(CF.FALSE_NORTHING, false_northing);
    addParameter(CDM.UNITS, "km");
  }
}
 
Example #8
Source File: Stereographic.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Construct a polar Stereographic Projection, from the "natural origin" and the tangent point,
 * calculating the scale factor.
 *
 * @param lat_ts_deg Latitude at natural origin (degrees_north)
 * @param latt_deg tangent point of projection (degrees_north)
 * @param lont_deg tangent point of projection, also origin of projection coord system ((degrees_east)
 * @param north true if north pole, false is south pole
 */
public Stereographic(double lat_ts_deg, double latt_deg, double lont_deg, boolean north) {
  super("PolarStereographic", false);

  this.latts = Math.toRadians(lat_ts_deg);
  this.latt = Math.toRadians(latt_deg);
  this.lont = Math.toRadians(lont_deg);
  this.isPolar = true;
  this.isNorth = north;
  this.earthRadius = EARTH_RADIUS;
  this.falseEasting = 0;
  this.falseNorthing = 0;

  precalculate();

  double scaleFactor = (lat_ts_deg == 90 || lat_ts_deg == -90) ? 1.0 : getScaleFactor(latts, north);
  this.scale = scaleFactor * earthRadius;

  addParameter(CF.GRID_MAPPING_NAME, "polar_stereographic");
  addParameter("longitude_of_projection_origin", lont_deg);
  addParameter("latitude_of_projection_origin", latt_deg);
  addParameter("scale_factor_at_projection_origin", scaleFactor);
}
 
Example #9
Source File: VerticalPerspectiveView.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Construct a VerticalPerspectiveView Projection
 *
 * @param lat0 lat origin of the coord. system on the projection plane
 * @param lon0 lon origin of the coord. system on the projection plane
 * @param earthRadius radius of the earth (km)
 * @param distance height above the earth (km)
 * @param false_easting easting offset (km)
 * @param false_northing northing offset (km)
 */
public VerticalPerspectiveView(double lat0, double lon0, double earthRadius, double distance, double false_easting,
    double false_northing) {

  super("VerticalPerspectiveView", false);

  this.lat0 = Math.toRadians(lat0);
  this.lon0 = Math.toRadians(lon0);
  R = earthRadius;
  H = distance;
  false_east = false_easting;
  false_north = false_northing;

  precalculate();

  addParameter(CF.GRID_MAPPING_NAME, CF.VERTICAL_PERSPECTIVE);
  addParameter(CF.LATITUDE_OF_PROJECTION_ORIGIN, lat0);
  addParameter(CF.LONGITUDE_OF_PROJECTION_ORIGIN, lon0);
  addParameter(CF.EARTH_RADIUS, earthRadius * 1000);
  addParameter(CF.PERSPECTIVE_POINT_HEIGHT, distance * 1000);
  if (false_easting != 0 || false_northing != 0) {
    addParameter(CF.FALSE_EASTING, false_easting);
    addParameter(CF.FALSE_NORTHING, false_northing);
    addParameter(CDM.UNITS, "km");
  }
}
 
Example #10
Source File: WriterCFPointCollection.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void writeHeader(PointFeature pf) throws IOException {
  List<VariableSimpleIF> coords = new ArrayList<>();
  coords.add(VariableSimpleBuilder.makeScalar(timeName, "time of measurement", timeUnit.getUdUnit(), DataType.DOUBLE)
      .addAttribute(CF.CALENDAR, timeUnit.getCalendar().toString()).build());

  coords.add(
      VariableSimpleBuilder.makeScalar(latName, "latitude of measurement", CDM.LAT_UNITS, DataType.DOUBLE).build());
  coords.add(
      VariableSimpleBuilder.makeScalar(lonName, "longitude of measurement", CDM.LON_UNITS, DataType.DOUBLE).build());
  Formatter coordNames = new Formatter().format("%s %s %s", timeName, latName, lonName);
  if (altUnits != null) {
    coords.add(VariableSimpleBuilder.makeScalar(altName, "altitude of measurement", altUnits, DataType.DOUBLE)
        .addAttribute(CF.POSITIVE, CF1Convention.getZisPositive(altName, altUnits)).build());
    coordNames.format(" %s", altName);
  }

  super.writeHeader(coords, null, pf.getDataAll(), coordNames.toString());
}
 
Example #11
Source File: EPSG_OGC_CF_Helper.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static String getWcs1_0CrsId(Projection proj) {
  String paramName = null;
  if (proj == null)
    paramName = "LatLon";
  else {
    for (Parameter curParam : proj.getProjectionParameters())
      if (curParam.getName().equalsIgnoreCase(CF.GRID_MAPPING_NAME) && curParam.isString())
        paramName = curParam.getStringValue();
  }
  if (paramName == null) {
    log.warn("getWcs1_0CrsId(): Unknown projection - " + projToString(proj));
    return ProjectionStandardsInfo.Unknown.getOgcName();
  }
  if (paramName.equalsIgnoreCase("LatLon")) {
    return "OGC:CRS84";
  }

  ProjectionStandardsInfo psi = ProjectionStandardsInfo.getProjectionByCfName(paramName);
  String crsId = "EPSG:" + psi.getEpsgCode() + " [" + psi.name();
  if (psi == ProjectionStandardsInfo.Unknown) {
    log.warn("getWcs1_0CrsId(): Unknown projection - " + projToString(proj));
    crsId += " - " + paramName;
  }
  return crsId + "]";
}
 
Example #12
Source File: GribIosp.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void makeTimeCoordinate1D(NetcdfFile ncfile, Group g, CoordinateTime coordTime) { // }, CoordinateRuntime
                                                                                          // runtime) {
  int ntimes = coordTime.getSize();
  String tcName = coordTime.getName();
  String dims = coordTime.getName();
  ncfile.addDimension(g, new Dimension(tcName, ntimes));
  Variable v = ncfile.addVariable(g, new Variable(ncfile, g, null, tcName, DataType.DOUBLE, dims));
  String units = coordTime.getTimeUdUnit();
  v.addAttribute(new Attribute(CDM.UNITS, units));
  v.addAttribute(new Attribute(CF.STANDARD_NAME, CF.TIME));
  v.addAttribute(new Attribute(CDM.LONG_NAME, Grib.GRIB_VALID_TIME));
  v.addAttribute(new Attribute(CF.CALENDAR, Calendar.proleptic_gregorian.toString()));

  double[] data = new double[ntimes];
  int count = 0;

  // coordinate values
  for (int val : coordTime.getOffsetSorted()) {
    data[count++] = val;
  }
  v.setCachedData(Array.factory(DataType.DOUBLE, new int[] {ntimes}, data));

  makeTimeAuxReference(ncfile, g, tcName, units, coordTime);
}
 
Example #13
Source File: SimpleGeometryReader.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Returns a Polygon given a variable name and the geometric index. If the Polygon is not found it will return null.
 * If the Polygon is a part of the Multi-Polygon, it will return the head
 * (the first Polygon in the series which constitutes the Multi-Polygon).
 * 
 * @param name of the variable which holds the Polygon
 * @param index of the Polygon within the variable
 * @return a new polygon with all associated information
 */
public Polygon readPolygon(String name, int index) {

  Variable polyvar = ds.findVariable(name);
  if (polyvar == null)
    return null;

  Polygon poly = null;

  // CFConvention
  if (ds.findGlobalAttribute(CF.CONVENTIONS) != null)
    if (ucar.nc2.dataset.conv.CF1Convention.getVersion(ds.findGlobalAttribute(CF.CONVENTIONS).getStringValue()) >= 8)
      poly = new CFPolygon();

  if (poly == null)
    return null;
  else
    return poly.setupPolygon(ds, polyvar, index);
}
 
Example #14
Source File: SimpleGeometryReader.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Returns a Line given a variable name and the geometric index. If the Line is not found it will return null. If the
 * Line is a part of the Multi-Line, it will return the head
 * (the first Line in the series which constitutes the Multi-Line).
 * 
 * @param name of the variable which holds the Line
 * @param index of the Line within the variable
 * @return a new line with all associated information
 */
public Line readLine(String name, int index) {

  Variable linevar = ds.findVariable(name);
  if (linevar == null)
    return null;
  Line line = null;

  // CFConvention
  if (ds.findGlobalAttribute(CF.CONVENTIONS) != null)
    if (ucar.nc2.dataset.conv.CF1Convention.getVersion(ds.findGlobalAttribute(CF.CONVENTIONS).getStringValue()) >= 8)
      line = new CFLine();

  if (line == null)
    return null;
  else
    return line.setupLine(ds, linevar, index);
}
 
Example #15
Source File: GribIospBuilder.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void makeTimeCoordinate1D(Group.Builder g, CoordinateTime coordTime) { // }, CoordinateRuntime
  // runtime) {
  int ntimes = coordTime.getSize();
  String tcName = coordTime.getName();
  String dims = coordTime.getName();
  g.addDimension(new Dimension(tcName, ntimes));
  Variable.Builder v = Variable.builder().setName(tcName).setDataType(DataType.DOUBLE).setParentGroupBuilder(g)
      .setDimensionsByName(dims);
  g.addVariable(v);
  String units = coordTime.getTimeUdUnit();
  v.addAttribute(new Attribute(CDM.UNITS, units));
  v.addAttribute(new Attribute(CF.STANDARD_NAME, CF.TIME));
  v.addAttribute(new Attribute(CDM.LONG_NAME, Grib.GRIB_VALID_TIME));
  v.addAttribute(new Attribute(CF.CALENDAR, Calendar.proleptic_gregorian.toString()));

  double[] data = new double[ntimes];
  int count = 0;

  // coordinate values
  for (int val : coordTime.getOffsetSorted()) {
    data[count++] = val;
  }
  v.setCachedData(Array.factory(DataType.DOUBLE, new int[] {ntimes}, data), false);

  makeTimeAuxReference(g, tcName, units, coordTime);
}
 
Example #16
Source File: WriterCFTrajectoryCollection.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected void makeFeatureVariables(StructureData featureData, boolean isExtended) {
  // LOOK why not unlimited here fro extended model ?
  Dimension profileDim = writer.addDimension(null, trajDimName, nfeatures);

  // add the profile Variables using the profile dimension
  List<VariableSimpleIF> featureVars = new ArrayList<>();
  featureVars.add(VariableSimpleBuilder.makeString(trajIdName, "trajectory identifier", null, id_strlen)
      .addAttribute(CF.CF_ROLE, CF.TRAJECTORY_ID).build());

  featureVars
      .add(VariableSimpleBuilder.makeScalar(numberOfObsName, "number of obs for this profile", null, DataType.INT)
          .addAttribute(CF.SAMPLE_DIMENSION, recordDimName).build());

  for (StructureMembers.Member m : featureData.getMembers()) {
    VariableSimpleIF dv = getDataVar(m.getName());
    if (dv != null)
      featureVars.add(dv);
  }

  if (isExtended) {
    featureStruct = (Structure) writer.addVariable(null, trajStructName, DataType.STRUCTURE, trajDimName);
    addCoordinatesExtended(featureStruct, featureVars);
  } else {
    addCoordinatesClassic(profileDim, featureVars, featureVarMap);
  }
}
 
Example #17
Source File: HdfEosModisConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public boolean isMine(NetcdfFile ncfile) {
  if (!ncfile.getFileTypeId().equals("HDF4-EOS")) {
    return false;
  }

  String typeName = ncfile.getRootGroup().attributes().findAttributeString(CF.FEATURE_TYPE, null);
  if (typeName == null) {
    return false;
  }
  if (!typeName.equals(FeatureType.GRID.toString()) && !typeName.equals(FeatureType.SWATH.toString())) {
    return false;
  }

  return checkGroup(ncfile.getRootGroup());
}
 
Example #18
Source File: GempakCdm.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) {
  boolean ok = false;
  String conv = ds.getRootGroup().findAttributeString(CDM.CONVENTIONS, null);
  if (conv == null)
    return false;
  if (conv.equals(Convention))
    ok = true;

  StringTokenizer stoke = new StringTokenizer(conv, ",");
  while (stoke.hasMoreTokens()) {
    String toke = stoke.nextToken().trim();
    if (toke.equals(Convention))
      ok = true;
  }
  if (!ok)
    return false;

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

  return (ftype == CF.FeatureType.timeSeries) || (ftype == CF.FeatureType.timeSeriesProfile);
}
 
Example #19
Source File: Mercator.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public ProjectionCT makeCoordinateTransform(AttributeContainer ctv, String geoCoordinateUnits) {
  double par = readAttributeDouble(ctv, CF.STANDARD_PARALLEL, Double.NaN);
  if (Double.isNaN(par)) {
    double scale = readAttributeDouble(ctv, CF.SCALE_FACTOR_AT_PROJECTION_ORIGIN, Double.NaN);
    if (Double.isNaN(scale))
      throw new IllegalArgumentException("Mercator projection must have attribute " + CF.STANDARD_PARALLEL + " or "
          + CF.SCALE_FACTOR_AT_PROJECTION_ORIGIN);
    par = ucar.unidata.geoloc.projection.Mercator.convertScaleToStandardParallel(scale);
  }

  readStandardParams(ctv, geoCoordinateUnits);

  ucar.unidata.geoloc.projection.Mercator proj =
      new ucar.unidata.geoloc.projection.Mercator(lon0, par, false_easting, false_northing, earth_radius);
  return new ProjectionCT(ctv.getName(), "FGDC", proj);
}
 
Example #20
Source File: FlatEarth.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public ProjectionCT makeCoordinateTransform(AttributeContainer ctv, String geoCoordinateUnits) {
  double lon0 = readAttributeDouble(ctv, CF.LONGITUDE_OF_PROJECTION_ORIGIN, Double.NaN);
  double lat0 = readAttributeDouble(ctv, CF.LATITUDE_OF_PROJECTION_ORIGIN, Double.NaN);
  double rot = readAttributeDouble(ctv, ucar.unidata.geoloc.projection.FlatEarth.ROTATIONANGLE, 0.0);
  double earth_radius = getEarthRadiusInKm(ctv);

  ucar.unidata.geoloc.projection.FlatEarth proj =
      new ucar.unidata.geoloc.projection.FlatEarth(lat0, lon0, rot, earth_radius);
  return new ProjectionCT(ctv.getName(), "FGDC", proj);
}
 
Example #21
Source File: Stereographic.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public ProjectionCT makeCoordinateTransform(AttributeContainer ctv, String geoCoordinateUnits) {
  double lon0 = readAttributeDouble(ctv, CF.LONGITUDE_OF_PROJECTION_ORIGIN, Double.NaN);
  double scale = readAttributeDouble(ctv, CF.SCALE_FACTOR_AT_PROJECTION_ORIGIN, 1.0);
  double lat0 = readAttributeDouble(ctv, CF.LATITUDE_OF_PROJECTION_ORIGIN, 90.0);
  double false_easting = readAttributeDouble(ctv, CF.FALSE_EASTING, 0.0);
  double false_northing = readAttributeDouble(ctv, CF.FALSE_NORTHING, 0.0);

  if ((false_easting != 0.0) || (false_northing != 0.0)) {
    double scalef = getFalseEastingScaleFactor(geoCoordinateUnits); // conversion from axis-unit to km
    false_easting *= scalef;
    false_northing *= scalef;
  }

  double earth_radius = getEarthRadiusInKm(ctv);
  double semi_major_axis = readAttributeDouble(ctv, CF.SEMI_MAJOR_AXIS, Double.NaN); // meters
  double semi_minor_axis = readAttributeDouble(ctv, CF.SEMI_MINOR_AXIS, Double.NaN);
  double inverse_flattening = readAttributeDouble(ctv, CF.INVERSE_FLATTENING, 0.0);

  ucar.unidata.geoloc.ProjectionImpl proj;

  // check for ellipsoidal earth
  if (!Double.isNaN(semi_major_axis) && (!Double.isNaN(semi_minor_axis) || inverse_flattening != 0.0)) {
    Earth earth = new Earth(semi_major_axis, semi_minor_axis, inverse_flattening);
    proj = new ucar.unidata.geoloc.projection.proj4.StereographicAzimuthalProjection(lat0, lon0, scale, 90.,
        false_easting, false_northing, earth);
  } else {
    proj = new ucar.unidata.geoloc.projection.Stereographic(lat0, lon0, scale, false_easting, false_northing,
        earth_radius);
  }
  return new ProjectionCT(ctv.getName(), "FGDC", proj);
}
 
Example #22
Source File: WriterCFTrajectoryCollection.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public WriterCFTrajectoryCollection(String fileOut, List<Attribute> globalAtts, List<VariableSimpleIF> dataVars,
    CalendarDateUnit timeUnit, String altUnits, CFPointWriterConfig config) throws IOException {
  super(fileOut, globalAtts, dataVars, timeUnit, altUnits, config);
  writer.addGroupAttribute(null, new Attribute(CF.FEATURE_TYPE, CF.FeatureType.trajectory.name()));
  writer.addGroupAttribute(null,
      new Attribute(CF.DSG_REPRESENTATION, "Contiguous ragged array representation of trajectories, H.4.3"));
}
 
Example #23
Source File: WriterCFTrajectoryProfileCollection.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void makeMiddleVariables(StructureData profileData, boolean isExtended) {
  Dimension profileDim = writerb.addDimension(profileDimName, nfeatures);

  // add the profile Variables using the profile dimension
  List<VariableSimpleIF> profileVars = new ArrayList<>();
  profileVars.add(VariableSimpleBuilder.makeString(profileIdName, "profile identifier", null, id_strlen)
      .addAttribute(CF.CF_ROLE, CF.PROFILE_ID) // profileId:cf_role = "profile_id";
      .addAttribute(CDM.MISSING_VALUE, String.valueOf(idMissingValue)).build());

  profileVars
      .add(VariableSimpleBuilder.makeScalar(latName, "profile latitude", CDM.LAT_UNITS, DataType.DOUBLE).build());
  profileVars
      .add(VariableSimpleBuilder.makeScalar(lonName, "profile longitude", CDM.LON_UNITS, DataType.DOUBLE).build());
  profileVars.add(VariableSimpleBuilder
      .makeScalar(profileTimeName, "nominal time of profile", timeUnit.getUdUnit(), DataType.DOUBLE)
      .addAttribute(CF.CALENDAR, timeUnit.getCalendar().toString()).build());

  profileVars.add(
      VariableSimpleBuilder.makeScalar(trajectoryIndexName, "trajectory index for this profile", null, DataType.INT)
          .addAttribute(CF.INSTANCE_DIMENSION, trajDimName).build());

  profileVars
      .add(VariableSimpleBuilder.makeScalar(numberOfObsName, "number of obs for this profile", null, DataType.INT)
          .addAttribute(CF.SAMPLE_DIMENSION, recordDimName).build());

  for (StructureMembers.Member m : profileData.getMembers()) {
    VariableSimpleIF dv = findDataVar(m.getName());
    if (dv != null)
      profileVars.add(dv);
  }

  if (isExtended) {
    Structure.Builder structb = writerb.addStructure(profileStructName, profileDimName);
    addCoordinatesExtended(structb, profileVars);
  } else {
    addCoordinatesClassic(profileDim, profileVars, profileVarMap);
  }
}
 
Example #24
Source File: WriterCFTrajectoryCollection.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
WriterCFTrajectoryCollection(String fileOut, AttributeContainer globalAtts, List<VariableSimpleIF> dataVars,
    CalendarDateUnit timeUnit, String altUnits, CFPointWriterConfig config) throws IOException {
  super(fileOut, globalAtts, dataVars, timeUnit, altUnits, config);
  writerb.addAttribute(new Attribute(CF.FEATURE_TYPE, CF.FeatureType.trajectory.name()));
  writerb.addAttribute(
      new Attribute(CF.DSG_REPRESENTATION, "Contiguous ragged array representation of trajectories, H.4.3"));
}
 
Example #25
Source File: GribIosp.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void makeRuntimeCoordinate(NetcdfFile ncfile, Group g, CoordinateRuntime rtc) {
  int n = rtc.getSize();
  boolean isScalar = (n == 1); // this is the case of runtime[1]
  String tcName = rtc.getName();
  String dims = isScalar ? null : rtc.getName(); // null means scalar
  if (!isScalar) {
    ncfile.addDimension(g, new Dimension(tcName, n));
  }

  Variable v = ncfile.addVariable(g, new Variable(ncfile, g, null, tcName, DataType.DOUBLE, dims));
  v.addAttribute(new Attribute(CDM.UNITS, rtc.getUnit()));
  v.addAttribute(new Attribute(CF.STANDARD_NAME, CF.TIME_REFERENCE));
  v.addAttribute(new Attribute(CDM.LONG_NAME, Grib.GRIB_RUNTIME));
  v.addAttribute(new Attribute(CF.CALENDAR, Calendar.proleptic_gregorian.toString()));

  /*
   * String vsName = tcName + "_ISO";
   * Variable vs = ncfile.addVariable(g, new Variable(ncfile, g, null, vsName, DataType.STRING, dims));
   * vs.addAttribute(new Attribute(CDM.UNITS, "ISO8601"));
   * v.addAttribute(new Attribute(CDM.LONG_NAME, "GRIB reference time"));
   * v.addAttribute(new Attribute(CF.CALENDAR, Calendar.proleptic_gregorian.toString()));
   * 
   * // coordinate values
   * String[] dataS = new String[n];
   * int count = 0;
   * for (CalendarDate val : rtc.getRuntimesSorted()) {
   * dataS[count++] = val.toString();
   * }
   * vs.setCachedData(Array.factory(DataType.STRING, isScalar ? new int[0] : new int[]{n}, dataS));
   */

  // lazy eval
  v.setSPobject(new Time2Dinfo(Time2DinfoType.reftime, null, rtc));
}
 
Example #26
Source File: RotatedPole.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public ProjectionCT makeCoordinateTransform(AttributeContainer ctv, String geoCoordinateUnits) {
  double lon = readAttributeDouble(ctv, CF.GRID_NORTH_POLE_LONGITUDE, Double.NaN);
  double lat = readAttributeDouble(ctv, CF.GRID_NORTH_POLE_LATITUDE, Double.NaN);

  ucar.unidata.geoloc.projection.RotatedPole proj = new ucar.unidata.geoloc.projection.RotatedPole(lat, lon);
  return new ProjectionCT(ctv.getName(), "FGDC", proj);
}
 
Example #27
Source File: McIDASAreaProjection.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Create a AREA coordinate system from the Area file's
 * directory and navigation blocks.
 * <p/>
 * This routine uses a flipped Y axis (first line of
 * the image file is number 0)
 *
 * @param dir is the AREA file directory block
 * @param nav is the AREA file navigation block
 * @param aux is the AREA file auxillary block
 */
public McIDASAreaProjection(int[] dir, int[] nav, int[] aux) {
  super("McIDASAreaProjection", false);

  try {
    anav = AREAnav.makeAreaNav(nav, aux);
  } catch (McIDASException excp) {
    throw new IllegalArgumentException("McIDASAreaProjection: problem creating projection" + excp);
  }
  dirBlock = dir;
  navBlock = nav;
  auxBlock = aux;
  anav.setImageStart(dir[5], dir[6]);
  anav.setRes(dir[11], dir[12]);
  anav.setStart(0, 0);
  anav.setMag(1, 1);
  lines = dir[8];
  elements = dir[9];
  anav.setFlipLineCoordinates(dir[8]); // invert Y axis coordinates

  addParameter(CF.GRID_MAPPING_NAME, GRID_MAPPING_NAME);
  addParameter(new Parameter(ATTR_AREADIR, makeDoubleArray(dir)));
  addParameter(new Parameter(ATTR_NAVBLOCK, makeDoubleArray(nav)));
  if (aux != null) {
    addParameter(new Parameter(ATTR_AUXBLOCK, makeDoubleArray(aux)));
  }
}
 
Example #28
Source File: RotatedPole.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Constructor.
 */
public RotatedPole(double northPoleLat, double northPoleLon) {
  super("RotatedPole", false);

  northPole = ProjectionPoint.create(northPoleLon, northPoleLat);
  buildRotationMatrices();

  addParameter(CF.GRID_MAPPING_NAME, CF.ROTATED_LATITUDE_LONGITUDE);
  addParameter(CF.GRID_NORTH_POLE_LATITUDE, northPoleLat);
  addParameter(CF.GRID_NORTH_POLE_LONGITUDE, northPoleLon);
}
 
Example #29
Source File: FeatureDatasetFactoryManager.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Try to determine the feature type of the dataset, by examining its metadata.
 *
 * @param ncd the dataset
 * @return FeatureType if found, else null
 */
public static FeatureType findFeatureType(NetcdfFile ncd) {
  // search for explicit featureType global attribute
  String cdm_datatype = ncd.getRootGroup().findAttributeString(CF.FEATURE_TYPE, null);
  if (cdm_datatype == null)
    cdm_datatype = ncd.getRootGroup().findAttributeString("cdm_data_type", null);
  if (cdm_datatype == null)
    cdm_datatype = ncd.getRootGroup().findAttributeString("cdm_datatype", null);
  if (cdm_datatype == null)
    cdm_datatype = ncd.getRootGroup().findAttributeString("thredds_data_type", null);

  if (cdm_datatype != null) {
    for (FeatureType ft : FeatureType.values())
      if (cdm_datatype.equalsIgnoreCase(ft.name())) {
        if (debug)
          System.out.println(" wrapUnknown found cdm_datatype " + cdm_datatype);
        return ft;
      }
  }

  CF.FeatureType cff = CF.FeatureType.getFeatureTypeFromGlobalAttribute(ncd);
  if (cff != null)
    return CF.FeatureType.convert(cff);


  return null;
}
 
Example #30
Source File: WriterCFStationProfileCollection.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void makeMiddleVariables(StructureData profileData, boolean isExtended) {
  Dimension profileDim = writer.addDimension(null, profileDimName, nfeatures);

  // add the profile Variables using the profile dimension
  List<VariableSimpleIF> profileVars = new ArrayList<>();
  profileVars.add(VariableSimpleBuilder.makeString(profileIdName, "profile identifier", null, id_strlen)
      .addAttribute(CF.CF_ROLE, CF.PROFILE_ID) // profileId:cf_role = "profile_id";
      .addAttribute(CDM.MISSING_VALUE, String.valueOf(idMissingValue)).build());

  profileVars
      .add(VariableSimpleBuilder.makeScalar(numberOfObsName, "number of obs for this profile", null, DataType.INT)
          .addAttribute(CF.SAMPLE_DIMENSION, recordDimName).build()); // rowSize:sample_dimension = "obs"

  profileVars.add(VariableSimpleBuilder
      .makeScalar(profileTimeName, "nominal time of profile", timeUnit.getUdUnit(), DataType.DOUBLE)
      .addAttribute(CF.CALENDAR, timeUnit.getCalendar().toString()).build());

  profileVars
      .add(VariableSimpleBuilder.makeScalar(stationIndexName, "station index for this profile", null, DataType.INT)
          .addAttribute(CF.INSTANCE_DIMENSION, stationDimName).build());

  for (StructureMembers.Member m : profileData.getMembers()) {
    VariableSimpleIF dv = getDataVar(m.getName());
    if (dv != null)
      profileVars.add(dv);
  }

  if (isExtended) {
    profileStruct = (Structure) writer.addVariable(null, profileStructName, DataType.STRUCTURE, profileDimName);
    addCoordinatesExtended(profileStruct, profileVars);
  } else {
    addCoordinatesClassic(profileDim, profileVars, profileVarMap);
  }
}