annotate artifacts/src/main/java/org/dive4elements/river/exports/process/SedimentLoadProcessor.java @ 9801:1d7a72a50183 3.2.x tip

Assume Compose V2, consistently
author Tom Gottfried <tom@intevation.de>
date Thu, 23 Nov 2023 10:14:13 +0100
parents 0a5239a1e46e
children
rev   line source
7685
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
1 /* Copyright (C) 2013 by Bundesanstalt für Gewässerkunde
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
2 * Software engineering by Intevation GmbH
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
3 *
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
6 * documentation coming with Dive4Elements River for details.
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
7 */
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
8
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
9 package org.dive4elements.river.exports.process;
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
10
9726
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8215
diff changeset
11 import org.apache.logging.log4j.Logger;
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8215
diff changeset
12 import org.apache.logging.log4j.LogManager;
7685
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
13 import org.jfree.data.xy.XYSeries;
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
14
8204
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
15 import gnu.trove.TDoubleArrayList;
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
16
7685
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
17 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
18 import org.dive4elements.artifacts.CallContext;
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
19 import org.dive4elements.river.exports.DiagramGenerator;
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
20 import org.dive4elements.river.exports.StyledSeriesBuilder;
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
21 import org.dive4elements.river.jfree.StyledXYSeries;
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
22 import org.dive4elements.river.themes.ThemeDocument;
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
23
8204
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
24 import org.dive4elements.river.artifacts.D4EArtifact;
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
25 import org.dive4elements.river.artifacts.access.RiverAccess;
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
26 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadData;
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
27 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadData.Station;
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
28 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadDataFactory;
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
29
7685
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
30 // Base class for SedimantLoad$UNITProcessors
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
31 public class SedimentLoadProcessor extends DefaultProcessor
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
32 {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8154
diff changeset
33 private final static Logger log =
9726
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8215
diff changeset
34 LogManager.getLogger(SedimentLoadProcessor.class);
7685
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
35
8204
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
36 private static final double EPS = 1e-4;
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
37
7685
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
38 @Override
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
39 public void doOut(
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
40 DiagramGenerator generator,
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
41 ArtifactAndFacet bundle,
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
42 ThemeDocument theme,
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
43 boolean visible) {
8215
204905c16ade Fetch missing values from database and show them in diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8204
diff changeset
44
7685
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
45 CallContext context = generator.getCallContext();
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
46 XYSeries series = new StyledXYSeries(bundle.getFacetDescription(),
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
47 false, // Handle NaN
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
48 theme);
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
49 Object data = bundle.getData(context);
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
50 String facetName = bundle.getFacetName();
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
51
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8154
diff changeset
52 log.debug("Do out for: " + facetName);
8148
eb48b244921d The rest is silence.
Tom Gottfried <tom@intevation.de>
parents: 8117
diff changeset
53 if (facetName.startsWith("sedimentload.")) {
8204
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
54 /* Remove stations (with NaN-values) at stations of
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
55 different type than appropriate for current fraction.*/
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
56 String [] facetNameParts = facetName.split("\\.");
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
57 int gfSType = SedimentLoadData.measurementStationType(
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
58 SedimentLoadData.grainFractionIndex(
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
59 facetNameParts[facetNameParts.length-1]));
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
60
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
61 RiverAccess access =
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
62 new RiverAccess((D4EArtifact)bundle.getArtifact());
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
63 String river = access.getRiverName();
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
64 SedimentLoadData sld =
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
65 SedimentLoadDataFactory.INSTANCE.getSedimentLoadData(river);
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
66
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
67 double [][] allData = (double[][]) data;
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
68 TDoubleArrayList cleanedKms =
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
69 new TDoubleArrayList(allData[0].length);
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
70 TDoubleArrayList cleanedValues =
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
71 new TDoubleArrayList(allData[0].length);
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
72
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
73 for (int i = 0; i < allData[0].length; ++i) {
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
74 double km = allData[0][i];
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
75 Station station = sld.findStations(km-EPS, km+EPS).get(0);
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
76 if (station.isType(gfSType)) {
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
77 cleanedKms.add(km);
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
78 cleanedValues.add(allData[1][i]);
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
79 }
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
80 }
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
81
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
82 double [][] points = new double[2][cleanedKms.size()];
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
83 points[0] = cleanedKms.toNativeArray();
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
84 points[1] = cleanedValues.toNativeArray();
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
85
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
86 StyledSeriesBuilder.addPoints(series, points, false); // Keep NaN
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
87
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
88 generator.addAxisSeries(series, axisName, visible);
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
89
7685
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
90 } else {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8154
diff changeset
91 log.error("Unknown facet name: " + facetName);
7685
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
92 return;
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
93 }
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
94 }
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
95 }
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
96

http://dive4elements.wald.intevation.org