ucar.nc2.constants.CDM Java Examples

The following examples show how to use ucar.nc2.constants.CDM. 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: 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 #2
Source File: Time2DOffsetCoordSys.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private CoverageCoordAxis makeScalarTimeCoord(double val, CoverageCoordAxis1D runAxisSubset) {
  String name = "constantForecastTime";
  String desc = "forecast time";
  AttributeContainerMutable atts = new AttributeContainerMutable(name);
  atts.addAttribute(new Attribute(CDM.UNITS, runAxisSubset.getUnits()));
  atts.addAttribute(new Attribute(CF.STANDARD_NAME, CF.TIME));
  atts.addAttribute(new Attribute(CDM.LONG_NAME, desc));
  atts.addAttribute(new Attribute(CF.CALENDAR, runAxisSubset.getCalendar().toString()));

  CoverageCoordAxisBuilder builder = new CoverageCoordAxisBuilder(name, runAxisSubset.getUnits(), desc,
      DataType.DOUBLE, AxisType.Time, atts, CoverageCoordAxis.DependenceType.scalar, null,
      CoverageCoordAxis.Spacing.regularPoint, 1, val, val, 0.0, null, null);
  builder.setIsSubset(true);

  return new CoverageCoordAxis1D(builder);
}
 
Example #3
Source File: DodsURLExtractor.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Extract all A-HREF contained URLS from the given URL and return in List
 */
public ArrayList extract(String url) throws IOException {
  if (debug)
    System.out.println(" URLextract=" + url);

  baseURL = new URL(url);
  InputStream in = baseURL.openStream();
  InputStreamReader r = new InputStreamReader(filterTag(in), CDM.UTF8);
  HTMLEditorKit.ParserCallback callback = new CallerBacker();

  urlList = new ArrayList();
  wantURLS = true;
  wantText = false;
  parser.parse(r, callback, false);

  return urlList;
}
 
Example #4
Source File: GribIosp.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void addGroup(NetcdfFile ncfile, Group parent, GribCollectionImmutable.GroupGC group,
    GribCollectionImmutable.Type gctype, boolean useGroups) {

  Group g;
  if (useGroups) {
    g = new Group(ncfile, parent, group.getId());
    g.addAttribute(new Attribute(CDM.LONG_NAME, group.getDescription()));
    try {
      ncfile.addGroup(parent, g);
    } catch (Exception e) {
      logger.warn("Duplicate Group - skipping");
      return;
    }
  } else {
    g = parent;
  }

  makeGroup(ncfile, g, group, gctype);
}
 
Example #5
Source File: InvCatalogFactory10.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected ThreddsMetadata.GeospatialCoverage readGeospatialCoverage(Element gcElem) {
  if (gcElem == null)
    return null;

  String zpositive = gcElem.getAttributeValue("zpositive");

  ThreddsMetadata.Range northsouth = readGeospatialRange(gcElem.getChild("northsouth", defNS), CDM.LAT_UNITS);
  ThreddsMetadata.Range eastwest = readGeospatialRange(gcElem.getChild("eastwest", defNS), CDM.LON_UNITS);
  ThreddsMetadata.Range updown = readGeospatialRange(gcElem.getChild("updown", defNS), "m");

  // look for names
  List<ThreddsMetadata.Vocab> names = new ArrayList<>();
  java.util.List<Element> list = gcElem.getChildren("name", defNS);
  for (Element e : list) {
    ThreddsMetadata.Vocab name = readControlledVocabulary(e);
    names.add(name);
  }

  return new ThreddsMetadata.GeospatialCoverage(eastwest, northsouth, updown, names, zpositive);
}
 
