Exemple #1
0
  @Test
  public void NetCDFTestAscatL1()
      throws NoSuchAuthorityCodeException, FactoryException, IOException, ParseException {
    File mosaic = new File(TestData.file(this, "."), "NetCDFTestAscatL1");
    if (mosaic.exists()) {
      FileUtils.deleteDirectory(mosaic);
    }
    assertTrue(mosaic.mkdirs());
    File file = TestData.file(this, "ascatl1.nc");
    FileUtils.copyFileToDirectory(file, mosaic);
    file = new File(mosaic, "ascatl1.nc");

    final Hints hints =
        new Hints(Hints.DEFAULT_COORDINATE_REFERENCE_SYSTEM, CRS.decode("EPSG:4326", true));
    hints.add(new Hints(Utils.EXCLUDE_MOSAIC, true));

    // Get format
    final AbstractGridFormat format =
        (AbstractGridFormat) GridFormatFinder.findFormat(file.toURI().toURL(), hints);
    final NetCDFReader reader = (NetCDFReader) format.getReader(file.toURI().toURL(), hints);

    assertNotNull(format);
    try {
      String[] names = reader.getGridCoverageNames();
      names = new String[] {names[1]};

      for (String coverageName : names) {

        final String[] metadataNames = reader.getMetadataNames(coverageName);
        assertNotNull(metadataNames);
        assertEquals(17, metadataNames.length);

        // Parsing metadata values
        assertEquals("false", reader.getMetadataValue(coverageName, "HAS_TIME_DOMAIN"));

        assertEquals("false", reader.getMetadataValue(coverageName, "HAS_ELEVATION_DOMAIN"));

        assertEquals("true", reader.getMetadataValue(coverageName, "HAS_NUMSIGMA_DOMAIN"));
        final String sigmaMetadata = reader.getMetadataValue(coverageName, "NUMSIGMA_DOMAIN");
        assertNotNull(sigmaMetadata);
        assertEquals("0,1,2", sigmaMetadata);
        assertEquals(3, sigmaMetadata.split(",").length);

        // subsetting the envelope
        final ParameterValue<GridGeometry2D> gg =
            AbstractGridFormat.READ_GRIDGEOMETRY2D.createValue();
        final GeneralEnvelope originalEnvelope = reader.getOriginalEnvelope(coverageName);
        final GeneralEnvelope reducedEnvelope =
            new GeneralEnvelope(
                new double[] {
                  originalEnvelope.getLowerCorner().getOrdinate(0),
                  originalEnvelope.getLowerCorner().getOrdinate(1)
                },
                new double[] {
                  originalEnvelope.getMedian().getOrdinate(0),
                  originalEnvelope.getMedian().getOrdinate(1)
                });
        reducedEnvelope.setCoordinateReferenceSystem(
            reader.getCoordinateReferenceSystem(coverageName));

        // Selecting bigger gridRange for a zoomed result
        final Dimension dim = new Dimension();
        GridEnvelope gridRange = reader.getOriginalGridRange(coverageName);
        dim.setSize(gridRange.getSpan(0) * 4.0, gridRange.getSpan(1) * 2.0);
        final Rectangle rasterArea = ((GridEnvelope2D) gridRange);
        rasterArea.setSize(dim);
        final GridEnvelope2D range = new GridEnvelope2D(rasterArea);
        gg.setValue(new GridGeometry2D(range, reducedEnvelope));

        ParameterValue<List<String>> sigmaValue = null;
        final String selectedSigma = "1";
        Set<ParameterDescriptor<List>> params = reader.getDynamicParameters(coverageName);
        for (ParameterDescriptor param : params) {
          if (param.getName().getCode().equalsIgnoreCase("NUMSIGMA")) {
            sigmaValue = param.createValue();
            sigmaValue.setValue(
                new ArrayList<String>() {
                  {
                    add(selectedSigma);
                  }
                });
          }
        }

        GeneralParameterValue[] values = new GeneralParameterValue[] {gg, sigmaValue};
        GridCoverage2D coverage = reader.read(coverageName, values);
        assertNotNull(coverage);
        if (TestData.isInteractiveTest()) {
          coverage.show();
        } else {
          PlanarImage.wrapRenderedImage(coverage.getRenderedImage()).getTiles();
        }
      }
    } catch (Throwable t) {
      throw new RuntimeException(t);
    } finally {
      if (reader != null) {
        try {
          reader.dispose();
        } catch (Throwable t) {
          // Does nothing
        }
      }
    }
  }
 /** Helper method for parameter descriptor creation. */
 private static final NamedIdentifier[] identifiers(final ParameterDescriptor parameter) {
   final Collection<GenericName> id = parameter.getAlias();
   return id.toArray(new NamedIdentifier[id.size()]);
 }
