comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/minfo/SedimentLoadCalculation.java @ 4522:a9753f717b3d

Completed and fixed sediment load calculation. * Now calculates with units. * Adds problems to error report. * Correctly calculates total loads.
author Raimund Renkert <rrenkert@intevation.de>
date Wed, 14 Nov 2012 17:18:44 +0100
parents cc6323401643
children e357716cf346
comparison
equal deleted inserted replaced
4521:71e6fe870c1d 4522:a9753f717b3d
1 package de.intevation.flys.artifacts.model.minfo; 1 package de.intevation.flys.artifacts.model.minfo;
2 2
3 import gnu.trove.TDoubleArrayList; 3 import gnu.trove.TDoubleArrayList;
4 4
5 import java.util.ArrayList; 5 import java.util.ArrayList;
6 import java.util.Iterator;
7 import java.util.List; 6 import java.util.List;
8 import java.util.Set;
9 7
10 import org.apache.log4j.Logger; 8 import org.apache.log4j.Logger;
11 import org.jfree.util.Log;
12 9
13 import de.intevation.flys.artifacts.access.SedimentLoadAccess; 10 import de.intevation.flys.artifacts.access.SedimentLoadAccess;
14 import de.intevation.flys.artifacts.model.Calculation; 11 import de.intevation.flys.artifacts.model.Calculation;
15 import de.intevation.flys.artifacts.model.CalculationResult; 12 import de.intevation.flys.artifacts.model.CalculationResult;
16 13
47 double kmLow = access.getLowerKM(); 44 double kmLow = access.getLowerKM();
48 if (yearEpoch.equals("year")) { 45 if (yearEpoch.equals("year")) {
49 period = access.getPeriod(); 46 period = access.getPeriod();
50 epoch = null; 47 epoch = null;
51 } 48 }
52 else if (yearEpoch.equals("epoch")) { 49 else if (yearEpoch.equals("epoch") || yearEpoch.equals("off_epoch")) {
53 epoch = access.getEpochs(); 50 epoch = access.getEpochs();
54 period = null; 51 period = null;
55 } 52 }
56 else { 53 else {
57 addProblem("minfo.missing.year_epoch"); 54 addProblem("minfo.missing.year_epoch");
163 double s = resLoad.getFraction(km).getSand(); 160 double s = resLoad.getFraction(km).getSand();
164 resLoad.setSand(km, s + f.getSand()); 161 resLoad.setSand(km, s + f.getSand());
165 sSum++; 162 sSum++;
166 } 163 }
167 if (f.getSusp_sand() > 0d) { 164 if (f.getSusp_sand() > 0d) {
168 double s = resLoad.getFraction(km).getSand(); 165 double s = resLoad.getFraction(km).getSusp_sand();
169 resLoad.setSuspSand(km, s + f.getSusp_sand()); 166 resLoad.setSuspSand(km, s + f.getSusp_sand());
170 ssSum++; 167 ssSum++;
171 } 168 }
172 if (f.getSusp_sand_bed() > 0d) { 169 if (f.getSusp_sand_bed() > 0d) {
173 double s = resLoad.getFraction(km).getSusp_sand_bed(); 170 double s = resLoad.getFraction(km).getSusp_sand_bed();
189 resLoad.setSuspSediment(km, fr.getSusp_sediment()/sseSum); 186 resLoad.setSuspSediment(km, fr.getSusp_sediment()/sseSum);
190 } 187 }
191 resLoad.setDescription(""); 188 resLoad.setDescription("");
192 resLoad.setEpoch(true); 189 resLoad.setEpoch(true);
193 190
194 SedimentLoad sl = calculateTotalLoad(resLoad); 191 SedimentLoadResult result;
195 return new SedimentLoadResult(epoch[i][0], epoch[i][1], sl); 192 SedimentLoad sl = calculateTotalLoad(resLoad, this.epoch[i][0]);
193 if (this.unit.equals("m3_per_a")) {
194 SedimentLoad slu = calculateUnit(sl, this.epoch[i][0]);
195 result = new SedimentLoadResult(
196 this.epoch[i][0],
197 this.epoch[i][1],
198 slu);
199 }
200 else {
201 result = new SedimentLoadResult(
202 this.epoch[i][0],
203 this.epoch[i][1],
204 sl);
205 }
206
207 return result;
196 } 208 }
197 209
198 private SedimentLoadResult calculateOffEpoch(int i) { 210 private SedimentLoadResult calculateOffEpoch(int i) {
199 return null; 211 SedimentLoad load = SedimentLoadFactory.getLoadwithData(
212 this.river,
213 this.yearEpoch,
214 kmLow,
215 kmUp,
216 this.epoch[i][0],
217 this.epoch[i][1]);
218 SedimentLoadResult result;
219 SedimentLoad sl = calculateTotalLoad(load, this.epoch[i][0]);
220 if (unit.equals("m3_per_a")) {
221 SedimentLoad slu = calculateUnit(sl, epoch[i][0]);
222 result = new SedimentLoadResult(
223 this.epoch[i][0],
224 this.epoch[i][1],
225 slu);
226 }
227 else {
228 result = new SedimentLoadResult(
229 this.epoch[i][0],
230 this.epoch[i][1],
231 sl);
232 }
233
234 return result;
200 } 235 }
201 236
202 private SedimentLoadResult calculateYear(int y) { 237 private SedimentLoadResult calculateYear(int y) {
203 SedimentLoad load = SedimentLoadFactory.getLoadwithData( 238 SedimentLoad load = SedimentLoadFactory.getLoadwithData(
204 this.river, 239 this.river,
206 this.kmLow, 241 this.kmLow,
207 this.kmUp, 242 this.kmUp,
208 y, 243 y,
209 y); 244 y);
210 245
211 SedimentLoad sl = calculateTotalLoad(load); 246 SedimentLoadResult result;
247 SedimentLoad sl = calculateTotalLoad(load, y);
212 if (unit.equals("m3_per_a")) { 248 if (unit.equals("m3_per_a")) {
213 SedimentLoad slu = calculateUnit(sl); 249 SedimentLoad slu = calculateUnit(sl, y);
214 } 250 result = new SedimentLoadResult(y, 0, slu);
215 251 }
216 SedimentLoadResult result = new SedimentLoadResult( 252 else {
217 y, 253 result = new SedimentLoadResult(y, 0, sl);
218 0, 254 }
219 sl);
220 return result; 255 return result;
221 } 256 }
222 257
223 private SedimentLoad validateData(SedimentLoad load) { 258 private SedimentLoad calculateTotalLoad(SedimentLoad load, int year) {
224 SedimentLoad clean = new SedimentLoad(); 259 logger.debug("calculateTotalLoad");
225 Set<Double> kms = load.getKms(); 260 if (!load.hasCoarse()) {
226 for (double km : kms) { 261 addProblem("missing.fraction.coarse" + " " + year);
262 }
263 if (!load.hasFineMiddle()) {
264 addProblem("missing.fraction.fine_middle" + " " + year);
265 }
266 if (!load.hasSand()) {
267 addProblem("missing.fraction.sand" + " " + year);
268 }
269 if (!load.hasSuspSand()) {
270 addProblem("missing.fraction.susp_sand" + " " + year);
271 }
272 if (!load.hasSuspSediment()) {
273 addProblem("missing.fraction.susp_sediment" + " " + year);
274 }
275 if (hasProblems()) {
276 return load;
277 }
278 for(double km : load.getKms()) {
279 logger.debug("total at km " + km);
227 SedimentLoadFraction fraction = load.getFraction(km); 280 SedimentLoadFraction fraction = load.getFraction(km);
228 if (fraction.getCoarse() > 0 && 281 double total = 0d;
229 fraction.getFine_middle() > 0 && 282 if ((fraction.getCoarse() <= 0d && load.hasCoarse())){
230 fraction.getSand() > 0 && 283 addProblem(km, "missing.data.coarse");
231 fraction.getSusp_sand() > 0&& 284 continue;
232 fraction.getSusp_sand_bed() > 0 && 285 }
233 fraction.getSusp_sediment() > 0) { 286 if (fraction.getFine_middle() <= 0d && load.hasFineMiddle()) {
234 clean.addKm(km, fraction); 287 addProblem(km, "missing.data.fine_middle");
235 } 288 continue;
236 } 289 }
237 return clean; 290 if (fraction.getSand() <= 0d && load.hasSand()) {
238 } 291 addProblem(km, "missing data.sand");
239 292 continue;
240 private SedimentLoad calculateTotalLoad(SedimentLoad load) { 293 }
241 Log.debug("calculateTotalLoad"); 294 if (fraction.getSusp_sand() <= 0d && load.hasSuspSand()) {
242 SedimentLoad clean = validateData(load); 295 addProblem(km, "missing.data.susp_sand");
243 if (clean.getKms().size() > 0) { 296 continue;
244 Iterator<Double> iter = clean.getKms().iterator(); 297 }
245 while (iter.hasNext()) { 298 if (fraction.getSusp_sediment() <= 0d && load.hasSuspSediment()) {
246 double km = iter.next(); 299 addProblem(km, "missing.data.susp_sediment");
247 SedimentLoadFraction f =clean.getFraction(km); 300 continue;
248 double total = f.getCoarse() + 301 }
249 f.getFine_middle() + 302 total += fraction.getCoarse() +
250 f.getSand() + 303 fraction.getFine_middle() +
251 f.getSusp_sand() + 304 fraction.getSand() +
252 f.getSusp_sediment(); 305 fraction.getSusp_sand() +
253 load.setTotal(km, total); 306 fraction.getSusp_sediment();
254 } 307 load.setTotal(km, total);
255 } 308 }
256 return load; 309 return load;
257 } 310 }
258 311
259 private SedimentLoad calculateUnit(SedimentLoad load) { 312 private SedimentLoad calculateUnit(SedimentLoad load, int year) {
260 //TODO implement me! 313 SedimentDensity density =
314 SedimentDensityFactory.getSedimentDensity(river, kmLow, kmUp, year);
315 for (double km: load.getKms()) {
316 double dens = density.getDensity(km, year);
317 logger.debug("factor: " + dens);
318 SedimentLoadFraction fraction = load.getFraction(km);
319 double coarse = fraction.getCoarse();
320 double fineMiddle = fraction.getFine_middle();
321 double sand = fraction.getSand();
322 double suspSand = fraction.getSusp_sand();
323 double bedSand = fraction.getSusp_sand_bed();
324 double sediment = fraction.getSusp_sediment();
325 double total = fraction.getTotal();
326 logger.debug("orig: " + coarse);
327 load.setCoarse(km, (coarse * dens));
328 load.setFineMiddle(km, (fineMiddle * dens));
329 load.setSand(km, (sand * dens));
330 load.setSuspSand(km, (suspSand * dens));
331 load.setSuspSandBed(km, (bedSand * dens));
332 load.setSuspSediment(km, (sediment * dens));
333 load.setTotal(km, (total * dens));
334 logger.debug("m3/a: " + load.getFraction(km).getCoarse());
335 }
261 return load; 336 return load;
262 } 337 }
263 } 338 }
264 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : 339 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org