From 82fdbe9c59fb1426378be22819f4fe5c0ee50f51 Mon Sep 17 00:00:00 2001 From: Leo Date: Wed, 22 May 2024 13:55:13 -0600 Subject: [PATCH 01/15] the best version so far --- .../java/ucar/nc2/filter/MinMaxScale.java | 78 +++++++++++++++++++ .../nc2/filter/QuantileTransformer1D.java | 41 ++++++++++ 2 files changed, 119 insertions(+) create mode 100644 cdm/core/src/main/java/ucar/nc2/filter/MinMaxScale.java create mode 100644 cdm/core/src/main/java/ucar/nc2/filter/QuantileTransformer1D.java diff --git a/cdm/core/src/main/java/ucar/nc2/filter/MinMaxScale.java b/cdm/core/src/main/java/ucar/nc2/filter/MinMaxScale.java new file mode 100644 index 0000000000..d6d6221364 --- /dev/null +++ b/cdm/core/src/main/java/ucar/nc2/filter/MinMaxScale.java @@ -0,0 +1,78 @@ +package ucar.nc2.filter; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import org.apache.commons.math.stat.descriptive.SummaryStatistics; +import ucar.ma2.Array; +import ucar.ma2.DataType; +import ucar.ma2.IndexIterator; +import ucar.nc2.dataset.VariableDS; + +public class Standard_Leo implements Enhancement { + private double min; + private double max; + private double newMin; + private double newMax; + + private final ScaleOffset scaleOffset; + private final double mean; + private final double stdDev; +/** VariableDS format is enhanced variable */ + public static Standard_Leo createFromVariable(VariableDS var) { + try { + Array arr = var.read(); + DataType type = var.getDataType(); + return createFromArray(arr, type); + } catch (IOException e) { + return new Standard_Leo(0.0, 1.0, var.getDataType()); + } + } + + public static Standard_Leo createFromArray(Array arr, DataType type) { + SummaryStatistics statistics = calculationHelper(arr); + if (statistics.getStandardDeviation() == 0) { + return new Standard_Leo(0.0, 1.0, type); + } + return new Standard_Leo(statistics.getMean(), statistics.getStandardDeviation(), type); + } + + private Standard_Leo(double mean, double stdDev, DataType type) { + this.mean = mean; + this.stdDev = stdDev; + Map props = new HashMap<>(); + props.put("offset", mean); + props.put("scale", 1 / stdDev); + props.put("dtype", type); + scaleOffset = new ScaleOffset(props); + } + + private static SummaryStatistics calculationHelper(Array arr) { + SummaryStatistics sumStat = new SummaryStatistics(); + IndexIterator iterArr = arr.getIndexIterator(); + while (iterArr.hasNext()) { + Number value = (Number) iterArr.getObjectNext(); + if (!Double.isNaN(value.doubleValue())) { + sumStat.addValue(value.doubleValue()); + } + } + return sumStat; + } + + public Array convert(Array arr) { + return scaleOffset.applyScaleOffset(arr); + } + + public double convert(double val) { + return scaleOffset.applyScaleOffset(val); + } + + public double getMean() { + return mean; + } + + public double getStdDev() { + return stdDev; + } +} + diff --git a/cdm/core/src/main/java/ucar/nc2/filter/QuantileTransformer1D.java b/cdm/core/src/main/java/ucar/nc2/filter/QuantileTransformer1D.java new file mode 100644 index 0000000000..88ee02a1ef --- /dev/null +++ b/cdm/core/src/main/java/ucar/nc2/filter/QuantileTransformer1D.java @@ -0,0 +1,41 @@ +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +public class QuantileTransformer1D { + public static double[] transform(double[] inputArray) { + // Step 1: Sorting + double[] sortedArray = Arrays.copyOf(inputArray, inputArray.length); + Arrays.sort(sortedArray); + + // Step 2: Assigning ranks + Map rankMap = new HashMap<>(); + for (int i = 0; i < sortedArray.length; i++) { + rankMap.put(sortedArray[i], i + 1); + } + + // Step 3: Calculating percentiles + double[] percentiles = new double[inputArray.length]; + for (int i = 0; i < inputArray.length; i++) { + double rank = rankMap.get(inputArray[i]); + double percentile = (rank - 1) / (inputArray.length - 1); + percentiles[i] = percentile; + } + + // Step 5: Applying transformation + double[] transformedArray = new double[inputArray.length]; + for (int i = 0; i < inputArray.length; i++) { + transformedArray[i] = percentiles[i]; + } + + return transformedArray; + } + + public static void main(String[] args) { + // Example usage + double[] data = {1.8, 2, 2.3, 2.4, 10, 11, 2, 5}; + Arrays.sort(data); + double[] transformedData = QuantileTransformer1D.transform(data); + System.out.println(Arrays.toString(transformedData)); + } +} From 20d02d5224b6826c7833df5ee2f0082e5bdaa11c Mon Sep 17 00:00:00 2001 From: Leo Date: Wed, 22 May 2024 15:53:46 -0600 Subject: [PATCH 02/15] matche python mostly --- .../src/main/java/ucar/nc2/filter/QuantileTransformer1D.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdm/core/src/main/java/ucar/nc2/filter/QuantileTransformer1D.java b/cdm/core/src/main/java/ucar/nc2/filter/QuantileTransformer1D.java index 88ee02a1ef..83ab21fb0d 100644 --- a/cdm/core/src/main/java/ucar/nc2/filter/QuantileTransformer1D.java +++ b/cdm/core/src/main/java/ucar/nc2/filter/QuantileTransformer1D.java @@ -33,7 +33,7 @@ public static double[] transform(double[] inputArray) { public static void main(String[] args) { // Example usage - double[] data = {1.8, 2, 2.3, 2.4, 10, 11, 2, 5}; + double[] data = {1.8, 2,2.3, 2.4, 5, 10, 11}; Arrays.sort(data); double[] transformedData = QuantileTransformer1D.transform(data); System.out.println(Arrays.toString(transformedData)); From dfdfbd014bbb71fc8e8cd58b07ad3d4746a943a2 Mon Sep 17 00:00:00 2001 From: Leo Date: Wed, 29 May 2024 10:47:31 -0600 Subject: [PATCH 03/15] before major change, kinda works --- .../ucar/nc2/filter/QuantileTransformer1D.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/cdm/core/src/main/java/ucar/nc2/filter/QuantileTransformer1D.java b/cdm/core/src/main/java/ucar/nc2/filter/QuantileTransformer1D.java index 83ab21fb0d..aa2ab4f837 100644 --- a/cdm/core/src/main/java/ucar/nc2/filter/QuantileTransformer1D.java +++ b/cdm/core/src/main/java/ucar/nc2/filter/QuantileTransformer1D.java @@ -1,9 +1,14 @@ import java.util.Arrays; import java.util.HashMap; import java.util.Map; +import java.util.TreeMap; +import java.util.Scanner; public class QuantileTransformer1D { public static double[] transform(double[] inputArray) { + + + // Step 1: Sorting double[] sortedArray = Arrays.copyOf(inputArray, inputArray.length); Arrays.sort(sortedArray); @@ -14,11 +19,19 @@ public static double[] transform(double[] inputArray) { rankMap.put(sortedArray[i], i + 1); } + // Create a TreeMap and pass the HashMap to its constructor + TreeMap sortedMap = new TreeMap<>(rankMap); + + // Print out the sorted contents of the HashMap + System.out.println("Contents of rankMap sorted by keys:"); + sortedMap.forEach((key, value) -> System.out.println(key + ": " + value)); + // Step 3: Calculating percentiles double[] percentiles = new double[inputArray.length]; for (int i = 0; i < inputArray.length; i++) { double rank = rankMap.get(inputArray[i]); double percentile = (rank - 1) / (inputArray.length - 1); + System.out.println("rank "+rank+" percentile, " + percentile); percentiles[i] = percentile; } @@ -33,7 +46,7 @@ public static double[] transform(double[] inputArray) { public static void main(String[] args) { // Example usage - double[] data = {1.8, 2,2.3, 2.4, 5, 10, 11}; + double[] data = {1.8, 2,2.3, 2.4,2.5, 5, 10, 11,12,13.1,14.4,15,16}; Arrays.sort(data); double[] transformedData = QuantileTransformer1D.transform(data); System.out.println(Arrays.toString(transformedData)); From d0f67e242a7ba47b5dba9f71fd837362fb89305d Mon Sep 17 00:00:00 2001 From: Leo Date: Wed, 29 May 2024 16:00:25 -0600 Subject: [PATCH 04/15] long one, all numpy stuff --- .../nc2/filter/QuantileTransformer1D.java | 234 ++++++++++++++++-- 1 file changed, 207 insertions(+), 27 deletions(-) diff --git a/cdm/core/src/main/java/ucar/nc2/filter/QuantileTransformer1D.java b/cdm/core/src/main/java/ucar/nc2/filter/QuantileTransformer1D.java index aa2ab4f837..a183e62ec4 100644 --- a/cdm/core/src/main/java/ucar/nc2/filter/QuantileTransformer1D.java +++ b/cdm/core/src/main/java/ucar/nc2/filter/QuantileTransformer1D.java @@ -1,54 +1,234 @@ + import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.TreeMap; import java.util.Scanner; +import org.apache.commons.math.MathException; +import org.apache.commons.math.distribution.NormalDistribution; +import org.apache.commons.math.distribution.NormalDistributionImpl; // Import the concrete class +//import org.apache.commons.math3.analysis.interpolation.LinearInterpolator + public class QuantileTransformer1D { - public static double[] transform(double[] inputArray) { + /** The actual number of quantiles used to discretize the cumulative + distribution function.*/ + private int n_quantiles_; + /** ndarray of shape (n_quantiles, n_features) + The values corresponding the quantiles of reference. + But in my case now it's only 1D, so shape (n_quantiles) */ + private double [] quantiles_; + /**ndarray of shape (n_quantiles, ) + Quantiles of references.*/ + private double [] references_; + /** to be used in constructor */ + private int n_quantiles; + /** to chose wether normal or uniform */ + private String outputDistribution; + // Default values + /** Constructor with all parameters */ + public QuantileTransformer1D(int n_quantiles, String outputDistribution) { + this.n_quantiles = n_quantiles; + this.outputDistribution = outputDistribution; + System.out.println("I am in the constructor"); + } - // Step 1: Sorting - double[] sortedArray = Arrays.copyOf(inputArray, inputArray.length); - Arrays.sort(sortedArray); + /** Dense matrix fit ? */ + /** should compute percentiles for dense matrix (i.e. not sparse) */ + public void _dense_fit(double [] X) { + // Initialize the references array with the same length as X + double[] references = new double[references_.length]; + /** X --> The data used to scale along the features axis. */ + int n_samples = X.length; - // Step 2: Assigning ranks - Map rankMap = new HashMap<>(); - for (int i = 0; i < sortedArray.length; i++) { - rankMap.put(sortedArray[i], i + 1); + for (int i = 0; i < this.references_.length; i++) { + references[i] = this.references_[i] * 100; } + System.out.println("I am in the _dense_fit"); + + + this.quantiles_ = computePercentiles(X,references); + /** make it monotonically increasing */ + ensureMonotonic(this.quantiles_); + + } + /** Compute the quantiles used for transforming. */ + public void fit(double [] X){ + /** Fit method --> Compute the quantiles used for transforming. */ + /** X --> The data used to scale along the features axis. + * shaoe (n_samples) */ + + int n_samples = X.length; + // Compute the number of quantiles to use + this.n_quantiles_ = Math.max(1, Math.min(this.n_quantiles, n_samples)); + // Compute the references array + this.references_ = linspace(0, 1, this.n_quantiles_); + System.out.println("I am in the fit"); + + _dense_fit(X); + + } + public double [] _transform_col(double [] X_col, double [] quantiles) throws MathException { + String output_distribution = this.outputDistribution; + double BOUNDS_THRESHOLD = 1e-7; + + double lower_bound_x = quantiles[0]; + double upper_bound_x = quantiles[quantiles.length-1]; + int lower_bound_y = 0; + int upper_bound_y = 1; + + // Create lower and upper bounds indices + boolean[] lowerBoundsIdx = new boolean[X_col.length]; + boolean[] upperBoundsIdx = new boolean[X_col.length]; + if ("normal".equals(output_distribution)) { + for (int i = 0; i < X_col.length; i++) { + lowerBoundsIdx[i] = X_col[i] - BOUNDS_THRESHOLD < lower_bound_x; + upperBoundsIdx[i] = X_col[i] + BOUNDS_THRESHOLD > upper_bound_x; + } + } else if ("uniform".equals(output_distribution)) { + for (int i = 0; i < X_col.length; i++) { + lowerBoundsIdx[i] = X_col[i] == lower_bound_x; + upperBoundsIdx[i] = X_col[i] == upper_bound_x; + } + } + + // Assuming X_col, quantiles, references_ are already defined variables of type double[] + + double[] interpolated1 = interpolate(X_col, quantiles, this.references_); + double[] interpolated2 = interpolate( + Arrays.stream(X_col).map(x -> -x).toArray(), + Arrays.stream(reverseArray(quantiles)).map(x -> -x).toArray(), + Arrays.stream(reverseArray(this.references_)).map(x -> -x).toArray() + ); + + double[] result = new double[X_col.length]; + for (int i = 0; i < X_col.length; i++) { + result[i] = 0.5 * (interpolated1[i] - interpolated2[i]); + } + + /** X_col[upper_bounds_idx] = upper_bound_y + X_col[lower_bounds_idx] = lower_bound_y */ + + for (int i = 0; i < X_col.length; i++) { + if (upperBoundsIdx[i]) { + X_col[i] = upper_bound_y; + } + if (lowerBoundsIdx[i]) { + X_col[i] = lower_bound_y; + } + } + System.out.println("I am in the _transform_col"); +// Assuming X_col, BOUNDS_THRESHOLD are defined variables - // Create a TreeMap and pass the HashMap to its constructor - TreeMap sortedMap = new TreeMap<>(rankMap); + if ("normal".equals(outputDistribution)) { + // Create a normal distribution object + NormalDistribution normalDist = new NormalDistributionImpl(); - // Print out the sorted contents of the HashMap - System.out.println("Contents of rankMap sorted by keys:"); - sortedMap.forEach((key, value) -> System.out.println(key + ": " + value)); + // Perform the inverse transform using the percent point function (ppf) + for (int i = 0; i < X_col.length; i++) { + X_col[i] = normalDist.inverseCumulativeProbability(X_col[i]); + } - // Step 3: Calculating percentiles - double[] percentiles = new double[inputArray.length]; - for (int i = 0; i < inputArray.length; i++) { - double rank = rankMap.get(inputArray[i]); - double percentile = (rank - 1) / (inputArray.length - 1); - System.out.println("rank "+rank+" percentile, " + percentile); - percentiles[i] = percentile; + // Find the values to clip the data to avoid mapping to infinity + double clip_min = normalDist.inverseCumulativeProbability(BOUNDS_THRESHOLD - Double.MIN_VALUE); + double clip_max = normalDist.inverseCumulativeProbability(1 - (BOUNDS_THRESHOLD - Double.MIN_VALUE)); + + // Clip the data such that the inverse transform will be consistent + for (int i = 0; i < X_col.length; i++) { + X_col[i] = Math.max(clip_min, Math.min(clip_max, X_col[i])); + } + } + return X_col; +// For uniform distribution, the ppf is the identity function, so no transformation is needed +// Else output distribution is uniform and we let X_col unchanged + + } + + public double [] _transform(double [] X) throws MathException { + int numRows = X.length; + double [] newX; + + newX=_transform_col(X, this.quantiles_); + System.out.println("I am in the _transform"); + + return newX; + } + + + public static double[] computePercentiles(double[] values, double[] percentiles) { + Arrays.sort(values); + double[] results = new double[percentiles.length]; + for (int i = 0; i < percentiles.length; i++) { + double rank = percentiles[i] / 100 * (values.length - 1); + int lowerIndex = (int) Math.floor(rank); + int upperIndex = (int) Math.ceil(rank); + if (lowerIndex == upperIndex) { + results[i] = values[lowerIndex]; + } else { + double weight = rank - lowerIndex; + results[i] = (1.0 - weight) * values[lowerIndex] + weight * values[upperIndex]; + } + } + return results; + } + + public static void ensureMonotonic(double[] array) { + for (int i = 1; i < array.length; i++) { + if (array[i] < array[i - 1]) { + array[i] = array[i - 1]; + } + } + } + public static double[] reverseArray(double[] array) { + double[] reversed = new double[array.length]; + for (int i = 0; i < array.length; i++) { + reversed[i] = array[array.length - 1 - i]; } + return reversed; + } - // Step 5: Applying transformation - double[] transformedArray = new double[inputArray.length]; - for (int i = 0; i < inputArray.length; i++) { - transformedArray[i] = percentiles[i]; + public static double[] interpolate(double[] x, double[] xp, double[] fp) { + double[] interpolated = new double[x.length]; + for (int i = 0; i < x.length; i++) { + double xi = x[i]; + if (xi < xp[0]) { + interpolated[i] = fp[0]; + } else if (xi > xp[xp.length - 1]) { + interpolated[i] = fp[fp.length - 1]; + } else { + int j = 0; + while (xi > xp[j + 1]) { + j++; + } + double x0 = xp[j]; + double x1 = xp[j + 1]; + double y0 = fp[j]; + double y1 = fp[j + 1]; + interpolated[i] = y0 + (xi - x0) * (y1 - y0) / (x1 - x0); + } } + return interpolated; + } - return transformedArray; + public static double[] linspace(double min, double max, int points) { + double[] d = new double[points]; + for (int i = 0; i < points; i++){ + d[i] = min + i * (max - min) / (points - 1); + } + return d; } - public static void main(String[] args) { +// public static double[] fit_transformer(double X) + + public static void main(String[] args) throws MathException { // Example usage double[] data = {1.8, 2,2.3, 2.4,2.5, 5, 10, 11,12,13.1,14.4,15,16}; + QuantileTransformer1D transformer = new QuantileTransformer1D(10, "uniform"); Arrays.sort(data); - double[] transformedData = QuantileTransformer1D.transform(data); + transformer.fit(data); + double[] transformedData = transformer._transform(data); System.out.println(Arrays.toString(transformedData)); } } From c44eddc95804234fab9a698258b6b4fe2896f725 Mon Sep 17 00:00:00 2001 From: Leo Date: Thu, 30 May 2024 14:00:44 -0600 Subject: [PATCH 05/15] added apache.commons.math3 --- cdm/core/build.gradle | 2 +- cdm/core/src/main/java/ucar/nc2/filter/Normalizer.java | 2 +- cdm/core/src/main/java/ucar/nc2/filter/Standardizer.java | 2 +- netcdf-java-platform/build.gradle | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cdm/core/build.gradle b/cdm/core/build.gradle index f02decb9ff..2ef449b1be 100644 --- a/cdm/core/build.gradle +++ b/cdm/core/build.gradle @@ -8,7 +8,7 @@ apply from: "$rootDir/gradle/any/protobuf.gradle" dependencies { api enforcedPlatform(project(':netcdf-java-platform')) - implementation 'commons-math:commons-math' + implementation 'org.apache.commons:commons-math3' testImplementation enforcedPlatform(project(':netcdf-java-testing-platform')) diff --git a/cdm/core/src/main/java/ucar/nc2/filter/Normalizer.java b/cdm/core/src/main/java/ucar/nc2/filter/Normalizer.java index 688c94090f..fb308b1eef 100644 --- a/cdm/core/src/main/java/ucar/nc2/filter/Normalizer.java +++ b/cdm/core/src/main/java/ucar/nc2/filter/Normalizer.java @@ -4,7 +4,7 @@ import java.util.HashMap; import java.util.Map; -import org.apache.commons.math.stat.descriptive.SummaryStatistics; +import org.apache.commons.math3.stat.descriptive.SummaryStatistics; import ucar.ma2.Array; import ucar.ma2.DataType; import ucar.ma2.IndexIterator; diff --git a/cdm/core/src/main/java/ucar/nc2/filter/Standardizer.java b/cdm/core/src/main/java/ucar/nc2/filter/Standardizer.java index 01613ba8c8..b750eaa10e 100644 --- a/cdm/core/src/main/java/ucar/nc2/filter/Standardizer.java +++ b/cdm/core/src/main/java/ucar/nc2/filter/Standardizer.java @@ -4,7 +4,7 @@ import java.util.HashMap; import java.util.Map; -import org.apache.commons.math.stat.descriptive.SummaryStatistics; +import org.apache.commons.math3.stat.descriptive.SummaryStatistics; import ucar.ma2.Array; import ucar.ma2.DataType; import ucar.ma2.IndexIterator; diff --git a/netcdf-java-platform/build.gradle b/netcdf-java-platform/build.gradle index b1d8b8b439..51a986c523 100644 --- a/netcdf-java-platform/build.gradle +++ b/netcdf-java-platform/build.gradle @@ -37,7 +37,7 @@ dependencies { api 'com.beust:jcommander:1.78' // cdm-core - api 'commons-math:commons-math:1.2' + api 'org.apache.commons:commons-math3:3.6.1' // cdm-grib api 'edu.ucar:jj2000:5.4' From 0a17feb343944900715c3704e057371017f49586 Mon Sep 17 00:00:00 2001 From: Leo Date: Tue, 2 Jul 2024 10:12:57 -0500 Subject: [PATCH 06/15] delete unused files --- .../java/ucar/nc2/filter/MinMaxScale.java | 78 ------ .../nc2/filter/QuantileTransformer1D.java | 234 ------------------ 2 files changed, 312 deletions(-) delete mode 100644 cdm/core/src/main/java/ucar/nc2/filter/MinMaxScale.java delete mode 100644 cdm/core/src/main/java/ucar/nc2/filter/QuantileTransformer1D.java diff --git a/cdm/core/src/main/java/ucar/nc2/filter/MinMaxScale.java b/cdm/core/src/main/java/ucar/nc2/filter/MinMaxScale.java deleted file mode 100644 index d6d6221364..0000000000 --- a/cdm/core/src/main/java/ucar/nc2/filter/MinMaxScale.java +++ /dev/null @@ -1,78 +0,0 @@ -package ucar.nc2.filter; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import org.apache.commons.math.stat.descriptive.SummaryStatistics; -import ucar.ma2.Array; -import ucar.ma2.DataType; -import ucar.ma2.IndexIterator; -import ucar.nc2.dataset.VariableDS; - -public class Standard_Leo implements Enhancement { - private double min; - private double max; - private double newMin; - private double newMax; - - private final ScaleOffset scaleOffset; - private final double mean; - private final double stdDev; -/** VariableDS format is enhanced variable */ - public static Standard_Leo createFromVariable(VariableDS var) { - try { - Array arr = var.read(); - DataType type = var.getDataType(); - return createFromArray(arr, type); - } catch (IOException e) { - return new Standard_Leo(0.0, 1.0, var.getDataType()); - } - } - - public static Standard_Leo createFromArray(Array arr, DataType type) { - SummaryStatistics statistics = calculationHelper(arr); - if (statistics.getStandardDeviation() == 0) { - return new Standard_Leo(0.0, 1.0, type); - } - return new Standard_Leo(statistics.getMean(), statistics.getStandardDeviation(), type); - } - - private Standard_Leo(double mean, double stdDev, DataType type) { - this.mean = mean; - this.stdDev = stdDev; - Map props = new HashMap<>(); - props.put("offset", mean); - props.put("scale", 1 / stdDev); - props.put("dtype", type); - scaleOffset = new ScaleOffset(props); - } - - private static SummaryStatistics calculationHelper(Array arr) { - SummaryStatistics sumStat = new SummaryStatistics(); - IndexIterator iterArr = arr.getIndexIterator(); - while (iterArr.hasNext()) { - Number value = (Number) iterArr.getObjectNext(); - if (!Double.isNaN(value.doubleValue())) { - sumStat.addValue(value.doubleValue()); - } - } - return sumStat; - } - - public Array convert(Array arr) { - return scaleOffset.applyScaleOffset(arr); - } - - public double convert(double val) { - return scaleOffset.applyScaleOffset(val); - } - - public double getMean() { - return mean; - } - - public double getStdDev() { - return stdDev; - } -} - diff --git a/cdm/core/src/main/java/ucar/nc2/filter/QuantileTransformer1D.java b/cdm/core/src/main/java/ucar/nc2/filter/QuantileTransformer1D.java deleted file mode 100644 index a183e62ec4..0000000000 --- a/cdm/core/src/main/java/ucar/nc2/filter/QuantileTransformer1D.java +++ /dev/null @@ -1,234 +0,0 @@ - -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; -import java.util.TreeMap; -import java.util.Scanner; -import org.apache.commons.math.MathException; -import org.apache.commons.math.distribution.NormalDistribution; -import org.apache.commons.math.distribution.NormalDistributionImpl; // Import the concrete class -//import org.apache.commons.math3.analysis.interpolation.LinearInterpolator - - -public class QuantileTransformer1D { - - /** The actual number of quantiles used to discretize the cumulative - distribution function.*/ - private int n_quantiles_; - /** ndarray of shape (n_quantiles, n_features) - The values corresponding the quantiles of reference. - But in my case now it's only 1D, so shape (n_quantiles) */ - private double [] quantiles_; - /**ndarray of shape (n_quantiles, ) - Quantiles of references.*/ - private double [] references_; - /** to be used in constructor */ - private int n_quantiles; - /** to chose wether normal or uniform */ - private String outputDistribution; - // Default values - /** Constructor with all parameters */ - public QuantileTransformer1D(int n_quantiles, String outputDistribution) { - this.n_quantiles = n_quantiles; - this.outputDistribution = outputDistribution; - System.out.println("I am in the constructor"); - - } - - /** Dense matrix fit ? */ - /** should compute percentiles for dense matrix (i.e. not sparse) */ - public void _dense_fit(double [] X) { - // Initialize the references array with the same length as X - double[] references = new double[references_.length]; - /** X --> The data used to scale along the features axis. */ - int n_samples = X.length; - - for (int i = 0; i < this.references_.length; i++) { - references[i] = this.references_[i] * 100; - } - System.out.println("I am in the _dense_fit"); - - - this.quantiles_ = computePercentiles(X,references); - /** make it monotonically increasing */ - ensureMonotonic(this.quantiles_); - - } - /** Compute the quantiles used for transforming. */ - public void fit(double [] X){ - /** Fit method --> Compute the quantiles used for transforming. */ - /** X --> The data used to scale along the features axis. - * shaoe (n_samples) */ - - int n_samples = X.length; - // Compute the number of quantiles to use - this.n_quantiles_ = Math.max(1, Math.min(this.n_quantiles, n_samples)); - // Compute the references array - this.references_ = linspace(0, 1, this.n_quantiles_); - System.out.println("I am in the fit"); - - _dense_fit(X); - - } - public double [] _transform_col(double [] X_col, double [] quantiles) throws MathException { - String output_distribution = this.outputDistribution; - double BOUNDS_THRESHOLD = 1e-7; - - double lower_bound_x = quantiles[0]; - double upper_bound_x = quantiles[quantiles.length-1]; - int lower_bound_y = 0; - int upper_bound_y = 1; - - // Create lower and upper bounds indices - boolean[] lowerBoundsIdx = new boolean[X_col.length]; - boolean[] upperBoundsIdx = new boolean[X_col.length]; - if ("normal".equals(output_distribution)) { - for (int i = 0; i < X_col.length; i++) { - lowerBoundsIdx[i] = X_col[i] - BOUNDS_THRESHOLD < lower_bound_x; - upperBoundsIdx[i] = X_col[i] + BOUNDS_THRESHOLD > upper_bound_x; - } - } else if ("uniform".equals(output_distribution)) { - for (int i = 0; i < X_col.length; i++) { - lowerBoundsIdx[i] = X_col[i] == lower_bound_x; - upperBoundsIdx[i] = X_col[i] == upper_bound_x; - } - } - - // Assuming X_col, quantiles, references_ are already defined variables of type double[] - - double[] interpolated1 = interpolate(X_col, quantiles, this.references_); - double[] interpolated2 = interpolate( - Arrays.stream(X_col).map(x -> -x).toArray(), - Arrays.stream(reverseArray(quantiles)).map(x -> -x).toArray(), - Arrays.stream(reverseArray(this.references_)).map(x -> -x).toArray() - ); - - double[] result = new double[X_col.length]; - for (int i = 0; i < X_col.length; i++) { - result[i] = 0.5 * (interpolated1[i] - interpolated2[i]); - } - - /** X_col[upper_bounds_idx] = upper_bound_y - X_col[lower_bounds_idx] = lower_bound_y */ - - for (int i = 0; i < X_col.length; i++) { - if (upperBoundsIdx[i]) { - X_col[i] = upper_bound_y; - } - if (lowerBoundsIdx[i]) { - X_col[i] = lower_bound_y; - } - } - System.out.println("I am in the _transform_col"); -// Assuming X_col, BOUNDS_THRESHOLD are defined variables - - if ("normal".equals(outputDistribution)) { - // Create a normal distribution object - NormalDistribution normalDist = new NormalDistributionImpl(); - - // Perform the inverse transform using the percent point function (ppf) - for (int i = 0; i < X_col.length; i++) { - X_col[i] = normalDist.inverseCumulativeProbability(X_col[i]); - } - - // Find the values to clip the data to avoid mapping to infinity - double clip_min = normalDist.inverseCumulativeProbability(BOUNDS_THRESHOLD - Double.MIN_VALUE); - double clip_max = normalDist.inverseCumulativeProbability(1 - (BOUNDS_THRESHOLD - Double.MIN_VALUE)); - - // Clip the data such that the inverse transform will be consistent - for (int i = 0; i < X_col.length; i++) { - X_col[i] = Math.max(clip_min, Math.min(clip_max, X_col[i])); - } - } - return X_col; -// For uniform distribution, the ppf is the identity function, so no transformation is needed -// Else output distribution is uniform and we let X_col unchanged - - } - - public double [] _transform(double [] X) throws MathException { - int numRows = X.length; - double [] newX; - - newX=_transform_col(X, this.quantiles_); - System.out.println("I am in the _transform"); - - return newX; - } - - - public static double[] computePercentiles(double[] values, double[] percentiles) { - Arrays.sort(values); - double[] results = new double[percentiles.length]; - for (int i = 0; i < percentiles.length; i++) { - double rank = percentiles[i] / 100 * (values.length - 1); - int lowerIndex = (int) Math.floor(rank); - int upperIndex = (int) Math.ceil(rank); - if (lowerIndex == upperIndex) { - results[i] = values[lowerIndex]; - } else { - double weight = rank - lowerIndex; - results[i] = (1.0 - weight) * values[lowerIndex] + weight * values[upperIndex]; - } - } - return results; - } - - public static void ensureMonotonic(double[] array) { - for (int i = 1; i < array.length; i++) { - if (array[i] < array[i - 1]) { - array[i] = array[i - 1]; - } - } - } - public static double[] reverseArray(double[] array) { - double[] reversed = new double[array.length]; - for (int i = 0; i < array.length; i++) { - reversed[i] = array[array.length - 1 - i]; - } - return reversed; - } - - public static double[] interpolate(double[] x, double[] xp, double[] fp) { - double[] interpolated = new double[x.length]; - for (int i = 0; i < x.length; i++) { - double xi = x[i]; - if (xi < xp[0]) { - interpolated[i] = fp[0]; - } else if (xi > xp[xp.length - 1]) { - interpolated[i] = fp[fp.length - 1]; - } else { - int j = 0; - while (xi > xp[j + 1]) { - j++; - } - double x0 = xp[j]; - double x1 = xp[j + 1]; - double y0 = fp[j]; - double y1 = fp[j + 1]; - interpolated[i] = y0 + (xi - x0) * (y1 - y0) / (x1 - x0); - } - } - return interpolated; - } - - public static double[] linspace(double min, double max, int points) { - double[] d = new double[points]; - for (int i = 0; i < points; i++){ - d[i] = min + i * (max - min) / (points - 1); - } - return d; - } - -// public static double[] fit_transformer(double X) - - public static void main(String[] args) throws MathException { - // Example usage - double[] data = {1.8, 2,2.3, 2.4,2.5, 5, 10, 11,12,13.1,14.4,15,16}; - QuantileTransformer1D transformer = new QuantileTransformer1D(10, "uniform"); - Arrays.sort(data); - transformer.fit(data); - double[] transformedData = transformer._transform(data); - System.out.println(Arrays.toString(transformedData)); - } -} From 773e4423416cb25c97ad1d12eb9b0b9a0f636469 Mon Sep 17 00:00:00 2001 From: Leo Date: Wed, 10 Jul 2024 11:58:36 -0500 Subject: [PATCH 07/15] Reach the class and do something --- .../java/ucar/nc2/dataset/VariableDS.java | 17 +++++++- .../main/java/ucar/nc2/filter/Classifier.java | 35 ++++++++++++++++ .../ucar/nc2/filter/EnhancementProvider.java | 40 +++++++++++++++++++ .../main/java/ucar/nc2/filter/Normalizer.java | 16 +++++++- .../java/ucar/nc2/filter/ScaleOffset.java | 11 ++++- .../java/ucar/nc2/filter/Standardizer.java | 17 ++++++++ .../unidata/io/spi/EnhancementProvider.java | 33 +++++++++++++++ .../ucar.nc2.filter.EnhancementProvider | 4 ++ 8 files changed, 170 insertions(+), 3 deletions(-) create mode 100644 cdm/core/src/main/java/ucar/nc2/filter/EnhancementProvider.java create mode 100644 cdm/core/src/main/java/ucar/unidata/io/spi/EnhancementProvider.java create mode 100644 cdm/core/src/main/resources/META-INF/services/ucar.nc2.filter.EnhancementProvider diff --git a/cdm/core/src/main/java/ucar/nc2/dataset/VariableDS.java b/cdm/core/src/main/java/ucar/nc2/dataset/VariableDS.java index 5581a1faf4..24118d1a36 100644 --- a/cdm/core/src/main/java/ucar/nc2/dataset/VariableDS.java +++ b/cdm/core/src/main/java/ucar/nc2/dataset/VariableDS.java @@ -32,7 +32,9 @@ * @author caron * @see NetcdfDataset */ -public class VariableDS extends Variable implements VariableEnhanced, EnhanceScaleMissingUnsigned { +public class VariableDS extends Variable implements VariableEnhanced, EnhanceScaleMissingUnsigned{ + + /** * Constructor when there's no underlying variable. @@ -269,8 +271,21 @@ Array convert(Array data, Set enhancements) { // datatype of the result depends on what enhancements were applied DataType convertedType = data.getDataType(); + // TODO: change to a provider for extensible Enhancements List toApply = new ArrayList<>(); + + + for (EnhancementProvider service : ServiceLoader.load(EnhancementProvider.class)) { + /** but how do I return an object which is delcared as private here? */ + if (service.canDo(enhancements)){ + System.out.println(service.getName()); +// toApply.add(service.ReturnObject()); + } + + } + + if (enhancements.contains(Enhance.ConvertUnsigned) && unsignedConversion != null) { toApply.add(unsignedConversion); convertedType = unsignedConversion.getOutType(); diff --git a/cdm/core/src/main/java/ucar/nc2/filter/Classifier.java b/cdm/core/src/main/java/ucar/nc2/filter/Classifier.java index ab3cae4ad2..565c9df80e 100644 --- a/cdm/core/src/main/java/ucar/nc2/filter/Classifier.java +++ b/cdm/core/src/main/java/ucar/nc2/filter/Classifier.java @@ -1,20 +1,30 @@ package ucar.nc2.filter; +import java.util.Map; +import java.util.Set; import ucar.ma2.Array; import ucar.ma2.IndexIterator; import ucar.nc2.Variable; import ucar.nc2.constants.CDM; import ucar.nc2.Attribute; +import ucar.nc2.dataset.NetcdfDataset.Enhance; import ucar.nc2.util.Misc; import java.util.ArrayList; import java.util.List; +import ucar.unidata.io.spi.RandomAccessFileProvider; public class Classifier implements Enhancement { + + private String[] AttCat; private List rules = new ArrayList<>(); + private static String name = "Classifier"; + + + public Classifier() { this.AttCat = new String[0]; this.rules = new ArrayList<>(); @@ -116,4 +126,29 @@ public static int[] stringToIntArray(String str) { return intArray; } + + public static class Provider implements EnhancementProvider { + + + @Override + public void doSomething(double val) { + System.out.println("CLASSIFIER ! "+val); + } + + @Override + public String getName() { + return name; + } + @Override + public boolean canDo (Set enhancements){ + if (enhancements.contains(Enhance.ApplyClassifier)) { + return true; + } + return false; + } + + } + + + } diff --git a/cdm/core/src/main/java/ucar/nc2/filter/EnhancementProvider.java b/cdm/core/src/main/java/ucar/nc2/filter/EnhancementProvider.java new file mode 100644 index 0000000000..4fd7b30956 --- /dev/null +++ b/cdm/core/src/main/java/ucar/nc2/filter/EnhancementProvider.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2021 University Corporation for Atmospheric Research/Unidata + * See LICENSE for license information. + */ + +package ucar.nc2.filter; + +import java.util.Map; +//package ucar.nc2.dataset; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Sets; +import ucar.ma2.*; +import ucar.nc2.*; +import ucar.nc2.constants.CDM; +import ucar.nc2.dataset.NetcdfDataset.Enhance; +import ucar.nc2.filter.*; +import ucar.nc2.internal.dataset.CoordinatesHelper; +import ucar.nc2.util.CancelTask; +import ucar.nc2.util.Misc; + +import javax.annotation.Nullable; +import java.io.IOException; +import java.io.OutputStream; +import java.util.*; + +/** + * A Service Provider of {@link Filter}. + */ +public interface EnhancementProvider { + + /** just do something for now? */ + void doSomething(double val); + + String getName(); + + boolean canDo (Set enhancements); +} + + diff --git a/cdm/core/src/main/java/ucar/nc2/filter/Normalizer.java b/cdm/core/src/main/java/ucar/nc2/filter/Normalizer.java index fb308b1eef..2895f758cd 100644 --- a/cdm/core/src/main/java/ucar/nc2/filter/Normalizer.java +++ b/cdm/core/src/main/java/ucar/nc2/filter/Normalizer.java @@ -15,7 +15,7 @@ public class Normalizer implements Enhancement { private final ScaleOffset scaleOffset; private final double minimum; private final double range; // maximum - minimum - + private static String name = "Normalizer"; public static Normalizer createFromVariable(VariableDS var) { try { Array arr = var.read(); @@ -72,4 +72,18 @@ public double getRange() { return range; } +// public static class Provider implements EnhancementProvider { +// +// +// @Override +// public void doSomething(double val) { +// System.out.println("NORMALIZER ! "+val); +// } +// +// @Override +// public String getName() { +// return name; +// } +// } + } diff --git a/cdm/core/src/main/java/ucar/nc2/filter/ScaleOffset.java b/cdm/core/src/main/java/ucar/nc2/filter/ScaleOffset.java index 21dd426e5a..b2cccb98a5 100644 --- a/cdm/core/src/main/java/ucar/nc2/filter/ScaleOffset.java +++ b/cdm/core/src/main/java/ucar/nc2/filter/ScaleOffset.java @@ -274,7 +274,7 @@ private Number convertUnsigned(Number value, Signedness signedness) { } - public static class Provider implements FilterProvider { + public static class Provider implements FilterProvider{ @Override public String getName() { @@ -290,5 +290,14 @@ public int getId() { public Filter create(Map properties) { return new ScaleOffset(properties); } + +// @Override +// public void doSomething(double val) { +// System.out.println("SCALEOFFSET ! "+val); +// } + + } + + } diff --git a/cdm/core/src/main/java/ucar/nc2/filter/Standardizer.java b/cdm/core/src/main/java/ucar/nc2/filter/Standardizer.java index b750eaa10e..054b6f34e3 100644 --- a/cdm/core/src/main/java/ucar/nc2/filter/Standardizer.java +++ b/cdm/core/src/main/java/ucar/nc2/filter/Standardizer.java @@ -15,6 +15,7 @@ public class Standardizer implements Enhancement { private final ScaleOffset scaleOffset; private final double mean; private final double stdDev; + private static String name = "Standardizer"; public static Standardizer createFromVariable(VariableDS var) { try { @@ -71,5 +72,21 @@ public double getMean() { public double getStdDev() { return stdDev; } + + + +// public static class Provider implements EnhancementProvider { +// +// +// @Override +// public void doSomething(double val) { +// System.out.println("STANDARDIZER ! "+val); +// } +// +// @Override +// public String getName() { +// return name; +// } +// } } diff --git a/cdm/core/src/main/java/ucar/unidata/io/spi/EnhancementProvider.java b/cdm/core/src/main/java/ucar/unidata/io/spi/EnhancementProvider.java new file mode 100644 index 0000000000..281c4c6578 --- /dev/null +++ b/cdm/core/src/main/java/ucar/unidata/io/spi/EnhancementProvider.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 1998-2019 University Corporation for Atmospheric Research/Unidata + * See LICENSE for license information. + */ +package ucar.unidata.io.spi; + +import java.io.IOException; +import ucar.unidata.io.RandomAccessFile; + +/** A Service Provider of RandomAccessFile. */ +public interface EnhancementProvider { + + /** Determine if this Provider owns this location. */ + boolean isOwnerOf(String location); + + /** Open a location that this Provider is the owner of. */ + RandomAccessFile open(String location) throws IOException; + + /** Open a location that this Provider is the owner of, with the given buffer size */ + default RandomAccessFile open(String location, int bufferSize) throws IOException { + return this.open(location); // avoid breaking an existing 3rd party implementations + } + + /** Acquire a file for a location from a cache, if available **/ + default RandomAccessFile acquire(String location) throws IOException { + return this.open(location); // avoid breaking an existing 3rd party implementations + } + + /** Acquire a file for a location, with the given buffer size, from a cache, if available **/ + default RandomAccessFile acquire(String location, int bufferSize) throws IOException { + return this.open(location, bufferSize); // avoid breaking an existing 3rd party implementations + } +} diff --git a/cdm/core/src/main/resources/META-INF/services/ucar.nc2.filter.EnhancementProvider b/cdm/core/src/main/resources/META-INF/services/ucar.nc2.filter.EnhancementProvider new file mode 100644 index 0000000000..2d19a61cee --- /dev/null +++ b/cdm/core/src/main/resources/META-INF/services/ucar.nc2.filter.EnhancementProvider @@ -0,0 +1,4 @@ +ucar.nc2.filter.Classifier$Provider +#ucar.nc2.filter.Standardizer$Provider +#ucar.nc2.filter.Normalizer$Provider +#ucar.nc2.filter.ScaleOffset$Provider From ecb551f3a0aecf930e2e6cc0ec3ba76679f5ee79 Mon Sep 17 00:00:00 2001 From: Leo Date: Fri, 12 Jul 2024 13:47:25 -0500 Subject: [PATCH 08/15] Service provider deep in VariableDS --- .../java/ucar/nc2/dataset/VariableDS.java | 12 +++++++ .../main/java/ucar/nc2/filter/Classifier.java | 36 +++++++++++++++++-- .../ucar/nc2/filter/EnhancementProvider.java | 7 ++++ .../ucar.nc2.filter.EnhancementProvider | 2 +- 4 files changed, 53 insertions(+), 4 deletions(-) diff --git a/cdm/core/src/main/java/ucar/nc2/dataset/VariableDS.java b/cdm/core/src/main/java/ucar/nc2/dataset/VariableDS.java index 24118d1a36..0b4e5942be 100644 --- a/cdm/core/src/main/java/ucar/nc2/dataset/VariableDS.java +++ b/cdm/core/src/main/java/ucar/nc2/dataset/VariableDS.java @@ -950,6 +950,18 @@ private void createEnhancements() { } this.dataType = scaleOffset != null ? scaleOffset.getScaledOffsetType() : this.dataType; } +/** how oh how ??? */ + for (Enhance enhance : enhanceMode) { + + for (EnhancementProvider service : ServiceLoader.load(EnhancementProvider.class)) { + if (service.appliesTo(enhance)&& dataType.isFloatingPoint()) { + System.out.println("yay"); + + } + } + } + + Attribute standardizerAtt = findAttribute(CDM.STANDARDIZE); if (standardizerAtt != null && this.enhanceMode.contains(Enhance.ApplyStandardizer) && dataType.isFloatingPoint()) { this.standardizer = Standardizer.createFromVariable(this); diff --git a/cdm/core/src/main/java/ucar/nc2/filter/Classifier.java b/cdm/core/src/main/java/ucar/nc2/filter/Classifier.java index 565c9df80e..eb89bfe383 100644 --- a/cdm/core/src/main/java/ucar/nc2/filter/Classifier.java +++ b/cdm/core/src/main/java/ucar/nc2/filter/Classifier.java @@ -15,7 +15,23 @@ import ucar.unidata.io.spi.RandomAccessFileProvider; -public class Classifier implements Enhancement { + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Sets; +import ucar.ma2.*; +import ucar.nc2.*; +import ucar.nc2.constants.CDM; +import ucar.nc2.dataset.NetcdfDataset.Enhance; +import ucar.nc2.filter.*; +import ucar.nc2.internal.dataset.CoordinatesHelper; +import ucar.nc2.util.CancelTask; +import ucar.nc2.util.Misc; + +import javax.annotation.Nullable; +import java.io.IOException; +import java.io.OutputStream; +import java.util.*; +public class Classifier implements Enhancement,EnhancementProvider { private String[] AttCat; @@ -37,6 +53,7 @@ public Classifier(String[] AttCat) { } // Factory method to create a Classifier from a Variable + public static Classifier createFromVariable(Variable var) { List attributes = var.attributes().getAttributes(); @@ -127,7 +144,7 @@ public static int[] stringToIntArray(String str) { } - public static class Provider implements EnhancementProvider { + @Override @@ -147,8 +164,21 @@ public boolean canDo (Set enhancements){ return false; } +// Attribute findAttribute(String attName); + + @Override + public boolean appliesTo(Enhance enhance) { + return enhance == Enhance.ApplyClassifier; + } +// @Override +// public void applyEnhancement(Object instance) { +// Attribute classifierAtt = findAttribute(CDM.CLASSIFY); +// if (classifierAtt != null && instance.enhanceMode.contains(Enhance.ApplyClassifier) && instance.dataType.isNumeric()) { +// instance.classifier = Classifier.createFromVariable(instance); +// } + } -} + diff --git a/cdm/core/src/main/java/ucar/nc2/filter/EnhancementProvider.java b/cdm/core/src/main/java/ucar/nc2/filter/EnhancementProvider.java index 4fd7b30956..18d78cc61c 100644 --- a/cdm/core/src/main/java/ucar/nc2/filter/EnhancementProvider.java +++ b/cdm/core/src/main/java/ucar/nc2/filter/EnhancementProvider.java @@ -32,9 +32,16 @@ public interface EnhancementProvider { /** just do something for now? */ void doSomething(double val); + String getName(); boolean canDo (Set enhancements); + + boolean appliesTo(Enhance enhance); + + +// void applyEnhancement(Object instance); + } diff --git a/cdm/core/src/main/resources/META-INF/services/ucar.nc2.filter.EnhancementProvider b/cdm/core/src/main/resources/META-INF/services/ucar.nc2.filter.EnhancementProvider index 2d19a61cee..d8b9621173 100644 --- a/cdm/core/src/main/resources/META-INF/services/ucar.nc2.filter.EnhancementProvider +++ b/cdm/core/src/main/resources/META-INF/services/ucar.nc2.filter.EnhancementProvider @@ -1,4 +1,4 @@ -ucar.nc2.filter.Classifier$Provider +ucar.nc2.filter.Classifier #ucar.nc2.filter.Standardizer$Provider #ucar.nc2.filter.Normalizer$Provider #ucar.nc2.filter.ScaleOffset$Provider From 17176757bdf550407d643dd73ff1f37fd3df8081 Mon Sep 17 00:00:00 2001 From: Leo Date: Mon, 15 Jul 2024 14:39:13 -0500 Subject: [PATCH 09/15] ok some things work here --- .../java/ucar/nc2/dataset/VariableDS.java | 35 +++------------ .../main/java/ucar/nc2/filter/Classifier.java | 26 ++++++----- .../ucar/nc2/filter/EnhancementProvider.java | 9 ++-- .../main/java/ucar/nc2/filter/Normalizer.java | 44 +++++++++++++------ .../java/ucar/nc2/filter/Standardizer.java | 43 ++++++++++++------ .../ucar.nc2.filter.EnhancementProvider | 10 +++-- .../ucar/nc2/ncml/TestEnhanceClassifier.java | 7 +-- 7 files changed, 97 insertions(+), 77 deletions(-) diff --git a/cdm/core/src/main/java/ucar/nc2/dataset/VariableDS.java b/cdm/core/src/main/java/ucar/nc2/dataset/VariableDS.java index 0b4e5942be..8927a61e6f 100644 --- a/cdm/core/src/main/java/ucar/nc2/dataset/VariableDS.java +++ b/cdm/core/src/main/java/ucar/nc2/dataset/VariableDS.java @@ -276,14 +276,7 @@ Array convert(Array data, Set enhancements) { List toApply = new ArrayList<>(); - for (EnhancementProvider service : ServiceLoader.load(EnhancementProvider.class)) { - /** but how do I return an object which is delcared as private here? */ - if (service.canDo(enhancements)){ - System.out.println(service.getName()); -// toApply.add(service.ReturnObject()); - } - } if (enhancements.contains(Enhance.ConvertUnsigned) && unsignedConversion != null) { @@ -881,9 +874,9 @@ public Array convert(Array in, boolean convertUnsigned, boolean applyScaleOffset // TODO make immutable in version 6 private UnsignedConversion unsignedConversion; private ScaleOffset scaleOffset; - private Standardizer standardizer; - private Normalizer normalizer; - private Classifier classifier; + public Standardizer standardizer; + public Normalizer normalizer; + public Classifier classifier; private ConvertMissing convertMissing; private Set enhanceMode = EnumSet.noneOf(Enhance.class); // The set of enhancements that were made. @@ -951,29 +944,15 @@ private void createEnhancements() { this.dataType = scaleOffset != null ? scaleOffset.getScaledOffsetType() : this.dataType; } /** how oh how ??? */ - for (Enhance enhance : enhanceMode) { - + for (Enhance enhance : this.enhanceMode) { for (EnhancementProvider service : ServiceLoader.load(EnhancementProvider.class)) { - if (service.appliesTo(enhance)&& dataType.isFloatingPoint()) { - System.out.println("yay"); - + /** Stand and Norm require floatingpoint, buc classifier can do just numeric? */ + if (service.appliesTo(enhance,this.attributes())&& dataType.isFloatingPoint()) { + service.Create(this); } } } - - Attribute standardizerAtt = findAttribute(CDM.STANDARDIZE); - if (standardizerAtt != null && this.enhanceMode.contains(Enhance.ApplyStandardizer) && dataType.isFloatingPoint()) { - this.standardizer = Standardizer.createFromVariable(this); - } - Attribute normalizerAtt = findAttribute(CDM.NORMALIZE); - if (normalizerAtt != null && this.enhanceMode.contains(Enhance.ApplyNormalizer) && dataType.isFloatingPoint()) { - this.normalizer = Normalizer.createFromVariable(this); - } - Attribute classifierAtt = findAttribute(CDM.CLASSIFY); - if (classifierAtt != null && this.enhanceMode.contains(Enhance.ApplyClassifier) && dataType.isNumeric()) { - this.classifier = Classifier.createFromVariable(this); - } } public Builder toBuilder() { diff --git a/cdm/core/src/main/java/ucar/nc2/filter/Classifier.java b/cdm/core/src/main/java/ucar/nc2/filter/Classifier.java index eb89bfe383..35c3be0c78 100644 --- a/cdm/core/src/main/java/ucar/nc2/filter/Classifier.java +++ b/cdm/core/src/main/java/ucar/nc2/filter/Classifier.java @@ -9,6 +9,7 @@ import ucar.nc2.constants.CDM; import ucar.nc2.Attribute; import ucar.nc2.dataset.NetcdfDataset.Enhance; +import ucar.nc2.dataset.VariableDS; import ucar.nc2.util.Misc; import java.util.ArrayList; import java.util.List; @@ -31,7 +32,7 @@ import java.io.IOException; import java.io.OutputStream; import java.util.*; -public class Classifier implements Enhancement,EnhancementProvider { +public class Classifier implements Enhancement { private String[] AttCat; @@ -54,7 +55,7 @@ public Classifier(String[] AttCat) { // Factory method to create a Classifier from a Variable - public static Classifier createFromVariable(Variable var) { + public static Classifier createFromVariable(VariableDS var) { List attributes = var.attributes().getAttributes(); for (Attribute attribute : attributes) { @@ -143,15 +144,15 @@ public static int[] stringToIntArray(String str) { return intArray; } - - - + public static class Provider implements EnhancementProvider { @Override - public void doSomething(double val) { - System.out.println("CLASSIFIER ! "+val); + public void Create(VariableDS var){ + var.classifier=Classifier.createFromVariable(var); } + + @Override public String getName() { return name; @@ -162,13 +163,13 @@ public boolean canDo (Set enhancements){ return true; } return false; - } + } // Attribute findAttribute(String attName); @Override - public boolean appliesTo(Enhance enhance) { - return enhance == Enhance.ApplyClassifier; + public boolean appliesTo(Enhance enhance, AttributeContainer attributes) { + return enhance == Enhance.ApplyClassifier && attributes.findAttribute(CDM.CLASSIFY)!= null; } // @Override // public void applyEnhancement(Object instance) { @@ -182,3 +183,8 @@ public boolean appliesTo(Enhance enhance) { + } + + + + diff --git a/cdm/core/src/main/java/ucar/nc2/filter/EnhancementProvider.java b/cdm/core/src/main/java/ucar/nc2/filter/EnhancementProvider.java index 18d78cc61c..8d67dd1899 100644 --- a/cdm/core/src/main/java/ucar/nc2/filter/EnhancementProvider.java +++ b/cdm/core/src/main/java/ucar/nc2/filter/EnhancementProvider.java @@ -14,6 +14,7 @@ import ucar.nc2.*; import ucar.nc2.constants.CDM; import ucar.nc2.dataset.NetcdfDataset.Enhance; +import ucar.nc2.dataset.VariableDS; import ucar.nc2.filter.*; import ucar.nc2.internal.dataset.CoordinatesHelper; import ucar.nc2.util.CancelTask; @@ -29,15 +30,13 @@ */ public interface EnhancementProvider { - /** just do something for now? */ - void doSomething(double val); - - String getName(); boolean canDo (Set enhancements); - boolean appliesTo(Enhance enhance); + boolean appliesTo(Enhance enhance, AttributeContainer attributes); + + void Create(VariableDS var); // void applyEnhancement(Object instance); diff --git a/cdm/core/src/main/java/ucar/nc2/filter/Normalizer.java b/cdm/core/src/main/java/ucar/nc2/filter/Normalizer.java index 2895f758cd..bcf86a80fa 100644 --- a/cdm/core/src/main/java/ucar/nc2/filter/Normalizer.java +++ b/cdm/core/src/main/java/ucar/nc2/filter/Normalizer.java @@ -3,11 +3,15 @@ import java.io.IOException; import java.util.HashMap; import java.util.Map; - +import ucar.nc2.constants.CDM; +import java.util.Set; import org.apache.commons.math3.stat.descriptive.SummaryStatistics; import ucar.ma2.Array; import ucar.ma2.DataType; import ucar.ma2.IndexIterator; +import ucar.nc2.AttributeContainer; +import ucar.nc2.Variable; +import ucar.nc2.dataset.NetcdfDataset.Enhance; import ucar.nc2.dataset.VariableDS; public class Normalizer implements Enhancement { @@ -71,19 +75,31 @@ public double getMinimum() { public double getRange() { return range; } + public static class Provider implements EnhancementProvider { + + @Override + public void Create(VariableDS var){ + var.normalizer=Normalizer.createFromVariable(var); -// public static class Provider implements EnhancementProvider { -// -// -// @Override -// public void doSomething(double val) { -// System.out.println("NORMALIZER ! "+val); -// } -// -// @Override -// public String getName() { -// return name; -// } -// } + } + @Override + public String getName() { + return name; + } + @Override + public boolean canDo (Set enhancements){ + if (enhancements.contains(Enhance.ApplyNormalizer)) { + return true; + } + return false; + } + + @Override + public boolean appliesTo(Enhance enhance, AttributeContainer attributes) { + return enhance == Enhance.ApplyNormalizer && attributes.findAttribute(CDM.NORMALIZE)!= null; + } + + + } } diff --git a/cdm/core/src/main/java/ucar/nc2/filter/Standardizer.java b/cdm/core/src/main/java/ucar/nc2/filter/Standardizer.java index 054b6f34e3..2116c413be 100644 --- a/cdm/core/src/main/java/ucar/nc2/filter/Standardizer.java +++ b/cdm/core/src/main/java/ucar/nc2/filter/Standardizer.java @@ -3,11 +3,15 @@ import java.io.IOException; import java.util.HashMap; import java.util.Map; +import ucar.nc2.constants.CDM; +import java.util.Set; import org.apache.commons.math3.stat.descriptive.SummaryStatistics; import ucar.ma2.Array; import ucar.ma2.DataType; import ucar.ma2.IndexIterator; +import ucar.nc2.AttributeContainer; +import ucar.nc2.dataset.NetcdfDataset.Enhance; import ucar.nc2.dataset.VariableDS; public class Standardizer implements Enhancement { @@ -75,18 +79,31 @@ public double getStdDev() { -// public static class Provider implements EnhancementProvider { -// -// -// @Override -// public void doSomething(double val) { -// System.out.println("STANDARDIZER ! "+val); -// } -// -// @Override -// public String getName() { -// return name; -// } -// } + public static class Provider implements EnhancementProvider { + + @Override + public void Create(VariableDS var){ + var.standardizer=Standardizer.createFromVariable(var); + + } + @Override + public String getName() { + return name; + } + @Override + public boolean canDo (Set enhancements){ + if (enhancements.contains(Enhance.ApplyStandardizer)) { + return true; + } + return false; + } + + @Override + public boolean appliesTo(Enhance enhance, AttributeContainer attributes) { + return enhance == Enhance.ApplyStandardizer && attributes.findAttribute(CDM.STANDARDIZE)!= null; + } + + + } } diff --git a/cdm/core/src/main/resources/META-INF/services/ucar.nc2.filter.EnhancementProvider b/cdm/core/src/main/resources/META-INF/services/ucar.nc2.filter.EnhancementProvider index d8b9621173..4fc1725949 100644 --- a/cdm/core/src/main/resources/META-INF/services/ucar.nc2.filter.EnhancementProvider +++ b/cdm/core/src/main/resources/META-INF/services/ucar.nc2.filter.EnhancementProvider @@ -1,4 +1,6 @@ -ucar.nc2.filter.Classifier -#ucar.nc2.filter.Standardizer$Provider -#ucar.nc2.filter.Normalizer$Provider -#ucar.nc2.filter.ScaleOffset$Provider +ucar.nc2.filter.Classifier$Provider +ucar.nc2.filter.Standardizer$Provider +ucar.nc2.filter.Normalizer$Provider + + + diff --git a/cdm/core/src/test/java/ucar/nc2/ncml/TestEnhanceClassifier.java b/cdm/core/src/test/java/ucar/nc2/ncml/TestEnhanceClassifier.java index a61d43d2c8..089a5de2f3 100644 --- a/cdm/core/src/test/java/ucar/nc2/ncml/TestEnhanceClassifier.java +++ b/cdm/core/src/test/java/ucar/nc2/ncml/TestEnhanceClassifier.java @@ -12,6 +12,7 @@ import ucar.nc2.NetcdfFile; import ucar.nc2.Variable; import ucar.nc2.dataset.NetcdfDatasets; +import ucar.nc2.dataset.VariableDS; import ucar.nc2.filter.Classifier; import ucar.unidata.util.test.TestDir; @@ -33,7 +34,7 @@ public void testEnhanceClassifier_Ints() throws IOException { assertThat((Object) classifySpecs).isNotNull(); assertThat(!classifySpecs.attributes().isEmpty()).isTrue(); Array Data = classifySpecs.read(); - Classifier classifier = Classifier.createFromVariable(classifySpecs); + Classifier classifier = Classifier.createFromVariable((VariableDS) classifySpecs); int[] ClassifiedArray = classifier.classifyWithAttributes(Data); assertThat(nearlyEquals(Array.makeFromJavaArray(ClassifiedArray), DATA_mixNumbers)).isTrue(); @@ -53,7 +54,7 @@ public void testEnhanceClassifier_Floats() throws IOException { assertThat((Object) classifySpecs).isNotNull(); assertThat(!classifySpecs.attributes().isEmpty()).isTrue(); Array Data = classifySpecs.read(); - Classifier classifier = Classifier.createFromVariable(classifySpecs); + Classifier classifier = Classifier.createFromVariable((VariableDS) classifySpecs); int[] ClassifiedArray = classifier.classifyWithAttributes(Data); assertThat(nearlyEquals(Array.makeFromJavaArray(ClassifiedArray), DATA_mixNumbers)).isTrue(); @@ -73,7 +74,7 @@ public void testEnhanceClassifier_classification() throws IOException { assertThat((Object) classifySpecs).isNotNull(); assertThat(!classifySpecs.attributes().isEmpty()).isTrue(); Array Data = classifySpecs.read(); - Classifier classifier = Classifier.createFromVariable(classifySpecs); + Classifier classifier = Classifier.createFromVariable((VariableDS) classifySpecs); int[] ClassifiedArray = classifier.classifyWithAttributes(Data); assertThat(nearlyEquals(Array.makeFromJavaArray(ClassifiedArray), CLASSIFICATION_TEST)).isTrue(); From 5324639dde7ac485e757b03a418b1f8b10076ea4 Mon Sep 17 00:00:00 2001 From: Leo Date: Mon, 15 Jul 2024 15:46:00 -0500 Subject: [PATCH 10/15] looks like all works?? --- .../java/ucar/nc2/dataset/VariableDS.java | 20 ++++++++----------- .../main/java/ucar/nc2/filter/Classifier.java | 16 +++++++++------ .../ucar/nc2/filter/EnhancementProvider.java | 3 +++ .../main/java/ucar/nc2/filter/Normalizer.java | 10 ++++++++++ .../java/ucar/nc2/filter/Standardizer.java | 9 ++++++++- 5 files changed, 39 insertions(+), 19 deletions(-) diff --git a/cdm/core/src/main/java/ucar/nc2/dataset/VariableDS.java b/cdm/core/src/main/java/ucar/nc2/dataset/VariableDS.java index 8927a61e6f..fce6664d0d 100644 --- a/cdm/core/src/main/java/ucar/nc2/dataset/VariableDS.java +++ b/cdm/core/src/main/java/ucar/nc2/dataset/VariableDS.java @@ -275,10 +275,6 @@ Array convert(Array data, Set enhancements) { // TODO: change to a provider for extensible Enhancements List toApply = new ArrayList<>(); - - - - if (enhancements.contains(Enhance.ConvertUnsigned) && unsignedConversion != null) { toApply.add(unsignedConversion); convertedType = unsignedConversion.getOutType(); @@ -291,16 +287,16 @@ Array convert(Array data, Set enhancements) { toApply.add(scaleOffset); convertedType = scaleOffset.getScaledOffsetType(); } - if (enhancements.contains(Enhance.ApplyStandardizer) && standardizer != null) { - toApply.add(standardizer); - } - if (enhancements.contains(Enhance.ApplyNormalizer) && normalizer != null) { - toApply.add(normalizer); - } - if (enhancements.contains(Enhance.ApplyClassifier) && classifier != null) { - toApply.add(classifier); +/** this == variableDS */ + for (Enhance enhance : enhancements) { + for (EnhancementProvider service : ServiceLoader.load(EnhancementProvider.class)) { + if (service.appliesTo(enhance, this)) { + toApply.add(service.returnObject(this)); + } + } } + double[] dataArray = (double[]) data.get1DJavaArray(DataType.DOUBLE); dataArray = Arrays.stream(dataArray).parallel().map((num) -> { diff --git a/cdm/core/src/main/java/ucar/nc2/filter/Classifier.java b/cdm/core/src/main/java/ucar/nc2/filter/Classifier.java index 35c3be0c78..76807e4768 100644 --- a/cdm/core/src/main/java/ucar/nc2/filter/Classifier.java +++ b/cdm/core/src/main/java/ucar/nc2/filter/Classifier.java @@ -171,12 +171,16 @@ public boolean canDo (Set enhancements){ public boolean appliesTo(Enhance enhance, AttributeContainer attributes) { return enhance == Enhance.ApplyClassifier && attributes.findAttribute(CDM.CLASSIFY)!= null; } -// @Override -// public void applyEnhancement(Object instance) { -// Attribute classifierAtt = findAttribute(CDM.CLASSIFY); -// if (classifierAtt != null && instance.enhanceMode.contains(Enhance.ApplyClassifier) && instance.dataType.isNumeric()) { -// instance.classifier = Classifier.createFromVariable(instance); -// } + @Override + public boolean appliesTo(Enhance enhance,VariableDS var){ + return enhance == Enhance.ApplyClassifier && var.classifier!=null; + } + + public Classifier returnObject( VariableDS var){ + return var.classifier; + } + + } diff --git a/cdm/core/src/main/java/ucar/nc2/filter/EnhancementProvider.java b/cdm/core/src/main/java/ucar/nc2/filter/EnhancementProvider.java index 8d67dd1899..75cf074401 100644 --- a/cdm/core/src/main/java/ucar/nc2/filter/EnhancementProvider.java +++ b/cdm/core/src/main/java/ucar/nc2/filter/EnhancementProvider.java @@ -36,7 +36,10 @@ public interface EnhancementProvider { boolean appliesTo(Enhance enhance, AttributeContainer attributes); + boolean appliesTo(Enhance enhance, VariableDS var); + void Create(VariableDS var); + Enhancement returnObject(VariableDS var); // void applyEnhancement(Object instance); diff --git a/cdm/core/src/main/java/ucar/nc2/filter/Normalizer.java b/cdm/core/src/main/java/ucar/nc2/filter/Normalizer.java index bcf86a80fa..401e7f86e7 100644 --- a/cdm/core/src/main/java/ucar/nc2/filter/Normalizer.java +++ b/cdm/core/src/main/java/ucar/nc2/filter/Normalizer.java @@ -98,6 +98,16 @@ public boolean canDo (Set enhancements){ public boolean appliesTo(Enhance enhance, AttributeContainer attributes) { return enhance == Enhance.ApplyNormalizer && attributes.findAttribute(CDM.NORMALIZE)!= null; } + @Override + public boolean appliesTo(Enhance enhance,VariableDS var){ + return enhance == Enhance.ApplyNormalizer && var.normalizer!= null; + } +@Override + public Normalizer returnObject( VariableDS var){ + return var.normalizer; + } + + } diff --git a/cdm/core/src/main/java/ucar/nc2/filter/Standardizer.java b/cdm/core/src/main/java/ucar/nc2/filter/Standardizer.java index 2116c413be..b01cda7181 100644 --- a/cdm/core/src/main/java/ucar/nc2/filter/Standardizer.java +++ b/cdm/core/src/main/java/ucar/nc2/filter/Standardizer.java @@ -102,8 +102,15 @@ public boolean canDo (Set enhancements){ public boolean appliesTo(Enhance enhance, AttributeContainer attributes) { return enhance == Enhance.ApplyStandardizer && attributes.findAttribute(CDM.STANDARDIZE)!= null; } + @Override + public boolean appliesTo(Enhance enhance,VariableDS var){ + return enhance == Enhance.ApplyStandardizer && var.standardizer!= null; + } - + @Override + public Standardizer returnObject( VariableDS var){ + return var.standardizer; + } } } From bfbc4ffd587943d2dd810700c031a690196eec2b Mon Sep 17 00:00:00 2001 From: Leo Date: Tue, 16 Jul 2024 11:57:37 -0500 Subject: [PATCH 11/15] style application --- .../java/ucar/nc2/dataset/VariableDS.java | 10 +++---- .../main/java/ucar/nc2/filter/Classifier.java | 26 +++++++++---------- .../ucar/nc2/filter/EnhancementProvider.java | 17 ++++++------ .../main/java/ucar/nc2/filter/Normalizer.java | 23 +++++++++------- .../java/ucar/nc2/filter/ScaleOffset.java | 10 +++---- .../java/ucar/nc2/filter/Standardizer.java | 17 +++++++----- 6 files changed, 56 insertions(+), 47 deletions(-) diff --git a/cdm/core/src/main/java/ucar/nc2/dataset/VariableDS.java b/cdm/core/src/main/java/ucar/nc2/dataset/VariableDS.java index fce6664d0d..0091766593 100644 --- a/cdm/core/src/main/java/ucar/nc2/dataset/VariableDS.java +++ b/cdm/core/src/main/java/ucar/nc2/dataset/VariableDS.java @@ -32,7 +32,7 @@ * @author caron * @see NetcdfDataset */ -public class VariableDS extends Variable implements VariableEnhanced, EnhanceScaleMissingUnsigned{ +public class VariableDS extends Variable implements VariableEnhanced, EnhanceScaleMissingUnsigned { @@ -287,7 +287,7 @@ Array convert(Array data, Set enhancements) { toApply.add(scaleOffset); convertedType = scaleOffset.getScaledOffsetType(); } -/** this == variableDS */ + /** this == variableDS */ for (Enhance enhance : enhancements) { for (EnhancementProvider service : ServiceLoader.load(EnhancementProvider.class)) { if (service.appliesTo(enhance, this)) { @@ -939,15 +939,15 @@ private void createEnhancements() { } this.dataType = scaleOffset != null ? scaleOffset.getScaledOffsetType() : this.dataType; } -/** how oh how ??? */ + /** how oh how ??? */ for (Enhance enhance : this.enhanceMode) { for (EnhancementProvider service : ServiceLoader.load(EnhancementProvider.class)) { /** Stand and Norm require floatingpoint, buc classifier can do just numeric? */ - if (service.appliesTo(enhance,this.attributes())&& dataType.isFloatingPoint()) { + if (service.appliesTo(enhance, this.attributes()) && dataType.isFloatingPoint()) { service.Create(this); } - } } + } } diff --git a/cdm/core/src/main/java/ucar/nc2/filter/Classifier.java b/cdm/core/src/main/java/ucar/nc2/filter/Classifier.java index 76807e4768..0ad3a1ff81 100644 --- a/cdm/core/src/main/java/ucar/nc2/filter/Classifier.java +++ b/cdm/core/src/main/java/ucar/nc2/filter/Classifier.java @@ -32,6 +32,7 @@ import java.io.IOException; import java.io.OutputStream; import java.util.*; + public class Classifier implements Enhancement { @@ -147,8 +148,8 @@ public static int[] stringToIntArray(String str) { public static class Provider implements EnhancementProvider { @Override - public void Create(VariableDS var){ - var.classifier=Classifier.createFromVariable(var); + public void Create(VariableDS var) { + var.classifier = Classifier.createFromVariable(var); } @@ -157,26 +158,28 @@ public void Create(VariableDS var){ public String getName() { return name; } + @Override - public boolean canDo (Set enhancements){ + public boolean canDo(Set enhancements) { if (enhancements.contains(Enhance.ApplyClassifier)) { return true; } return false; } -// Attribute findAttribute(String attName); + // Attribute findAttribute(String attName); @Override - public boolean appliesTo(Enhance enhance, AttributeContainer attributes) { - return enhance == Enhance.ApplyClassifier && attributes.findAttribute(CDM.CLASSIFY)!= null; + public boolean appliesTo(Enhance enhance, AttributeContainer attributes) { + return enhance == Enhance.ApplyClassifier && attributes.findAttribute(CDM.CLASSIFY) != null; } + @Override - public boolean appliesTo(Enhance enhance,VariableDS var){ - return enhance == Enhance.ApplyClassifier && var.classifier!=null; + public boolean appliesTo(Enhance enhance, VariableDS var) { + return enhance == Enhance.ApplyClassifier && var.classifier != null; } - public Classifier returnObject( VariableDS var){ + public Classifier returnObject(VariableDS var) { return var.classifier; } @@ -186,9 +189,6 @@ public Classifier returnObject( VariableDS var){ - - } - - +} diff --git a/cdm/core/src/main/java/ucar/nc2/filter/EnhancementProvider.java b/cdm/core/src/main/java/ucar/nc2/filter/EnhancementProvider.java index 75cf074401..b2718d9c33 100644 --- a/cdm/core/src/main/java/ucar/nc2/filter/EnhancementProvider.java +++ b/cdm/core/src/main/java/ucar/nc2/filter/EnhancementProvider.java @@ -6,7 +6,7 @@ package ucar.nc2.filter; import java.util.Map; -//package ucar.nc2.dataset; +// package ucar.nc2.dataset; import com.google.common.collect.ImmutableList; import com.google.common.collect.Sets; @@ -30,19 +30,20 @@ */ public interface EnhancementProvider { - String getName(); + String getName(); - boolean canDo (Set enhancements); + boolean canDo(Set enhancements); - boolean appliesTo(Enhance enhance, AttributeContainer attributes); + boolean appliesTo(Enhance enhance, AttributeContainer attributes); - boolean appliesTo(Enhance enhance, VariableDS var); + boolean appliesTo(Enhance enhance, VariableDS var); - void Create(VariableDS var); - Enhancement returnObject(VariableDS var); + void Create(VariableDS var); + Enhancement returnObject(VariableDS var); -// void applyEnhancement(Object instance); + + // void applyEnhancement(Object instance); } diff --git a/cdm/core/src/main/java/ucar/nc2/filter/Normalizer.java b/cdm/core/src/main/java/ucar/nc2/filter/Normalizer.java index 401e7f86e7..11a82e4974 100644 --- a/cdm/core/src/main/java/ucar/nc2/filter/Normalizer.java +++ b/cdm/core/src/main/java/ucar/nc2/filter/Normalizer.java @@ -20,6 +20,7 @@ public class Normalizer implements Enhancement { private final double minimum; private final double range; // maximum - minimum private static String name = "Normalizer"; + public static Normalizer createFromVariable(VariableDS var) { try { Array arr = var.read(); @@ -75,19 +76,22 @@ public double getMinimum() { public double getRange() { return range; } + public static class Provider implements EnhancementProvider { @Override - public void Create(VariableDS var){ - var.normalizer=Normalizer.createFromVariable(var); + public void Create(VariableDS var) { + var.normalizer = Normalizer.createFromVariable(var); } + @Override public String getName() { return name; } + @Override - public boolean canDo (Set enhancements){ + public boolean canDo(Set enhancements) { if (enhancements.contains(Enhance.ApplyNormalizer)) { return true; } @@ -96,20 +100,21 @@ public boolean canDo (Set enhancements){ @Override public boolean appliesTo(Enhance enhance, AttributeContainer attributes) { - return enhance == Enhance.ApplyNormalizer && attributes.findAttribute(CDM.NORMALIZE)!= null; + return enhance == Enhance.ApplyNormalizer && attributes.findAttribute(CDM.NORMALIZE) != null; } + @Override - public boolean appliesTo(Enhance enhance,VariableDS var){ - return enhance == Enhance.ApplyNormalizer && var.normalizer!= null; + public boolean appliesTo(Enhance enhance, VariableDS var) { + return enhance == Enhance.ApplyNormalizer && var.normalizer != null; } -@Override - public Normalizer returnObject( VariableDS var){ + + @Override + public Normalizer returnObject(VariableDS var) { return var.normalizer; } - } } diff --git a/cdm/core/src/main/java/ucar/nc2/filter/ScaleOffset.java b/cdm/core/src/main/java/ucar/nc2/filter/ScaleOffset.java index b2cccb98a5..a4a7cb1edd 100644 --- a/cdm/core/src/main/java/ucar/nc2/filter/ScaleOffset.java +++ b/cdm/core/src/main/java/ucar/nc2/filter/ScaleOffset.java @@ -274,7 +274,7 @@ private Number convertUnsigned(Number value, Signedness signedness) { } - public static class Provider implements FilterProvider{ + public static class Provider implements FilterProvider { @Override public String getName() { @@ -291,10 +291,10 @@ public Filter create(Map properties) { return new ScaleOffset(properties); } -// @Override -// public void doSomething(double val) { -// System.out.println("SCALEOFFSET ! "+val); -// } + // @Override + // public void doSomething(double val) { + // System.out.println("SCALEOFFSET ! "+val); + // } } diff --git a/cdm/core/src/main/java/ucar/nc2/filter/Standardizer.java b/cdm/core/src/main/java/ucar/nc2/filter/Standardizer.java index b01cda7181..a0a5f6c4da 100644 --- a/cdm/core/src/main/java/ucar/nc2/filter/Standardizer.java +++ b/cdm/core/src/main/java/ucar/nc2/filter/Standardizer.java @@ -82,16 +82,18 @@ public double getStdDev() { public static class Provider implements EnhancementProvider { @Override - public void Create(VariableDS var){ - var.standardizer=Standardizer.createFromVariable(var); + public void Create(VariableDS var) { + var.standardizer = Standardizer.createFromVariable(var); } + @Override public String getName() { return name; } + @Override - public boolean canDo (Set enhancements){ + public boolean canDo(Set enhancements) { if (enhancements.contains(Enhance.ApplyStandardizer)) { return true; } @@ -100,15 +102,16 @@ public boolean canDo (Set enhancements){ @Override public boolean appliesTo(Enhance enhance, AttributeContainer attributes) { - return enhance == Enhance.ApplyStandardizer && attributes.findAttribute(CDM.STANDARDIZE)!= null; + return enhance == Enhance.ApplyStandardizer && attributes.findAttribute(CDM.STANDARDIZE) != null; } + @Override - public boolean appliesTo(Enhance enhance,VariableDS var){ - return enhance == Enhance.ApplyStandardizer && var.standardizer!= null; + public boolean appliesTo(Enhance enhance, VariableDS var) { + return enhance == Enhance.ApplyStandardizer && var.standardizer != null; } @Override - public Standardizer returnObject( VariableDS var){ + public Standardizer returnObject(VariableDS var) { return var.standardizer; } } From 74f6a03806a67e8455aaedd0a4e9d40f5d315d48 Mon Sep 17 00:00:00 2001 From: Leo Date: Wed, 17 Jul 2024 12:33:31 -0500 Subject: [PATCH 12/15] Make it shorter and nicer --- .../java/ucar/nc2/dataset/VariableDS.java | 19 ++++------- .../main/java/ucar/nc2/filter/Classifier.java | 32 ++----------------- .../ucar/nc2/filter/EnhancementProvider.java | 8 +---- .../main/java/ucar/nc2/filter/Normalizer.java | 26 +++------------ .../java/ucar/nc2/filter/Standardizer.java | 25 +++------------ 5 files changed, 18 insertions(+), 92 deletions(-) diff --git a/cdm/core/src/main/java/ucar/nc2/dataset/VariableDS.java b/cdm/core/src/main/java/ucar/nc2/dataset/VariableDS.java index 0091766593..626b4e9de8 100644 --- a/cdm/core/src/main/java/ucar/nc2/dataset/VariableDS.java +++ b/cdm/core/src/main/java/ucar/nc2/dataset/VariableDS.java @@ -287,14 +287,8 @@ Array convert(Array data, Set enhancements) { toApply.add(scaleOffset); convertedType = scaleOffset.getScaledOffsetType(); } - /** this == variableDS */ - for (Enhance enhance : enhancements) { - for (EnhancementProvider service : ServiceLoader.load(EnhancementProvider.class)) { - if (service.appliesTo(enhance, this)) { - toApply.add(service.returnObject(this)); - } - } - } + + toApply.addAll(loadedEnhancements); double[] dataArray = (double[]) data.get1DJavaArray(DataType.DOUBLE); @@ -870,9 +864,8 @@ public Array convert(Array in, boolean convertUnsigned, boolean applyScaleOffset // TODO make immutable in version 6 private UnsignedConversion unsignedConversion; private ScaleOffset scaleOffset; - public Standardizer standardizer; - public Normalizer normalizer; - public Classifier classifier; + private List loadedEnhancements = new ArrayList<>(); + private ConvertMissing convertMissing; private Set enhanceMode = EnumSet.noneOf(Enhance.class); // The set of enhancements that were made. @@ -943,8 +936,8 @@ private void createEnhancements() { for (Enhance enhance : this.enhanceMode) { for (EnhancementProvider service : ServiceLoader.load(EnhancementProvider.class)) { /** Stand and Norm require floatingpoint, buc classifier can do just numeric? */ - if (service.appliesTo(enhance, this.attributes()) && dataType.isFloatingPoint()) { - service.Create(this); + if (service.appliesTo(enhance, this.attributes(), dataType)) { + loadedEnhancements.add(service.returnObject(this)); } } } diff --git a/cdm/core/src/main/java/ucar/nc2/filter/Classifier.java b/cdm/core/src/main/java/ucar/nc2/filter/Classifier.java index 0ad3a1ff81..6e8b1fb9bc 100644 --- a/cdm/core/src/main/java/ucar/nc2/filter/Classifier.java +++ b/cdm/core/src/main/java/ucar/nc2/filter/Classifier.java @@ -147,12 +147,6 @@ public static int[] stringToIntArray(String str) { public static class Provider implements EnhancementProvider { - @Override - public void Create(VariableDS var) { - var.classifier = Classifier.createFromVariable(var); - } - - @Override public String getName() { @@ -160,35 +154,15 @@ public String getName() { } @Override - public boolean canDo(Set enhancements) { - if (enhancements.contains(Enhance.ApplyClassifier)) { - return true; - } - return false; - } - - // Attribute findAttribute(String attName); - - @Override - public boolean appliesTo(Enhance enhance, AttributeContainer attributes) { - return enhance == Enhance.ApplyClassifier && attributes.findAttribute(CDM.CLASSIFY) != null; - } - - @Override - public boolean appliesTo(Enhance enhance, VariableDS var) { - return enhance == Enhance.ApplyClassifier && var.classifier != null; + public boolean appliesTo(Enhance enhance, AttributeContainer attributes, DataType dt) { + return enhance == Enhance.ApplyClassifier && attributes.findAttribute(CDM.CLASSIFY) != null && dt.isNumeric(); } public Classifier returnObject(VariableDS var) { - return var.classifier; + return createFromVariable(var); } - - - } - - } diff --git a/cdm/core/src/main/java/ucar/nc2/filter/EnhancementProvider.java b/cdm/core/src/main/java/ucar/nc2/filter/EnhancementProvider.java index b2718d9c33..614a8667f9 100644 --- a/cdm/core/src/main/java/ucar/nc2/filter/EnhancementProvider.java +++ b/cdm/core/src/main/java/ucar/nc2/filter/EnhancementProvider.java @@ -32,13 +32,7 @@ public interface EnhancementProvider { String getName(); - boolean canDo(Set enhancements); - - boolean appliesTo(Enhance enhance, AttributeContainer attributes); - - boolean appliesTo(Enhance enhance, VariableDS var); - - void Create(VariableDS var); + boolean appliesTo(Enhance enhance, AttributeContainer attributes, DataType dt); Enhancement returnObject(VariableDS var); diff --git a/cdm/core/src/main/java/ucar/nc2/filter/Normalizer.java b/cdm/core/src/main/java/ucar/nc2/filter/Normalizer.java index 11a82e4974..65ea5880c1 100644 --- a/cdm/core/src/main/java/ucar/nc2/filter/Normalizer.java +++ b/cdm/core/src/main/java/ucar/nc2/filter/Normalizer.java @@ -79,38 +79,20 @@ public double getRange() { public static class Provider implements EnhancementProvider { - @Override - public void Create(VariableDS var) { - var.normalizer = Normalizer.createFromVariable(var); - - } - @Override public String getName() { return name; } @Override - public boolean canDo(Set enhancements) { - if (enhancements.contains(Enhance.ApplyNormalizer)) { - return true; - } - return false; - } - - @Override - public boolean appliesTo(Enhance enhance, AttributeContainer attributes) { - return enhance == Enhance.ApplyNormalizer && attributes.findAttribute(CDM.NORMALIZE) != null; - } - - @Override - public boolean appliesTo(Enhance enhance, VariableDS var) { - return enhance == Enhance.ApplyNormalizer && var.normalizer != null; + public boolean appliesTo(Enhance enhance, AttributeContainer attributes, DataType dt) { + return enhance == Enhance.ApplyNormalizer && attributes.findAttribute(CDM.NORMALIZE) != null + && dt.isFloatingPoint(); } @Override public Normalizer returnObject(VariableDS var) { - return var.normalizer; + return Normalizer.createFromVariable(var); } diff --git a/cdm/core/src/main/java/ucar/nc2/filter/Standardizer.java b/cdm/core/src/main/java/ucar/nc2/filter/Standardizer.java index a0a5f6c4da..6ca0620b2d 100644 --- a/cdm/core/src/main/java/ucar/nc2/filter/Standardizer.java +++ b/cdm/core/src/main/java/ucar/nc2/filter/Standardizer.java @@ -81,38 +81,21 @@ public double getStdDev() { public static class Provider implements EnhancementProvider { - @Override - public void Create(VariableDS var) { - var.standardizer = Standardizer.createFromVariable(var); - - } - @Override public String getName() { return name; } - @Override - public boolean canDo(Set enhancements) { - if (enhancements.contains(Enhance.ApplyStandardizer)) { - return true; - } - return false; - } - - @Override - public boolean appliesTo(Enhance enhance, AttributeContainer attributes) { - return enhance == Enhance.ApplyStandardizer && attributes.findAttribute(CDM.STANDARDIZE) != null; - } @Override - public boolean appliesTo(Enhance enhance, VariableDS var) { - return enhance == Enhance.ApplyStandardizer && var.standardizer != null; + public boolean appliesTo(Enhance enhance, AttributeContainer attributes, DataType dt) { + return enhance == Enhance.ApplyStandardizer && attributes.findAttribute(CDM.STANDARDIZE) != null + && dt.isFloatingPoint(); } @Override public Standardizer returnObject(VariableDS var) { - return var.standardizer; + return createFromVariable(var); } } } From 7ee573e0366a47d32d745d07a4094ac0ca1b848c Mon Sep 17 00:00:00 2001 From: Leo Date: Wed, 17 Jul 2024 14:59:00 -0500 Subject: [PATCH 13/15] Fix the comments --- .../java/ucar/nc2/dataset/VariableDS.java | 4 +-- .../main/java/ucar/nc2/filter/Classifier.java | 27 ++------------- .../ucar/nc2/filter/EnhancementProvider.java | 22 ++----------- .../main/java/ucar/nc2/filter/Normalizer.java | 6 +--- .../java/ucar/nc2/filter/ScaleOffset.java | 6 ---- .../java/ucar/nc2/filter/Standardizer.java | 7 +--- .../unidata/io/spi/EnhancementProvider.java | 33 ------------------- 7 files changed, 7 insertions(+), 98 deletions(-) delete mode 100644 cdm/core/src/main/java/ucar/unidata/io/spi/EnhancementProvider.java diff --git a/cdm/core/src/main/java/ucar/nc2/dataset/VariableDS.java b/cdm/core/src/main/java/ucar/nc2/dataset/VariableDS.java index 626b4e9de8..822e7517df 100644 --- a/cdm/core/src/main/java/ucar/nc2/dataset/VariableDS.java +++ b/cdm/core/src/main/java/ucar/nc2/dataset/VariableDS.java @@ -932,12 +932,10 @@ private void createEnhancements() { } this.dataType = scaleOffset != null ? scaleOffset.getScaledOffsetType() : this.dataType; } - /** how oh how ??? */ for (Enhance enhance : this.enhanceMode) { for (EnhancementProvider service : ServiceLoader.load(EnhancementProvider.class)) { - /** Stand and Norm require floatingpoint, buc classifier can do just numeric? */ if (service.appliesTo(enhance, this.attributes(), dataType)) { - loadedEnhancements.add(service.returnObject(this)); + loadedEnhancements.add(service.Create(this)); } } } diff --git a/cdm/core/src/main/java/ucar/nc2/filter/Classifier.java b/cdm/core/src/main/java/ucar/nc2/filter/Classifier.java index 6e8b1fb9bc..66a3f4d3da 100644 --- a/cdm/core/src/main/java/ucar/nc2/filter/Classifier.java +++ b/cdm/core/src/main/java/ucar/nc2/filter/Classifier.java @@ -1,11 +1,7 @@ package ucar.nc2.filter; - -import java.util.Map; -import java.util.Set; import ucar.ma2.Array; import ucar.ma2.IndexIterator; -import ucar.nc2.Variable; import ucar.nc2.constants.CDM; import ucar.nc2.Attribute; import ucar.nc2.dataset.NetcdfDataset.Enhance; @@ -13,25 +9,9 @@ import ucar.nc2.util.Misc; import java.util.ArrayList; import java.util.List; -import ucar.unidata.io.spi.RandomAccessFileProvider; - - - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Sets; import ucar.ma2.*; import ucar.nc2.*; -import ucar.nc2.constants.CDM; -import ucar.nc2.dataset.NetcdfDataset.Enhance; -import ucar.nc2.filter.*; -import ucar.nc2.internal.dataset.CoordinatesHelper; -import ucar.nc2.util.CancelTask; -import ucar.nc2.util.Misc; -import javax.annotation.Nullable; -import java.io.IOException; -import java.io.OutputStream; -import java.util.*; public class Classifier implements Enhancement { @@ -148,17 +128,14 @@ public static int[] stringToIntArray(String str) { public static class Provider implements EnhancementProvider { - @Override - public String getName() { - return name; - } @Override public boolean appliesTo(Enhance enhance, AttributeContainer attributes, DataType dt) { return enhance == Enhance.ApplyClassifier && attributes.findAttribute(CDM.CLASSIFY) != null && dt.isNumeric(); } - public Classifier returnObject(VariableDS var) { + @Override + public Classifier Create(VariableDS var) { return createFromVariable(var); } } diff --git a/cdm/core/src/main/java/ucar/nc2/filter/EnhancementProvider.java b/cdm/core/src/main/java/ucar/nc2/filter/EnhancementProvider.java index 614a8667f9..f1d0f7ee2d 100644 --- a/cdm/core/src/main/java/ucar/nc2/filter/EnhancementProvider.java +++ b/cdm/core/src/main/java/ucar/nc2/filter/EnhancementProvider.java @@ -5,39 +5,21 @@ package ucar.nc2.filter; -import java.util.Map; -// package ucar.nc2.dataset; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Sets; import ucar.ma2.*; import ucar.nc2.*; -import ucar.nc2.constants.CDM; import ucar.nc2.dataset.NetcdfDataset.Enhance; import ucar.nc2.dataset.VariableDS; -import ucar.nc2.filter.*; -import ucar.nc2.internal.dataset.CoordinatesHelper; -import ucar.nc2.util.CancelTask; -import ucar.nc2.util.Misc; -import javax.annotation.Nullable; -import java.io.IOException; -import java.io.OutputStream; -import java.util.*; /** - * A Service Provider of {@link Filter}. + * A Service Provider of {@link Enhancement}. */ public interface EnhancementProvider { - String getName(); - boolean appliesTo(Enhance enhance, AttributeContainer attributes, DataType dt); - Enhancement returnObject(VariableDS var); - + Enhancement Create(VariableDS var); - // void applyEnhancement(Object instance); } diff --git a/cdm/core/src/main/java/ucar/nc2/filter/Normalizer.java b/cdm/core/src/main/java/ucar/nc2/filter/Normalizer.java index 65ea5880c1..b97941b6f2 100644 --- a/cdm/core/src/main/java/ucar/nc2/filter/Normalizer.java +++ b/cdm/core/src/main/java/ucar/nc2/filter/Normalizer.java @@ -79,10 +79,6 @@ public double getRange() { public static class Provider implements EnhancementProvider { - @Override - public String getName() { - return name; - } @Override public boolean appliesTo(Enhance enhance, AttributeContainer attributes, DataType dt) { @@ -91,7 +87,7 @@ public boolean appliesTo(Enhance enhance, AttributeContainer attributes, DataTyp } @Override - public Normalizer returnObject(VariableDS var) { + public Normalizer Create(VariableDS var) { return Normalizer.createFromVariable(var); } diff --git a/cdm/core/src/main/java/ucar/nc2/filter/ScaleOffset.java b/cdm/core/src/main/java/ucar/nc2/filter/ScaleOffset.java index a4a7cb1edd..4f7de9ff11 100644 --- a/cdm/core/src/main/java/ucar/nc2/filter/ScaleOffset.java +++ b/cdm/core/src/main/java/ucar/nc2/filter/ScaleOffset.java @@ -291,12 +291,6 @@ public Filter create(Map properties) { return new ScaleOffset(properties); } - // @Override - // public void doSomething(double val) { - // System.out.println("SCALEOFFSET ! "+val); - // } - - } diff --git a/cdm/core/src/main/java/ucar/nc2/filter/Standardizer.java b/cdm/core/src/main/java/ucar/nc2/filter/Standardizer.java index 6ca0620b2d..1ca59957ea 100644 --- a/cdm/core/src/main/java/ucar/nc2/filter/Standardizer.java +++ b/cdm/core/src/main/java/ucar/nc2/filter/Standardizer.java @@ -81,11 +81,6 @@ public double getStdDev() { public static class Provider implements EnhancementProvider { - @Override - public String getName() { - return name; - } - @Override public boolean appliesTo(Enhance enhance, AttributeContainer attributes, DataType dt) { @@ -94,7 +89,7 @@ public boolean appliesTo(Enhance enhance, AttributeContainer attributes, DataTyp } @Override - public Standardizer returnObject(VariableDS var) { + public Standardizer Create(VariableDS var) { return createFromVariable(var); } } diff --git a/cdm/core/src/main/java/ucar/unidata/io/spi/EnhancementProvider.java b/cdm/core/src/main/java/ucar/unidata/io/spi/EnhancementProvider.java deleted file mode 100644 index 281c4c6578..0000000000 --- a/cdm/core/src/main/java/ucar/unidata/io/spi/EnhancementProvider.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 1998-2019 University Corporation for Atmospheric Research/Unidata - * See LICENSE for license information. - */ -package ucar.unidata.io.spi; - -import java.io.IOException; -import ucar.unidata.io.RandomAccessFile; - -/** A Service Provider of RandomAccessFile. */ -public interface EnhancementProvider { - - /** Determine if this Provider owns this location. */ - boolean isOwnerOf(String location); - - /** Open a location that this Provider is the owner of. */ - RandomAccessFile open(String location) throws IOException; - - /** Open a location that this Provider is the owner of, with the given buffer size */ - default RandomAccessFile open(String location, int bufferSize) throws IOException { - return this.open(location); // avoid breaking an existing 3rd party implementations - } - - /** Acquire a file for a location from a cache, if available **/ - default RandomAccessFile acquire(String location) throws IOException { - return this.open(location); // avoid breaking an existing 3rd party implementations - } - - /** Acquire a file for a location, with the given buffer size, from a cache, if available **/ - default RandomAccessFile acquire(String location, int bufferSize) throws IOException { - return this.open(location, bufferSize); // avoid breaking an existing 3rd party implementations - } -} From 642b9f28a873a011ed21d045f2599a4894f0caeb Mon Sep 17 00:00:00 2001 From: Leo Date: Thu, 18 Jul 2024 09:31:34 -0500 Subject: [PATCH 14/15] final version --- cdm/core/src/main/java/ucar/nc2/filter/Classifier.java | 5 +---- .../src/main/java/ucar/nc2/filter/EnhancementProvider.java | 2 +- cdm/core/src/main/java/ucar/nc2/filter/Normalizer.java | 2 +- cdm/core/src/main/java/ucar/nc2/filter/Standardizer.java | 2 +- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/cdm/core/src/main/java/ucar/nc2/filter/Classifier.java b/cdm/core/src/main/java/ucar/nc2/filter/Classifier.java index 66a3f4d3da..1734400be2 100644 --- a/cdm/core/src/main/java/ucar/nc2/filter/Classifier.java +++ b/cdm/core/src/main/java/ucar/nc2/filter/Classifier.java @@ -126,16 +126,13 @@ public static int[] stringToIntArray(String str) { } public static class Provider implements EnhancementProvider { - - - @Override public boolean appliesTo(Enhance enhance, AttributeContainer attributes, DataType dt) { return enhance == Enhance.ApplyClassifier && attributes.findAttribute(CDM.CLASSIFY) != null && dt.isNumeric(); } @Override - public Classifier Create(VariableDS var) { + public Classifier create(VariableDS var) { return createFromVariable(var); } } diff --git a/cdm/core/src/main/java/ucar/nc2/filter/EnhancementProvider.java b/cdm/core/src/main/java/ucar/nc2/filter/EnhancementProvider.java index f1d0f7ee2d..a8cf2fdb04 100644 --- a/cdm/core/src/main/java/ucar/nc2/filter/EnhancementProvider.java +++ b/cdm/core/src/main/java/ucar/nc2/filter/EnhancementProvider.java @@ -18,7 +18,7 @@ public interface EnhancementProvider { boolean appliesTo(Enhance enhance, AttributeContainer attributes, DataType dt); - Enhancement Create(VariableDS var); + Enhancement create(VariableDS var); } diff --git a/cdm/core/src/main/java/ucar/nc2/filter/Normalizer.java b/cdm/core/src/main/java/ucar/nc2/filter/Normalizer.java index b97941b6f2..fcae8710c4 100644 --- a/cdm/core/src/main/java/ucar/nc2/filter/Normalizer.java +++ b/cdm/core/src/main/java/ucar/nc2/filter/Normalizer.java @@ -87,7 +87,7 @@ public boolean appliesTo(Enhance enhance, AttributeContainer attributes, DataTyp } @Override - public Normalizer Create(VariableDS var) { + public Normalizer create(VariableDS var) { return Normalizer.createFromVariable(var); } diff --git a/cdm/core/src/main/java/ucar/nc2/filter/Standardizer.java b/cdm/core/src/main/java/ucar/nc2/filter/Standardizer.java index 1ca59957ea..5bf8948b29 100644 --- a/cdm/core/src/main/java/ucar/nc2/filter/Standardizer.java +++ b/cdm/core/src/main/java/ucar/nc2/filter/Standardizer.java @@ -89,7 +89,7 @@ public boolean appliesTo(Enhance enhance, AttributeContainer attributes, DataTyp } @Override - public Standardizer Create(VariableDS var) { + public Standardizer create(VariableDS var) { return createFromVariable(var); } } From 7892b2d049c44a532af3a7ec155cd18155e4b0e1 Mon Sep 17 00:00:00 2001 From: Leo Date: Thu, 18 Jul 2024 09:38:58 -0500 Subject: [PATCH 15/15] one case sensitive letter update --- cdm/core/src/main/java/ucar/nc2/dataset/VariableDS.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdm/core/src/main/java/ucar/nc2/dataset/VariableDS.java b/cdm/core/src/main/java/ucar/nc2/dataset/VariableDS.java index 822e7517df..c12a232341 100644 --- a/cdm/core/src/main/java/ucar/nc2/dataset/VariableDS.java +++ b/cdm/core/src/main/java/ucar/nc2/dataset/VariableDS.java @@ -935,7 +935,7 @@ private void createEnhancements() { for (Enhance enhance : this.enhanceMode) { for (EnhancementProvider service : ServiceLoader.load(EnhancementProvider.class)) { if (service.appliesTo(enhance, this.attributes(), dataType)) { - loadedEnhancements.add(service.Create(this)); + loadedEnhancements.add(service.create(this)); } } }