comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataCalculation.java @ 8213:ebdf34cae14d

Error reports for sediment load calculation.
author Tom Gottfried <tom@intevation.de>
date Fri, 05 Sep 2014 20:57:31 +0200
parents 04d1d56d896b
children be3c11bef6e8
comparison
equal deleted inserted replaced
8210:3bb00338228c 8213:ebdf34cae14d
211 if ("year".equals(yearEpoch)) return calculateYears(); 211 if ("year".equals(yearEpoch)) return calculateYears();
212 if ("epoch".equals(yearEpoch)) return calculateEpochs(); 212 if ("epoch".equals(yearEpoch)) return calculateEpochs();
213 if ("off_epoch".equals(yearEpoch)) return calculateOffEpochs(); 213 if ("off_epoch".equals(yearEpoch)) return calculateOffEpochs();
214 214
215 // TODO: i18n 215 // TODO: i18n
216 return error("minfo.sediment.load.unknown.calc.mode"); 216 return error("minfo.sedimentload.unknown.calc.mode");
217 } 217 }
218 218
219 private CalculationResult calculateYears() { 219 private CalculationResult calculateYears() {
220 SedimentLoadData sld = 220 SedimentLoadData sld =
221 SedimentLoadDataFactory.INSTANCE.getSedimentLoadData(river); 221 SedimentLoadDataFactory.INSTANCE.getSedimentLoadData(river);
222 if (sld == null) { 222 if (sld == null) {
223 // TODO: i18n 223 return error("minfo.sedimentload.no.data");
224 return error("minfo.sediment.load.no.data");
225 } 224 }
226 225
227 SedimentLoadDataResult sldr = new SedimentLoadDataResult(); 226 SedimentLoadDataResult sldr = new SedimentLoadDataResult();
228
229 Set<Integer> missingFractions = new TreeSet<Integer>();
230 227
231 Not notEpochs = new Not(IsEpoch.INSTANCE); 228 Not notEpochs = new Not(IsEpoch.INSTANCE);
232 229
233 Sum sum = new Sum(); 230 Sum sum = new Sum();
234 231
244 241
245 for (LoadSum ls: LOAD_SUMS) { 242 for (LoadSum ls: LOAD_SUMS) {
246 243
247 double [][] result = sum( 244 double [][] result = sum(
248 sld, ls.getGrainFractions(), ls.getStationType(), 245 sld, ls.getGrainFractions(), ls.getStationType(),
249 filter, sum, missingFractions); 246 filter, sum);
250 247
251 if (result[0].length == 0 || DoubleUtil.isNaN(result[1])) { 248 if (result[0].length == 0 || DoubleUtil.isNaN(result[1])) {
252 // TODO: resolve i18n 249 addProblem("sedimentload.missing.fraction." +
253 addProblem("minfo.sediment.load.no.fractions", 250 ls.getDescription(), period);
254 ls.getDescription());
255 continue; 251 continue;
256 } 252 }
257 253
258 transformT2M3(sd, year, result); 254 transformT2M3(sd, year, result);
259 255
260 SedimentLoadDataResult.Fraction sldrf = 256 SedimentLoadDataResult.Fraction sldrf =
261 new SedimentLoadDataResult.Fraction(ls.getDescription(), result, period); 257 new SedimentLoadDataResult.Fraction(ls.getDescription(), result, period);
262 258
263 sldr.addFraction(sldrf); 259 sldr.addFraction(sldrf);
264 } 260 }
265 261 }
266 }
267 // TODO: Generate messages for missing fractions.
268 return new CalculationResult(sldr, this); 262 return new CalculationResult(sldr, this);
269 } 263 }
270 264
271 private CalculationResult calculateEpochs() { 265 private CalculationResult calculateEpochs() {
272 SedimentLoadData sld = 266 SedimentLoadData sld =
273 SedimentLoadDataFactory.INSTANCE.getSedimentLoadData(river); 267 SedimentLoadDataFactory.INSTANCE.getSedimentLoadData(river);
274 if (sld == null) { 268 if (sld == null) {
275 // TODO: i18n 269 return error("minfo.sedimentload.no.data");
276 return error("minfo.sediment.load.no.data");
277 } 270 }
278 271
279 SedimentLoadDataResult sldr = new SedimentLoadDataResult(); 272 SedimentLoadDataResult sldr = new SedimentLoadDataResult();
280
281 Set<Integer> missingFractions = new TreeSet<Integer>();
282 273
283 Sum sum = new Sum(); 274 Sum sum = new Sum();
284 275
285 SedimentDensity sd = getSedimentDensity(); 276 SedimentDensity sd = getSedimentDensity();
286 277
302 Value.Filter filter = new And(notEpochs) 293 Value.Filter filter = new And(notEpochs)
303 .add(new TimeRangeIntersects(year)); 294 .add(new TimeRangeIntersects(year));
304 295
305 double [][] result = sum( 296 double [][] result = sum(
306 sld, ls.getGrainFractions(), ls.getStationType(), 297 sld, ls.getGrainFractions(), ls.getStationType(),
307 filter, sum, missingFractions); 298 filter, sum);
308 299
309 if (result[0].length == 0 || DoubleUtil.isNaN(result[1])) { 300 if (result[0].length == 0 || DoubleUtil.isNaN(result[1])) {
310 // TODO: resolve i18n
311 addProblem("minfo.sediment.load.no.fractions",
312 ls.getDescription());
313 continue; 301 continue;
314 } 302 }
315 303
316 transformT2M3(sd, year, result); 304 transformT2M3(sd, year, result);
317 results.add(result); 305 results.add(result);
318 } 306 }
319 307
320 if (results.size() == 0) { 308 if (results.size() == 0) {
309 addProblem("sedimentload.missing.fraction." +
310 ls.getDescription(), period);
321 continue; 311 continue;
322 } 312 }
323 313
324 double [][] result = average(results); 314 double [][] result = average(results);
325 315
327 SedimentLoadDataResult.Fraction sldrf = 317 SedimentLoadDataResult.Fraction sldrf =
328 new SedimentLoadDataResult.Fraction( 318 new SedimentLoadDataResult.Fraction(
329 ls.getDescription(), result, period); 319 ls.getDescription(), result, period);
330 sldr.addFraction(sldrf); 320 sldr.addFraction(sldrf);
331 } 321 }
322 else {
323 addProblem("sedimentload.missing.fraction." +
324 ls.getDescription(), period);
325 }
332 } 326 }
333 327
334 } 328 }
335 // TODO: Generate messages for missing fractions.
336 return new CalculationResult(sldr, this); 329 return new CalculationResult(sldr, this);
337 } 330 }
338 331
339 private CalculationResult calculateOffEpochs() { 332 private CalculationResult calculateOffEpochs() {
340 SedimentLoadData sld = 333 SedimentLoadData sld =
341 SedimentLoadDataFactory.INSTANCE.getSedimentLoadData(river); 334 SedimentLoadDataFactory.INSTANCE.getSedimentLoadData(river);
342 if (sld == null) { 335 if (sld == null) {
343 // TODO: i18n 336 return error("minfo.sedimentload.no.data");
344 return error("minfo.sediment.load.no.data");
345 } 337 }
346 338
347 SedimentLoadDataResult sldr = new SedimentLoadDataResult(); 339 SedimentLoadDataResult sldr = new SedimentLoadDataResult();
348 340
349 SedimentDensity sd = getSedimentDensity(); 341 SedimentDensity sd = getSedimentDensity();
362 Sum sum = new Sum(); 354 Sum sum = new Sum();
363 355
364 for (LoadSum ls: LOAD_SUMS) { 356 for (LoadSum ls: LOAD_SUMS) {
365 double [][] result = sum( 357 double [][] result = sum(
366 sld, ls.getGrainFractions(), ls.getStationType(), 358 sld, ls.getGrainFractions(), ls.getStationType(),
367 filter, sum, missingFractions); 359 filter, sum);
368 360
369 if (result[0].length == 0 || DoubleUtil.isNaN(result[1])) { 361 if (result[0].length == 0 || DoubleUtil.isNaN(result[1])) {
370 // TODO: resolve i18n 362 addProblem("sedimentload.missing.fraction." +
371 addProblem("minfo.sediment.load.no.fractions", 363 ls.getDescription(), period);
372 ls.getDescription());
373 continue; 364 continue;
374 } 365 }
366
375 transformT2M3(sd, year, result); 367 transformT2M3(sd, year, result);
376 SedimentLoadDataResult.Fraction sldrf = 368 SedimentLoadDataResult.Fraction sldrf =
377 new SedimentLoadDataResult.Fraction(ls.getDescription(), result, period); 369 new SedimentLoadDataResult.Fraction(ls.getDescription(), result, period);
378 sldr.addFraction(sldrf); 370 sldr.addFraction(sldrf);
379 } 371 }
410 public double[][] sum( 402 public double[][] sum(
411 SedimentLoadData sld, 403 SedimentLoadData sld,
412 int [] grainFractions, 404 int [] grainFractions,
413 int lsSType, 405 int lsSType,
414 Value.Filter filter, 406 Value.Filter filter,
415 Sum sum, 407 Sum sum
416 Set<Integer> missingFractions
417 ) { 408 ) {
418 List<Station> stations = sld.findStations(from, to); 409 List<Station> stations = sld.findStations(from, to);
419 410
420 double [] values = new double[grainFractions.length]; 411 double [] values = new double[grainFractions.length];
421 412
456 } 447 }
457 } 448 }
458 } 449 }
459 450
460 if (sum.getN() == 0) { 451 if (sum.getN() == 0) {
461 missingFractions.add(gf);
462 values[i] = Double.NaN; 452 values[i] = Double.NaN;
463 } else { 453 } else {
464 values[i] = sum.getSum(); 454 values[i] = sum.getSum();
465 } 455 }
466 } 456 }
467 result[0][j] = station.getStation(); 457 result[0][j] = station.getStation();
468 result[1][j] = DoubleUtil.sum(values); 458 result[1][j] = DoubleUtil.sum(values);
469 } 459 }
470
471 // TODO: Handle 'virtual' measument stations 'from' and 'to'.
472 460
473 return result; 461 return result;
474 } 462 }
475 463
476 private static final class XSum { 464 private static final class XSum {

http://dive4elements.wald.intevation.org