private ErosionParameters GetErosionParameters( WepsResponseV5_2 wepsResponse, WeppResponseV3_1 weppResponse, Rusle2ResponseV5_0 rusle2Response) { double null_flag = -9999.99; ErosionParameters result = new ErosionParameters() { Latitude = wepsResponse.Latitude, Longitude = wepsResponse.Longitude, RotationName = wepsResponse.RotationName, WepsOM = wepsResponse.OM, WeppOM = weppResponse?.OM ?? null_flag, Rusle2OM = rusle2Response?.OM ?? null_flag, WepsFO = wepsResponse.FO, WeppFO = weppResponse?.FO ?? null_flag, Rusle2FO = rusle2Response?.FO ?? null_flag, WepsER = wepsResponse.ER, WeppER = weppResponse?.ER ?? null_flag, Rusle2ER = rusle2Response?.ER ?? null_flag, WepsStir = wepsResponse.Stir, WeppStir = weppResponse?.Stir ?? null_flag, Rusle2Stir = rusle2Response?.Stir ?? null_flag, WepsWindErosion = wepsResponse.WindErosion, WeppSoilLoss = weppResponse?.SoilLoss ?? null_flag, Rusle2SoilLoss = rusle2Response?.SoilLoss ?? null_flag, Rusle2Sci = rusle2Response?.SCI ?? null_flag, WepsAverageBiomass = wepsResponse?.AverageBiomass ?? null_flag }; return(result); }
public bool Run( string inputWeppPath, string inputWepsPath, string inputRusle2Path, string outputFilePath) { // Read json files with simulation results List <WeppResponseV3_1> weppResponses = jsonHandler.ReadWeppResponseV3_1Files( inputWeppPath, weppV3_1Service); List <WepsResponseV5_2> wepsResponses = jsonHandler.ReadWepsResponseV5_2Files( inputWepsPath, wepsV5_2Service); List <Rusle2ResponseV5_0> rusle2Responses = jsonHandler.ReadRusle2ResponseV5_0Files( inputRusle2Path, rusle2V5_0Service); /* I should allow for failed runs - SciBuilder should check for missing values and skip those * if ((weppResponses.Count != wepsResponses.Count) || * (weppResponses.Count != rusle2Responses.Count)) * throw new ArgumentException("Input paths do not contain the same number of files"); */ // Merge simulation results into erosion parameters // Using WEPS results to merge because when calc "SCI" both "old" and "new" versions require WEPS List <ErosionParameters> erosionParametersList = new List <ErosionParameters>(); foreach (WepsResponseV5_2 wepsResponse in wepsResponses) { WeppResponseV3_1 weppResponse = weppResponses.First( x => x.Latitude == wepsResponse.Latitude && x.Longitude == wepsResponse.Longitude && x.RotationName == wepsResponse.RotationName); Rusle2ResponseV5_0 rusle2Response = rusle2Responses.First( x => x.Latitude == wepsResponse.Latitude && x.Longitude == wepsResponse.Longitude && x.RotationName == wepsResponse.RotationName); ErosionParameters erosionParameters = GetErosionParameters( wepsResponse, weppResponse, rusle2Response); erosionParametersList.Add(erosionParameters); } // Write file csvHandler.WriteErosionParameters( outputFilePath, erosionParametersList); return(true); }
public JObject AddParameters( JObject scenario, ErosionParameters erosionParameters) { JObject withParameters = scenario; // Note: The components of the name are split using double underscore (__), not single, due to an underscore being used in RotationName string scenarioName = $"{erosionParameters.Latitude.ToString()}__{erosionParameters.Longitude.ToString()}__{erosionParameters.RotationName}"; // Set name withParameters["metainfo"]["name"] = scenarioName; foreach (var p in withParameters["parameter"]) { string paramName = p["name"].ToString(); // Note: We're using the organic matter value from WEPP, so overriding wind_om with value from WEPP (wind_om = WaterOM) switch (paramName) { case "erosion_water": p["value"] = erosionParameters.Rusle2ER; break; case "water_om": p["value"] = erosionParameters.Rusle2OM; break; case "water_fo": p["value"] = erosionParameters.Rusle2FO; break; case "wind_om": p["value"] = erosionParameters.Rusle2OM; break; case "wind_fo": p["value"] = erosionParameters.WepsFO; break; case "erosion_wind": p["value"] = erosionParameters.WepsER; break; } } return(withParameters); }
public bool Run( string inputCsipLocationsPath, string inputErosionParametersPath, string inputSciResponsePath, string outputFilePath) { const int PRECISION = 5; // CsipLocations and ErosionParameters should be in csv format already, from previous steps List <CsipLocation> csipLocations = csvHandler.ReadCsipLocationFile( inputCsipLocationsPath); List <ErosionParameters> erosionParameters = csvHandler.ReadErosionParameters( inputErosionParametersPath); List <SciResponseV2_1> sciResponses = jsonHandler.ReadSciResponseV2_1Files( inputSciResponsePath, serviceHandler); List <ExperimentalResults> experimentalResultsList = new List <ExperimentalResults>(); foreach (SciResponseV2_1 sciResponse in sciResponses) { // Find matching scenarios CsipLocation csipLocation = csipLocations .First(x => Math.Round(x.Latitude, PRECISION) == Math.Round(sciResponse.Latitude, PRECISION) && Math.Round(x.Longitude, PRECISION) == Math.Round(sciResponse.Longitude, PRECISION)); ErosionParameters erosionParameter = erosionParameters .First(x => Math.Round(x.Latitude, PRECISION) == Math.Round(sciResponse.Latitude, PRECISION) && Math.Round(x.Longitude, PRECISION) == Math.Round(sciResponse.Longitude, PRECISION) && x.RotationName == sciResponse.RotationName); if (csipLocation == null || erosionParameter == null) { throw new Exception( "Could not find matching CsipLocation and/or ErosionParameter for given SciResponse"); } ExperimentalResults result = new ExperimentalResults() { // TODO: Create new column for actual WindOM and value used by SCI service? Latitude = sciResponse.Latitude, Longitude = sciResponse.Longitude, RotationName = sciResponse.RotationName, AnthromeKey = csipLocation.AnthromeKey, Cokey = csipLocation.Cokey, Slope = csipLocation.Slope, SlopeLength = csipLocation.SlopeLength, PercentOfMapUnit = csipLocation.PercentOfMapUnit, MapUnitName = csipLocation.MapUnitName, WaterOM = sciResponse.WaterOM, WindOM = sciResponse.WindOM, WaterFO = sciResponse.WaterFO, WindFO = sciResponse.WindFO, ErosionWater = sciResponse.ErosionWater, ErosionWind = sciResponse.ErosionWind, SciTotal = sciResponse.SciTotal }; experimentalResultsList.Add(result); } // Write file csvHandler.WriteExperimentalResultsParameters( outputFilePath, experimentalResultsList); return(true); }