Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadCalculation.java @ 8024:963ede7b32bb
Renamed SedimentLoad to SedimentLoadLSData to make place for SedimentLoad in backend.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Wed, 09 Jul 2014 17:33:57 +0200 |
parents | b4117b8adb79 |
children | fdb26fe898dc |
comparison
equal
deleted
inserted
replaced
8023:f7f86f4e4c8d | 8024:963ede7b32bb |
---|---|
143 * @param km km at which to build fractions average. | 143 * @param km km at which to build fractions average. |
144 * @param epochLoads the loads to build average over. | 144 * @param epochLoads the loads to build average over. |
145 * @param[out] resLoad resulting SedimentLoad. | 145 * @param[out] resLoad resulting SedimentLoad. |
146 */ | 146 */ |
147 private void calculateEpochKm( | 147 private void calculateEpochKm( |
148 List<SedimentLoad> epochLoads, | 148 List<SedimentLoadLSData> epochLoads, |
149 SedimentLoad resLoad, | 149 SedimentLoadLSData resLoad, |
150 double km | 150 double km |
151 ) { | 151 ) { |
152 int cSum = 0; | 152 int cSum = 0; |
153 int fmSum = 0; | 153 int fmSum = 0; |
154 int sSum = 0; | 154 int sSum = 0; |
155 int ssSum = 0; | 155 int ssSum = 0; |
156 int ssbSum = 0; | 156 int ssbSum = 0; |
157 int sseSum = 0; | 157 int sseSum = 0; |
158 for (SedimentLoad load : epochLoads) { | 158 for (SedimentLoadLSData load : epochLoads) { |
159 SedimentLoadFraction f = load.getFraction(km); | 159 SedimentLoadFraction f = load.getFraction(km); |
160 if (f.getCoarse() > 0d) { | 160 if (f.getCoarse() > 0d) { |
161 double c = makeNaN0(resLoad.getFraction(km).getCoarse()); | 161 double c = makeNaN0(resLoad.getFraction(km).getCoarse()); |
162 resLoad.setCoarse(km, c + f.getCoarse(), f.getCoarseRange()); | 162 resLoad.setCoarse(km, c + f.getCoarse(), f.getCoarseRange()); |
163 cSum++; | 163 cSum++; |
217 /** | 217 /** |
218 * Calculate result for the ith given epoch. | 218 * Calculate result for the ith given epoch. |
219 * @param i index of epoch (if multiple given). | 219 * @param i index of epoch (if multiple given). |
220 */ | 220 */ |
221 private SedimentLoadResult calculateEpoch(int i) { | 221 private SedimentLoadResult calculateEpoch(int i) { |
222 List<SedimentLoad> epochLoads = new ArrayList<SedimentLoad>(); | 222 List<SedimentLoadLSData> epochLoads = new ArrayList<SedimentLoadLSData>(); |
223 for (int j = epoch[i][0]; j <= epoch[i][1]; j++) { | 223 for (int j = epoch[i][0]; j <= epoch[i][1]; j++) { |
224 epochLoads.add(SedimentLoadFactory.getLoadWithData( | 224 epochLoads.add(SedimentLoadFactory.getLoadWithData( |
225 this.river, | 225 this.river, |
226 this.yearEpoch, | 226 this.yearEpoch, |
227 this.kmLow, | 227 this.kmLow, |
228 this.kmUp, | 228 this.kmUp, |
229 j, //syear | 229 j, //syear |
230 j)); //eyear | 230 j)); //eyear |
231 } | 231 } |
232 | 232 |
233 SedimentLoad resLoad = new SedimentLoad(); | 233 SedimentLoadLSData resLoad = new SedimentLoadLSData(); |
234 TDoubleArrayList kms = new TDoubleArrayList(); | 234 TDoubleArrayList kms = new TDoubleArrayList(); |
235 | 235 |
236 for (SedimentLoad load : epochLoads) { | 236 for (SedimentLoadLSData load : epochLoads) { |
237 for (double km : load.getKms()) { | 237 for (double km : load.getKms()) { |
238 if (!kms.contains(km)) { | 238 if (!kms.contains(km)) { |
239 kms.add(km); | 239 kms.add(km); |
240 } | 240 } |
241 } | 241 } |
245 calculateEpochKm(epochLoads, resLoad, kms.get(j)); | 245 calculateEpochKm(epochLoads, resLoad, kms.get(j)); |
246 } | 246 } |
247 resLoad.setDescription(""); | 247 resLoad.setDescription(""); |
248 resLoad.setEpoch(true); | 248 resLoad.setEpoch(true); |
249 | 249 |
250 SedimentLoad sl = calculateTotalLoad(resLoad, this.epoch[i][0]); | 250 SedimentLoadLSData sl = calculateTotalLoad(resLoad, this.epoch[i][0]); |
251 | 251 |
252 if (this.unit.equals("m3_per_a")) { | 252 if (this.unit.equals("m3_per_a")) { |
253 sl = calculateUnit(sl, this.epoch[i][0]); | 253 sl = calculateUnit(sl, this.epoch[i][0]); |
254 } | 254 } |
255 | 255 |
262 /** | 262 /** |
263 * Calculate/Fetch values at off. epochs. | 263 * Calculate/Fetch values at off. epochs. |
264 * @param i index in epochs. | 264 * @param i index in epochs. |
265 */ | 265 */ |
266 private SedimentLoadResult calculateOffEpoch(int i) { | 266 private SedimentLoadResult calculateOffEpoch(int i) { |
267 SedimentLoad load = SedimentLoadFactory.getLoadWithData( | 267 SedimentLoadLSData load = SedimentLoadFactory.getLoadWithData( |
268 this.river, | 268 this.river, |
269 this.yearEpoch, | 269 this.yearEpoch, |
270 kmLow, | 270 kmLow, |
271 kmUp, | 271 kmUp, |
272 this.epoch[i][0], | 272 this.epoch[i][0], |
273 this.epoch[i][1]); | 273 this.epoch[i][1]); |
274 SedimentLoadResult result; | 274 SedimentLoadResult result; |
275 SedimentLoad sl = calculateTotalLoad(load, this.epoch[i][0]); | 275 SedimentLoadLSData sl = calculateTotalLoad(load, this.epoch[i][0]); |
276 if (unit.equals("m3_per_a")) { | 276 if (unit.equals("m3_per_a")) { |
277 SedimentLoad slu = calculateUnit(sl, epoch[i][0]); | 277 SedimentLoadLSData slu = calculateUnit(sl, epoch[i][0]); |
278 result = new SedimentLoadResult( | 278 result = new SedimentLoadResult( |
279 this.epoch[i][0], | 279 this.epoch[i][0], |
280 this.epoch[i][1], | 280 this.epoch[i][1], |
281 slu); | 281 slu); |
282 } | 282 } |
294 * Fetch loads for a single year, calculate total and | 294 * Fetch loads for a single year, calculate total and |
295 * return the result containing both. | 295 * return the result containing both. |
296 * @param y year, e.g. 1980 | 296 * @param y year, e.g. 1980 |
297 */ | 297 */ |
298 private SedimentLoadResult calculateYear(int y) { | 298 private SedimentLoadResult calculateYear(int y) { |
299 SedimentLoad load = SedimentLoadFactory.getLoadWithData( | 299 SedimentLoadLSData load = SedimentLoadFactory.getLoadWithData( |
300 this.river, | 300 this.river, |
301 this.yearEpoch, | 301 this.yearEpoch, |
302 this.kmLow, | 302 this.kmLow, |
303 this.kmUp, | 303 this.kmUp, |
304 y, | 304 y, |
305 y); | 305 y); |
306 | 306 |
307 SedimentLoadResult result; | 307 SedimentLoadResult result; |
308 SedimentLoad sl = calculateTotalLoad(load, y); | 308 SedimentLoadLSData sl = calculateTotalLoad(load, y); |
309 if (unit.equals("m3_per_a")) { | 309 if (unit.equals("m3_per_a")) { |
310 SedimentLoad slu = calculateUnit(sl, y); | 310 SedimentLoadLSData slu = calculateUnit(sl, y); |
311 result = new SedimentLoadResult(y, 0, slu); | 311 result = new SedimentLoadResult(y, 0, slu); |
312 } | 312 } |
313 else { | 313 else { |
314 result = new SedimentLoadResult(y, 0, sl); | 314 result = new SedimentLoadResult(y, 0, sl); |
315 } | 315 } |
316 return result; | 316 return result; |
317 } | 317 } |
318 | 318 |
319 /** Add up the loads of a year. */ | 319 /** Add up the loads of a year. */ |
320 private SedimentLoad calculateTotalLoad(SedimentLoad load, int year) { | 320 private SedimentLoadLSData calculateTotalLoad(SedimentLoadLSData load, int year) { |
321 logger.debug("calculateTotalLoad"); | 321 logger.debug("calculateTotalLoad"); |
322 boolean problemThisYear = false; | 322 boolean problemThisYear = false; |
323 if (!load.hasCoarse()) { | 323 if (!load.hasCoarse()) { |
324 addProblem("missing.fraction.coarse", Integer.toString(year)); | 324 addProblem("missing.fraction.coarse", Integer.toString(year)); |
325 problemThisYear = true; | 325 problemThisYear = true; |
359 * where the km-ranges did not completely match. | 359 * where the km-ranges did not completely match. |
360 * | 360 * |
361 * @param load SedimentLoad to add total values (and ranges) to. | 361 * @param load SedimentLoad to add total values (and ranges) to. |
362 * @return input param load, with total values set. | 362 * @return input param load, with total values set. |
363 */ | 363 */ |
364 private SedimentLoad partialTotal(SedimentLoad load) { | 364 private SedimentLoadLSData partialTotal(SedimentLoadLSData load) { |
365 // The load with balanced ranges, will be returned. | 365 // The load with balanced ranges, will be returned. |
366 SedimentLoad fairLoad = load; | 366 SedimentLoadLSData fairLoad = load; |
367 | 367 |
368 Range lastOtherRange = null; | 368 Range lastOtherRange = null; |
369 double lastOtherValue = 0d; | 369 double lastOtherValue = 0d; |
370 | 370 |
371 Range lastSuspRange = null; | 371 Range lastSuspRange = null; |
519 * @param load The load of which values should be transformed. | 519 * @param load The load of which values should be transformed. |
520 * @param year The year at which to look at density (e.g. 2003). | 520 * @param year The year at which to look at density (e.g. 2003). |
521 * | 521 * |
522 * @return parameter load with transformed values. | 522 * @return parameter load with transformed values. |
523 */ | 523 */ |
524 private SedimentLoad calculateUnit(SedimentLoad load, int year) { | 524 private SedimentLoadLSData calculateUnit(SedimentLoadLSData load, int year) { |
525 SedimentDensity density = | 525 SedimentDensity density = |
526 SedimentDensityFactory.getSedimentDensity(river, kmLow, kmUp, year); | 526 SedimentDensityFactory.getSedimentDensity(river, kmLow, kmUp, year); |
527 | 527 |
528 for (double km: load.getKms()) { | 528 for (double km: load.getKms()) { |
529 double dens = 1d/density.getDensity(km, year); | 529 double dens = 1d/density.getDensity(km, year); |