view artifacts/src/main/java/org/dive4elements/river/artifacts/model/WQDay.java @ 7300:83bb52fa0c32

(issue1529) Be more tolerant in the fitting. The invalid value warning is removed because invalid data is expected there when datapoints are not valid for this KM
author Andre Heinecke <aheinecke@intevation.de>
date Fri, 11 Oct 2013 18:40:33 +0200
parents af13ceeba52a
children 8b614d152a79
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 gnu.trove.TIntArrayList;

/**
 * This class represents a pool of data triples that consists of 'W', 'Q' and
 * 'Day' data.
 *
 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
 */
public class WQDay
extends      WQ
{
    protected TIntArrayList days;

    public WQDay() {
        super("");
        days = new TIntArrayList();
    }

    public WQDay(int capacity) {
        super(capacity);
        days = new TIntArrayList(capacity);
    }

    public WQDay(int [] days, double [] ws, double [] qs) {
        super(qs, ws, "");
        this.days = new TIntArrayList(days);
    }


    public void add(int day, double w, double q) {
        super.add(w, q);
        days.add(day);
    }


    public boolean isIncreasing() {
        int lo = getDay(0);
        int hi = getDay(size()-1);

        return lo < hi;
    }


    public int getDay(int idx) {
        return days.getQuick(idx);
    }

    @Override
    public void removeNaNs() {

        int dest = 0;
        int N = ws.size();

        for (int i = 0; i < N; ++i) {
            double wi = ws.getQuick(i);
            double qi = qs.getQuick(i);

            if (Double.isNaN(wi) || Double.isNaN(qi)) {
                continue;
            }

            days.setQuick(dest, days.getQuick(i));
            ws.setQuick(dest, wi);
            qs.setQuick(dest, qi);
            ++dest;
        }

        if (dest < N) {
            days.remove(dest, N-dest);
            ws  .remove(dest, N-dest);
            qs  .remove(dest, N-dest);
        }
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org