Exemple #1
0
  public static void main(String[] args) throws Exception {
    DiskCache.setCachePolicy(true);

    File f = new File(args[0]);
    Pair<String, String> nameParts = FileNames.splitExtension(f);
    String ext = nameParts.b;
    if (ext.equals("grb") || ext.equals("bz2") || ext.equals("gz")) {
      Map<String, Metadata> metaMap = ConvertNetCDF.readFile(f.getAbsolutePath());

      /* Don't cache more than 1 GB: */
      DiskCache.cleanCache(1073741824, null);

      /*String[] attribs = { "temperature_surface",
      "total_cloud_cover_entire_atmosphere",
      "visibility_surface",
      "pressure_surface",
      "categorical_snow_yes1_no0_surface",
      "categorical_rain_yes1_no0_surface",
      "relative_humidity_zerodegc_isotherm" };*/
      String[] attribs = {"U-component_of_wind"};
      Metadata m = metaMap.get("9x");
      System.out.print("9x@" + m.getTemporalProperties().getStart() + "\t");
      for (String attrib : attribs) {
        System.out.print(m.getAttribute(attrib).getString() + "\t");
      }
      System.out.println();
    }
  }
Exemple #2
0
 /** Creates a block/metadata pair subset for indexing. */
 public static Block createBlock(String name, Metadata meta) throws IOException {
   Metadata m = new Metadata(name);
   addIndexField("visibility", meta, m);
   addIndexField("pressure", meta, m);
   addIndexField("total_precipitation", meta, m);
   addIndexField("precipitable_water", meta, m);
   addIndexField("temperature_surface", meta, m);
   addIndexField("total_cloud_cover", meta, m);
   addIndexField("snow_depth", meta, m);
   m.setTemporalProperties(meta.getTemporalProperties());
   m.setSpatialProperties(meta.getSpatialProperties());
   Block block = new Block("samples", m, Serializer.serialize(meta));
   return block;
 }
Exemple #3
0
  /**
   * Determines the storage directory for a file, using its spatial properties run through the
   * Geohash algorithm.
   *
   * <p>The resulting format is xx/xxx, which is specific to the NOAA NAM dataset, because this will
   * place each unique grid point in its own directory.
   */
  private static String getStorageDir(String outputDir, Metadata meta) {
    Coordinates coords = meta.getSpatialProperties().getCoordinates();
    String location = GeoHash.encode(coords.getLatitude(), coords.getLongitude(), 10);

    String subDir = location.substring(0, 2) + "/" + location.substring(2, 5);
    return outputDir + "/" + subDir;
  }
Exemple #4
0
  /** 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);
      }
    }
  }
Exemple #5
0
 /**
  * Takes a Metadata instance being used as Block content, and extracts the given Feature for
  * indexing purposes.
  */
 private static void addIndexField(String featureName, Metadata baseMeta, Metadata indexMeta) {
   Feature f = baseMeta.getAttribute(featureName);
   if (f != null) {
     indexMeta.putAttribute(f);
   }
 }