Example #6
Source File: CFGridCoverageWriter.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void addLatLon2D(CoverageCollection subsetDataset, Group.Builder group) {
  HorizCoordSys horizCoordSys = subsetDataset.getHorizCoordSys();
  CoverageCoordAxis1D xAxis = horizCoordSys.getXAxis();
  CoverageCoordAxis1D yAxis = horizCoordSys.getYAxis();

  Dimension xDim = group.findDimension(xAxis.getName())
      .orElseThrow(() -> new IllegalStateException("We should've added X dimension in addDimensions()."));
  Dimension yDim = group.findDimension(yAxis.getName())
      .orElseThrow(() -> new IllegalStateException("We should've added Y dimension in addDimensions()."));

  List<Dimension> dims = Arrays.asList(yDim, xDim);

  Variable.Builder latVar = Variable.builder().setName("lat").setDataType(DataType.DOUBLE).setDimensions(dims);
  latVar.addAttribute(new Attribute(CDM.UNITS, CDM.LAT_UNITS));
  latVar.addAttribute(new Attribute(CF.STANDARD_NAME, CF.LATITUDE));
  latVar.addAttribute(new Attribute(CDM.LONG_NAME, "latitude coordinate"));
  latVar.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Lat.toString()));
  group.addVariable(latVar);

  Variable.Builder lonVar = Variable.builder().setName("lon").setDataType(DataType.DOUBLE).setDimensions(dims);
  lonVar.addAttribute(new Attribute(CDM.UNITS, CDM.LON_UNITS));
  lonVar.addAttribute(new Attribute(CF.STANDARD_NAME, CF.LONGITUDE));
  lonVar.addAttribute(new Attribute(CDM.LONG_NAME, "longitude coordinate"));
  lonVar.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Lon.toString()));
  group.addVariable(lonVar);
}
 
Example #7
Source File: Suomi.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void augmentDataset(NetcdfDataset ds, CancelTask cancelTask) {
  String start_date = ds.findAttValueIgnoreCase(null, "start_date", null);
  if (start_date == null)
    return;

  SimpleDateFormat df = new SimpleDateFormat("yyyy.DDD.HH.mm.ss"); // "2006.105.00.00.00"
  DateFormatter dfo = new DateFormatter();

  Date start;
  try {
    start = df.parse(start_date);
  } catch (ParseException e) {
    throw new RuntimeException("Cant read start_date=" + start_date);
  }

  Variable v = ds.findVariable("time_offset");
  v.addAttribute(new Attribute(CDM.UNITS, "seconds since " + dfo.toDateTimeString(start)));

  Group root = ds.getRootGroup();
  root.addAttribute(new Attribute(CDM.CONVENTIONS, "Suomi-Station-CDM"));
  ds.finish();
}
 
Example #8
Source File: WRFConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private CoordinateAxis makeYCoordAxis(NetcdfDataset ds, String axisName, Dimension dim) {
  if (dim == null)
    return null;
  double dy = findAttributeDouble(ds, "DY") / 1000.0;
  int ny = dim.getLength();
  double starty = centerY - dy * (ny - 1) / 2; // - dy/2; // ya just gotta know

  CoordinateAxis v = new CoordinateAxis1D(ds, null, axisName, DataType.DOUBLE, dim.getShortName(), "km",
      "synthesized GeoY coordinate from DY attribute");
  v.setValues(ny, starty, dy);
  v.addAttribute(new Attribute(_Coordinate.AxisType, "GeoY"));
  if (!axisName.equals(dim.getShortName()))
    v.addAttribute(new Attribute(_Coordinate.AliasForDimension, dim.getShortName()));

  if (gridE)
    v.addAttribute(new Attribute(_Coordinate.Stagger, CDM.ARAKAWA_E));
  return v;
}
 
