Mercurial > dive4elements > river
changeset 8066:fe5ef780f8b1
Sediment load: fetch sediment density for transforming t/a to m^3/a.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Wed, 30 Jul 2014 19:26:20 +0200 |
parents | fdb26fe898dc |
children | 6d24ba2ac964 |
files | artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataCalculation.java |
diffstat | 1 files changed, 32 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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,