Mercurial > dive4elements > river
view artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedQualityResultValue.java @ 8587:07c9ac22f611
(issue1755) Generalise BedQuality result handling
The bedquality calculation now produces a result for each time period
which has BedQualityResultValues for each specific result type.
Formally this was split up in density, porosity and diameter classes
with some bedload diameter classes mixed in for extra fun.
The intent of this commit is to allow more shared code and generic
access patterns to the BedQuality results.
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Wed, 18 Mar 2015 18:42:08 +0100 |
parents | |
children | 3c78fc83fc6d |
line wrap: on
line source
/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde * Software engineering by Intevation GmbH * * This file is Free Software under the GNU AGPL (>=v3) * and comes with ABSOLUTELY NO WARRANTY! Check out the * documentation coming with Dive4Elements River for details. */ package org.dive4elements.river.artifacts.model.minfo; import org.dive4elements.river.utils.DoubleUtil; import org.apache.commons.math.analysis.polynomials.PolynomialSplineFunction; import org.apache.commons.math.ArgumentOutsideDomainException; import java.util.Arrays; import java.util.Set; import java.util.HashSet; import java.io.Serializable; /** Holder of a specific result from the bed quality calculation. * * Data is always a map of km to value. The type "bedload" * translates to german "Geschiebe" other results are either * specific to the top or the sublayer of the riverbed. * * The name can be the diameter of this result for bed and bedload * data. **/ public class BedQualityResultValue implements Serializable { public static final String[] DIAMETER_NAMES = new String[] { "D90", "D84", "D80", "D75", "D70", "D60", "D50", "D40", "D30", "D25", "D20", "D16", "D10", "DM", "DMIN", "DMAX" }; /* For ease of access */ public static final Set<String> DIAMETER_NAME_SET = new HashSet<String>( Arrays.asList(DIAMETER_NAMES)); private String name; private String type; private double [][] data; private transient PolynomialSplineFunction interpolFunc; public BedQualityResultValue() { } public BedQualityResultValue(String name, double [][] data, String type) { this.name = name; setData(data); this.type = type; } public String getName() { return name; } public void setName(String name) { this.name = name; } public double [][] getData() { return data; } public double getData(double x) { int idx = Arrays.binarySearch(data[0], x); if (idx < 0) { return Double.NaN; } else { return data[1][idx]; } } public double getDataInterpolated(double x) { if (interpolFunc == null) { interpolFunc = DoubleUtil.getLinearInterpolator(data[0], data[1]); } try { return interpolFunc.value(x); } catch (ArgumentOutsideDomainException e) { return getData(x); } } public double [][] getDataInterpolated(double[] x) { double y[] = new double[x.length]; int i = 0; for (double point: x) { y[i++] = getDataInterpolated(point); } return new double[][] {x, y}; } public void setData(double [][] data) { this.data = data; } public void setType(String type) { this.type = type; } public String getType() { return type; } /** Checks wether or not the name matches that of a diameter */ public boolean isDiameterResult() { return DIAMETER_NAME_SET.contains(name.toUpperCase()); } }