RatioCalculator { public Observation calculateRatio(long l3BinIndex, Observation l2Observation) { float[] meanL3FeatureValues = l3MeanValues.get(l3BinIndex); int numObservations = l2Observation.size(); float[] newObservationValues = new float[numObservations]; for (int i = 0; i < numObservations; i++) { float l2Value = l2Observation.get(i); if (associatedMeanL3Index[i] != -1) { float meanValue = meanL3FeatureValues[associatedMeanL3Index[i]]; newObservationValues[i] = l2Value / meanValue; } else { newObservationValues[i] = l2Value; } } return new ObservationImpl(l2Observation.getLatitude(), l2Observation.getLongitude(), l2Observation.getMJD(), newObservationValues); } RatioCalculator(VariableContext variableContext, String[] l3MeanFeatureNames, Map<Long, float[]> l3MeanValues); Observation calculateRatio(long l3BinIndex, Observation l2Observation);  }
@Test public void testCalculateRatio_Simple() throws Exception { VariableContextImpl l2VariableContext = new VariableContextImpl(); l2VariableContext.defineVariable("xaxis"); l2VariableContext.defineVariable("radiance_1"); String[] l3FeatureNames = new String[]{"radiance_1_mean"}; final long l3BinIndex = 42L; float[] meanL3Values = {5f}; Map<Long, float[]> l3MeanValueMap = new HashMap<>(); l3MeanValueMap.put(l3BinIndex, meanL3Values); RatioCalculator ratioCalculator = new RatioCalculator(l2VariableContext, l3FeatureNames, l3MeanValueMap); Observation l2Observation = new ObservationImpl(0, 0, 0, 10f, 20f); Observation observation = ratioCalculator.calculateRatio(l3BinIndex, l2Observation); assertNotNull(observation); assertEquals(l2Observation.size(), observation.size()); assertEquals(10f, observation.get(0), 1e-5); assertEquals(20f / 5f, observation.get(1), 1e-5); }
@Test public void testCalculateRatio_complex() throws Exception { VariableContextImpl l2VariableContext = new VariableContextImpl(); l2VariableContext.defineVariable("xaxis"); l2VariableContext.defineVariable("radiance_1"); l2VariableContext.defineVariable("radiance_2"); l2VariableContext.defineVariable("radiance_3"); String[] l3FeatureNames = new String[]{ "radiance_1_mean", "radiance_1_sigma", "radiance_2_mean", "radiance_2_sigma", "radiance_3_mean", "radiance_3_sigma"}; final long l3BinIndex = 42L; float[] meanL3Values = {2f, 3f, 5f, 3, 10f, 3f}; Map<Long, float[]> l3MeanValueMap = new HashMap<>(); l3MeanValueMap.put(l3BinIndex, meanL3Values); RatioCalculator ratioCalculator = new RatioCalculator(l2VariableContext, l3FeatureNames, l3MeanValueMap); Observation l2Observation = new ObservationImpl(0, 0, 0, 10f, 20f, 30f, 40f); Observation observation = ratioCalculator.calculateRatio(l3BinIndex, l2Observation); assertNotNull(observation); assertEquals(l2Observation.size(), observation.size()); assertEquals(10f, observation.get(0), 1e-5); assertEquals(20f / 2f, observation.get(1), 1e-5); assertEquals(30f / 5f, observation.get(2), 1e-5); assertEquals(40f / 10f, observation.get(3), 1e-5); }