Search in sources :

Example 1 with ConstantRandomIter

use of org.hortonmachine.gears.utils.coverage.ConstantRandomIter in project hortonmachine by TheHortonMachine.

the class OmsShalstab method process.

@Execute
public void process() throws Exception {
    if (!concatOr(outShalstab == null, doReset)) {
        return;
    }
    checkNull(inSlope, inTca);
    if (pRock == -9999.0)
        pRock = 5.67;
    RenderedImage slopeRI = inSlope.getRenderedImage();
    RenderedImage abRI = inTca.getRenderedImage();
    RandomIter trasmissivityIter = null;
    if (inTrasmissivity != null) {
        RenderedImage trasmissivityRI = inTrasmissivity.getRenderedImage();
        trasmissivityIter = RandomIterFactory.create(trasmissivityRI, null);
    } else {
        trasmissivityIter = new ConstantRandomIter(pTrasmissivity);
    }
    RandomIter tghiIter = null;
    if (inTgphi != null) {
        RenderedImage tgphiRI = inTgphi.getRenderedImage();
        tghiIter = RandomIterFactory.create(tgphiRI, null);
    } else {
        tghiIter = new ConstantRandomIter(pTgphi);
    }
    RandomIter cohesionIter = null;
    if (inCohesion != null) {
        RenderedImage cohesionRI = inCohesion.getRenderedImage();
        cohesionIter = RandomIterFactory.create(cohesionRI, null);
    } else {
        cohesionIter = new ConstantRandomIter(pCohesion);
    }
    RandomIter hsIter = null;
    if (inSdepth != null) {
        RenderedImage hsRI = inSdepth.getRenderedImage();
        hsIter = RandomIterFactory.create(hsRI, null);
    } else {
        hsIter = new ConstantRandomIter(pSdepth);
    }
    RandomIter qIter = null;
    if (inQ != null) {
        RenderedImage qRI = inQ.getRenderedImage();
        qIter = RandomIterFactory.create(qRI, null);
    } else {
        qIter = new ConstantRandomIter(pQ);
    }
    RandomIter rhoIter = null;
    if (inRho != null) {
        RenderedImage rhoRI = inRho.getRenderedImage();
        rhoIter = RandomIterFactory.create(rhoRI, null);
    } else {
        rhoIter = new ConstantRandomIter(pRho);
    }
    qcrit(slopeRI, abRI, trasmissivityIter, tghiIter, cohesionIter, hsIter, qIter, rhoIter);
}
Also used : ConstantRandomIter(org.hortonmachine.gears.utils.coverage.ConstantRandomIter) RandomIter(javax.media.jai.iterator.RandomIter) WritableRandomIter(javax.media.jai.iterator.WritableRandomIter) ConstantRandomIter(org.hortonmachine.gears.utils.coverage.ConstantRandomIter) RenderedImage(java.awt.image.RenderedImage) Execute(oms3.annotations.Execute)

Example 2 with ConstantRandomIter

use of org.hortonmachine.gears.utils.coverage.ConstantRandomIter in project hortonmachine by TheHortonMachine.

the class OmsDownSlopeConnectivity method process.

// VARS DOC END
@Execute
public void process() throws Exception {
    checkNull(inFlow, inNet, inSlope);
    if (pWeight == null && inWeights == null) {
        throw new ModelsIllegalargumentException("At lest one weight definition needs to be supplied.", this);
    }
    RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inFlow);
    int nCols = regionMap.getCols();
    int nRows = regionMap.getRows();
    double xres = regionMap.getXres();
    double yres = regionMap.getYres();
    RandomIter flowIter = CoverageUtilities.getRandomIterator(inFlow);
    RandomIter netIter = CoverageUtilities.getRandomIterator(inNet);
    RandomIter slopeIter = CoverageUtilities.getRandomIterator(inSlope);
    int flowNv = HMConstants.getIntNovalue(inFlow);
    double netNv = HMConstants.getNovalue(inNet);
    RandomIter weightsIter;
    if (inWeights != null) {
        weightsIter = CoverageUtilities.getRandomIterator(inWeights);
    } else {
        weightsIter = new ConstantRandomIter(pWeight);
    }
    WritableRaster[] connectivityRasterHolder = new WritableRaster[1];
    outConnectivity = CoverageUtilities.createCoverageFromTemplate(inFlow, HMConstants.doubleNovalue, connectivityRasterHolder);
    WritableRandomIter connectivityIter = CoverageUtilities.getWritableRandomIterator(connectivityRasterHolder[0]);
    pm.beginTask("Calculate downslope connectivity...", nRows);
    for (int r = 0; r < nRows; r++) {
        if (pm.isCanceled()) {
            return;
        }
        for (int c = 0; c < nCols; c++) {
            FlowNode flowNode = new FlowNode(flowIter, nCols, nRows, c, r, flowNv);
            if (!flowNode.isValid()) {
                continue;
            }
            GridNode netNode = new GridNode(netIter, nCols, nRows, xres, yres, c, r, netNv);
            double connectivitySum = 0;
            while (flowNode.isValid() && !netNode.isValid()) {
                FlowNode nextFlowNode = flowNode.goDownstream();
                if (nextFlowNode == null) {
                    throw new ModelsRuntimeException("Could not properly navigate the flowdirections. Are you using an extracted basin?", this);
                }
                int col = flowNode.col;
                int nextCol = nextFlowNode.col;
                int row = flowNode.row;
                int nextRow = nextFlowNode.row;
                double distance = sqrt(pow((nextCol - col) * xres, 2.0) + pow((nextRow - row) * yres, 2.0));
                double weight = weightsIter.getSampleDouble(flowNode.col, flowNode.row, 0);
                double slope = slopeIter.getSampleDouble(flowNode.col, flowNode.row, 0);
                if (slope == 0.0) {
                    slope = 0.005;
                }
                double Di = distance / weight / slope;
                connectivitySum = connectivitySum + Di;
                flowNode = nextFlowNode;
                netNode = new GridNode(netIter, nCols, nRows, xres, yres, nextFlowNode.col, nextFlowNode.row, netNv);
            }
            connectivityIter.setSample(c, r, 0, connectivitySum);
        }
        pm.worked(1);
    }
    pm.done();
}
Also used : ModelsIllegalargumentException(org.hortonmachine.gears.libs.exceptions.ModelsIllegalargumentException) ConstantRandomIter(org.hortonmachine.gears.utils.coverage.ConstantRandomIter) WritableRandomIter(javax.media.jai.iterator.WritableRandomIter) GridNode(org.hortonmachine.gears.libs.modules.GridNode) WritableRaster(java.awt.image.WritableRaster) RegionMap(org.hortonmachine.gears.utils.RegionMap) RandomIter(javax.media.jai.iterator.RandomIter) WritableRandomIter(javax.media.jai.iterator.WritableRandomIter) ConstantRandomIter(org.hortonmachine.gears.utils.coverage.ConstantRandomIter) ModelsRuntimeException(org.hortonmachine.gears.libs.exceptions.ModelsRuntimeException) FlowNode(org.hortonmachine.gears.libs.modules.FlowNode) Execute(oms3.annotations.Execute)

Aggregations

RandomIter (javax.media.jai.iterator.RandomIter)2 WritableRandomIter (javax.media.jai.iterator.WritableRandomIter)2 Execute (oms3.annotations.Execute)2 ConstantRandomIter (org.hortonmachine.gears.utils.coverage.ConstantRandomIter)2 RenderedImage (java.awt.image.RenderedImage)1 WritableRaster (java.awt.image.WritableRaster)1 ModelsIllegalargumentException (org.hortonmachine.gears.libs.exceptions.ModelsIllegalargumentException)1 ModelsRuntimeException (org.hortonmachine.gears.libs.exceptions.ModelsRuntimeException)1 FlowNode (org.hortonmachine.gears.libs.modules.FlowNode)1 GridNode (org.hortonmachine.gears.libs.modules.GridNode)1 RegionMap (org.hortonmachine.gears.utils.RegionMap)1