raimund@3898: package de.intevation.flys.artifacts.model.minfo; raimund@3898: raimund@3898: import org.apache.log4j.Logger; raimund@3898: raimund@3898: import de.intevation.artifactdatabase.state.Facet; raimund@3898: import de.intevation.artifacts.Artifact; raimund@3898: import de.intevation.artifacts.CallContext; raimund@3898: import de.intevation.flys.artifacts.FLYSArtifact; rrenkert@4639: import de.intevation.flys.artifacts.access.RiverAccess; rrenkert@4639: import de.intevation.flys.artifacts.context.FLYSContext; raimund@3898: import de.intevation.flys.artifacts.model.CalculationResult; raimund@3898: import de.intevation.flys.artifacts.model.DataFacet; rrenkert@4640: import de.intevation.flys.artifacts.math.MovingAverage; rrenkert@4639: import de.intevation.flys.artifacts.model.ZoomScale; raimund@3898: import de.intevation.flys.artifacts.states.DefaultState.ComputeType; raimund@3898: raimund@3898: raimund@3898: public class BedDiffYearFacet raimund@3898: extends DataFacet raimund@3898: { raimund@3898: private static Logger logger = Logger.getLogger(BedDiffYearFacet.class); raimund@3898: raimund@3898: public BedDiffYearFacet() { raimund@3898: } raimund@3898: raimund@3898: public BedDiffYearFacet(int idx, String name, String description, raimund@3898: ComputeType type, String stateId, String hash) { raimund@3898: super(idx, name, description, type, hash, stateId); raimund@3898: } raimund@3898: raimund@3898: public Object getData(Artifact artifact, CallContext context) { raimund@3898: logger.debug("Get data for bed density at index: " + index); raimund@3898: raimund@3898: FLYSArtifact flys = (FLYSArtifact) artifact; raimund@3898: raimund@3898: CalculationResult res = (CalculationResult) flys.compute(context, hash, raimund@3898: stateId, type, false); raimund@3898: rrenkert@4639: BedDiffYearResult[] data = raimund@3898: (BedDiffYearResult[]) res.getData(); // TODO CAST TO SPECIFIC CLASS rrenkert@4639: Double start = (Double)context.getContextValue("startkm"); rrenkert@4639: Double end = (Double)context.getContextValue("endkm"); rrenkert@4639: if(start != null && end != null) { rrenkert@4639: FLYSContext fc = (FLYSContext)context.globalContext(); rrenkert@4639: ZoomScale scales = (ZoomScale)fc.get("zoomscale"); rrenkert@4639: RiverAccess access = new RiverAccess((FLYSArtifact)artifact); rrenkert@4639: String river = access.getRiver(); raimund@3898: rrenkert@4639: double radius = scales.getRadius(river, start, end); rrenkert@4639: BedDiffYearResult oldData = data[index]; rrenkert@4639: BedDiffYearResult newData = new BedDiffYearResult(); rrenkert@4639: newData.setStart(oldData.getStart()); rrenkert@4639: newData.setEnd(oldData.getEnd()); rrenkert@4639: double[][] diffs = MovingAverage.weighted(oldData.getDifferencesData(), radius); rrenkert@4639: double[][] heights1 = MovingAverage.weighted(oldData.getHeights1Data(), radius); rrenkert@4639: double[][] heights2 = MovingAverage.weighted(oldData.getHeights2Data(), radius); rrenkert@4639: double[][] morph = oldData.getMorphWidthData(); rrenkert@4639: double[][] year = MovingAverage.weighted(oldData.getHeightPerYearData(), radius); rrenkert@4639: for(int j = 0; j < diffs[0].length; j++) { rrenkert@4639: newData.addKm(diffs[0][j]); rrenkert@4639: newData.addBedHeights(year[1][j]); rrenkert@4639: newData.addMorphWidth(morph[1][j]); rrenkert@4639: newData.addDifference(diffs[1][j]); rrenkert@4639: newData.addHeight1(heights1[1][j]); rrenkert@4639: newData.addHeight2(heights2[1][j]); rrenkert@4639: } rrenkert@4639: return newData; rrenkert@4639: } raimund@3898: return data != null && data.length > index ? data[index] : null; raimund@3898: } raimund@3898: raimund@3898: /** Copy deeply. */ raimund@3898: @Override raimund@3898: public Facet deepCopy() { raimund@3898: BedDiffYearFacet copy = new BedDiffYearFacet(); raimund@3898: copy.set(this); raimund@3898: copy.type = type; raimund@3898: copy.hash = hash; raimund@3898: copy.stateId = stateId; raimund@3898: return copy; raimund@3898: } raimund@3898: } raimund@3898: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :