[PATCH] Sediment load: fetch sediment density for transforming t/a to m^3/a

Wald Commits scm-commit at wald.intevation.org
Wed Jul 30 19:26:24 CEST 2014


# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1406741180 -7200
# Node ID fe5ef780f8b1934175bc9bb6a7973c770d71c644
# Parent  fdb26fe898dc6f09c204b129902d96f78eef6221
Sediment load: fetch sediment density for transforming t/a to m^3/a.

diff -r fdb26fe898dc -r fe5ef780f8b1 artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataCalculation.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataCalculation.java	Wed Jul 30 19:06:35 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataCalculation.java	Wed Jul 30 19:26:20 2014 +0200
@@ -254,6 +254,8 @@
 
         Sum sum = new Sum();
 
+        SedimentDensity sd = getSedimentDensity();
+
         for (int year: years) {
             Value.Filter filter = new And()
                 .add(notEpochs)
@@ -270,9 +272,12 @@
                         gf.getDescription());
                     continue;
                 }
-                // TODO: Optionally transform units.
+
+                transformT2M3(sd, year, result);
+
                 SedimentLoadDataResult.Fraction sldrf =
                     new SedimentLoadDataResult.Fraction(gf.getDescription(), result);
+
                 sldr.addFraction(sldrf);
             }
         }
@@ -280,6 +285,7 @@
         return new CalculationResult(sldr, this);
     }
 
+
     private CalculationResult calculateEpochs() {
         SedimentLoadData sld =
             SedimentLoadDataFactory.INSTANCE.getSedimentLoadData(river);
@@ -375,6 +381,31 @@
         return r.getKmUp();
     }
 
+    private final boolean inM3() {
+        return unit.equals("m3_per_a");
+    }
+
+    private SedimentDensity getSedimentDensity() {
+        return inM3()
+            ? SedimentDensityFactory.getSedimentDensity(river, from, to)
+            : null;
+    }
+
+    private static void transformT2M3(SedimentDensity sd, int year, double [][] data) {
+        if (sd == null) {
+            return;
+        }
+        double [] kms = data[0];
+        double [] values = data[1];
+        for (int i = 0; i < kms.length; ++i) {
+            if (Double.isNaN(kms[i]) || Double.isNaN(kms[i])) {
+                continue;
+            }
+            double density = sd.getDensity(kms[i], year);
+            values[i] /= density;
+        }
+    }
+
     public double[][] sum(
         SedimentLoadData sld,
         int []           grainFractions,


More information about the Dive4Elements-commits mailing list