[Dive4elements-commits] [PATCH 11 of 13] Completed and fixed sediment load calculation

Wald Commits scm-commit at wald.intevation.org
Wed Nov 14 17:26:37 CET 2012


# HG changeset patch
# User Raimund Renkert <rrenkert at intevation.de>
# Date 1352909924 -3600
# Node ID a9753f717b3dd27dc91118867129612f135a5f0f
# Parent  71e6fe870c1dac0e00be148d679cf748401e6021
Completed and fixed sediment load calculation.

* Now calculates with units.
* Adds problems to error report.
* Correctly calculates total loads.

diff -r 71e6fe870c1d -r a9753f717b3d flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/minfo/SedimentLoadCalculation.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/minfo/SedimentLoadCalculation.java	Wed Nov 14 17:17:02 2012 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/minfo/SedimentLoadCalculation.java	Wed Nov 14 17:18:44 2012 +0100
@@ -3,12 +3,9 @@
 import gnu.trove.TDoubleArrayList;
 
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
-import java.util.Set;
 
 import org.apache.log4j.Logger;
-import org.jfree.util.Log;
 
 import de.intevation.flys.artifacts.access.SedimentLoadAccess;
 import de.intevation.flys.artifacts.model.Calculation;
@@ -49,7 +46,7 @@
             period = access.getPeriod();
             epoch = null;
         }
-        else if (yearEpoch.equals("epoch")) {
+        else if (yearEpoch.equals("epoch") || yearEpoch.equals("off_epoch")) {
             epoch = access.getEpochs();
             period = null;
         }
@@ -165,7 +162,7 @@
                     sSum++;
                 }
                 if (f.getSusp_sand() > 0d) {
-                    double s = resLoad.getFraction(km).getSand();
+                    double s = resLoad.getFraction(km).getSusp_sand();
                     resLoad.setSuspSand(km, s + f.getSusp_sand());
                     ssSum++;
                 }
@@ -191,12 +188,50 @@
         resLoad.setDescription("");
         resLoad.setEpoch(true);
 
-        SedimentLoad sl = calculateTotalLoad(resLoad);
-        return new SedimentLoadResult(epoch[i][0], epoch[i][1], sl);
+        SedimentLoadResult result;
+        SedimentLoad sl = calculateTotalLoad(resLoad, this.epoch[i][0]);
+        if (this.unit.equals("m3_per_a")) {
+            SedimentLoad slu = calculateUnit(sl, this.epoch[i][0]);
+            result = new SedimentLoadResult(
+                this.epoch[i][0],
+                this.epoch[i][1],
+                slu);
+        }
+        else {
+            result = new SedimentLoadResult(
+                this.epoch[i][0],
+                this.epoch[i][1],
+                sl);
+        }
+
+        return result;
     }
 
     private SedimentLoadResult calculateOffEpoch(int i) {
-        return null;
+        SedimentLoad load = SedimentLoadFactory.getLoadwithData(
+            this.river,
+            this.yearEpoch,
+            kmLow,
+            kmUp,
+            this.epoch[i][0],
+            this.epoch[i][1]);
+        SedimentLoadResult result;
+        SedimentLoad sl = calculateTotalLoad(load, this.epoch[i][0]);
+        if (unit.equals("m3_per_a")) {
+            SedimentLoad slu = calculateUnit(sl, epoch[i][0]);
+            result = new SedimentLoadResult(
+                this.epoch[i][0],
+                this.epoch[i][1],
+                slu);
+        }
+        else {
+            result = new SedimentLoadResult(
+                this.epoch[i][0],
+                this.epoch[i][1],
+                sl);
+        }
+
+        return result;
     }
 
     private SedimentLoadResult calculateYear(int y) {
@@ -208,56 +243,96 @@
             y,
             y);
 
-        SedimentLoad sl = calculateTotalLoad(load);
+        SedimentLoadResult result;
+        SedimentLoad sl = calculateTotalLoad(load, y);
         if (unit.equals("m3_per_a")) {
-            SedimentLoad slu = calculateUnit(sl);
+            SedimentLoad slu = calculateUnit(sl, y);
+            result = new SedimentLoadResult(y, 0, slu);
         }
-
-        SedimentLoadResult result = new SedimentLoadResult(
-            y,
-            0,
-            sl);
+        else {
+            result = new SedimentLoadResult(y, 0, sl);
+        }
         return result;
     }
 
