Skip to content

Commit

Permalink
PR feedback and ignore DAP4 remote tests
Browse files Browse the repository at this point in the history
  • Loading branch information
haileyajohnson committed Jul 6, 2023
1 parent aa203e7 commit 5a56969
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cdm/core/src/main/java/ucar/nc2/dataset/NetcdfDataset.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public enum Enhance {
/** Apply scale and offset to values, promoting the data type if needed. */
ApplyScaleOffset,
/**
* Replace {@link EnhanceScaleMissingUnsigned#isMissing missing} data with NaNs, for efficiency. Note that if the
* Replace {@link ucar.nc2.filter.ConvertMissing#isMissing missing} data with NaNs, for efficiency. Note that if the
* enhanced data type is not {@code FLOAT} or {@code DOUBLE}, this has no effect.
*/
ConvertMissing,
Expand Down
6 changes: 3 additions & 3 deletions cdm/core/src/main/java/ucar/nc2/dataset/VariableDS.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,7 @@ Array convert(Array data, Set<NetcdfDataset.Enhance> enhancements) {
if (enhancements.contains(Enhance.ApplyScaleOffset) && scaleOffset != null) {
data = scaleOffset.removeScaleOffset(data);
}
if (enhancements.contains(Enhance.ConvertMissing) && convertMissing != null
&& (dataType == DataType.FLOAT || dataType == DataType.DOUBLE)) {
if (enhancements.contains(Enhance.ConvertMissing) && convertMissing != null) {
data = convertMissing.convertMissing(data);
}
return data;
Expand Down Expand Up @@ -870,7 +869,8 @@ private void createEnhancements() {
}
}
}
if (this.enhanceMode.contains(Enhance.ConvertMissing)) {
if (this.enhanceMode.contains(Enhance.ConvertMissing)
&& (dataType == DataType.FLOAT || dataType == DataType.DOUBLE)) {
this.convertMissing = ConvertMissing.createFromVariable(this);
}
}
Expand Down
8 changes: 7 additions & 1 deletion cdm/core/src/main/java/ucar/nc2/filter/ScaleOffset.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,17 @@ private static ByteOrder parseByteOrder(String dtype, ByteOrder defaultOrder) {

public double applyScaleOffset(Number value) {
double convertedValue = value.doubleValue();
return Math.round((convertedValue - offset) * scale);
if (astype.isIntegral()) {
return Math.round((convertedValue - offset) * scale);
}
return (convertedValue - offset) * scale;
}

public double removeScaleOffset(Number value) {
double convertedValue = value.doubleValue();
if (dtype.isIntegral()) {
return Math.round(convertedValue / scale + offset);
}
return convertedValue / scale + offset;
}

Expand Down
6 changes: 4 additions & 2 deletions cdm/core/src/test/java/ucar/nc2/filter/TestEnhancements.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class TestEnhancements {

private static final Short SIGNED_SCALED_MAX = -2;
private static final Short SIGNED_SCALED_FILL_VALUE = -4;
private static final Short SIGNED_SCALED_MISSING_VALUE = -3;

@ClassRule
public static final TemporaryFolder tempFolder = new TemporaryFolder();
Expand Down Expand Up @@ -71,7 +72,8 @@ public static void setUp() throws IOException, InvalidRangeException {
builder.addVariable("enhanceAll", DataType.SHORT, "dim").addAttribute(new Attribute(CDM.UNSIGNED, "true"))
.addAttribute(new Attribute(CDM.SCALE_FACTOR, 10.0)).addAttribute(new Attribute(CDM.ADD_OFFSET, 10))
.addAttribute(new Attribute(CDM.VALID_MAX, SIGNED_SCALED_MAX))
.addAttribute(new Attribute(CDM.FILL_VALUE, SIGNED_SCALED_FILL_VALUE));
.addAttribute(new Attribute(CDM.FILL_VALUE, SIGNED_SCALED_FILL_VALUE))
.addAttribute(new Attribute(CDM.MISSING_VALUE, SIGNED_SCALED_MISSING_VALUE));

// write data
NetcdfFormatWriter writer = builder.build();
Expand Down Expand Up @@ -145,7 +147,7 @@ public void testConvertMissing() throws IOException {

@Test
public void testCombinedEnhancements() throws IOException {
double[] expected = new double[] {655320, Double.NaN, 655340, 655350, Double.NaN, 10, 20, 30, 40, 50};
double[] expected = new double[] {655320, Double.NaN, Double.NaN, 655350, Double.NaN, 10, 20, 30, 40, 50};
Variable v = ncd.findVariable("enhanceAll");
Array data = v.read();
assertThat((double[]) data.copyTo1DJavaArray()).isEqualTo(expected);
Expand Down
2 changes: 2 additions & 0 deletions dap4/src/test/java/dap4/test/TestRemote.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import dap4.core.util.DapConstants;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
Expand All @@ -31,6 +32,7 @@
* tests by adding fields to the TestCase object.
*/

@Ignore("Disable while RemoteTest server is not working")
@RunWith(Parameterized.class)
public class TestRemote extends DapTestCommon implements Dap4ManifestIF {

Expand Down

0 comments on commit 5a56969

Please sign in to comment.