ucar.nc2.dataset.CoordinateAxis1D Java Examples

The following examples show how to use ucar.nc2.dataset.CoordinateAxis1D. 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: VariableWrapper.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the scale and offset coefficients in the given "grid to CRS" transform if possible.
 * This method is invoked only for variables that represent a coordinate system axis.
 */
@Override
protected boolean trySetTransform(final Matrix gridToCRS, final int srcDim, final int tgtDim, final Vector values)
        throws IOException, DataStoreException
{
    if (variable instanceof CoordinateAxis1D) {
        final CoordinateAxis1D axis = (CoordinateAxis1D) variable;
        if (axis.isRegular()) {
            final double start     = axis.getStart();
            final double increment = axis.getIncrement();
            if (start != 0 || increment != 0) {
                gridToCRS.setElement(tgtDim, srcDim, increment);
                gridToCRS.setElement(tgtDim, gridToCRS.getNumCol() - 1, start);
                return true;
            }
            /*
             * The UCAR library sometime left those information uninitialized.
             * If it seems to be the case, fallback on our own code.
             */
        }
    }
    return super.trySetTransform(gridToCRS, srcDim, tgtDim, values);
}
 
Example #2
Source File: WRFConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Nullable
private CoordinateAxis.Builder makeLatCoordAxis(String axisName, Dimension dim) {
  if (dim == null)
    return null;
  double dy = findAttributeDouble("DY");
  int ny = dim.getLength();
  double starty = centerY - dy * (ny - 1) / 2;

  CoordinateAxis.Builder v = CoordinateAxis1D.builder().setName(axisName).setDataType(DataType.DOUBLE)
      .setDimensionsByName(dim.getShortName()).setUnits("degrees_north").setDesc("synthesized latitude coordinate");
  v.setAutoGen(starty, dy);
  v.setAxisType(AxisType.Lat);
  v.addAttribute(new Attribute(_Coordinate.AxisType, "Lat"));
  if (!axisName.equals(dim.getShortName()))
    v.addAttribute(new Attribute(_Coordinate.AliasForDimension, dim.getShortName()));

  return v;
}
 
Example #3
Source File: WRFConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Nullable
private CoordinateAxis.Builder makeLonCoordAxis(String axisName, Dimension dim) {
  if (dim == null)
    return null;
  double dx = 4 * findAttributeDouble("DX");
  int nx = dim.getLength();
  double startx = centerX - dx * (nx - 1) / 2;

  CoordinateAxis.Builder v = CoordinateAxis1D.builder().setName(axisName).setDataType(DataType.DOUBLE)
      .setDimensionsByName(dim.getShortName()).setUnits("degrees_east").setDesc("synthesized longitude coordinate");
  v.setAutoGen(startx, dx);
  v.setAxisType(AxisType.Lon);
  v.addAttribute(new Attribute(_Coordinate.AxisType, "Lon"));
  if (!axisName.equals(dim.getShortName()))
    v.addAttribute(new Attribute(_Coordinate.AliasForDimension, dim.getShortName()));

  return v;
}
 
