コード例 #1
0
ファイル: CompareNetcdf2.java プロジェクト: jnbek/thredds
  public boolean compareVariables(NetcdfFile org, NetcdfFile copy) {
    f.format("Original = %s%n", org.getLocation());
    f.format("CompareTo= %s%n", copy.getLocation());
    boolean ok = true;

    for (Variable orgV : org.getVariables()) {
      if (orgV.isCoordinateVariable()) continue;
      Variable copyVar = copy.findVariable(orgV.getShortName());
      if (copyVar == null) {
        f.format(" MISSING '%s' in 2nd file%n", orgV.getFullName());
        ok = false;
      } else {
        List<Dimension> dims1 = orgV.getDimensions();
        List<Dimension> dims2 = copyVar.getDimensions();
        if (!compare(dims1, dims2)) {
          f.format(" %s != %s%n", orgV.getNameAndDimensions(), copyVar.getNameAndDimensions());
        } else {
          // f.format("   ok %s%n", orgV.getName());
        }
      }
    }

    f.format("%n");
    for (Variable orgV : copy.getVariables()) {
      if (orgV.isCoordinateVariable()) continue;
      Variable copyVar = org.findVariable(orgV.getShortName());
      if (copyVar == null) {
        f.format(" MISSING '%s' in 1st file%n", orgV.getFullName());
        ok = false;
      }
    }

    return ok;
  }
コード例 #2
0
ファイル: DatasetViewer.java プロジェクト: mazl123321/thredds
  private void showDeclaration(BeanTableSorted from, boolean isNcml) {
    Variable v = getCurrentVariable(from);
    if (v == null) return;
    infoTA.clear();
    if (isNcml) {
      Formatter out = new Formatter();
      try {
        NCdumpW.writeNcMLVariable(v, out);
      } catch (IOException e) {
        e.printStackTrace();
      }
      infoTA.appendLine(out.toString());

    } else {
      infoTA.appendLine(v.toString());
    }

    if (Debug.isSet("Xdeveloper")) {
      infoTA.appendLine("\n");
      infoTA.appendLine("FULL NAME = " + v.getFullName());
      infoTA.appendLine("\n");
      infoTA.appendLine(v.toStringDebug());
    }
    infoTA.gotoTop();
    infoWindow.setTitle("Variable Info");
    infoWindow.show();
  }
コード例 #3
0
ファイル: CompareNetcdf2.java プロジェクト: jnbek/thredds
  private boolean compareGroups(Group org, Group copy) {
    if (showCompare) f.format("compare Group %s to %s %n", org.getName(), copy.getName());
    boolean ok = true;

    if (!org.getName().equals(copy.getName())) {
      f.format(" ** names are different %s != %s %n", org.getName(), copy.getName());
      ok = false;
    }

    // dimensions
    ok &= checkAll(org.getDimensions(), copy.getDimensions(), null);

    // attributes
    ok &= checkAll(org.getAttributes(), copy.getAttributes(), null);

    // variables
    // cant use object equality, just match on short name
    for (Variable orgV : org.getVariables()) {
      Variable copyVar = copy.findVariable(orgV.getShortName());
      if (copyVar == null) {
        f.format(" ** cant find variable %s in 2nd file%n", orgV.getFullName());
        ok = false;
      } else {
        ok &= compareVariables(orgV, copyVar, compareData, true);
      }
    }

    for (Variable copyV : copy.getVariables()) {
      Variable orgV = org.findVariable(copyV.getShortName());
      if (orgV == null) {
        f.format(" ** cant find variable %s in 1st file%n", copyV.getFullName());
        ok = false;
      }
    }

    // nested groups
    List groups = new ArrayList();
    ok &= checkAll(org.getGroups(), copy.getGroups(), groups);
    for (int i = 0; i < groups.size(); i += 2) {
      Group orgGroup = (Group) groups.get(i);
      Group ncmlGroup = (Group) groups.get(i + 1);
      ok &= compareGroups(orgGroup, ncmlGroup);
    }

    return ok;
  }
