comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/FlowVelocityFilterFacet.java @ 5838:5aa05a7a34b7

Rename modules to more fitting names.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 15:23:37 +0200
parents flys-artifacts/src/main/java/org/dive4elements/river/artifacts/model/FlowVelocityFilterFacet.java@bd047b71ab37
children 4897a58c8746
comparison
equal deleted inserted replaced
5837:d9901a08d0a6 5838:5aa05a7a34b7
1 package org.dive4elements.river.artifacts.model;
2
3 import org.dive4elements.artifactdatabase.state.Facet;
4
5 import org.dive4elements.artifacts.Artifact;
6 import org.dive4elements.artifacts.CallContext;
7
8 import org.dive4elements.river.artifacts.FLYSArtifact;
9
10 import org.dive4elements.river.artifacts.access.RiverAccess;
11 import org.dive4elements.river.artifacts.context.FLYSContext;
12
13 import org.dive4elements.river.artifacts.math.MovingAverage;
14 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType;
15
16 import org.apache.log4j.Logger;
17
18 /**
19 * Facet of a FlowVelocity curve.
20 */
21 public class FlowVelocityFilterFacet extends DataFacet {
22
23 private static Logger logger = Logger.getLogger(FlowVelocityFilterFacet.class);
24
25 public FlowVelocityFilterFacet() {
26 // required for clone operation deepCopy()
27 }
28
29
30 public FlowVelocityFilterFacet(
31 int idx,
32 String name,
33 String description,
34 ComputeType type,
35 String stateId,
36 String hash
37 ) {
38 super(idx, name, description, type, hash, stateId);
39 }
40
41
42 public Object getData(Artifact artifact, CallContext context) {
43 logger.debug("Get data for flow velocity at index: " + index);
44
45 Double start = (Double)context.getContextValue("startkm");
46 Double end = (Double)context.getContextValue("endkm");
47 FLYSArtifact flys = (FLYSArtifact) artifact;
48
49 CalculationResult res = (CalculationResult)
50 flys.compute(context, hash, stateId, type, false);
51
52 FlowVelocityData[] data = (FlowVelocityData[]) res.getData();
53 if(start != null && end != null) {
54 FLYSContext fc = (FLYSContext)context.globalContext();
55 ZoomScale scales = (ZoomScale)fc.get("zoomscale");
56 RiverAccess access = new RiverAccess((FLYSArtifact)artifact);
57 String river = access.getRiver();
58
59 double radius = scales.getRadius(river, start, end);
60 FlowVelocityData oldData = data[index];
61 FlowVelocityData newData = new FlowVelocityData();
62 double[][] q = oldData.getQPoints();
63 double[][] totalV = MovingAverage.weighted(oldData.getTotalChannelPoints(), radius);
64 double[][] mainV = MovingAverage.weighted(oldData.getMainChannelPoints(), radius);
65 double[][] tau = MovingAverage.weighted(oldData.getTauPoints(), radius);
66 for(int j = 0; j < q[0].length; j++) {
67 newData.addKM(q[0][j]);
68 newData.addQ(q[1][j]);
69 newData.addTauMain(tau[1][j]);
70 newData.addVMain(mainV[1][j]);
71 newData.addVTotal(totalV[1][j]);
72 }
73 return newData;
74 }
75 return data[index];
76 }
77
78
79 /** Copy deeply. */
80 @Override
81 public Facet deepCopy() {
82 FlowVelocityFilterFacet copy = new FlowVelocityFilterFacet();
83 copy.set(this);
84 copy.type = type;
85 copy.hash = hash;
86 copy.stateId = stateId;
87 return copy;
88 }
89 }
90 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org