public WcsRangeField( GridDatatype gridDatatype ) { if ( gridDatatype == null) throw new IllegalArgumentException( "Range field must be non-null."); this.gridDatatype = gridDatatype; this.name = this.gridDatatype.getFullName(); this.label = this.gridDatatype.getInfo(); this.description = this.gridDatatype.getDescription(); this.datatypeString = this.gridDatatype.getDataType().toString(); this.unitsString = this.gridDatatype.getUnitsString(); this.validMin = this.gridDatatype.getVariable().getValidMin(); this.validMax = this.gridDatatype.getVariable().getValidMax(); // ToDo GeoGrids only handle scalar range fields. (???) axes = Collections.emptyList(); }
@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 testUnpackedValidRange() throws IOException, URISyntaxException { File testResource = new File(getClass().getResource("testScaleOffsetMissingUnsigned.ncml").toURI()); DatasetUrl location = DatasetUrl.findDatasetUrl(testResource.getAbsolutePath()); Set<Enhance> enhanceMode = EnumSet.of(Enhance.ConvertUnsigned, Enhance.ApplyScaleOffset); // No ConvertMissing! try (NetcdfDataset ncd = NetcdfDataset.openDataset(location, enhanceMode, -1, null, null)) { VariableDS var = (VariableDS) ncd.findVariable("unpackedValidRange"); // valid_range will be interpreted as unpacked because of: /* * If valid_range is the same type as scale_factor (actually the wider of scale_factor and add_offset) and this * is wider than the external data, then it will be interpreted as being in the units of the internal (unpacked) * data. Otherwise it is in the units of the external (packed) data.</li> */ // As a result, scale_factor will not be applied to it. 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[] { 9.8f, 9.9f, 10.0f, 10.1f, 10.2f }; float[] actuals = (float[]) var.read().getStorage(); Assert2.assertArrayNearlyEquals(expecteds, actuals); } }
@Test public void testMissingUnsigned() throws URISyntaxException, IOException { File testResource = new File(getClass().getResource("testScaleOffsetMissingUnsigned.ncml").toURI()); try (NetcdfDataset ncd = NetcdfDataset.openDataset(testResource.getAbsolutePath(), true, null)) { VariableDS var = (VariableDS) ncd.findVariable("missingUnsigned"); // Packed valid_min == -106. Interpreting bit pattern as unsigned, we get 150. Assert2.assertNearlyEquals(150, var.getValidMin()); // Packed valid_min == -6. Interpreting bit pattern as unsigned, we get 250. Assert2.assertNearlyEquals(250, var.getValidMax()); // Packed _FillValue and missing_value are -1. Interpreting bit pattern as unsigned, we get 255. Assert2.assertNearlyEquals(255, var.getFillValue()); Assert2.assertNearlyEquals(255, var.getMissingValues()[0]); // "missingUnsigned" was originally UBYTE, but was widened to accommodate unsigned conversion. Assert.assertEquals(DataType.USHORT, var.getDataType()); // Packed values are: -107, -106, -6, -5, -1, 80. Interpreting them as unsigned yields: short[] expecteds = new short[] { 149, 150, 250, 251, 255, 80 }; short[] actuals = (short[]) var.read().getStorage(); Assert.assertArrayEquals(expecteds, actuals); } }
Assert.assertEquals(25001, var.getValidMax(), 0);
Assert2.assertNearlyEquals(1, fooVar.getValidMax(), Misc.defaultMaxRelativeDiffFloat);