コード例 #4
0
ファイル: HdfEos.java プロジェクト: julienchastang/thredds
  // convert to shared dimensions
  private void setSharedDimensions(
      Variable v, List<Element> values, List<Dimension> unknownDims, String location) {
    if (values.size() == 0) return;

    // remove the "scalar" dumbension
    Iterator<Element> iter = values.iterator();
    while (iter.hasNext()) {
      Element value = iter.next();
      String dimName = value.getText().trim();
      if (dimName.equalsIgnoreCase("scalar")) iter.remove();
    }

    // gotta have same number of dimensions
    List<Dimension> oldDims = v.getDimensions();
    if (oldDims.size() != values.size()) {
      log.error("Different number of dimensions for {} {}", v, location);
      return;
    }

    List<Dimension> newDims = new ArrayList<>();
    Group group = v.getParentGroup();

    for (int i = 0; i < values.size(); i++) {
      Element value = values.get(i);
      String dimName = value.getText().trim();
      dimName = NetcdfFile.makeValidCdmObjectName(dimName);

      Dimension dim = group.findDimension(dimName);
      Dimension oldDim = oldDims.get(i);
      if (dim == null) dim = checkUnknownDims(dimName, unknownDims, oldDim, location);

      if (dim == null) {
        log.error(
            "Unknown Dimension= {} for variable = {} {} ", dimName, v.getFullName(), location);
        return;
      }
      if (dim.getLength() != oldDim.getLength()) {
        log.error(
            "Shared dimension ("
                + dim.getShortName()
                + ") has different length than data dimension ("
                + oldDim.getShortName()
                + ") shared="
                + dim.getLength()
                + " org="
                + oldDim.getLength()
                + " for "
                + v
                + " "
                + location);
        return;
      }
      newDims.add(dim);
    }
    v.setDimensions(newDims);
    if (showWork) System.out.printf(" set shared dimensions for %s %n", v.getNameAndDimensions());
  }
コード例 #5
0
 private String showMissing(Variable v) {
   if (!(v instanceof VariableDS)) return "";
   VariableDS ve = (VariableDS) v;
   Formatter buff = new Formatter();
   buff.format("%s:", v.getFullName());
   EnumSet<NetcdfDataset.Enhance> enhanceMode = ve.getEnhanceMode();
   buff.format("enhanceMode= %s%n", enhanceMode);
   ve.showScaleMissingProxy(buff);
   return buff.toString();
 }
コード例 #6
0
ファイル: ConvertNetCDF.java プロジェクト: jkachika/galileo
  /** Converts a 3D variable to a {@link Metadata} representation */
  private static void convert3DVariable(GridDatatype g, Date date, Map<String, Metadata> metaMap)
      throws IOException {

    Variable v = g.getVariable();
    System.out.println("Reading: " + v.getFullName());
    Array values = v.read();

    int h = v.getShape(1);
    int w = v.getShape(2);

    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        LatLonPoint pt = g.getCoordinateSystem().getLatLon(j, i);
        String hash =
            GeoHash.encode((float) pt.getLatitude(), (float) pt.getLongitude(), 10).toLowerCase();

        Metadata meta = metaMap.get(hash);
        if (meta == null) {
          /* We need to create Metadata for this location */
          meta = new Metadata();

          UUID metaUUID = UUID.nameUUIDFromBytes(hash.getBytes());
          meta.setName(metaUUID.toString());

          SpatialProperties location =
              new SpatialProperties((float) pt.getLatitude(), (float) pt.getLongitude());
          meta.setSpatialProperties(location);

          TemporalProperties time = new TemporalProperties(date.getTime());
          meta.setTemporalProperties(time);

          metaMap.put(hash, meta);
        }

        String featureName = v.getFullName().toLowerCase();
        float featureValue = values.getFloat(i * w + j);
        Feature feature = new Feature(featureName, featureValue);
        meta.putAttribute(feature);
      }
    }
  }
コード例 #7
0
  @Test
  public void testNoValid2DVariable() throws Exception {
    final File file = TestData.file(this, "noVars.nc");
    NetcdfDataset dataset = NetcdfDataset.acquireDataset(file.getAbsolutePath(), null);
    List<Variable> variables = dataset.getVariables();
    boolean speedVariableIsPresent = false;
    String speedVariableName = "";

    for (Variable variable : variables) {
      if (variable.getShortName().equals("spd")) {
        speedVariableIsPresent = true;
        speedVariableName = variable.getFullName();
        break;
      }
    }

    assertTrue(speedVariableIsPresent);

    final NetCDFImageReaderSpi unidataImageReaderSpi = new NetCDFImageReaderSpi();
    assertTrue(unidataImageReaderSpi.canDecodeInput(file));
    NetCDFImageReader reader = null;
    try {

      // sample dataset containing a water_speed variable having
      // only time, depth dimensions. No lon/lat dims are present
      // resulting into variable not usable.
      reader = (NetCDFImageReader) unidataImageReaderSpi.createReaderInstance();
      reader.setInput(file);
      final List<Name> names = reader.getCoveragesNames();

      boolean isSpeedCoverageAvailable = false;
      for (Name name : names) {
        if (name.toString().equals(speedVariableName)) {
          isSpeedCoverageAvailable = true;
          break;
        }
      }
      // Checking that only "mask" variable is found
      assertFalse(isSpeedCoverageAvailable);
    } finally {
      if (dataset != null) {
        dataset.close();
      }

      if (reader != null) {
        try {
          reader.dispose();
        } catch (Throwable t) {
          // Does nothing
        }
      }
    }
  }
