aheinecke@7685: /* Copyright (C) 2013 by Bundesanstalt für Gewässerkunde aheinecke@7685: * Software engineering by Intevation GmbH aheinecke@7685: * aheinecke@7685: * This file is Free Software under the GNU AGPL (>=v3) aheinecke@7685: * and comes with ABSOLUTELY NO WARRANTY! Check out the aheinecke@7685: * documentation coming with Dive4Elements River for details. aheinecke@7685: */ aheinecke@7685: aheinecke@7685: package org.dive4elements.river.exports.process; aheinecke@7685: aheinecke@7685: import org.apache.log4j.Logger; aheinecke@7685: import org.jfree.data.xy.XYSeries; aheinecke@7685: tom@8204: import gnu.trove.TDoubleArrayList; tom@8204: aheinecke@7685: import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; aheinecke@7685: import org.dive4elements.artifacts.CallContext; aheinecke@7685: import org.dive4elements.river.exports.DiagramGenerator; aheinecke@7685: import org.dive4elements.river.exports.StyledSeriesBuilder; aheinecke@7685: import org.dive4elements.river.jfree.StyledXYSeries; aheinecke@7685: import org.dive4elements.river.themes.ThemeDocument; aheinecke@7685: tom@8204: import org.dive4elements.river.artifacts.D4EArtifact; tom@8204: import org.dive4elements.river.artifacts.access.RiverAccess; tom@8204: import org.dive4elements.river.artifacts.model.minfo.SedimentLoadData; tom@8204: import org.dive4elements.river.artifacts.model.minfo.SedimentLoadData.Station; tom@8204: import org.dive4elements.river.artifacts.model.minfo.SedimentLoadDataFactory; tom@8204: aheinecke@7685: // Base class for SedimantLoad$UNITProcessors aheinecke@7685: public class SedimentLoadProcessor extends DefaultProcessor aheinecke@7685: { teichmann@8202: private final static Logger log = aheinecke@7685: Logger.getLogger(SedimentLoadProcessor.class); aheinecke@7685: tom@8204: private static final double EPS = 1e-4; tom@8204: aheinecke@7685: @Override aheinecke@7685: public void doOut( aheinecke@7685: DiagramGenerator generator, aheinecke@7685: ArtifactAndFacet bundle, aheinecke@7685: ThemeDocument theme, aheinecke@7685: boolean visible) { tom@8215: gernotbelger@9123: CallContext context = generator.getContext(); gernotbelger@9556: XYSeries series = new StyledXYSeries(bundle.getFacetName(),bundle.getFacetDescription(), aheinecke@7685: false, // Handle NaN aheinecke@7685: theme); aheinecke@7685: Object data = bundle.getData(context); aheinecke@7685: String facetName = bundle.getFacetName(); aheinecke@7685: teichmann@8202: log.debug("Do out for: " + facetName); tom@8148: if (facetName.startsWith("sedimentload.")) { tom@8204: /* Remove stations (with NaN-values) at stations of tom@8204: different type than appropriate for current fraction.*/ tom@8204: String [] facetNameParts = facetName.split("\\."); tom@8204: int gfSType = SedimentLoadData.measurementStationType( tom@8204: SedimentLoadData.grainFractionIndex( tom@8204: facetNameParts[facetNameParts.length-1])); tom@8204: tom@8204: RiverAccess access = tom@8204: new RiverAccess((D4EArtifact)bundle.getArtifact()); tom@8204: String river = access.getRiverName(); tom@8204: SedimentLoadData sld = tom@8204: SedimentLoadDataFactory.INSTANCE.getSedimentLoadData(river); tom@8204: tom@8204: double [][] allData = (double[][]) data; tom@8204: TDoubleArrayList cleanedKms = tom@8204: new TDoubleArrayList(allData[0].length); tom@8204: TDoubleArrayList cleanedValues = tom@8204: new TDoubleArrayList(allData[0].length); tom@8204: tom@8204: for (int i = 0; i < allData[0].length; ++i) { tom@8204: double km = allData[0][i]; tom@8204: Station station = sld.findStations(km-EPS, km+EPS).get(0); tom@8204: if (station.isType(gfSType)) { tom@8204: cleanedKms.add(km); tom@8204: cleanedValues.add(allData[1][i]); tom@8204: } tom@8204: } tom@8204: tom@8204: double [][] points = new double[2][cleanedKms.size()]; tom@8204: points[0] = cleanedKms.toNativeArray(); tom@8204: points[1] = cleanedValues.toNativeArray(); tom@8204: tom@8204: StyledSeriesBuilder.addPoints(series, points, false); // Keep NaN tom@8204: tom@8204: generator.addAxisSeries(series, axisName, visible); tom@8204: aheinecke@7685: } else { teichmann@8202: log.error("Unknown facet name: " + facetName); aheinecke@7685: return; aheinecke@7685: } aheinecke@7685: } aheinecke@7685: } aheinecke@7685: