teichmann@5863: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
teichmann@5863: * Software engineering by Intevation GmbH
teichmann@5863: *
teichmann@5994: * This file is Free Software under the GNU AGPL (>=v3)
teichmann@5863: * and comes with ABSOLUTELY NO WARRANTY! Check out the
teichmann@5994: * documentation coming with Dive4Elements River for details.
teichmann@5863: */
teichmann@5863:
teichmann@5831: package org.dive4elements.river.artifacts.model.fixings;
raimund@3169:
teichmann@5831: import org.dive4elements.artifacts.Artifact;
teichmann@5831: import org.dive4elements.artifacts.CallContext;
sascha@3203:
teichmann@5867: import org.dive4elements.river.artifacts.D4EArtifact;
raimund@3169:
teichmann@5831: import org.dive4elements.river.artifacts.model.CalculationResult;
teichmann@5831: import org.dive4elements.river.artifacts.model.DataFacet;
teichmann@5831: import org.dive4elements.river.artifacts.model.FacetTypes;
teichmann@5831: import org.dive4elements.river.artifacts.model.Parameters;
teichmann@5831:
teichmann@5831: import org.dive4elements.river.artifacts.states.DefaultState.ComputeType;
teichmann@5831:
teichmann@5831: import org.dive4elements.river.utils.KMIndex;
raimund@3169:
tom@9726: import org.apache.logging.log4j.Logger;
tom@9726: import org.apache.logging.log4j.LogManager;
raimund@3169:
raimund@3169: /**
raimund@3169: * Facet to show average W values for Q sectors.
raimund@3169: *
raimund@3169: * @author Raimund Renkert
raimund@3169: */
raimund@3169: public class FixLongitudinalDeviationFacet
raimund@3169: extends DataFacet
raimund@3169: implements FacetTypes {
raimund@3169:
teichmann@8202: /** House log. */
tom@9726: private static Logger log = LogManager.getLogger(
tom@8856: FixLongitudinalDeviationFacet.class);
raimund@3169:
raimund@3169: /** Trivial Constructor. */
raimund@3169: public FixLongitudinalDeviationFacet() {
raimund@3169: }
raimund@3169:
raimund@3169:
raimund@3169: public FixLongitudinalDeviationFacet(
raimund@3169: int ndx,
raimund@3169: String name,
raimund@3169: String description)
raimund@3169: {
raimund@3169: super(
raimund@3169: ndx,
raimund@3169: name,
raimund@3169: description,
raimund@3169: ComputeType.ADVANCE,
raimund@3169: null,
raimund@3169: null);
raimund@3169: }
raimund@3169:
raimund@3169:
raimund@3169: /**
raimund@3169: * Returns the data this facet requires.
raimund@3169: *
raimund@3169: * @param artifact the owner artifact.
raimund@3169: * @param context the CallContext.
raimund@3169: *
raimund@3169: * @return the data as KMIndex.
raimund@3169: */
raimund@3169: @Override
raimund@3169: public Object getData(Artifact artifact, CallContext context) {
teichmann@8202: log.debug("FixLongitudinalDeviationFacet.getData");
raimund@3169:
teichmann@5867: if (artifact instanceof D4EArtifact) {
teichmann@5867: D4EArtifact flys = (D4EArtifact)artifact;
raimund@3169:
raimund@3169: CalculationResult res =
raimund@3169: (CalculationResult) flys.compute(context,
raimund@3169: ComputeType.ADVANCE,
raimund@3169: false);
raimund@3169:
sascha@3415: FixAnalysisResult result = (FixAnalysisResult) res.getData();
raimund@3169:
raimund@3169: KMIndex kmPeriods = result.getAnalysisPeriods();
raimund@3169:
raimund@3169: if (kmPeriods == null) {
teichmann@8202: log.warn("No analysis periods found.");
raimund@3169: return null;
raimund@3169: }
raimund@3169:
raimund@3169: Parameters params = result.getParameters();
raimund@3169:
raimund@3169: KMIndex kmIndex = new KMIndex();
raimund@3169: for (KMIndex.Entry entry: kmPeriods) {
raimund@3169: double km = entry.getKm();
raimund@3169: double[] stdDev =
raimund@3169: params.interpolate("km", km, new String[] {"std-dev"});
raimund@3169:
raimund@3169: if(stdDev == null) {
teichmann@8202: log.warn("getData: stdDev == null");
raimund@3169: continue;
raimund@3169: }
raimund@3169: kmIndex.add(km, stdDev);
raimund@3169: }
raimund@3169:
raimund@3169: return kmIndex;
raimund@3169: }
raimund@3169: else {
teichmann@8202: log.warn("Artifact is no instance of D4EArtifact.");
raimund@3169: return null;
raimund@3169: }
raimund@3169: }
raimund@3169:
raimund@3169:
raimund@3169: /**
raimund@3169: * Create a deep copy of this Facet.
raimund@3169: * @return a deep copy.
raimund@3169: */
raimund@3169: @Override
raimund@3169: public FixLongitudinalDeviationFacet deepCopy() {
tom@8856: FixLongitudinalDeviationFacet copy =
tom@8856: new FixLongitudinalDeviationFacet();
raimund@3169: copy.set(this);
raimund@3169: return copy;
raimund@3169: }
raimund@3169: }
raimund@3169: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :