public double calculateQmax() { double area_super = fixedParams.getArea(); double area_sub = fixedParams.getArea_sub(); double area_tot = 0f; /* if (effectsBox.containsKey("ampi_sub")) */ if (area_sub != 0) { area_tot = area_sub + area_super; } else { area_tot = area_super; } double qmax = (double) (J * area_tot * (ModelsEngine.width_interpolate(ampidiff, iuhC.getTstarMax(), 0, 2) - ModelsEngine.width_interpolate(ampidiff, iuhC.getTstarMax() - tpmax, 0, 2))); return qmax; }
/** * Executing ordinary kriging. * * <p> * <li>Verify if the parameters are correct. * <li>Calculating the matrix of the covariance (a). * <li>For each point to interpolated, evalutate the know term vector (b) and solve the system (a * x)=b where x is the weight. * * @throws SchemaException */ @Execute public void process() throws Exception { verifyInput(); List<Double> xStationList = new ArrayList<Double>(); List<Double> yStationList = new ArrayList<Double>(); List<Double> zStationList = new ArrayList<Double>(); List<Double> hStationList = new ArrayList<Double>(); /* * counter for the number of station with measured value !=0. */ int n1 = 0; /* * Store the station coordinates and measured data in the array. */ FeatureIterator<SimpleFeature> stationsIter = inStations.features(); try { while (stationsIter.hasNext()) { SimpleFeature feature = stationsIter.next(); Object stationId = feature.getAttribute(fStationsid); int id; if (stationId instanceof Number) { id = ((Number) stationId).intValue(); } else if (stationId instanceof String) { id = (int) Double.parseDouble((String) stationId); } else { throw new ModelsIllegalargumentException( "Unreadable type found for the station id.", this, pm); } double z = 0; if (fStationsZ != null) { try { z = ((Number) feature.getAttribute(fStationsZ)).doubleValue(); } catch (NullPointerException e) { pm.errorMessage(msg.message("kriging.noStationZ")); throw new Exception(msg.message("kriging.noStationZ")); } } Coordinate coordinate = ((Geometry) feature.getDefaultGeometry()).getCentroid().getCoordinate(); double[] h = inData.get(id); if (h == null || isNovalue(h[0])) { /* * skip data for non existing stations, they are allowed. * Also skip novalues. */ continue; } if (defaultVariogramMode == 0) { if (doIncludezero) { if (Math.abs(h[0]) >= 0.0) { // TOLL xStationList.add(coordinate.x); yStationList.add(coordinate.y); zStationList.add(z); hStationList.add(h[0]); n1 = n1 + 1; } } else { if (Math.abs(h[0]) > 0.0) { // TOLL xStationList.add(coordinate.x); yStationList.add(coordinate.y); zStationList.add(z); hStationList.add(h[0]); n1 = n1 + 1; } } } else if (defaultVariogramMode == 1) { if (doIncludezero) { if (Math.abs(h[0]) >= 0.0) { // TOLL xStationList.add(coordinate.x); yStationList.add(coordinate.y); zStationList.add(z); hStationList.add(h[0]); n1 = n1 + 1; } } else { if (Math.abs(h[0]) > 0.0) { // TOLL xStationList.add(coordinate.x); yStationList.add(coordinate.y); zStationList.add(z); hStationList.add(h[0]); n1 = n1 + 1; } } } } } finally { stationsIter.close(); } int nStaz = xStationList.size(); /* * The coordinates of the station points plus in last position a place * for the coordinate of the point to interpolate. */ double[] xStation = new double[nStaz + 1]; double[] yStation = new double[nStaz + 1]; double[] zStation = new double[nStaz + 1]; double[] hStation = new double[nStaz + 1]; boolean areAllEquals = true; if (nStaz != 0) { xStation[0] = xStationList.get(0); yStation[0] = yStationList.get(0); zStation[0] = zStationList.get(0); hStation[0] = hStationList.get(0); double previousValue = hStation[0]; for (int i = 1; i < nStaz; i++) { double xTmp = xStationList.get(i); double yTmp = yStationList.get(i); double zTmp = zStationList.get(i); double hTmp = hStationList.get(i); boolean doubleStation = ModelsEngine.verifyDoubleStation( xStation, yStation, zStation, hStation, xTmp, yTmp, zTmp, hTmp, i, false, pm); if (!doubleStation) { xStation[i] = xTmp; yStation[i] = yTmp; zStation[i] = zTmp; hStation[i] = hTmp; if (areAllEquals && hStation[i] != previousValue) { areAllEquals = false; } previousValue = hStation[i]; } } } LinkedHashMap<Integer, Coordinate> pointsToInterpolateId2Coordinates = null; // vecchio int numPointToInterpolate = getNumPoint(inInterpolate); int numPointToInterpolate = 0; /* * if the isLogarithmic is true then execute the model with log value. */ // vecchio double[] result = new double[numPointToInterpolate]; if (pMode == 0) { pointsToInterpolateId2Coordinates = getCoordinate(numPointToInterpolate, inInterpolate, fInterpolateid); } else if (pMode == 1) { pointsToInterpolateId2Coordinates = getCoordinate(inInterpolationGrid); numPointToInterpolate = pointsToInterpolateId2Coordinates.size(); } else { throw new ModelsIllegalargumentException("The parameter pMode can only be 0 or 1.", this, pm); } Set<Integer> pointsToInterpolateIdSet = pointsToInterpolateId2Coordinates.keySet(); Iterator<Integer> idIterator = pointsToInterpolateIdSet.iterator(); int j = 0; // vecchio int[] idArray = new int[inInterpolate.size()]; int[] idArray = new int[pointsToInterpolateId2Coordinates.size()]; double[] result = new double[pointsToInterpolateId2Coordinates.size()]; if (n1 != 0) { if (doLogarithmic) { for (int i = 0; i < nStaz; i++) { if (hStation[i] > 0.0) { hStation[i] = Math.log(hStation[i]); } } } /* * calculating the covariance matrix. */ double[][] covarianceMatrix = covMatrixCalculating(xStation, yStation, zStation, n1); /* * extract the coordinate of the points where interpolated. */ /* * initialize the solution and its variance vector. */ if (!areAllEquals && n1 > 1) { // pm.beginTask(msg.message("kriging.working"),inInterpolate.size()); while (idIterator.hasNext()) { double sum = 0.; int id = idIterator.next(); idArray[j] = id; Coordinate coordinate = (Coordinate) pointsToInterpolateId2Coordinates.get(id); xStation[n1] = coordinate.x; yStation[n1] = coordinate.y; zStation[n1] = coordinate.z; /* * calculating the right hand side of the kriging linear * system. */ double[] knownTerm = knownTermsCalculation(xStation, yStation, zStation, n1); /* * solve the linear system, where the result is the weight. */ ColumnVector knownTermColumn = new ColumnVector(knownTerm); LinearSystem linearSystem = new LinearSystem(covarianceMatrix); ColumnVector solution = linearSystem.solve(knownTermColumn, true); // Matrix a = new Matrix(covarianceMatrix); // Matrix b = new Matrix(knownTerm, knownTerm.length); // Matrix x = a.solve(b); double[] moltiplicativeFactor = solution.copyValues1D(); double h0 = 0.0; for (int k = 0; k < n1; k++) { h0 = h0 + moltiplicativeFactor[k] * hStation[k]; sum = sum + moltiplicativeFactor[k]; } if (doLogarithmic) { h0 = Math.exp(h0); } result[j] = h0; j++; if (Math.abs(sum - 1) >= TOLL) { throw new ModelsRuntimeException( "Error in the coffeicients calculation", this.getClass().getSimpleName()); } } } else if (n1 == 1 || areAllEquals) { double tmp = hStation[0]; int k = 0; pm.message(msg.message("kriging.setequalsvalue")); while (idIterator.hasNext()) { int id = idIterator.next(); result[k] = tmp; idArray[k] = id; k++; } } if (pMode == 0) { storeResult(result, idArray); } else { storeResult(result, pointsToInterpolateId2Coordinates); } } else { pm.errorMessage("No rain for this time step"); j = 0; double[] value = inData.values().iterator().next(); while (idIterator.hasNext()) { int id = idIterator.next(); idArray[j] = id; result[j] = value[0]; j++; } if (pMode == 0) { storeResult(result, idArray); } else { storeResult(result, pointsToInterpolateId2Coordinates); } } }
protected double equation(double time) { double d = 1.0 / k * Math.exp(-t / k) * ModelsEngine.width_interpolate(ampi_sub, time, 0, 1); return d; }
public double[][] calculateQ() { double timestep = fixedParams.getTimestep(); double area_super = fixedParams.getArea(); double area_sub = fixedParams.getArea_sub(); double area_tot = 0f; double tcorr = ampidiff[ampidiff.length - 1][0]; double[][] Q = new double[(int) Math.floor((tcorr + tpmax) / timestep) + 1][4]; if (area_sub != -9999.0) { area_tot = area_sub + area_super; } else { area_tot = area_super; } /* * calculate the discharge for t < tcorr */ int j = 0; pm.beginTask("Calculating discharge for t < tcorr...", (int) tcorr); for (int t = 1; t < tcorr; t += timestep) { j = (int) Math.floor((t) / timestep); if (t <= tpmax) { Q[j][0] = t; Q[j][1] = (double) (J * area_tot * ModelsEngine.width_interpolate(ampidiff, t, 0, 2)); Q[j][2] = Q[j - 1][2] + Q[j][1]; Q[j][3] = h; } else { Q[j][0] = t; Q[j][1] = (double) (J * area_tot * (ModelsEngine.width_interpolate(ampidiff, t, 0, 2) - ModelsEngine.width_interpolate(ampidiff, t - tpmax, 0, 2))); Q[j][2] = Q[j - 1][2] + Q[j][1]; Q[j][3] = 0.0; } pm.worked((int) timestep); } pm.done(); /* * calculate the discharge for t > tcorr */ pm.beginTask("Calculating discharge for t > tcorr...", (int) tpmax); for (double t = tcorr; t < (tcorr + tpmax); t += timestep) { j = (int) Math.floor(((int) t) / timestep); Q[j][0] = t; Q[j][1] = (double) (J * area_tot * (ampidiff[ampidiff.length - 1][2] - ModelsEngine.width_interpolate(ampidiff, t - tpmax, 0, 2))); Q[j][2] = Q[j - 1][2] + Q[j][1]; Q[j][3] = 0.0; pm.worked((int) timestep); } pm.done(); /* * calculate the volumes */ // double vol = Q[Q.length - 2][2] * timestep; // double vol2 = (double) (area_tot * h / 1000); return Q; }