Example #9
Source File: TestGribCoverageBuilding.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testGaussianLats() throws IOException {
  String filename = TestDir.cdmUnitTestDir + "formats/grib1/cfs.wmo";
  try (FeatureDatasetCoverage cc = CoverageDatasetFactory.open(filename)) {
    Assert.assertNotNull(filename, cc);
    String gridName = "Albedo_surface_Average";

    Assert.assertEquals(1, cc.getCoverageCollections().size());
    CoverageCollection cd = cc.getCoverageCollections().get(0);
    Coverage cov = cd.findCoverage(gridName);
    Assert.assertNotNull(gridName, cov);
    CoverageCoordSys csys = cov.getCoordSys();
    Assert.assertNotNull("CoverageCoordSys", csys);

    CoverageCoordAxis latAxis = csys.getAxis(AxisType.Lat);
    Assert.assertNotNull(AxisType.RunTime.toString(), latAxis);
    Assert.assertTrue(latAxis.getClass().getName(), latAxis instanceof CoverageCoordAxis1D);
    Assert.assertEquals(CoverageCoordAxis.Spacing.irregularPoint, latAxis.getSpacing());
    Assert.assertEquals(CoverageCoordAxis.DependenceType.independent, latAxis.getDependenceType());

    Attribute att = latAxis.findAttribute(CDM.GAUSSIAN);
    Assert.assertNotNull(att);
    Assert.assertEquals("true", att.getStringValue());
  }
}
 
Example #10
Source File: AWIPSConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private CoordinateAxis makeLatCoordAxis(NetcdfDataset ds, int n, String xname) {
  double min = findAttributeDouble(ds, "yMin");
  double max = findAttributeDouble(ds, "yMax");
  double d = findAttributeDouble(ds, "dy");
  if (Double.isNaN(min) || Double.isNaN(max) || Double.isNaN(d))
    return null;

  CoordinateAxis v = new CoordinateAxis1D(ds, null, xname, DataType.DOUBLE, xname, CDM.LAT_UNITS, "latitude");
  v.setValues(n, min, d);
  v.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Lat.toString()));

  double maxCalc = min + d * n;
  parseInfo.format("Created Lat Coordinate Axis (max calc= %f should be = %f)%n", maxCalc, max);
  v.getNameAndDimensions(parseInfo, true, false);
  parseInfo.format("%n");

  return v;
}
 
Example #11
Source File: TestStream.java    From tds with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testString() throws URISyntaxException, IOException {
  String catalogName = "http://localhost:8081/thredds/catalog.xml";
  URI catalogURI = new URI(catalogName);

  try (HTTPSession client = HTTPFactory.newSession(catalogName)) {
    HTTPMethod m = HTTPFactory.Get(client, catalogName);

    int statusCode = m.execute();
    logger.debug("status = {}", statusCode);

    String catAsString = m.getResponseAsString(CDM.UTF8);
    logger.debug("cat = {}", catAsString);

    CatalogBuilder builder = new CatalogBuilder();
    Catalog cat = builder.buildFromString(catAsString, catalogURI);
    CatalogXmlWriter writer = new CatalogXmlWriter();

    try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
      writer.writeXML(cat, baos, false);
      logger.debug(baos.toString());
    }
  }
}
 
Example #12
Source File: TimeHelper.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static TimeHelper factory(String units, AttributeContainer atts) {
  if (units == null)
    units = atts.findAttributeString(CDM.UDUNITS, null);
  if (units == null)
    units = atts.findAttributeString(CDM.UNITS, null);
  if (units == null)
    throw new IllegalStateException("No units");

  Calendar cal = getCalendarFromAttribute(atts);
  CalendarDateUnit dateUnit;
  try {
    dateUnit = CalendarDateUnit.withCalendar(cal, units); // this will throw exception on failure
    return new TimeHelper(dateUnit);
  } catch (IllegalArgumentException e) {
    return null;
  }
}
 
Example #13
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 #14
Source File: OceanS.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Create a new vertical transform for Ocean S coordinates
 *
 * @param ds dataset
 * @param timeDim time dimension
 * @param params list of transformation Parameters
 */