コード例 #8
0
ファイル: CompareNetcdf2.java プロジェクト: jnbek/thredds
  private void compareVariableData(
      Variable var1, Variable var2, boolean showCompare, boolean justOne) throws IOException {
    Array data1 = var1.read();
    Array data2 = var2.read();

    if (showCompare)
      f.format(
          " compareArrays %s unlimited=%s size=%d%n",
          var1.getNameAndDimensions(), var1.isUnlimited(), data1.getSize());
    compareData(var1.getFullName(), data1, data2, justOne);
    if (showCompare) f.format("   ok%n");
  }
コード例 #9
0
 /**
  * Returns the phenomenon that the given variable represents.
  *
  * <p>This name will be, in order of preference:
  *
  * <p>The standard name
  *
  * <p>The long name
  *
  * <p>The variable name
  */
 private static String getVariableName(Variable var) {
   Attribute stdNameAtt = var.findAttributeIgnoreCase("standard_name");
   if (stdNameAtt == null || stdNameAtt.getStringValue().trim().equals("")) {
     Attribute longNameAtt = var.findAttributeIgnoreCase("long_name");
     if (longNameAtt == null || longNameAtt.getStringValue().trim().equals("")) {
       return var.getFullName();
     } else {
       return longNameAtt.getStringValue();
     }
   } else {
     return stdNameAtt.getStringValue();
   }
 }
コード例 #10
0
ファイル: CompareNetcdf2.java プロジェクト: jnbek/thredds
  public boolean compareVariables(
      Variable org, Variable copy, boolean compareData, boolean justOne) {
    boolean ok = true;

    if (showCompare)
      f.format("compare Variable %s to %s %n", org.getFullName(), copy.getFullName());
    if (!org.getFullName().equals(copy.getFullName())) {
      f.format(" ** names are different %s != %s %n", org.getFullName(), copy.getFullName());
      ok = false;
    }

    // dimensions
    ok &= checkAll(org.getDimensions(), copy.getDimensions(), null);

    // attributes
    ok &= checkAll(org.getAttributes(), copy.getAttributes(), null);

    // coord sys
    if ((org instanceof VariableEnhanced) && (copy instanceof VariableEnhanced)) {
      VariableEnhanced orge = (VariableEnhanced) org;
      VariableEnhanced copye = (VariableEnhanced) copy;
      ok &= checkAll(orge.getCoordinateSystems(), copye.getCoordinateSystems(), null);
    }

    // data !!
    if (compareData) {
      try {
        compareVariableData(org, copy, showCompare, justOne);

      } catch (IOException e) {
        ByteArrayOutputStream bos = new ByteArrayOutputStream(10000);
        e.printStackTrace(new PrintStream(bos));
        f.format("%s", bos.toString());
      }
    }

    // nested variables
    if (org instanceof Structure) {
      if (!(copy instanceof Structure)) {
        f.format("  ** %s not Structure%n", org);
        ok = false;

      } else {
        Structure orgS = (Structure) org;
        Structure ncmlS = (Structure) copy;

        List vars = new ArrayList();
        ok &= checkAll(orgS.getVariables(), ncmlS.getVariables(), vars);
        for (int i = 0; i < vars.size(); i += 2) {
          Variable orgV = (Variable) vars.get(i);
          Variable ncmlV = (Variable) vars.get(i + 1);
          ok &= compareVariables(orgV, ncmlV, false, true);
        }
      }
    }

    return ok;
  }
コード例 #11
0
ファイル: Write2ncRect.java プロジェクト: nbald/thredds
  private void copyAll(NetcdfFileWriteable ncfile, Variable oldVar) throws IOException {
    String newName = N3iosp.makeValidNetcdfObjectName(oldVar.getShortName());

    Array data = oldVar.read();
    try {
      if (oldVar.getDataType() == DataType.STRING) {
        data = convertToChar(ncfile.findVariable(newName), data);
      }
      if (data.getSize() > 0) // zero when record dimension = 0
      ncfile.write(newName, data);

    } catch (InvalidRangeException e) {
      e.printStackTrace();
      throw new IOException(e.getMessage() + " for Variable " + oldVar.getFullName());
    }
  }