Example #4
Source File: WRFConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Nullable
private CoordinateAxis.Builder makeXCoordAxis(String axisName, String dimName) {
  Optional<Dimension> dimOpt = rootGroup.findDimension(dimName);
  if (!dimOpt.isPresent()) {
    return null;
  }
  Dimension dim = dimOpt.get();
  double dx = findAttributeDouble("DX") / 1000.0; // km ya just gotta know
  int nx = dim.getLength();
  double startx = centerX - dx * (nx - 1) / 2; // ya just gotta know

  CoordinateAxis.Builder v = CoordinateAxis1D.builder().setName(axisName).setDataType(DataType.DOUBLE)
      .setParentGroupBuilder(rootGroup).setDimensionsByName(dim.getShortName()).setUnits("km")
      .setDesc("synthesized GeoX coordinate from DX attribute");
  v.setAutoGen(startx, dx);
  v.setAxisType(AxisType.GeoX);
  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 #5
Source File: WRFConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Nullable
private CoordinateAxis.Builder makeYCoordAxis(String axisName, String dimName) {
  Optional<Dimension> dimOpt = rootGroup.findDimension(dimName);
  if (!dimOpt.isPresent()) {
    return null;
  }
  Dimension dim = dimOpt.get();
  double dy = findAttributeDouble("DY") / 1000.0;
  int ny = dim.getLength();
  double starty = centerY - dy * (ny - 1) / 2; // - dy/2; // ya just gotta know

  CoordinateAxis.Builder v = CoordinateAxis1D.builder().setName(axisName).setDataType(DataType.DOUBLE)
      .setParentGroupBuilder(rootGroup).setDimensionsByName(dim.getShortName()).setUnits("km")
      .setDesc("synthesized GeoY coordinate from DY attribute");
  v.setAxisType(AxisType.GeoY);
  v.addAttribute(new Attribute(_Coordinate.AxisType, "GeoY"));
  v.setAutoGen(starty, dy);
  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 #6
Source File: ADASConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void makeCoordAxis(String axisName) throws IOException {
  String name = axisName + "_stag";
  if (!rootGroup.findVariableLocal(name).isPresent()) {
    return;
  }
  VariableDS.Builder stagV = (VariableDS.Builder) rootGroup.findVariableLocal(name).get();
  Array data_stag = stagV.orgVar.read();
  int n = (int) data_stag.getSize() - 1;
  DataType dt = DataType.getType(data_stag);
  Array data = Array.factory(dt, new int[] {n});
  Index stagIndex = data_stag.getIndex();
  Index dataIndex = data.getIndex();
  for (int i = 0; i < n; i++) {
    double val = data_stag.getDouble(stagIndex.set(i)) + data_stag.getDouble(stagIndex.set(i + 1));
    data.setDouble(dataIndex.set(i), 0.5 * val);
  }

  DataType dtype = DataType.getType(data);
  String units = stagV.getAttributeContainer().findAttributeString(CDM.UNITS, "m");
  CoordinateAxis.Builder cb = CoordinateAxis1D.builder().setName(axisName).setDataType(dtype)
      .setParentGroupBuilder(rootGroup).setDimensionsByName(axisName).setUnits(units)
      .setDesc("synthesized non-staggered " + axisName + " coordinate");
  cb.setCachedData(data, true);
  datasetBuilder.replaceCoordinateAxis(rootGroup, cb);
}
 
Example #7
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 #8
Source File: AWIPSConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private CoordinateAxis makeLonCoordAxis(NetcdfDataset ds, int n, String xname) {
  double min = findAttributeDouble(ds, "xMin");
  double max = findAttributeDouble(ds, "xMax");
  double d = findAttributeDouble(ds, "dx");
  if (Double.isNaN(min) || Double.isNaN(max) || Double.isNaN(d))
    return null;

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

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

  return v;
}
 
Example #9
Source File: HdfEosModisConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private boolean addTimeCoordinate() {
  // add time coordinate by parsing the filename, of course.
  CalendarDate cd = parseFilenameForDate(datasetBuilder.orgFile.getLocation());
  if (cd == null) {
    return false;
  }

  rootGroup.addAttribute(new Attribute("_MODIS_Date", cd.toString()));

  // add the time dimension
  rootGroup.addDimension(new Dimension(TIME_NAME, 1));

  // add the coordinate variable
  String units = "seconds since " + cd;
  CoordinateAxis.Builder timeCoord = CoordinateAxis1D.builder().setName(TIME_NAME).setDataType(DataType.DOUBLE)
      .setParentGroupBuilder(rootGroup).setDimensionsByName("").setUnits(units).setDesc("time coordinate");
  timeCoord.setAutoGen(0, 0);
  timeCoord.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Time.toString()));
  datasetBuilder.replaceCoordinateAxis(rootGroup, timeCoord);

  return true;
}
 
Example #10
Source File: VertPanel.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void setSlice(int slice) {

    if (isLatLon) {
      leftScale.setText(LatLonPoints.latToString(yleft, 3));
      midScale.setText(LatLonPoints.latToString(ymid, 3));
      rightScale.setText(LatLonPoints.latToString(yright, 3));
      return;
    }
    double xval;

    if ((xaxis != null) && (xaxis instanceof CoordinateAxis1D)) {
      xval = ((CoordinateAxis1D) xaxis).getCoordValue(slice);

      // set bottom scale
      leftScale.setText(getYstr(xval, yleft));
      midScale.setText(getYstr(xval, ymid));
      rightScale.setText(getYstr(xval, yright));
    }

    repaint();
  }
 
Example #11
Source File: GridAsPointDataset.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public Point readData(GridDatatype grid, CalendarDate date, double zCoord, double lat, double lon)
    throws java.io.IOException {
  GridCoordSystem gcs = grid.getCoordinateSystem();

  int tidx = -1;
  // Date may be null if the grid does not have time axis
  if (date != null)
    tidx = findTimeIndexForCalendarDate(gcs, date);

  CoordinateAxis1D zAxis = gcs.getVerticalAxis();
  int zidx = zAxis.findCoordElement(zCoord);

  int[] xy = gcs.findXYindexFromLatLon(lat, lon, null);

  Array data = grid.readDataSlice(tidx, zidx, xy[1], xy[0]);

  // use actual grid midpoint
  LatLonPoint latlon = gcs.getLatLon(xy[0], xy[1]);

  Point p = new Point();
  p.lat = latlon.getLatitude();
  p.lon = latlon.getLongitude();
  p.z = zAxis.getCoordValue(zidx);
  p.dataValue = data.getDouble(data.getIndex());
  return p;
}
 
Example #12
Source File: AWIPSConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private CoordinateAxis.Builder makeLatCoordAxis(int n, String name) {
  double min = findAttributeDouble("yMin");
  double max = findAttributeDouble("yMax");
  double d = findAttributeDouble("dy");
  if (Double.isNaN(min) || Double.isNaN(max) || Double.isNaN(d))
    return null;

  CoordinateAxis1D.Builder v = CoordinateAxis1D.builder().setName(name).setDataType(DataType.DOUBLE)
      .setParentGroupBuilder(rootGroup).setDimensionsByName(name).setUnits(CDM.LAT_UNITS).setDesc("latitude");
  v.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Lat.toString()));
  v.setAutoGen(min, d);

  double maxCalc = min + d * n;
  parseInfo.format("Created Lat Coordinate Axis (max calc= %f should be = %f)%n", maxCalc, max);
  return v;
}
 
Example #13
Source File: GridRenderer.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @return x index for given point
 */
public int findSliceFromPoint(ProjectionPoint pp) {
  if ((null == drawProjection) || (null == stridedGrid))
    return -1;

  // convert to dataProjection, where x and y are orthogonal
  if (!sameProjection) {
    LatLonPoint llpt = drawProjection.projToLatLon(pp);
    pp = dataProjection.latLonToProj(llpt);
  }

  // find the grid index
  GridCoordSystem geocs = stridedGrid.getCoordinateSystem();
  CoordinateAxis xaxis = geocs.getXHorizAxis();
  if (!(xaxis instanceof CoordinateAxis1D))
    return -1;
  int[] index = geocs.findXYindexFromCoord(pp.getX(), pp.getY(), null);
  return index[0];
}
 