public OceanS(NetcdfFile ds, Dimension timeDim, List<Parameter> params) {

  super(timeDim);
  String etaName = getParameterStringValue(params, ETA);
  String sName = getParameterStringValue(params, S);
  String depthName = getParameterStringValue(params, DEPTH);
  String aName = getParameterStringValue(params, A);
  String bName = getParameterStringValue(params, B);
  String depthCName = getParameterStringValue(params, DEPTH_C);

  etaVar = ds.findVariable(etaName);
  sVar = ds.findVariable(sName);
  depthVar = ds.findVariable(depthName);
  aVar = ds.findVariable(aName);
  bVar = ds.findVariable(bName);
  depthCVar = ds.findVariable(depthCName);

  units = depthVar.findAttributeString(CDM.UNITS, "none");
}
 
Example #15
Source File: RecordDatasetHelper.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void setLocationInfo(String latVName, String lonVName, String zcoordVName) {
  this.latVName = latVName;
  this.lonVName = lonVName;
  this.zcoordVName = zcoordVName;

  // check for meter conversion
  if (zcoordVName != null) {
    Variable v = ncfile.findVariable(zcoordVName);
    zcoordUnits = ncfile.findAttValueIgnoreCase(v, CDM.UNITS, null);
    if (zcoordUnits != null)
      try {
        altScaleFactor = getMetersConversionFactor(zcoordUnits);
      } catch (Exception e) {
        if (errs != null)
          errs.format("%s", e.getMessage());
      }
  }
}
 
Example #16
Source File: CatalogBuilder.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected ThreddsMetadata.GeospatialCoverage readGeospatialCoverage(Element gcElem) {
  if (gcElem == null) {
    return null;
  }

  String zpositive = gcElem.getAttributeValue("zpositive");

  ThreddsMetadata.GeospatialRange northsouth =
      readGeospatialRange(gcElem.getChild("northsouth", Catalog.defNS), CDM.LAT_UNITS);
  ThreddsMetadata.GeospatialRange eastwest =
      readGeospatialRange(gcElem.getChild("eastwest", Catalog.defNS), CDM.LON_UNITS);
  ThreddsMetadata.GeospatialRange updown = readGeospatialRange(gcElem.getChild("updown", Catalog.defNS), "m");

  // look for names
  List<ThreddsMetadata.Vocab> names = new ArrayList<>();
  java.util.List<Element> list = gcElem.getChildren("name", Catalog.defNS);
  for (Element e : list) {
    ThreddsMetadata.Vocab name = readControlledVocabulary(e);
    names.add(name);
  }

  return new ThreddsMetadata.GeospatialCoverage(eastwest, northsouth, updown, names, zpositive);
}
 
Example #17
Source File: Mercator.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Construct a Mercator Projection.
 *
 * @param lon0 longitude of origin (degrees)
 * @param par standard parallel (degrees). cylinder cuts earth at this latitude.
 * @param false_easting false_easting in km
 * @param false_northing false_northing in km
 * @param radius earth radius in km
 */
public Mercator(double lon0, double par, double false_easting, double false_northing, double radius) {
  super("Mercator", false);

  this.lon0 = lon0;
  this.par = par;
  this.falseEasting = false_easting;
  this.falseNorthing = false_northing;
  this.earthRadius = radius;

  this.par_r = Math.toRadians(par);

  precalculate();

  addParameter(CF.GRID_MAPPING_NAME, CF.MERCATOR);
  addParameter(CF.LONGITUDE_OF_PROJECTION_ORIGIN, lon0);
  addParameter(CF.STANDARD_PARALLEL, par);
  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 #18
Source File: Variable.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Returns {@code true} if this variable contains data that are already in the unit of measurement represented by
 * {@link #getUnit()}, except for the fill/missing values. If {@code true}, then replacing fill/missing values by
 * {@code NaN} is the only action needed for having converted values.
 *
 * <p>This method is for detecting when {@link RasterResource#getSampleDimensions()} should return sample dimensions
 * for already converted values. But to be consistent with {@code SampleDimension} contract, it requires fill/missing
 * values to be replaced by NaN. This is done by {@link #replaceNaN(Object)}.</p>
 *
 * @return whether this variable contains values in unit of measurement, ignoring fill and missing values.
 */
final boolean hasRealValues() {
    final int n = getDataType().number;
    if (n == Numbers.FLOAT | n == Numbers.DOUBLE) {
        final Convention convention = decoder.convention();
        if (convention != Convention.DEFAULT) {
            return convention.transferFunction(this).isIdentity();
        }
        // Shortcut for common case.
        double c = getAttributeAsNumber(CDM.SCALE_FACTOR);
        if (Double.isNaN(c) || c == 1) {
            c = getAttributeAsNumber(CDM.ADD_OFFSET);
            return Double.isNaN(c) || c == 0;
        }
    }
    return false;
}
 
Example #19
Source File: AbstractTransformBuilder.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static String getGeoCoordinateUnits(NetcdfDataset ds, AttributeContainer ctv) {
  String units = ctv.findAttributeString(CDM.UNITS, null);
  if (units == null) {
    List<CoordinateAxis> axes = ds.getCoordinateAxes();
    for (CoordinateAxis axis : axes) {
      if (axis.getAxisType() == AxisType.GeoX) { // kludge - what if there's multiple ones?
        Variable v = axis.getOriginalVariable(); // LOOK why original variable ?
        units = (v == null) ? axis.getUnitsString() : v.getUnitsString();
        break;
      }
    }
    if (units == null) {
      Variable xvar = ds.findVariableByAttribute(null, _Coordinate.AxisType.toString(), AxisType.GeoX.toString());
      if (xvar != null) {
        units = xvar.getUnitsString();
      }
    }
  }
  return units;
}
 
Example #20
Source File: NmcObsLegacy.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private Structure makeReportIndexStructure() throws InvalidRangeException {
  Structure reportIndex = new Structure(ncfile, null, null, "reportIndex");
  reportIndex.setDimensions("report");

  reportIndex.addAttribute(new Attribute(CDM.LONG_NAME, "index on report - in memory"));
  int pos = 0;

  Variable v =
      reportIndex.addMemberVariable(new Variable(ncfile, null, reportIndex, "stationName", DataType.CHAR, ""));
  v.setDimensionsAnonymous(new int[] {6});
  v.addAttribute(new Attribute(CDM.LONG_NAME, "name of station"));
  v.addAttribute(new Attribute("standard_name", "station_name"));
  v.setSPobject(new Vinfo(pos));
  pos += 6;

  v = reportIndex.addMemberVariable(new Variable(ncfile, null, reportIndex, "time", DataType.INT, ""));
  v.addAttribute(new Attribute(CDM.UNITS, "secs since 1970-01-01 00:00"));
  v.addAttribute(new Attribute(CDM.LONG_NAME, "observation time"));
  v.setSPobject(new Vinfo(pos));

  return reportIndex;
}
 
Example #21
Source File: WRFConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private CoordinateAxis makeXCoordAxis(NetcdfDataset ds, String axisName, Dimension dim) {
  if (dim == null)
    return null;
  double dx = findAttributeDouble(ds, "DX") / 1000.0; // km ya just gotta know
  int nx = dim.getLength();
  double startx = centerX - dx * (nx - 1) / 2; // ya just gotta know

  CoordinateAxis v = new CoordinateAxis1D(ds, null, axisName, DataType.DOUBLE, dim.getShortName(), "km",
      "synthesized GeoX coordinate from DX attribute");
  v.setValues(nx, startx, dx);
  v.addAttribute(new Attribute(_Coordinate.AxisType, "GeoX"));
  if (!axisName.equals(dim.getShortName()))
    v.addAttribute(new Attribute(_Coordinate.AliasForDimension, dim.getShortName()));

  if (gridE)
    v.addAttribute(new Attribute(_Coordinate.Stagger, CDM.ARAKAWA_E));
  return v;
}
 
Example #22
Source File: NmcObsLegacy.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void open(RandomAccessFile raf, NetcdfFile ncfile, CancelTask cancelTask) throws IOException {
  super.open(raf, ncfile, cancelTask);

  init();

  ncfile.addAttribute(null, new Attribute(CDM.HISTORY, "Direct read of NMC ON29 by CDM"));
  ncfile.addAttribute(null, new Attribute(CDM.CONVENTIONS, "Unidata"));
  ncfile.addAttribute(null, new Attribute(CF.FEATURE_TYPE, CF.FeatureType.timeSeriesProfile.toString()));

  try {
    ncfile.addDimension(null, new Dimension("station", stations.size()));
    Structure station = makeStationStructure();
    ncfile.addVariable(null, station);

    ncfile.addDimension(null, new Dimension("report", reports.size()));
    Structure reportIndexVar = makeReportIndexStructure();
    ncfile.addVariable(null, reportIndexVar);

    Structure reportVar = makeReportStructure();
    ncfile.addVariable(null, reportVar);

  } catch (InvalidRangeException e) {
    logger.error("open ON29 File", e);
    throw new IllegalStateException(e.getMessage());
  }
}
 
Example #23
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 #24
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 #25
Source File: OceanSG1.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Create a new vertical transform for Ocean_S_coordinate_g1
 *
 * @param ds dataset
 * @param timeDim time dimension
 * @param params list of transformation Parameters
 */
public OceanSG1(NetcdfFile ds, Dimension timeDim, List<Parameter> params) {

  super(timeDim);
  String etaName = getParameterStringValue(params, ETA);
  String sName = getParameterStringValue(params, S);
  String depthName = getParameterStringValue(params, DEPTH);
  String depthCName = getParameterStringValue(params, DEPTH_C);
  String cName = getParameterStringValue(params, C);

  etaVar = ds.findVariable(etaName);
  sVar = ds.findVariable(sName);
  depthVar = ds.findVariable(depthName);
  depthCVar = ds.findVariable(depthCName);
  cVar = ds.findVariable(cName);

  units = depthVar.findAttributeString(CDM.UNITS, "none");
}
 
Example #26
Source File: VariableDS.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public T setUnits(String units) {
  this.units = units;
  if (units != null) {
    this.units = units.trim();
    addAttribute(new Attribute(CDM.UNITS, this.units));
  }
  return self();
}
 
Example #27
Source File: VariableDS.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public String getDescription() {
  String result = desc;
  if (result == null) {
    result = getAttributeContainer().findAttributeString(CDM.LONG_NAME, null);
  }
  if (result == null && orgVar != null) {
    result = orgVar.attributes().findAttributeString(CDM.LONG_NAME, null);
  }
  return (result == null) ? null : result.trim();
}
 
Example #28
Source File: Construct2.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void annotate(Variable v, BufrConfig.FieldConverter fld) {
  if (fld.type == null)
    return;

  switch (fld.type) {
    case lat:
      v.addAttribute(new Attribute(CDM.UNITS, CDM.LAT_UNITS));
      v.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Lat.toString()));
      coordinates.format("%s ", v.getShortName());
      break;

    case lon:
      v.addAttribute(new Attribute(CDM.UNITS, CDM.LON_UNITS));
      v.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Lon.toString()));
      coordinates.format("%s ", v.getShortName());
      break;

    case height:
    case heightOfStation:
    case heightAboveStation:
      v.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Height.toString()));
      coordinates.format("%s ", v.getShortName());
      break;

    case stationId:
      v.addAttribute(new Attribute(CF.STANDARD_NAME, CF.STATION_ID));
      break;

    case wmoId:
      v.addAttribute(new Attribute(CF.STANDARD_NAME, CF.STATION_WMOID));
      break;
  }

}
 
Example #29
Source File: AWIPSSatConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected AxisType getAxisType(VariableDS.Builder v) {
  String units = v.getUnits();

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

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

  return super.getAxisType(v);
}
 
Example #30
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 = 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(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 = 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);
  }
}