comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedQualityResultValue.java @ 8587:07c9ac22f611

(issue1755) Generalise BedQuality result handling The bedquality calculation now produces a result for each time period which has BedQualityResultValues for each specific result type. Formally this was split up in density, porosity and diameter classes with some bedload diameter classes mixed in for extra fun. The intent of this commit is to allow more shared code and generic access patterns to the BedQuality results.
author Andre Heinecke <andre.heinecke@intevation.de>
date Wed, 18 Mar 2015 18:42:08 +0100
parents
children 3c78fc83fc6d
comparison
equal deleted inserted replaced
8586:19fde13e2db4 8587:07c9ac22f611
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
2 * Software engineering by Intevation GmbH
3 *
4 * This file is Free Software under the GNU AGPL (>=v3)
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
6 * documentation coming with Dive4Elements River for details.
7 */
8
9 package org.dive4elements.river.artifacts.model.minfo;
10
11 import org.dive4elements.river.utils.DoubleUtil;
12
13 import org.apache.commons.math.analysis.polynomials.PolynomialSplineFunction;
14 import org.apache.commons.math.ArgumentOutsideDomainException;
15
16 import java.util.Arrays;
17 import java.util.Set;
18 import java.util.HashSet;
19
20 import java.io.Serializable;
21
22 /** Holder of a specific result from the bed quality calculation.
23 *
24 * Data is always a map of km to value. The type "bedload"
25 * translates to german "Geschiebe" other results are either
26 * specific to the top or the sublayer of the riverbed.
27 *
28 * The name can be the diameter of this result for bed and bedload
29 * data.
30 **/
31 public class BedQualityResultValue implements Serializable {
32 public static final String[] DIAMETER_NAMES = new String[] {
33 "D90",
34 "D84",
35 "D80",
36 "D75",
37 "D70",
38 "D60",
39 "D50",
40 "D40",
41 "D30",
42 "D25",
43 "D20",
44 "D16",
45 "D10",
46 "DM",
47 "DMIN",
48 "DMAX"
49 };
50
51 /* For ease of access */
52 public static final Set<String> DIAMETER_NAME_SET = new HashSet<String>(
53 Arrays.asList(DIAMETER_NAMES));
54
55 private String name;
56 private String type;
57 private double [][] data;
58 private transient PolynomialSplineFunction interpolFunc;
59
60 public BedQualityResultValue() {
61 }
62
63 public BedQualityResultValue(String name, double [][] data, String type) {
64 this.name = name;
65 setData(data);
66 this.type = type;
67 }
68
69 public String getName() {
70 return name;
71 }
72
73 public void setName(String name) {
74 this.name = name;
75 }
76
77 public double [][] getData() {
78 return data;
79 }
80
81 public double getData(double x) {
82 int idx = Arrays.binarySearch(data[0], x);
83 if (idx < 0) {
84 return Double.NaN;
85 } else {
86 return data[1][idx];
87 }
88 }
89
90 public double getDataInterpolated(double x) {
91 if (interpolFunc == null) {
92 interpolFunc = DoubleUtil.getLinearInterpolator(data[0], data[1]);
93 }
94 try {
95 return interpolFunc.value(x);
96 } catch (ArgumentOutsideDomainException e) {
97 return getData(x);
98 }
99 }
100
101 public double [][] getDataInterpolated(double[] x) {
102 double y[] = new double[x.length];
103 int i = 0;
104 for (double point: x) {
105 y[i++] = getDataInterpolated(point);
106 }
107 return new double[][] {x, y};
108 }
109
110 public void setData(double [][] data) {
111 this.data = data;
112 }
113
114 public void setType(String type) {
115 this.type = type;
116 }
117
118 public String getType() {
119 return type;
120 }
121
122 /** Checks wether or not the name matches that of a diameter */
123 public boolean isDiameterResult() {
124 return DIAMETER_NAME_SET.contains(name.toUpperCase());
125 }
126 }

http://dive4elements.wald.intevation.org