view flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/minfo/BedDiffEpochFilterFacet.java @ 5645:696d710470f5

flys/issue1077: Show loads as step line, therefore transform data in SedimentLoadFacet to stretch as in the measurement stations bounds. Deal with this new kind of data in the Generator.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 10 Apr 2013 09:35:07 +0200
parents 12e3da5724e6
children
line wrap: on
line source
package de.intevation.flys.artifacts.model.minfo;

import org.apache.log4j.Logger;

import de.intevation.artifactdatabase.state.Facet;
import de.intevation.artifacts.Artifact;
import de.intevation.artifacts.CallContext;
import de.intevation.flys.artifacts.FLYSArtifact;
import de.intevation.flys.artifacts.access.RiverAccess;
import de.intevation.flys.artifacts.context.FLYSContext;
import de.intevation.flys.artifacts.model.CalculationResult;
import de.intevation.flys.artifacts.model.DataFacet;
import de.intevation.flys.artifacts.math.MovingAverage;
import de.intevation.flys.artifacts.model.ZoomScale;
import de.intevation.flys.artifacts.states.DefaultState.ComputeType;


public class BedDiffEpochFilterFacet
extends DataFacet
{
    private static Logger logger = Logger.getLogger(BedDensityFacet.class);

    public BedDiffEpochFilterFacet() {
    }

    public BedDiffEpochFilterFacet(int idx, String name, String description,
        ComputeType type, String stateId, String hash) {
        super(idx, name, description, type, hash, stateId);
    }

    public Object getData(Artifact artifact, CallContext context) {
        logger.debug("Get data for bed density at index: " + index);

        FLYSArtifact flys = (FLYSArtifact) artifact;

        CalculationResult res = (CalculationResult) flys.compute(context, hash,
            stateId, type, false);

        BedDiffEpochResult[] data =
            (BedDiffEpochResult[]) res.getData(); // TODO CAST TO SPECIFIC CLASS
        Double start = (Double)context.getContextValue("startkm");
        Double end = (Double)context.getContextValue("endkm");

        if(start != null && end != null) {
            FLYSContext fc = (FLYSContext)context.globalContext();
            ZoomScale scales = (ZoomScale)fc.get("zoomscale");
            RiverAccess access = new RiverAccess((FLYSArtifact)artifact);
            String river = access.getRiver();

            double radius = scales.getRadius(river, start, end);
            BedDiffEpochResult oldData = data[index];
            BedDiffEpochResult newData = new BedDiffEpochResult();
            newData.setStart(oldData.getStart());
            newData.setEnd(oldData.getEnd());
            double[][] diffs = MovingAverage.weighted(oldData.getDifferencesData(), radius);
            double[][] heights1 = MovingAverage.weighted(oldData.getHeights1Data(), radius);
            double[][] heights2 = MovingAverage.weighted(oldData.getHeights2Data(), radius);
            for(int j = 0; j < diffs[0].length; j++) {
                newData.addKm(diffs[0][j]);
                newData.addDifference(diffs[1][j]);
                newData.addHeight1(heights1[1][j]);
                newData.addHeight2(heights2[1][j]);
            }
            return newData;
        }
        return data != null && data.length > index ? data[index] : null;
    }

    /** Copy deeply. */
    @Override
    public Facet deepCopy() {
        BedDiffEpochFilterFacet copy = new BedDiffEpochFilterFacet();
        copy.set(this);
        copy.type = type;
        copy.hash = hash;
        copy.stateId = stateId;
        return copy;
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org