Examples of GridDatatype


Examples of ucar.nc2.dt.GridDatatype

    while (dataI.hasNext())
      System.out.println(" coord="+dataI.getObjectNext());
  }

  public void testReadData(GridDataset gds) throws IOException {
    GridDatatype g = gds.findGridDatatype("IR_WV");
    assert null != g;
    assert g.getFullName().equals("IR_WV");
    assert g.getRank() == 3;
    assert g.getShape()[0] == ntimes;
    assert g.getShape()[1] == 1008;
    assert g.getShape()[2] == 1536;
    assert g.getDataType() == DataType.SHORT;

    GridCoordSystem gsys = g.getCoordinateSystem();
    assert gsys.getXHorizAxis() != null;
    assert gsys.getYHorizAxis() != null;
    assert gsys.getTimeAxis() != null;
    assert gsys.getVerticalAxis() == null;
    assert gsys.getProjection() != null;

    Array data = g.readVolumeData(0);
    assert data.getRank() == 2;
    assert data.getShape()[0] == 1008;
    assert data.getShape()[1] == 1536;
    assert data.getElementType() == short.class;
  }
View Full Code Here

Examples of ucar.nc2.dt.GridDatatype

  // may be bug in HDF5 1.8.4-patch1
  public void utestTiling() throws IOException {
    // Global Heap 1t 13059 runs out with no heap id = 0
    String filename = testDir+"tiling.nc4";
    GridDataset gridDataset = GridDataset.open(filename);
    GridDatatype grid = gridDataset.findGridByName("Turbulence_SIGMET_AIRMET" );
    System.out.printf("grid=%s%n", grid);
    grid.readDataSlice( 4, 13, 176, 216 ); // FAILS
    gridDataset.close();
  }
View Full Code Here

Examples of ucar.nc2.dt.GridDatatype

        File tifFile = File.createTempFile( "WCS", ".tif", dir );
        if ( log.isDebugEnabled() )
          log.debug( "writeCoverageDataToFile(): tifFile=" + tifFile.getPath() );

        WcsRangeField rangeField = this.range.get( reqRangeFieldName );
        GridDatatype subset = rangeField.getGridDatatype()
                .makeSubset( tRange, zRange, bboxLatLonRect, 1, 1, 1 );
        Array data = subset.readDataSlice( 0, 0, -1, -1 );

        GeotiffWriter writer = new GeotiffWriter( tifFile.getPath() );
        writer.writeGrid( this.dataset.getDataset(), subset, data, format == WcsRequest.Format.GeoTIFF );

        writer.close();
View Full Code Here

