use of javax.media.jai.iterator.RandomIter 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);
}
use of javax.media.jai.iterator.RandomIter in project hortonmachine by TheHortonMachine.
the class OmsEnergyIndexCalculator method process.
@Execute
public void process() throws Exception {
HashMap<String, Double> regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inBasins);
cols = regionMap.get(CoverageUtilities.COLS).intValue();
rows = regionMap.get(CoverageUtilities.ROWS).intValue();
dx = regionMap.get(CoverageUtilities.XRES);
dy = regionMap.get(CoverageUtilities.YRES);
double n = regionMap.get(CoverageUtilities.NORTH);
double s = regionMap.get(CoverageUtilities.SOUTH);
double w = regionMap.get(CoverageUtilities.WEST);
double e = regionMap.get(CoverageUtilities.EAST);
double meanX = w + (e - w) / 2.0;
double meanY = s + (n - s) / 2.0;
Coordinate tmp = new Coordinate(meanX, meanY);
MathTransform mathTransform = CRS.findMathTransform(inAspect.getCoordinateReferenceSystem(), DefaultGeographicCRS.WGS84);
Coordinate newC = JTS.transform(tmp, null, mathTransform);
avgLatitude = newC.y;
RenderedImage idbasinImage = inBasins.getRenderedImage();
idbasinImageIterator = RandomIterFactory.create(idbasinImage, null);
RenderedImage elevImage = inElev.getRenderedImage();
elevImageIterator = RandomIterFactory.create(elevImage, null);
RenderedImage tmpImage = inCurvatures.getRenderedImage();
curvatureImage = CoverageUtilities.createWritableRaster(tmpImage.getWidth(), tmpImage.getHeight(), null, null, null);
RandomIter tmpIterator = RandomIterFactory.create(tmpImage, null);
// TODO check what this is for?!?!?
for (int i = 0; i < tmpImage.getHeight(); i++) {
for (int j = 0; j < tmpImage.getWidth(); j++) {
double value = tmpIterator.getSampleDouble(j, i, 0);
curvatureImage.setSample(j, i, 0, value);
}
}
RenderedImage aspectImage = inAspect.getRenderedImage();
aspectImageIterator = RandomIterFactory.create(aspectImage, null);
RenderedImage slopeImage = inSlope.getRenderedImage();
slopeImageIterator = RandomIterFactory.create(slopeImage, null);
avgLatitude *= (PI / 180.0);
// $NON-NLS-1$
pm.message(msg.message("eicalculator.preparing_inputs"));
eibasinNum = prepareInputsOutputs();
// $NON-NLS-1$
pm.beginTask(msg.message("eicalculator.computing"), 6);
for (int m = 0; m < 6; m++) {
pm.worked(1);
compute_EI(m + 1);
}
pm.done();
average_EI(10, 6);
// $NON-NLS-1$
pm.beginTask(msg.message("eicalculator.calc_areas"), eibasinNum);
for (int i = 0; i < eibasinNum; i++) {
pm.worked(1);
area(i);
}
pm.done();
/*
* putting the results together
*/
outAltimetry = new ArrayList<EIAltimetry>();
outEnergy = new ArrayList<EIEnergy>();
outArea = new ArrayList<EIAreas>();
for (int i = 0; i < eibasinNum; i++) {
int realBasinId = index2idMap.get(i + 1);
/*
* ENERGY BANDS
*
* Cycle over the virtual months:
* 0: 22 DICEMBRE - 20 GENNAIO
* 1: 21 GENNAIO - 20 FEBBRAIO
* 2: 21 FEBBRAIO - 22 MARZO
* 3: 23 MARZO - 22 APRILE
* 4: 23 APRILE - 22 MAGGIO
* 5: 23 MAGGIO - 22 GIUGNO
*/
for (int j = 0; j < 6; j++) {
for (int k = 0; k < pEi; k++) {
EIEnergy tmpEi = new EIEnergy();
// the basin id
tmpEi.basinId = realBasinId;
tmpEi.energeticBandId = k;
tmpEi.virtualMonth = j;
tmpEi.energyValue = eibasinEI[0][k][i];
outEnergy.add(tmpEi);
}
}
/*
* ALTIMETRIC BANDS
*/
for (int k = 0; k < pEs; k++) {
EIAltimetry tmpAl = new EIAltimetry();
tmpAl.basinId = realBasinId;
tmpAl.altimetricBandId = k;
tmpAl.elevationValue = eibasinES[k][i];
tmpAl.bandRange = eibasinESrange[k][i];
outAltimetry.add(tmpAl);
}
/*
* AREAS
*/
for (int j = 0; j < pEs; j++) {
for (int k = 0; k < pEi; k++) {
EIAreas tmpAr = new EIAreas();
tmpAr.basinId = realBasinId;
tmpAr.altimetricBandId = j;
tmpAr.energyBandId = k;
tmpAr.areaValue = eibasinA[j][k][i];
outArea.add(tmpAr);
}
}
}
}
use of javax.media.jai.iterator.RandomIter in project hortonmachine by TheHortonMachine.
the class OmsInfiltratedWaterVolume method process.
// VARS DOC END
@Execute
public void process() throws Exception {
checkNull(inPet, inRainfall, inFlowdirections, inNet, inRunoff);
RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inFlowdirections);
int rows = regionMap.getRows();
int cols = regionMap.getCols();
// -1E32;// as INVEST HMConstants.doubleNovalue;
double outNv = -9999;
WritableRaster outLiWR = CoverageUtilities.createWritableRaster(cols, rows, null, null, outNv);
WritableRandomIter outLiIter = CoverageUtilities.getWritableRandomIterator(outLiWR);
WritableRaster outLiAvailableWR = CoverageUtilities.createWritableRaster(cols, rows, null, null, outNv);
WritableRandomIter outLiAvailableIter = CoverageUtilities.getWritableRandomIterator(outLiAvailableWR);
WritableRaster outAetWR = CoverageUtilities.createWritableRaster(cols, rows, null, null, outNv);
WritableRandomIter outAetIter = CoverageUtilities.getWritableRandomIterator(outAetWR);
RandomIter flowIter = CoverageUtilities.getRandomIterator(inFlowdirections);
int flowNv = HMConstants.getIntNovalue(inFlowdirections);
RandomIter petIter = CoverageUtilities.getRandomIterator(inPet);
double petNv = HMConstants.getNovalue(inPet);
RandomIter runoffIter = CoverageUtilities.getRandomIterator(inRunoff);
double runoffNv = HMConstants.getNovalue(inRunoff);
RandomIter rainIter = CoverageUtilities.getRandomIterator(inRainfall);
double rainNv = HMConstants.getNovalue(inRainfall);
RandomIter netIter = CoverageUtilities.getRandomIterator(inNet);
double netNv = HMConstants.getNovalue(inNet);
List<FlowNode> sourceCells = new ArrayList<>();
try {
pm.beginTask("Collect source cells...", rows);
for (int r = 0; r < rows; r++) {
if (pm.isCanceled()) {
return;
}
for (int c = 0; c < cols; c++) {
FlowNode node = new FlowNode(flowIter, cols, rows, c, r, flowNv);
if (node.isSource()) {
sourceCells.add(node);
}
}
pm.worked(1);
}
pm.done();
double[][] lSumAvailableMatrix = new double[rows][cols];
for (int r = 0; r < lSumAvailableMatrix.length; r++) {
for (int c = 0; c < lSumAvailableMatrix[0].length; c++) {
lSumAvailableMatrix[r][c] = outNv;
}
}
for (FlowNode sourceCell : sourceCells) {
double pet = sourceCell.getValueFromMap(petIter);
double runoff = sourceCell.getValueFromMap(runoffIter);
double rain = sourceCell.getValueFromMap(rainIter);
double net = sourceCell.getValueFromMap(netIter);
if (!HMConstants.isNovalue(rain, rainNv) && !HMConstants.isNovalue(runoff, runoffNv)) {
boolean isPetNv = HMConstants.isNovalue(pet, petNv);
boolean isStream = !HMConstants.isNovalue(net, netNv) && net != 0.0;
double initialAet = 0;
double li = 0;
if (!isStream) {
if (isPetNv) {
initialAet = rain - runoff;
} else {
initialAet = Math.min(pet, rain - runoff);
}
li = rain - runoff - initialAet;
}
double lAvailable = Math.min(pGamma * li, li);
lSumAvailableMatrix[sourceCell.row][sourceCell.col] = 0;
sourceCell.setDoubleValueInMap(outLiAvailableIter, lAvailable);
sourceCell.setDoubleValueInMap(outLiIter, li);
sourceCell.setDoubleValueInMap(outAetIter, initialAet);
// go downstream
FlowNode cell = sourceCell.goDownstream();
Set<FlowNode> seen = new HashSet<>();
while (cell != null) {
List<FlowNode> upstreamCells = cell.getEnteringNodes();
// check if all upstream have a value
boolean canProcess = canProcess(outNv, outLiAvailableIter, upstreamCells);
if (canProcess) {
pet = cell.getDoubleValueFromMap(petIter);
isPetNv = HMConstants.isNovalue(pet, petNv);
rain = cell.getDoubleValueFromMap(rainIter);
runoff = cell.getDoubleValueFromMap(runoffIter);
net = cell.getDoubleValueFromMap(netIter);
if (!HMConstants.isNovalue(rain, rainNv) && !HMConstants.isNovalue(runoff, runoffNv)) {
isStream = !HMConstants.isNovalue(net, netNv) && net != 0.0;
double lAvailableUpstream = 0.0;
double lSumAvailableUpstream = 0.0;
for (FlowNode upstreamCell : upstreamCells) {
double upstreamLAvailable = upstreamCell.getValueFromMap(outLiAvailableIter);
// infiltratedWaterVolumeState.get(upstreamCell,
// Double.class);
int x = upstreamCell.col;
int y = upstreamCell.row;
lSumAvailableUpstream += lSumAvailableMatrix[y][x];
lAvailableUpstream += upstreamLAvailable;
}
double lSumAvailableCurrentCell = lSumAvailableUpstream + lAvailableUpstream;
lSumAvailableCurrentCell /= upstreamCells.size();
lSumAvailableMatrix[cell.row][cell.col] = lSumAvailableCurrentCell;
double aetCC = 0;
double liCC = 0;
if (!isStream) {
if (isPetNv) {
aetCC = rain - runoff + pAlpha * pBeta * lSumAvailableCurrentCell;
} else {
aetCC = Math.min(pet, rain - runoff + pAlpha * pBeta * lSumAvailableCurrentCell);
}
liCC = rain - runoff - aetCC;
}
double lAvailableCC = Math.min(pGamma * liCC, liCC);
cell.setDoubleValueInMap(outLiAvailableIter, lAvailableCC);
cell.setDoubleValueInMap(outLiIter, liCC);
cell.setDoubleValueInMap(outAetIter, aetCC);
} else if (!HMConstants.isNovalue(net, netNv) && net != 0.0 && cell.isValid()) {
cell.setDoubleValueInMap(outLiAvailableIter, 0);
cell.setDoubleValueInMap(outLiIter, 0);
cell.setDoubleValueInMap(outAetIter, 0);
}
cell = cell.goDownstream();
if (cell != null) {
if (seen.contains(cell)) {
cell = null;
} else {
seen.add(cell);
}
}
} else {
break;
}
}
}
}
outInfiltration = CoverageUtilities.buildCoverageWithNovalue("infiltration", outLiWR, regionMap, inFlowdirections.getCoordinateReferenceSystem(), outNv);
outNetInfiltration = CoverageUtilities.buildCoverageWithNovalue("netinfiltration", outLiAvailableWR, regionMap, inFlowdirections.getCoordinateReferenceSystem(), outNv);
outAet = CoverageUtilities.buildCoverageWithNovalue("aet", outAetWR, regionMap, inFlowdirections.getCoordinateReferenceSystem(), outNv);
outLsumAvailable = CoverageUtilities.buildCoverageWithNovalue("lsum", lSumAvailableMatrix, regionMap, inFlowdirections.getCoordinateReferenceSystem(), true, outNv);
} finally {
flowIter.done();
petIter.done();
runoffIter.done();
rainIter.done();
netIter.done();
outLiIter.done();
outLiAvailableIter.done();
outAetIter.done();
}
}
use of javax.media.jai.iterator.RandomIter in project hortonmachine by TheHortonMachine.
the class OmsIntensityClassifierDebrisFlowTN method process.
// VARS DOC END
@Execute
public void process() throws Exception {
if (!concatOr(outIntensity == null, doReset)) {
return;
}
checkNull(//
inVelocity, //
pUpperThresVelocity, //
pLowerThresVelocity, //
inWaterDepth, //
pUpperThresWaterdepth, //
pLowerThresWaterdepth, //
inErosionDepth, //
pUpperThresErosionDepth, //
pLowerThresErosionDepth, //
inDepositsThickness, //
pUpperThresDepositsThickness, //
pLowerThresDepositsThickness);
// do autoboxing only once
double maxWD = pUpperThresWaterdepth;
double minWD = pLowerThresWaterdepth;
double maxV = pUpperThresVelocity;
double minV = pLowerThresVelocity;
double maxED = pUpperThresErosionDepth;
double minED = pLowerThresErosionDepth;
double maxDT = pUpperThresDepositsThickness;
double minDT = pLowerThresDepositsThickness;
RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inWaterDepth);
int nCols = regionMap.getCols();
int nRows = regionMap.getRows();
RandomIter waterdepthIter = CoverageUtilities.getRandomIterator(inWaterDepth);
RandomIter velocityIter = CoverageUtilities.getRandomIterator(inVelocity);
RandomIter erosiondepthIter = CoverageUtilities.getRandomIterator(inErosionDepth);
RandomIter depositThicknessIter = CoverageUtilities.getRandomIterator(inDepositsThickness);
WritableRaster outWR = CoverageUtilities.createWritableRaster(nCols, nRows, null, null, doubleNovalue);
WritableRandomIter outIter = RandomIterFactory.createWritable(outWR, null);
pm.beginTask("Processing map...", nRows);
for (int r = 0; r < nRows; r++) {
if (isCanceled(pm)) {
return;
}
for (int c = 0; c < nCols; c++) {
double h = waterdepthIter.getSampleDouble(c, r, 0);
double v = velocityIter.getSampleDouble(c, r, 0);
double ed = erosiondepthIter.getSampleDouble(c, r, 0);
double dt = depositThicknessIter.getSampleDouble(c, r, 0);
if (isNovalue(h) && isNovalue(v) && isNovalue(ed) && isNovalue(dt)) {
continue;
} else if (!isNovalue(h) && !isNovalue(v) && !isNovalue(ed) && !isNovalue(dt)) {
double value = 0.0;
if (h > maxWD || v > maxV || dt > maxDT || ed > maxED) {
value = INTENSITY_HIGH;
} else if (//
(h <= maxWD && h > minWD) || //
(v <= maxV && v > minV) || //
(dt <= maxDT && dt > minDT) || (ed <= maxED && ed > minED)) {
value = INTENSITY_MEDIUM;
} else if (h <= minWD || v <= minV || dt <= minDT || ed <= minED) {
value = INTENSITY_LOW;
} else {
throw new ModelsIllegalargumentException("No intensity could be calculated for h = " + h + " and v = " + v + " and ed = " + ed + " and dt = " + dt, this, pm);
}
outIter.setSample(c, r, 0, value);
} else {
pm.errorMessage("WARNING: a cell was found in which one of velocity, water depth, erosion depth or deposit thickness are novalue, while the other not. /nThe maps should be covering the exact same cells. /nGoing on ignoring the cell: " + c + "/" + r);
}
}
pm.worked(1);
}
pm.done();
outIntensity = CoverageUtilities.buildCoverage("intensity", outWR, regionMap, inWaterDepth.getCoordinateReferenceSystem());
}
use of javax.media.jai.iterator.RandomIter in project hortonmachine by TheHortonMachine.
the class OmsIntensityClassifierFlood method process.
// VARS DOC END
@Execute
public void process() throws Exception {
if (!concatOr(outIntensity == null, doReset)) {
return;
}
checkNull(inWaterDepth, inVelocity, pUpperThresVelocityWaterdepth, pUpperThresWaterdepth, pLowerThresVelocityWaterdepth, pLowerThresWaterdepth);
// do autoboxing only once
double maxWD = pUpperThresWaterdepth;
double maxVWD = pUpperThresVelocityWaterdepth;
double minWD = pLowerThresWaterdepth;
double minVWD = pLowerThresVelocityWaterdepth;
RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inWaterDepth);
int nCols = regionMap.getCols();
int nRows = regionMap.getRows();
RandomIter waterdepthIter = CoverageUtilities.getRandomIterator(inWaterDepth);
RandomIter velocityIter = CoverageUtilities.getRandomIterator(inVelocity);
WritableRaster outWR = CoverageUtilities.createWritableRaster(nCols, nRows, null, null, doubleNovalue);
WritableRandomIter outIter = RandomIterFactory.createWritable(outWR, null);
pm.beginTask("Processing map...", nRows);
for (int r = 0; r < nRows; r++) {
if (isCanceled(pm)) {
return;
}
for (int c = 0; c < nCols; c++) {
double h = waterdepthIter.getSampleDouble(c, r, 0);
double v = velocityIter.getSampleDouble(c, r, 0);
if (isNovalue(h) && isNovalue(v)) {
continue;
} else if (!isNovalue(h) && !isNovalue(v)) {
double value = 0.0;
double vh = v * h;
if (h > maxWD || vh > maxVWD) {
value = INTENSITY_HIGH;
} else if ((h > minWD && h <= maxWD) || (vh > minVWD && vh <= maxVWD)) {
value = INTENSITY_MEDIUM;
} else if (h <= minWD && vh <= minVWD) {
value = INTENSITY_LOW;
} else {
throw new ModelsIllegalargumentException("No intensity could be calculated for h = " + h + " and v = " + v, this, pm);
}
outIter.setSample(c, r, 0, value);
} else {
pm.errorMessage("WARNING: a cell was found in which one of velocity and water depth are novalue, while the other not. /nThe maps should be covering the exact same cells. /nGoing on ignoring the cell: " + c + "/" + r);
}
}
pm.worked(1);
}
pm.done();
outIntensity = CoverageUtilities.buildCoverage("intensity", outWR, regionMap, inWaterDepth.getCoordinateReferenceSystem());
}
Aggregations