Exemple #3
0
  @SuppressWarnings({"rawtypes", "unchecked"})
  @Test
  @Ignore
  public void IASI() throws Exception {

    final URL testURL = TestData.url(this, "IASI_C_EUMP_20121120062959_31590_eps_o_l2.nc");
    final Hints hints =
        new Hints(Hints.DEFAULT_COORDINATE_REFERENCE_SYSTEM, CRS.decode("EPSG:4326", true));
    // Get format
    final AbstractGridFormat format =
        (AbstractGridFormat) GridFormatFinder.findFormat(testURL, hints);
    final NetCDFReader reader = (NetCDFReader) format.getReader(testURL, hints);
    assertNotNull(format);
    assertNotNull(reader);
    try {
      String[] names = reader.getGridCoverageNames();
      assertNotNull(names);
      assertEquals(names.length, 20);

      // surface_emissivity
      final String coverageName = "surface_emissivity";
      final String[] metadataNames = reader.getMetadataNames(coverageName);
      assertNotNull(metadataNames);
      assertEquals(14, metadataNames.length);

      // Parsing metadata values
      assertEquals("false", reader.getMetadataValue(coverageName, "HAS_TIME_DOMAIN"));
      assertEquals("false", reader.getMetadataValue(coverageName, "HAS_ELEVATION_DOMAIN"));
      assertEquals("true", reader.getMetadataValue(coverageName, "HAS_NEW_DOMAIN"));

      // additional domains
      final String newDomain = reader.getMetadataValue(coverageName, "NEW_DOMAIN");
      assertNotNull(metadataNames);
      final String[] newDomainValues = newDomain.split(",");
      assertNotNull(newDomainValues);
      assertEquals(12, newDomainValues.length);
      assertEquals(13.063399669990758, Double.valueOf(newDomainValues[11]), 1E-6);
      assertEquals(3.6231999084702693, Double.valueOf(newDomainValues[0]), 1E-6);

      // subsetting the envelope
      final ParameterValue<GridGeometry2D> gg =
          AbstractGridFormat.READ_GRIDGEOMETRY2D.createValue();
      final GeneralEnvelope originalEnvelope = reader.getOriginalEnvelope(coverageName);
      final GeneralEnvelope reducedEnvelope =
          new GeneralEnvelope(
              new double[] {
                originalEnvelope.getLowerCorner().getOrdinate(0),
                originalEnvelope.getLowerCorner().getOrdinate(1)
              },
              new double[] {
                originalEnvelope.getMedian().getOrdinate(0),
                originalEnvelope.getMedian().getOrdinate(1)
              });
      reducedEnvelope.setCoordinateReferenceSystem(
          reader.getCoordinateReferenceSystem(coverageName));

      // Selecting bigger gridRange for a zoomed result
      final Dimension dim = new Dimension();
      GridEnvelope gridRange = reader.getOriginalGridRange(coverageName);
      dim.setSize(gridRange.getSpan(0) * 4.0, gridRange.getSpan(1) * 2.0);
      final Rectangle rasterArea = ((GridEnvelope2D) gridRange);
      rasterArea.setSize(dim);
      final GridEnvelope2D range = new GridEnvelope2D(rasterArea);
      gg.setValue(new GridGeometry2D(range, reducedEnvelope));

      // specify additional Dimensions
      Set<ParameterDescriptor<List>> params = reader.getDynamicParameters(coverageName);
      ParameterValue<List> new_ = null;
      for (ParameterDescriptor param : params) {
        if (param.getName().getCode().equalsIgnoreCase("NEW")) {
          new_ = param.createValue();
          new_.setValue(
              new ArrayList() {
                {
                  add(Double.valueOf(newDomainValues[11]));
                }
              });
        }
      }

      GeneralParameterValue[] values = new GeneralParameterValue[] {gg, new_};
      GridCoverage2D coverage = reader.read(coverageName, values);
      assertNotNull(coverage);
      if (TestData.isInteractiveTest()) {
        coverage.show();
      } else {
        PlanarImage.wrapRenderedImage(coverage.getRenderedImage()).getTiles();
      }
    } finally {
      if (reader != null) {
        try {
          reader.dispose();
        } catch (Throwable t) {
          // Does nothing
        }
      }
    }
  }