diff --git a/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/i18n/HortonMessages.java b/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/i18n/HortonMessages.java index a2c6acf52..40421cb42 100644 --- a/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/i18n/HortonMessages.java +++ b/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/i18n/HortonMessages.java @@ -1328,5 +1328,109 @@ public class HortonMessages { public static final String OMSEXTRACTBASIN_outBasin_DESCRIPTION = "The extracted basin mask."; public static final String OMSEXTRACTBASIN_outOutlet_DESCRIPTION = "The optional outlet point vector map."; public static final String OMSEXTRACTBASIN_outVectorBasin_DESCRIPTION = "The optional extracted basin vector map."; + + public static final int OMSCISLAM_STATUS = oms3.annotations.Status.EXPERIMENTAL; + public static final String OMSCISLAM_NAME = "cislam"; + public static final String OMSCISLAM_DESCRIPTION = "A version of the OmsCislam model."; + public static final String OMSCISLAM_DOCUMENTATION = "OmsCislam.html"; + public static final String OMSCISLAM_KEYWORDS = "OmsCislam, Hydrology"; + public static final String OMSCISLAM_LABEL = HYDROGEOMORPHOLOGY + "/CI-slam"; + public static final String OMSCISLAM_LICENSE = "General Public License Version 3 (GPLv3)"; + public static final String OMSCISLAM_AUTHORNAMES = "Marco Foi, Cristiano Lanni, Antonello Andrea, Franceschi Silvia, Rigon Riccardo"; + public static final String OMSCISLAM_AUTHORCONTACTS = "http://www.mcfoi.it, http://www.hydrologis.com, http://www.ing.unitn.it/dica/hp/?user=rigon"; + public static final String OMSCISLAM_SUBMODULES_LABEL = OMSCISLAM_LABEL + "/Utility Models"; + // Sub-models - Utility-Models DEFINITIONS + public static final String OMSCISLAM_OMSSLOPEFORCISLAM_DESCRIPTION = "A model used internally to the OmsCislam one for computing a tailored Slope map out of the default one from the OsmSlope model. The model actually just replaces all zero values in the Slope map, with a non-zero positive value provided by the user. This is done to allow processing of flow paths with simple algorithms."; + public static final String OMSCISLAM_OMSSLOPEFORCISLAM_NAME = "slopeforcislam"; + public static final int OMSCISLAM_OMSSLOPEFORCISLAM_STATUS = oms3.annotations.Status.EXPERIMENTAL; + public static final String OMSCISLAM_OMSSLOPEFORCISLAM_KEYWORDS = "OmsSlopeForCislam, OmsCislam, Hydrology"; + public static final String OMSCISLAM_OMSSOILTHICKNESS_DESCRIPTION = "A model for providing a testing soil thickness map to the OmsCislam model. It implements the specific soilthickness-slope relation:

SoilThickness=1.006-0.85*slope

For this reason it SHOULD NOT be used as default source of soil-thickness maps. Instead a specific map should be created for each basin, evenutually relying on the OmsMapcalc model."; + public static final String OMSCISLAM_OMSSOILTHICKNESS_NAME = "soilthickness"; + public static final int OMSCISLAM_OMSSOILTHICKNESS_STATUS = oms3.annotations.Status.EXPERIMENTAL; + public static final String OMSCISLAM_OMSSOILTHICKNESS_KEYWORDS = "OmsSoilThickness, OmsCislam, Hydrology"; + public static final String OMSCISLAM_OMSVANGENUCHMAPGEN_DESCRIPTION = "A model for providing van Genuchten parameter maps, geotechnical maps and phisical parameter maps to run TESTS of the OmsCislam model."; + public static final String OMSCISLAM_OMSVANGENUCHMAPGEN_NAME = "vangenuchtenmapsgenerator"; + public static final int OMSCISLAM_OMSVANGENUCHMAPGEN_STATUS = oms3.annotations.Status.EXPERIMENTAL; + public static final String OMSCISLAM_OMSVANGENUCHMAPGEN_KEYWORDS = "OmsVanGenuchtenMapsGenerator, OmsCislam, Hydrology"; + public static final String OMSCISLAM_OMSVWT_DESCRIPTION = "A model to compute the soil mosture volume needed to produce a perched water table, so the saturation, at the soil-bedrock interface due to vertical infiltration, during a rainfall event (no lateral flow considered). The model is used as a component within the OmsCislam model."; + public static final String OMSCISLAM_OMSVWT_NAME = "soilmoisturetowatertable"; + public static final int OMSCISLAM_OMSVWT_STATUS = oms3.annotations.Status.EXPERIMENTAL; + public static final String OMSCISLAM_OMSVWT_KEYWORDS = "OmsVwt, OmsCislam, Hydrology"; + public static final String OMSCISLAM_OMSPSIINITATBEDROCK_DESCRIPTION = "A model to produce a map defining the initial suction head (psi) at soil-bedrock interface before any rainfall event. It computes a map basing on what the user provides:"; + public static final String OMSCISLAM_OMSPSIINITATBEDROCK_NAME = "psiinitatbedrock"; + public static final int OMSCISLAM_OMSPSIINITATBEDROCK_STATUS = oms3.annotations.Status.EXPERIMENTAL; + public static final String OMSCISLAM_OMSPSIINITATBEDROCK_KEYWORDS = "OmsPsiInitAtBedrock, OmsCislam, Hydrology"; + public static final String OMSCISLAM_OMSV0_DESCRIPTION = "A model to compute the volume of soil mosture initally contained through the soil profile before any rainfall event. The model is used as a component within the OmsCislam model."; + public static final String OMSCISLAM_OMSV0_NAME = "soilmoisturebeforerainfall"; + public static final int OMSCISLAM_OMSV0_STATUS = oms3.annotations.Status.EXPERIMENTAL; + public static final String OMSCISLAM_OMSV0_KEYWORDS = "OmsV0, OmsCislam, Hydrology"; + public static final String OMSCISLAM_OMSAFETYFACTORGEOMECHANIC_DESCRIPTION = "A model to produce a geo-technical Safety Factor map. This calculation does not take into account hydrologic factors that may negatively affect the result. This means that map areas that do not even stand the test of this geo-technical safety factor will surely result in not stable areas even when hydrology is taken into account."; + public static final String OMSCISLAM_OMSAFETYFACTORGEOMECHANIC_NAME = "safetyfactorgeomechanic"; + public static final int OMSCISLAM_OMSAFETYFACTORGEOMECHANIC_STATUS = oms3.annotations.Status.EXPERIMENTAL; + public static final String OMSCISLAM_OMSAFETYFACTORGEOMECHANIC_KEYWORDS = "OmsSafetyFactorGeomechanic, OmsCislam, Hydrology"; + public static final String OMSCISLAM_OMSSAFETYFACTORCOMPOSER_DESCRIPTION = "A model to compose a set of Safety Factor maps created for the same Return Time but for different rainfallon durations. The model uses a worst-case logic so that the lowest values from each map is set in the output, cell by cell."; + public static final String OMSCISLAM_OMSSAFETYFACTORCOMPOSER_NAME = "safetyfactorsworstcasecomposer"; + public static final int OMSCISLAM_OMSSAFETYFACTORCOMPOSER_STATUS = oms3.annotations.Status.EXPERIMENTAL; + public static final String OMSCISLAM_OMSSAFETYFACTORCOMPOSER_KEYWORDS = "OmsSafetyFactorsWorstCaseComposer, OmsCislam, Hydrology"; + // Output-related parameters + public static final String OMSCISLAM_pOutFolder_DESCRIPTION = "The folder in which results will be deployed along with by-products, if specified."; + public static final String OMSCISLAM_doSaveByproducts_DESCRIPTION = "Save processing byproducts as ASCII grids."; + public static final String OMSCISLAM_doCalculateGeoMechanicSafetyFactor_DESCRIPTION = "Calculate (and save) geo-mechanic only Safety Factor (uses OmsSafetyFactorGeomechanic model)."; + public static final String OMSCISLAM_doCalculateInitialSafetyFactor_DESCRIPTION = "Calculate (and save) initial hydrologic Safety Factor."; + // Input PARAMETERS + public static final String OMSCISLAM_pMinSlope_DESCRIPTION = "The non-zero value to replace in the zero cells."; + public static final String OMSCISLAM_pReturnTimes_DESCRIPTION = "List of comma-separated return times (e.g.: 30,100,200 )."; + public static final String OMSCISLAM_pRainfallDurations_DESCRIPTION = "List of comma-separated simulated rainfall durations (e.g.: 1,3,6,12,25 )."; + // Input MAPS + public static final String OMSCISLAM_inSoilThickness_DESCRIPTION = "Map of Soil Thickness. (A sample map can be computed with the experimental OmsSoilThickness model but should not be used for any basin as it implements a specific soil-slope relation suitable just for specific environments)."; + public static final String OMSCISLAM_inPsiInitAtBedrock_DESCRIPTION = "Map of initial Psi value (suction head at soil-bedrock interface). Can be created with OmsPsiInitAtBedrock model."; + public static final String OMSCISLAM_inSlope_DESCRIPTION = "Map of Slope (from OmsSlope model)."; + public static final String OMSCISLAM_inPit_DESCRIPTION = "Map of Depitted Elevations (from OmsPit model)."; + public static final String OMSCISLAM_inFlow_DESCRIPTION = "Map of Flow Directions (from OmsFlowDirections model)."; + public static final String OMSCISLAM_inAb_DESCRIPTION = "Map of Area per Length (from OmsAb model)."; + // van Genuchten parameters/maps + public static final String OMSCISLAM_inGeo_DESCRIPTION = "Map of classified Geological/Pedological areas."; + public static final String OMSCISLAM_inCohesion_DESCRIPTION = "Map of Cohesion."; + public static final String OMSCISLAM_outCohesion_DESCRIPTION = OMSCISLAM_inCohesion_DESCRIPTION; + public static final String OMSCISLAM_pCohesion_DESCRIPTION = "A Cohesion value, to be used as a constant for the whole basin (alternative to map)."; + public static final String OMSCISLAM_inPhi_DESCRIPTION = "Map of effective frictional angle (Phi)."; + public static final String OMSCISLAM_outPhi_DESCRIPTION = OMSCISLAM_inPhi_DESCRIPTION; + public static final String OMSCISLAM_pPhi_DESCRIPTION = "An effective frictional angle value (Phi), to be used as a constant for the whole basin (alternative to map)."; + public static final String OMSCISLAM_inGamma_DESCRIPTION = "Map of Soil Gamma (density)."; + public static final String OMSCISLAM_outGamma_DESCRIPTION = OMSCISLAM_inGamma_DESCRIPTION; + public static final String OMSCISLAM_pGamma_DESCRIPTION = "A Soil Gamma value (density), to be used as a constant for the whole basin (alternative to map)."; + public static final String OMSCISLAM_inKsat_DESCRIPTION = "Map of Saturated Hydraulic Conductivity (Ksat)"; + public static final String OMSCISLAM_outKsat_DESCRIPTION = OMSCISLAM_inKsat_DESCRIPTION; + public static final String OMSCISLAM_pKsat_DESCRIPTION = "A Saturated Hydraulic Conductivity (Ksat) value, to be used as a constant for the whole basin (alternative to map)."; + public static final String OMSCISLAM_inTheta_s_DESCRIPTION = "Map of saturated water content (Theta S): saturated water content."; + public static final String OMSCISLAM_outTheta_s_DESCRIPTION = OMSCISLAM_inTheta_s_DESCRIPTION; + public static final String OMSCISLAM_pTheta_s_DESCRIPTION = "A Theta S value, to be used as a constant for the whole basin (alternative to map)."; + public static final String OMSCISLAM_inTheta_r_DESCRIPTION = "Map of residual water content (Theta R): residual water content."; + public static final String OMSCISLAM_outTheta_r_DESCRIPTION = OMSCISLAM_inTheta_r_DESCRIPTION; + public static final String OMSCISLAM_pTheta_r_DESCRIPTION = "A residual water content value (Theta R) , to be used as a constant for the whole basin (alternative to map)."; + public static final String OMSCISLAM_inAlfaVanGen_DESCRIPTION = "Map of Alfa (van Genuchten parm.)."; + public static final String OMSCISLAM_outAlfaVanGen_DESCRIPTION = OMSCISLAM_inAlfaVanGen_DESCRIPTION; + public static final String OMSCISLAM_pAlfaVanGen_DESCRIPTION = "An Alfa value (van Genuchten), to be used as a constant for the whole basin (alternative to map)."; + public static final String OMSCISLAM_inNVanGen_DESCRIPTION = "Map of n (van Genuchten parm.)."; + public static final String OMSCISLAM_outNVanGen_DESCRIPTION = OMSCISLAM_inNVanGen_DESCRIPTION; + public static final String OMSCISLAM_pNVanGen_DESCRIPTION = "An n value (van Genuchten), to be used as a constant for the whole basin (alternative to map)."; + // Rainfall statistical parameters + public static final String OMSCISLAM_pSigma1_DESCRIPTION = "Sigma1: parameter derived by linear regression of expectations of rainfall depth vs. duration."; + public static final String OMSCISLAM_pmF_DESCRIPTION = "mF: parameter derived by linear regression of expectations of rainfall depth vs. duration."; + public static final String OMSCISLAM_pCV_DESCRIPTION = "CV: Coefficient of Variation of rainfalls."; + // Submodels Inputs-Outputs + public static final String OMSCISLAM_OMSV0_inPsiInitAtBedrock_DESCRIPTION = "Map of initial Psi value (suction head at soil-bedrock interface). (Can be created with OmsPsiInitAtBedrock model)"; + public static final String OMSCISLAM_OMSV0_outV0_DESCRIPTION = "Map of initial soil moisture volume throgh the soil profile before a rainfall event."; + public static final String OMSCISLAM_OMSVWT_outVwt_DESCRIPTION = "Map of soil moisture volume needed to produce a perched water table - zero-pressure head - at the soil-bedrock interface."; + public static final String OMSCISLAM_OMSSLOPEFORCISLAM_inSlope_DESCRIPTION = "Map of Slope with no zero values and recomputed border (from OmsSlopeForCislam model)."; + public static final String OMSCISLAM_OMSSLOPEFORCISLAM_outSlope_DESCRIPTION = "Map of Slope for OsmCislam model (no zero values and with value-bearing border)."; + public static final String OMSCISLAM_OMSSOILTHICKNESS_outSoilThickness_DESCRIPTION = "Map of Soil thickness."; + public static final String OMSCISLAM_OMSPSIINITATBEDROCK_pPsiInitAtBedrockConstant_DESCRIPTION = "An initial suction head value at soil-bedrock interface (psi), alternative to the soil thickness map, to be used as a constant for the whole basin."; + public static final String OMSCISLAM_OMSPSIINITATBEDROCK_outPsiInitAtBedrock_DESCRIPTION = "Map of initial Psi value (suction head at soil-bedrock interface)."; + public static final String OMSCISLAM_OMSAFETYFACTORGEOMECHANIC_outSafetyactorGeoMechanic_DESCRIPTION = "Map of Safety Factor taking into account just geo-mechanical parameter. No suction head due to soil moisture or rainfall effect are considered."; + public static final String OMSCISLAM_OMSSAFETYFACTORCOMPOSER_inRasters_DESCRIPTION = "List of Safety Factor maps computed for the same Return Time but different Rainfall Durations"; + public static final String OMSCISLAM_OMSSAFETYFACTORCOMPOSER_pReturnTime_DESCRIPTION = "Return Time for which the computation was run."; + public static final String OMSCISLAM_OMSSAFETYFACTORCOMPOSER_outSafetyFactorTotal_DESCRIPTION = "Worst-case composed Safety Factor map."; + } diff --git a/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/OmsCislam.java b/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/OmsCislam.java new file mode 100644 index 000000000..8e9b25dbc --- /dev/null +++ b/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/OmsCislam.java @@ -0,0 +1,681 @@ +/* + * This file is part of JGrasstools (http://www.jgrasstools.org) + * (C) HydroloGIS - www.hydrologis.com + * + * JGrasstools is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam; + +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_AUTHORCONTACTS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_AUTHORNAMES; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_DOCUMENTATION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_KEYWORDS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_LABEL; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_LICENSE; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_NAME; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_STATUS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_doCalculateInitialSafetyFactor_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_doSaveByproducts_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inAb_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inAlfaVanGen_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inCohesion_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inFlow_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inGamma_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inKsat_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inNVanGen_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inPhi_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inPit_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inPsiInitAtBedrock_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inSlope_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inSoilThickness_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inTheta_r_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inTheta_s_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_pCV_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_pOutFolder_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_pRainfallDurations_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_pReturnTimes_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_pSigma1_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_pmF_DESCRIPTION; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +import oms3.annotations.Author; +import oms3.annotations.Description; +import oms3.annotations.Documentation; +import oms3.annotations.Execute; +import oms3.annotations.In; +import oms3.annotations.Keywords; +import oms3.annotations.Label; +import oms3.annotations.License; +import oms3.annotations.Name; +import oms3.annotations.Status; +import oms3.annotations.UI; +import oms3.annotations.Unit; + +import org.geotools.coverage.grid.GridCoverage2D; +import org.jgrasstools.gears.libs.modules.JGTConstants; +import org.jgrasstools.gears.libs.modules.JGTModel; +import org.jgrasstools.hortonmachine.i18n.HortonMessageHandler; +import org.jgrasstools.hortonmachine.modules.demmanipulation.markoutlets.OmsMarkoutlets; +import org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.utility_models.OmsV0; +import org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.utility_models.OmsVwt; +import org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.utils.MapCalculationFunctions; +import org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.utils.MapCalculationFunctions.MapOfCumulatedValue; +import org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.utils.MapDumpingFunctions; +import org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.utils.MapPreprocessingUtilities; +import org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.utils.ParameterCalculationFunctions; + +/** + * + * @author Marco Foi (www.mcfoi.it) + * + */ +@Description(OMSCISLAM_DESCRIPTION) +@Documentation(OMSCISLAM_DOCUMENTATION) +@Author(name = OMSCISLAM_AUTHORNAMES, contact = OMSCISLAM_AUTHORCONTACTS) +@Keywords(OMSCISLAM_KEYWORDS) +@Label(OMSCISLAM_LABEL) +@Name(OMSCISLAM_NAME) +@Status(OMSCISLAM_STATUS) +@License(OMSCISLAM_LICENSE) +public class OmsCislam extends JGTModel { + + // Default minimum slope value used as a substitute for Slope Map values equal to zero. Required to avoid division by zero. + public static final double MINIMM_ALLOWED_SLOPE = 0.009; + // Default rainfall durations used to compute maps of times to develop water table. + private static final String RAINFALL_DURATIONS_ARRAY = "1, 3, 6, 12, 24"; + + @Description(OMSCISLAM_pReturnTimes_DESCRIPTION) + @Unit("years") + @In + public String pReturnTimes = new String("30, 100, 200"); + + @Description(OMSCISLAM_pRainfallDurations_DESCRIPTION) + @Unit("hours") + @In + public String pRainfallDurations = RAINFALL_DURATIONS_ARRAY; + + // Input files + @Description(OMSCISLAM_inPit_DESCRIPTION) + @Unit("m") + @In + public GridCoverage2D inPit = null; + + @Description(OMSCISLAM_inFlow_DESCRIPTION) + @In + public GridCoverage2D inFlow = null; + + @Description(OMSCISLAM_inSlope_DESCRIPTION) + @In + public GridCoverage2D inSlope = null; + + @Description(OMSCISLAM_inAb_DESCRIPTION) + @In + public GridCoverage2D inAb = null; + + @Description(OMSCISLAM_inSoilThickness_DESCRIPTION) + @Unit("m") + @In + public GridCoverage2D inSoilThickness = null; + + // ############################################# + // Rainfall-statistics related parameters + // ############################################# + @Description(OMSCISLAM_pSigma1_DESCRIPTION) + @In + public double pSigma1 = 11.82; + + @Description(OMSCISLAM_pmF_DESCRIPTION) + @In + public double pmF = 0.54; + + @Description(OMSCISLAM_pCV_DESCRIPTION) + @In + public double pCV = 0.23; + + // ############################################# + // Hydrologic parameters + // ############################################# + @Description(OMSCISLAM_inPsiInitAtBedrock_DESCRIPTION) + @Unit("m") + @In + public GridCoverage2D inPsiInitAtBedrock = null; + + // ############################################# + // Geo-Techical parameters + // ############################################# + @Description(OMSCISLAM_inCohesion_DESCRIPTION) + @UI(JGTConstants.FILEIN_UI_HINT) + @Unit("kPa") + @In + public GridCoverage2D inCohesion = null; + + @Description(OMSCISLAM_inPhi_DESCRIPTION) + @UI(JGTConstants.FILEIN_UI_HINT) + @In + public GridCoverage2D inPhi = null; + + @Description(OMSCISLAM_inGamma_DESCRIPTION) + @In + public GridCoverage2D inGammaSoil = null; + + @Description(OMSCISLAM_inKsat_DESCRIPTION) + @Unit("m/s") + @In + public GridCoverage2D inKsat = null; + + @Description(OMSCISLAM_inTheta_s_DESCRIPTION) + @Unit("-") + @In + public GridCoverage2D inTheta_s = null; + + @Description(OMSCISLAM_inTheta_r_DESCRIPTION) + @Unit("-") + @In + public GridCoverage2D inTheta_r = null; + + + // ############################################# + // van Genuchten parameters + // ############################################# + @Description(OMSCISLAM_inAlfaVanGen_DESCRIPTION) + @Unit("1/m") + @In + public GridCoverage2D inAlfaVanGen = null; + + @Description(OMSCISLAM_inNVanGen_DESCRIPTION) + @Unit("-") + @In + public GridCoverage2D inNVanGen = null; + + // ############################################# + // Calculate hydrologic Initial Safety Factor + // ############################################# + @Description(OMSCISLAM_doCalculateInitialSafetyFactor_DESCRIPTION) + @In + public boolean doCalculateInitialSafetyFactor = false; + + // ############################################# + // Save by-products to file + // ############################################# + @Description(OMSCISLAM_doSaveByproducts_DESCRIPTION) + @In + public boolean doSaveByProducts = false; + + @Description(OMSCISLAM_pOutFolder_DESCRIPTION) + @In + public String pOutFolder = System.getProperty("java.io.tmpdir"); + + // ############# + // References to internal by-products for DEBUGGING and TESTING purposes + private GridCoverage2D outMarkedFlow_Raster = null; + private GridCoverage2D outFixedSlope_Raster = null; + private GridCoverage2D out_avg_slope_cum_Raster = null; + private GridCoverage2D out_avg_soil_thickness_cum_Raster = null; + private GridCoverage2D out_avg_th_time_cum_Raster = null; + private GridCoverage2D out_avg_ab_cum_Raster = null; + private GridCoverage2D out_cumRatio_Raster = null; + private GridCoverage2D out_cumDist_Raster = null; + private GridCoverage2D out_cumCont_Raster = null; + private GridCoverage2D out_avg_slope_cum_fixed_Raster = null; + private GridCoverage2D out_avg_soil_thickness_cum_fixed_Raster = null; + private GridCoverage2D out_avg_th_time_cum_fixed_Raster = null; + private GridCoverage2D out_avg_ab_cum_fixed_Raster = null; + private GridCoverage2D out_cumRatio_fixed_Raster = null; + private GridCoverage2D out_cumDist_fixed_Raster = null; + private GridCoverage2D out_IT_din_lin_Raster = null; + private GridCoverage2D out_psi_b_Eq9_Raster = null; + private GridCoverage2D out_psi_b_Eq12_Raster = null; + private GridCoverage2D out_psi_b_Combined_Raster = null; + private GridCoverage2D out_SafetyFactor_Initial_Raster = null; + private GridCoverage2D out_SafetyFactor_InfiniteSlope_accounting_for_SaturatedZones_Raster = null; + private GridCoverage2D out_SafetyFactor_InfiniteSlope_accounting_for_SaturatedZones_RetTime_TOTAL_Raster = null; + // ############# + + private HortonMessageHandler msg = HortonMessageHandler.getInstance(); + + @Execute + public void process() throws Exception { + + // Check required parameters + checkNull(pReturnTimes); + checkNull(pRainfallDurations); + + checkNull(inPit); + checkNull(inFlow); + checkNull(inSlope); + checkNull(inAb); + checkNull(inSoilThickness); + checkNull(inPsiInitAtBedrock); + + checkNull(pSigma1, pmF, pCV); + + checkNull(inTheta_s); + checkNull(inTheta_r); + + checkNull(inAlfaVanGen); + checkNull(inNVanGen); + + checkNull(inKsat); + checkNull(inGammaSoil); + checkNull(inCohesion); + checkNull(inPhi); + + if(pOutFolder == "" || pOutFolder == null){ + pOutFolder = System.getProperty("java.io.tmpdir"); + } + + pOutFolder = MapDumpingFunctions.fixOutputFolderString(pOutFolder); + + // Take flow map, created by the user using OmsFlowDirections, and rebuild border + GridCoverage2D inFlowWithBorder = MapPreprocessingUtilities.flowMapRebuildBorder(inFlow, inPit, pm); + + // Take flow map with proper border and mark basin outlet with value 10 + GridCoverage2D inFlowWithBorderAndOutlet = MapPreprocessingUtilities.flowMapMarkOutlet(inFlowWithBorder, pm); + + // ################################################################################## + // Rebuild border of slope map, computing cell values, and replace zero values with a not-null minimum + GridCoverage2D inSlopeFixZeroValuesAndBorder = MapPreprocessingUtilities.slopeMapFixZeroValuesAndBorder(inSlope, inPit, + OmsCislam.MINIMM_ALLOWED_SLOPE, pm); + + // ################################################################################## + // Parse simulated Rainfall Durations string into an array of integers + ArrayList rainfallDurationsArrayList = ParameterCalculationFunctions.parseRainfallDurationsString(pRainfallDurations, pm); + + // Parse Return Times string into an array of integers + ArrayList returnTimesArrayList = ParameterCalculationFunctions.parseReturnTimesString(pReturnTimes, pm); + + // ################################################################################## + // Compute Th_time from Eq. (7) and Eq. (6) of reference paper. + + // ##==## Equation (7) + OmsVwt mVwt = new OmsVwt(); + mVwt.inSoilThickness = inSoilThickness; + mVwt.inTheta_r = inTheta_r; + mVwt.inTheta_s = inTheta_s; + mVwt.inAlfaVanGen = inAlfaVanGen; + mVwt.inNVanGen = inNVanGen; + mVwt.process(); + GridCoverage2D outVwt = mVwt.outVwt; + + + // ##==## Equation (6) + OmsV0 mV0 = new OmsV0(); + mV0.inSoilThickness = inSoilThickness; + mV0.inTheta_r = inTheta_r; + mV0.inTheta_s = inTheta_s; + mV0.inAlfaVanGen = inAlfaVanGen; + mV0.inNVanGen = inNVanGen; + mV0.inPsiInitAtBedrock = inPsiInitAtBedrock; + mV0.process(); + GridCoverage2D outV0 = mV0.outV0; + + HashMap mapsOfTwt = new HashMap(); + // Calculate Time-to-develop-Watertable maps for each provided return time for each of the default rainfall durations + for( int pReturnTime : returnTimesArrayList ) { + + for( int pRainfallDuration : rainfallDurationsArrayList ) { + + double pRainfallIntensity = ParameterCalculationFunctions.calculateRainfallIntensity(pSigma1, pmF, pCV, pReturnTime, + pRainfallDuration, null); + pm.message(" "); + pm.message("######################################################################################"); + pm.message("######################################################################################"); + pm.message("### ###"); + pm.message("Computing Twt map for Rainfall Duration: " + pRainfallDuration + "hours and Return Time: " + pReturnTime + + "years"); + GridCoverage2D rasterTwt = MapCalculationFunctions.computeMapOfTimeForWaterTableDevelopmentTwt(outVwt, outV0, + pRainfallIntensity, pm); + + pm.message("Stats for Twt map for Rainfall Duration " + pRainfallDuration + "hours and Return Time: " + pReturnTime + + "years"); + pm.message(MapCalculationFunctions.getCoverageStatsAsString(rasterTwt)); + + mapsOfTwt.put(new Integer[]{pRainfallDuration, pReturnTime}, rasterTwt); + } + } + + int computedMaps = mapsOfTwt.size(); + pm.message(" "); + pm.message("A total number of " + computedMaps + " have been calculated."); + pm.message("### ###"); + pm.message("######################################################################################"); + pm.message("######################################################################################"); + // Dump results to file + if (doSaveByProducts) { + MapDumpingFunctions.dumpMapsOfTwt(mapsOfTwt, pOutFolder, pm); + } + // End of Twt maps computation + // ################################################################################## + + + + for( int y : returnTimesArrayList ) { + + GridCoverage2D[] mapsSafetyFactor_InfSlope_with_SaturZones_LastHour = new GridCoverage2D[rainfallDurationsArrayList.size()]; + int durationArrayStep = -1; + + for( int h : rainfallDurationsArrayList ) { + + durationArrayStep++; + double pRainfallIntensity = ParameterCalculationFunctions.calculateRainfallIntensity(pSigma1, pmF, pCV, y, h, null); + + GridCoverage2D mapPsiMultiHours_Eq9 = null; + pm.message(" "); + pm.message("######################################################################################"); + pm.message("### COMPUTING Psi Maps FOR Return Time: " + y + " years and Rainfall Duration: " + h + " hours."); + + GridCoverage2D singleTwtMap = getTwsMap(mapsOfTwt, y, h); + + // ################################################################################## + // Compute maps of Psi at bedrock during rainfall due to vertical infiltration + // for increasing hours of rainfall duration + // + // Equation (9) of reference paper. + // + // Relies on Twt maps, rainfall parameters (pSigma1, pmF, pCV) and + // + mapPsiMultiHours_Eq9 = MapCalculationFunctions.computeMapsOfPsiAtBedrockDuringVerticalInfiltration(singleTwtMap, + inPsiInitAtBedrock, pRainfallIntensity, inSoilThickness, inTheta_s, inTheta_r, inAlfaVanGen, inNVanGen, pm); + + int numMaps = mapPsiMultiHours_Eq9.getNumSampleDimensions(); + pm.message("Number of Psi hourly maps returned from computation: " + numMaps); + + // Dump results to file + if (doSaveByProducts){ + MapDumpingFunctions.dumpMapsOfPsiMultiHours(mapPsiMultiHours_Eq9, y, h, pOutFolder, pm); + } + + // Export map references for allowing testing + out_psi_b_Eq9_Raster = mapPsiMultiHours_Eq9; + + pm.message(" "); + pm.message("### COMPUTING Psi Maps IS COMPLETED ###"); + pm.message("#######################################"); + pm.message("#######################################"); + // End of Psi-at-bedrock-during-rainfall maps computation + // ################################################################################## + + // ################################################################################## + // Compute maps of Concentration time + pm.message(" "); + pm.message("###########################################"); + pm.message("### Compute maps of Concentration time. ###"); + pm.message(" "); + + pm.message(" "); + pm.message("### First compute maps of cumulated parameters. ########################"); + pm.message(" "); + HashMap mapsOfCumulatedParameters = MapCalculationFunctions + .calculateMapsOfCumulatedParameters(inPit, inFlowWithBorderAndOutlet, inKsat, inSoilThickness, inTheta_s, inAb, + singleTwtMap, pm); + + // Dump results to file + if (doSaveByProducts) { + MapDumpingFunctions.dumpCumulatedParametersToFiles(mapsOfCumulatedParameters, pOutFolder, pm); + } + + // Export map references for allowing testing + out_cumRatio_Raster = mapsOfCumulatedParameters.get(MapOfCumulatedValue.RATIO); + out_cumDist_Raster = mapsOfCumulatedParameters.get(MapOfCumulatedValue.DIST); + out_cumCont_Raster = mapsOfCumulatedParameters.get(MapOfCumulatedValue.CONT); + + // Compute averages of cumulated parameters + pm.message(" "); + pm.message("### Then average maps of cumulated parameters with step-count. #########"); + pm.message(" "); + GridCoverage2D avg_slope_cum = MapCalculationFunctions.computeMapOfAverageFromCumulated( + mapsOfCumulatedParameters.get(MapOfCumulatedValue.SLOPE_CUM), + mapsOfCumulatedParameters.get(MapOfCumulatedValue.CONT)); + + GridCoverage2D avg_soil_thickness_cum = MapCalculationFunctions.computeMapOfAverageFromCumulated( + mapsOfCumulatedParameters.get(MapOfCumulatedValue.SOIL_THICK), + mapsOfCumulatedParameters.get(MapOfCumulatedValue.CONT)); + + GridCoverage2D avg_th_time_cum = MapCalculationFunctions + .computeMapOfAverageFromCumulated(mapsOfCumulatedParameters.get(MapOfCumulatedValue.TH_TIME), + mapsOfCumulatedParameters.get(MapOfCumulatedValue.CONT)); + + GridCoverage2D avg_ab_cum = MapCalculationFunctions.computeMapOfAverageFromCumulated( + mapsOfCumulatedParameters.get(MapOfCumulatedValue.AB), mapsOfCumulatedParameters.get(MapOfCumulatedValue.CONT)); + + // Export map references for allowing testing + out_avg_slope_cum_Raster = avg_slope_cum; + out_avg_soil_thickness_cum_Raster = avg_soil_thickness_cum; + out_avg_th_time_cum_Raster = avg_th_time_cum; + out_avg_ab_cum_Raster = avg_ab_cum; + + // Dump results to file + if (doSaveByProducts) { + MapDumpingFunctions.dumpSingleBandCoverage(avg_slope_cum, pOutFolder, pm); + MapDumpingFunctions.dumpSingleBandCoverage(avg_soil_thickness_cum, pOutFolder, pm); + MapDumpingFunctions.dumpSingleBandCoverage(avg_th_time_cum, pOutFolder, pm); + MapDumpingFunctions.dumpSingleBandCoverage(avg_ab_cum, pOutFolder, pm); + } + + // Rebuild borders in average parameter maps + pm.message(" "); + pm.message("### Rebuild borders of averaged maps. ##################################"); + pm.message(" "); + GridCoverage2D avg_slope_cum_BorderFixed = MapCalculationFunctions.fixBorders_AvgSlopeCum(avg_slope_cum, + inSlopeFixZeroValuesAndBorder); + GridCoverage2D avg_soil_thickness_cum_BorderFixed = MapCalculationFunctions.fixBorders_AvgSoilThicknessCum( + avg_soil_thickness_cum, inSoilThickness); + GridCoverage2D avg_ab_cum_BorderFixed = MapCalculationFunctions.fixBorders_AvgAbCum(avg_ab_cum, inPit); + GridCoverage2D DIST_BorderFixed = MapCalculationFunctions.fixBorders_Dist( + mapsOfCumulatedParameters.get(MapOfCumulatedValue.DIST), inPit, inFlowWithBorderAndOutlet); + GridCoverage2D RATIO_BorderFixed = MapCalculationFunctions.fixBorders_Ratio( + mapsOfCumulatedParameters.get(MapOfCumulatedValue.RATIO), DIST_BorderFixed, inPit, inTheta_s, inKsat); + GridCoverage2D avg_TH_TIME_BorderFixed = MapCalculationFunctions.fixBorders_AvgThTime(avg_th_time_cum, singleTwtMap); + + // Dump results to file + if (doSaveByProducts) { + MapDumpingFunctions.dumpSingleBandCoverage(avg_slope_cum_BorderFixed, pOutFolder, pm); + MapDumpingFunctions.dumpSingleBandCoverage(avg_soil_thickness_cum_BorderFixed, pOutFolder, pm); + MapDumpingFunctions.dumpSingleBandCoverage(avg_ab_cum_BorderFixed, pOutFolder, pm); + MapDumpingFunctions.dumpSingleBandCoverage(DIST_BorderFixed, pOutFolder, pm); + MapDumpingFunctions.dumpSingleBandCoverage(RATIO_BorderFixed, pOutFolder, pm); + MapDumpingFunctions.dumpSingleBandCoverage(avg_TH_TIME_BorderFixed, pOutFolder, pm); + } + + // Export map references for allowing testing + out_avg_slope_cum_fixed_Raster = avg_slope_cum_BorderFixed; + out_avg_soil_thickness_cum_fixed_Raster = avg_soil_thickness_cum_BorderFixed; + out_avg_ab_cum_fixed_Raster = avg_ab_cum_BorderFixed; + out_cumDist_fixed_Raster = DIST_BorderFixed; + out_cumRatio_fixed_Raster = RATIO_BorderFixed; + out_avg_th_time_cum_fixed_Raster = avg_TH_TIME_BorderFixed; + + // Compute map of Dynamic Linear Topographic Index + pm.message(" "); + pm.message("### Now computing Dinamic Linear Topographic Index. ####################"); + pm.message(" "); + GridCoverage2D IT_din_lin_Multiband_Coverage = MapCalculationFunctions.computeMapOfDynamicLinearTopographicIndex(avg_TH_TIME_BorderFixed, + singleTwtMap, y, h, RATIO_BorderFixed, inAb, inSlopeFixZeroValuesAndBorder, pm); + + // Dump results to file + if (doSaveByProducts) { + String message = "Dumping Dinamic-Linear Topographic Index maps to "; + MapDumpingFunctions.dumpMultiBandCoverage(IT_din_lin_Multiband_Coverage, pOutFolder, null, message); + } + + // Export map references for allowing testing + out_IT_din_lin_Raster = IT_din_lin_Multiband_Coverage; + + // ################################################################################## + // Compute maps of Psi for t < t_tw but t > t_wt_up + // so during infiltration but with active lateral flow from catchment + // Compute pressure at bedrock in the pore pressure positive zones + pm.message(" "); + pm.message("### Compute Pressure at bedrock (Psi) in the pore pressure positive zones.##"); + pm.message(" "); + + GridCoverage2D mapPsiMultiHours_Eq12 = MapCalculationFunctions.computeMapOfPsiAtBedrockInPositivePressureZones(y, h, inSoilThickness, pRainfallIntensity, inKsat, IT_din_lin_Multiband_Coverage, pm); + + // Dump results to file + if (doSaveByProducts) { + String message = "Dumping maps of Psi at bedrock in the pore pressure positive zones to "; + MapDumpingFunctions.dumpMultiBandCoverage(mapPsiMultiHours_Eq12, pOutFolder, null, message); + } + + // Export map references for allowing testing + out_psi_b_Eq12_Raster = mapPsiMultiHours_Eq12; + + // ################################################################################## + // Compute maps of combined Pressure at soil-bedrock interface (Psi) + // + // This matrix is the combination of the two psi matrices computed for different conditions + // + // = mapPsiMultiHours_Eq9 (Eq. 9) for t < t_wt (during infiltration) + // = mapPsiMultiHours_Eq12 (Eq.12) for t < t_tw but t > t_wt_up (during infiltration but with active lateral flow from catchment) + // ( D = simulation duration ) + pm.message(" "); + pm.message("### Compute maps of combined Pressure at soil-bedrock interface. ##"); + pm.message(" "); + + GridCoverage2D mapPsiMultiHours_Combined_Eq9_Eq12 = MapCalculationFunctions.computeMapOfPsiCombined_Eq9_Eq12(y, mapPsiMultiHours_Eq9, mapPsiMultiHours_Eq12, inSoilThickness, pm); + + if (doSaveByProducts) { + String message = "Dumping maps of Combined Psi at bedrock to "; + MapDumpingFunctions.dumpMultiBandCoverage(mapPsiMultiHours_Combined_Eq9_Eq12, pOutFolder, null, message); + } + + // Export map references for allowing testing + out_psi_b_Combined_Raster = mapPsiMultiHours_Combined_Eq9_Eq12; + pm.message("### Calculation of combined Psi map completed ###"); + pm.message("##########################################################################################################"); + + + // ################################################################################## + // Compute Safety Factor with infinite slope model and hydrologic control ####### + // 2. SF for t=1...D + // + // Equation (14a) & (14b) of reference paper + // + // but using combined Psi from Eq.(9) and Eq.(12) instead of initial Psi map + // + pm.message(" "); + pm.message("##########################################################################################################"); + pm.message("### Compute the HYDROLOGY-and-GEOMECHANIC driven SAFETY FACTOR for: R.Time="+y+"y & RainDuration="+h+"h ##"); + pm.message(" "); + + //GridCoverage2D mapSafetyFactor_InfiniteSlope_with_SaturatedZones = MapCalculationFunctions.computeSafetyFactor_InfiniteSlope_with_SaturatedZones(y, h, mapPsiMultiHours_Combined_Eq9_Eq12, inSoilThickness, inPhi, inGammaSoil, inCohesion, inAlfaVanGen, inNVanGen, inSlopeFixZeroValuesAndBorder, pm); + GridCoverage2D mapSafetyFactor_InfiniteSlope_with_SaturatedZones_SingleBand = MapCalculationFunctions.computeSafetyFactorInfiniteSlopeWithSaturatedZonesSingleBand(y, h, mapPsiMultiHours_Combined_Eq9_Eq12, inSoilThickness, inPhi, inGammaSoil, inCohesion, inAlfaVanGen, inNVanGen, inSlopeFixZeroValuesAndBorder, pm); + + // Dump results to file + if (doSaveByProducts) { + String message = "Dumping maps of HYDROLOGY-and-GEOMECHANIC driven SAFETY FACTOR to "; + MapDumpingFunctions.dumpSingleBandCoverage(mapSafetyFactor_InfiniteSlope_with_SaturatedZones_SingleBand, pOutFolder, pm, message); + } + // Export map references for allowing testing + out_SafetyFactor_InfiniteSlope_accounting_for_SaturatedZones_Raster = mapSafetyFactor_InfiniteSlope_with_SaturatedZones_SingleBand; + + mapsSafetyFactor_InfSlope_with_SaturZones_LastHour[durationArrayStep] = mapSafetyFactor_InfiniteSlope_with_SaturatedZones_SingleBand; + + } // Step to next simulated Rainfall Duration [h] + + // ################################################################################## + // Condense all computed Safety Factor maps into an overall one basing on worst-case# + + pm.message(" "); + pm.message("######################################################################################"); + pm.message("######################################################################################"); + pm.errorMessage("### Merging all final SAFETY FACTOR maps computed for RETURN TIME: "+y+"y ##"); + pm.message(" "); + + GridCoverage2D mapSafetyFactor_InfiniteSlope_with_SaturatedZones_RetTime_TOTAL = MapCalculationFunctions.computeSafetyFactorTOTAL(mapsSafetyFactor_InfSlope_with_SaturZones_LastHour, y, pm); + + MapDumpingFunctions.dumpSingleBandCoverage(mapSafetyFactor_InfiniteSlope_with_SaturatedZones_RetTime_TOTAL, pOutFolder, pm); + + out_SafetyFactor_InfiniteSlope_accounting_for_SaturatedZones_RetTime_TOTAL_Raster = mapSafetyFactor_InfiniteSlope_with_SaturatedZones_RetTime_TOTAL; + + pm.message(" "); + pm.message("######################################################################################"); + pm.message("######################################################################################"); + pm.message(" "); + + } // Step to next simulated Return Time [year] + + // ################################################################################## + // ################################################################################## + // ################################################################################## + // ### END OF LOOPS BETWEEN Return Times AND Rainfall Durations ##################### + // ################################################################################## + // ################################################################################## + // ################################################################################## + + + + + if (doCalculateInitialSafetyFactor) { + // ################################################################################## + // Calculation of Safety Factor with infinite slope model and initial Psi ####### + // 1. Initial SF (based on theta_I) ##==## theta_I is in paper 'V' + // + // Equation (14a) & (14b) + // + // inPsiInitAtBedrock is usually a matrix of 0.05 values covering the whole basin + // + pm.message(" "); + pm.message("######################################################################################"); + pm.message("### Compute the INITIAL SAFETY FACTOR drivend by geo-technic an hydrologic forces ##"); + pm.message(" "); + + GridCoverage2D mapSafetyFactor_Initial = MapCalculationFunctions.computeSafetyFactor_Initial(inPsiInitAtBedrock, inSoilThickness, inPhi, inGammaSoil, inCohesion, inAlfaVanGen, inNVanGen, inSlopeFixZeroValuesAndBorder, pm); + + // Dump results to file + + MapDumpingFunctions.dumpSingleBandCoverage(mapSafetyFactor_Initial, pOutFolder, pm); + + // Export map references for allowing testing + out_SafetyFactor_Initial_Raster = mapSafetyFactor_Initial; + + } + + pm.message(" "); + pm.message("######################################################################################"); + pm.message("### !!! --- Cislam model completed successfully --- !!! ##"); + pm.message("######################################################################################"); + pm.message("######################################################################################"); + pm.message("######################################################################################"); + pm.message(" "); + + // End of maps computation + // ################################################################################## + + } + + private GridCoverage2D getTwsMap( HashMap mapsOfTwt, int year, int hour ) { + + // Cycle in the Twt map set to extract the map corresponding the current Return Time year (y) and rainfall simulation duration (h) + Set s = mapsOfTwt.keySet(); + Iterator i = s.iterator(); + Integer[] key = null; + while( i.hasNext() ) { + Integer[] keyTmp = i.next(); + if (keyTmp[0] == hour && keyTmp[1] == year) { + key = keyTmp; + GridCoverage2D mapTwt = mapsOfTwt.get(key); + return mapTwt; + } + } + return null; + } + +} diff --git a/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/OmsCislam.ucd b/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/OmsCislam.ucd new file mode 100644 index 000000000..0154ed8c7 --- /dev/null +++ b/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/OmsCislam.ucd @@ -0,0 +1,375 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/OmsCislamPakage.ucd b/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/OmsCislamPakage.ucd new file mode 100644 index 000000000..29d428d5c --- /dev/null +++ b/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/OmsCislamPakage.ucd @@ -0,0 +1,372 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utility_models/OmsPsiInitAtBedrock.java b/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utility_models/OmsPsiInitAtBedrock.java new file mode 100644 index 000000000..157efa0b4 --- /dev/null +++ b/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utility_models/OmsPsiInitAtBedrock.java @@ -0,0 +1,152 @@ +/* + * This file is part of the "CI-slam module": an addition to JGrassTools + * It has been entirely contributed by Marco Foi (www.mcfoi.it) + * + * "CI-slam module" is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.utility_models; + +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_AUTHORCONTACTS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_AUTHORNAMES; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_LICENSE; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSPSIINITATBEDROCK_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSPSIINITATBEDROCK_KEYWORDS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSPSIINITATBEDROCK_NAME; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSPSIINITATBEDROCK_outPsiInitAtBedrock_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSPSIINITATBEDROCK_pPsiInitAtBedrockConstant_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSPSIINITATBEDROCK_STATUS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_SUBMODULES_LABEL; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inPit_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inSoilThickness_DESCRIPTION; + +import java.awt.image.WritableRaster; + +import javax.media.jai.iterator.RandomIter; +import javax.media.jai.iterator.RandomIterFactory; +import javax.media.jai.iterator.WritableRandomIter; + +import oms3.annotations.Author; +import oms3.annotations.Description; +import oms3.annotations.Execute; +import oms3.annotations.In; +import oms3.annotations.Keywords; +import oms3.annotations.Label; +import oms3.annotations.License; +import oms3.annotations.Name; +import oms3.annotations.Out; +import oms3.annotations.Status; +import oms3.annotations.Unit; + +import org.geotools.coverage.grid.GridCoverage2D; +import org.jgrasstools.gears.libs.exceptions.ModelsIllegalargumentException; +import org.jgrasstools.gears.libs.modules.JGTConstants; +import org.jgrasstools.gears.libs.modules.JGTModel; +import org.jgrasstools.gears.utils.RegionMap; +import org.jgrasstools.gears.utils.coverage.CoverageUtilities; + +@Description(OMSCISLAM_OMSPSIINITATBEDROCK_DESCRIPTION) +@Author(name = OMSCISLAM_AUTHORNAMES, contact = OMSCISLAM_AUTHORCONTACTS) +@Keywords(OMSCISLAM_OMSPSIINITATBEDROCK_KEYWORDS) +@Label(OMSCISLAM_SUBMODULES_LABEL) +@Name(OMSCISLAM_OMSPSIINITATBEDROCK_NAME) +@Status(OMSCISLAM_OMSPSIINITATBEDROCK_STATUS) +@License(OMSCISLAM_LICENSE) +public class OmsPsiInitAtBedrock extends JGTModel { + + public final double DEFAULT_PSI_CONSTANT = 0.05; + + @Description(OMSCISLAM_inPit_DESCRIPTION) + @Unit("m") + @In + public GridCoverage2D inPit = null; + + @Description(OMSCISLAM_inSoilThickness_DESCRIPTION) + @Unit("m") + @In + public GridCoverage2D inSoilThickness = null; + + @Description(OMSCISLAM_OMSPSIINITATBEDROCK_pPsiInitAtBedrockConstant_DESCRIPTION) + @Unit("m") + @In + public double pPsiInitAtBedrockConstant = 0.0; + + @Description(OMSCISLAM_OMSPSIINITATBEDROCK_outPsiInitAtBedrock_DESCRIPTION) + @Unit("m") + @Out + public GridCoverage2D outPsiInitAtBedrock = null; + + @Execute + public void process() { + if (!concatOr(outPsiInitAtBedrock == null, doReset)) { + return; + } + // Either Pit or Soil Thickness are required to compute RegionMap and CRS + if (inPit == null && inSoilThickness == null) { + throw new ModelsIllegalargumentException("Either Pit or Soil Thickness are required to run the model. Check your input...", + this.getClass().getSimpleName()); + } + + GridCoverage2D refmap; + if (inPit != null) { + refmap = inPit; + } else { + refmap = inSoilThickness; + } + RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(refmap); + int cols = regionMap.getCols(); + int rows = regionMap.getRows(); + + WritableRaster mPsiInitAtBedrockWR = CoverageUtilities.createDoubleWritableRaster(cols, rows, null, null, + JGTConstants.doubleNovalue); + WritableRandomIter mPsiInitAtBedrockIter = RandomIterFactory.createWritable(mPsiInitAtBedrockWR, null); + + if (inSoilThickness == null && (pPsiInitAtBedrockConstant == 0 || pPsiInitAtBedrockConstant == JGTConstants.doubleNovalue)) { + pm.message("No soil map nor constant Psi was provided: the model will fall back on using a predefinde Psi constant of 0.05m for the whole basin."); + RandomIter pitIter = RandomIterFactory.create(inPit.getRenderedImage(), null); + for( int r = 0; r < rows; r++ ) { + for( int c = 0; c < cols; c++ ) { + if (!Double.isNaN(pitIter.getSampleDouble(c, r, 0))) { + mPsiInitAtBedrockIter.setSample(c, r, 0, DEFAULT_PSI_CONSTANT); + } + } + } + } else if (inSoilThickness == null && pPsiInitAtBedrockConstant != 0) { + pm.message("The module will produce a map with the provided constant Psi value."); + RandomIter pitIter = RandomIterFactory.create(inPit.getRenderedImage(), null); + for( int r = 0; r < rows; r++ ) { + for( int c = 0; c < cols; c++ ) { + if (!Double.isNaN(pitIter.getSampleDouble(c, r, 0))) { + mPsiInitAtBedrockIter.setSample(c, r, 0, pPsiInitAtBedrockConstant); + } + } + } + } else if (inSoilThickness != null) { + pm.message("Since a soil map has been provided, the Psi map will be computed using the formula [1-(soil-thickness)]"); + RandomIter soilThicknessIter = RandomIterFactory.create(inSoilThickness.getRenderedImage(), null); + for( int r = 0; r < rows; r++ ) { + for( int c = 0; c < cols; c++ ) { + double sT = soilThicknessIter.getSampleDouble(c, r, 0); + if ( !Double.isNaN(sT) ) { + mPsiInitAtBedrockIter.setSample(c, r, 0, (1.0 - sT)); + } + } + } + } + + outPsiInitAtBedrock = CoverageUtilities.buildCoverage("PsiInitAtBedrock", mPsiInitAtBedrockWR, regionMap, + refmap.getCoordinateReferenceSystem()); + + } + +} diff --git a/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utility_models/OmsSafetyFactorGeomechanic.java b/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utility_models/OmsSafetyFactorGeomechanic.java new file mode 100644 index 000000000..85e971939 --- /dev/null +++ b/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utility_models/OmsSafetyFactorGeomechanic.java @@ -0,0 +1,266 @@ +package org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.utility_models; + +import static org.jgrasstools.gears.libs.modules.JGTConstants.isNovalue; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_AUTHORCONTACTS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_AUTHORNAMES; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_LICENSE; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSAFETYFACTORGEOMECHANIC_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSAFETYFACTORGEOMECHANIC_KEYWORDS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSAFETYFACTORGEOMECHANIC_NAME; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSAFETYFACTORGEOMECHANIC_STATUS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSAFETYFACTORGEOMECHANIC_outSafetyactorGeoMechanic_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_SUBMODULES_LABEL; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inCohesion_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inGamma_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inKsat_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inPhi_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inSlope_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inSoilThickness_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inTheta_r_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inTheta_s_DESCRIPTION; + +import java.awt.image.WritableRaster; + +import javax.media.jai.iterator.RandomIter; +import javax.media.jai.iterator.RandomIterFactory; +import javax.media.jai.iterator.WritableRandomIter; + +import oms3.annotations.Author; +import oms3.annotations.Description; +import oms3.annotations.Execute; +import oms3.annotations.In; +import oms3.annotations.Keywords; +import oms3.annotations.Label; +import oms3.annotations.License; +import oms3.annotations.Name; +import oms3.annotations.Out; +import oms3.annotations.Status; +import oms3.annotations.UI; +import oms3.annotations.Unit; + +import org.geotools.coverage.grid.GridCoverage2D; +import org.jgrasstools.gears.libs.modules.JGTConstants; +import org.jgrasstools.gears.libs.modules.JGTModel; +import org.jgrasstools.gears.libs.monitor.IJGTProgressMonitor; +import org.jgrasstools.gears.utils.RegionMap; +import org.jgrasstools.gears.utils.coverage.CoverageUtilities; +import org.opengis.referencing.crs.CoordinateReferenceSystem; + +@Description(OMSCISLAM_OMSAFETYFACTORGEOMECHANIC_DESCRIPTION) +@Author(name = OMSCISLAM_AUTHORNAMES, contact = OMSCISLAM_AUTHORCONTACTS) +@Keywords(OMSCISLAM_OMSAFETYFACTORGEOMECHANIC_KEYWORDS) +@Label(OMSCISLAM_SUBMODULES_LABEL) +@Name(OMSCISLAM_OMSAFETYFACTORGEOMECHANIC_NAME) +@Status(OMSCISLAM_OMSAFETYFACTORGEOMECHANIC_STATUS) +@License(OMSCISLAM_LICENSE) +public class OmsSafetyFactorGeomechanic extends JGTModel { + + @Description(OMSCISLAM_inSlope_DESCRIPTION) + @In + public GridCoverage2D inSlope = null; + + @Description(OMSCISLAM_inSoilThickness_DESCRIPTION) + @Unit("m") + @In + public GridCoverage2D inSoilThickness = null; + + // ############################################# + // Geo-Techical parameters + // ############################################# + @Description(OMSCISLAM_inCohesion_DESCRIPTION) + @Unit("kPa") + @In + public GridCoverage2D inCohesion = null; + + @Description(OMSCISLAM_inPhi_DESCRIPTION) + @In + public GridCoverage2D inPhi = null; + + @Description(OMSCISLAM_inGamma_DESCRIPTION) + @In + public GridCoverage2D inGammaSoil = null; + + @Description(OMSCISLAM_inKsat_DESCRIPTION) + @Unit("m/s") + @In + public GridCoverage2D inKsat = null; + + @Description(OMSCISLAM_inTheta_s_DESCRIPTION) + @Unit("-") + @In + public GridCoverage2D inTheta_s = null; + + @Description(OMSCISLAM_inTheta_r_DESCRIPTION) + @Unit("-") + @In + public GridCoverage2D inTheta_r = null; + + @Description(OMSCISLAM_OMSAFETYFACTORGEOMECHANIC_outSafetyactorGeoMechanic_DESCRIPTION) + @Unit("-") + @Out + public GridCoverage2D outSafetyactorGeoMechanic = null; + + @Execute + public void process() { + + /* + * model.inSlope = inSlope; model.inPhi = inPhi; model.inCohesion = + * inCohesion; model.inGammaSoil = inGammaSoil; model.inSoilThickness = + * inSoilThickness; + */ + + /** + * Computes a geo-technical SafetyFactor Map This calculation does not + * take into account hydrologic factors that may negatively affect the + * result. This means that map areas that do not even stand the test of + * this geo-technical safety factor will surely result in not stable + * areas even when hydrology is taken into account. + * + * @param slopeMap + * The user provided slope map: can be computed using + * {@link OmsSlope} model + * @param phiMap + * The user provided phi map (effective frictional angle) + * @param cochesionMap + * The user provided effective cohesion map + * @param gammaMap + * The user provided gamma map (density) + * @param soil_thicknessMap + * The user provided soil_thickness map: can be computed + * using {@link OmsSoilThickness} model + * @param pm2 + * @return + */ + RegionMap regionMap = CoverageUtilities + .getRegionParamsFromGridCoverage(inSlope); + int cols = regionMap.getCols(); + int rows = regionMap.getRows(); + double xRes = regionMap.getXres(); + double yRes = regionMap.getYres(); + + CoordinateReferenceSystem crs = inSlope.getCoordinateReferenceSystem(); + + RandomIter slopeIter = CoverageUtilities.getRandomIterator(inSlope); + RandomIter phiIter = CoverageUtilities.getRandomIterator(inPhi); + RandomIter cochesionIter = CoverageUtilities + .getRandomIterator(inCohesion); + RandomIter gammaIter = CoverageUtilities.getRandomIterator(inGammaSoil); + RandomIter soil_thicknessIter = CoverageUtilities + .getRandomIterator(inSoilThickness); + + WritableRaster outSafetyFactorGeoTechnicalWR = CoverageUtilities + .createDoubleWritableRaster(cols, rows, null, null, + JGTConstants.doubleNovalue); + WritableRandomIter outSafetyFactorGeoTechnicalIter = RandomIterFactory + .createWritable(outSafetyFactorGeoTechnicalWR, null); + + pm.beginTask("Start Safety Factor computation..", rows); //$NON-NLS-1$ + + double slope, phi, cohesion, gamma, soil_thickness, FSi; + // Cycling into the valid region. + for (int r = 0; r < rows; r++) { + for (int c = 0; c < cols; c++) { + + if (!isNovalue(slopeIter.getSampleDouble(c, r, 0))) { + + slope = slopeIter.getSampleDouble(c, r, 0); + phi = phiIter.getSampleDouble(c, r, 0); + cohesion = cochesionIter.getSampleDouble(c, r, 0); + gamma = gammaIter.getSampleDouble(c, r, 0); + soil_thickness = soil_thicknessIter + .getSampleDouble(c, r, 0); + + // Quickfix to inconsistent input + // TODO : remove this once model implements input check + // https://bitbucket.org/mcfoi/jgrasstool-clone/issue/1/quickfix-to-inconsistent-input-in + double[] args = checkInputQuickfix(new double[] { slope, + phi, cohesion, gamma, soil_thickness }, pm); + slope = args[0]; + phi = args[1]; + cohesion = args[2]; + gamma = args[3]; + soil_thickness = args[4]; + // end of Quickfix + + FSi = Math.tan(phi / 180 * Math.PI) + / slope + + (2 * cohesion) + / (gamma * soil_thickness * Math.sin(2 * Math + .atan(slope))); + if (Double.isInfinite(FSi)) + pm.message("Output data contains INFINITE Safety Factor!"); + else + outSafetyFactorGeoTechnicalIter.setSample(c, r, 0, FSi); + } + } + pm.worked(1); + } + pm.done(); + + GridCoverage2D outSafetyFactor = CoverageUtilities.buildCoverage( + "safetyfactor", outSafetyFactorGeoTechnicalWR, regionMap, crs); + outSafetyactorGeoMechanic = outSafetyFactor; + + } + + /** + * Checks whether Safety Factor inputs satisfy computational requirements + * This method is deprecated and has to be replaced with sound input + * checking policy at model level + * + * @deprecated + * @param args + * slope phi cohesion gamma soil_thicknes + * @return double[] containing computational safe values + */ + private static double[] checkInputQuickfix(double[] args, + IJGTProgressMonitor pm) { + + for (int i = 0; i < args.length; i++) { + if (args[i] == 0.0) { + String message = null; + switch (i) { + case 0: + message = "slope"; + pm.errorMessage("An invalid value of " + message + + " has been fixed on the fly! [" + args[i] + "]"); + args[i] = 0.009; // slope + pm.errorMessage("<==" + args[i]); + break; + case 1: + message = "phi"; + pm.errorMessage("An invalid value of " + message + + " has been fixed on the fly! [" + args[i] + "]"); + args[i] = 30.0; // phi + pm.errorMessage("<==" + args[i]); + break; + case 2: + message = "cohesion"; + pm.errorMessage("An invalid value of " + message + + " has been fixed on the fly! [" + args[i] + "]"); + args[i] = 1.0; // cohesion + pm.errorMessage("<==" + args[i]); + break; + case 3: + message = "gamma"; + pm.errorMessage("An invalid value of " + message + + " has been fixed on the fly! [" + args[i] + "]"); + args[i] = 18.0; // gamma soil + pm.errorMessage("<==" + args[i]); + break; + case 4: + message = "soil_thicknes"; + pm.errorMessage("\nAn invalid value of " + message + + " has been fixed on the fly! [" + args[i] + "]"); + args[i] = 0.1; // soil_thicknes + pm.errorMessage("<==" + args[i] + "\n"); + break; + default: + break; + } + } + } + return args; + } + +} diff --git a/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utility_models/OmsSafetyFactorsWorstCaseComposer.java b/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utility_models/OmsSafetyFactorsWorstCaseComposer.java new file mode 100644 index 000000000..ca7fac661 --- /dev/null +++ b/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utility_models/OmsSafetyFactorsWorstCaseComposer.java @@ -0,0 +1,70 @@ +package org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.utility_models; + +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_AUTHORCONTACTS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_AUTHORNAMES; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_LICENSE; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSSAFETYFACTORCOMPOSER_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSSAFETYFACTORCOMPOSER_KEYWORDS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSSAFETYFACTORCOMPOSER_NAME; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSSAFETYFACTORCOMPOSER_STATUS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSSAFETYFACTORCOMPOSER_inRasters_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSSAFETYFACTORCOMPOSER_outSafetyFactorTotal_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSSAFETYFACTORCOMPOSER_pReturnTime_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_SUBMODULES_LABEL; + +import java.util.List; + +import oms3.annotations.Author; +import oms3.annotations.Description; +import oms3.annotations.Execute; +import oms3.annotations.In; +import oms3.annotations.Keywords; +import oms3.annotations.Label; +import oms3.annotations.License; +import oms3.annotations.Name; +import oms3.annotations.Out; +import oms3.annotations.Status; + +import org.geotools.coverage.grid.GridCoverage2D; +import org.jgrasstools.gears.libs.modules.JGTModel; +import org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.utils.MapCalculationFunctions; + + +@Description(OMSCISLAM_OMSSAFETYFACTORCOMPOSER_DESCRIPTION) +@Author(name = OMSCISLAM_AUTHORNAMES, contact = OMSCISLAM_AUTHORCONTACTS) +@Keywords(OMSCISLAM_OMSSAFETYFACTORCOMPOSER_KEYWORDS) +@Label(OMSCISLAM_SUBMODULES_LABEL) +@Name(OMSCISLAM_OMSSAFETYFACTORCOMPOSER_NAME) +@Status(OMSCISLAM_OMSSAFETYFACTORCOMPOSER_STATUS) +@License(OMSCISLAM_LICENSE) +public class OmsSafetyFactorsWorstCaseComposer extends JGTModel { + + @Description(OMSCISLAM_OMSSAFETYFACTORCOMPOSER_inRasters_DESCRIPTION) + @In + public List inRasters; + + @Description(OMSCISLAM_OMSSAFETYFACTORCOMPOSER_pReturnTime_DESCRIPTION) + @In + public int pReturnTime; + + @Description(OMSCISLAM_OMSSAFETYFACTORCOMPOSER_outSafetyFactorTotal_DESCRIPTION) + @Out + public GridCoverage2D outSafetyFactorTotal; + + @Execute + public void process(){ + + GridCoverage2D[] inRastersArray = new GridCoverage2D[inRasters.size()]; + + // gather maps + int i = 0; + for( GridCoverage2D mapGC : inRasters ) { + inRastersArray[i] = mapGC; + i++; + } + + outSafetyFactorTotal = MapCalculationFunctions.computeSafetyFactorTOTAL(inRastersArray, pReturnTime, pm); + + } + +} \ No newline at end of file diff --git a/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utility_models/OmsSlopeForCislam.java b/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utility_models/OmsSlopeForCislam.java new file mode 100644 index 000000000..26f0f766b --- /dev/null +++ b/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utility_models/OmsSlopeForCislam.java @@ -0,0 +1,85 @@ +/* + * This file is part of the "CI-slam module": an addition to JGrassTools + * It has been entirely contributed by Marco Foi (www.mcfoi.it) + * + * "CI-slam module" is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.utility_models; + +//import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSSHALSTAB_inSlope_DESCRIPTION; +//import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSASPECT_doRound_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_AUTHORCONTACTS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_AUTHORNAMES; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_LICENSE; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSSLOPEFORCISLAM_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSSLOPEFORCISLAM_KEYWORDS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSSLOPEFORCISLAM_NAME; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSSLOPEFORCISLAM_STATUS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_SUBMODULES_LABEL; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inPit_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inSlope_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_pMinSlope_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSSLOPEFORCISLAM_outSlope_DESCRIPTION; +import oms3.annotations.Author; +import oms3.annotations.Description; +import oms3.annotations.Execute; +import oms3.annotations.In; +import oms3.annotations.Keywords; +import oms3.annotations.Label; +import oms3.annotations.License; +import oms3.annotations.Name; +import oms3.annotations.Out; +import oms3.annotations.Range; +import oms3.annotations.Status; +import oms3.annotations.Unit; + +import org.geotools.coverage.grid.GridCoverage2D; +import org.jgrasstools.gears.libs.modules.JGTModel; +import org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.utils.MapPreprocessingUtilities; + +@Description(OMSCISLAM_OMSSLOPEFORCISLAM_DESCRIPTION) +@Author(name = OMSCISLAM_AUTHORNAMES, contact = OMSCISLAM_AUTHORCONTACTS) +@Keywords(OMSCISLAM_OMSSLOPEFORCISLAM_KEYWORDS) +@Label(OMSCISLAM_SUBMODULES_LABEL) +@Name(OMSCISLAM_OMSSLOPEFORCISLAM_NAME) +@Status(OMSCISLAM_OMSSLOPEFORCISLAM_STATUS) +@License(OMSCISLAM_LICENSE) +public class OmsSlopeForCislam extends JGTModel { + + @Description(OMSCISLAM_inSlope_DESCRIPTION) + @Unit("m/m") + @In + public GridCoverage2D inSlope = null; + + @Description(OMSCISLAM_inPit_DESCRIPTION) + @Unit("m") + @In + public GridCoverage2D inPit = null; + + @Description(OMSCISLAM_pMinSlope_DESCRIPTION) + @Unit("m/m") + @Range(min = 0.000001, max = 58.0) + @In + public double pMinSlope = 0.0090; + + @Description(OMSCISLAM_OMSSLOPEFORCISLAM_outSlope_DESCRIPTION) + @Unit("m/m") + @Out + public GridCoverage2D outSlope = null; + + @Execute + public void process() { + outSlope = MapPreprocessingUtilities.slopeMapFixZeroValuesAndBorder(inPit, inSlope, pMinSlope, pm); + } +} \ No newline at end of file diff --git a/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utility_models/OmsSoilThickness.java b/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utility_models/OmsSoilThickness.java new file mode 100644 index 000000000..87ec28e25 --- /dev/null +++ b/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utility_models/OmsSoilThickness.java @@ -0,0 +1,185 @@ +/* + * This file is part of the "CI-slam module": an addition to JGrassTools + * It has been entirely contributed by Marco Foi (www.mcfoi.it) + * + * "CI-slam module" is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.utility_models; + +//import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSSHALSTAB_inSlope_DESCRIPTION; +//import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSASPECT_doRound_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_AUTHORCONTACTS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_AUTHORNAMES; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_LICENSE; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSSLOPEFORCISLAM_inSlope_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSSOILTHICKNESS_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSSOILTHICKNESS_KEYWORDS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSSOILTHICKNESS_NAME; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSSOILTHICKNESS_STATUS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_SUBMODULES_LABEL; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSSOILTHICKNESS_outSoilThickness_DESCRIPTION; + +import java.awt.image.RenderedImage; +import java.awt.image.WritableRaster; + +import javax.media.jai.iterator.RandomIter; +import javax.media.jai.iterator.RandomIterFactory; +import javax.media.jai.iterator.WritableRandomIter; + +import oms3.annotations.Author; +import oms3.annotations.Description; +import oms3.annotations.Execute; +import oms3.annotations.In; +import oms3.annotations.Keywords; +import oms3.annotations.Label; +import oms3.annotations.License; +import oms3.annotations.Name; +import oms3.annotations.Out; +import oms3.annotations.Status; +import oms3.annotations.Unit; + +import org.geotools.coverage.grid.GridCoverage2D; +import org.jgrasstools.gears.libs.exceptions.ModelsIllegalargumentException; +import org.jgrasstools.gears.libs.modules.GridNode; +import org.jgrasstools.gears.libs.modules.JGTConstants; +import org.jgrasstools.gears.libs.modules.JGTModel; +import org.jgrasstools.gears.utils.RegionMap; +import org.jgrasstools.gears.utils.coverage.CoverageUtilities; +import org.jgrasstools.hortonmachine.i18n.HortonMessageHandler; +//import org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.i18n.HortonMessageHandler; +import org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.utils.MapPreprocessingUtilities; + +@Description(OMSCISLAM_OMSSOILTHICKNESS_DESCRIPTION) +@Author(name = OMSCISLAM_AUTHORNAMES, contact = OMSCISLAM_AUTHORCONTACTS) +@Keywords(OMSCISLAM_OMSSOILTHICKNESS_KEYWORDS) +@Label(OMSCISLAM_SUBMODULES_LABEL) +@Name(OMSCISLAM_OMSSOILTHICKNESS_NAME) +@Status(OMSCISLAM_OMSSOILTHICKNESS_STATUS) +@License(OMSCISLAM_LICENSE) +public class OmsSoilThickness extends JGTModel { + + @Description(OMSCISLAM_OMSSLOPEFORCISLAM_inSlope_DESCRIPTION) + @Unit("m/m") + @In + public GridCoverage2D inSlope = null; + + @Description(OMSCISLAM_OMSSOILTHICKNESS_outSoilThickness_DESCRIPTION) + @Unit("m") + @Out + public GridCoverage2D outSoilThickness = null; + + private HortonMessageHandler msg = HortonMessageHandler.getInstance(); + + @Execute + public void process() throws Exception { + if (!concatOr(outSoilThickness == null, doReset)) { + return; + } + checkNull(inSlope); + + // Check if input map is valid for computation + if (!MapPreprocessingUtilities.isValidSlopeMap(inSlope, pm)) { + String errorMessage = "Input Slope map does not meet requirements. Consider using OmsSlopeForCislam module."; + pm.errorMessage(errorMessage); + throw new ModelsIllegalargumentException(errorMessage, this); + } else { + pm.message(msg.message("cislam.omssoilthickness.validslopemapprovided")); + } + + RegionMap regionMap = CoverageUtilities + .getRegionParamsFromGridCoverage(inSlope); + int cols = regionMap.getCols(); + int rows = regionMap.getRows(); + double xRes = regionMap.getXres(); + double yRes = regionMap.getYres(); + + // Prepare tools for iterating over the slope map + RenderedImage slopeRI = inSlope.getRenderedImage(); + RandomIter slopeRandomIter = RandomIterFactory.create(slopeRI, null); + + // Prepare data structures for storing soil thickness + WritableRaster soilThicknessWR = CoverageUtilities + .createDoubleWritableRaster(cols, rows, null, null, + JGTConstants.doubleNovalue); + WritableRandomIter soilThicknessIter = RandomIterFactory + .createWritable(soilThicknessWR, null); + + // Send message to progress monitor + pm.beginTask("Calculating soil thickness...", rows); + + double slopeCurrent; + double soilthickness = 0; + // Cycling into the valid region. + for (int r = 1; r < rows - 1; r++) { + for (int c = 1; c < cols - 1; c++) { + // GridNode node = new GridNode(slopeRandomIter, cols, rows, + // xRes, yRes, c, r); + slopeCurrent = slopeRandomIter.getSampleDouble(c, r, 0); + // The following will not work as getSampleDouble returns a + // Double.NaN + // if (slopeCurrent != JGTConstants.doubleNovalue) { + if (Double.isInfinite(slopeCurrent)) { + pm.errorMessage("Infinite value spotted in slope map: fix before proceeding. Now aborting!" ); + return; + } + if (slopeCurrent==0.0) { + pm.errorMessage("Zero value spotted in slope map: fix with OmsSlopeForCislam before proceeding. Now aborting!" ); + return; + } + if (!Double.isNaN(slopeCurrent)) { + soilthickness = calculateSoilThickness(slopeCurrent); + } else { + soilthickness = JGTConstants.doubleNovalue; + } + + // Use the iterator to write in the writable raster. + soilThicknessIter.setSample(c, r, 0, soilthickness); + + } + pm.worked(1); + } + pm.done(); + + CoverageUtilities.setNovalueBorder(soilThicknessWR); + outSoilThickness = CoverageUtilities.buildCoverage("soilthikness", + soilThicknessWR, regionMap, + inSlope.getCoordinateReferenceSystem()); + + } + + /** + * Calculates the soil thickness in a given {@link GridNode}. Implements + * logic from Equation 20 of reference paper: Lanni et Al. (2012) on Hydrol. + * Earth Syst. Sci., 16, 3959-3971 Note that + * + * @param slopeCurrent + * the current grid node. + * @param slope + * (tan_beta) at the current grid node + * @return the value of aspect. + */ + public static double calculateSoilThickness(double slopeCurrent) { + + double soilThickness; + if (slopeCurrent <= Math.tan(90.0 / 180.0 * Math.PI)) { + soilThickness = 1.006 - 0.85 * slopeCurrent; + if (soilThickness < 0.1) + soilThickness = 0.1; + } else { + soilThickness = 0.0; + } + return soilThickness; + } + +} diff --git a/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utility_models/OmsV0.java b/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utility_models/OmsV0.java new file mode 100644 index 000000000..5edd6ae78 --- /dev/null +++ b/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utility_models/OmsV0.java @@ -0,0 +1,169 @@ +/* + * This file is part of the "CI-slam module": an addition to JGrassTools + * It has been entirely contributed by Marco Foi (www.mcfoi.it) + * + * "CI-slam module" is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.utility_models; + +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_AUTHORCONTACTS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_AUTHORNAMES; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_LICENSE; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSV0_STATUS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_SUBMODULES_LABEL; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSV0_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSV0_KEYWORDS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSV0_NAME; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inAlfaVanGen_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inNVanGen_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inSoilThickness_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSV0_inPsiInitAtBedrock_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSV0_outV0_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inTheta_r_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inTheta_s_DESCRIPTION; + +import java.awt.image.WritableRaster; + +import javax.media.jai.iterator.RandomIter; +import javax.media.jai.iterator.RandomIterFactory; +import javax.media.jai.iterator.WritableRandomIter; + +import oms3.annotations.Author; +import oms3.annotations.Description; +import oms3.annotations.Execute; +import oms3.annotations.In; +import oms3.annotations.Keywords; +import oms3.annotations.Label; +import oms3.annotations.License; +import oms3.annotations.Name; +import oms3.annotations.Out; +import oms3.annotations.Status; +import oms3.annotations.Unit; + +import org.geotools.coverage.grid.GridCoverage2D; +import org.jgrasstools.gears.libs.modules.JGTConstants; +import org.jgrasstools.gears.libs.modules.JGTModel; +import org.jgrasstools.gears.utils.RegionMap; +import org.jgrasstools.gears.utils.coverage.CoverageUtilities; + +@Description(OMSCISLAM_OMSV0_DESCRIPTION) +@Author(name = OMSCISLAM_AUTHORNAMES, contact = OMSCISLAM_AUTHORCONTACTS) +@Keywords(OMSCISLAM_OMSV0_KEYWORDS) +@Label(OMSCISLAM_SUBMODULES_LABEL) +@Name(OMSCISLAM_OMSV0_NAME) +@Status(OMSCISLAM_OMSV0_STATUS) +@License(OMSCISLAM_LICENSE) +public class OmsV0 extends JGTModel { + @Description(OMSCISLAM_inSoilThickness_DESCRIPTION) + @Unit("m") + @In + public GridCoverage2D inSoilThickness = null; + + @Description(OMSCISLAM_inTheta_s_DESCRIPTION) + @In + public GridCoverage2D inTheta_s = null; + + @Description(OMSCISLAM_inTheta_r_DESCRIPTION) + @In + public GridCoverage2D inTheta_r = null; + + @Description(OMSCISLAM_OMSV0_inPsiInitAtBedrock_DESCRIPTION) + @In + public GridCoverage2D inPsiInitAtBedrock = null; + + @Description(OMSCISLAM_inAlfaVanGen_DESCRIPTION) + @In + public GridCoverage2D inAlfaVanGen = null; + + @Description(OMSCISLAM_inNVanGen_DESCRIPTION) + @In + public GridCoverage2D inNVanGen = null; + + @Description(OMSCISLAM_OMSV0_outV0_DESCRIPTION) + @Out + public GridCoverage2D outV0 = null; + + @Execute + public void process() { + if (!concatOr(outV0 == null, doReset)) { + return; + } + checkNull(inSoilThickness, inTheta_r, inTheta_s, inPsiInitAtBedrock, inAlfaVanGen, inNVanGen); + + RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inSoilThickness); + int cols = regionMap.getCols(); + int rows = regionMap.getRows(); + + // Prepare objects for iterating over the maps + RandomIter theta_rIter = RandomIterFactory.create(inTheta_r.getRenderedImage(), null); + RandomIter theta_sIter = RandomIterFactory.create(inTheta_s.getRenderedImage(), null); + RandomIter psiInitAtBedrockIter = RandomIterFactory.create(inPsiInitAtBedrock.getRenderedImage(), null); + RandomIter soilThicknessIter = RandomIterFactory.create(inSoilThickness.getRenderedImage(), null); + RandomIter alfaVanGenuchtenIter = RandomIterFactory.create(inAlfaVanGen.getRenderedImage(), null); + RandomIter nVanGenuchtenIter = RandomIterFactory.create(inNVanGen.getRenderedImage(), null); + + WritableRaster mV0WR = CoverageUtilities.createDoubleWritableRaster(cols, rows, null, null, JGTConstants.doubleNovalue); + WritableRandomIter mV0Iter = RandomIterFactory.createWritable(mV0WR, null); + + double mV0 = 0.0; + pm.beginTask("Start computing V0 map (map of initial storage of soil moisture)...", rows); + for(int r = 0; r < rows; r++){ + for(int c = 0; c < cols; c++){ + double theta_r = theta_rIter.getSampleDouble(c, r, 0); + double theta_s = theta_sIter.getSampleDouble(c, r, 0); + double psi_i = psiInitAtBedrockIter.getSampleDouble(c, r, 0); + double soilThickness = soilThicknessIter.getSampleDouble(c, r, 0); + double alfaVanGenuchten = alfaVanGenuchtenIter.getSampleDouble(c, r, 0); + double nVanGenuchten = nVanGenuchtenIter.getSampleDouble(c, r, 0); + if(!Double.isNaN(soilThickness)){ + + mV0 = calculateNodeInitialSoilMoisture_V0(soilThickness, theta_s, theta_r, psi_i, alfaVanGenuchten, nVanGenuchten); + + //pm.message(Double.toString(mVwt)); + mV0Iter.setSample(c, r, 0, mV0); + } + } + pm.worked(1); + } + pm.done(); + + outV0 = CoverageUtilities.buildCoverage("V0", mV0WR, regionMap, inSoilThickness.getCoordinateReferenceSystem()); + + } + + public static double calculateNodeInitialSoilMoisture_V0(double soilThickness, double theta_s, double theta_r, double psi_i, double alfaVanGenuchten, double nVanGenuchten){ + double mV0 = (theta_r*soilThickness)+ + (theta_s - theta_r)* + ( + (soilThickness+psi_i)* + Math.pow(1+ + Math.pow( + (alfaVanGenuchten*(soilThickness+psi_i)), + (nVanGenuchten) + ), + (-1.0/nVanGenuchten) + ) + - + psi_i* + Math.pow(1+ + Math.pow( + (alfaVanGenuchten*psi_i), + (nVanGenuchten) + ), + (-1.0/nVanGenuchten) + ) + ); + return mV0; + } +} diff --git a/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utility_models/OmsVanGenuchtenMapsGenerator.java b/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utility_models/OmsVanGenuchtenMapsGenerator.java new file mode 100644 index 000000000..fee0c4027 --- /dev/null +++ b/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utility_models/OmsVanGenuchtenMapsGenerator.java @@ -0,0 +1,246 @@ +/* + * This file is part of the "CI-slam module": an addition to JGrassTools + * It has been entirely contributed by Marco Foi (www.mcfoi.it) + * + * "CI-slam module" is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.utility_models; + +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_AUTHORCONTACTS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_AUTHORNAMES; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_SUBMODULES_LABEL; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_LICENSE; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSVANGENUCHMAPGEN_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSVANGENUCHMAPGEN_KEYWORDS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSVANGENUCHMAPGEN_NAME; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSVANGENUCHMAPGEN_STATUS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inGeo_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_outAlfaVanGen_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_outCohesion_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_outGamma_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_outKsat_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_outNVanGen_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_outPhi_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_outTheta_r_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_outTheta_s_DESCRIPTION; + +import java.awt.image.RenderedImage; +import java.awt.image.WritableRaster; +import java.util.Hashtable; + +import javax.media.jai.iterator.RandomIter; +import javax.media.jai.iterator.RandomIterFactory; +import javax.media.jai.iterator.WritableRandomIter; + +import oms3.annotations.Author; +import oms3.annotations.Description; +import oms3.annotations.Execute; +import oms3.annotations.In; +import oms3.annotations.Out; +import oms3.annotations.Keywords; +import oms3.annotations.Label; +import oms3.annotations.License; +import oms3.annotations.Name; +import oms3.annotations.Status; + +import org.geotools.coverage.grid.GridCoverage2D; +import org.jgrasstools.gears.libs.modules.GridNode; +import org.jgrasstools.gears.libs.modules.JGTModel; +import org.jgrasstools.gears.utils.RegionMap; +import org.jgrasstools.gears.utils.coverage.CoverageUtilities; +import org.jgrasstools.hortonmachine.i18n.HortonMessageHandler; +import org.opengis.referencing.crs.CoordinateReferenceSystem; + +@Description(OMSCISLAM_OMSVANGENUCHMAPGEN_DESCRIPTION) +@Author(name = OMSCISLAM_AUTHORNAMES, contact = OMSCISLAM_AUTHORCONTACTS) +@Keywords(OMSCISLAM_OMSVANGENUCHMAPGEN_KEYWORDS) +@Label(OMSCISLAM_SUBMODULES_LABEL) +@Name(OMSCISLAM_OMSVANGENUCHMAPGEN_NAME) +@Status(OMSCISLAM_OMSVANGENUCHMAPGEN_STATUS) +@License(OMSCISLAM_LICENSE) +public class OmsVanGenuchtenMapsGenerator extends JGTModel { + + @Description(OMSCISLAM_inGeo_DESCRIPTION) + @In + public GridCoverage2D inGeo = null; + + @Description(OMSCISLAM_outCohesion_DESCRIPTION) + @Out + public GridCoverage2D outCohesion = null; + + @Description(OMSCISLAM_outPhi_DESCRIPTION) + @Out + public GridCoverage2D outPhi = null; + + @Description(OMSCISLAM_outGamma_DESCRIPTION) + @Out + public GridCoverage2D outGamma = null; + + @Description(OMSCISLAM_outKsat_DESCRIPTION) + @Out + public GridCoverage2D outKsat = null; + + @Description(OMSCISLAM_outTheta_s_DESCRIPTION) + @Out + public GridCoverage2D outTheta_s = null; + + @Description(OMSCISLAM_outTheta_r_DESCRIPTION) + @Out + public GridCoverage2D outTheta_r = null; + + @Description(OMSCISLAM_outAlfaVanGen_DESCRIPTION) + @Out + public GridCoverage2D outAlfaVanGen = null; + + @Description(OMSCISLAM_outNVanGen_DESCRIPTION) + @Out + public GridCoverage2D outNVanGen = null; + + // TODO Replace custom DEVELOPMENT class with default framework one before pulling into main JGrassTools repository + // private HortonMessageHandler msg = HortonMessageHandler.getInstance(); + private HortonMessageHandler msg = HortonMessageHandler.getInstance(); + + @Execute + public void process() { + if (!concatOr(outCohesion == null, outPhi == null, outGamma == null, outKsat == null, outTheta_s == null, + outTheta_r == null, outAlfaVanGen == null, outNVanGen == null)) { + return; + } + checkNull(inGeo); + + Hashtable vanGenchtenTable = new Hashtable(11, 1); + /* + * This table was derived from the R script written y Cristiano Lanni to develop and test the model on the Pizzano basin + * so it is just here for development purposes as its values are applicable just on that basin as well as its geological classification codes + ##==## | |0 |1 |2 |3 |4 |5 |6 |7 | + ##==## | geo | tetha r |alfaVanGen| n |cohesion| phi | gamma |Ksat| theta s | + ##==## | 1 | 0.0233 | 6.93 | 1.3165| 1.0 | 38.0 | 18.0 |1e-3| 0.2 | + ##==## | 2 | 0.0227 | 8.18 | 1.3035| 1.0 | 38.0 | 19.0 |1e-3| 0.2 | + ##==## | 3 | 0.0434 | 2.39 | 1.2361| 2.0 | 34.0 | 18.5 |1e-6| 0.26 | + ##==## | 4 | 0.0463 | 1.27 | 1.3562| 5.0 | 18.0 | 18.0 |1e-6| 0.26 | + ##==## | 5 | 0.0456 | 2.07 | 1.2676| 1.0 | 34.5 | 18.0 |1e-6| 0.23 | + ##==## | 6 | 0.0369 | 3.29 | 1.2486| 1.0 | 30.0 | 18.0 |1e-7| 0.29 | + ##==## | 7 | 0.0252 | 7.08 | 1.3849| 1.0 | 34.5 | 18.0 |1e-5| 0.28 | + ##==## | 8 | 0.0363 | 4.46 | 1.2160| 0.5 | 39.0 | 18.5 |1e-5| 0.28 | + ##==## | 9 | 0.0363 | 4.46 | 1.2160| 1.0 | 33.0 | 18.5 |1e-5| 0.23 | + ##==## | 10 | 0.0583 | 1.52 | 1.3250| 20.0 | 28.0 | 17.0 |1e-8| 0.50 | + ##==## | 11 | 0.0355 | 2.98 | 1.2616| 2.0 | 33.0 | 18.0 |1e-5| 0.23 | + To skip the step on line 40 of R script (replacing all 0 available in geo map with code11) + we are adding one more raw to the HashTable to associate key 0 with same values as key 11 + ##==## | 0 | 0.0355 | 2.98 | 1.2616| 2.0 | 33.0 | 18.0 |1e-5| 0.23 | + */ + vanGenchtenTable.put(1, new Double[]{0.0233, 6.93, 1.3165, 1.0, 38.0, 18.0, 1e-3, 0.2}); + vanGenchtenTable.put(2, new Double[]{0.0227, 8.18, 1.3035, 1.0, 38.0, 19.0, 1e-3, 0.2}); + vanGenchtenTable.put(3, new Double[]{0.0434, 2.39, 1.2361, 2.0, 34.0, 18.5, 1e-6, 0.26}); + vanGenchtenTable.put(4, new Double[]{0.0463, 1.27, 1.3562, 5.0, 18.0, 18.0, 1e-6, 0.26}); + vanGenchtenTable.put(5, new Double[]{0.0456, 2.07, 1.2676, 1.0, 34.5, 18.0, 1e-6, 0.23}); + vanGenchtenTable.put(6, new Double[]{0.0369, 3.29, 1.2486, 1.0, 30.0, 18.0, 1e-7, 0.29}); + vanGenchtenTable.put(7, new Double[]{0.0252, 7.08, 1.3849, 1.0, 34.5, 18.0, 1e-5, 0.28}); + vanGenchtenTable.put(8, new Double[]{0.0363, 4.46, 1.2160, 0.5, 39.0, 18.5, 1e-5, 0.28}); + vanGenchtenTable.put(9, new Double[]{0.0363, 4.46, 1.2160, 1.0, 33.0, 18.5, 1e-5, 0.23}); + vanGenchtenTable.put(10, new Double[]{0.0583, 1.52, 1.3250, 20.0, 28.0, 17.0, 1e-8, 0.50}); + vanGenchtenTable.put(11, new Double[]{0.0355, 2.98, 1.2616, 2.0, 33.0, 18.0, 1e-5, 0.23}); + vanGenchtenTable.put(0, new Double[]{0.0355, 2.98, 1.2616, 2.0, 33.0, 18.0, 1e-5, 0.23}); + + RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inGeo); + int cols = regionMap.getCols(); + int rows = regionMap.getRows(); + double xRes = regionMap.getXres(); + double yRes = regionMap.getYres(); + + RenderedImage geoImage = inGeo.getRenderedImage(); + RandomIter geoIter = RandomIterFactory.create(geoImage, null); + + WritableRaster outCohesionWR = CoverageUtilities.renderedImage2WritableRaster(geoImage, false); + WritableRaster outPhiWR = CoverageUtilities.renderedImage2WritableRaster(geoImage, false); + WritableRaster outGammaWR = CoverageUtilities.renderedImage2WritableRaster(geoImage, false); + WritableRaster outKsatWR = CoverageUtilities.renderedImage2WritableRaster(geoImage, false); + WritableRaster outTheta_sWR = CoverageUtilities.renderedImage2WritableRaster(geoImage, false); + WritableRaster outTheta_rWR = CoverageUtilities.renderedImage2WritableRaster(geoImage, false); + WritableRaster outAlfaVanGenWR = CoverageUtilities.renderedImage2WritableRaster(geoImage, false); + WritableRaster outNVanGenWR = CoverageUtilities.renderedImage2WritableRaster(geoImage, false); + + WritableRandomIter outCohesionIter = RandomIterFactory.createWritable(outCohesionWR, null); + WritableRandomIter outPhiIter = RandomIterFactory.createWritable(outPhiWR, null); + WritableRandomIter outGammaIter = RandomIterFactory.createWritable(outGammaWR, null); + WritableRandomIter outKsatIter = RandomIterFactory.createWritable(outKsatWR, null); + WritableRandomIter outTheta_sIter = RandomIterFactory.createWritable(outTheta_sWR, null); + WritableRandomIter outTheta_rIter = RandomIterFactory.createWritable(outTheta_rWR, null); + WritableRandomIter outAlfaVanGenIter = RandomIterFactory.createWritable(outAlfaVanGenWR, null); + WritableRandomIter outNVanGenIter = RandomIterFactory.createWritable(outNVanGenWR, null); + + //String message = msg.message("cislam.dev.computing.maps"); + String message = null; + /* + try { + message = msg.message("cislam.dev.computing.maps"); + } catch (Exception e) { + e.printStackTrace(); + message = "Computing maps.."; + } + */ + message = "Computing maps.."; //$NON-NLS-1$ + pm.beginTask(message, rows); + + // Cycling into the valid region. + for( int r = 0; r < rows; r++ ) { + for( int c = 0; c < cols; c++ ) { + GridNode gridNode = new GridNode(geoIter, cols, rows, xRes, yRes, c, r); + if (gridNode.isValid()) { + int geoClass = (int) gridNode.elevation; + if (geoClass >= 0) { + Double[] parameters = vanGenchtenTable.get(geoClass); + /* + * Parameter indexes in the 'parameters[]' array + ##==## | |0 |1 |2 |3 |4 |5 |6 |7 | + ##==## | geo | tetha r |alfaVanGen| n |cohesion| phi | gamma |Ksat| theta s | + */ + double choesion = parameters[3]; + gridNode.setValueInMap(outCohesionIter, choesion); + gridNode.setValueInMap(outPhiIter, parameters[4]); + gridNode.setValueInMap(outGammaIter, parameters[5]); + gridNode.setValueInMap(outKsatIter, parameters[6]); + gridNode.setValueInMap(outTheta_sIter, parameters[7]); + gridNode.setValueInMap(outTheta_rIter, parameters[0]); + gridNode.setValueInMap(outAlfaVanGenIter, parameters[1]); + gridNode.setValueInMap(outNVanGenIter, parameters[2]); + } + } + } + pm.worked(1); + } + pm.done(); + + CoordinateReferenceSystem crs = inGeo.getCoordinateReferenceSystem(); + + pm.beginTask("Saving files..." /*msg.message("cislam.dev.saving.files")*/, 8); //$NON-NLS-1$ + outCohesion = CoverageUtilities.buildCoverage("cohesion", outCohesionWR, regionMap, crs); + pm.worked(1); + outPhi = CoverageUtilities.buildCoverage("phi", outPhiWR, regionMap, crs); + pm.worked(1); + outGamma = CoverageUtilities.buildCoverage("gamma", outGammaWR, regionMap, crs); + pm.worked(1); + outKsat = CoverageUtilities.buildCoverage("ksat", outKsatWR, regionMap, crs); + pm.worked(1); + outTheta_s = CoverageUtilities.buildCoverage("thetas", outTheta_sWR, regionMap, crs); + pm.worked(1); + outTheta_r = CoverageUtilities.buildCoverage("thetar", outTheta_rWR, regionMap, crs); + pm.worked(1); + outAlfaVanGen = CoverageUtilities.buildCoverage("alfa", outAlfaVanGenWR, regionMap, crs); + pm.worked(1); + outNVanGen = CoverageUtilities.buildCoverage("n", outNVanGenWR, regionMap, crs); + pm.worked(1); + pm.done(); + } +} diff --git a/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utility_models/OmsVwt.java b/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utility_models/OmsVwt.java new file mode 100644 index 000000000..3b6b878ce --- /dev/null +++ b/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utility_models/OmsVwt.java @@ -0,0 +1,150 @@ +/* + * This file is part of the "CI-slam module": an addition to JGrassTools + * It has been entirely contributed by Marco Foi (www.mcfoi.it) + * + * "CI-slam module" is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.utility_models; + +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_AUTHORCONTACTS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_AUTHORNAMES; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_LICENSE; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSVWT_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSVWT_KEYWORDS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSVWT_NAME; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSVWT_STATUS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSVWT_outVwt_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_SUBMODULES_LABEL; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inAlfaVanGen_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inNVanGen_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inSoilThickness_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inTheta_r_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inTheta_s_DESCRIPTION; + +import java.awt.image.WritableRaster; + +import javax.media.jai.iterator.RandomIter; +import javax.media.jai.iterator.RandomIterFactory; +import javax.media.jai.iterator.WritableRandomIter; + +import oms3.annotations.Author; +import oms3.annotations.Description; +import oms3.annotations.Execute; +import oms3.annotations.In; +import oms3.annotations.Keywords; +import oms3.annotations.Label; +import oms3.annotations.License; +import oms3.annotations.Name; +import oms3.annotations.Out; +import oms3.annotations.Status; +import oms3.annotations.Unit; + +import org.geotools.coverage.grid.GridCoverage2D; +import org.jgrasstools.gears.libs.modules.JGTConstants; +import org.jgrasstools.gears.libs.modules.JGTModel; +import org.jgrasstools.gears.utils.RegionMap; +import org.jgrasstools.gears.utils.coverage.CoverageUtilities; + + +@Description(OMSCISLAM_OMSVWT_DESCRIPTION) +@Author(name = OMSCISLAM_AUTHORNAMES, contact = OMSCISLAM_AUTHORCONTACTS) +@Keywords(OMSCISLAM_OMSVWT_KEYWORDS) +@Label(OMSCISLAM_SUBMODULES_LABEL) +@Name(OMSCISLAM_OMSVWT_NAME) +@Status(OMSCISLAM_OMSVWT_STATUS) +@License(OMSCISLAM_LICENSE) +public class OmsVwt extends JGTModel { + + @Description(OMSCISLAM_inSoilThickness_DESCRIPTION) + @Unit("m") + @In + public GridCoverage2D inSoilThickness = null; + + @Description(OMSCISLAM_inTheta_s_DESCRIPTION) + @In + public GridCoverage2D inTheta_s = null; + + @Description(OMSCISLAM_inTheta_r_DESCRIPTION) + @In + public GridCoverage2D inTheta_r = null; + + @Description(OMSCISLAM_inAlfaVanGen_DESCRIPTION) + @In + public GridCoverage2D inAlfaVanGen = null; + + @Description(OMSCISLAM_inNVanGen_DESCRIPTION) + @In + public GridCoverage2D inNVanGen = null; + + @Description(OMSCISLAM_OMSVWT_outVwt_DESCRIPTION) + @Out + public GridCoverage2D outVwt = null; + + @Execute + public void process(){ + if (!concatOr(outVwt == null, doReset)) { + return; + } + + checkNull(inSoilThickness, inTheta_s, inTheta_r, inAlfaVanGen, inNVanGen); + + RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inSoilThickness); + int cols = regionMap.getCols(); + int rows = regionMap.getRows(); + + // Prepare objects for iterating over the maps + RandomIter theta_rIter = RandomIterFactory.create(inTheta_r.getRenderedImage(), null); + RandomIter theta_sIter = RandomIterFactory.create(inTheta_s.getRenderedImage(), null); + RandomIter soilThicknessIter = RandomIterFactory.create(inSoilThickness.getRenderedImage(), null); + RandomIter alfaVanGenuchtenIter = RandomIterFactory.create(inAlfaVanGen.getRenderedImage(), null); + RandomIter nVanGenuchtenIter = RandomIterFactory.create(inNVanGen.getRenderedImage(), null); + + WritableRaster mVwtWR = CoverageUtilities.createDoubleWritableRaster(cols, rows, null, null, JGTConstants.doubleNovalue); + WritableRandomIter mVwtIter = RandomIterFactory.createWritable(mVwtWR, null); + + double mVwt = 0.0; + pm.beginTask("Start computing Vwt map (map of storage of soil moisture needed to produce a perched water table)...", rows); + for(int r = 0; r < rows; r++){ + for(int c = 0; c < cols; c++){ + double theta_r = theta_rIter.getSampleDouble(c, r, 0); + double theta_s = theta_sIter.getSampleDouble(c, r, 0); + double soilThickness = soilThicknessIter.getSampleDouble(c, r, 0); + double alfaVanGenuchten = alfaVanGenuchtenIter.getSampleDouble(c, r, 0); + double nVanGenuchten = nVanGenuchtenIter.getSampleDouble(c, r, 0); + if(theta_r!=0.0 && theta_s != 0.0){ + mVwt = + (theta_r*soilThickness) + + (theta_s-theta_r)* + (soilThickness*( + Math.pow( + (1 + Math.pow( + (alfaVanGenuchten*soilThickness), + nVanGenuchten) + ), + (-1.0/nVanGenuchten) + ) + ) + ); + //pm.message(Double.toString(mVwt)); + mVwtIter.setSample(c, r, 0, mVwt); + } + } + pm.worked(1); + } + pm.done(); + + outVwt = CoverageUtilities.buildCoverage("Vwt", mVwtWR, regionMap, inSoilThickness.getCoordinateReferenceSystem()); + } + +} diff --git a/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utils/FileDumperRunner.java b/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utils/FileDumperRunner.java new file mode 100644 index 000000000..97ce18486 --- /dev/null +++ b/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utils/FileDumperRunner.java @@ -0,0 +1,34 @@ +/* + * This file is part of the "CI-slam module": an addition to JGrassTools + * It has been entirely contributed by Marco Foi (www.mcfoi.it) + * + * "CI-slam module" is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.utils; + + +public class FileDumperRunner implements Runnable { + + IRunBehavior runBehaviour; + + public FileDumperRunner( IRunBehavior rb ) { + runBehaviour = rb; + } + + @Override + public void run() { + runBehaviour.runLaunch(); + } + +} diff --git a/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utils/IRunBehavior.java b/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utils/IRunBehavior.java new file mode 100644 index 000000000..ce65d9c9d --- /dev/null +++ b/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utils/IRunBehavior.java @@ -0,0 +1,24 @@ +/* + * This file is part of the "CI-slam module": an addition to JGrassTools + * It has been entirely contributed by Marco Foi (www.mcfoi.it) + * + * "CI-slam module" is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.utils; + +public interface IRunBehavior { + + public void runLaunch(); + +} diff --git a/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utils/MapCalculationFunctions.java b/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utils/MapCalculationFunctions.java new file mode 100644 index 000000000..3cfd7d7c9 --- /dev/null +++ b/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utils/MapCalculationFunctions.java @@ -0,0 +1,1509 @@ +/* + * This file is part of the "CI-slam module": an addition to JGrassTools + * It has been entirely contributed by Marco Foi (www.mcfoi.it) + * + * "CI-slam module" is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.utils; + +import static java.lang.Math.pow; +import static java.lang.Math.sqrt; + +import java.awt.image.BandedSampleModel; +import java.awt.image.DataBuffer; +import java.awt.image.WritableRaster; +import java.text.DecimalFormat; +import java.text.NumberFormat; +import java.util.HashMap; +import java.util.Locale; + +import javax.media.jai.iterator.RandomIter; +import javax.media.jai.iterator.RandomIterFactory; +import javax.media.jai.iterator.WritableRandomIter; + +import org.geotools.coverage.grid.GridCoverage2D; +import org.jgrasstools.gears.io.rasterwriter.OmsRasterWriter; +import org.jgrasstools.gears.libs.modules.FlowNode; +import org.jgrasstools.gears.libs.modules.JGTConstants; +import org.jgrasstools.gears.libs.monitor.IJGTProgressMonitor; +import org.jgrasstools.gears.utils.RegionMap; +import org.jgrasstools.gears.utils.coverage.CoverageUtilities; + +public class MapCalculationFunctions { + + public enum MapOfCumulatedValue { + RATIO,SLOPE_CUM, DIST, AB, CONT, SOIL_THICK, TH_TIME; + } + + + /** + * Computes the map of the times required by each basing node to develop a perched water table + * given the rainfall intensity (assumed uniform in space and time), + * the map of initial soil moisture content V0 [L] and the map of soil moisture requires to develop the water table Vwt. + * Relies on the method {@link calculateTimeForWaterTableDevelopmentTwt() } + * The calculation is based on Equation (1) of the reference paper. + * @param mapVwt GridCoverage2D + * @param mapV0 GridCoverage2D + * @param pRainfallIntensity [L/T] + * @param pm The progress monitor to return process information. + * @return + */ + public static GridCoverage2D computeMapOfTimeForWaterTableDevelopmentTwt( GridCoverage2D mapVwt, GridCoverage2D mapV0, + double pRainfallIntensity, IJGTProgressMonitor pm ) { + + RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(mapVwt); + int cols = regionMap.getCols(); + int rows = regionMap.getRows(); + + // Prepare objects for iterating over the maps + RandomIter mapVwtIter = RandomIterFactory.create(mapVwt.getRenderedImage(), null); + RandomIter mapV0Iter = RandomIterFactory.create(mapV0.getRenderedImage(), null); + + WritableRaster mapTwtWR = CoverageUtilities.createDoubleWritableRaster(cols, rows, null, null, JGTConstants.doubleNovalue); + WritableRandomIter mapTwtIter = RandomIterFactory.createWritable(mapTwtWR, null); + + double mTwt, pVwt, pV0 = Double.NaN; + + pm.beginTask("Start computing Twt map..", rows); + for( int r = 0; r < rows; r++ ) { + for( int c = 0; c < cols; c++ ) { + + pVwt = mapVwtIter.getSampleDouble(c, r, 0); + pV0 = mapV0Iter.getSampleDouble(c, r, 0); + mTwt = ParameterCalculationFunctions.calculateTimeForWaterTableDevelopmentTwt(pVwt, pV0, pRainfallIntensity); + + mapTwtIter.setSample(c, r, 0, mTwt); + + } + // pm.worked(1); + } + pm.done(); + + GridCoverage2D mapTwt = CoverageUtilities.buildCoverage("twt", mapTwtWR, regionMap, mapVwt.getCoordinateReferenceSystem()); + + return mapTwt; + } + + /** + * Returns a multi-banded GridCoverage2D containing a set of Psi maps at soil-bedrock interface. + * Logic is from Equation (9) of reference paper. + * Each band in the coverage contains the Psi values after i+1 hours of rainfall, so that the band #3 represents + * the status after 4 hours of rainfall. + * The total number of bands depends on the max value in the passed Twt map, + * so depends on the time required for having all cells developed their local perched water table due to vertical infiltration. + * NOTE THAT any multi-banded map set is computed for a specific Return Time [years] and a simulated Rainfall Duration [hours] that, + * thoug not passed to the method, is embedded in the calculation of Twt map and Rainfall Intensity I. + * @param Twt GridCoverage2D (depends on Return Time and Rainfall Duration) + * @param psiInit GridCoverage2D (depends on basin) + * @param I double (depends on Return Time and Rainfall Duration) + * @param soil_thickness GridCoverage2D (depends on basin) + * @param theta_s GridCoverage2D (depends on basin) + * @param theta_r GridCoverage2D (depends on basin) + * @param alfaVanGenuchten GridCoverage2D (depends on basin) + * @param nVanGenuchten GridCoverage2D (depends on basin) + * @param pm + * @return + */ + public static GridCoverage2D computeMapsOfPsiAtBedrockDuringVerticalInfiltration( GridCoverage2D Twt, GridCoverage2D psiInit, + double I, GridCoverage2D soil_thickness, GridCoverage2D theta_s, GridCoverage2D theta_r, GridCoverage2D alfaVanGenuchten, + GridCoverage2D nVanGenuchten, IJGTProgressMonitor pm ) { + + RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(soil_thickness); + int cols = regionMap.getCols(); + int rows = regionMap.getRows(); + + // Prepare objects for iterating over the maps + RandomIter mapPsiInitIter = RandomIterFactory.create(psiInit.getRenderedImage(), null); + RandomIter mapSoilThicknessIter = RandomIterFactory.create(soil_thickness.getRenderedImage(), null); + RandomIter mapTheta_SIter = RandomIterFactory.create(theta_s.getRenderedImage(), null); + RandomIter mapTheta_RIter = RandomIterFactory.create(theta_r.getRenderedImage(), null); + RandomIter mapAalfaVanGenuchtenIter = RandomIterFactory.create(alfaVanGenuchten.getRenderedImage(), null); + RandomIter mapNVanGenuchtenIter = RandomIterFactory.create(nVanGenuchten.getRenderedImage(), null); + + double maxTwt = CoverageUtilities.getMinMaxMeanSdevCount(Twt, null)[1]; + int countOfToBeStoredPsiCoverages = (int) (Math.round(maxTwt)) + 1; + + BandedSampleModel sampleModel = new BandedSampleModel(DataBuffer.TYPE_DOUBLE, cols, rows, countOfToBeStoredPsiCoverages); + + int numBands = sampleModel.getNumBands(); + WritableRaster psiMultiHoursWR = CoverageUtilities.createDoubleWritableRaster(cols, rows, null, sampleModel, + JGTConstants.doubleNovalue); + WritableRandomIter psiWRIter = RandomIterFactory.createWritable(psiMultiHoursWR, null); + + double pPreviousPsi_bb, pI, pSoil_thickness, pTheta_s, pTheta_r, pAlfaVanGenuchten, pNVanGenuchten; + int dt = ParameterCalculationFunctions.DELTA_T_INTEGRATION_STEP_IN_SECONDS; + + pm.beginTask("Started computing Psi maps after each of the " + numBands + + " hour/s of required rainfall simulation to exceed MAX Twt time...", rows); + long start = System.nanoTime(); + for( int r = 0; r < rows; r++ ) { + for( int c = 0; c < cols; c++ ) { + // Check we are in the basin by probing Soil Thickness + pSoil_thickness = mapSoilThicknessIter.getSampleDouble(c, r, 0); + + if (!Double.isNaN(pSoil_thickness)) { + + pPreviousPsi_bb = mapPsiInitIter.getSampleDouble(c, r, 0); + pI = I; + pTheta_s = mapTheta_SIter.getSampleDouble(c, r, 0); + pTheta_r = mapTheta_RIter.getSampleDouble(c, r, 0); + pAlfaVanGenuchten = mapAalfaVanGenuchtenIter.getSampleDouble(c, r, 0); + pNVanGenuchten = mapNVanGenuchtenIter.getSampleDouble(c, r, 0); + + double[] pixel = new double[countOfToBeStoredPsiCoverages]; + // Cycle in the total number of simulation hours (derived from the max Twt time of the basin for given Return Time and + // Rainfall Intensity + for( int j = 0; j < countOfToBeStoredPsiCoverages; j++ ) { + int i = 1; + // Loop until the sum of iteration steps over one cell reaches one hour (3600 sec) then write computed psi to raster + while( (i * dt) % ((3600 / dt) + 1) != 0 ) { + + // int counter = ((i * ParameterCalculationFunctions.DELTA_T_INTEGRATION_STEP_IN_SECONDS) % 3600); + + pPreviousPsi_bb = ParameterCalculationFunctions.calculatePsiAtBedrockDuringVerticalInfiltration( + pPreviousPsi_bb, pI, pSoil_thickness, pTheta_s, pTheta_r, pAlfaVanGenuchten, pNVanGenuchten); + i++; + } + + pixel[j] = pPreviousPsi_bb; + } + psiWRIter.setPixel(c, r, pixel); + // DEBUG CODE + /* + double[] outPixel = new double[4]; + psiMultiHoursWR.getPixel(252,682,outPixel); + psiMultiHoursWR.getPixel(c,r,outPixel); + double[] bandValues = outPixel; + */ + } + } + pm.worked(1); + } + pm.message("Elapsed time: " + (System.nanoTime() - start) / 1000000000 + " sec."); + pm.done(); + + GridCoverage2D psiMapsAtIncreasingHours; + + psiMapsAtIncreasingHours = CoverageUtilities.buildCoverage("psimultihours", psiMultiHoursWR, regionMap, + Twt.getCoordinateReferenceSystem()); + + GridCoverage2D[] coverageArry = fromMultibandCoverageToCoverageArray(psiMapsAtIncreasingHours); + for( int c = 0; c < coverageArry.length; c++ ) { + pm.message("Stats for Psi map at end of " + (c + 1) + " hour rainfall " + getCoverageStatsAsString(coverageArry[c])); + } + + // PROBE CODE for Coverages as MULTIBAND GridCoverage2D + // final Point2D.Double point = new Point2D.Double(); + // point.x = 623630.1509; + // point.y = 5137453.8354; + // double[] bufferCov = null; + + // bufferCov = psiMapsAtIncreasingHours.evaluate(point, bufferCov); + + return psiMapsAtIncreasingHours; + + } + + /** + * Computes from the input maps a set of maps containing variables cumulated along FLOW path + * The returned maps are: RATIO,SLOPE_CUM, DIST, AB, CONT, SOIL_THICK, TH_TIME + * @param inPit + * @param inFlowWithBorderAndOutlet + * @param inKsat + * @param inSoilThickness + * @param inTheta_s + * @param inAb + * @param inTwt + * @param pm + * @return GridCoverage2D[] containing following sequence of maps: {RATIO,SLOPE_CUM, DIST, AB, CONT, SOIL_THICK, TH_TIME} + */ + public static HashMap calculateMapsOfCumulatedParameters( GridCoverage2D inPit, GridCoverage2D inFlowWithBorderAndOutlet, + GridCoverage2D inKsat, GridCoverage2D inSoilThickness, GridCoverage2D inTheta_s, GridCoverage2D inAb, + GridCoverage2D inTwt, IJGTProgressMonitor pm ) { + + double delta_st = 0.0; + double delta_l = 0.0; + double delta_ll = 0.0; + double delta_s = 0.0; + double delta_Ab = 0.0; + double delta_tt = 0.0; + int r = 0; + int c = 0; + int rnew = 0; + int cnew = 0; + double d_st = 0.0; + double d_l = 0.0; + double d_ll = 0.0; + double d_s = 0.0; + double d_tt = 0.0; + double cont = 0.0; + + double d_Ab = 0.0; + + RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inPit); + int cols = regionMap.getCols(); + int rows = regionMap.getRows(); + double xRes = regionMap.getXres(); + double yRes = regionMap.getYres(); + + // Prepare objects for iterating over the maps + RandomIter mapPitIter = RandomIterFactory.create(inPit.getRenderedImage(), null); + RandomIter mapFlowIter = RandomIterFactory.create(inFlowWithBorderAndOutlet.getRenderedImage(), null); + RandomIter mapKsatIter = RandomIterFactory.create(inKsat.getRenderedImage(), null); + RandomIter mapSoilThicknessIter = RandomIterFactory.create(inSoilThickness.getRenderedImage(), null); + RandomIter mapTheta_SIter = RandomIterFactory.create(inTheta_s.getRenderedImage(), null); + RandomIter mapAbIter = RandomIterFactory.create(inAb.getRenderedImage(), null); + RandomIter mapTwtIter = RandomIterFactory.create(inTwt.getRenderedImage(), null); + + WritableRaster DIST_WR = CoverageUtilities.createDoubleWritableRaster(cols, rows, null, null, 0.0); + WritableRaster SOIL_THICK_WR = CoverageUtilities.createDoubleWritableRaster(cols, rows, null, null, 0.0); + WritableRaster SLOPE_CUM_WR = CoverageUtilities.createDoubleWritableRaster(cols, rows, null, null, 0.0); + WritableRaster TH_TIME_WR = CoverageUtilities.createDoubleWritableRaster(cols, rows, null, null, 0.0); + WritableRaster RATIO_WR = CoverageUtilities.createDoubleWritableRaster(cols, rows, null, null, 0.0); + WritableRaster CONT_WR = CoverageUtilities.createDoubleWritableRaster(cols, rows, null, null, 0.0); + WritableRaster AB_WR = CoverageUtilities.createDoubleWritableRaster(cols, rows, null, null, 0.0); + + WritableRandomIter DIST_Iter = RandomIterFactory.createWritable(DIST_WR, null); + WritableRandomIter SOIL_THICK_Iter = RandomIterFactory.createWritable(SOIL_THICK_WR, null); + WritableRandomIter SLOPE_CUM_Iter = RandomIterFactory.createWritable(SLOPE_CUM_WR, null); + WritableRandomIter TH_TIME_Iter = RandomIterFactory.createWritable(TH_TIME_WR, null); + WritableRandomIter RATIO_Iter = RandomIterFactory.createWritable(RATIO_WR, null); + WritableRandomIter CONT_Iter = RandomIterFactory.createWritable(CONT_WR, null); + WritableRandomIter AB_Iter = RandomIterFactory.createWritable(AB_WR, null); + + for( int rloop = 0; rloop < rows; rloop++ ) { + for( int cloop = 0; cloop < cols; cloop++ ) { + + delta_st = 0.0; + delta_l = 0.0; + delta_ll = 0.0; + delta_s = 0.0; + delta_Ab = 0.0; + delta_tt = 0.0; + r = rloop; + c = cloop; + rnew = 0; + cnew = 0; + d_st = 0.0; + d_l = 0.0; + d_ll = 0.0; + d_s = 0.0; + d_tt = 0.0; + cont = 0.0; + + FlowNode flowNode = new FlowNode(mapFlowIter, cols, rows, cloop, rloop); + + // flowNode.flow returns a double - not an int!! + while( !Double.isNaN(flowNode.flow) && flowNode.flow != 10.0 ) { + + d_st = 0.0; + d_l = 0.0; + d_s = 0.0; + d_tt = 0.0; + d_Ab = 0.0; + + c = flowNode.col; // Useless at first loop but leads processing downstream from second loop hence + r = flowNode.row; // Useless at first loop but leads processing downstream from second loop hence + + FlowNode nextFlowNode = flowNode.goDownstream(); + + cnew = nextFlowNode.col; + rnew = nextFlowNode.row; + + + // Actual distance between starting and destination cell is returned + d_ll = sqrt(pow((cnew - c) * xRes, 2.0) + pow((rnew - r) * yRes, 2.0)); //OK 4.0 + + double d_quota = mapPitIter.getSampleDouble(c, r, 0) - mapPitIter.getSampleDouble(cnew, rnew, 0);//OK 3.6293945 + + // Incrementally store the path length along FLOW direction + delta_ll = delta_ll + d_ll;//OK 4.0 8.0 + + d_l = + ( + (d_ll)* + (( mapTheta_SIter.getSampleDouble(c, r, 0) + mapTheta_SIter.getSampleDouble(cnew, rnew, 0) )/2)//OK 0.23 + )/ + ( + // quello che segue e' la K saturo nella direzione del flusso (Ksat e' in origine espressa orizzontalmente) + Math.cos(Math.atan(Math.max(0.01,(d_quota))/(d_ll)))* //OK 0.740582 + Math.sin(Math.atan(Math.max(0.01,(d_quota))/(d_ll)))* //OK 0.671966 + ((mapKsatIter.getSampleDouble(c, r, 0)+mapKsatIter.getSampleDouble(cnew, rnew, 0))/2) //OK 1.0E-5 + ); //OK 184870.4 184003.5 + + // Incrementally store the value found (d_l) along FLOW direction + delta_l = delta_l + d_l; //OK 184870.4 368873.9 + + // slope in path direction + d_s = Math.max(0.01,d_quota)/(d_ll); //OK 0.9073486 1.006226 + + //Incrementally store the value found (d_s) along FLOW direction + delta_s = delta_s + d_s; //OK 0.9073486 1.913574 + + // Ab = AbFLOW + d_Ab = mapAbIter.getSampleDouble(c, r, 0); //OK 2.105263 5.912811 + // Incrementally store the value found (d_Ab) along FLOW direction + delta_Ab = delta_Ab + d_Ab; //OK 2.105263 8.018075 + + d_st = mapSoilThicknessIter.getSampleDouble(c, r, 0); //OK 0.2347537 + // Incrementally store the value found (d_st) along FLOW direction + delta_st = delta_st + d_st; //0.2347537 0.3854619 + // Remind that 'th_time' is computed for a specific return time (here 200 years as on line 294) + d_tt = Math.max(0,mapTwtIter.getSampleDouble(c, r, 0)); //OK 1.518616 1.129852 + // Incrementally store the value found (d_tt) along FLOW direction + delta_tt = delta_tt + d_tt; //OK 1.518616 2.648468 + + cont = cont +1; + + // RATIO is initially a matrix of 0 values + // If a cell with RATIO >= value_to_be_assigned is met, FLOW path processing is halted and next cell is inspected. + double nextRatio = RATIO_Iter.getSampleDouble(cnew, rnew, 0); + if (nextRatio < delta_l) { + // Assign to cells along FLOW path the cumulated value of preceeding ones (each variable has its own matrix) + // NOTE THAT PATH STARTING CELLS (k,l) get no value: this is fixed for each parameter matrix on line 633 and following + // Cumulated 'd_l' parameter + RATIO_Iter.setSample(cnew, rnew, 0, delta_l); + // Cumulated SLOPE along path + SLOPE_CUM_Iter.setSample(cnew, rnew, 0, delta_s); + // Total DISTANCE along path + DIST_Iter.setSample(cnew, rnew, 0, delta_ll); + // Cumulated AbSLOPE (directly from file on line 26) + AB_Iter.setSample(cnew, rnew, 0, delta_Ab); + // COUNTER of path steps + CONT_Iter.setSample(cnew, rnew, 0, cont); + // Cumulated SOIL THICKNESS + SOIL_THICK_Iter.setSample(cnew, rnew, 0, delta_st); + // Cumulated time to water table generation t_wt (Equation (1)) + // NOTE that delta_tt derives from th_time that is computed for a specific Return Time (200 years as on line 294) + // so also TH_TIME is related to the same Return Time + TH_TIME_Iter.setSample(cnew, rnew, 0, delta_tt); + } + else {break;} + + // Move on to the new cell along the D8 FLOW direction + //k=knew; + //l=lnew; + flowNode = flowNode.goDownstream(); + } + } // Next Column + }// Next Row + + GridCoverage2D RATIO = CoverageUtilities.buildCoverage("RATIO", RATIO_WR, regionMap, inPit.getCoordinateReferenceSystem()); + GridCoverage2D SLOPE_CUM = CoverageUtilities.buildCoverage("SLOPE_CUM", SLOPE_CUM_WR, regionMap, inPit.getCoordinateReferenceSystem()); + GridCoverage2D DIST = CoverageUtilities.buildCoverage("DIST", DIST_WR, regionMap, inPit.getCoordinateReferenceSystem()); + GridCoverage2D AB = CoverageUtilities.buildCoverage("AB", AB_WR, regionMap, inPit.getCoordinateReferenceSystem()); + GridCoverage2D CONT = CoverageUtilities.buildCoverage("CONT", CONT_WR, regionMap, inPit.getCoordinateReferenceSystem()); + GridCoverage2D SOIL_THICK = CoverageUtilities.buildCoverage("SOIL_THICK", SOIL_THICK_WR, regionMap, inPit.getCoordinateReferenceSystem()); + GridCoverage2D TH_TIME = CoverageUtilities.buildCoverage("TH_TIME", TH_TIME_WR, regionMap, inPit.getCoordinateReferenceSystem()); + + HashMap maps = new HashMap(cols*rows*8*8, 1); + + maps.put(MapOfCumulatedValue.RATIO, RATIO); + maps.put(MapOfCumulatedValue.SLOPE_CUM, SLOPE_CUM); + maps.put(MapOfCumulatedValue.DIST, DIST); + maps.put(MapOfCumulatedValue.AB, AB); + maps.put(MapOfCumulatedValue.CONT, CONT); + maps.put(MapOfCumulatedValue.SOIL_THICK, SOIL_THICK); + maps.put(MapOfCumulatedValue.TH_TIME, TH_TIME); + + return maps; + } + + /** + * Takes two GridCoverage2D coverage maps, divides the values of the first with the second and returns the resulting map. + * It is used to compute the averages of the cumulated parameters computed with calculateMapsOfCumulatedParameters + * by passing it one of the maps as first argument and the COUNT map as second. + * @param GridCoverage2D toBeAveragedMap + * @param GridCoverage2D countsMapToUseToAverage + * @return GridCoverage2D the map containing the ratio between first and second + */ + public static GridCoverage2D computeMapOfAverageFromCumulated(GridCoverage2D toBeAveragedMap, GridCoverage2D countsMapToUseToAverage){ + + + RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(toBeAveragedMap); + int cols = regionMap.getCols(); + int rows = regionMap.getRows(); + + // Prepare objects for iterating over the maps + RandomIter toBeAveragedMapIter = RandomIterFactory.create(toBeAveragedMap.getRenderedImage(), null); + RandomIter dividerMapIter = RandomIterFactory.create(countsMapToUseToAverage.getRenderedImage(), null); + + WritableRaster averagedMapWR = CoverageUtilities.createDoubleWritableRaster(cols, rows, null, null, JGTConstants.doubleNovalue); + WritableRandomIter averagedMapIter = RandomIterFactory.createWritable(averagedMapWR, null); + + double toBeAveragedValue; + double divider; + double averagedValue; + + for( int r = 0; r < rows; r++ ) { + for( int c = 0; c < cols; c++ ) { + toBeAveragedValue = toBeAveragedMapIter.getSampleDouble(c, r, 0); + divider = dividerMapIter.getSampleDouble(c, r, 0); + if(!Double.isNaN(toBeAveragedValue) && !Double.isNaN(divider) && !Double.isInfinite(divider)){ + averagedValue = toBeAveragedValue/divider; + averagedMapIter.setSample(c, r, 0, averagedValue); + } + } + } + + String newName = "avg_"+toBeAveragedMap.getName(); + + GridCoverage2D outAveragedCoverage = CoverageUtilities.buildCoverage(newName, averagedMapWR, regionMap, + toBeAveragedMap.getCoordinateReferenceSystem()); + + return outAveragedCoverage; + } + + + + /** + * Computes a multi-band GridCoverage2D containing one map for each hour of simulated rainfall. + * Each map contains the value of a dinamic linear Topographic Index computed using formula from + * {@link ParameterCalculationFunctions.calculateDinamicLinearTopographicIndexValue} + * @param avg_TH_TIME_BorderFixed Map computed by calculateMapsOfCumulatedParameters() then passed in computeAverageFromCumulated() and finally in fixBorders_AvgThTime() + * @param singleTwtMap the map of the time-to-water-table creation computed for the provided D value + * @param pReturnTime the return time for which the simulation is run [years] + * @param D Rainfall simulated duration + * @param mapRATIO Map computed by calculateMapsOfCumulatedParameters() and then passed in fixBorders_Ratio() + * @param inAb Ab map computed for the basin + * @param inSlopeFixZeroValuesAndBorder Slope map computed for the basin and fixed with slopeMapFixZeroValuesAndBorder() in MapPreprocessingUtilities.class + * @return + */ + public static GridCoverage2D computeMapOfDynamicLinearTopographicIndex(GridCoverage2D avg_TH_TIME_BorderFixed, GridCoverage2D singleTwtMap, int pReturnTime, int D, GridCoverage2D mapRATIO, GridCoverage2D inAb, GridCoverage2D inSlopeFixZeroValuesAndBorder, IJGTProgressMonitor pm){ + + RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(avg_TH_TIME_BorderFixed); + int cols = regionMap.getCols(); + int rows = regionMap.getRows(); + + // Prepare objects for iterating over the maps + BandedSampleModel bandedSampleModel = new BandedSampleModel(DataBuffer.TYPE_DOUBLE, cols, rows, D); + WritableRaster IT_din_lin_WR = CoverageUtilities.createDoubleWritableRaster(cols, rows, null, bandedSampleModel, JGTConstants.doubleNovalue); + + RandomIter avg_TH_TIME_BorderFixed_Iter = RandomIterFactory.create(avg_TH_TIME_BorderFixed.getRenderedImage(), null); + RandomIter singleTwtMap_Iter = RandomIterFactory.create(singleTwtMap.getRenderedImage(), null); + RandomIter mapRATIO_Iter = RandomIterFactory.create(mapRATIO.getRenderedImage(), null); + RandomIter inAb_Iter = RandomIterFactory.create(inAb.getRenderedImage(), null); + RandomIter inSlopeFixZeroValuesAndBorder_Iter = RandomIterFactory.create(inSlopeFixZeroValuesAndBorder.getRenderedImage(), null); + + double tempo_soglia; + double th_time; + + pm.beginTask("Starting computing TopoIndex_din_lin ...", rows*D); + for( int t = 1; t <= D; t++ ) { + + for( int r = 0; r < rows; r++ ) { + for( int c = 0; c < cols; c++ ) { + + tempo_soglia = avg_TH_TIME_BorderFixed_Iter.getSampleDouble(c, r, 0); + th_time = singleTwtMap_Iter.getSampleDouble(c, r, 0); + + if( !Double.isNaN(th_time) && !Double.isNaN(th_time) ) { + + if( t <= Math.max(tempo_soglia, th_time) ){ + + IT_din_lin_WR.setSample(c, r, (t-1), JGTConstants.doubleNovalue); + + } else if (t > Math.max(tempo_soglia, th_time)){ + + double Ab = inAb_Iter.getSampleDouble(c, r, 0); + double ratio = mapRATIO_Iter.getSampleDouble(c, r, 0); + double slope = inSlopeFixZeroValuesAndBorder_Iter.getSampleDouble(c, r, 0); + + double IT_din_lin_Value = ParameterCalculationFunctions.calculateDinamicLinearTopographicIndexValue(t, Ab, tempo_soglia, th_time, ratio, slope); + // t starts from 1 (h) but bands are 0-indexed + IT_din_lin_WR.setSample(c, r, (t-1), IT_din_lin_Value); + + } + + } + } + pm.worked(1); + } + } + pm.done(); + + return CoverageUtilities.buildCoverage("Topographic_Index_dinamic_linear_" + pReturnTime + "y_", IT_din_lin_WR, regionMap, avg_TH_TIME_BorderFixed.getCoordinateReferenceSystem()); + + } + + /** + * Calculates the pressure at bedrock in the pore pressure positive zones (psi > 0) according to + * Equation (12) in reference paper. + * The returned multi-band Coverage has a number of bands equal to D: the number of simulate rainfall hours. + * Note that IT_din_lin is used as equivalent to Area/(perimeter*sin(beta)) + * @param pReturnTime The return time for which simulation is running + * @param D The rainfall duration for which simulation is running + * @param inSoilThickness Map of soil thickness + * @param I Rainfall intensity computed for pReturnTime and D + * @param inKsat + * @param IT_din_lin GricDoverage2D The Dynamic Linear Topographic Index multibadn map containing the computed TI for each of the D rainfall hours + * @param pm IJGTProgressMonitor + * @return + */ + public static GridCoverage2D computeMapOfPsiAtBedrockInPositivePressureZones(int pReturnTime, int D, GridCoverage2D inSoilThickness, double I, + GridCoverage2D inKsat, GridCoverage2D IT_din_lin, IJGTProgressMonitor pm ) { + + + RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inSoilThickness); + int cols = regionMap.getCols(); + int rows = regionMap.getRows(); + + // Prepare objects for iterating over the maps + BandedSampleModel bandedSampleModel = new BandedSampleModel(DataBuffer.TYPE_DOUBLE, cols, rows, D); + WritableRaster psi_b_WR = CoverageUtilities.createDoubleWritableRaster(cols, rows, null, bandedSampleModel, JGTConstants.doubleNovalue); + + RandomIter inSoilThickness_Iter = RandomIterFactory.create(inSoilThickness.getRenderedImage(), null); + RandomIter inKsat_Iter = RandomIterFactory.create(inKsat.getRenderedImage(), null); + RandomIter IT_din_lin_Iter = RandomIterFactory.create(IT_din_lin.getRenderedImage(), null); + + double IT_din_lin_Val; + + pm.beginTask("Starting computing Psi at bedrock in positive_pressure_zones (t < T_tw but t > T_wt_up)...", rows*D); + for( int t = 1; t <= D; t++ ) { + + for( int r = 0; r < rows; r++ ) { + for( int c = 0; c < cols; c++ ) { + + IT_din_lin_Val = IT_din_lin_Iter.getSampleDouble(c, r, (t-1)); + + if( !Double.isNaN(IT_din_lin_Val) ) { + + double soil_thickness = inSoilThickness_Iter.getSampleDouble(c, r, 0); + double K = inKsat_Iter.getSampleDouble(c, r, 0); + + double psi_b = ParameterCalculationFunctions.calculatePsiAtBedrockInPositivePressureZonesVAlue(soil_thickness, I, K, IT_din_lin_Val, pm ); + // t starts from 1 (h) but bands are 0-indexed + psi_b_WR.setSample(c, r, (t-1), psi_b); + + + } + } + pm.worked(1); + } + } + pm.done(); + + return CoverageUtilities.buildCoverage("Psi_at_Bedrock_in_positive_pressure_zones_" + pReturnTime + "y_", psi_b_WR, regionMap, inSoilThickness.getCoordinateReferenceSystem()); + + } + + /** + * Compute maps of combined Pressure at soil-bedrock interface (Psi) + * This matrix is the combination of the two psi matrices computed for different conditions + * + * = mapPsiMultiHours_Eq9 (Eq. 9) for t < t_wt (during infiltration) + * = mapPsiMultiHours_Eq12 (Eq.12) for t < t_tw but t > t_wt_up (during infiltration but with active lateral flow from catchment) + * ( D = simulation duration ) + * @param pReturnTime + * @param mapPsiMultiHours_Eq9 + * @param mapPsiMultiHours_Eq12 + * @param inSoilThickness Map of soil thickness + * @param pm + * @return + */ + public static GridCoverage2D computeMapOfPsiCombined_Eq9_Eq12(int pReturnTime, GridCoverage2D mapPsiMultiHours_Eq9, GridCoverage2D mapPsiMultiHours_Eq12, GridCoverage2D inSoilThickness, IJGTProgressMonitor pm) { + + RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inSoilThickness); + int cols = regionMap.getCols(); + int rows = regionMap.getRows(); + + // Get the number of bands on which to run the computation + // mapPsiMultiHours_Eq9 has a number of bands equal to the hours needed to let all cells in basin to develop a perched water table ~ Math.ceil(MAX Twt) + // mapPsiMultiHours_Eq12 has ALWAYS a number of bands equal to the number of hours of simulated rainfall D + int minNumBands = Math.min(mapPsiMultiHours_Eq9.getNumSampleDimensions(), mapPsiMultiHours_Eq12.getNumSampleDimensions()); + int D = mapPsiMultiHours_Eq12.getNumSampleDimensions(); + + // Prepare objects for iterating over the maps + BandedSampleModel bandedSampleModel = new BandedSampleModel(DataBuffer.TYPE_DOUBLE, cols, rows, D); + WritableRaster mapsPsiComposedMultiBandedWR = CoverageUtilities.createDoubleWritableRaster(cols, rows, null, bandedSampleModel, JGTConstants.doubleNovalue); + + RandomIter inSoilThickness_Iter = RandomIterFactory.create(inSoilThickness.getRenderedImage(), null); + RandomIter mapPsiMultiHours_Eq9_Iter = RandomIterFactory.create(mapPsiMultiHours_Eq9.getRenderedImage(), null); + RandomIter mapPsiMultiHours_Eq12_Iter = RandomIterFactory.create(mapPsiMultiHours_Eq12.getRenderedImage(), null); + + if(pm!=null){pm.beginTask("Starting computing combined Psi at bedrock...", rows*minNumBands);} + double psi_bEq9; + double psi_bEq12; + // First cycle through the bands for which we have changing Psi due to v. infiltration while no lateral flow + if(pm!=null){pm.message("First calculating Composed Psi combinig Psi from Eq 9 and Eq 12 of reference paper.. ");} + for( int t = 1; t <= minNumBands; t++ ) { + for( int r = 0; r < rows; r++ ) { + for( int c = 0; c < cols; c++ ) { + + psi_bEq9 = mapPsiMultiHours_Eq9_Iter.getSampleDouble(c, r, (t-1)); + psi_bEq12 = mapPsiMultiHours_Eq12_Iter.getSampleDouble(c, r, (t-1)); + + if (psi_bEq12 < 0 && !Double.isNaN(psi_bEq12)){ + mapsPsiComposedMultiBandedWR.setSample(c, r, (t-1), psi_bEq12); + } + if (psi_bEq9 > 0 && !Double.isNaN(psi_bEq9)){ + mapsPsiComposedMultiBandedWR.setSample(c, r, (t-1), psi_bEq9); + } + } + } + } + + // Now cycle through bands whose rainfall duration exceeds max Twt in basing + if(pm!=null){pm.message("Now setting Composed Psi to Psi-during-lateral-flow for simulation hours exceeding T_wt_up.. ");} + for( int t = minNumBands+1; t <= D; t++ ) { + for( int r = 0; r < rows; r++ ) { + for( int c = 0; c < cols; c++ ) { + + psi_bEq12 = mapPsiMultiHours_Eq12_Iter.getSampleDouble(c, r, (t-1)); + + mapsPsiComposedMultiBandedWR.setSample(c, r, (t-1), psi_bEq12); + + } + } + } + + if(pm!=null){pm.message("Now setting Composed Psi to zero where NaN.. ");} + double soil_thickness, psi_b_Composed; + for( int t = 1; t <= D; t++ ) { + for( int r = 0; r < rows; r++ ) { + for( int c = 0; c < cols; c++ ) { + + psi_b_Composed = mapsPsiComposedMultiBandedWR.getSampleDouble(c, r, (t-1)); + soil_thickness = inSoilThickness_Iter.getSampleDouble(c, r, 0); + + if(soil_thickness > 0.0 && Double.isNaN(psi_b_Composed)){ + mapsPsiComposedMultiBandedWR.setSample(c, r, (t-1), 0.0); + } + } + } + } + + return CoverageUtilities.buildCoverage("Psi_at_Bedrock_Combined_" + pReturnTime + "y_", mapsPsiComposedMultiBandedWR, regionMap, inSoilThickness.getCoordinateReferenceSystem()); + + } + + + /** + * #### calcolo FS infinite slope model ####### + * Initial SAFETY FACTOR based on V : initial soil moisture content. + * Equation (14a) & (14b) + * psi_i = the provided initial psi map out of a constant replicated all over the basin or out of some algebra + * + * @param inPsi_Initial GridCoverage2D + * @param inSoil_Thickness GridCoverage2D + * @param inPhi GridCoverage2D + * @param inGammaSoil GridCoverage2D + * @param inCohesion GridCoverage2D + * @param inAlfaVanGen GridCoverage2D + * @param inNVanGen GridCoverage2D + * @param inSlopeFixedBorders GridCoverage2D + * @param pm + * @return GridCoverage2D Safety_Factor_initial + */ + public static GridCoverage2D computeSafetyFactor_Initial(GridCoverage2D inPsi_Initial, GridCoverage2D inSoil_Thickness, GridCoverage2D inPhi, GridCoverage2D inGammaSoil, GridCoverage2D inCohesion, GridCoverage2D inAlfaVanGen, GridCoverage2D inNVanGen, GridCoverage2D inSlopeFixedBorders, IJGTProgressMonitor pm) { + + RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inPhi); + int cols = regionMap.getCols(); + int rows = regionMap.getRows(); + + RandomIter inPsi_Initial_Iter = RandomIterFactory.create(inPsi_Initial.getRenderedImage(), null); + RandomIter inSoil_Thickness_Iter = RandomIterFactory.create(inSoil_Thickness.getRenderedImage(), null); + RandomIter inPhi_Iter = RandomIterFactory.create(inPhi.getRenderedImage(), null); + RandomIter inGammaSoil_Iter = RandomIterFactory.create(inGammaSoil.getRenderedImage(), null); + RandomIter inCohesion_Iter = RandomIterFactory.create(inCohesion.getRenderedImage(), null); + RandomIter inAlfaVanGen_Iter = RandomIterFactory.create(inAlfaVanGen.getRenderedImage(), null); + RandomIter inNVAnGen_Iter = RandomIterFactory.create(inNVanGen.getRenderedImage(), null); + RandomIter inSlopeFixedBorders_Iter = RandomIterFactory.create(inSlopeFixedBorders.getRenderedImage(), null); + + WritableRaster mapSafetyFactor_Initial_WR = CoverageUtilities.createDoubleWritableRaster(cols, rows, null, null, JGTConstants.doubleNovalue); + + double psi_i; + double soil_thick; + double tan_phi; + double gamma; + double gamma_w = 1; + double cohesion; + double alfaVanGen; + double nVanGen; + double angle; + double tg; + double ctg; + double pSF_Initial; + + for( int r = 0; r < rows; r++ ) { + for( int c = 0; c < cols; c++ ) { + + psi_i = inPsi_Initial_Iter.getSampleDouble(c, r, 0); + soil_thick = inSoil_Thickness_Iter.getSampleDouble(c, r, 0); + tan_phi = Math.tan(inPhi_Iter.getSampleDouble(c, r, 0)/180.0*Math.PI); + gamma = inGammaSoil_Iter.getSampleDouble(c, r, 0)/10.0; + cohesion = inCohesion_Iter.getSampleDouble(c, r, 0); + alfaVanGen = inAlfaVanGen_Iter.getSampleDouble(c, r, 0); + nVanGen = inNVAnGen_Iter.getSampleDouble(c, r, 0); + angle = Math.atan(inSlopeFixedBorders_Iter.getSampleDouble(c, r, 0)); + tg = Math.tan(angle); + ctg = 1.0/tg; + + if(psi_i <= 0){ + pSF_Initial = + (tan_phi/tg)+ + (gamma_w/gamma)*(psi_i/soil_thick)*(tg+ctg)*tan_phi+ + (2*cohesion)/ + ((gamma*10)*soil_thick*Math.sin(2*angle)); + + mapSafetyFactor_Initial_WR.setSample(c, r, 0, pSF_Initial); + } + + if(psi_i > 0){ + pSF_Initial = + (tan_phi/tg)+ + (Math.pow( (1+ Math.pow((alfaVanGen*psi_i),nVanGen)),(-1-1/nVanGen) ) )* + (gamma_w/gamma)*(psi_i/soil_thick)*(tg+ctg)*tan_phi+ + (2*cohesion)/ + ((gamma*10)*soil_thick*Math.sin(2*angle)); + + mapSafetyFactor_Initial_WR.setSample(c, r, 0, pSF_Initial); + } + } + } + + return CoverageUtilities.buildCoverage("Safety_Factor_initial", mapSafetyFactor_Initial_WR, regionMap, inSoil_Thickness.getCoordinateReferenceSystem()); + + } + + /** + * #### Calulate Saety Factor infinite slope model ####### + * 2. SF for t=1...D' + * Equation (14a) & (14b) + * but using combined Psi from Eq.(9) and Eq.(12) instead of initial Psi map + * + * @param pReturnTime int + * @param pRainfallDuration int + * @param inPsi_Initial GridCoverage2D + * @param inSoil_Thickness GridCoverage2D + * @param inPhi GridCoverage2D + * @param inGammaSoil GridCoverage2Di + * @param inCohesion GridCoverage2D + * @param inAlfaVanGen GridCoverage2D + * @param inNVanGen GridCoverage2D + * @param inSlopeFixedBorders GridCoverage2D + * @param pm + * @return GridCoverage2D Safety_Factor_initial + */ + public static GridCoverage2D computeSafetyFactorInfiniteSlopeWithSaturatedZonesSingleBand(int pReturnTime, int pRainfallDuration, GridCoverage2D inPsi_Combined, GridCoverage2D inSoil_Thickness, GridCoverage2D inPhi, GridCoverage2D inGammaSoil, GridCoverage2D inCohesion, GridCoverage2D inAlfaVanGen, GridCoverage2D inNVanGen, GridCoverage2D inSlopeFixedBorders, IJGTProgressMonitor pm) { + + RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inPhi); + int cols = regionMap.getCols(); + int rows = regionMap.getRows(); + + RandomIter inPsiCombinedIter = RandomIterFactory.create(inPsi_Combined.getRenderedImage(), null); + RandomIter inSoilThicknessIter = RandomIterFactory.create(inSoil_Thickness.getRenderedImage(), null); + RandomIter inPhiIter = RandomIterFactory.create(inPhi.getRenderedImage(), null); + RandomIter inGammaSoilIter = RandomIterFactory.create(inGammaSoil.getRenderedImage(), null); + RandomIter inCohesionIter = RandomIterFactory.create(inCohesion.getRenderedImage(), null); + RandomIter inAlfaVanGenIter = RandomIterFactory.create(inAlfaVanGen.getRenderedImage(), null); + RandomIter inNVAnGenIter = RandomIterFactory.create(inNVanGen.getRenderedImage(), null); + RandomIter inSlopeFixedBordersIter = RandomIterFactory.create(inSlopeFixedBorders.getRenderedImage(), null); + + // Prepare objects for iterating over the maps + BandedSampleModel bandedSampleModel = new BandedSampleModel(DataBuffer.TYPE_DOUBLE, cols, rows, pRainfallDuration); + + WritableRaster mapSafetyFactor_Hydologic_WR = CoverageUtilities.createDoubleWritableRaster(cols, rows, null, null, JGTConstants.doubleNovalue); + + double psi_combined; + double soil_thick; + double tan_phi; + double gamma; + double gamma_w = 1; + double cohesion; + double alfaVanGen; + double nVanGen; + double angle; + double tg; + double ctg; + double pSF_Hydologic; + + //for( int t = 1; t <= pRainfallDuration; t++ ) { + for( int c = 0; c < cols; c++ ) { + for( int r = 0; r < rows; r++ ) { + + psi_combined = inPsiCombinedIter.getSampleDouble(c, r, (pRainfallDuration-1)); + + soil_thick = inSoilThicknessIter.getSampleDouble(c, r, 0); + tan_phi = Math.tan(inPhiIter.getSampleDouble(c, r, 0)/180.0*Math.PI); + gamma = inGammaSoilIter.getSampleDouble(c, r, 0)/10.0; + cohesion = inCohesionIter.getSampleDouble(c, r, 0); + alfaVanGen = inAlfaVanGenIter.getSampleDouble(c, r, 0); + nVanGen = inNVAnGenIter.getSampleDouble(c, r, 0); + angle = Math.atan(inSlopeFixedBordersIter.getSampleDouble(c, r, 0)); + tg = Math.tan(angle); + ctg = 1.0/tg; + + if(psi_combined <= 0.0){ + + pSF_Hydologic = + (tan_phi/tg)+ + (gamma_w/gamma)*(psi_combined/soil_thick)*(tg+ctg)*tan_phi+ + (2*cohesion)/ + ((gamma*10)*soil_thick*Math.sin(2*angle)); + + mapSafetyFactor_Hydologic_WR.setSample(c, r, 0, pSF_Hydologic); + } + + if(psi_combined > 0.0){ + + pSF_Hydologic = + (tan_phi/tg)+ + ( Math.pow( (1+ Math.pow((alfaVanGen*psi_combined),nVanGen)),(-1-1/nVanGen) ) )* + (gamma_w/gamma)*(psi_combined/soil_thick)*(tg+ctg)*tan_phi+ + (2*cohesion)/ + ((gamma*10)*soil_thick*Math.sin(2*angle)); + + mapSafetyFactor_Hydologic_WR.setSample(c, r, 0, pSF_Hydologic); + } + + } + } + //} + return CoverageUtilities.buildCoverage("Safety_Factor_Hydrologic_" + pReturnTime + "y_" + pRainfallDuration + "h", mapSafetyFactor_Hydologic_WR, regionMap, inSoil_Thickness.getCoordinateReferenceSystem()); + + } + + /** + * #### Calulate Saety Factor infinite slope model ####### + * 2. SF for t=1...D' + * Equation (14a) & (14b) + * but using combined Psi from Eq.(9) and Eq.(12) instead of initial Psi map + * + * @param pReturnTime int + * @param pRainfallDuration int + * @param inPsi_Initial GridCoverage2D + * @param inSoil_Thickness GridCoverage2D + * @param inPhi GridCoverage2D + * @param inGammaSoil GridCoverage2Di + * @param inCohesion GridCoverage2D + * @param inAlfaVanGen GridCoverage2D + * @param inNVanGen GridCoverage2D + * @param inSlopeFixedBorders GridCoverage2D + * @param pm + * @return GridCoverage2D Safety_Factor_initial + */ + public static GridCoverage2D computeSafetyFactor_InfiniteSlope_with_SaturatedZones(int pReturnTime, int pRainfallDuration, GridCoverage2D inPsi_Combined, GridCoverage2D inSoil_Thickness, GridCoverage2D inPhi, GridCoverage2D inGammaSoil, GridCoverage2D inCohesion, GridCoverage2D inAlfaVanGen, GridCoverage2D inNVanGen, GridCoverage2D inSlopeFixedBorders, IJGTProgressMonitor pm) { + + RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inPhi); + int cols = regionMap.getCols(); + int rows = regionMap.getRows(); + + RandomIter inPsi_Combined_Iter = RandomIterFactory.create(inPsi_Combined.getRenderedImage(), null); + RandomIter inSoil_Thickness_Iter = RandomIterFactory.create(inSoil_Thickness.getRenderedImage(), null); + RandomIter inPhi_Iter = RandomIterFactory.create(inPhi.getRenderedImage(), null); + RandomIter inGammaSoil_Iter = RandomIterFactory.create(inGammaSoil.getRenderedImage(), null); + RandomIter inCohesion_Iter = RandomIterFactory.create(inCohesion.getRenderedImage(), null); + RandomIter inAlfaVanGen_Iter = RandomIterFactory.create(inAlfaVanGen.getRenderedImage(), null); + RandomIter inNVAnGen_Iter = RandomIterFactory.create(inNVanGen.getRenderedImage(), null); + RandomIter inSlopeFixedBorders_Iter = RandomIterFactory.create(inSlopeFixedBorders.getRenderedImage(), null); + + // Prepare objects for iterating over the maps + BandedSampleModel bandedSampleModel = new BandedSampleModel(DataBuffer.TYPE_DOUBLE, cols, rows, pRainfallDuration); + + WritableRaster mapSafetyFactor_Hydologic_WR = CoverageUtilities.createDoubleWritableRaster(cols, rows, null, bandedSampleModel, JGTConstants.doubleNovalue); + + double psi_combined; + double soil_thick; + double tan_phi; + double gamma; + double gamma_w = 1; + double cohesion; + double alfaVanGen; + double nVanGen; + double angle; + double tg; + double ctg; + double pSF_Hydologic; + + for( int t = 1; t <= pRainfallDuration; t++ ) { + for( int c = 0; c < cols; c++ ) { + for( int r = 0; r < rows; r++ ) { + + psi_combined = inPsi_Combined_Iter.getSampleDouble(c, r, (t-1)); + + soil_thick = inSoil_Thickness_Iter.getSampleDouble(c, r, 0); + tan_phi = Math.tan(inPhi_Iter.getSampleDouble(c, r, 0)/180.0*Math.PI); + gamma = inGammaSoil_Iter.getSampleDouble(c, r, 0)/10.0; + cohesion = inCohesion_Iter.getSampleDouble(c, r, 0); + alfaVanGen = inAlfaVanGen_Iter.getSampleDouble(c, r, 0); + nVanGen = inNVAnGen_Iter.getSampleDouble(c, r, 0); + angle = Math.atan(inSlopeFixedBorders_Iter.getSampleDouble(c, r, 0)); + tg = Math.tan(angle); + ctg = 1.0/tg; + + if(psi_combined <= 0.0){ + + pSF_Hydologic = + (tan_phi/tg)+ + (gamma_w/gamma)*(psi_combined/soil_thick)*(tg+ctg)*tan_phi+ + (2*cohesion)/ + ((gamma*10)*soil_thick*Math.sin(2*angle)); + + mapSafetyFactor_Hydologic_WR.setSample(c, r, (t-1), pSF_Hydologic); + } + + if(psi_combined > 0.0){ + + pSF_Hydologic = + (tan_phi/tg)+ + ( Math.pow( (1+ Math.pow((alfaVanGen*psi_combined),nVanGen)),(-1-1/nVanGen) ) )* + (gamma_w/gamma)*(psi_combined/soil_thick)*(tg+ctg)*tan_phi+ + (2*cohesion)/ + ((gamma*10)*soil_thick*Math.sin(2*angle)); + + mapSafetyFactor_Hydologic_WR.setSample(c, r, (t-1), pSF_Hydologic); + } + + + + } + } + } + return CoverageUtilities.buildCoverage("Safety_Factor_Hydrologic_" + pReturnTime + "y_" + pRainfallDuration + "h", mapSafetyFactor_Hydologic_WR, regionMap, inSoil_Thickness.getCoordinateReferenceSystem()); + + } + + + + public static GridCoverage2D computeSafetyFactorTOTAL(GridCoverage2D[] singleBandCoverageArray, int returnTime, IJGTProgressMonitor pm ){ + + if(singleBandCoverageArray.length>0){ + + RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(singleBandCoverageArray[0]); + int cols = regionMap.getCols(); + int rows = regionMap.getRows(); + + RandomIter[] mapIterators = new RandomIter[singleBandCoverageArray.length]; + WritableRaster singleBandWR = CoverageUtilities.createDoubleWritableRaster(cols, rows, null, null, JGTConstants.doubleNovalue); + WritableRandomIter singleBand_Iter = RandomIterFactory.createWritable(singleBandWR, null); + + String[] safetyFactorMapsNames = new String[singleBandCoverageArray.length]; + + for(int i = 0; i 0.0) + psiWRIter[b].setSample(c, r, 0, pixel[b]); + } + } + } + + GridCoverage2D[] outCoverageArray = new GridCoverage2D[bands]; + for( int i = 0; i < bands; i++ ) { + outCoverageArray[i] = CoverageUtilities.buildCoverage("psi", psiMultiHoursWR[i], regionMap, + multibandCoverage.getCoordinateReferenceSystem()); + } + + return outCoverageArray; + + } + + + public static double round8Decimals( double d ) { + + Locale loc = Locale.US; + + NumberFormat f = NumberFormat.getInstance(loc); + if (f instanceof DecimalFormat) { + ((DecimalFormat) f).setDecimalSeparatorAlwaysShown(true); + } + + f.setMaximumFractionDigits(8); + f.setMinimumIntegerDigits(1); + + if (!Double.isInfinite(d) && !Double.isNaN(d)) { + return Double.valueOf(f.format(d)); + } else { + return d; + } + } + + + public static double maxValue(double[] array) { + double max = array[0]; + for (int i = 0; i < array.length; i++) { + if (array[i] > max) { + max = array[i]; + } + } + return max; + } + + public static double minValue(double[] array) { + double min = array[0]; + for (int i = 0; i < array.length; i++) { + if (array[i] < min) { + min = array[i]; + } + } + return min; + } + + + /* + public static GridCoverage2D[] calculateMapsOfPsiAtBedrockDuringVerticalInfiltration( GridCoverage2D Twt, GridCoverage2D psiInit, + double I, GridCoverage2D soil_thickness, GridCoverage2D theta_s, GridCoverage2D theta_r, GridCoverage2D alfaVanGenuchten, + GridCoverage2D nVanGenuchten, IJGTProgressMonitor pm ) { + + RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(soil_thickness); + int cols = regionMap.getCols(); + int rows = regionMap.getRows(); + + // Prepare objects for iterating over the maps + RandomIter mapPsiInitIter = RandomIterFactory.create(psiInit.getRenderedImage(), null); + RandomIter mapSoilThicknessIter = RandomIterFactory.create(soil_thickness.getRenderedImage(), null); + RandomIter mapTheta_SIter = RandomIterFactory.create(theta_s.getRenderedImage(), null); + RandomIter mapTheta_RIter = RandomIterFactory.create(theta_r.getRenderedImage(), null); + RandomIter mapAalfaVanGenuchtenIter = RandomIterFactory.create(alfaVanGenuchten.getRenderedImage(), null); + RandomIter mapNVanGenuchtenIter = RandomIterFactory.create(nVanGenuchten.getRenderedImage(), null); + + // WritableRaster psiWR = CoverageUtilities.renderedImage2WritableRaster(psiInit.getRenderedImage(), false); + // WritableRandomIter psiWRIter = RandomIterFactory.createWritable(psiWR, null); + + double maxTwt = CoverageUtilities.getMinMaxMeanSdevCount(Twt, null)[1]; + int countOfToBeStoredPsiCoverages = (int) (Math.round(maxTwt)) + 1; + + int[] bandOffsets = new int[countOfToBeStoredPsiCoverages]; + for( int o = 0; o < countOfToBeStoredPsiCoverages; o++ ) { + bandOffsets[o] = o * cols; + } + + ComponentSampleModel sampleModel_old = new ComponentSampleModel(DataBuffer.TYPE_DOUBLE, cols, rows, 1, cols, bandOffsets); + BandedSampleModel sampleModel = new BandedSampleModel(DataBuffer.TYPE_DOUBLE, cols, rows, countOfToBeStoredPsiCoverages); + + int numBands = sampleModel.getNumBands(); + WritableRaster psiMultiHoursWR = CoverageUtilities.createDoubleWritableRaster(cols, rows, null, sampleModel, JGTConstants.doubleNovalue); + WritableRandomIter psiWRIter = RandomIterFactory.createWritable(psiMultiHoursWR, null); + + double pPreviousPsi_bb, pI, pSoil_thickness, pTheta_s, pTheta_r, pAlfaVanGenuchten, pNVanGenuchten; + + pm.beginTask("Started computing Psi maps after each of the " + numBands + " hour/s of simulated rainfall...", rows); + long start = System.nanoTime(); + for( int r = 0; r < rows; r++ ) { + for( int c = 0; c < cols; c++ ) { + // Check we are in the basin by probing Soil Thickness + pSoil_thickness = mapSoilThicknessIter.getSampleDouble(c, r, 0); + + if (!Double.isNaN(pSoil_thickness)) { + + pPreviousPsi_bb = mapPsiInitIter.getSampleDouble(c, r, 0); + pI = I; + pTheta_s = mapTheta_SIter.getSampleDouble(c, r, 0); + pTheta_r = mapTheta_RIter.getSampleDouble(c, r, 0); + pAlfaVanGenuchten = mapAalfaVanGenuchtenIter.getSampleDouble(c, r, 0); + pNVanGenuchten = mapNVanGenuchtenIter.getSampleDouble(c, r, 0); + + double[] pixel = new double[countOfToBeStoredPsiCoverages]; + // Cycle in the total number of simulation hours (derived from the max Twt time of the basin for given Return Time and + // Rainfall Intensity + for( int j = 0; j < countOfToBeStoredPsiCoverages; j++ ) { + int i = 1; + // Loop until the sum of iteration steps over one cell reaches one hour (3600 sec) then write computed psi to raster + while( ((i * ParameterCalculationFunctions.DELTA_T_INTEGRATION_STEP_IN_SECONDS) % 3600) != 0 ) { + + // int counter = ((i * ParameterCalculationFunctions.DELTA_T_INTEGRATION_STEP_IN_SECONDS) % 3600); + + pPreviousPsi_bb = ParameterCalculationFunctions.calculatePsiAtBedrockDuringVerticalInfiltration( + pPreviousPsi_bb, pI, pSoil_thickness, pTheta_s, pTheta_r, pAlfaVanGenuchten, pNVanGenuchten); + i++; + } + // psiWRIter.setSample(c, r, j, pPreviousPsi_bb); + pixel[j] = pPreviousPsi_bb; + } + psiWRIter.setPixel(c, r, pixel); + // DEBUG CODE + // + //double[] outPixel = new double[4]; + //psiMultiHoursWR.getPixel(252,682,outPixel); + //psiMultiHoursWR.getPixel(c,r,outPixel); + //double[] bandValues = outPixel; + // + } + } + pm.worked(1); + } + pm.message("Elapsed time: " + (System.nanoTime() - start) / 1000000000 + " sec."); + pm.done(); + + GridCoverage2D[] psiMapsAtIncreasingHours = new GridCoverage2D[psiMultiHoursWR.getNumBands()]; + + for( int band_Hour_Index = 0; band_Hour_Index < psiMultiHoursWR.getNumBands(); band_Hour_Index++ ) { + + int[] bandList = new int[]{band_Hour_Index}; + WritableRaster currentPsiBand = psiMultiHoursWR.createWritableChild(0, 0, cols, rows, 0, 0, bandList); + + psiMapsAtIncreasingHours[band_Hour_Index] = CoverageUtilities.buildCoverage("psimultihours", currentPsiBand, regionMap, + Twt.getCoordinateReferenceSystem()); + } + // PROBE CODE for Coverages as GridCoverage2D ARRAY + // + //final Point2D.Double point = new Point2D.Double(); + //point.x = 623630.1509; + //point.y = 5137453.8354; + //double[] bufferCov = null; + //for( int band_Hour_Index = 0; band_Hour_Index < psiMultiHoursWR.getNumBands(); band_Hour_Index++ ) { + // bufferCov = psiMapsAtIncreasingHours[band_Hour_Index].evaluate(point, bufferCov); + //} + // + return psiMapsAtIncreasingHours; + + } + */ + + +} diff --git a/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utils/MapDumpingFunctions.java b/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utils/MapDumpingFunctions.java new file mode 100644 index 000000000..672aaa3e9 --- /dev/null +++ b/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utils/MapDumpingFunctions.java @@ -0,0 +1,314 @@ +/* + * This file is part of the "CI-slam module": an addition to JGrassTools + * It has been entirely contributed by Marco Foi (www.mcfoi.it) + * + * "CI-slam module" is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.utils; + +import java.awt.image.WritableRaster; +import java.util.HashMap; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; + +import javax.media.jai.iterator.RandomIter; +import javax.media.jai.iterator.RandomIterFactory; +import javax.media.jai.iterator.WritableRandomIter; + +import org.geotools.coverage.grid.GridCoverage2D; +import org.jgrasstools.gears.io.rasterwriter.OmsRasterWriter; +import org.jgrasstools.gears.libs.modules.JGTConstants; +import org.jgrasstools.gears.libs.monitor.IJGTProgressMonitor; +import org.jgrasstools.gears.utils.RegionMap; +import org.jgrasstools.gears.utils.coverage.CoverageUtilities; +import org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.utils.MapCalculationFunctions.MapOfCumulatedValue; +import org.opengis.referencing.crs.CoordinateReferenceSystem; + +public class MapDumpingFunctions { + + public static void dumpMapsOfPsiMultiHours( GridCoverage2D mapsPsiMultiHours, int y, int h, String pOutFolder, IJGTProgressMonitor pm ) { + + pOutFolder = fixOutputFolderString(pOutFolder); + //String tempDir = System.getProperty("java.io.tmpdir"); + if(pm != null){pm.message("Dumping Psi maps to " + pOutFolder);} + + GridCoverage2D[] outHourlyPsiMapArray = MapCalculationFunctions.fromMultibandCoverageToCoverageArray(mapsPsiMultiHours); + + for( int i = 0; i < outHourlyPsiMapArray.length; i++ ) { + + try { + OmsRasterWriter.writeRaster(pOutFolder + "Psi_" + y + "y_" + h + "h_" + (i + 1) + "hsim.asc", outHourlyPsiMapArray[i]); + } catch (Exception e) { + e.printStackTrace(); + } + } + + } + + public static void dumpMapsOfTwt( HashMap mapsHashMap, String pOutFolder, IJGTProgressMonitor pm ) { + + pOutFolder = fixOutputFolderString(pOutFolder); + + for( Integer[] keyArr : mapsHashMap.keySet() ) { + + if(pm != null){pm.message("Dumping Twt maps to " + pOutFolder);} + try { + OmsRasterWriter.writeRaster(pOutFolder + "Twt_" + keyArr[1] + "y_" + keyArr[0] + "h.asc", mapsHashMap.get(keyArr)); + pm.message("Stats for Twt map " + keyArr[1] + "y_" + keyArr[0] + " " + MapCalculationFunctions.getCoverageStatsAsString(mapsHashMap.get(keyArr))); + } catch (Exception e) { + if(pm != null){pm.errorMessage("An error was encounterd while dumping Twt maps to file in dir " + pOutFolder);} + e.printStackTrace(); + } + + } + + } + + public static void dumpMapsOfPsiMultiHoursToTempDir( GridCoverage2D[] mapsPsiMultiHours, String pOutFolder, IJGTProgressMonitor pm ) { + + pOutFolder = fixOutputFolderString(pOutFolder); + + RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(mapsPsiMultiHours[0]); + int cols = regionMap.getCols(); + int rows = regionMap.getRows(); + + // Prepare objects for iterating over the maps + + int maps = mapsPsiMultiHours.length; + + WritableRaster psiHourlyMapWR; + WritableRandomIter psiHourlyMapIter; + RandomIter mapPsiInitIter; + for( int i = 0; i < maps; i++ ) { + + mapPsiInitIter = RandomIterFactory.create(mapsPsiMultiHours[i].getRenderedImage(), null); + psiHourlyMapWR = CoverageUtilities.createDoubleWritableRaster(cols, rows, null, null, JGTConstants.doubleNovalue); + psiHourlyMapIter = RandomIterFactory.createWritable(psiHourlyMapWR, null); + + if(pm != null){pm.beginTask("Starting to copy Coverages into Rasters...", rows);} + for( int r = 0; r < rows; r++ ) { + for( int c = 0; c < cols; c++ ) { + double value = mapPsiInitIter.getSample(c, r, 0); + if (!Double.isNaN(value)) + psiHourlyMapIter.setSample(c, r, 0, value); + } + } + + if(pm != null){pm.message("Dumping Psi map to " + pOutFolder);} + + GridCoverage2D outHourlyPsiMap = CoverageUtilities.buildCoverage("psi", psiHourlyMapWR, regionMap, + mapsPsiMultiHours[0].getCoordinateReferenceSystem()); + try { + OmsRasterWriter.writeRaster(pOutFolder + "Psi_" + (i + 1) + "h.asc", outHourlyPsiMap); + } catch (Exception e) { + e.printStackTrace(); + } + + } + + } + + /** + * Takes a GridCoverage2d with several bands and dumps each one as a single ESRI Ascii Grid + * inside the provided the destination folder. + * @param multiband_Coverage + * @param pOutFolder The string path of the destination folder. MUST be provided linux-style using forward slashes "/" also in WINDOWS and MUST end with a backslash. + * @param pm The IJGTProgressMonitor to notify of the task. Can be null. + * @param message The custom message to display while dumping. Ignored if 'pmi is null + */ + public static void dumpMultiBandCoverage( GridCoverage2D multiband_Coverage, + String pOutFolder, IJGTProgressMonitor pm, String message ) { + + if(pm != null){pm.message(message + pOutFolder);} + + pOutFolder = fixOutputFolderString(pOutFolder); + + int availableThreads = Runtime.getRuntime().availableProcessors(); + + ExecutorService fixedThreadPool = Executors.newFixedThreadPool(availableThreads); + + RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(multiband_Coverage); + int cols = regionMap.getCols(); + int rows = regionMap.getRows(); + + CoordinateReferenceSystem crs = multiband_Coverage.getCoordinateReferenceSystem(); + + int bands = multiband_Coverage.getNumSampleDimensions(); + + for( int band = 0; band < bands; band++ ) { + + RandomIter multiBandMapIter = RandomIterFactory.create(multiband_Coverage.getRenderedImage(), null); + + String filePrefix = multiband_Coverage.getName().toString(); + + IRunBehavior rb = new RunMultiBandFileDumper(band, cols, rows, filePrefix, pOutFolder, multiBandMapIter, regionMap, crs, pm); + + fixedThreadPool.execute(new FileDumperRunner(rb)); + } + + try { + fixedThreadPool.shutdown(); + fixedThreadPool.awaitTermination(30, TimeUnit.DAYS); + fixedThreadPool.shutdownNow(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + } + + + /** + * Takes a GridCoverage2d with several bands and dumps the requested one to a single ESRI Ascii Grid + * inside the provided the destination folder. + * @param multiband_Coverage + * @param bandToDump int The index of the band to dump: 24th band has index 23. + * @param pOutFolder String The string path of the destination folder. MUST be provided linux-style using forward slashes "/" also in WINDOWS and MUST end with a backslash. + * @param pm The IJGTProgressMonitor to notify of the task. Can be null. + * @param message String The custom message to display while dumping. Ignored if 'pmi is null + */ + public static void dumpMultiBandCoverage( GridCoverage2D multiband_Coverage, int bandToDump, String pOutFolder, + IJGTProgressMonitor pm, String message ) { + + if(pm != null){pm.message(message + pOutFolder);} + + pOutFolder = fixOutputFolderString(pOutFolder); + + int availableThreads = Runtime.getRuntime().availableProcessors(); + + ExecutorService fixedThreadPool = Executors.newFixedThreadPool(availableThreads); + + RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(multiband_Coverage); + int cols = regionMap.getCols(); + int rows = regionMap.getRows(); + + CoordinateReferenceSystem crs = multiband_Coverage.getCoordinateReferenceSystem(); + + int bands = multiband_Coverage.getNumSampleDimensions(); + + if( bandToDump < bands ) { + + RandomIter multiBandMapIter = RandomIterFactory.create(multiband_Coverage.getRenderedImage(), null); + + String filePrefix = multiband_Coverage.getName().toString(); + + IRunBehavior rb = new RunMultiBandFileDumper(bandToDump, cols, rows, filePrefix, pOutFolder, multiBandMapIter, regionMap, crs, pm); + + fixedThreadPool.execute(new FileDumperRunner(rb)); + + } else { + + if(pm != null){pm.errorMessage("Could not dump band to file: the requested band does not exist in the provided Coverage!");} + + } + + try { + fixedThreadPool.shutdown(); + fixedThreadPool.awaitTermination(30, TimeUnit.DAYS); + fixedThreadPool.shutdownNow(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + } + + /** + * Wrapper for dumpSingleBandCoverage providing a default message + * @param coverage + * @param pOutFolder + * @param pm + */ + public static void dumpSingleBandCoverage( GridCoverage2D coverage, String pOutFolder, IJGTProgressMonitor pm ) { + + String message = "Dumping map to "; + dumpSingleBandCoverage(coverage, pOutFolder, pm, message); + } + + /** + * Takes a single banded GridCoverage2d and dumps it to a single ESRI Ascii grid inside the provided + * destination folder. + * @param coverage + * @param pOutFolder String The string path of the destination folder. MUST be provided linux-style using forward slashes "/" also in WINDOWS and MUST end with a backslash. + * @param pm The IJGTProgressMonitor to notify of the task. Can be null. + * @param message + */ + public static void dumpSingleBandCoverage( GridCoverage2D coverage, String pOutFolder, IJGTProgressMonitor pm, String message ) { + + if(pm != null){pm.message(message + pOutFolder);} + pOutFolder = fixOutputFolderString(pOutFolder); + CharSequence name = coverage.getName(); + try { + OmsRasterWriter.writeRaster(pOutFolder+name+".asc", coverage); + } catch (Exception e) { + if(pm != null){pm.errorMessage("Problems encountered dumping map " + name + " to " + pOutFolder +"! File was not saved.");} + e.printStackTrace(); + } + + } + + /** + * + * @param mapsOfCumulatedParameters HashMap + * @param pOutFolder String The string path of the destination folder. MUST be provided linux-style using forward slashes "/" also in WINDOWS and MUST end with a backslash. + * @param pm + */ + public static void dumpCumulatedParametersToFiles( HashMap mapsOfCumulatedParameters, String pOutFolder, IJGTProgressMonitor pm ) { + + if(pm != null){pm.message("Dumping cumulated parameters maps to " + pOutFolder);} + + pOutFolder = fixOutputFolderString(pOutFolder); + + int availableThreads = Runtime.getRuntime().availableProcessors(); + + ExecutorService fixedThreadPool = Executors.newFixedThreadPool(availableThreads); + + for(Enum e : MapCalculationFunctions.MapOfCumulatedValue.values()){ + + GridCoverage2D coverage = mapsOfCumulatedParameters.get(e); + String path = pOutFolder+e.toString()+".asc"; + + IRunBehavior rb = new RunBasicFileDumper(path, coverage); + + fixedThreadPool.execute(new FileDumperRunner(rb)); + + } + + try { + fixedThreadPool.shutdown(); + fixedThreadPool.awaitTermination(30, TimeUnit.DAYS); + fixedThreadPool.shutdownNow(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * Takes a string representing a folder path and converts it to linux-stile by + * replacing backslash with forward slashes and adding a trailing forward slash if missing. + * @param String pOutFolder + * @return String a path using forward slashes and ending with a "/" + */ + public static String fixOutputFolderString(String pOutFolder){ + + pOutFolder = pOutFolder.replace("\\", "/"); + + if(!pOutFolder.endsWith("/")){ + pOutFolder += "/"; + } + + return pOutFolder; + } + + +} diff --git a/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utils/MapPreprocessingUtilities.java b/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utils/MapPreprocessingUtilities.java new file mode 100644 index 000000000..807e80848 --- /dev/null +++ b/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utils/MapPreprocessingUtilities.java @@ -0,0 +1,340 @@ +/* + * This file is part of the "CI-slam module": an addition to JGrassTools + * It has been entirely contributed by Marco Foi (www.mcfoi.it) + * + * "CI-slam module" is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.utils; + +import java.awt.image.WritableRaster; +import java.util.List; + +import javax.media.jai.iterator.RandomIter; +import javax.media.jai.iterator.RandomIterFactory; +import javax.media.jai.iterator.WritableRandomIter; + +import org.geotools.coverage.grid.GridCoverage2D; +import org.jgrasstools.gears.libs.modules.FlowNode; +import org.jgrasstools.gears.libs.modules.GridNode; +import org.jgrasstools.gears.libs.modules.JGTConstants; +import org.jgrasstools.gears.libs.modules.Node; +import org.jgrasstools.gears.libs.monitor.IJGTProgressMonitor; +import org.jgrasstools.gears.libs.monitor.PrintStreamProgressMonitor; +import org.jgrasstools.gears.utils.RegionMap; +import org.jgrasstools.gears.utils.coverage.CoverageUtilities; +import org.jgrasstools.hortonmachine.i18n.HortonMessageHandler; +import org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.OmsCislam; + +public class MapPreprocessingUtilities { + + /** + * Runs across the passed elevation map and check corresponding points in passed Slope map. + * When a border point is found (valid in elevation map but null in slope) a new value is computed for the border + * and is assigned to the slope cell. More, when a valid but zero value is found in Slope map, the is substituted + * @param inSlope The Slope map from OmsSlope module + * @param inPit The depitted elevation map from OmsPit module + * @param minimumAllowedSlope the value to substitute to zero values (if left zero defaults to 0,009 [== tan(0.5 degree) ] ) + * @return outSlope the fixed Slope map ready for OmsCislam model + * @prerequisite The two Grids must have the same RegionMap + */ + public static GridCoverage2D slopeMapFixZeroValuesAndBorder( GridCoverage2D inSlope, GridCoverage2D inPit, double minimumAllowedSlope, + IJGTProgressMonitor pm ) { + + if (minimumAllowedSlope <= 0) { + minimumAllowedSlope = OmsCislam.MINIMM_ALLOWED_SLOPE; + } + + // TODO Check region maps of the two Grids are the same + + RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inPit); + int cols = regionMap.getCols(); + int rows = regionMap.getRows(); + double xRes = regionMap.getXres(); + double yRes = regionMap.getYres(); + + RandomIter inPitIter = CoverageUtilities.getRandomIterator(inPit); + + WritableRaster inSlopeWR = CoverageUtilities.renderedImage2WritableRaster(inSlope.getRenderedImage(), false); + WritableRandomIter inSlopeIter = RandomIterFactory.createWritable(inSlopeWR, null); + + pm.beginTask("Started fixing slope borders and zero values..", rows); //$NON-NLS-1$ + + GridNode elevationNode; + // Cycling into the valid region. + for( int r = 0; r < rows; r++ ) { + for( int c = 0; c < cols; c++ ) { + + elevationNode = new GridNode(inPitIter, cols, rows, xRes, yRes, c, r); + + if (elevationNode.isValid()) { + + double slopeValue = elevationNode.getValueFromMap(inSlopeIter); + // Check if we are on the border (slope maps out of OmsSlope module are + // one cell smaller than parent elevation map unless fixed) + if (JGTConstants.isNovalue(slopeValue)) { + // We are on the border where elevation is valid but slope is not: + // compute value for slope + List surroundingValidNodes = elevationNode.getValidSurroundingNodes(); + double newSlope = minimumAllowedSlope; + for( GridNode elevNode : surroundingValidNodes ) { + double slope = elevationNode.getSlopeTo(elevNode); + if (slope > newSlope) { + newSlope = slope; + } + } + elevationNode.setValueInMap(inSlopeIter, newSlope); + } else if (slopeValue == 0.0) { + // We are inside the basin but on a 'plateau' of the elevation model + // Implement fixing: zero values cells are given value 0.009 [tan(0.5degree)] + elevationNode.setValueInMap(inSlopeIter, minimumAllowedSlope); + } + } + } + pm.worked(1); + } + pm.done(); + + // CoverageUtilities.setNovalueBorder(mflowWR); + GridCoverage2D outFixedSlope = CoverageUtilities.buildCoverage("slope", inSlopeWR, regionMap, inPit.getCoordinateReferenceSystem()); + + return outFixedSlope; + } + + /** + * Runs across the passed elevation map and check corresponding points in passed Slope map. + * When a border point is found (valid in elevation map but null in slope) a new value is computed for the border + * and is assigned to the slope cell. More, when a valid but zero value is found in Slope map, a default value of 0.009 is substituted + * @param inPit depitted elevation map from OmsPit module + * @param inSlope slope map from OmsSlope module + * @return outSlope the fixed Slope map ready for OmsCislam model + * @prerequisite The two Grids must have the same RegionMap + */ + public static GridCoverage2D slopeMapFixZeroValuesAndBorder( GridCoverage2D inPit, GridCoverage2D inSlope, IJGTProgressMonitor pm ) { + return slopeMapFixZeroValuesAndBorder(inSlope, inPit, OmsCislam.MINIMM_ALLOWED_SLOPE, pm); + } + + /** + * Runs across the passed Flow map and marks any outlet with the FlowNode.OUTLET constant (=10) + * @param inFlow + * @param pm + * @return + */ + public static GridCoverage2D flowMapMarkOutlet( GridCoverage2D inFlow, IJGTProgressMonitor pm ) { + // Implement fixing: mark Outlet cell with value 10 + RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inFlow); + int cols = regionMap.getCols(); + int rows = regionMap.getRows(); + // double xRes = regionMap.getXres(); + // double yRes = regionMap.getYres(); + + // RandomIter flowIter = CoverageUtilities.getRandomIterator(inFlow); + + WritableRaster mflowWR = CoverageUtilities.renderedImage2WritableRaster(inFlow.getRenderedImage(), false); + WritableRandomIter mflowIter = RandomIterFactory.createWritable(mflowWR, null); + + pm.beginTask("Start finding Outlets..", rows); //$NON-NLS-1$ + + // Cycling into the valid region. + for( int r = 0; r < rows; r++ ) { + for( int c = 0; c < cols; c++ ) { + FlowNode flowNode = new FlowNode(mflowIter, cols, rows, c, r); + if (flowNode.isValid() && flowNode.isHeadingOutside()) { + flowNode.setValueInMap(mflowIter, FlowNode.OUTLET); + pm.message("A node was marked as an Outlet"); + } + } + pm.worked(1); + } + pm.done(); + + // CoverageUtilities.setNovalueBorder(mflowWR); + GridCoverage2D outMarkedFlow = CoverageUtilities.buildCoverage("flow", mflowWR, regionMap, inFlow.getCoordinateReferenceSystem()); + + return outMarkedFlow; + } + + public static boolean isValidFlowMap( GridCoverage2D inFlow, IJGTProgressMonitor pm ) { + + int outletCount = countCellsWith10Value(inFlow, pm); + + if (outletCount == 0) { + pm.errorMessage("No cell marked as outlets (value 10) was found. Use OmsMarkoutles model to fix this problem."); + return false; + } else if (outletCount > 1) { + pm.errorMessage("More than one cell marked as outlet (value 10) was found. This Fow map may include more than one basin and is so not suitable for the OmsCislam module."); + return false; + } else { + return true; + } + } + + public static int countCellsWith10Value( GridCoverage2D inMap, IJGTProgressMonitor pm ) { + RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inMap); + int cols = regionMap.getCols(); + int rows = regionMap.getRows(); + + RandomIter inMapIter = CoverageUtilities.getRandomIterator(inMap); + + pm.beginTask("Started checking Slope map for zero values..", rows); //$NON-NLS-1$ + + double celValue; + int outletCount = 0; + // Cycling into the valid region. + for( int r = 0; r < rows; r++ ) { + for( int c = 0; c < cols; c++ ) { + + celValue = inMapIter.getSampleDouble(c, r, 0); + if (celValue == 10.0) { + pm.errorMessage("A cell with value equal to 10 was found at " + c + ";" + r); //$NON-NLS-1$ + outletCount++; + } + // elevationNode = new GridNode(inPitIter, cols, rows, yRes, yRes, c, r); + } + pm.worked(1); + } + pm.done(); + + return outletCount; + } + + public static boolean isValidSlopeMap( GridCoverage2D inSlope, IJGTProgressMonitor pm ) { + + int errorCount = countZeroValueCells(inSlope, pm); + + if (errorCount != 0) { + pm.errorMessage("One or more cells with slope value equal to zero have been found: fix this issue to proceed"); + return false; + } else { + return true; + } + } + + /** + * Returns the number of map cells having a zero-value + * @param inMap the map to check for zero-value cells + * @param pm + * @return int the number of zero-value cells in the inspected map + */ + public static int countZeroValueCells( GridCoverage2D inMap, IJGTProgressMonitor pm ) { + + RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inMap); + int cols = regionMap.getCols(); + int rows = regionMap.getRows(); + + RandomIter inMapIter = CoverageUtilities.getRandomIterator(inMap); + + pm.beginTask("Started checking Slope map for zero values..", rows); //$NON-NLS-1$ + + double nodeSample; + int errorCount = 0; + // Cycling into the valid region. + for( int r = 0; r < rows; r++ ) { + for( int c = 0; c < cols; c++ ) { + + nodeSample = inMapIter.getSampleDouble(c, r, 0); + if (nodeSample == 0.0) { + pm.errorMessage("A cell with Slope value equal to zero was found at " + c + ";" + r); //$NON-NLS-1$ + errorCount++; + } + // elevationNode = new GridNode(inPitIter, cols, rows, yRes, yRes, c, r); + } + pm.worked(1); + } + pm.done(); + + return errorCount; + } + + /** + * Runs across the passed Flow map and checks for missing border cells to rebuild. Tools like OmsFlowDirections do not calculate + * flow values for cells that lack one or more of the eight surrounding cells and this causes the outcome flow map not to fully cover + * the corresponding basin + * @param inFlow The to-be-chacked flow map + * @param inPit The depitted DEM map + * @param pm Parent's progress monitor + * @return + */ + public static GridCoverage2D flowMapRebuildBorder( GridCoverage2D inFlow, GridCoverage2D inPit, IJGTProgressMonitor pm ) { + + RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inPit); + int cols = regionMap.getCols(); + int rows = regionMap.getRows(); + double xRes = regionMap.getXres(); + double yRes = regionMap.getYres(); + + RandomIter inPitIter = CoverageUtilities.getRandomIterator(inPit); + + WritableRaster mflowWR = CoverageUtilities.renderedImage2WritableRaster(inFlow.getRenderedImage(), false); + WritableRandomIter mflowIter = RandomIterFactory.createWritable(mflowWR, null); + + pm.beginTask("Started checking for missing border cell in flow map..", rows); //$NON-NLS-1$ + + GridNode pitnode; + FlowNode flownode; + List pitNodes; + + // Cycling into the valid region. + int r = 0; + int c = 0; + for( r = 0; r < rows; r++ ) { + for( c = 0; c < cols; c++ ) { + + pitnode = new GridNode(inPitIter, cols, rows, xRes, yRes, c, r); + flownode = new FlowNode(mflowIter, cols, rows, c, r); + + // Select valid DEM cells that lack a correspondence in flow map + if (pitnode.isValid() && !flownode.isValid()) { + + // We are on a border cell: let's compute its Flow value + pitNodes = pitnode.getSurroundingNodes(); + int flowvalue = 0; + double delta = 0.0; + for( int i = 0; i < 8; i++ ) { + + // Skip null cells + if (pitNodes.get(i) != null) { + if (pitnode.getSlopeTo(pitNodes.get(i)) >= delta) { + delta = pitnode.getSlopeTo(pitNodes.get(i)); + flowvalue = i + 1; + } + } + + } + + // If flowvalue cannot be determined, the cell should be an outlet + if (flowvalue == 0) { + pm.message("An outlet was found in the flow map: use OmsMarkoutlets model to mark it"); + List surrNodes = pitnode.getSurroundingNodes(); + for( int j = 0; j < 8; j++ ) { + // Find the first node around the outlet which is not in the map (so is invalid) + // and assign to the outlet his flow direction (so outside the basin). + // This will allow the outlet to be seen as outward flowing by other tools + if(surrNodes.get(j)==null){ + flowvalue = j+1; + } + } + } + pitnode.setValueInMap(mflowIter, flowvalue); + } + } + pm.worked(1); + } + pm.done(); + + GridCoverage2D outFlow = CoverageUtilities.buildCoverage("flow", mflowWR, regionMap, inFlow.getCoordinateReferenceSystem()); + + return outFlow; + } + +} diff --git a/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utils/ParameterCalculationFunctions.java b/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utils/ParameterCalculationFunctions.java new file mode 100644 index 000000000..5a124a76a --- /dev/null +++ b/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utils/ParameterCalculationFunctions.java @@ -0,0 +1,276 @@ +/* + * This file is part of the "CI-slam module": an addition to JGrassTools + * It has been entirely contributed by Marco Foi (www.mcfoi.it) + * + * "CI-slam module" is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.utils; + +import java.util.ArrayList; + +import org.jgrasstools.gears.libs.exceptions.ModelsIllegalargumentException; +import org.jgrasstools.gears.libs.modules.GridNode; +import org.jgrasstools.gears.libs.modules.JGTConstants; +import org.jgrasstools.gears.libs.monitor.IJGTProgressMonitor; + +public class ParameterCalculationFunctions { + + public final static double EULER_CONSTANT = 0.5772157; + // SigmaL: obtained by linear regression of rainfall depth against duration after log + // transformation + public static double pSigma1 = 11.82; + // mF: obtained by linear regression of rainfall depth against duration after log transformation + public static double pmF = 0.54; + // Coefficient of Variation: can be obtained as the average of coefficients computed for the + // different durations + public static double pCV = 0.23; + // Return period in [YEARS] + private static int pReturnTime = 200; + // Rainfall DURATION in [hours] + private static double pRainfallDuration = 1.0; + // Integration step : 30 seconds expressed in fraction of [hours] + public static int DELTA_T_INTEGRATION_STEP_IN_SECONDS = 30; + // Integration step : 30 seconds expressed in fraction of [hours] + public static double DELTA_T_INTEGRATION_STEP_IN_HOURS = DELTA_T_INTEGRATION_STEP_IN_SECONDS/3600.0; + + /** + * Wrapper for running Test Cases without providing any parameter: do not use in actual module workflow! + * @param pm + * @return I intensity of rainfall event + */ + public static double calculateRainfallIntensity( IJGTProgressMonitor pm ) { + return calculateRainfallIntensity(pSigma1, pmF, pCV, pReturnTime, pRainfallDuration, pm); + } + + /** + * Wrapper for running with default parameters for Casini Basin: do not use in actual module workflow! + * Default used basin parameters: + * pSigma1 = 11.82; + * pmF = 0.54; + * pCV = 0.23; Coefficient of Variation + * @param pReturnTime Return period in [YEARS] + * @param pRainfallDuration Rainfall DURATION in [hours] + * @return I intensity of rainfall event + */ + public static double calculateRainfallIntensity(int pReturnTime, double pRainfallDuration, IJGTProgressMonitor pm ) { + return calculateRainfallIntensity(pSigma1, pmF, pCV, pReturnTime, pRainfallDuration, pm); + } + + /** + * Calculate rainfall Intensity. + * Logic from Equation 18 of reference paper that is abased on the intensity-duration-frequency (IDF) relationship + * propose by Koutsoyiannis et al (1998). + * + * @param pSigma1 Sigma1: obtained by linear regression of rainfall depth against duration after log transformation + * @param pmF obtained by linear regression of rainfall depth against duration after log transformation + * @param pCV Coefficient of Variation: can be obtained as the average of coefficients computed for the different durations + * @param pReturnTime Return period in [YEARS] + * @param pRainfallDuration Rainfall DURATION in [hours] + * @param pm IJGTProgressMonitor Progress monitor to return info on progress. Pass null to avoid messages in console. + * @return I intensity of rainfall event + */ + public static double calculateRainfallIntensity( double pSigma1, double pmF, double pCV, int pReturnTime, double pRainfallDuration, + IJGTProgressMonitor pm) { + + // Logic from Equation 18 of reference paper. + + // Send message to progress monitor + if(pm !=null){pm.beginTask("Started calculating intensity...", 1);} + double yTr = Math.log(Math.log(pReturnTime / (pReturnTime - 1.0))); + double I = (pSigma1 * (1 - ((pCV * Math.pow(6.0, 0.5)) / Math.PI) * (EULER_CONSTANT + yTr)) * Math.pow(pRainfallDuration, + pmF - 1.0)) / 1000.0; + if(pm !=null){ + pm.worked(1); + pm.done(); + } + + return I; + } + + /** + * Calculates the soil thickness in a given {@link GridNode}. + * + * @param slopeCurrent the current grid node. + * @param slope (tan_beta) at the current grid node + * @param doRound if true, values are round to integer. + * @return the value of aspect. + */ + public static double calculateSoilThickness( double slopeCurrent, boolean doRound ) { + + double soilThickness = 1.006 - 0.85 * slopeCurrent; + return soilThickness; + } + + /** + * Returns the computed psi value for the dT increment. + * @param previousPsi_bb + * @param I + * @param soil_thickness + * @param theta_s + * @param theta_r + * @param alfaVanGenuchten + * @param nVanGenuchten + * @return psi value or JGTConstants.doubleNovalue if psi would be negative + */ + public static double calculatePsiAtBedrockDuringVerticalInfiltration(double previousPsi_bb, double I, double soil_thickness, double theta_s, double theta_r, double alfaVanGenuchten, double nVanGenuchten){ + + //psi_bb[i,j]<-psi_bb[i,j]+I/((theta_s[i,j]-theta_r[i,j])*((1+(alfaVanGen[i,j]*(soil_thick[i,j]+psi_bb[i,j]))^n[i,j])^(-1-1/n[i,j])-(1+(alfaVanGen[i,j]*(psi_bb[i,j]))^n[i,j])^(-1-1/n[i,j])))*dt + + double psi_bb = 0.0; + + double pow1 = Math.pow( + ( + 1+( Math.pow( alfaVanGenuchten * (soil_thickness + previousPsi_bb), nVanGenuchten) ) + ), + (-1-(1/nVanGenuchten)) + ); + double pow2 = Math.pow( + ( + 1+( Math.pow( alfaVanGenuchten * previousPsi_bb, nVanGenuchten) ) + ), + (-1-(1/nVanGenuchten)) + ); + psi_bb = previousPsi_bb + + I/ + ( + (theta_s - theta_r)* + (pow1 - pow2) + )* + DELTA_T_INTEGRATION_STEP_IN_HOURS; + + if (psi_bb < 0){ + psi_bb = JGTConstants.doubleNovalue; + } + return psi_bb; + } + + + public static double calculateDinamicLinearTopographicIndexValue(int t, double Ab, double tempo_soglia, double th_time, double ratio, double slope){ + + int Dt = 3600; // Required to express result + double IT_din_lin_Value = Ab* + Math.max( + 0, + Math.min( + ( + ( + // This could be tau1_c : "corrivation time" as in Equation (11). The exp at following line raises from 0 to 1 once system is at steady-state. + t - Math.max(tempo_soglia,th_time) + // K = RATIO : a matrix of cumulated d_l along flow path. 'd_l' is defined on line 555 of R script + )*Dt/ratio + ), + 1 + ) + )/ + slope; + return IT_din_lin_Value; + + } + + + /** + * Calculates the time required by a basing node to develop a perched water table, + * given the rainfall intensity (assumed uniform in space and time), + * the initial soil moisture content V0 [L] and the soil moisture requires to develop the water table. + * The calculation is based on Equation (1) of the reference paper. + * @param pVwt double [L] + * @param pV0 double [L] + * @param pRainfallIntensity [L/T] + * @return Twt double [h] Hours required to develop a perched water table at soil-bedrock interface + */ + public static double calculateTimeForWaterTableDevelopmentTwt( double pVwt, double pV0, double pRainfallIntensity ) { + + double Twt = (pVwt - pV0) / pRainfallIntensity; + + return Twt; + + } + + /** + * Computes Psi at bedrock as in Equation (12) of reference paper + * Note that IT_din_lin is used as equivalent to Area/(perimeter*sin(beta)) + * @param soil_thickness + * @param I + * @param K + * @param IT_din_lin_Val + * @param pm + * @return + */ + public static double calculatePsiAtBedrockInPositivePressureZonesVAlue(double soil_thickness, double I, double K, + double IT_din_lin_Val, IJGTProgressMonitor pm ) { + + double psi_b = - (Math.min( soil_thickness, (I/(K*3600))*(IT_din_lin_Val)) ); + return psi_b; + } + + + + public static ArrayList parseRainfallDurationsString(String pRainfallDurations, IJGTProgressMonitor pm){ + + String[] rainfallDurationsSplit = pRainfallDurations.trim().split(","); + ArrayList rainfallDurationsArrayList = new ArrayList(); + String durations = ""; + for( int i = 0; i < rainfallDurationsSplit.length; i++ ) { + try { + if (Integer.parseInt(rainfallDurationsSplit[i].trim()) > 0) { + durations += rainfallDurationsSplit[i].trim() + " "; + rainfallDurationsArrayList.add(i, (Integer) Integer.parseInt(rainfallDurationsSplit[i].trim())); + } else { + if(pm!=null){pm.errorMessage("One of the provided Rainfall Durations was interpreted as zero: please check your input!");} + throw new ModelsIllegalargumentException( + "One of the provided Rainfall Durations was interpreted as zero: please check your input!", ParameterCalculationFunctions.class.getSimpleName()); + } + } catch (NumberFormatException e) { + if(pm!=null){pm.errorMessage("One of the provided Rainfall Durations could not be interpreted as a valid hourly duration: check your input!");} + throw new ModelsIllegalargumentException( + "One of the provided Rainfall Durations could not be interpreted as a valid hourly duration: check your input!", ParameterCalculationFunctions.class.getSimpleName()); + } + } + if(pm!=null){pm.message("The simulations will be carried on using the following Rainfall Durationss [hours]: " + durations);} + + return rainfallDurationsArrayList; + } + + public static ArrayList parseReturnTimesString(String pReturnTimes, IJGTProgressMonitor pm){ + + String[] returnTimesSplit = pReturnTimes.trim().split(","); + ArrayList returnTimesArrayList = new ArrayList(); + String years = ""; + for( int i = 0; i < returnTimesSplit.length; i++ ) { + try { + if (Integer.parseInt(returnTimesSplit[i].trim()) > 0) { + years += returnTimesSplit[i].trim() + " "; + returnTimesArrayList.add(i, (Integer) Integer.parseInt(returnTimesSplit[i].trim())); + } else { + if(pm!=null){pm.errorMessage("One of the provided Return Times was interpreted as zero: please check your input!");} + throw new ModelsIllegalargumentException( + "One of the provided Return Times was interpreted as zero: please check your input!", ParameterCalculationFunctions.class.getSimpleName()); + } + } catch (NumberFormatException e) { + if(pm!=null){pm.errorMessage("One of the provided Return Times could not be interpreted as a valid year: check your input!");} + throw new ModelsIllegalargumentException( + "One of the provided Return Times could not be interpreted as a valid year: check your input!", ParameterCalculationFunctions.class.getSimpleName()); + } + } + if(pm!=null){pm.message("The calculation will be carried on for the following Retrun Times [years]: " + years);} + + return returnTimesArrayList; + } + + public static void calculateFS_Initial() { + // TODO Auto-generated method stub + + } + +} diff --git a/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utils/RunBasicFileDumper.java b/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utils/RunBasicFileDumper.java new file mode 100644 index 000000000..73d70e599 --- /dev/null +++ b/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utils/RunBasicFileDumper.java @@ -0,0 +1,44 @@ +/* + * This file is part of the "CI-slam module": an addition to JGrassTools + * It has been entirely contributed by Marco Foi (www.mcfoi.it) + * + * "CI-slam module" is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.utils; + +import org.geotools.coverage.grid.GridCoverage2D; +import org.jgrasstools.gears.io.rasterwriter.OmsRasterWriter; + +public class RunBasicFileDumper implements IRunBehavior { + + String path = null; + GridCoverage2D coverage = null; + + public RunBasicFileDumper(String path, GridCoverage2D coverage){ + + this.path = path; + this.coverage = coverage; + } + + @Override + public void runLaunch() { + try { + OmsRasterWriter.writeRaster(path, coverage); + } catch (Exception e) { + e.printStackTrace(); + } + + } + +} diff --git a/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utils/RunMultiBandFileDumper.java b/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utils/RunMultiBandFileDumper.java new file mode 100644 index 000000000..ad1986d58 --- /dev/null +++ b/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/utils/RunMultiBandFileDumper.java @@ -0,0 +1,82 @@ +/* + * This file is part of the "CI-slam module": an addition to JGrassTools + * It has been entirely contributed by Marco Foi (www.mcfoi.it) + * + * "CI-slam module" is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.utils; + +import java.awt.image.WritableRaster; + +import javax.media.jai.iterator.RandomIter; +import javax.media.jai.iterator.RandomIterFactory; +import javax.media.jai.iterator.WritableRandomIter; + +import org.geotools.coverage.grid.GridCoverage2D; +import org.jgrasstools.gears.io.rasterwriter.OmsRasterWriter; +import org.jgrasstools.gears.libs.modules.JGTConstants; +import org.jgrasstools.gears.libs.monitor.IJGTProgressMonitor; +import org.jgrasstools.gears.utils.RegionMap; +import org.jgrasstools.gears.utils.coverage.CoverageUtilities; +import org.opengis.referencing.crs.CoordinateReferenceSystem; + +public class RunMultiBandFileDumper implements IRunBehavior { + + private int band; + private String pOutFolder = null; + private String filePrefix = null; + private RandomIter multiBandMapIter = null; + private int cols; + private int rows; + private IJGTProgressMonitor pm; + private RegionMap regionMap; + private CoordinateReferenceSystem crs; + + public RunMultiBandFileDumper(int band, int cols, int rows, String filePrefix, String pOutFolder, RandomIter multiBandMapIter, RegionMap regionMap, CoordinateReferenceSystem crs, IJGTProgressMonitor pm){ + this.band = band; + this.cols = cols; + this.rows = rows; + this.pm = pm; + this.pOutFolder = pOutFolder; + this.filePrefix = filePrefix; + this.multiBandMapIter = multiBandMapIter; + this.regionMap = regionMap; + this.crs = crs; + } + + @Override + public void runLaunch() { + + WritableRaster outputBand_WR = CoverageUtilities.createDoubleWritableRaster(cols, rows, null, null, JGTConstants.doubleNovalue); + WritableRandomIter outputBand_Iter = RandomIterFactory.createWritable(outputBand_WR, null); + + if(pm != null){pm.beginTask("Starting to copy Coverages into Rasters...", rows);} + + for( int r = 0; r < rows; r++ ) { + for( int c = 0; c < cols; c++ ) { + double value = multiBandMapIter.getSampleDouble(c, r, band); + if (!Double.isNaN(value)) + outputBand_Iter.setSample(c, r, 0, value); + } + } + + GridCoverage2D outBand = CoverageUtilities.buildCoverage(filePrefix + (band + 1) + "h", outputBand_WR, regionMap, crs); + + try { + OmsRasterWriter.writeRaster(pOutFolder + outBand.getName() + ".asc", outBand); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/hortonmachine/src/main/resources/META-INF/services/org.jgrasstools.gears.libs.modules.JGTModel b/hortonmachine/src/main/resources/META-INF/services/org.jgrasstools.gears.libs.modules.JGTModel index b4e464984..d8a2398f5 100644 --- a/hortonmachine/src/main/resources/META-INF/services/org.jgrasstools.gears.libs.modules.JGTModel +++ b/hortonmachine/src/main/resources/META-INF/services/org.jgrasstools.gears.libs.modules.JGTModel @@ -59,6 +59,14 @@ org.jgrasstools.hortonmachine.modules.hydrogeomorphology.melton.OmsMeltonNumber org.jgrasstools.hortonmachine.modules.hydrogeomorphology.peakflow.OmsPeakflow org.jgrasstools.hortonmachine.modules.hydrogeomorphology.shalstab.OmsShalstab org.jgrasstools.hortonmachine.modules.hydrogeomorphology.skyview.OmsSkyview +org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.OmsCislam +org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.utility_models.OmsPsiInitAtBedrock +org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.utility_models.OmsSlopeForCislam +org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.utility_models.OmsSoilThickness +org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.utility_models.OmsV0 +org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.utility_models.OmsVwt +org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.utility_models.OmsSafetyFactorGeomechanic +org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.utility_models.OmsSafetyFactorsWorstCaseComposer org.jgrasstools.hortonmachine.modules.network.distancetooutlet.OmsDistanceToOutlet org.jgrasstools.hortonmachine.modules.network.extractnetwork.OmsExtractNetwork org.jgrasstools.hortonmachine.modules.network.hacklength.OmsHackLength diff --git a/hortonmachine/src/main/resources/hm_messages.properties b/hortonmachine/src/main/resources/hm_messages.properties index 623cda1da..ce47bbb85 100644 --- a/hortonmachine/src/main/resources/hm_messages.properties +++ b/hortonmachine/src/main/resources/hm_messages.properties @@ -170,4 +170,6 @@ trentoP.error.fieldPerArea = invalid percentage of the area trentoP.generatefile.project = Create TrentoP project shapefiles... trentoP.generatefile.error.noFeature = No old simulation feature collection -hm.error.noGridCoverageInput = There is an input map which is null, verify the \ No newline at end of file +hm.error.noGridCoverageInput = There is an input map which is null, verify the + +cislam.omssoilthickness.validslopemapprovided = The provided slope map was checked and resulted VALID (no zero or infinite values). \ No newline at end of file diff --git a/hortonmachine/src/main/resources/hm_messages_it.properties b/hortonmachine/src/main/resources/hm_messages_it.properties index d0e074f9d..162212f28 100644 --- a/hortonmachine/src/main/resources/hm_messages_it.properties +++ b/hortonmachine/src/main/resources/hm_messages_it.properties @@ -74,4 +74,6 @@ trentoP.error.fieldPerArea = percentuale di area non valida trentoP.generatefile.project = Creazione del file di input per trentoP... trentoP.generatefile.error.noFeature = non ho trovato la FeatureCollection di origine -hm.error.noGridCoverageInput = C'è una mappa di input nulla, verifica \ No newline at end of file +hm.error.noGridCoverageInput = C'è una mappa di input nulla, verifica + +cislam.omssoilthickness.validslopemapprovided = La mappa fornita è stata controllata ed è risultata VALIDA (nessuna cella con valore zero o infinito). \ No newline at end of file diff --git a/hortonmachine/src/main/resources/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/OmsCislam.html b/hortonmachine/src/main/resources/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/OmsCislam.html new file mode 100644 index 000000000..1994b08d6 --- /dev/null +++ b/hortonmachine/src/main/resources/org/jgrasstools/hortonmachine/modules/hydrogeomorphology/cislam/OmsCislam.html @@ -0,0 +1,64 @@ +This is a version of the Ci-Slam stability model for the evaluation of the proneness to instability of each pixel of a map belonging to a single basin, based on an infinite slope model affected by hydrological variables. +
The output, at the current stage of development, is composed by a set of maps containing the Stability Factor of each cell. +
Each map represents the worst-case based composition of a set of maps computed for a single Return Time (RT) and for a number simulated rainfall events with different durations (1h, 3h, etc.). +
Since the model can also be run for one single Return Time, the final output can consist in just one Safety Factor map. +
+For example, an output file named +
+
SAFETY_FACTOR_HYDOLOGIC_30y_1h3h6h.asc +
+
represents the result of a simulation run for a RT of 30 years and for the three different rainfall durations of 1 hour, 3hours and 6 hours. + +
+

Reference Paper

+The CI-Slam module is an implementation of the methodology proposed in the paper: +
+
+Lanni, C., Borga, M., Rigon, R. and Tarolli, P. (2012) Modelling shallow landslide susceptibility by means of a subsurface flow path connectivity index and estimates of soil depth spatial distribution. Hydrology and Earth System Sciences, 16(11), pp. 3959-3971. +
Available at: http://www.hydrol-earth-syst-sci.net/16/3959/2012/hess-16-3959-2012.html +
+

Inputs

+
+The parameters used for the evaluation of the stability conditions are: +
    +
  • the comma-separated list of Return Times for which to run the simulation
  • +
  • the comma-separated list of Rainfall Durations for which to run the simulation
  • +
  • the depitted elevation map
  • +
  • the flow directions map
  • +
  • the slope map
  • +
  • the area for unit length map
  • +
  • the soil thickness map
  • +
  • the Sigma1 parameter
  • +
  • the mF parameter
  • +
  • the Coefficent of Varaition parameter
  • +
  • the map of initial suction head (Psi) at soil-bedrock interface
  • +
  • the map of effective soil Cohesion
  • +
  • the map of effective frictional angle (Phi)
  • +
  • the map of soil density (Gamma S)
  • +
  • the map of saturated hydraulic conductivity (Ksat)
  • +
  • the map of saturated water content (Theta S)
  • +
  • the map of residual water content (Theta R)
  • the map of alpha (van Genuchten parameter) +
  • the map of n (van Genuchten parameter)
  • +
+
+
+Those parameters that should be possible to insert as single constant values to be used over all the basin (soil thickness, psi, cohesion, ecc) have to be converted into maps before proceeding, by using other modules. +
+

Output

+
+The output is composed by one or more maps of the Safety Factor, one fore each Return Time requested. +
    +
  • one or more maps of Safety Factor deployed in the user-specified output folder
  • +
+
+The cell values mean: +
+
    +
  • <1 : unstable cell
  • +
  • >1 : stable cell
  • +
  • -9999 : no-value area
  • +
+
+Upon request (checking the relevant box) also the Initial Safety Factor map is computed: a safety factor controlled by hydrological parameters but not considering rainfalls. +
diff --git a/jgrassgears/src/main/java/org/jgrasstools/gears/utils/coverage/CoverageUtilities.java b/jgrassgears/src/main/java/org/jgrasstools/gears/utils/coverage/CoverageUtilities.java index f160c5d0b..d951deb8e 100644 --- a/jgrassgears/src/main/java/org/jgrasstools/gears/utils/coverage/CoverageUtilities.java +++ b/jgrassgears/src/main/java/org/jgrasstools/gears/utils/coverage/CoverageUtilities.java @@ -1100,6 +1100,53 @@ public static ROI prepareROI( Geometry roi, AffineTransform mt2d ) throws Except // build a shape using a fast point in polygon wrapper return new ROIShape(new FastLiteShape(simplifiedGeometry)); } + + /** + * Read the min, max, mean, sdev, valid cells count from a coverage. + * + * @param coverage the coverage to browse. + * @param mask an optional mask to apply. + * @return the min, max, mean, sdev, count. + */ + public static double[] getMinMaxMeanSdevCount( GridCoverage2D coverage, GridCoverage2D mask ) { + double[] minMaxMeanSdevCount = {Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, 0.0, 0.0, 0.0}; + RandomIter coverageIter = getRandomIterator(coverage); + RenderedImage coverageRI = coverage.getRenderedImage(); + RandomIter maskIter = null; + if (mask != null) + maskIter = getRandomIterator(mask); + int cellCount = 0; + double sum = 0; + double sumSquare = 0; + for( int i = 0; i < coverageRI.getWidth(); i++ ) { + for( int j = 0; j < coverageRI.getHeight(); j++ ) { + double value = coverageIter.getSampleDouble(i, j, 0); + if (isNovalue(value)) { + continue; + } + if (maskIter != null) { + double maskValue = maskIter.getSampleDouble(i, j, 0); + if (isNovalue(maskValue)) { + continue; + } + } + if (value < minMaxMeanSdevCount[0]) { + minMaxMeanSdevCount[0] = value; + } + if (value > minMaxMeanSdevCount[1]) { + minMaxMeanSdevCount[1] = value; + } + cellCount++; + sum = sum + value; + sumSquare = sum + value * value; + } + } + minMaxMeanSdevCount[2] = sum / cellCount; + minMaxMeanSdevCount[3] = Math.sqrt(sumSquare / cellCount - minMaxMeanSdevCount[2] * minMaxMeanSdevCount[2]); + minMaxMeanSdevCount[4] = cellCount; + + return minMaxMeanSdevCount; + } /** * Checks if the given path is a GRASS raster file. diff --git a/modules/src/main/java/org/jgrasstools/modules/Cislam.java b/modules/src/main/java/org/jgrasstools/modules/Cislam.java new file mode 100644 index 000000000..8f1c2a6ff --- /dev/null +++ b/modules/src/main/java/org/jgrasstools/modules/Cislam.java @@ -0,0 +1,286 @@ +/* + * This file is part of the "CI-slam module": an addition to JGrassTools + * It has been entirely contributed by Marco Foi (www.mcfoi.it) + * + * "CI-slam module" is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.jgrasstools.modules; + +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_AUTHORCONTACTS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_AUTHORNAMES; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_KEYWORDS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_LABEL; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_LICENSE; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_NAME; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_STATUS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_doSaveByproducts_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inAb_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inAlfaVanGen_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inCohesion_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inFlow_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inGamma_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inKsat_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inNVanGen_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inPhi_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inPit_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inPsiInitAtBedrock_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inSlope_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inSoilThickness_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inTheta_r_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inTheta_s_DESCRIPTION; +//import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_pAlfaVanGen_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_pCV_DESCRIPTION; +//import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_pCohesion_DESCRIPTION; +//import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_pGamma_DESCRIPTION; +//import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_pKsat_DESCRIPTION; +//import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_pNVanGen_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_pOutFolder_DESCRIPTION; +//import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_pPhi_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_pRainfallDurations_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_pReturnTimes_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_pSigma1_DESCRIPTION; +//import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_pTheta_r_DESCRIPTION; +//import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_pTheta_s_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_pmF_DESCRIPTION; +import oms3.annotations.Author; +import oms3.annotations.Description; +import oms3.annotations.Execute; +import oms3.annotations.In; +import oms3.annotations.Keywords; +import oms3.annotations.Label; +import oms3.annotations.License; +import oms3.annotations.Name; +import oms3.annotations.Status; +import oms3.annotations.UI; +import oms3.annotations.Unit; + +import org.jgrasstools.gears.libs.modules.JGTConstants; +import org.jgrasstools.gears.libs.modules.JGTModel; +import org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.OmsCislam; + +/** + * + * @author Marco Foi (www.mcfoi.it) + * + */ +@Description(OMSCISLAM_DESCRIPTION) +@Author(name = OMSCISLAM_AUTHORNAMES, contact = OMSCISLAM_AUTHORCONTACTS) +@Keywords(OMSCISLAM_KEYWORDS) +@Label(OMSCISLAM_LABEL) +@Name("_" + OMSCISLAM_NAME) +@Status(OMSCISLAM_STATUS) +@License(OMSCISLAM_LICENSE) +public class Cislam extends JGTModel { + + // Default minimum slope value used as a substitute for Slope Map values + // equal to zero. Required to avoid division by zero. + public static final double MINIMM_ALLOWED_SLOPE = 0.009; + // Default rainfall durations used to compute maps of times to develop water + // table. + private static final String RAINFALL_DURATIONS_ARRAY = "1, 3, 6, 12, 24"; + + @Description(OMSCISLAM_pReturnTimes_DESCRIPTION) + @Unit("Years") + @In + public String pReturnTimes = new String("30, 100, 200"); + + @Description(OMSCISLAM_pRainfallDurations_DESCRIPTION) + @Unit("Hours") + @In + public String pRainfallDurations = RAINFALL_DURATIONS_ARRAY; + + // Input files + @Description(OMSCISLAM_inPit_DESCRIPTION) + @Unit("m") + @UI(JGTConstants.FILEIN_UI_HINT) + @In + public String inPit = null; + + @Description(OMSCISLAM_inFlow_DESCRIPTION) + @UI(JGTConstants.FILEIN_UI_HINT) + @In + public String inFlow = null; + + @Description(OMSCISLAM_inSlope_DESCRIPTION) + @UI(JGTConstants.FILEIN_UI_HINT) + @In + public String inSlope = null; + + @Description(OMSCISLAM_inAb_DESCRIPTION) + @UI(JGTConstants.FILEIN_UI_HINT) + @In + public String inAb = null; + + @Description(OMSCISLAM_inSoilThickness_DESCRIPTION) + @UI(JGTConstants.FILEIN_UI_HINT) + @Unit("m") + @In + public String inSoilThickness = null; + + // ############################################# + // Rainfall-statistics related parameters + // ############################################# + @Description(OMSCISLAM_pSigma1_DESCRIPTION) + @In + public double pSigma1 = 11.82; + + @Description(OMSCISLAM_pmF_DESCRIPTION) + @In + public double pmF = 0.54; + + @Description(OMSCISLAM_pCV_DESCRIPTION) + @In + public double pCV = 0.23; + + // ############################################# + // Hydrologic parameters + // ############################################# + @Description(OMSCISLAM_inPsiInitAtBedrock_DESCRIPTION) + @Unit("m") + @UI(JGTConstants.FILEIN_UI_HINT) + @In + public String inPsiInitAtBedrock = null; + + // ############################################# + // van Genuchten parameters + // ############################################# + @Description(OMSCISLAM_inCohesion_DESCRIPTION) + @UI(JGTConstants.FILEIN_UI_HINT) + @Unit("kPa") + @In + public String inCohesion = null; + /* + * @Description(OMSCISLAM_pCohesion_DESCRIPTION) + * + * @Unit("Pa") + * + * @In public double pCohesion = -1.0; + */ + @Description(OMSCISLAM_inPhi_DESCRIPTION) + @UI(JGTConstants.FILEIN_UI_HINT) + @In + public String inPhi = null; + /* + * @Description(OMSCISLAM_pPhi_DESCRIPTION) + * + * @In public double pPhi = 30.0; + */ + @Description(OMSCISLAM_inGamma_DESCRIPTION) + @UI(JGTConstants.FILEIN_UI_HINT) + @In + public String inGammaSoil = null; + /* + * @Description(OMSCISLAM_pGamma_DESCRIPTION) + * + * @In public double pGamma = 19.0; + */ + @Description(OMSCISLAM_inKsat_DESCRIPTION) + @Unit("m/s") + @UI(JGTConstants.FILEIN_UI_HINT) + @In + public String inKsat = null; + /* + * @Description(OMSCISLAM_pKsat_DESCRIPTION) + * + * @In public double pKsat_ = 10 ^ (-6); + */ + @Description(OMSCISLAM_inTheta_s_DESCRIPTION) + @Unit("-") + @UI(JGTConstants.FILEIN_UI_HINT) + @In + public String inTheta_s = null; + /* + * @Description(OMSCISLAM_pTheta_s_DESCRIPTION) + * + * @In public double pTheta_s = 0.3; + */ + @Description(OMSCISLAM_inTheta_r_DESCRIPTION) + @Unit("-") + @UI(JGTConstants.FILEIN_UI_HINT) + @In + public String inTheta_r = null; + /* + * @Description(OMSCISLAM_pTheta_r_DESCRIPTION) + * + * @In public double pTheta_r = 0.03; + */ + @Description(OMSCISLAM_inAlfaVanGen_DESCRIPTION) + @Unit("1/m") + @UI(JGTConstants.FILEIN_UI_HINT) + @In + public String inAlfaVanGen = null; + /* + * @Description(OMSCISLAM_pAlfaVanGen_DESCRIPTION) + * + * @In public double pAlfaVanGen = 6.5; + */ + @Description(OMSCISLAM_inNVanGen_DESCRIPTION) + @UI(JGTConstants.FILEIN_UI_HINT) + @Unit("-") + @In + public String inNVanGen = null; + /* + * @Description(OMSCISLAM_pNVanGen_DESCRIPTION) + * + * @Unit("-") + * + * @In public double pNVanGen = 1.36; + */ + + // ############################################# + // Save by-products to file + // ############################################# + @Description(OMSCISLAM_doSaveByproducts_DESCRIPTION) + @In + public boolean doSaveByProducts = false; + + @Description(OMSCISLAM_pOutFolder_DESCRIPTION) + @UI(JGTConstants.FOLDEROUT_UI_HINT) + @In + public String pOutFolder = System.getProperty("java.io.tmpdir"); + + @Execute + public void process() throws Exception { + OmsCislam omscislam = new OmsCislam(); + + omscislam.pOutFolder = pOutFolder; + + omscislam.doSaveByProducts = doSaveByProducts; + + omscislam.pReturnTimes = pReturnTimes; + omscislam.pRainfallDurations = pRainfallDurations; + + omscislam.inPit = getRaster(inPit); + omscislam.inFlow = getRaster(inFlow); + omscislam.inSlope = getRaster(inSlope); + omscislam.inAb = getRaster(inAb); + omscislam.inSoilThickness = getRaster(inSoilThickness); + omscislam.inTheta_s = getRaster(inTheta_s); + omscislam.inTheta_r = getRaster(inTheta_r); + omscislam.inPsiInitAtBedrock = getRaster(inPsiInitAtBedrock); + omscislam.inAlfaVanGen = getRaster(inAlfaVanGen); + omscislam.inNVanGen = getRaster(inNVanGen); + omscislam.inKsat = getRaster(inKsat); + omscislam.inGammaSoil = getRaster(inGammaSoil); + omscislam.inCohesion = getRaster(inCohesion); + omscislam.inPhi = getRaster(inPhi); + + omscislam.pSigma1 = pSigma1; + omscislam.pmF = pmF; + omscislam.pCV = pCV; + + omscislam.process(); + } +} diff --git a/modules/src/main/java/org/jgrasstools/modules/CislamPsiInitAtBedrock.java b/modules/src/main/java/org/jgrasstools/modules/CislamPsiInitAtBedrock.java new file mode 100644 index 000000000..149bdc1ae --- /dev/null +++ b/modules/src/main/java/org/jgrasstools/modules/CislamPsiInitAtBedrock.java @@ -0,0 +1,92 @@ +/* + * This file is part of the "CI-slam module": an addition to JGrassTools + * It has been contributed by Marco Foi (www.mcfoi.it) and Cristiano Lanni + * + * "CI-slam module" is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.jgrasstools.modules; + +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_AUTHORCONTACTS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_AUTHORNAMES; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_LICENSE; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSPSIINITATBEDROCK_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSPSIINITATBEDROCK_KEYWORDS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSPSIINITATBEDROCK_NAME; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSPSIINITATBEDROCK_STATUS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSPSIINITATBEDROCK_outPsiInitAtBedrock_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSPSIINITATBEDROCK_pPsiInitAtBedrockConstant_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_SUBMODULES_LABEL; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inPit_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inSoilThickness_DESCRIPTION; +import oms3.annotations.Author; +import oms3.annotations.Description; +import oms3.annotations.Execute; +import oms3.annotations.In; +import oms3.annotations.Keywords; +import oms3.annotations.Label; +import oms3.annotations.License; +import oms3.annotations.Name; +import oms3.annotations.Out; +import oms3.annotations.Status; +import oms3.annotations.UI; +import oms3.annotations.Unit; + +import org.jgrasstools.gears.libs.modules.JGTConstants; +import org.jgrasstools.gears.libs.modules.JGTModel; +import org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.utility_models.OmsPsiInitAtBedrock; + +@Description(OMSCISLAM_OMSPSIINITATBEDROCK_DESCRIPTION) +@Author(name = OMSCISLAM_AUTHORNAMES, contact = OMSCISLAM_AUTHORCONTACTS) +@Keywords(OMSCISLAM_OMSPSIINITATBEDROCK_KEYWORDS) +@Label(OMSCISLAM_SUBMODULES_LABEL) +@Name(OMSCISLAM_OMSPSIINITATBEDROCK_NAME) +@Status(OMSCISLAM_OMSPSIINITATBEDROCK_STATUS) +@License(OMSCISLAM_LICENSE) +public class CislamPsiInitAtBedrock extends JGTModel { + + public final double DEFAULT_PSI_CONSTANT = 0.05; + + @Description(OMSCISLAM_inPit_DESCRIPTION) + @Unit("m") + @UI(JGTConstants.FILEIN_UI_HINT) + @In + public String inPit = null; + + @Description(OMSCISLAM_inSoilThickness_DESCRIPTION) + @Unit("m") + @UI(JGTConstants.FILEIN_UI_HINT) + @In + public String inSoilThickness = null; + + @Description(OMSCISLAM_OMSPSIINITATBEDROCK_pPsiInitAtBedrockConstant_DESCRIPTION) + @Unit("m") + @In + public double pPsiInitAtBedrockConstant = 0.0; + + @Description(OMSCISLAM_OMSPSIINITATBEDROCK_outPsiInitAtBedrock_DESCRIPTION) + @Unit("m") + @Out + public String outPsiInitAtBedrock = null; + + @Execute + public void process() throws Exception { + OmsPsiInitAtBedrock omsPsiInitAtBedrock = new OmsPsiInitAtBedrock(); + omsPsiInitAtBedrock.inPit = getRaster(inPit); + omsPsiInitAtBedrock.inSoilThickness = getRaster(inSoilThickness); + omsPsiInitAtBedrock.pPsiInitAtBedrockConstant = pPsiInitAtBedrockConstant; + omsPsiInitAtBedrock.inSoilThickness = getRaster(inSoilThickness); + omsPsiInitAtBedrock.process(); + dumpRaster(omsPsiInitAtBedrock.outPsiInitAtBedrock, outPsiInitAtBedrock); + } +} diff --git a/modules/src/main/java/org/jgrasstools/modules/CislamSafetyFactorGeomechanic.java b/modules/src/main/java/org/jgrasstools/modules/CislamSafetyFactorGeomechanic.java new file mode 100644 index 000000000..3fb658052 --- /dev/null +++ b/modules/src/main/java/org/jgrasstools/modules/CislamSafetyFactorGeomechanic.java @@ -0,0 +1,132 @@ +/* + * This file is part of the "CI-slam module": an addition to JGrassTools + * It has been contributed by Marco Foi (www.mcfoi.it) and Cristiano Lanni + * + * "CI-slam module" is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.jgrasstools.modules; + +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_AUTHORCONTACTS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_AUTHORNAMES; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_LICENSE; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSAFETYFACTORGEOMECHANIC_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSAFETYFACTORGEOMECHANIC_KEYWORDS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSAFETYFACTORGEOMECHANIC_NAME; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSAFETYFACTORGEOMECHANIC_STATUS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSAFETYFACTORGEOMECHANIC_outSafetyactorGeoMechanic_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_SUBMODULES_LABEL; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inCohesion_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inGamma_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inKsat_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inPhi_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inSlope_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inSoilThickness_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inTheta_r_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inTheta_s_DESCRIPTION; +import oms3.annotations.Author; +import oms3.annotations.Description; +import oms3.annotations.Execute; +import oms3.annotations.In; +import oms3.annotations.Keywords; +import oms3.annotations.Label; +import oms3.annotations.License; +import oms3.annotations.Name; +import oms3.annotations.Out; +import oms3.annotations.Status; +import oms3.annotations.UI; +import oms3.annotations.Unit; + +import org.jgrasstools.gears.libs.modules.JGTConstants; +import org.jgrasstools.gears.libs.modules.JGTModel; +import org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.utility_models.OmsSafetyFactorGeomechanic; + +@Description(OMSCISLAM_OMSAFETYFACTORGEOMECHANIC_DESCRIPTION) +@Author(name = OMSCISLAM_AUTHORNAMES, contact = OMSCISLAM_AUTHORCONTACTS) +@Keywords(OMSCISLAM_OMSAFETYFACTORGEOMECHANIC_KEYWORDS) +@Label(OMSCISLAM_SUBMODULES_LABEL) +@Name(OMSCISLAM_OMSAFETYFACTORGEOMECHANIC_NAME) +@Status(OMSCISLAM_OMSAFETYFACTORGEOMECHANIC_STATUS) +@License(OMSCISLAM_LICENSE) +public class CislamSafetyFactorGeomechanic extends JGTModel { + + @Description(OMSCISLAM_inSlope_DESCRIPTION) + @UI(JGTConstants.FILEIN_UI_HINT) + @In + public String inSlope = null; + + @Description(OMSCISLAM_inSoilThickness_DESCRIPTION) + @UI(JGTConstants.FILEIN_UI_HINT) + @Unit("m") + @In + public String inSoilThickness = null; + + // ############################################# + // Geo-Techical parameters + // ############################################# + @Description(OMSCISLAM_inCohesion_DESCRIPTION) + @UI(JGTConstants.FILEIN_UI_HINT) + @Unit("kPa") + @In + public String inCohesion = null; + + @Description(OMSCISLAM_inPhi_DESCRIPTION) + @UI(JGTConstants.FILEIN_UI_HINT) + @In + public String inPhi = null; + + @Description(OMSCISLAM_inGamma_DESCRIPTION) + @UI(JGTConstants.FILEIN_UI_HINT) + @In + public String inGammaSoil = null; + + @Description(OMSCISLAM_inKsat_DESCRIPTION) + @Unit("m/s") + @UI(JGTConstants.FILEIN_UI_HINT) + @In + public String inKsat = null; + + @Description(OMSCISLAM_inTheta_s_DESCRIPTION) + @Unit("-") + @UI(JGTConstants.FILEIN_UI_HINT) + @In + public String inTheta_s = null; + + @Description(OMSCISLAM_inTheta_r_DESCRIPTION) + @Unit("-") + @UI(JGTConstants.FILEIN_UI_HINT) + @In + public String inTheta_r = null; + + @Description(OMSCISLAM_OMSAFETYFACTORGEOMECHANIC_outSafetyactorGeoMechanic_DESCRIPTION) + @Unit("-") + @UI(JGTConstants.FILEIN_UI_HINT) + @Out + public String outSafetyactorGeoMechanic = null; + + @Execute + public void process() throws Exception { + + OmsSafetyFactorGeomechanic omsModel = new OmsSafetyFactorGeomechanic(); + omsModel.inSlope = getRaster(inSlope); + omsModel.inSoilThickness = getRaster(inSoilThickness); + omsModel.inCohesion = getRaster(inCohesion); + omsModel.inPhi = getRaster(inPhi); + omsModel.inGammaSoil = getRaster(inGammaSoil); + omsModel.inKsat = getRaster(inKsat); + omsModel.inTheta_s = getRaster(inTheta_s); + omsModel.inTheta_r = getRaster(inTheta_r); + omsModel.process(); + dumpRaster(omsModel.outSafetyactorGeoMechanic, outSafetyactorGeoMechanic); + } +} diff --git a/modules/src/main/java/org/jgrasstools/modules/CislamSafetyFactorsWorstCaseComposer.java b/modules/src/main/java/org/jgrasstools/modules/CislamSafetyFactorsWorstCaseComposer.java new file mode 100644 index 000000000..5c9a87b76 --- /dev/null +++ b/modules/src/main/java/org/jgrasstools/modules/CislamSafetyFactorsWorstCaseComposer.java @@ -0,0 +1,87 @@ +/* + * This file is part of the "CI-slam module": an addition to JGrassTools + * It has been contributed by Marco Foi (www.mcfoi.it) and Cristiano Lanni + * + * "CI-slam module" is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.jgrasstools.modules; + +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_AUTHORCONTACTS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_AUTHORNAMES; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_LICENSE; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSSAFETYFACTORCOMPOSER_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSSAFETYFACTORCOMPOSER_KEYWORDS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSSAFETYFACTORCOMPOSER_NAME; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSSAFETYFACTORCOMPOSER_STATUS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSSAFETYFACTORCOMPOSER_inRasters_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSSAFETYFACTORCOMPOSER_outSafetyFactorTotal_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSSAFETYFACTORCOMPOSER_pReturnTime_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_SUBMODULES_LABEL; + +import java.util.ArrayList; +import java.util.List; + +import oms3.annotations.Author; +import oms3.annotations.Description; +import oms3.annotations.Execute; +import oms3.annotations.In; +import oms3.annotations.Keywords; +import oms3.annotations.Label; +import oms3.annotations.License; +import oms3.annotations.Name; +import oms3.annotations.Out; +import oms3.annotations.Status; + +import org.geotools.coverage.grid.GridCoverage2D; +import org.jgrasstools.gears.libs.modules.JGTModel; +import org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.utility_models.OmsSafetyFactorGeomechanic; +import org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.utility_models.OmsSafetyFactorsWorstCaseComposer; + + +@Description(OMSCISLAM_OMSSAFETYFACTORCOMPOSER_DESCRIPTION) +@Author(name = OMSCISLAM_AUTHORNAMES, contact = OMSCISLAM_AUTHORCONTACTS) +@Keywords(OMSCISLAM_OMSSAFETYFACTORCOMPOSER_KEYWORDS) +@Label(OMSCISLAM_SUBMODULES_LABEL) +@Name(OMSCISLAM_OMSSAFETYFACTORCOMPOSER_NAME) +@Status(OMSCISLAM_OMSSAFETYFACTORCOMPOSER_STATUS) +@License(OMSCISLAM_LICENSE) +public class CislamSafetyFactorsWorstCaseComposer extends JGTModel { + + @Description(OMSCISLAM_OMSSAFETYFACTORCOMPOSER_inRasters_DESCRIPTION) + @In + public List inRasters; + + @Description(OMSCISLAM_OMSSAFETYFACTORCOMPOSER_pReturnTime_DESCRIPTION) + @In + public int pReturnTime; + + @Description(OMSCISLAM_OMSSAFETYFACTORCOMPOSER_outSafetyFactorTotal_DESCRIPTION) + @Out + public String outSafetyFactorTotal; + + @Execute + public void process() throws Exception { + + OmsSafetyFactorsWorstCaseComposer omsModel = new OmsSafetyFactorsWorstCaseComposer(); + + List rasterList = new ArrayList(); + for (String inRaster : inRasters){ + rasterList.add(getRaster(inRaster)); + } + omsModel.inRasters = rasterList; + omsModel.pReturnTime = pReturnTime; + omsModel.process(); + dumpRaster(omsModel.outSafetyFactorTotal, outSafetyFactorTotal); + } +} \ No newline at end of file diff --git a/modules/src/main/java/org/jgrasstools/modules/CislamSlopeForCislam.java b/modules/src/main/java/org/jgrasstools/modules/CislamSlopeForCislam.java new file mode 100644 index 000000000..7e55295ec --- /dev/null +++ b/modules/src/main/java/org/jgrasstools/modules/CislamSlopeForCislam.java @@ -0,0 +1,92 @@ +/* + * This file is part of the "CI-slam module": an addition to JGrassTools + * It has been contributed by Marco Foi (www.mcfoi.it) and Cristiano Lanni + * + * "CI-slam module" is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.jgrasstools.modules; + +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_AUTHORCONTACTS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_AUTHORNAMES; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_LICENSE; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSSLOPEFORCISLAM_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSSLOPEFORCISLAM_KEYWORDS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSSLOPEFORCISLAM_NAME; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSSLOPEFORCISLAM_STATUS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSSLOPEFORCISLAM_outSlope_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_SUBMODULES_LABEL; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inPit_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inSlope_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_pMinSlope_DESCRIPTION; +import oms3.annotations.Author; +import oms3.annotations.Description; +import oms3.annotations.Execute; +import oms3.annotations.In; +import oms3.annotations.Keywords; +import oms3.annotations.Label; +import oms3.annotations.License; +import oms3.annotations.Name; +import oms3.annotations.Out; +import oms3.annotations.Range; +import oms3.annotations.Status; +import oms3.annotations.UI; +import oms3.annotations.Unit; + +import org.jgrasstools.gears.libs.modules.JGTConstants; +import org.jgrasstools.gears.libs.modules.JGTModel; +import org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.utility_models.OmsSlopeForCislam; + +@Description(OMSCISLAM_OMSSLOPEFORCISLAM_DESCRIPTION) +@Author(name = OMSCISLAM_AUTHORNAMES, contact = OMSCISLAM_AUTHORCONTACTS) +@Keywords(OMSCISLAM_OMSSLOPEFORCISLAM_KEYWORDS) +@Label(OMSCISLAM_SUBMODULES_LABEL) +@Name(OMSCISLAM_OMSSLOPEFORCISLAM_NAME) +@Status(OMSCISLAM_OMSSLOPEFORCISLAM_STATUS) +@License(OMSCISLAM_LICENSE) +public class CislamSlopeForCislam extends JGTModel { + + @Description(OMSCISLAM_inSlope_DESCRIPTION) + @Unit("m/m") + @UI(JGTConstants.FILEIN_UI_HINT) + @In + public String inSlope = null; + + @Description(OMSCISLAM_inPit_DESCRIPTION) + @Unit("m") + @UI(JGTConstants.FILEIN_UI_HINT) + @In + public String inPit = null; + + @Description(OMSCISLAM_pMinSlope_DESCRIPTION) + @Unit("m/m") + @Range(min = 0.000001, max = 58.0) + @In + public double pMinSlope = 0.0090; + + @Description(OMSCISLAM_OMSSLOPEFORCISLAM_outSlope_DESCRIPTION) + @Unit("m/m") + @Out + public String outSlope = null; + + @Execute + public void process() throws Exception { + + OmsSlopeForCislam omsModel = new OmsSlopeForCislam(); + omsModel.inSlope = getRaster(inSlope); + omsModel.inPit = getRaster(inPit); + omsModel.pMinSlope = pMinSlope; + omsModel.process(); + dumpRaster(omsModel.outSlope, outSlope); + } +} \ No newline at end of file diff --git a/modules/src/main/java/org/jgrasstools/modules/CislamSoilThickness.java b/modules/src/main/java/org/jgrasstools/modules/CislamSoilThickness.java new file mode 100644 index 000000000..5b6a305d9 --- /dev/null +++ b/modules/src/main/java/org/jgrasstools/modules/CislamSoilThickness.java @@ -0,0 +1,75 @@ +/* + * This file is part of the "CI-slam module": an addition to JGrassTools + * It has been contributed by Marco Foi (www.mcfoi.it) and Cristiano Lanni + * + * "CI-slam module" is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.jgrasstools.modules; + +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_AUTHORCONTACTS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_AUTHORNAMES; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_LICENSE; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSSLOPEFORCISLAM_inSlope_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSSOILTHICKNESS_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSSOILTHICKNESS_KEYWORDS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSSOILTHICKNESS_NAME; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSSOILTHICKNESS_STATUS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSSOILTHICKNESS_outSoilThickness_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_SUBMODULES_LABEL; +import oms3.annotations.Author; +import oms3.annotations.Description; +import oms3.annotations.Execute; +import oms3.annotations.In; +import oms3.annotations.Keywords; +import oms3.annotations.Label; +import oms3.annotations.License; +import oms3.annotations.Name; +import oms3.annotations.Out; +import oms3.annotations.Status; +import oms3.annotations.UI; +import oms3.annotations.Unit; + +import org.jgrasstools.gears.libs.modules.JGTConstants; +import org.jgrasstools.gears.libs.modules.JGTModel; +import org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.utility_models.OmsSoilThickness; + +@Description(OMSCISLAM_OMSSOILTHICKNESS_DESCRIPTION) +@Author(name = OMSCISLAM_AUTHORNAMES, contact = OMSCISLAM_AUTHORCONTACTS) +@Keywords(OMSCISLAM_OMSSOILTHICKNESS_KEYWORDS) +@Label(OMSCISLAM_SUBMODULES_LABEL) +@Name(OMSCISLAM_OMSSOILTHICKNESS_NAME) +@Status(OMSCISLAM_OMSSOILTHICKNESS_STATUS) +@License(OMSCISLAM_LICENSE) +public class CislamSoilThickness extends JGTModel { + + @Description(OMSCISLAM_OMSSLOPEFORCISLAM_inSlope_DESCRIPTION) + @Unit("m/m") + @UI(JGTConstants.FILEIN_UI_HINT) + @In + public String inSlope = null; + + @Description(OMSCISLAM_OMSSOILTHICKNESS_outSoilThickness_DESCRIPTION) + @Unit("m") + @Out + public String outSoilThickness = null; + + @Execute + public void process() throws Exception { + + OmsSoilThickness omsModel = new OmsSoilThickness(); + omsModel.inSlope = getRaster(inSlope); + omsModel.process(); + dumpRaster(omsModel.outSoilThickness, outSoilThickness); + } +} diff --git a/modules/src/main/java/org/jgrasstools/modules/CislamV0.java b/modules/src/main/java/org/jgrasstools/modules/CislamV0.java new file mode 100644 index 000000000..015c64e99 --- /dev/null +++ b/modules/src/main/java/org/jgrasstools/modules/CislamV0.java @@ -0,0 +1,108 @@ +/* + * This file is part of the "CI-slam module": an addition to JGrassTools + * It has been contributed by Marco Foi (www.mcfoi.it) and Cristiano Lanni + * + * "CI-slam module" is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.jgrasstools.modules; + +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_AUTHORCONTACTS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_AUTHORNAMES; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_LICENSE; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSV0_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSV0_KEYWORDS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSV0_NAME; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSV0_STATUS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSV0_inPsiInitAtBedrock_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSV0_outV0_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_SUBMODULES_LABEL; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inAlfaVanGen_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inNVanGen_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inSoilThickness_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inTheta_r_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inTheta_s_DESCRIPTION; +import oms3.annotations.Author; +import oms3.annotations.Description; +import oms3.annotations.Execute; +import oms3.annotations.In; +import oms3.annotations.Keywords; +import oms3.annotations.Label; +import oms3.annotations.License; +import oms3.annotations.Name; +import oms3.annotations.Out; +import oms3.annotations.Status; +import oms3.annotations.UI; +import oms3.annotations.Unit; + +import org.jgrasstools.gears.libs.modules.JGTConstants; +import org.jgrasstools.gears.libs.modules.JGTModel; +import org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.utility_models.OmsV0; + +@Description(OMSCISLAM_OMSV0_DESCRIPTION) +@Author(name = OMSCISLAM_AUTHORNAMES, contact = OMSCISLAM_AUTHORCONTACTS) +@Keywords(OMSCISLAM_OMSV0_KEYWORDS) +@Label(OMSCISLAM_SUBMODULES_LABEL) +@Name(OMSCISLAM_OMSV0_NAME) +@Status(OMSCISLAM_OMSV0_STATUS) +@License(OMSCISLAM_LICENSE) +public class CislamV0 extends JGTModel { + @Description(OMSCISLAM_inSoilThickness_DESCRIPTION) + @Unit("m") + @UI(JGTConstants.FILEIN_UI_HINT) + @In + public String inSoilThickness = null; + + @Description(OMSCISLAM_inTheta_s_DESCRIPTION) + @UI(JGTConstants.FILEIN_UI_HINT) + @In + public String inTheta_s = null; + + @Description(OMSCISLAM_inTheta_r_DESCRIPTION) + @UI(JGTConstants.FILEIN_UI_HINT) + @In + public String inTheta_r = null; + + @Description(OMSCISLAM_OMSV0_inPsiInitAtBedrock_DESCRIPTION) + @UI(JGTConstants.FILEIN_UI_HINT) + @In + public String inPsiInitAtBedrock = null; + + @Description(OMSCISLAM_inAlfaVanGen_DESCRIPTION) + @UI(JGTConstants.FILEIN_UI_HINT) + @In + public String inAlfaVanGen = null; + + @Description(OMSCISLAM_inNVanGen_DESCRIPTION) + @UI(JGTConstants.FILEIN_UI_HINT) + @In + public String inNVanGen = null; + + @Description(OMSCISLAM_OMSV0_outV0_DESCRIPTION) + @Out + public String outV0 = null; + + @Execute + public void process() throws Exception { + + OmsV0 omsModel = new OmsV0(); + omsModel.inSoilThickness = getRaster(inSoilThickness); + omsModel.inTheta_s = getRaster(inTheta_s); + omsModel.inTheta_r = getRaster(inTheta_r); + omsModel.inPsiInitAtBedrock = getRaster(inPsiInitAtBedrock); + omsModel.inAlfaVanGen = getRaster(inAlfaVanGen); + omsModel.inNVanGen = getRaster(inNVanGen); + omsModel.process(); + dumpRaster(omsModel.outV0, outV0); + } +} diff --git a/modules/src/main/java/org/jgrasstools/modules/CislamVanGenuchtenMapsGenerator.java b/modules/src/main/java/org/jgrasstools/modules/CislamVanGenuchtenMapsGenerator.java new file mode 100644 index 000000000..eefad2b90 --- /dev/null +++ b/modules/src/main/java/org/jgrasstools/modules/CislamVanGenuchtenMapsGenerator.java @@ -0,0 +1,114 @@ +/* + * This file is part of the "CI-slam module": an addition to JGrassTools + * It has been contributed by Marco Foi (www.mcfoi.it) and Cristiano Lanni + * + * "CI-slam module" is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.jgrasstools.modules; + +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_AUTHORCONTACTS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_AUTHORNAMES; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_LICENSE; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSVANGENUCHMAPGEN_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSVANGENUCHMAPGEN_KEYWORDS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSVANGENUCHMAPGEN_NAME; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSVANGENUCHMAPGEN_STATUS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_SUBMODULES_LABEL; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inGeo_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_outAlfaVanGen_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_outCohesion_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_outGamma_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_outKsat_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_outNVanGen_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_outPhi_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_outTheta_r_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_outTheta_s_DESCRIPTION; +import oms3.annotations.Author; +import oms3.annotations.Description; +import oms3.annotations.Execute; +import oms3.annotations.In; +import oms3.annotations.Keywords; +import oms3.annotations.Label; +import oms3.annotations.License; +import oms3.annotations.Name; +import oms3.annotations.Out; +import oms3.annotations.Status; +import oms3.annotations.UI; + +import org.jgrasstools.gears.libs.modules.JGTConstants; +import org.jgrasstools.gears.libs.modules.JGTModel; +import org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.utility_models.OmsVanGenuchtenMapsGenerator; + +@Description(OMSCISLAM_OMSVANGENUCHMAPGEN_DESCRIPTION) +@Author(name = OMSCISLAM_AUTHORNAMES, contact = OMSCISLAM_AUTHORCONTACTS) +@Keywords(OMSCISLAM_OMSVANGENUCHMAPGEN_KEYWORDS) +@Label(OMSCISLAM_SUBMODULES_LABEL) +@Name(OMSCISLAM_OMSVANGENUCHMAPGEN_NAME) +@Status(OMSCISLAM_OMSVANGENUCHMAPGEN_STATUS) +@License(OMSCISLAM_LICENSE) +public class CislamVanGenuchtenMapsGenerator extends JGTModel { + + @Description(OMSCISLAM_inGeo_DESCRIPTION) + @UI(JGTConstants.FILEIN_UI_HINT) + @In + public String inGeo = null; + + @Description(OMSCISLAM_outCohesion_DESCRIPTION) + @Out + public String outCohesion = null; + + @Description(OMSCISLAM_outPhi_DESCRIPTION) + @Out + public String outPhi = null; + + @Description(OMSCISLAM_outGamma_DESCRIPTION) + @Out + public String outGamma = null; + + @Description(OMSCISLAM_outKsat_DESCRIPTION) + @Out + public String outKsat = null; + + @Description(OMSCISLAM_outTheta_s_DESCRIPTION) + @Out + public String outTheta_s = null; + + @Description(OMSCISLAM_outTheta_r_DESCRIPTION) + @Out + public String outTheta_r = null; + + @Description(OMSCISLAM_outAlfaVanGen_DESCRIPTION) + @Out + public String outAlfaVanGen = null; + + @Description(OMSCISLAM_outNVanGen_DESCRIPTION) + @Out + public String outNVanGen = null; + + @Execute + public void process() throws Exception { + + OmsVanGenuchtenMapsGenerator omsModel = new OmsVanGenuchtenMapsGenerator(); + omsModel.inGeo = getRaster(inGeo); + omsModel.process(); + dumpRaster(omsModel.outCohesion, outCohesion); + dumpRaster(omsModel.outPhi, outPhi); + dumpRaster(omsModel.outGamma, outGamma); + dumpRaster(omsModel.outKsat, outKsat); + dumpRaster(omsModel.outTheta_s, outTheta_s); + dumpRaster(omsModel.outTheta_r, outTheta_r); + dumpRaster(omsModel.outAlfaVanGen, outAlfaVanGen); + dumpRaster(omsModel.outNVanGen, outNVanGen); + } +} diff --git a/modules/src/main/java/org/jgrasstools/modules/CislamVwt.java b/modules/src/main/java/org/jgrasstools/modules/CislamVwt.java new file mode 100644 index 000000000..3e57cc936 --- /dev/null +++ b/modules/src/main/java/org/jgrasstools/modules/CislamVwt.java @@ -0,0 +1,103 @@ +/* + * This file is part of the "CI-slam module": an addition to JGrassTools + * It has been contributed by Marco Foi (www.mcfoi.it) and Cristiano Lanni + * + * "CI-slam module" is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.jgrasstools.modules; + +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_AUTHORCONTACTS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_AUTHORNAMES; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_LICENSE; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSVWT_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSVWT_KEYWORDS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSVWT_NAME; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSVWT_STATUS; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_OMSVWT_outVwt_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_SUBMODULES_LABEL; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inAlfaVanGen_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inNVanGen_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inSoilThickness_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inTheta_r_DESCRIPTION; +import static org.jgrasstools.hortonmachine.i18n.HortonMessages.OMSCISLAM_inTheta_s_DESCRIPTION; +import oms3.annotations.Author; +import oms3.annotations.Description; +import oms3.annotations.Execute; +import oms3.annotations.In; +import oms3.annotations.Keywords; +import oms3.annotations.Label; +import oms3.annotations.License; +import oms3.annotations.Name; +import oms3.annotations.Out; +import oms3.annotations.Status; +import oms3.annotations.UI; +import oms3.annotations.Unit; + +import org.jgrasstools.gears.libs.modules.JGTConstants; +import org.jgrasstools.gears.libs.modules.JGTModel; +import org.jgrasstools.hortonmachine.modules.hydrogeomorphology.cislam.utility_models.OmsVwt; + + +@Description(OMSCISLAM_OMSVWT_DESCRIPTION) +@Author(name = OMSCISLAM_AUTHORNAMES, contact = OMSCISLAM_AUTHORCONTACTS) +@Keywords(OMSCISLAM_OMSVWT_KEYWORDS) +@Label(OMSCISLAM_SUBMODULES_LABEL) +@Name(OMSCISLAM_OMSVWT_NAME) +@Status(OMSCISLAM_OMSVWT_STATUS) +@License(OMSCISLAM_LICENSE) +public class CislamVwt extends JGTModel { + + @Description(OMSCISLAM_inSoilThickness_DESCRIPTION) + @Unit("m") + @UI(JGTConstants.FILEIN_UI_HINT) + @In + public String inSoilThickness = null; + + @Description(OMSCISLAM_inTheta_s_DESCRIPTION) + @UI(JGTConstants.FILEIN_UI_HINT) + @In + public String inTheta_s = null; + + @Description(OMSCISLAM_inTheta_r_DESCRIPTION) + @UI(JGTConstants.FILEIN_UI_HINT) + @In + public String inTheta_r = null; + + @Description(OMSCISLAM_inAlfaVanGen_DESCRIPTION) + @UI(JGTConstants.FILEIN_UI_HINT) + @In + public String inAlfaVanGen = null; + + @Description(OMSCISLAM_inNVanGen_DESCRIPTION) + @UI(JGTConstants.FILEIN_UI_HINT) + @In + public String inNVanGen = null; + + @Description(OMSCISLAM_OMSVWT_outVwt_DESCRIPTION) + @Out + public String outVwt = null; + + @Execute + public void process() throws Exception{ + + OmsVwt omsModel = new OmsVwt(); + omsModel.inSoilThickness = getRaster(inSoilThickness); + omsModel.inTheta_s = getRaster(inTheta_s); + omsModel.inTheta_r = getRaster(inTheta_r); + omsModel.inAlfaVanGen = getRaster(inAlfaVanGen); + omsModel.inNVanGen = getRaster(inNVanGen); + omsModel.process(); + dumpRaster(omsModel.outVwt, outVwt); + } +} diff --git a/modules/src/main/resources/META-INF/services/org.jgrasstools.gears.libs.modules.JGTModel b/modules/src/main/resources/META-INF/services/org.jgrasstools.gears.libs.modules.JGTModel index 4686caf9d..19fd512d6 100644 --- a/modules/src/main/resources/META-INF/services/org.jgrasstools.gears.libs.modules.JGTModel +++ b/modules/src/main/resources/META-INF/services/org.jgrasstools.gears.libs.modules.JGTModel @@ -5,6 +5,14 @@ org.jgrasstools.modules.Buffer org.jgrasstools.modules.CannyEdgeDetector org.jgrasstools.modules.Carver org.jgrasstools.modules.Cb +org.jgrasstools.modules.Cislam +org.jgrasstools.modules.CislamPsiInitAtBedrock +org.jgrasstools.modules.CislamSafetyFactorGeomechanic +org.jgrasstools.modules.CislamSlopeForCislam +org.jgrasstools.modules.CislamSoilThickness +org.jgrasstools.modules.CislamV0 +org.jgrasstools.modules.CislamVanGenuchtenMapsGenerator +org.jgrasstools.modules.CislamVwt org.jgrasstools.modules.ContourExtractor org.jgrasstools.modules.Curvatures org.jgrasstools.modules.CurvaturesBivariate