public static void GenerateEcoregionClimateData(IEcoregion ecoregion, int startYear, double latitude, double fieldCapacity, double wiltingPoint) { // JM: these next three lines are not currently used, but may need to be modified if used: //int numberOftimeSteps = Climate.ModelCore.EndTime - Climate.ModelCore.StartTime; //annualPDSI = new double[Climate.ModelCore.Ecoregions.Count, future_allData.Count]; //landscapeAnnualPDSI = new double[future_allData.Count]; double[] temperature_normals = new double[12]; double[] precip_normals = new double[12]; double availableWaterCapacity = fieldCapacity - wiltingPoint; Climate.ModelCore.UI.WriteLine(" Core.StartTime = {0}, Core.EndTime = {1}.", ModelCore.StartTime, ModelCore.EndTime); //Climate.ModelCore.UI.WriteLine(" Climate.LandscapeAnnualPDSI.Length = {0}.", Climate.LandscapeAnnualPDSI.Length); //First Calculate Climate Normals from Spin-up data int timeStepIndex = 0; foreach (KeyValuePair <int, AnnualClimate_Monthly[]> timeStep in Spinup_MonthlyData) { //Climate.ModelCore.UI.WriteLine(" Calculating Weather for SPINUP: timeStep = {0}, actualYear = {1}", timeStep.Key, startYear + timeStep.Key); AnnualClimate_Monthly annualClimateMonthly = new AnnualClimate_Monthly(ecoregion, latitude, Climate.Phase.SpinUp_Climate, timeStep.Key, timeStepIndex); Spinup_MonthlyData[startYear + timeStep.Key][ecoregion.Index] = annualClimateMonthly; for (int mo = 0; mo < 12; mo++) { temperature_normals[mo] += annualClimateMonthly.MonthlyTemp[mo]; precip_normals[mo] += annualClimateMonthly.MonthlyPrecip[mo]; } timeStepIndex++; } // Calculate AVERAGE T normal. for (int mo = 0; mo < 12; mo++) { temperature_normals[mo] /= (double)Spinup_MonthlyData.Count; precip_normals[mo] /= (double)Spinup_MonthlyData.Count; //Climate.ModelCore.UI.WriteLine("Month = {0}, Original Monthly T normal = {1}", mo, month_Temp_normal[mo]); } timeStepIndex = 0; PDSI_Calculator.InitializeEcoregion_PDSI(temperature_normals, precip_normals, availableWaterCapacity, latitude, UnitSystem.metrics, ecoregion); foreach (KeyValuePair <int, AnnualClimate_Monthly[]> timeStep in Future_MonthlyData) { //Climate.ModelCore.UI.WriteLine(" Completed calculations for Future_Climate: TimeStepYear = {0}, actualYear = {1}", timeStep.Key, startYear + timeStep.Key); AnnualClimate_Monthly annualClimateMonthly = new AnnualClimate_Monthly(ecoregion, latitude, Climate.Phase.Future_Climate, timeStep.Key, timeStepIndex); Future_MonthlyData[startYear + timeStep.Key][ecoregion.Index] = annualClimateMonthly;
//public static void GenerateClimate_GetPDSI(int startYear, int endYear, int latitude, double fieldCapacity, double wiltingPoint) //{ // string outputFilePath = @"PDSI_BaseBDA_Genrated_Climate.csv"; // File.WriteAllText(outputFilePath, String.Empty); // foreach (IEcoregion ecoregion in Climate.ModelCore.Ecoregions) // { // AnnualClimate_Monthly[] acs; // int numOfYears = endYear - startYear + 1; // acs = new AnnualClimate_Monthly[numOfYears]; // //foreach time step it should be called // for (int i = startYear; i <= endYear; i++) // { // acs[i - startYear] = new AnnualClimate_Monthly(ecoregion, 0, latitude); // Latitude should be given // //Climate.ModelCore.UI.WriteLine(ac.MonthlyTemp[0].ToString() + "\n"); // //Climate.ModelCore.UI.WriteLine(ac.MonthlyPrecip[0].ToString() + "\n"); // } // double[] mon_T_normal = new double[12];//new double[12] { 19.693, 23.849, 34.988, 49.082, 60.467, 70.074, 75.505, 73.478, 64.484, 52.634, 36.201, 24.267 }; // IClimateRecord[] climateRecs = new ClimateRecord[12]; // //If timestep is 0 then calculate otherwise get the mon_T_normal for timestep 0 // Climate.TimestepData = future_allData[0]; // for (int mo = 0; mo < 12; mo++) // { // climateRecs[mo] = Climate.TimestepData[ecoregion.Index, mo]; // mon_T_normal[mo] = (climateRecs[mo].AvgMinTemp + climateRecs[mo].AvgMinTemp) / 2; // } // double AWC = fieldCapacity - wiltingPoint; // //double latitude = Landis.Extension.Succession.Century.EcoregionData.Latitude[ecoregion]; // new PDSI_Calculator().CalculatePDSI(acs, mon_T_normal, AWC, latitude, /*outputFilePath,*/ UnitSystem.metrics); // } //} //public static void GenerateEcoregionClimateData() //{ //} public static void GenerateEcoregionClimateData(IEcoregion ecoregion, int startYear, double latitude, double fieldCapacity, double wiltingPoint) { Climate.ModelCore.UI.WriteLine(" Generating Ecoregion Climate Data for ecoregion = {0}.", ecoregion.Name); int numberOftimeSteps = Climate.ModelCore.EndTime - Climate.ModelCore.StartTime; annualPDSI = new double[Climate.ModelCore.Ecoregions.Count, future_allData.Count]; //numberOftimeSteps + 1]; landscapeAnnualPDSI = new double[future_allData.Count]; //numberOftimeSteps+1]; double[] temperature_normals = new double[12]; double availableWaterCapacity = fieldCapacity - wiltingPoint; //Climate.ModelCore.UI.WriteLine(" Latitude = {0}, Available Water = {1}.", latitude, availableWaterCapacity); //IClimateRecord[] climateRecs = new ClimateRecord[12]; //int minimumTime = 5000; //Firt Calculate Climate Normals from Spin-up data foreach (KeyValuePair <int, IClimateRecord[, ]> timeStep in spinup_allData) { //Climate.ModelCore.UI.WriteLine(" Calculating Weather for SPINUP Year = {0}.", timeStep.Key); AnnualClimate_Monthly annualClimateMonthly = new AnnualClimate_Monthly(ecoregion, startYear + timeStep.Key, latitude, Climate.Phase.SpinUp_Climate, timeStep.Key); Spinup_MonthlyData[startYear + timeStep.Key][ecoregion.Index] = annualClimateMonthly; for (int mo = 0; mo < 12; mo++) { temperature_normals[mo] += annualClimateMonthly.MonthlyTemp[mo]; } } // Calculate AVERAGE T normal. for (int mo = 0; mo < 12; mo++) { temperature_normals[mo] /= (double)spinup_allData.Count; //Climate.ModelCore.UI.WriteLine("Month = {0}, Original Monthly T normal = {1}", mo, month_Temp_normal[mo]); } int timestepIndex = 0; // Next calculate PSDI for the future data foreach (KeyValuePair <int, AnnualClimate_Monthly[]> timeStep in Future_MonthlyData) //foreach (KeyValuePair<int, IClimateRecord[,]> timeStep in future_allData) { //if (timeStep.Key < minimumTime) // minimumTime = timeStep.Key; //if (timestepIndex > numberOftimeSteps) // break; //Climate.ModelCore.UI.WriteLine(" Calculating Weather for FUTURE Year = {0}.", timeStep.Key); AnnualClimate_Monthly annualClimateMonthly = new AnnualClimate_Monthly(ecoregion, startYear + timeStep.Key, latitude, Climate.Phase.Future_Climate, timeStep.Key); Future_MonthlyData[startYear + timeStep.Key][ecoregion.Index] = annualClimateMonthly; Future_MonthlyData[startYear + timeStep.Key][ecoregion.Index].PDSI = PDSI_Calculator.CalculatePDSI(annualClimateMonthly, temperature_normals, availableWaterCapacity, latitude, UnitSystem.metrics, ecoregion); Climate.LandscapeAnnualPDSI[timestepIndex] += (Future_MonthlyData[startYear + timeStep.Key][ecoregion.Index].PDSI / Climate.ModelCore.Ecoregions.Count); //Climate.ModelCore.UI.WriteLine("Calculated PDSI for Ecoregion {0}, timestep {1}, PDSI Year {2}; PDSI={3:0.00}.", ecoregion.Name, timestepIndex, timeStep.Key, PDSI); timestepIndex++; } }