annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java @ 5508:c6e552348934

SedimentDensityParser: don't try to guess year from comment column
author Tom Gottfried <tom.gottfried@intevation.de>
date Thu, 28 Mar 2013 16:43:20 +0100
parents 5f38d1c39ebd
children
rev   line source
146
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.artifacts.model;
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 import java.util.List;
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4 import java.util.Map;
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
5 import java.util.HashMap;
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6 import java.util.Arrays;
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
7
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
8 import java.io.Serializable;
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10 import org.hibernate.Session;
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11 import org.hibernate.Query;
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13 import org.apache.log4j.Logger;
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14
315
94c176fdcb89 Removed the SessionHolder and adapted imports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 311
diff changeset
15 import de.intevation.flys.backend.SessionHolder;
146
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16 import de.intevation.flys.model.Gauge;
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17 import de.intevation.flys.model.DischargeTable;
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18 import de.intevation.flys.model.DischargeTableValue;
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19
2418
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
20 import gnu.trove.TDoubleArrayList;
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
21
3050
02254d763bc0 cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2418
diff changeset
22 /** Documentation goes here. */
146
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 public class DischargeTables
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 implements Serializable
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25 {
3050
02254d763bc0 cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2418
diff changeset
26 /** Private logger. */
329
0b2358bc716d Discharge table: Added static method getWForQ() to interpolate a w value for a given q value based on a given discharge table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 328
diff changeset
27 private static Logger log = Logger.getLogger(DischargeTables.class);
0b2358bc716d Discharge table: Added static method getWForQ() to interpolate a w value for a given q value based on a given discharge table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 328
diff changeset
28
5340
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4919
diff changeset
29 /** Scale to convert discharge table values of master table into [cm]. */
4138
1d9c9a3493ea #904 Use the correct scale to convert discharge table values into [cm].
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3269
diff changeset
30 public static final double MASTER_SCALE = 100d;
1d9c9a3493ea #904 Use the correct scale to convert discharge table values into [cm].
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3269
diff changeset
31
5340
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4919
diff changeset
32 /** Scale to convert discharge table values of historical tables into [cm]. */
4138
1d9c9a3493ea #904 Use the correct scale to convert discharge table values into [cm].
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3269
diff changeset
33 public static final double HISTORICAL_SCALE = 1d;
328
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
34
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
35 public static final int MASTER = 0;
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
36
146
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 protected List<String> gaugeNames;
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 protected String riverName;
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40
154
03362976fa0f DischargeTables: Cache the scale, too. Otherwise two calls to getValues() with different arguments will result in the same output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 153
diff changeset
41 protected double scale;
03362976fa0f DischargeTables: Cache the scale, too. Otherwise two calls to getValues() with different arguments will result in the same output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 153
diff changeset
42
328
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
43 protected int kind;
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
44
150
c904d52cdfd0 Don't used interleaved x/y data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 146
diff changeset
45 protected Map<String, double [][]> values;
146
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47 public DischargeTables() {
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48 }
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49
328
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
50 public DischargeTables(String riverName, String gaugeName) {
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
51 this(riverName, gaugeName, MASTER);
146
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52 }
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53
328
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
54 public DischargeTables(String riverName, String gaugeName, int kind) {
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
55 this(riverName, new String [] { gaugeName }, kind);
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
56 }
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
57
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
58 public DischargeTables(String riverName, String [] gaugeNames) {
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
59 this(riverName, gaugeNames, MASTER);
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
60 }
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
61
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
62 public DischargeTables(String riverName, String [] gaugeNames, int kind) {
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
63 this(riverName, Arrays.asList(gaugeNames), kind);
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
64 }
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
65
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
66 public DischargeTables(
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
67 String riverName,
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
68 List<String> gaugeNames,
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
69 int kind
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
70 ) {
154
03362976fa0f DischargeTables: Cache the scale, too. Otherwise two calls to getValues() with different arguments will result in the same output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 153
diff changeset
71 scale = Double.NaN;
328
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
72 this.kind = kind;
146
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
73 this.riverName = riverName;
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
74 this.gaugeNames = gaugeNames;
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
75 }
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
76
328
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
77 public double [][] getFirstTable() {
4138
1d9c9a3493ea #904 Use the correct scale to convert discharge table values into [cm].
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3269
diff changeset
78 return getFirstTable(MASTER_SCALE);
328
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
79 }
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
80
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
81 public double [][] getFirstTable(double scale) {
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
82 Map<String, double [][]> values = getValues(scale);
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
83 for (double [][] table: values.values()) {
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
84 return table;
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
85 }
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
86 return null;
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
87 }
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
88
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
89 public Map<String, double [][]> getValues() {
4138
1d9c9a3493ea #904 Use the correct scale to convert discharge table values into [cm].
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3269
diff changeset
90 return getValues(MASTER_SCALE);
328
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
91 }
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
92
153
c97f9bc9b642 The out() operation of the WINFO artifact draws discharge tables for gauges specified by the user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 150
diff changeset
93 public Map<String, double [][]> getValues(double scale) {
154
03362976fa0f DischargeTables: Cache the scale, too. Otherwise two calls to getValues() with different arguments will result in the same output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 153
diff changeset
94 if (values == null || scale != this.scale) {
153
c97f9bc9b642 The out() operation of the WINFO artifact draws discharge tables for gauges specified by the user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 150
diff changeset
95 values = loadValues(scale);
154
03362976fa0f DischargeTables: Cache the scale, too. Otherwise two calls to getValues() with different arguments will result in the same output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 153
diff changeset
96 this.scale = scale;
146
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
97 }
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
98 return values;
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
99 }
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
100
1929
6b0ae0f2cae6 (Minor) cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 735
diff changeset
101 /**
6b0ae0f2cae6 (Minor) cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 735
diff changeset
102 * Returns mapping of gauge name to values.
6b0ae0f2cae6 (Minor) cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 735
diff changeset
103 */
153
c97f9bc9b642 The out() operation of the WINFO artifact draws discharge tables for gauges specified by the user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 150
diff changeset
104 protected Map<String, double [][]> loadValues(double scale) {
150
c904d52cdfd0 Don't used interleaved x/y data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 146
diff changeset
105 Map<String, double [][]> values = new HashMap<String, double [][]>();
146
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
106
311
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
107 Session session = SessionHolder.HOLDER.get();
146
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
108
311
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
109 Query gaugeQuery = session.createQuery(
336
7f13ed751277 Fixed broken HQL statement.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 334
diff changeset
110 "from Gauge where name=:gauge and river.name=:river");
311
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
111 gaugeQuery.setParameter("river", riverName);
146
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
112
311
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
113 for (String gaugeName: gaugeNames) {
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
114 gaugeQuery.setParameter("gauge", gaugeName);
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
115 List<Gauge> gauges = gaugeQuery.list();
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
116 if (gauges.isEmpty()) {
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
117 log.warn(
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
118 "no gauge '"+gaugeName+"' at river '"+riverName+"'");
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
119 continue;
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
120 }
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
121 Gauge gauge = gauges.get(0);
146
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
122
311
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
123 List<DischargeTable> tables = gauge.getDischargeTables();
146
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
124
311
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
125 if (tables.isEmpty()) {
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
126 log.warn(
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
127 "no discharge table for gauge '" + gaugeName + "'");
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
128 continue;
146
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
129 }
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
130
311
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
131 // TODO: Filter by time interval
4919
dbe9b7d6b80b Find correct discharge table for gauge.
Raimund Renkert <rrenkert@intevation.de>
parents: 4226
diff changeset
132 DischargeTable table = null;
dbe9b7d6b80b Find correct discharge table for gauge.
Raimund Renkert <rrenkert@intevation.de>
parents: 4226
diff changeset
133 for (DischargeTable dt : tables) {
dbe9b7d6b80b Find correct discharge table for gauge.
Raimund Renkert <rrenkert@intevation.de>
parents: 4226
diff changeset
134 if (dt.getKind() == 0) {
dbe9b7d6b80b Find correct discharge table for gauge.
Raimund Renkert <rrenkert@intevation.de>
parents: 4226
diff changeset
135 table = dt;
dbe9b7d6b80b Find correct discharge table for gauge.
Raimund Renkert <rrenkert@intevation.de>
parents: 4226
diff changeset
136 break;
dbe9b7d6b80b Find correct discharge table for gauge.
Raimund Renkert <rrenkert@intevation.de>
parents: 4226
diff changeset
137 }
dbe9b7d6b80b Find correct discharge table for gauge.
Raimund Renkert <rrenkert@intevation.de>
parents: 4226
diff changeset
138 }
dbe9b7d6b80b Find correct discharge table for gauge.
Raimund Renkert <rrenkert@intevation.de>
parents: 4226
diff changeset
139 if (table == null) {
dbe9b7d6b80b Find correct discharge table for gauge.
Raimund Renkert <rrenkert@intevation.de>
parents: 4226
diff changeset
140 table = tables.get(0);
dbe9b7d6b80b Find correct discharge table for gauge.
Raimund Renkert <rrenkert@intevation.de>
parents: 4226
diff changeset
141 }
2418
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
142 double [][] vs = loadDischargeTableValues(table, scale);
329
0b2358bc716d Discharge table: Added static method getWForQ() to interpolate a w value for a given q value based on a given discharge table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 328
diff changeset
143
2418
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
144 values.put(gaugeName, vs);
146
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
145 }
311
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
146
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
147 return values;
146
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
148 }
329
0b2358bc716d Discharge table: Added static method getWForQ() to interpolate a w value for a given q value based on a given discharge table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 328
diff changeset
149
2230
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
150
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
151 /**
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
152 * @param table The discharge table
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
153 * @param scale The scale factor to adjust W and Q values.
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
154 *
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
155 * @return the values of a discharge table.
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
156 */
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
157 public static double[][] loadDischargeTableValues(
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
158 DischargeTable table,
2418
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
159 double scale
2230
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
160 ) {
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
161 List<DischargeTableValue> dtvs = table.getDischargeTableValues();
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
162
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
163 final double [][] vs = new double[2][dtvs.size()];
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
164
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
165 int idx = 0;
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
166 for (DischargeTableValue dtv: dtvs) {
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
167 double q = dtv.getQ().doubleValue();
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
168 vs[0][idx] = q * scale;
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
169 vs[1][idx] = dtv.getW().doubleValue() * scale;
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
170 ++idx;
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
171 }
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
172
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
173 return vs;
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
174 }
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
175
2418
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
176 private static final double EPSILON = 1e-5;
2230
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
177
2418
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
178 private static final boolean epsEquals(double a, double b) {
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
179 return Math.abs(a - b) < EPSILON;
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
180 }
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
181
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
182 private static final boolean between(double a, double b, double x) {
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
183 if (a > b) { double t = a; a = b; b = t; }
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
184 return x > a && x < b;
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
185 }
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
186
5340
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4919
diff changeset
187 /**
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4919
diff changeset
188 * Find or interpolate Qs from q/w array.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4919
diff changeset
189 * @param values [[q0,q1,q2],[w0,w1,w2]]
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4919
diff changeset
190 * @param w W value to look for in values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4919
diff changeset
191 */
2418
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
192 public static double [] getQsForW(double [][] values, double w) {
378
20c3a5b36434 Repaired DischargeTables.getQForW()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 376
diff changeset
193
20c3a5b36434 Repaired DischargeTables.getQForW()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 376
diff changeset
194 boolean debug = log.isDebugEnabled();
20c3a5b36434 Repaired DischargeTables.getQForW()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 376
diff changeset
195
20c3a5b36434 Repaired DischargeTables.getQForW()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 376
diff changeset
196 if (debug) {
2418
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
197 log.debug("getQsForW: W = " + w);
329
0b2358bc716d Discharge table: Added static method getWForQ() to interpolate a w value for a given q value based on a given discharge table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 328
diff changeset
198 }
0b2358bc716d Discharge table: Added static method getWForQ() to interpolate a w value for a given q value based on a given discharge table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 328
diff changeset
199
2418
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
200 double [] qs = values[0];
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
201 double [] ws = values[1];
329
0b2358bc716d Discharge table: Added static method getWForQ() to interpolate a w value for a given q value based on a given discharge table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 328
diff changeset
202
2418
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
203 int N = Math.min(qs.length, ws.length);
329
0b2358bc716d Discharge table: Added static method getWForQ() to interpolate a w value for a given q value based on a given discharge table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 328
diff changeset
204
2418
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
205 if (N == 0) {
378
20c3a5b36434 Repaired DischargeTables.getQForW()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 376
diff changeset
206 if (debug) {
2418
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
207 log.debug("Q(" + w + ") = []");
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
208 }
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
209 return new double [0];
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
210 }
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
211
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
212 TDoubleArrayList outQs = new TDoubleArrayList();
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
213
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
214 if (epsEquals(ws[0], w)) {
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
215 outQs.add(qs[0]);
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
216 }
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
217
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
218 for (int i = 1; i < N; ++i) {
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
219 if (epsEquals(ws[i], w)) {
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
220 outQs.add(qs[i]);
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
221 }
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
222 else if (between(ws[i-1], ws[i], w)) {
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
223 double w1 = ws[i-1];
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
224 double w2 = ws[i];
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
225 double q1 = qs[i-1];
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
226 double q2 = qs[i];
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
227
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
228 // q1 = m*w1 + b
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
229 // q2 = m*w2 + b
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
230 // q2 - q1 = m*(w2 - w1)
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
231 // m = (q2 - q1)/(w2 - w1) # w2 != w1
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
232 // b = q1 - m*w1
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
233 // w1 != w2
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
234
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
235 double m = (q2 - q1)/(w2 - w1);
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
236 double b = q1 - m*w1;
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
237 double q = w*m + b;
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
238
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
239 outQs.add(q);
378
20c3a5b36434 Repaired DischargeTables.getQForW()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 376
diff changeset
240 }
329
0b2358bc716d Discharge table: Added static method getWForQ() to interpolate a w value for a given q value based on a given discharge table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 328
diff changeset
241 }
2418
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
242
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
243 double [] result = outQs.toNativeArray();
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
244
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
245 if (debug) {
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
246 log.debug("Q(" + w + ") = " + Arrays.toString(result));
378
20c3a5b36434 Repaired DischargeTables.getQForW()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 376
diff changeset
247 }
2418
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
248
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
249 return result;
329
0b2358bc716d Discharge table: Added static method getWForQ() to interpolate a w value for a given q value based on a given discharge table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 328
diff changeset
250 }
4226
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
251
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
252 public static double [] getWsForQ(double [][] values, double q) {
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
253
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
254 boolean debug = log.isDebugEnabled();
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
255
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
256 if (debug) {
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
257 log.debug("getWsForQ: W = " + q);
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
258 }
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
259
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
260 double [] qs = values[0];
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
261 double [] ws = values[1];
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
262
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
263 int N = Math.min(qs.length, ws.length);
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
264
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
265 if (N == 0) {
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
266 if (debug) {
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
267 log.debug("W(" + q + ") = []");
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
268 }
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
269 return new double [0];
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
270 }
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
271
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
272 TDoubleArrayList outWs = new TDoubleArrayList();
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
273
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
274 if (epsEquals(qs[0], q)) {
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
275 outWs.add(ws[0]);
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
276 }
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
277
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
278 for (int i = 1; i < N; ++i) {
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
279 if (epsEquals(qs[i], q)) {
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
280 outWs.add(ws[i]);
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
281 }
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
282 else if (between(qs[i-1], qs[i], q)) {
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
283 double w1 = ws[i-1];
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
284 double w2 = ws[i];
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
285 double q1 = qs[i-1];
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
286 double q2 = qs[i];
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
287
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
288 // w1 = m*q1 + b
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
289 // w2 = m*q2 + b
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
290 // w2 - w1 = m*(q2 - q1)
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
291 // m = (w2 - w1)/(q2 - q1) # q2 != q1
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
292 // b = w1 - m*q1
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
293 // q1 != q2
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
294
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
295 double m = (w2 - w1)/(q2 - q1);
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
296 double b = w1 - m*q1;
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
297 double w = q*m + b;
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
298
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
299 outWs.add(w);
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
300 }
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
301 }
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
302
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
303 double [] result = outWs.toNativeArray();
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
304
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
305 if (debug) {
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
306 log.debug("W(" + q + ") = " + Arrays.toString(result));
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
307 }
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
308
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
309 return result;
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
310 }
146
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
311 }
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
312 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org