Java Code Examples for ucar.ma2.Array#getFloat()

The following examples show how to use ucar.ma2.Array#getFloat() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestAggFmrc.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testDataValues() throws IOException {
  Array valuesScan = varScan.read();
  Array valuesExplicit = varExplicit.read();
  List<int[]> idxs = new ArrayList<>();
  idxs.add(new int[] {0, 0, 0, 0, 0});
  idxs.add(new int[] {2, 20, 5, 38, 44});
  idxs.add(new int[] {1, 10, 3, 19, 22});

  Index idx = Index.factory(valuesScan.getShape());

  for (int[] loc : idxs) {
    idx.set(loc);
    float a = valuesScan.getFloat(idx);
    float b = valuesExplicit.getFloat(idx);
    Assert.assertEquals(a, b, 0);
  }
}
 
Example 2
Source File: TestGribMisc.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testReadBadEcmwf() throws IOException {
  Grib1RecordScanner.setAllowBadDsLength(true);
  Grib1RecordScanner.setAllowBadIsLength(true);

  String filename = TestDir.cdmUnitTestDir + "formats/grib1/problem/badEcmwf.grib1";
  try (NetcdfFile nc = NetcdfFiles.open(filename)) {

    Variable var = nc.findVariable("2_metre_temperature_surface");
    Array data = var.read();
    int npts = 2560 * 5136;
    Assert.assertEquals(npts, data.getSize());

    float first = data.getFloat(0);
    float last = data.getFloat(npts - 1);

    Assert.assertEquals(273.260162, first, 1e-6);
    Assert.assertEquals(224.599670, last, 1e-6);
  }

  Grib1RecordScanner.setAllowBadDsLength(false);
  Grib1RecordScanner.setAllowBadIsLength(false);
}
 
Example 3
Source File: TestGrib1Unpack.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testThinGridAtEndofFile() throws IOException {
  final String testfile = "../grib/src/test/data/thinGrid.grib1";
  try (NetcdfFile nc = NetcdfFiles.open(testfile)) {

    Variable var = nc.findVariable("Temperature_isobaric");
    Array data = var.read();
    Assert.assertEquals(73 * 73, data.getSize());

    float first = data.getFloat(0);
    float last = data.getFloat((73 * 73) - 1);

    Assert.assertEquals(291.0, first, 1e-6);
    Assert.assertEquals(278.0, last, 1e-6);
  }
}
 
Example 4
Source File: GeotiffWriter.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void dump(Array data, int col) {
  int[] shape = data.getShape();
  Index ima = data.getIndex();

  for (int j = 0; j < shape[0]; j++) {
    float dd = data.getFloat(ima.set(j, col));
    System.out.println(j + " value= " + dd);
  }
}
 
Example 5
Source File: TestCoverageSubsetTime.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test // 1 runtime, 1 time (Time2DCoordSys case 1b)
public void test1Runtime1TimeIntervalEdge() throws IOException, InvalidRangeException {
  String endpoint = TestDir.cdmUnitTestDir + "gribCollections/gfs_2p5deg/gfs_2p5deg.ncx4";
  String covName = "Momentum_flux_u-component_surface_Mixed_intervals_Average";

  logger.debug("test1Runtime1TimeInterval Dataset {} coverage {}", endpoint, covName);

  try (FeatureDatasetCoverage cc = CoverageDatasetFactory.open(endpoint)) {
    Assert.assertNotNull(endpoint, cc);
    CoverageCollection gcs = cc.findCoverageDataset(FeatureType.FMRC);
    Assert.assertNotNull("gcs", gcs);
    Coverage cover = gcs.findCoverage(covName);
    Assert.assertNotNull(covName, cover);

    SubsetParams params = new SubsetParams();
    CalendarDate runtime = CalendarDate.parseISOformat(null, "2015-03-01T00:00:00Z");
    params.set(SubsetParams.runtime, runtime);
    CalendarDate time = CalendarDate.parseISOformat(null, "2015-03-06T19:30:00Z"); // (6,12), (12,18)
    params.set(SubsetParams.time, time);
    logger.debug("  subset {}", params);

    GeoReferencedArray geo = cover.readData(params);
    testGeoArray(geo, runtime, time, null);

    Array data = geo.getData();
    Index ai = data.getIndex();
    float testValue = data.getFloat(ai.set(0, 0, 3, 0));
    Assert2.assertNearlyEquals(0.244f, testValue);
  }
}
 
