view artifacts/src/main/java/org/dive4elements/river/artifacts/model/Calculation3.java @ 9534:b380a5693514

Calculation of Dauerlinie corrected in WInfo (fix wst position according to a reference gauge, km specific discharge instead of that of the gauge); using same calculation in SInfo flood duration
author mschaefer
date Thu, 11 Oct 2018 18:39:21 +0200
parents e4606eae8ea5
children
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;

import org.apache.log4j.Logger;
import org.dive4elements.river.artifacts.model.WstValueTable.QPosition;

/**
 * Duration curve calculation of a km based on the duration curve of a gauge
 */
public class Calculation3
extends      Calculation
{
    private static Logger log = Logger.getLogger(Calculation3.class);

    protected double    km;
    protected int    [] days;
    protected double [] qs;
    private double gaugeKm;

    public Calculation3() {
    }

    public Calculation3(final double km, final int[] days, final double[] qs, final double gaugeKm) {
        this.km   = km;
        this.days = days;
        this.qs   = qs;
        this.gaugeKm = gaugeKm;
    }

    /**
     * Calculates the W and Q duration curve of the active km
     */
    public CalculationResult calculate(final WstValueTable wst) {

        if (this.days == null || this.days.length == 0) {
            addProblem(this.km, "cannot.find.ds");
        }

        final double[] ws = new double[this.days.length];
        final double[] kmqs = new double[this.days.length];
        for (int i = 0; i <= this.days.length - 1; i++) {
            final QPosition qpos = wst.getQPosition(this.gaugeKm, this.qs[i]);
            if (qpos != null) {
                ws[i] = wst.interpolateW(this.km, qpos);
                kmqs[i] = wst.getQ(qpos, this.km);
            }
            else {
                addProblem(this.km, "cannot.find.q", this.qs[i]);
                ws[i] = Double.NaN;
            }
        }

        if (log.isDebugEnabled()) {
            log.debug("Calculate duration curve data:");
            log.debug("    km       : " + this.km);
            log.debug("    num Days : " + (this.days != null ? this.days.length : 0));
            log.debug("    num Qs   : " + (this.qs != null ? this.qs.length : 0));
            log.debug("    result Ws: " + (ws != null ? ws.length : 0));
        }

        final WQDay wqday = new WQDay(this.days, ws, kmqs);

        if (hasProblems()) {
            log.debug("calculation caused "+numProblems()+" problem(s).");
            wqday.removeNaNs();
        }

        return new CalculationResult(wqday, this);
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org