public void TestInitializeEnsembleFromPrmFile() { string ParameterFile = "SmallDiverseModel.prm"; int NumberOfEnsembleMembers = 10; string paramsFileFullPath = TestDataFolder + "\\" + ParameterFile; EnsembleHandler EnsMods = new EnsembleHandler(); EnsMods.InitializeFromFile(paramsFileFullPath, NumberOfEnsembleMembers); EnsembleStatistics ensstats = new EnsembleStatistics(); ensstats.SetStats(true, false, true, true, false); EnsMods.AddOutputVariable(DtuSmModels.SmOutput.OutputType.GlobalVolumen, ensstats, ""); EnsMods.AddOutputVariable(DtuSmModels.SmOutput.OutputType.nodeVolume, ensstats, "SM3"); double[] rainfall = new double[1200]; rainfall[5] = 5; //5 mm of rainfall in one minute. IEnsembleNoise noise = new TemporallyCorrelatedNoise(NumberOfEnsembleMembers, 0.8, 60 * 10, 60, 3); EnsMods.AddNoiseOnRain(noise); EnsMods.SetRainDataForAllCatchments(rainfall); EnsMods.runForOneMinuteRainInput(); EnsMods.SetRainDataForAllCatchments(rainfall); EnsMods.runForOneMinuteRainInput(); var data1 = EnsMods.outputCollection.hydraulicOutput[0].dataSeries[0].data.ToArray(); var data2 = EnsMods.outputCollection.hydraulicOutput[0].dataSeries[1].data.ToArray(); var data3 = EnsMods.outputCollection.hydraulicOutput[0].dataSeries[2].data.ToArray(); }
public void TestRunAndUpdate1() { string ParameterFile = "SmallDiverseModel.prm"; int NumberOfEnsembleMembers = 10; string paramsFileFullPath = TestDataFolder + "\\" + ParameterFile; EnsembleHandler EnsMods = new EnsembleHandler(); EnsMods.InitializeFromFile(paramsFileFullPath, NumberOfEnsembleMembers); EnsembleStatistics ensstats = new EnsembleStatistics(); ensstats.SetStats(true, false, true, true, false); //EnsMods.AddOutputVariable(DtuSmModels.SmOutput.outputType.GlobalVolumen, ensstats, ""); EnsMods.Mat_AddOutputVariable(DtuSmModels.SmOutput.OutputType.outletFlowTimeSeries, "outlet1", true, true, true, true, false); EnsMods.Mat_AddOutputVariableLinkFlow("SM3", "SM4", "myPipe", true, true, true, true, false); EnsMods.AddDA_variable(DtuSmModels.SmOutput.OutputType.outletFlowTimeSeries, "outlet1", "", "", ""); double[] rainfall = new double[1200]; rainfall[5] = 5; //5 mm of rainfall in one minute. IEnsembleNoise noise = new TemporallyCorrelatedNoise(NumberOfEnsembleMembers, 0.8, 60 * 10, 60, 3); EnsMods.AddNoiseOnRain(noise); double affald = 0.7; Double[] obs = { affald }; Double[,] obsVar = { { 0.1 } }; for (int i = 0; i < rainfall.Length / 5; i++) {//update every fifth time step. EnsMods.SetRainDataForAllCatchments(rainfall.Skip(i * 5).Take(5).ToArray()); EnsMods.runForOneMinuteRainInput(); EnsMods.UpdateToObs(obs, obsVar, 1, 1); } EnsMods.SetRainDataForAllCatchments(rainfall); EnsMods.runForOneMinuteRainInput(); var data1 = EnsMods.outputCollection.hydraulicOutput[0].dataSeries[0].data.ToArray(); var data2 = EnsMods.outputCollection.hydraulicOutput[0].dataSeries[1].data.ToArray(); var data3 = EnsMods.outputCollection.hydraulicOutput[0].dataSeries[2].data.ToArray(); }
public void TestKalmanUpdateOfParameters() { //string ParameterFile = "SmallDiverseModel.prm"; string ParameterFile = "SmallLinResModel.prm"; int NumberOfEnsembleMembers = 4; double initialStdOfParams = 0.2; //relative. double varianceScaling = Math.Sqrt(12 * initialStdOfParams * initialStdOfParams); //since I use a uniform distribution string paramsFileFullPath = TestDataFolder + "\\" + ParameterFile; EnsembleHandler EnsMods = new EnsembleHandler(); EnsMods.InitializeFromFile(paramsFileFullPath, NumberOfEnsembleMembers); EnsembleStatistics ensstats = new EnsembleStatistics(); ensstats.SetStats(true, false, true, true, false); //EnsMods.AddOutputVariable(DtuSmModels.SmOutput.outputType.GlobalVolumen, ensstats, ""); EnsMods.Mat_AddOutputVariable(DtuSmModels.SmOutput.OutputType.outletFlowTimeSeries, "outlet1", true, true, true, true, false); EnsMods.AddDA_variable(DtuSmModels.SmOutput.OutputType.outletFlowTimeSeries, "outlet1", "", "", ""); Random rand = new Random(); for (int i = 0; i < NumberOfEnsembleMembers; i++) { double[] prm = EnsMods.models[i].getParameters(); for (int j = 0; j < prm.Length; j++) { prm[j] = prm[j] * (1 + (rand.NextDouble() - 0.5) * varianceScaling); } EnsMods.models[i].setParameter(prm); } EnsMods.Mat_SetParameterDaMethod("TolDEnKF", 0, 0, 0); double[] rainfall = new double[1200]; rainfall[5] = 5; //5 mm of rainfall in one minute. IEnsembleNoise noise = new TemporallyCorrelatedNoise(NumberOfEnsembleMembers, 0.8, 60 * 10, 60, 3); EnsMods.AddNoiseOnRain(noise); Double[] obs = { 0.7 }; Double[,] obsVar = { { 0.1 } }; for (int i = 0; i < rainfall.Length / 5; i++) {//update every fifth time step. EnsMods.SetRainDataForAllCatchments(rainfall.Skip(i * 5).Take(5).ToArray()); EnsMods.runForOneMinuteRainInput(); EnsMods.updateParamsFromObs(obs, obsVar, 1.001, 0.01); EnsMods.UpdateToObs(obs, obsVar, 1, 1); } EnsMods.SetRainDataForAllCatchments(rainfall); EnsMods.runForOneMinuteRainInput(); var data1 = EnsMods.outputCollection.hydraulicOutput[0].dataSeries[0].data.ToArray(); var data2 = EnsMods.outputCollection.hydraulicOutput[0].dataSeries[1].data.ToArray(); var data3 = EnsMods.outputCollection.hydraulicOutput[0].dataSeries[2].data.ToArray(); }