Skip to content

Commit

Permalink
remove unused ncml, add int and float test
Browse files Browse the repository at this point in the history
  • Loading branch information
matakleo committed Jun 27, 2024
1 parent da03532 commit 87d5aa8
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 109 deletions.
3 changes: 1 addition & 2 deletions cdm/core/src/main/java/ucar/nc2/filter/Classifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public int classifyArray(double val) {
public int classifyArrayAttribute(double val) {
for (int[] rule : rules) {
if (val > rule[0] && val <= rule[1] + Misc.defaultMaxRelativeDiffFloat) {
return rule[2]; // Return the matched rule's value
return rule[2];
}
}
// Return min possible int if no rule matches
Expand All @@ -104,7 +104,6 @@ public int classifyArrayAttribute(double val) {
// Method to load classification rules from the attributes
private List<int[]> loadClassificationRules() {
for (String rules : this.AttCat) {
System.out.println("RULEZ" + rules);
int[] rule = stringToIntArray(rules);
this.rules.add(rule);
}
Expand Down
12 changes: 12 additions & 0 deletions cdm/core/src/test/data/ncml/enhance/testAddToClassifier.ncml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@
<values>-500000 NaN -10 0 1 2 3 11 25 29 NaN 100 150 121 102 199999 12211</values>
</variable>

<variable name="classify_ints" shape="17" type="int">
<attribute name="classify" value="NaN 0 0; 0 NaN 1"/>
<values>1 -2 0 4 -5</values>
</variable>

<variable name="classify_floats" shape="17" type="float">
<attribute name="classify" value="NaN 0 0; 0 NaN 1"/>
<values>1.0 -2.0 0.0 4.0 -5.0</values>
</variable>





</netcdf>
54 changes: 0 additions & 54 deletions cdm/core/src/test/data/ncml/enhance/testClassifier.ncml

This file was deleted.

51 changes: 0 additions & 51 deletions cdm/core/src/test/java/ucar/nc2/filter/TestClassifier.java

This file was deleted.

44 changes: 42 additions & 2 deletions cdm/core/src/test/java/ucar/nc2/ncml/TestEnhanceClassifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,52 @@
public class TestEnhanceClassifier {

private static String dataDir = TestDir.cdmLocalTestDataDir + "ncml/enhance/";

public static final int[] mixNumbers = {1, 0, 0, 1, 0};
public static final Array DATA_mixNumbers = Array.makeFromJavaArray(mixNumbers);
public static final int[] Classification_test =
{0, -2147483648, 0, 0, 10, 10, 10, 100, 100, 100, -2147483648, 100, 1000, 1000, 1000, 1000, 1000};
public static final Array CLASSIFICATION_TEST = Array.makeFromJavaArray(Classification_test);

/** test on doubles, all positives, all negatives and a mixed array */
@Test
public void testEnhanceClassifier_Ints() throws IOException {

try (NetcdfFile ncfile = NetcdfDatasets.openDataset(dataDir + "testAddToClassifier.ncml", true, null)) {

Variable classifySpecs = ncfile.findVariable("classify_ints");
assertThat((Object) classifySpecs).isNotNull();
assertThat(!classifySpecs.attributes().isEmpty()).isTrue();
Array Data = classifySpecs.read();
Classifier classifier = Classifier.createFromVariable(classifySpecs);
int[] ClassifiedArray = classifier.classifyWithAttributes(Data);
assertThat(nearlyEquals(Array.makeFromJavaArray(ClassifiedArray), DATA_mixNumbers)).isTrue();


} catch (IOException e) {
throw new RuntimeException(e);
}

}

@Test
public void testEnhanceClassifier_Floats() throws IOException {

try (NetcdfFile ncfile = NetcdfDatasets.openDataset(dataDir + "testAddToClassifier.ncml", true, null)) {

Variable classifySpecs = ncfile.findVariable("classify_floats");
assertThat((Object) classifySpecs).isNotNull();
assertThat(!classifySpecs.attributes().isEmpty()).isTrue();
Array Data = classifySpecs.read();
Classifier classifier = Classifier.createFromVariable(classifySpecs);
int[] ClassifiedArray = classifier.classifyWithAttributes(Data);
assertThat(nearlyEquals(Array.makeFromJavaArray(ClassifiedArray), DATA_mixNumbers)).isTrue();


} catch (IOException e) {
throw new RuntimeException(e);
}

}

@Test
public void testEnhanceClassifier_classification() throws IOException {

Expand Down

0 comments on commit 87d5aa8

Please sign in to comment.