comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhcalculation/TkhCalculator.java @ 8978:b5600453bb8f

SINFO Calculations: do not produce result rows if some input data has missing values. Also check for years of waterlevels in flow depth development calculation.
author gernotbelger
date Thu, 05 Apr 2018 11:57:54 +0200
parents 45f1ad66560e
children d5802f22e4f5
comparison
equal deleted inserted replaced
8977:bf8a9df86f32 8978:b5600453bb8f
106 106
107 private double getBedMeasurement(final double km) { 107 private double getBedMeasurement(final double km) {
108 return this.bedMeasurementsFinder.findD50(km); 108 return this.bedMeasurementsFinder.findD50(km);
109 } 109 }
110 110
111 public void calculateTkh(final double km, final SInfoResultRow row) { 111 public boolean calculateTkh(final double km, final SInfoResultRow row) {
112 112
113 row.putValue(SInfoResultType.station, km); 113 row.putValue(SInfoResultType.station, km);
114 114
115 final SoilKind kind = getSoilKind(km); 115 final SoilKind kind = getSoilKind(km);
116 row.putValue(SInfoResultType.soilkind, kind); 116 row.putValue(SInfoResultType.soilkind, kind);
117 117
118 final double wst = this.waterlevelProvider.getWaterlevel(km); 118 final double wst = this.waterlevelProvider.getWaterlevel(km);
119 row.putValue(SInfoResultType.waterlevel, wst); 119 row.putValue(SInfoResultType.waterlevel, wst);
120 if (Double.isNaN(wst))
121 return false;
120 122
121 final double meanBedHeight = this.bedHeightsProvider.getMeanBedHeight(km); 123 final double meanBedHeight = this.bedHeightsProvider.getMeanBedHeight(km);
122 row.putValue(SInfoResultType.meanBedHeight, meanBedHeight); 124 row.putValue(SInfoResultType.meanBedHeight, meanBedHeight);
125 if (Double.isNaN(meanBedHeight))
126 return false;
123 127
124 final double flowDepth = wst - meanBedHeight; 128 final double flowDepth = wst - meanBedHeight;
125 row.putValue(SInfoResultType.flowdepth, flowDepth); 129 row.putValue(SInfoResultType.flowdepth, flowDepth);
130 if (Double.isNaN(flowDepth))
131 return false;
126 132
127 final double discharge = this.dischargeProvider.getDischarge(km); 133 final double discharge = this.dischargeProvider.getDischarge(km);
128 row.putValue(SInfoResultType.discharge, discharge); 134 row.putValue(SInfoResultType.discharge, discharge);
135
136 if (!this.hasTkh())
137 return true;
138
139 // Missing discharge or kind is only a problem if we want to calculate tkh
129 if (Double.isNaN(discharge)) 140 if (Double.isNaN(discharge))
130 return; 141 return false;
131 142 if (kind == null)
132 if (!this.hasTkh()) 143 return false;
133 return;
134 144
135 final double d50 = getBedMeasurement(km); 145 final double d50 = getBedMeasurement(km);
146 row.putValue(SInfoResultType.d50, d50);
136 if (Double.isNaN(d50)) 147 if (Double.isNaN(d50))
137 return; 148 return false;
138 row.putValue(SInfoResultType.d50, d50);
139 149
140 if (!this.flowVelocitiesFinder.findKmQValues(km, discharge)) 150 if (!this.flowVelocitiesFinder.findKmQValues(km, discharge))
141 return; 151 return false;
142 152
143 final double velocity = this.flowVelocitiesFinder.getFindVmainFound(); 153 final double velocity = this.flowVelocitiesFinder.getFindVmainFound();
144 row.putValue(SInfoResultType.velocity, velocity); 154 row.putValue(SInfoResultType.velocity, velocity);
155 if (Double.isNaN(velocity))
156 return false;
145 157
146 final double tau = this.flowVelocitiesFinder.getFindTauFound(); 158 final double tau = this.flowVelocitiesFinder.getFindTauFound();
147 row.putValue(SInfoResultType.tau, tau); 159 row.putValue(SInfoResultType.tau, tau);
160 if (Double.isNaN(tau))
161 return false;
148 162
149 final double tkh = calculateTkh(wst - meanBedHeight, velocity, d50, tau); 163 final double tkh = calculateTkh(wst - meanBedHeight, velocity, d50, tau);
150 row.putValue(SInfoResultType.tkh, tkh); 164 row.putValue(SInfoResultType.tkh, tkh);
165 if (Double.isNaN(tkh))
166 return false;
151 167
152 switch (kind) { 168 switch (kind) {
153 case starr: 169 case starr:
154 row.putValue(SInfoResultType.tkhup, tkh); 170 row.putValue(SInfoResultType.tkhup, tkh);
155 row.putValue(SInfoResultType.tkhdown, 0.0); 171 row.putValue(SInfoResultType.tkhdown, 0.0);
162 break; 178 break;
163 } 179 }
164 180
165 final double flowDepthTkh = calculateFlowDepthTkh(tkh, kind, wst, meanBedHeight); 181 final double flowDepthTkh = calculateFlowDepthTkh(tkh, kind, wst, meanBedHeight);
166 row.putValue(SInfoResultType.flowdepthtkh, flowDepthTkh); 182 row.putValue(SInfoResultType.flowdepthtkh, flowDepthTkh);
183
184 return true;
167 } 185 }
168 186
169 /** 187 /**
170 * Calculates a transport body height 188 * Calculates a transport body height
171 * 189 *
200 return tkh; 218 return tkh;
201 } 219 }
202 220
203 private double calculateFlowDepthTkh(final double tkhValue, final SoilKind tkhKind, final double wst, final double meanBedHeight) { 221 private double calculateFlowDepthTkh(final double tkhValue, final SoilKind tkhKind, final double wst, final double meanBedHeight) {
204 222
205 if (Double.isNaN(tkhValue) || tkhKind == null)
206 return Double.NaN;
207
208 switch (tkhKind) { 223 switch (tkhKind) {
209 case starr: 224 case starr:
210 return wst - (meanBedHeight + tkhValue / 100); 225 return wst - (meanBedHeight + tkhValue / 100);
211 226
212 case mobil: 227 case mobil:

http://dive4elements.wald.intevation.org