-    private SedimentLoad validateData(SedimentLoad load) {
-        SedimentLoad clean = new SedimentLoad();
-        Set<Double> kms = load.getKms();
-        for (double km : kms) {
+    private SedimentLoad calculateTotalLoad(SedimentLoad load, int year) {
+        logger.debug("calculateTotalLoad");
+        if (!load.hasCoarse()) {
+            addProblem("missing.fraction.coarse" + " " + year);
+        }
+        if (!load.hasFineMiddle()) {
+            addProblem("missing.fraction.fine_middle" + " " + year);
+        }
+        if (!load.hasSand()) {
+            addProblem("missing.fraction.sand" + " " + year);
+        }
+        if (!load.hasSuspSand()) {
+            addProblem("missing.fraction.susp_sand" + " " + year);
+        }
+        if (!load.hasSuspSediment()) {
+            addProblem("missing.fraction.susp_sediment" + " " + year);
+        }
+        if (hasProblems()) {
+            return load;
+        }
+        for(double km : load.getKms()) {
+            logger.debug("total at km " + km);
             SedimentLoadFraction fraction = load.getFraction(km);
-            if (fraction.getCoarse() > 0 &&
-                fraction.getFine_middle() > 0 &&
-                fraction.getSand() > 0 &&
-                fraction.getSusp_sand() > 0&&
-                fraction.getSusp_sand_bed() > 0 &&
-                fraction.getSusp_sediment() > 0) {
-                clean.addKm(km, fraction);
+            double total = 0d;
+            if ((fraction.getCoarse() <= 0d && load.hasCoarse())){
+                addProblem(km, "missing.data.coarse");
+                continue;
             }
-        }
-        return clean;
-    }
-
-    private SedimentLoad calculateTotalLoad(SedimentLoad load) {
-        Log.debug("calculateTotalLoad");
-        SedimentLoad clean = validateData(load);
-        if (clean.getKms().size() > 0) {
-            Iterator<Double> iter = clean.getKms().iterator();
-            while (iter.hasNext()) {
-                double km = iter.next();
-                SedimentLoadFraction f =clean.getFraction(km);
-                double total = f.getCoarse() +
-                    f.getFine_middle() +
-                    f.getSand() +
-                    f.getSusp_sand() +
-                    f.getSusp_sediment();
-                load.setTotal(km, total);
+            if (fraction.getFine_middle() <= 0d && load.hasFineMiddle()) {
+                addProblem(km, "missing.data.fine_middle");
+                continue;
             }
+            if (fraction.getSand() <= 0d && load.hasSand()) {
+                addProblem(km, "missing data.sand");
+                continue;
+            }
+            if (fraction.getSusp_sand() <= 0d && load.hasSuspSand()) {
+                addProblem(km, "missing.data.susp_sand");
+                continue;
+            }
+            if (fraction.getSusp_sediment() <= 0d && load.hasSuspSediment()) {
+                addProblem(km, "missing.data.susp_sediment");
+                continue;
+            }
+            total += fraction.getCoarse() +
+                fraction.getFine_middle() +
+                fraction.getSand() +
+                fraction.getSusp_sand() +
+                fraction.getSusp_sediment();
+            load.setTotal(km, total);
         }
         return load;
     }
 
-    private SedimentLoad calculateUnit(SedimentLoad load) {
-        //TODO implement me!
+    private SedimentLoad calculateUnit(SedimentLoad load, int year) {
+        SedimentDensity density =
+            SedimentDensityFactory.getSedimentDensity(river, kmLow, kmUp, year);
+        for (double km: load.getKms()) {
+            double dens = density.getDensity(km, year);
+            logger.debug("factor: " + dens);
+            SedimentLoadFraction fraction = load.getFraction(km);
+            double coarse = fraction.getCoarse();
+            double fineMiddle = fraction.getFine_middle();
+            double sand = fraction.getSand();
+            double suspSand = fraction.getSusp_sand();
+            double bedSand = fraction.getSusp_sand_bed();
+            double sediment = fraction.getSusp_sediment();
+            double total = fraction.getTotal();
+            logger.debug("orig: " + coarse);
+            load.setCoarse(km, (coarse * dens));
+            load.setFineMiddle(km, (fineMiddle * dens));
+            load.setSand(km, (sand * dens));
+            load.setSuspSand(km, (suspSand * dens));
+            load.setSuspSandBed(km, (bedSand * dens));
+            load.setSuspSediment(km, (sediment * dens));
+            load.setTotal(km, (total * dens));
+            logger.debug("m3/a: " + load.getFraction(km).getCoarse());
+        }
         return load;
     }
 }


More information about the Dive4elements-commits mailing list