コード例 #12
0
  @Override
  public AbstractGridDataset createDataset(String id, String location)
      throws IOException, EdalException {
    NetcdfDataset nc = null;
    try {
      /*
       * Open the dataset, using the cache for NcML aggregations
       */
      nc = openAndAggregateDataset(location);

      /*-
       * We may in future be able to use forecast model run collection aggregations for
       * dealing with the case of overlapping time axes.  To do this the code will look
       * something like this:
       *
       * StringBuilder sb = new StringBuilder();
       * Formatter formatter = new Formatter(sb, Locale.UK);
       * Fmrc f = Fmrc.open(location, formatter);
       *
       * in openAndAggregateDataset.  It will need to build up an NcML document which
       * does this.  It should look something like:
       *
       *  <netcdf xmlns="http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2" enhance="true">
       *      <aggregation dimName="run" type="forecastModelRunCollection" timeUnitsChange="true">
       *           <!-- scanFmrc actually works, but what we want is something like the following bit -->
       *           <scanFmrc location="/home/guy/Data/POLCOMS_IRISH/" regExp=".*\.nc"/>
       *           <netcdf location="/home/guy/Data/POLCOMS_IRISH/polcoms_irish_hourly_20090320.nc" coordValue="2009-03-20T00:00:00Z" enhance="true" />
       *           <netcdf location="/home/guy/Data/POLCOMS_IRISH/polcoms_irish_hourly_20090321.nc" coordValue="2009-03-21T00:00:00Z" enhance="true" />
       *           <netcdf location="/home/guy/Data/POLCOMS_IRISH/polcoms_irish_hourly_20090322.nc" coordValue="2009-03-22T00:00:00Z" enhance="true" />
       *      </aggregation>
       *  </netcdf>
       *
       * For more documentation see:
       * http://mailman.unidata.ucar.edu/software/thredds/current/netcdf-java/ncml/FmrcAggregation.html
       *
       * We then can do stuff like:
       *
       * ucar.nc2.dt.GridDataset gridDataset = f.getDatasetBest();
       *
       * To get the single best aggregation of the overlapping time axis
       *
       * Then we need to work with GridDatasets in place of NetcdfDatasets.  Stuff like:
       *
       * for(Variable variable : gridDataset.getNetcdfFile().getVariables()) {
       *    // blah blah
       * }
       *
       * will be necessary.  We need to check that that works with remote datasets too
       */

      /*
       * We look for NetCDF-U variables to group mean/standard-deviation.
       *
       * We need to do this here because we want to subsequently ignore
       * parent variables
       */
      Map<String, String[]> varId2AncillaryVars = new HashMap<String, String[]>();
      for (Variable variable : nc.getVariables()) {
        /*
         * Just look for parent variables, since these may not have a
         * grid directly associated with them
         */
        for (Attribute attr : variable.getAttributes()) {
          if (attr.getFullName().equalsIgnoreCase("ancillary_variables")) {
            varId2AncillaryVars.put(variable.getFullName(), attr.getStringValue().split(" "));
            continue;
          }
        }
      }

      ucar.nc2.dt.GridDataset gridDataset = CdmUtils.getGridDataset(nc);
      List<GridVariableMetadata> vars = new ArrayList<GridVariableMetadata>();
      /*
       * Store a map of component names. Key is the compound name, value
       * is a 2-element String array with x, y component IDs
       *
       * Also store a map of whether these components are really
       * eastward/northward, or whether they are locally u/v
       */
      Map<String, String[]> xyComponentPairs = new HashMap<String, String[]>();
      Map<String, Boolean> xyNameToTrueEN = new HashMap<String, Boolean>();
      /*
       * Store a map of variable IDs to UncertML URLs. This will be used
       * to determine which components are mean/std/etc.
       *
       * TODO implement more than just Mean/SD
       */
      Map<String, String> varId2UncertMLRefs = new HashMap<String, String>();
      /*
       * Here we store the parent variable IDs and their corresponding
       * title.
       */
      Map<String, String> parentVarId2Title = new HashMap<String, String>();
      for (Gridset gridset : gridDataset.getGridsets()) {
        GridCoordSystem coordSys = gridset.getGeoCoordSystem();
        HorizontalGrid hDomain = CdmUtils.createHorizontalGrid(coordSys);
        VerticalAxis zDomain = CdmUtils.createVerticalAxis(coordSys);
        TimeAxis tDomain = CdmUtils.createTimeAxis(coordSys);

        /*
         * Create a VariableMetadata object for each GridDatatype
         */
        for (GridDatatype grid : gridset.getGrids()) {
          VariableDS variable = grid.getVariable();
          String varId = variable.getFullName();
          String name = getVariableName(variable);

          /*
           * If this is a parent variable for a stats collection, we
           * don't want it to be a normal variable as well.
           */
          if (varId2AncillaryVars.containsKey(varId)) {
            parentVarId2Title.put(varId, name);
            continue;
          }

          /*
           * If it is a child variable is (potentially) referenced by
           * UncertML, store its ID and the (possible) UncertML URI
           */
          for (Attribute attr : variable.getAttributes()) {
            if (attr.getFullName().equalsIgnoreCase("ref")) {
              varId2UncertMLRefs.put(varId, attr.getStringValue());
            }
          }

          Parameter parameter =
              new Parameter(
                  varId,
                  variable.getShortName(),
                  variable.getDescription(),
                  variable.getUnitsString(),
                  name);
          GridVariableMetadata metadata =
              new GridVariableMetadata(
                  variable.getFullName(), parameter, hDomain, zDomain, tDomain, true);
          vars.add(metadata);

          if (name != null) {
            /*
             * Check for vector components
             */
            if (name.contains("eastward_")) {
              String compoundName = name.replaceFirst("eastward_", "");
              String[] cData;
              if (!xyComponentPairs.containsKey(compoundName)) {
                cData = new String[2];
                xyComponentPairs.put(compoundName, cData);
                xyNameToTrueEN.put(compoundName, true);
              }
              cData = xyComponentPairs.get(compoundName);
              /*
               * By doing this, we will end up with the merged
               * coverage
               */
              cData[0] = varId;
            } else if (name.contains("northward_")) {
              String compoundName = name.replaceFirst("northward_", "");
              String[] cData;
              if (!xyComponentPairs.containsKey(compoundName)) {
                cData = new String[2];
                xyComponentPairs.put(compoundName, cData);
                xyNameToTrueEN.put(compoundName, true);
              }
              cData = xyComponentPairs.get(compoundName);
              /*
               * By doing this, we will end up with the merged
               * coverage
               */
              cData[1] = varId;
            } else if (name.matches("u-.*component")) {
              String compoundName = name.replaceFirst("u-(.*)component", "$1");
              String[] cData;
              if (!xyComponentPairs.containsKey(compoundName)) {
                cData = new String[2];
                xyComponentPairs.put(compoundName, cData);
                xyNameToTrueEN.put(compoundName, false);
              }
              cData = xyComponentPairs.get(compoundName);
              /*
               * By doing this, we will end up with the merged
               * coverage
               */
              cData[0] = varId;
            } else if (name.matches("v-.*component")) {
              String compoundName = name.replaceFirst("v-(.*)component", "$1");
              String[] cData;
              if (!xyComponentPairs.containsKey(compoundName)) {
                cData = new String[2];
                xyComponentPairs.put(compoundName, cData);
                xyNameToTrueEN.put(compoundName, false);
              }
              cData = xyComponentPairs.get(compoundName);
              /*
               * By doing this, we will end up with the merged
               * coverage
               */
              cData[1] = varId;
            }
            /*
             * We could potentially add a check for zonal/meridional
             * here if required.
             */
          }
        }
      }

      CdmGridDataset cdmGridDataset =
          new CdmGridDataset(id, location, vars, CdmUtils.getOptimumDataReadingStrategy(nc));
      for (Entry<String, String[]> componentData : xyComponentPairs.entrySet()) {
        String commonName = componentData.getKey();
        String[] comps = componentData.getValue();
        if (comps[0] != null && comps[1] != null) {
          cdmGridDataset.addVariablePlugin(
              new VectorPlugin(comps[0], comps[1], commonName, xyNameToTrueEN.get(commonName)));
        }
      }

      for (String statsCollectionId : varId2AncillaryVars.keySet()) {
        String[] ids = varId2AncillaryVars.get(statsCollectionId);
        String meanId = null;
        String stddevId = null;
        for (String statsVarIds : ids) {
          String uncertRef = varId2UncertMLRefs.get(statsVarIds);
          if (uncertRef != null
              && uncertRef.equalsIgnoreCase("http://www.uncertml.org/statistics/mean")) {
            meanId = statsVarIds;
          }
          if (uncertRef != null
              && uncertRef.equalsIgnoreCase(
                  "http://www.uncertml.org/statistics/standard-deviation")) {
            stddevId = statsVarIds;
          }
        }
        if (meanId != null && stddevId != null) {
          MeanSDPlugin meanSDPlugin =
              new MeanSDPlugin(meanId, stddevId, parentVarId2Title.get(statsCollectionId));
          cdmGridDataset.addVariablePlugin(meanSDPlugin);
        }
      }

      return cdmGridDataset;
    } finally {
      CdmUtils.closeDataset(nc);
    }
  }