Example #14
Source File: AWIPSConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Nullable
private CoordinateAxis.Builder makeLonCoordAxis(int n, String xname) {
  double min = findAttributeDouble("xMin");
  double max = findAttributeDouble("xMax");
  double d = findAttributeDouble("dx");
  if (Double.isNaN(min) || Double.isNaN(max) || Double.isNaN(d))
    return null;

  CoordinateAxis1D.Builder v = CoordinateAxis1D.builder().setName(xname).setDataType(DataType.DOUBLE)
      .setParentGroupBuilder(rootGroup).setDimensionsByName(xname).setUnits(CDM.LON_UNITS).setDesc("longitude");
  v.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Lon.toString()));
  v.setAutoGen(min, d);

  double maxCalc = min + d * n;
  parseInfo.format("Created Lon Coordinate Axis (max calc= %f should be = %f)%n", maxCalc, max);
  return v;
}
 
Example #15
Source File: GridRenderer.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * find the data value at this point
 *
 * @param loc : point in display projection coordinates (vertical view)
 * @return String representation of value
 */
public String getYZvalueStr(Point2D loc) {
  if ((stridedGrid == null) || (dataV == null))
    return "";

  // find the grid indexes
  GridCoordSystem geocs = stridedGrid.getCoordinateSystem();
  CoordinateAxis1D zaxis = geocs.getVerticalAxis();
  if (zaxis == null)
    return "";

  valueIndex = geocs.findXYindexFromCoord(loc.getX(), lastSlice, valueIndex);

  int wanty = valueIndex[1];
  int wantz = zaxis.findCoordElement(loc.getY());

  // get value, construct the string
  if ((wanty == -1) || (wantz == -1))
    return "outside grid area";
  else {
    Index imaV = dataV.getIndex();
    double value = dataV.getDouble(imaV.set(wantz, wanty));
    int wantx = (geocs.getXHorizAxis() == null) ? -1 : lastSlice;
    return makeXYZvalueStr(value, wantx, wanty, wantz);
  }
}
 
Example #16
Source File: ThreddsMetadataExtractor.java    From tds with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public ThreddsMetadata.GeospatialCoverage extractGeospatial(GridDataset gridDataset) {
  LatLonRect llbb = null;
  CoordinateAxis1D vaxis = null;

  for (GridDataset.Gridset gridset : gridDataset.getGridsets()) {
    GridCoordSystem gsys = gridset.getGeoCoordSystem();
    if (llbb == null)
      llbb = gsys.getLatLonBoundingBox();

    CoordinateAxis1D vaxis2 = gsys.getVerticalAxis();
    if (vaxis == null)
      vaxis = vaxis2;
    else if ((vaxis2 != null) && (vaxis2.getSize() > vaxis.getSize()))
      vaxis = vaxis2;
  }

  return new ThreddsMetadata.GeospatialCoverage(llbb, vaxis, 0.0, 0.0); // LOOK can we extract dx, dy ?
}
 
Example #17
Source File: MetadataExtractor.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static ThreddsMetadata.GeospatialCoverage extractGeospatial(GridDataset gridDataset) {
  ThreddsMetadata.GeospatialCoverage gc = new ThreddsMetadata.GeospatialCoverage();
  LatLonRect llbb = null;
  CoordinateAxis1D vaxis = null;

  for (GridDataset.Gridset gridset : gridDataset.getGridsets()) {
    GridCoordSystem gsys = gridset.getGeoCoordSystem();
    if (llbb == null)
      llbb = gsys.getLatLonBoundingBox();

    CoordinateAxis1D vaxis2 = gsys.getVerticalAxis();
    if (vaxis == null)
      vaxis = vaxis2;
    else if ((vaxis2 != null) && (vaxis2.getSize() > vaxis.getSize()))
      vaxis = vaxis2;
  }

  if (llbb != null)
    gc.setBoundingBox(llbb);
  if (vaxis != null)
    gc.setVertical(vaxis);
  return gc;
}
 
Example #18
Source File: M3IOConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void makeZCoordAxis(String dimName, String levelsName, String unitName) {
  Dimension dimz = rootGroup.findDimension(dimName).get();
  int nz = dimz.getLength();
  ArrayDouble.D1 dataLev = new ArrayDouble.D1(nz);
  ArrayDouble.D1 dataLayers = new ArrayDouble.D1(nz + 1);

  // layer values are a numeric global attribute array !!
  Attribute layers = rootGroup.getAttributeContainer().findAttribute(levelsName);
  for (int i = 0; i <= nz; i++)
    dataLayers.set(i, layers.getNumericValue(i).doubleValue());

  for (int i = 0; i < nz; i++) {
    double midpoint = (dataLayers.get(i) + dataLayers.get(i + 1)) / 2;
    dataLev.set(i, midpoint);
  }

  CoordinateAxis.Builder v = CoordinateAxis1D.builder().setName("level").setDataType(DataType.DOUBLE)
      .setParentGroupBuilder(rootGroup).setDimensionsByName(dimName).setUnits(unitName)
      .setDesc("synthesized coordinate from " + levelsName + " global attributes");
  v.setCachedData(dataLev, true);
  v.addAttribute(new Attribute("positive", "down"));
  v.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.GeoZ.toString()));

  // layer edges
  String edge_name = "layer";
  Dimension lay_edge = new Dimension(edge_name, nz + 1);
  rootGroup.addDimension(lay_edge);
  CoordinateAxis.Builder vedge = CoordinateAxis1D.builder().setName(edge_name).setDataType(DataType.DOUBLE)
      .setParentGroupBuilder(rootGroup).setDimensionsByName(edge_name).setUnits(unitName)
      .setDesc("synthesized coordinate from " + levelsName + " global attributes");
  vedge.setCachedData(dataLayers, true);
  v.setBoundary(edge_name);

  datasetBuilder.replaceCoordinateAxis(rootGroup, v);
  datasetBuilder.replaceCoordinateAxis(rootGroup, vedge);
}
 
Example #19
Source File: NUWGConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
void makeYCoordAxis(String yname) {
  CoordinateAxis.Builder v = CoordinateAxis1D.builder().setName(yname).setDataType(DataType.DOUBLE)
      .setParentGroupBuilder(rootGroup).setDimensionsByName(yname).setUnits((0 == grid_code) ? CDM.LAT_UNITS : "km")
      .setDesc("synthesized Y coord");
  v.addAttribute(
      new Attribute(_Coordinate.AxisType, (0 == grid_code) ? AxisType.Lat.toString() : AxisType.GeoY.toString()));
  v.setAutoGen(starty, dy);
  datasetBuilder.replaceCoordinateAxis(rootGroup, v);
}
 
Example #20
Source File: TestDtWithCoverageBuilding.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testGaussianLats() throws IOException {

  String filename = TestDir.cdmUnitTestDir + "formats/grib1/cfs.wmo";

  try (DtCoverageDataset gds = DtCoverageDataset.open(filename)) {
    Assert.assertNotNull(filename, gds);
    String gridName = "Albedo_surface_1_Month_Average";

    DtCoverage grid = gds.findGridByShortName(gridName);
    Assert.assertNotNull(gridName, grid);

    DtCoverageCS gcs = grid.getCoordinateSystem();
    Assert.assertNotNull(gridName + " cs", gcs);
    Assert.assertEquals("ucar.nc2.ft2.coverage.adapter.GridCS", gcs.getClass().getName());
    GridCS gridCS = (GridCS) gcs;

    CoordinateAxis1D latAxis = gridCS.getYHorizAxis();
    Assert.assertNotNull("latAxis axis", latAxis);
    Assert.assertTrue(!latAxis.isRegular());
    Attribute att = latAxis.findAttribute(CDM.GAUSSIAN);
    Assert.assertNotNull(att);
    Assert.assertEquals("true", att.getStringValue());

    Formatter errlog = new Formatter();
    try (FeatureDatasetCoverage cc = DtCoverageAdapter.factory(gds, errlog)) {
      Assert.assertNotNull(filename, cc);
      Assert.assertEquals(1, cc.getCoverageCollections().size());
      CoverageCollection cd = cc.getCoverageCollections().get(0);
      Coverage cov = cd.findCoverage(gridName);
      Assert.assertNotNull(gridName, cov);

      CoverageCoordAxis cca = cd.findCoordAxis(latAxis.getShortName());
      Assert.assertNotNull(latAxis.getShortName(), cca);
      Assert.assertEquals(CoverageCoordAxis.Spacing.irregularPoint, cca.getSpacing());
    }
  }
}
 
Example #21
Source File: GridRenderer.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * find the level (z) index that is represented by this point
 *
 * @param pos coord in data z coordinate space.
 */
public int findLevelCoordElement(double pos) {
  if (null == orgGrid)
    return -1;

  // find the grid index
  GridCoordSystem geocs = orgGrid.getCoordinateSystem();
  CoordinateAxis1D zaxis = geocs.getVerticalAxis();
  return (zaxis == null) ? -1 : zaxis.findCoordElement(pos);
}
 
Example #22
Source File: GridRenderer.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Get the (y,z) position from the vertical view coordinates.
 *
 * @param loc : point in display projection coordinates (vertical view)
 * @return String representation of position
 */
public String getYZpositionStr(Point2D loc) {
  if ((stridedGrid == null) || (dataV == null))
    return "";

  GridCoordSystem geocs = stridedGrid.getCoordinateSystem();
  /*
   * CoordinateAxis1D xaxis = (CoordinateAxis1D) geocs.getXHorizAxis();
   * double x = (xaxis == null) ? 0.0 : xaxis.getCoordValue(lastSlice);
   * double y = loc.getX();
   * LatLonPointImpl lpt = dataProjection.projToLatLon(x, y);
   * sbuff.setLength(0);
   * sbuff.append(LatLonPointImpl.latToString(lpt.getLatitude(), 3));
   */

  StringBuilder sbuff = new StringBuilder();
  sbuff.setLength(0);
  sbuff.append(Format.d(loc.getX(), 3));
  CoordinateAxis yaxis = geocs.getYHorizAxis();
  sbuff.append(" ").append(yaxis.getUnitsString());
  sbuff.append(" ");
  sbuff.append(Format.d(loc.getY(), 3));
  CoordinateAxis1D zaxis = geocs.getVerticalAxis();
  sbuff.append(" ").append(zaxis.getUnitsString());

  return sbuff.toString();
}
 
Example #23
Source File: GridRenderer.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private int drawPathShape(Graphics2D g, int color, CoordinateAxis1D xaxis, CoordinateAxis1D yaxis) {
  int count = 0;
  for (int y = 0; y < yaxis.getSize() - 1; y++) {
    double y1 = yaxis.getCoordEdge(y);
    double y2 = yaxis.getCoordEdge(y + 1);
    count += drawPathRun(g, color, y1, y2, xaxis, 0, (int) xaxis.getSize() - 1);
  }

  return count;
}
 
Example #24
Source File: VertCoord.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
VertCoord(CoordinateAxis1D axis) {
  // this.axis = axis;
  this.name = axis.getFullName();
  this.units = axis.getUnitsString();

  int n = (int) axis.getSize();
  if (axis.isInterval()) {
    values1 = axis.getBound1();
    values2 = axis.getBound2();
  } else {
    values1 = new double[n];
    for (int i = 0; i < axis.getSize(); i++)
      values1[i] = axis.getCoordValue(i);
  }
}
 
Example #25
Source File: ThreddsMetadata.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void setVertical(CoordinateAxis1D vaxis) {
  int n = (int) vaxis.getSize();
  double size = vaxis.getCoordValue(n - 1) - vaxis.getCoordValue(0);
  double resolution = vaxis.getIncrement();
  String units = vaxis.getUnitsString();
  this.updown = new Range(vaxis.getCoordValue(0), size, resolution, units);
  if (units != null) {
    setZPositiveUp(SimpleUnit.isCompatible("m", units));
  }
}
 
