Package ucar.ma2

Examples of ucar.ma2.StructureDataIterator


     * @throws InvalidRangeException  range doesn't match data
     */
    public Array readVariable(Variable v2, Section section)
            throws IOException, InvalidRangeException {

        Range timeRange = null;
        Range bandRange = null;
        Range geoXRange = null;
        Range geoYRange = null;
        if (section != null & section.getRank() > 0) {
            if (section.getRank() > 3) {
                timeRange = (Range) section.getRange(0);
                bandRange = (Range) section.getRange(1);
                geoYRange = (Range) section.getRange(2);
                geoXRange = (Range) section.getRange(3);
            } else if (section.getRank() > 2) {
                timeRange = (Range) section.getRange(0);
                geoYRange = (Range) section.getRange(1);
                geoXRange = (Range) section.getRange(2);
            } else if (section.getRank() > 1) {
                geoYRange = (Range) section.getRange(0);
                geoXRange = (Range) section.getRange(1);
            } else {
                geoXRange = (Range) section.getRange(0);
            }
        }

        String varname = v2.getFullName();

        Array dataArray =
            Array.factory(v2.getDataType().getPrimitiveClassType(),
                          section.getShape());

        Index dataIndex = dataArray.getIndex();

        if (varname.equals("latitude") || varname.equals("longitude")) {
            double[][] pixel = new double[2][1];
            double[][] latLon;
            double[][][] latLonValues =
                new double[geoXRange.length()][geoYRange.length()][2];

            // Use Range object, which calculates requested i, j
            // values and incorporates stride
            for (int i = 0; i < geoXRange.length(); i++) {
                for (int j = 0; j < geoYRange.length(); j++) {
                    pixel[0][0] = (double) geoXRange.element(i);
                    pixel[1][0] = (double) geoYRange.element(j);
                    latLon      = nav.toLatLon(pixel);

                    if (varname.equals("lat")) {
                        dataArray.setFloat(dataIndex.set(j, i),
                                           (float) (latLon[0][0]));
                    } else {
                        dataArray.setFloat(dataIndex.set(j, i),
                                           (float) (latLon[1][0]));
                    }
                }
            }
        }

        if (varname.equals("image")) {
            try {
                int[][] pixelData = new int[1][1];
                if (bandRange != null) {
                    for (int k = 0; k < bandRange.length(); k++) {
                        int bandIndex = bandRange.element(k) + 1// band numbers in McIDAS are 1 based
                        for (int j = 0; j < geoYRange.length(); j++) {
                            for (int i = 0; i < geoXRange.length(); i++) {
                                pixelData = af.getData(geoYRange.element(j),
                                        geoXRange.element(i), 1, 1,
                                        bandIndex);
                                dataArray.setInt(dataIndex.set(0, k, j, i),
                                        (pixelData[0][0]));
                            }
                        }
                    }

                } else {
                    for (int j = 0; j < geoYRange.length(); j++) {
                        for (int i = 0; i < geoXRange.length(); i++) {
                            pixelData = af.getData(geoYRange.element(j),
                                    geoXRange.element(i), 1, 1);
                            dataArray.setInt(dataIndex.set(0, j, i),
                                             (pixelData[0][0]));
                        }
                    }
View Full Code Here


        groups = volScan.getWidthGroups();
      else if( shortName.startsWith("DiffReflectivity"))
        groups = volScan.getDifferentialReflectivityGroups();

      if(section.getRank() == 2) {
          Range radialRange = section.getRange(0);
          Range gateRange = section.getRange(1);
          List lli = (List)groups.get(0);
          readOneScan(lli, radialRange, gateRange, ii);
      } else {
          Range scanRange = section.getRange(0);
          Range radialRange = section.getRange(1);
          Range gateRange = section.getRange(2);
          for (int i=scanRange.first(); i<=scanRange.last(); i+= scanRange.stride()) {
            readOneScan((List)groups.get(i), radialRange, gateRange, ii);
          }
      }
      return data;
View Full Code Here

    boolean tRangeDone = false;

    try
    {
      // Get the height range.
      Range zRange = vertSubset != null ? vertSubset.getRange() : null;
      zRangeDone = true;

      // Get the time range.
      Range tRange = null;
      if ( timeRange != null )
      {
        CoordinateAxis1DTime timeAxis = this.coordSys.getTimeAxis1D();
        int startIndex = timeAxis.findTimeIndexFromDate( timeRange.getStart().getDate() );
        int endIndex = timeAxis.findTimeIndexFromDate( timeRange.getEnd().getDate() );
        tRange = new Range( startIndex, endIndex );
        tRangeDone = true;
      }

      if ( format == WcsRequest.Format.GeoTIFF || format == WcsRequest.Format.GeoTIFF_Float )
      {
View Full Code Here

  public boolean hasNext() { // have to actually fetch the thing here
    if (totalNelemsDone >= totalNelems) return false;

    if ((index == null) || !index.hasNext()) { // get new data node
      try {
        Section dataSection;
        DataChunk dataChunk;

        while (true) { // look for intersecting sections

          if (!chunkIterator.hasNext()) {
            next = null;
            return false;
          }

          // get next dataChunk
          try {
            dataChunk = chunkIterator.next();
          } catch (IOException e) {
            e.printStackTrace();
            next = null;
            return false;
          }

          // make the dataSection for this chunk
          dataSection = new Section(dataChunk.offset, chunkSize);
          if (dataSection.intersects(want)) // does it intersect ?
            break;
        }

        if (debug)
          System.out.println(" found intersecting section: " + dataSection + " for filePos " + dataChunk.filePos);
View Full Code Here

  public boolean hasNext() { // have to actually fetch the thing
    if (totalNelemsDone >= totalNelems) return false;

    if ((index == null) || !index.hasNext()) { // get new data node
      try {
        Section dataSection;
        DataChunk dataChunk;

        while (true) { // look for intersecting sections
          if (!chunkIterator.hasNext()) {
            next = null;
            return false;
          }

          // get next dataChunk
          try {
            dataChunk = chunkIterator.next();
          } catch (IOException e) {
            e.printStackTrace();
            next = null;
            return false;
          }

          // make the dataSection for this chunk
          dataSection = new Section(dataChunk.getOffset(), chunkSize);
          if (debugIntersection)
            System.out.println(" test intersecting: " + dataSection + " want: " + want);
          if (dataSection.intersects(want)) // does it intersect ?
            break;
        }

        if (debug)
          System.out.println(" found intersecting dataSection: " + dataSection+" intersect= "+dataSection.intersect(want));

        index = new IndexChunkerTiled(dataSection, want); // new indexer into this chunk
        next = new Chunk( dataChunk.getByteBuffer()); // this does the uncompression

      } catch (InvalidRangeException e) {
View Full Code Here

    this.done = 0;

    // LOOK - need test for "all" common case

    // The actual wanted data we can get from this section
    Section intersect = dataSection.intersect(wantSection);
    this.total = intersect.computeSize();
    if (total <= 0) {
      System.out.println("hey");
    }
    assert total > 0;
    int varRank = intersect.getRank();

    // create the List<Dim>
    // Section shifted = intersect.shiftOrigin(dataSection); // want reletive to dataSection
    int wantStride = 1;
    int dataStride = 1;
    for (int ii = varRank - 1; ii >= 0; ii--) {
      Range dr = dataSection.getRange(ii);
      Range wr = wantSection.getRange(ii);
      Range ir = intersect.getRange(ii);
      dimList.add(new Dim(dr, wr, ir, dataStride, wantStride)); // note reversed : fastest first
      dataStride *= dr.length();
      wantStride *= wr.length();
    }

View Full Code Here

      NetcdfFile ncfile = TestH5.open(filename);
      //System.out.println("\n"+ncfile);

      for (Variable v : ncfile.getVariables()) {
        if (v.getSize() > max_size) {
          Section s = makeSubset(v);
          System.out.println("  Try to read variable " + v.getNameAndDimensions() + " size= " + v.getSize() + " section= " + s);
          v.read(s);
        } else {
          System.out.println("  Try to read variable " + v.getNameAndDimensions() + " size= " + v.getSize());
          v.read();
View Full Code Here

  static int max_size = 1000 * 1000 * 10;
  static Section makeSubset(Variable v) throws InvalidRangeException {
    int[] shape = v.getShape();
    shape[0] = 1;
    Section s = new Section(shape);
    long size = s.computeSize();
    shape[0] = (int) Math.max(1, max_size / size);
    return new Section(shape);
  }
View Full Code Here

    if (null == axis) throw new IllegalArgumentException("There is no GeoZ coordinate");
    return readValue( axis, fromVar, index);
  }

  public double readValue(Variable targetVar, Variable fromVar, int[] index) throws InvalidRangeException, IOException {
    Section axisElement = mapIndex( targetVar, fromVar, index);
    Array result = targetVar.read(axisElement);
    return result.nextDouble();
  }
View Full Code Here

  }

  public Section mapIndex(Variable targetVar, Variable fromVar, int[] fromIndex) throws InvalidRangeException {
    List<Dimension> toDims = targetVar.getDimensions();
    List<Dimension> fromDims = fromVar.getDimensions();
    Section result = new Section();

    // each dimension in the target must be present in the source
    for (int i=0; i<toDims.size(); i++) {
      Dimension dim = toDims.get(i);
      int varIndex = fromDims.indexOf(toDims.get(i));
      if (varIndex < 0) throw new IllegalArgumentException("Dimension "+dim+" does not exist");
      result.appendRange(fromIndex[varIndex], fromIndex[varIndex]);
    }
    return result;
  }
View Full Code Here

TOP

Related Classes of ucar.ma2.StructureDataIterator

Copyright © 2018 www.massapicom. 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.