Example 6
Source File: TestCoverageSubsetTime.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test // 1 runtime, 1 time (Time2DCoordSys case 1b)
public void test1Runtime1TimeInterval() throws IOException, InvalidRangeException {
  String endpoint = TestDir.cdmUnitTestDir + "gribCollections/gfs_2p5deg/gfs_2p5deg.ncx4";
  String covName = "Momentum_flux_u-component_surface_Mixed_intervals_Average";

  logger.debug("test1Runtime1TimeInterval Dataset {} coverage {}", endpoint, covName);

  try (FeatureDatasetCoverage cc = CoverageDatasetFactory.open(endpoint)) {
    Assert.assertNotNull(endpoint, cc);
    CoverageCollection gcs = cc.findCoverageDataset(FeatureType.FMRC);
    Assert.assertNotNull("gcs", gcs);
    Coverage cover = gcs.findCoverage(covName);
    Assert.assertNotNull(covName, cover);

    SubsetParams params = new SubsetParams();
    CalendarDate runtime = CalendarDate.parseISOformat(null, "2015-03-01T06:00:00Z");
    params.set(SubsetParams.runtime, runtime);
    CalendarDate time = CalendarDate.parseISOformat(null, "2015-03-01T11:00:00Z"); // (6,12), (12,18)
    params.set(SubsetParams.time, time);
    logger.debug("  subset {}", params);

    GeoReferencedArray geo = cover.readData(params);
    testGeoArray(geo, runtime, time, null);

    Array data = geo.getData();
    Index ai = data.getIndex();
    float testValue = data.getFloat(ai.set(0, 0, 2, 2));
    Assert2.assertNearlyEquals(0.073f, testValue);
  }
}
 
Example 7
Source File: TestCoverageSubsetTime.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test // 1 runtime, 1 time (Time2DCoordSys case 1b)
public void test1Runtime1Time() throws IOException, InvalidRangeException {
  String endpoint = TestDir.cdmUnitTestDir + "gribCollections/gfs_2p5deg/gfs_2p5deg.ncx4";
  String covName = "Total_ozone_entire_atmosphere_single_layer";

  logger.debug("test1Runtime1Time Dataset {} coverage {}", endpoint, covName);

  try (FeatureDatasetCoverage cc = CoverageDatasetFactory.open(endpoint)) {
    Assert.assertNotNull(endpoint, cc);
    CoverageCollection gcs = cc.findCoverageDataset(FeatureType.FMRC);
    Assert.assertNotNull("gcs", gcs);
    Coverage cover = gcs.findCoverage(covName);
    Assert.assertNotNull(covName, cover);

    SubsetParams params = new SubsetParams();
    CalendarDate runtime = CalendarDate.parseISOformat(null, "2015-03-01T06:00:00Z");
    params.set(SubsetParams.runtime, runtime);
    CalendarDate time = CalendarDate.parseISOformat(null, "2015-03-01T12:00:00Z");
    params.set(SubsetParams.time, time);
    logger.debug("  subset {}", params);

    GeoReferencedArray geo = cover.readData(params);
    testGeoArray(geo, runtime, time, null);

    Array data = geo.getData();
    Index ai = data.getIndex();
    float testValue = data.getFloat(ai.set(0, 0, 1, 0));
    Assert2.assertNearlyEquals(371.5, testValue);
  }
}
 
Example 8
Source File: TestGrib1Unpack.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testEcmwfExtendedComplexData() throws IOException {
  final String testfile = "../grib/src/test/data/complex_packing.grib1";
  try (NetcdfFile nc = NetcdfFiles.open(testfile)) {
    Variable var = nc.findVariable("Minimum_temperature_at_2_metres_in_the_last_6_hours_surface_6_Hour");
    Array data = var.read();
    float first = data.getFloat(0);

    Assert.assertEquals(264.135559, first, 1e-6);
  }
}
 
Example 9
Source File: TestGrib1Unpack.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testEcmwfExtendedComplexData2() throws IOException {
  final String testfile = "../grib/src/test/data/complex_packing2.grib1";
  try (NetcdfFile nc = NetcdfFiles.open(testfile)) {

    Variable var = nc.findVariable("Snowfall_surface");
    Array data = var.read();

    float first = data.getFloat(0);

    Assert.assertEquals(.326607, first, 1e-6);
  }
}