Examples of ucar.nc2.dt.GridDatatype

      if (gds != null) gds.close();
      gds = null;
    }

    public void testGrid() {
      GridDatatype grid = gds.findGridDatatype("T");
      assert null != grid;
      assert grid.getFullName().equals("T");
      assert grid.getRank() == 3;
      assert grid.getDataType() == DataType.DOUBLE;

      GridCoordSystem gcsys = grid.getCoordinateSystem();
      assert gcsys.getYHorizAxis() != null;
      assert gcsys.getXHorizAxis() != null;
      assert gcsys.getTimeAxis() != null;

      CoordinateAxis1DTime taxis = gcsys.getTimeAxis1D();
View Full Code Here

Examples of ucar.nc2.dt.GridDatatype

      if (varNameList.contains(gridName))
        continue;

      varNameList.add(gridName);

      GridDatatype grid = gds.findGridDatatype(gridName);
      GridCoordSystem gcsOrg = grid.getCoordinateSystem();
      CoordinateAxis1DTime timeAxis = gcsOrg.getTimeAxis1D();

      // make subset if needed
      Range timeRange = null;
      if ((dateRange != null) && (timeAxis != null)) {
        int startIndex = timeAxis.findTimeIndexFromDate(dateRange.getStart().getDate());
        int endIndex = timeAxis.findTimeIndexFromDate(dateRange.getEnd().getDate());
        if (startIndex < 0)
          throw new InvalidRangeException("start time=" + dateRange.getStart().getDate() + " must be >= " + timeAxis.getTimeDate(0));
        if (endIndex < 0)
          throw new InvalidRangeException("end time=" + dateRange.getEnd().getDate() + " must be >= " + timeAxis.getTimeDate(0));
        timeRange = new Range(startIndex, endIndex);
      }

      if ((null != timeRange) || (zRange != null) || (llbb != null) || (horizStride > 1)) {
        grid = grid.makeSubset(timeRange, zRange, llbb, 1, horizStride, horizStride);
      }

      Variable gridV = (Variable) grid.getVariable();
      varList.add(gridV);
      total_size += gridV.getSize() * gridV.getElementSize();

      // add coordinate axes
      GridCoordSystem gcs = grid.getCoordinateSystem();
      for (CoordinateAxis axis : gcs.getCoordinateAxes()) {
        if (!varNameList.contains(axis.getFullName())) {
          varNameList.add(axis.getFullName());
          varList.add(axis); // LOOK dont we have to subset these ??
          axisList.add(axis);
        }
      }

      // add coordinate transform variables
      for (CoordinateTransform ct : gcs.getCoordinateTransforms()) {
        Variable v = ncd.findVariable(ct.getName());
        if (!varNameList.contains(ct.getName()) && (null != v)) {
          varNameList.add(ct.getName());
          varList.add(v);
        }
      }

      // optional lat/lon
      if (addLatLon) {
        Projection proj = gcs.getProjection();
        if ((null != proj) && !(proj instanceof LatLonProjection)) {
          addLatLon2D(ncd, varList, proj, gcs.getXHorizAxis(), gcs.getYHorizAxis());
          addLatLon = false;
        }
      }
    }

    // check size is ok
    boolean isLargeFile = false;
    long maxSize = 2 * 1000 * 1000 * 1000;
    if (total_size > maxSize) {
      log.info("Request size = {} Mbytes", total_size / 1000 / 1000);
      isLargeFile = true;
    }

    FileWriter writer = new FileWriter(location, false, isLargeFile, -1);
    // global attributes
    for (Attribute att : gds.getGlobalAttributes())
      writer.writeGlobalAttribute(att);

    writer.writeGlobalAttribute(new Attribute("Conventions", "CF-1.0"));
    writer.writeGlobalAttribute(new Attribute("History",
            "Translated to CF-1.0 Conventions by Netcdf-Java CDM (NetcdfCFWriter)\n" +
                    "Original Dataset = " + gds.getLocationURI() + "; Translation Date = " + new Date()));


    writer.writeVariables(varList);

    // now add CF annotations as needed - dont change original ncd or gds
    NetcdfFileWriteable ncfile = writer.getNetcdf();
    Group root = ncfile.getRootGroup();
    for (String gridName : gridList) {
      GridDatatype grid = gds.findGridDatatype(gridName);
      Variable newV = root.findVariable(gridName);
      if (newV == null) {
        log.warn("NetcdfCFWriter cant find "+gridName+" in gds "+gds.getLocationURI());
        continue;
      }

      // annotate Variable for CF
      StringBuilder sbuff = new StringBuilder();
      GridCoordSystem gcs = grid.getCoordinateSystem();
      for (Variable axis : gcs.getCoordinateAxes()) {
        sbuff.append(axis.getFullName()).append(" ");
      }
      if (addLatLon)
        sbuff.append("lat lon");
View Full Code Here

Examples of ucar.nc2.dt.GridDatatype

    while (iter.hasNext()) {
      GridDataset.Gridset gridset = (GridDataset.Gridset) iter.next();
      gridset.getGeoCoordSystem();
    }

    GridDatatype grid = gridDs.findGridDatatype(gridName);
    assert (grid != null) : "Cant find grid "+gridName;

    GridCoordSystem gcs = grid.getCoordinateSystem();
    CoordinateAxis1DTime runtime = gcs.getRunTimeAxis();
    assert (runtime != null) : "Cant find runtime for "+gridName;
    CoordinateAxis time = gcs.getTimeAxis();
    assert (time != null) : "Cant find time for "+gridName;
    assert (time.getRank() == 2) : "Time should be 2D "+gridName;
View Full Code Here

Examples of ucar.nc2.dt.GridDatatype

    while (iter.hasNext()) {
      GridDataset.Gridset gridset = (GridDataset.Gridset) iter.next();
      gridset.getGeoCoordSystem();
    }

    GridDatatype grid = gridDs.findGridDatatype(gridName);
    assert (grid != null) : "Cant find grid "+gridName;

    GridCoordSystem gcs = grid.getCoordinateSystem();
    CoordinateAxis1DTime runtime = gcs.getRunTimeAxis();
    //System.out.println(" has runtime axis=" +  (runtime != null));

    assert (runtime != null) : "Cant find runtime for "+gridName;
    //assert (runtime == null) : "Should not have runtime coord= "+runtime;
View Full Code Here

Examples of ucar.nc2.dt.GridDatatype

  public static void main(String arg[]) throws IOException {
    String defaultFilename = "C:/data/rap/fmrc.xml";
    String filename = (arg.length > 0) ? arg[0] : defaultFilename;

    GridDataset gds = ucar.nc2.dt.grid.GridDataset.open(filename);
    GridDatatype gg = gds.findGridDatatype("T");
    GridCoordSystem gsys = gg.getCoordinateSystem();

    // gsys.getTimeAxisForRun(1);  // generate error

    CoordinateAxis1DTime rtaxis = gsys.getRunTimeAxis();
    CoordinateAxis taxis2D = gsys.getTimeAxis();
View Full Code Here

Examples of ucar.nc2.dt.GridDatatype

    public void writeGrid(String fileName, String gridName, int time,
                          int level, boolean greyScale,
                          LatLonRect pt) throws IOException {
        double          scaler;
        GridDataset     dataset = ucar.nc2.dt.grid.GridDataset.open(fileName);
        GridDatatype    grid    = dataset.findGridDatatype(gridName);
        GridCoordSystem gcs     = grid.getCoordinateSystem();
        ProjectionImpl  proj    = grid.getProjection();

        if (grid == null) {
            throw new IllegalArgumentException("No grid named " + gridName
                    + " in fileName");
        }
        if ( !gcs.isRegularSpatial()) {
            Attribute att = dataset.findGlobalAttributeIgnoreCase("datasetId");
            if(att != null && att.getStringValue().contains("DMSP")){
                writeSwathGrid(fileName, gridName,time,level, greyScale, pt);
                return;
            } else {
                throw new IllegalArgumentException(
                    "Must have 1D x and y axes for " + grid.getFullName());
            }

        }

        CoordinateAxis1D xaxis = (CoordinateAxis1D) gcs.getXHorizAxis();
        CoordinateAxis1D yaxis = (CoordinateAxis1D) gcs.getYHorizAxis();
        if ( !xaxis.isRegular() || !yaxis.isRegular()) {
            throw new IllegalArgumentException(
                "Must be evenly spaced grid = " + grid.getFullName());
        }

        // read in data
        Array data = grid.readDataSlice(time, level, -1, -1);
        Array lon  = xaxis.read();
        Array lat  = yaxis.read();

        //latlon coord does not need to time 1000.0
        if (gcs.isLatLon()) {
View Full Code Here

Examples of ucar.nc2.dt.GridDatatype

                               LatLonRect llr) throws IOException {

        double           scaler;
        GridDataset      dataset =
            ucar.nc2.dt.grid.GridDataset.open(fileName);
        GridDatatype     grid    = dataset.findGridDatatype(gridName);
        GridCoordSystem  gcs     = grid.getCoordinateSystem();
        ProjectionImpl   proj    = grid.getProjection();

        CoordinateAxis2D xaxis   = (CoordinateAxis2D) gcs.getXHorizAxis();
        CoordinateAxis2D yaxis   = (CoordinateAxis2D) gcs.getYHorizAxis();

        // read in data
        Array    data      = grid.readDataSlice(time, level, -1, -1);
        Array    lon       = xaxis.read();
        Array    lat       = yaxis.read();

        double[] swathInfo = getSwathLatLonInformation(lat, lon);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.