001    package org.wdssii.polarmerger;
002    
003    import org.wdssii.core.DataType;
004    
005    
006    /**
007     * Use the distance weights to create a weighted average.
008     * 
009     * @author lakshman
010     * 
011     */
012    public class DistanceWeightedObservationMerger extends AbstractWeightedObservationMerger {
013    
014            private static float MIN_WEIGHT = 0.5f;
015            
016            public void update(float[][][] values, int w_e, int w_az, int w_rn,
017                            Observation obs, float wt) {
018                    values[w_e][w_az][w_rn]  += wt * obs.getValue();
019                    weights[w_e][w_az][w_rn] += wt;
020            }
021    
022            public void finishComputation(float[][][] values) {
023                    for (int i=0; i < weights.length; ++i){
024                            for (int j=0; j < weights[0].length; ++j){
025                                    for (int k=0; k < weights[0][0].length; ++k){
026                                            if (weights[i][j][k] < MIN_WEIGHT){
027                                                    values[i][j][k] = DataType.MissingData;
028                                            } else {
029                                                    values[i][j][k] /= weights[i][j][k];
030                                            } 
031                                    }
032                            }
033                    }
034            }
035    
036    }