コード例 #13
0
 /**
  * Make the station variables from a representative station
  *
  * @param stations list of stations
  * @param dim station dimension
  * @return the list of variables
  */
 protected List<Variable> makeStationVars(List<GempakStation> stations, Dimension dim) {
   int numStations = stations.size();
   boolean useSTID = true;
   for (GempakStation station : stations) {
     if (station.getSTID().equals("")) {
       useSTID = false;
       break;
     }
   }
   List<Variable> vars = new ArrayList<Variable>();
   List<String> stnKeyNames = gemreader.getStationKeyNames();
   for (String varName : stnKeyNames) {
     Variable v = makeStationVariable(varName, dim);
     // use STNM or STID as the name or description
     Attribute stIDAttr = new Attribute("standard_name", "station_id");
     if (varName.equals(GempakStation.STID) && useSTID) {
       v.addAttribute(stIDAttr);
     }
     if (varName.equals(GempakStation.STNM) && !useSTID) {
       v.addAttribute(stIDAttr);
     }
     vars.add(v);
   }
   // see if we fill these in completely now
   if ((dim != null) && (numStations > 0)) {
     for (Variable v : vars) {
       Array varArray;
       if (v.getDataType().equals(DataType.CHAR)) {
         int[] shape = v.getShape();
         varArray = new ArrayChar.D2(shape[0], shape[1]);
       } else {
         varArray = get1DArray(v.getDataType(), numStations);
       }
       int index = 0;
       String varname = v.getFullName();
       for (GempakStation stn : stations) {
         String test = "";
         if (varname.equals(GempakStation.STID)) {
           test = stn.getName();
         } else if (varname.equals(GempakStation.STNM)) {
           ((ArrayInt.D1) varArray)
               .set(
                   index,
                   // (int) (stn.getSTNM() / 10));
                   (int) (stn.getSTNM()));
         } else if (varname.equals(GempakStation.SLAT)) {
           ((ArrayFloat.D1) varArray).set(index, (float) stn.getLatitude());
         } else if (varname.equals(GempakStation.SLON)) {
           ((ArrayFloat.D1) varArray).set(index, (float) stn.getLongitude());
         } else if (varname.equals(GempakStation.SELV)) {
           ((ArrayFloat.D1) varArray).set(index, (float) stn.getAltitude());
         } else if (varname.equals(GempakStation.STAT)) {
           test = stn.getSTAT();
         } else if (varname.equals(GempakStation.COUN)) {
           test = stn.getCOUN();
         } else if (varname.equals(GempakStation.STD2)) {
           test = stn.getSTD2();
         } else if (varname.equals(GempakStation.SPRI)) {
           ((ArrayInt.D1) varArray).set(index, stn.getSPRI());
         } else if (varname.equals(GempakStation.SWFO)) {
           test = stn.getSWFO();
         } else if (varname.equals(GempakStation.WFO2)) {
           test = stn.getWFO2();
         }
         if (!test.equals("")) {
           ((ArrayChar.D2) varArray).setString(index, test);
         }
         index++;
       }
       v.setCachedData(varArray, false);
     }
   }
   return vars;
 }
