@Test public void testScaleValidRange() throws IOException, URISyntaxException { File testResource = new File(getClass().getResource("testScaleOffsetMissingUnsigned.ncml").toURI()); try (NetcdfDataset ncd = NetcdfDataset.openDataset(testResource.getAbsolutePath(), true, null)) { VariableDS var = (VariableDS) ncd.findVariable("scaleValidRange"); var.addEnhancement(Enhance.ConvertMissing); Assert2.assertNearlyEquals(9.9f, (float) var.getValidMin()); Assert2.assertNearlyEquals(10.1f, (float) var.getValidMax()); Assert.assertEquals(DataType.FLOAT, var.getDataType()); // scale_factor is float. float[] expecteds = new float[] { Float.NaN, 9.9f, 10.0f, 10.1f, Float.NaN }; float[] actuals = (float[]) var.read().getStorage(); Assert2.assertArrayNearlyEquals(expecteds, actuals); } }
@Test public void testScaledFillValue() throws URISyntaxException, IOException { File testResource = new File(getClass().getResource("testScaledFillValue.ncml").toURI()); try (NetcdfDataset ncd = NetcdfDataset.openDataset(testResource.getAbsolutePath(), true, null)) { VariableDS fooVar = (VariableDS) ncd.findVariable("foo"); double expectedFillValue = .99999; double actualFillValue = fooVar.getFillValue(); // Scale factor of "1.e-05" has been applied to original "99999". Assert2.assertNearlyEquals(expectedFillValue, actualFillValue); fooVar.removeEnhancement(Enhance.ConvertMissing); double fooValWithoutNaNs = fooVar.read().getDouble(0); // "foo" value is equals to fill value. Scale factor has been applied to both. Assert2.assertNearlyEquals(actualFillValue, fooValWithoutNaNs); // "foo" value is considered a fill. Assert.assertTrue(fooVar.isFillValue(fooValWithoutNaNs)); fooVar.addEnhancement(Enhance.ConvertMissing); double fooValWithNaNs = fooVar.read().getDouble(0); // "foo" value was converted to NaN because it was equal to _FillValue. Assert.assertTrue(Double.isNaN(fooValWithNaNs)); // Note that we can't use isFillValue() because we've applied the ConvertMissing enhancement. // See the EnhanceScaleMissingUnsigned Javadoc. Assert.assertTrue(fooVar.isMissing(fooValWithNaNs)); } }