annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FlowVelocityFacet.java @ 4630:63368dcc3f94

Moved MovingAverage into math package
author Sascha L. Teichmann <teichmann@intevation.de>
date Mon, 03 Dec 2012 18:44:48 +0100
parents 5b551e3a58d5
children 87c938d082d6
rev   line source
2706
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.artifacts.model;
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
2
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
3 import de.intevation.artifactdatabase.state.Facet;
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
4
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
5 import de.intevation.artifacts.Artifact;
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
6 import de.intevation.artifacts.CallContext;
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
7
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
8 import de.intevation.flys.artifacts.FLYSArtifact;
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
9
4626
5b551e3a58d5 Add start and end km of current chart zoomlevel to the context and use these
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
10 import de.intevation.flys.artifacts.access.RiverAccess;
5b551e3a58d5 Add start and end km of current chart zoomlevel to the context and use these
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
11 import de.intevation.flys.artifacts.context.FLYSContext;
4630
63368dcc3f94 Moved MovingAverage into math package
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4626
diff changeset
12
63368dcc3f94 Moved MovingAverage into math package
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4626
diff changeset
13 import de.intevation.flys.artifacts.math.MovingAverage;
2706
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
14 import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
15
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16 import org.apache.log4j.Logger;
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
17
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
18 /**
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
19 * Facet of a FlowVelocity curve.
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
20 */
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
21 public class FlowVelocityFacet extends DataFacet {
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
22
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
23 private static Logger logger = Logger.getLogger(FlowVelocityFacet.class);
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
24
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
25 public FlowVelocityFacet() {
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
26 // required for clone operation deepCopy()
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
27 }
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
28
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
29
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
30 public FlowVelocityFacet(
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
31 int idx,
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
32 String name,
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
33 String description,
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
34 ComputeType type,
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
35 String stateId,
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
36 String hash
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
37 ) {
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
38 super(idx, name, description, type, hash, stateId);
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
39 }
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
40
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
41
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
42 public Object getData(Artifact artifact, CallContext context) {
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
43 logger.debug("Get data for flow velocity at index: " + index);
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
44
4626
5b551e3a58d5 Add start and end km of current chart zoomlevel to the context and use these
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
45 Double start = (Double)context.getContextValue("startkm");
5b551e3a58d5 Add start and end km of current chart zoomlevel to the context and use these
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
46 Double end = (Double)context.getContextValue("endkm");
2706
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
47 FLYSArtifact flys = (FLYSArtifact) artifact;
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
48
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
49 CalculationResult res = (CalculationResult)
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
50 flys.compute(context, hash, stateId, type, false);
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
51
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
52 FlowVelocityData[] data = (FlowVelocityData[]) res.getData();
4626
5b551e3a58d5 Add start and end km of current chart zoomlevel to the context and use these
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
53 if(start != null && end != null) {
5b551e3a58d5 Add start and end km of current chart zoomlevel to the context and use these
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
54 FLYSContext fc = (FLYSContext)context.globalContext();
5b551e3a58d5 Add start and end km of current chart zoomlevel to the context and use these
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
55 ZoomScale scales = (ZoomScale)fc.get("zoomscale");
5b551e3a58d5 Add start and end km of current chart zoomlevel to the context and use these
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
56 RiverAccess access = new RiverAccess((FLYSArtifact)artifact);
5b551e3a58d5 Add start and end km of current chart zoomlevel to the context and use these
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
57 String river = access.getRiver();
2706
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
58
4626
5b551e3a58d5 Add start and end km of current chart zoomlevel to the context and use these
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
59 double radius = scales.getRadius(river, start, end);
5b551e3a58d5 Add start and end km of current chart zoomlevel to the context and use these
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
60 FlowVelocityData oldData = data[index];
5b551e3a58d5 Add start and end km of current chart zoomlevel to the context and use these
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
61 FlowVelocityData newData = new FlowVelocityData();
5b551e3a58d5 Add start and end km of current chart zoomlevel to the context and use these
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
62 double[][] q = oldData.getQPoints();
5b551e3a58d5 Add start and end km of current chart zoomlevel to the context and use these
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
63 double[][] totalV = MovingAverage.weighted(oldData.getTotalChannelPoints(), radius);
5b551e3a58d5 Add start and end km of current chart zoomlevel to the context and use these
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
64 double[][] mainV = MovingAverage.weighted(oldData.getMainChannelPoints(), radius);
5b551e3a58d5 Add start and end km of current chart zoomlevel to the context and use these
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
65 double[][] tau = MovingAverage.weighted(oldData.getTauPoints(), radius);
5b551e3a58d5 Add start and end km of current chart zoomlevel to the context and use these
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
66 for(int j = 0; j < q[0].length; j++) {
5b551e3a58d5 Add start and end km of current chart zoomlevel to the context and use these
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
67 newData.addKM(q[0][j]);
5b551e3a58d5 Add start and end km of current chart zoomlevel to the context and use these
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
68 newData.addQ(q[1][j]);
5b551e3a58d5 Add start and end km of current chart zoomlevel to the context and use these
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
69 newData.addTauMain(tau[1][j]);
5b551e3a58d5 Add start and end km of current chart zoomlevel to the context and use these
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
70 newData.addVMain(mainV[1][j]);
5b551e3a58d5 Add start and end km of current chart zoomlevel to the context and use these
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
71 newData.addVTotal(totalV[1][j]);
5b551e3a58d5 Add start and end km of current chart zoomlevel to the context and use these
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
72 }
5b551e3a58d5 Add start and end km of current chart zoomlevel to the context and use these
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
73 return newData;
5b551e3a58d5 Add start and end km of current chart zoomlevel to the context and use these
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
74 }
2706
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
75 return data[index];
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
76 }
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
77
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
78
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
79 /** Copy deeply. */
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
80 @Override
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
81 public Facet deepCopy() {
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
82 FlowVelocityFacet copy = new FlowVelocityFacet();
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
83 copy.set(this);
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
84 copy.type = type;
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
85 copy.hash = hash;
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
86 copy.stateId = stateId;
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
87 return copy;
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
88 }
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
89 }
d8444fcb4e44 Create chart facets for flow velocity calculation and a chart generator for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
90 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org