コード例 #14
0
ファイル: TestDorade.java プロジェクト: msdsoftware/thredds
  @Test
  public void testDoradeGround() throws IOException {

    System.out.println("**** Open " + groundDoradeFile);
    try (NetcdfFile ncfile = NetcdfFile.open(groundDoradeFile)) {

      for (Variable v : ncfile.getVariables()) {
        System.out.println(v.getFullName());
      }

      /* test both gate and radial dimension */
      Dimension gateDim = ncfile.getRootGroup().findDimension("gate_1");

      assert (gateDim.getLength() == 1008);

      Dimension radialDim = ncfile.getRootGroup().findDimension("radial");

      assert (radialDim.getLength() == 439);

      /* test some att  */
      Attribute testAtt = ncfile.getRootGroup().findAttribute("Conventions");
      assert (testAtt.getStringValue().equals(_Coordinate.Convention));

      testAtt = ncfile.getRootGroup().findAttribute("format");
      assert (testAtt.getStringValue().equals("Unidata/netCDF/Dorade"));

      testAtt = ncfile.getRootGroup().findAttribute("Project_name");
      assert (testAtt.getStringValue().equalsIgnoreCase("IHOP_2002"));

      testAtt = ncfile.getRootGroup().findAttribute("Radar_Name");
      assert (testAtt.getStringValue().equalsIgnoreCase("SPOL"));

      testAtt = ncfile.getRootGroup().findAttribute("VolumeCoveragePatternName");
      assert (testAtt.getStringValue().equalsIgnoreCase("SUR"));

      testAtt = ncfile.getRootGroup().findAttribute("Volume_Number");
      assert (testAtt.getStringValue().equalsIgnoreCase("1"));

      testAtt = ncfile.getRootGroup().findAttribute("Sweep_Number");
      assert (testAtt.getStringValue().equalsIgnoreCase("2"));

      testAtt = ncfile.getRootGroup().findAttribute("Sweep_Date");
      assert (testAtt.getStringValue().equalsIgnoreCase("2002-05-11 01:58:15Z"));

      Variable var;
      var = ncfile.findVariable("elevation");
      testReadData(var);
      var = ncfile.findVariable("azimuth");
      testReadData(var);
      var = ncfile.findVariable("distance_1");
      testReadData(var);
      var = ncfile.findVariable("latitudes_1");
      testReadData(var);
      var = ncfile.findVariable("longitudes_1");
      testReadData(var);
      var = ncfile.findVariable("altitudes_1");
      testReadData(var);
      var = ncfile.findVariable("rays_time");
      testReadData(var);
      var = ncfile.findVariable("Range_to_First_Cell");
      float t = testReadScalar(var);
      assert (t == (float) 150.0);

      var = ncfile.findVariable("Cell_Spacing");
      t = testReadScalar(var);
      assert (t == (float) 149.89624);
      var = ncfile.findVariable("Fixed_Angle");
      t = testReadScalar(var);
      assert (t == (float) 1.1975098);
      var = ncfile.findVariable("Nyquist_Velocity");
      t = testReadScalar(var);
      assert (t == (float) 25.618269);
      var = ncfile.findVariable("Unambiguous_Range");
      t = testReadScalar(var);
      assert (t == (float) 156.11694);
      var = ncfile.findVariable("Radar_Constant");
      t = testReadScalar(var);
      assert (t == (float) 70.325195);
      var = ncfile.findVariable("rcvr_gain");
      t = testReadScalar(var);
      assert (t == (float) 46.95);
      var = ncfile.findVariable("ant_gain");
      t = testReadScalar(var);
      assert (t == (float) 45.58);
      var = ncfile.findVariable("sys_gain");
      t = testReadScalar(var);
      assert (t == (float) 46.95);
      var = ncfile.findVariable("bm_width");
      t = testReadScalar(var);
      assert (t == (float) 0.92);

      var = ncfile.findVariable("VE");
      testReadData(var);
      var = ncfile.findVariable("DM");
      testReadData(var);
      var = ncfile.findVariable("NCP");
      testReadData(var);
      var = ncfile.findVariable("SW");
      testReadData(var);
      var = ncfile.findVariable("DZ");
      testReadData(var);
      var = ncfile.findVariable("DCZ");
      testReadData(var);
      var = ncfile.findVariable("LVDR");
      testReadData(var);
      var = ncfile.findVariable("NIQ");
      testReadData(var);
      var = ncfile.findVariable("AIQ");
      testReadData(var);
      var = ncfile.findVariable("CH");
      testReadData(var);
      var = ncfile.findVariable("AH");
      testReadData(var);
      var = ncfile.findVariable("CV");
      testReadData(var);
      var = ncfile.findVariable("AV");
      testReadData(var);
      var = ncfile.findVariable("RHOHV");
      testReadData(var);
      var = ncfile.findVariable("LDR");
      testReadData(var);
      var = ncfile.findVariable("DL");
      testReadData(var);
      var = ncfile.findVariable("DX");
      testReadData(var);
      var = ncfile.findVariable("ZDR");
      testReadData(var);
      var = ncfile.findVariable("PHI");
      testReadData(var);
      var = ncfile.findVariable("KDP");
      testReadData(var);

      assert (0 == var.findDimensionIndex("radial"));
      assert (1 == var.findDimensionIndex("gate_1"));
    }
  }