Example #26
Source File: AWIPSConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
CoordinateAxis.Builder makeYCoordAxis(String yname) {
  CoordinateAxis1D.Builder v = CoordinateAxis1D.builder().setName(yname).setDataType(DataType.DOUBLE)
      .setParentGroupBuilder(rootGroup).setDimensionsByName(yname).setUnits("km").setDesc("y on projection");
  v.setAutoGen(starty, dy);

  parseInfo.format("Created Y Coordinate Axis = %s%n", yname);
  return v;
}
 
Example #27
Source File: M3IOConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private CoordinateAxis.Builder makeCoordAxis(String name, String dimName, String startName, String incrName,
    String unitName) {

  double start = .001 * findAttributeDouble(startName); // km
  double incr = .001 * findAttributeDouble(incrName); // km
  start = start + incr / 2.0; // shifting x and y to central
  CoordinateAxis.Builder v = CoordinateAxis1D.builder().setName(name).setDataType(DataType.DOUBLE)
      .setParentGroupBuilder(rootGroup).setDimensionsByName(dimName).setUnits(unitName)
      .setDesc("synthesized coordinate from " + startName + " " + incrName + " global attributes");
  v.setAutoGen(start, incr);
  return v;
}
 
Example #28
Source File: HdfEosOmiConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private CoordinateAxis.Builder makeLonCoordAxis(Group.Builder g2, int n, String dimName) {
  CoordinateAxis.Builder v = CoordinateAxis1D.builder().setName("lon").setDataType(DataType.FLOAT)
      .setParentGroupBuilder(g2).setDimensionsByName(dimName).setUnits(CDM.LON_UNITS).setDesc("longitude");

  double incr = 360.0 / n;
  v.setAutoGen(-180.0 + 0.5 * incr, incr);
  v.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Lon.toString()));
  return v;
}
 
Example #29
Source File: HdfEosOmiConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private CoordinateAxis.Builder makeLatCoordAxis(Group.Builder g2, int n, String dimName) {
  CoordinateAxis.Builder v = CoordinateAxis1D.builder().setName("lat").setDataType(DataType.FLOAT)
      .setParentGroupBuilder(g2).setDimensionsByName(dimName).setUnits(CDM.LAT_UNITS).setDesc("latitude");

  double incr = 180.0 / n;
  v.setAutoGen(-90.0 + 0.5 * incr, incr);
  v.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Lat.toString()));
  return v;
}
 
Example #30
Source File: AWIPSConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Nullable
private CoordinateAxis.Builder makeTimeCoordAxisFromReference(Array vals) {
  if (!rootGroup.findVariableLocal("reftime").isPresent())
    return null;
  VariableDS.Builder refVar = (VariableDS.Builder) rootGroup.findVariableLocal("reftime").get();

  double refValue;
  try {
    Array refArray = refVar.orgVar.read();
    refValue = refArray.getDouble(refArray.getIndex()); // get the first value
  } catch (IOException ioe) {
    return null;
  }
  if (refValue == N3iosp.NC_FILL_DOUBLE) // why?
    return null;

  // construct the values array - make it a double to be safe
  Array dvals = Array.factory(DataType.DOUBLE, vals.getShape());
  IndexIterator diter = dvals.getIndexIterator();
  IndexIterator iiter = vals.getIndexIterator();
  while (iiter.hasNext())
    diter.setDoubleNext(iiter.getDoubleNext() + refValue); // add reftime to each of the values

  String name = "timeCoord";
  String units = refVar.getAttributeContainer().findAttributeString(CDM.UNITS, "seconds since 1970-1-1 00:00:00");
  units = normalize(units);
  String desc = "synthesized time coordinate from reftime, valtimeMINUSreftime";
  CoordinateAxis1D.Builder timeCoord =
      CoordinateAxis1D.builder().setName(name).setDataType(DataType.DOUBLE).setParentGroupBuilder(rootGroup)
          .setDimensionsByName("record").setUnits(units).setDesc(desc).setCachedData(dvals, true);

  parseInfo.format("Created Time Coordinate Axis From reftime Variable%n");
  return timeCoord;
}