コード例 #15
0
ファイル: TestDorade.java プロジェクト: msdsoftware/thredds
  @Test
  public void testDoradeAir() throws IOException {
    System.out.println("**** Open " + airDoradeFile);
    try (NetcdfFile ncfile = NetcdfFile.open(airDoradeFile)) {

      for (Variable v : ncfile.getVariables()) {
        System.out.println(v.getFullName());
      }

      Dimension gateDim = ncfile.getRootGroup().findDimension("gate_1");
      assert (gateDim.getLength() == 320);
      Dimension radialDim = ncfile.getRootGroup().findDimension("radial");
      assert (radialDim.getLength() == 274);

      Variable var;
      var = ncfile.findVariable("elevation");
      testReadData(var);
      var = ncfile.findVariable("azimuth");
      testReadData(var);
      var = ncfile.findVariable("distance_1");
      testReadData(var);
      var = ncfile.findVariable("latitudes_1");
      testReadData(var);
      var = ncfile.findVariable("longitudes_1");
      testReadData(var);
      var = ncfile.findVariable("altitudes_1");
      testReadData(var);
      var = ncfile.findVariable("rays_time");
      testReadData(var);

      var = ncfile.findVariable("Range_to_First_Cell");
      float t = testReadScalar(var);
      assert (t == (float) -2.0);
      var = ncfile.findVariable("Cell_Spacing");
      t = testReadScalar(var);
      assert (t == (float) 150.0);
      var = ncfile.findVariable("Fixed_Angle");
      t = testReadScalar(var);
      assert (t == (float) -16.53);
      var = ncfile.findVariable("Nyquist_Velocity");
      t = testReadScalar(var);
      assert (t == (float) 78.03032);
      var = ncfile.findVariable("Unambiguous_Range");
      t = testReadScalar(var);
      assert (t == (float) 60.0);
      var = ncfile.findVariable("Radar_Constant");
      t = testReadScalar(var);
      assert (t == (float) -81.17389);
      var = ncfile.findVariable("rcvr_gain");
      t = testReadScalar(var);
      assert (t == (float) 32.64);
      var = ncfile.findVariable("ant_gain");
      t = testReadScalar(var);
      assert (t == (float) 39.35);
      var = ncfile.findVariable("sys_gain");
      t = testReadScalar(var);
      assert (t == (float) 52.34);
      var = ncfile.findVariable("bm_width");
      t = testReadScalar(var);
      assert (t == (float) 1.79);

      var = ncfile.findVariable("VS");
      testReadData(var);
      var = ncfile.findVariable("VL");
      testReadData(var);
      var = ncfile.findVariable("SW");
      testReadData(var);
      var = ncfile.findVariable("VR");
      testReadData(var);
      var = ncfile.findVariable("NCP");
      testReadData(var);
      var = ncfile.findVariable("DBZ");
      testReadData(var);
      var = ncfile.findVariable("VG");
      testReadData(var);
      var = ncfile.findVariable("VT");
      testReadData(var);
      assert (null != var.getDimension(0));
      assert (null != var.getDimension(1));
    }
  }
コード例 #16
0
  @Test
  public void testArraySubset() throws IOException {
    DODSNetcdfFile dodsfile = TestDODSRead.open("test.02?i32[1:10],f64[2:2:10]");

    Variable v = null;
    Array a = null;

    // int32
    assert (null != (v = dodsfile.findVariable("i32")));
    assert v.getFullName().equals("i32");
    assert v.getRank() == 1;
    assert v.getSize() == 10;
    assert v.getDataType() == DataType.INT;
    a = v.read();
    assert a.getRank() == 1;
    assert a.getSize() == 25;
    assert a.getElementType() == int.class;
    assert a instanceof ArrayInt.D1;

    ArrayInt.D1 ai = (ArrayInt.D1) a;
    for (int i = 0; i < 10; i++) {
      int val = ai.get(i);
      assert (val == i * 2048) : val + " != " + (i * 2048);
    }

    // uint16
    assert null == (v = dodsfile.findVariable("ui16"));
    assert null == (v = dodsfile.findVariable("ui32"));

    // double
    assert (null != (v = dodsfile.findVariable("f64")));
    assert v.getFullName().equals("f64");
    assert v.getRank() == 1;
    assert v.getSize() == 5;
    assert v.getDataType() == DataType.DOUBLE : v.getDataType();
    a = v.read();
    assert a.getRank() == 1;
    assert a.getSize() == 25;
    assert a.getElementType() == double.class;
    assert a instanceof ArrayDouble.D1;
    ArrayDouble.D1 ad = (ArrayDouble.D1) a;
    double[] tFloat64 =
        new double[] {
          1.0,
          0.9999500004166653,
          0.9998000066665778,
          0.9995500337489875,
          0.9992001066609779,
          0.9987502603949663,
          0.9982005399352042,
          0.9975510002532796,
          0.9968017063026194,
          0.9959527330119943,
          0.9950041652780257,
          0.9939560979566968,
          0.9928086358538663,
          0.9915618937147881,
          0.9902159962126371,
          0.9887710779360422,
          0.9872272833756269,
          0.9855847669095608,
          0.9838436927881214,
          0.9820042351172703,
          0.9800665778412416,
          0.9780309147241483,
          0.9758974493306055,
          0.9736663950053749,
          0.9713379748520297
        };

    for (int i = 0; i < 5; i++) {
      double val = ad.get(i);
      assert Misc.closeEnough(val, tFloat64[i], 1.0e-9);
    }

    dodsfile.close();
  }