/// <summary> /// Writes the names of the models that are included in each cluster /// </summary> public void writeProjectionSummaries() { List <string> toWrite; if (outputFolderName == "") { return; } setNamePadding(); string[] names = processor.getModelNames(); for (int range = 0; range < dates.Count - 1; range++) { toWrite = new List <string>(); for (int i = 0; i < ensembles.Length; i++) { string currentLine = ""; ProcessData.Ensemble ensemble = ensembles[i]; currentLine += ensemble.ensembleName + "\r\n"; if (names == null) //print out column numbers { int rank = 1; currentLine += string.Format("{0,-25}", "Column") + "\tChange in Precip(%)\tChange in Temp(degC)\tRank\r\n"; for (int index = 0; index < ensemble.columnNumbers.GetLength(1); index++) { currentLine += "\t" + (ensemble.columnNumbers[range, index] + 1) + "\t\t\t" + ensemble.points[range, index].X.ToString("F6") + "\t\t\t" + ensemble.points[range, index].Y.ToString("F6") + "\t\t\t" + (rank++) + "\r\n"; } } else //print out GCM names; { int rank = 1; currentLine += string.Format("{0,-25}", "GCM") + "\tChange in Precip(%)\tChange in Temp(degC)\tRank\r\n"; for (int index = 0; index < ensemble.columnNumbers.GetLength(1); index++) { int adjustedRange = range; if (!ensemble.statistical)//if the ensemble is custom, it will only have set of column numbers { adjustedRange = 0; } currentLine += string.Format("{0,-25}", names[ensemble.columnNumbers[adjustedRange, index] - 2]) + "\t\t" + ensemble.points[range, index].X.ToString("F6") + "\t\t\t" + ensemble.points[range, index].Y.ToString("F6") + "\t\t\t" + (rank++) + "\r\n"; } } toWrite.Add(currentLine); } File.WriteAllLines(outputFolderName + @"\Projections_Summary_" + dates[range + 1].ToStringWithUnderscores() + ".txt", toWrite); } }
/// <summary> /// Writes the hybrid delta ensemble data to file /// </summary> public void writeHybridDeltaEnsemble() //ensemble.hybriddeltaensemble is null for some reason { List <string> lines; if (outputFolderName == "") { return; } setNamePadding(); for (int range = 0; range < dates.Count - 1; range++) { lines = new List <string>(); lines.Add(string.Format("{0,-" + namePadding + "}", "ensemble") + "\tqtl \tJan \tFeb \tMar \tApr \tMay \tJun \tJul \tAug \tSep \tOct \tNov \tDec"); //go through each percentile from .02 to .98 for (int i = 0; i < 49; i++) { double percentile = i * .02 + .02; for (int j = 0; j < ensembles.Count(); j++) { //hybridDeltaEnsemble = 12 months * 49 quantiles .02 - .98 * precip, temp * future periods ProcessData.Ensemble ensemble = ensembles[j]; for (int temp = 0; temp < 2; temp++) { string name; if (temp == 0) { name = ensemble.ensembleName + "_dP"; } else { name = ensemble.ensembleName + "_dT"; } lines.Add(string.Format("{0,-" + namePadding + "}", name) + "\t" + percentile.ToString("F2") + "\t" + ensemble.hybridDeltaEnsemble[0, i, temp, range].ToString("F2") + "\t" + ensemble.hybridDeltaEnsemble[1, i, temp, range].ToString("F2") + "\t" + ensemble.hybridDeltaEnsemble[2, i, temp, range].ToString("F2") + "\t" + ensemble.hybridDeltaEnsemble[3, i, temp, range].ToString("F2") + "\t" + ensemble.hybridDeltaEnsemble[4, i, temp, range].ToString("F2") + "\t" + ensemble.hybridDeltaEnsemble[5, i, temp, range].ToString("F2") + "\t" + ensemble.hybridDeltaEnsemble[6, i, temp, range].ToString("F2") + "\t" + ensemble.hybridDeltaEnsemble[7, i, temp, range].ToString("F2") + "\t" + ensemble.hybridDeltaEnsemble[8, i, temp, range].ToString("F2") + "\t" + ensemble.hybridDeltaEnsemble[9, i, temp, range].ToString("F2") + "\t" + ensemble.hybridDeltaEnsemble[10, i, temp, range].ToString("F2") + "\t" + ensemble.hybridDeltaEnsemble[11, i, temp, range].ToString("F2")); } } } File.WriteAllLines(outputFolderName + @"\Monthly_HDePT_Factors_" + dates[range + 1].ToStringWithUnderscores() + ".txt", lines); } }
/// <summary> /// Writes the delta ensemble file which contains the average change factors for each month and ensemble /// </summary> public void writeDeltaEnsemble() { List <string> lines; if (outputFolderName == "") { return; } setNamePadding(); //write deltaEnsembles to file for (int range = 0; range < dates.Count - 1; range++) { lines = new List <string>(); lines.Add(string.Format("{0,-" + namePadding + "}", " ") + "\tJan \tFeb \tMar \tApr \tMay \tJun \tJul \tAug \tSep \tOct \tNov \tDec"); for (int i = 0; i < ensembles.Length; i++) { ProcessData.Ensemble ensemble = ensembles[i]; //deltaEnsemble: 12 months * precip, temp * future periods for (int temp = 0; temp < 2; temp++) { string name; if (temp == 0) { name = ensemble.ensembleName + "_dP"; } else { name = ensemble.ensembleName + "_dT"; } lines.Add(string.Format("{0,-" + namePadding + "}", name) + "\t" + ensemble.deltaEnsemble[0, temp, range].ToString("F2") + "\t" + ensemble.deltaEnsemble[1, temp, range].ToString("F2") + "\t" + ensemble.deltaEnsemble[2, temp, range].ToString("F2") + "\t" + ensemble.deltaEnsemble[3, temp, range].ToString("F2") + "\t" + ensemble.deltaEnsemble[4, temp, range].ToString("F2") + "\t" + ensemble.deltaEnsemble[5, temp, range].ToString("F2") + "\t" + ensemble.deltaEnsemble[6, temp, range].ToString("F2") + "\t" + ensemble.deltaEnsemble[7, temp, range].ToString("F2") + "\t" + ensemble.deltaEnsemble[8, temp, range].ToString("F2") + "\t" + ensemble.deltaEnsemble[9, temp, range].ToString("F2") + "\t" + ensemble.deltaEnsemble[10, temp, range].ToString("F2") + "\t" + ensemble.deltaEnsemble[11, temp, range].ToString("F2")); } } File.WriteAllLines(outputFolderName + @"\Monthly_DePT_Factors_" + dates[range + 1].ToStringWithUnderscores() + ".txt", lines); } }
internal ProcessData.Ensemble[] createStandardEnsembles(float low, float mid, float high, int ensembleNumber) { var rval = new ProcessData.Ensemble[5]; ProcessData.Ensemble hd = new ProcessData.Ensemble("More Warming/Dry"); hd.statistical = true; hd.precipPercent = low; hd.tempPercent = high; hd.numberOfModels = ensembleNumber; rval[0] = hd; ProcessData.Ensemble hw = new ProcessData.Ensemble("More Warming/Wet"); hw.statistical = true; hw.precipPercent = high; hw.tempPercent = high; hw.numberOfModels = ensembleNumber; rval[1] = hw; ProcessData.Ensemble mi = new ProcessData.Ensemble("Median"); mi.statistical = true; mi.precipPercent = mid; mi.tempPercent = mid; mi.numberOfModels = ensembleNumber; rval[2] = mi; ProcessData.Ensemble wd = new ProcessData.Ensemble("Less Warming/Dry"); wd.statistical = true; wd.precipPercent = low; wd.tempPercent = low; wd.numberOfModels = ensembleNumber; rval[3] = wd; ProcessData.Ensemble ww = new ProcessData.Ensemble("Less Warming/Wet"); ww.statistical = true; ww.precipPercent = high; ww.tempPercent = low; ww.numberOfModels = ensembleNumber; rval[4] = ww; return(rval); }
private void addButton_Click(object sender, EventArgs e) { String ensembleName; //get name try { ensembleName = textBox1.Text; } catch (Exception) { MessageBox.Show("Please provide a name for this ensemble."); return; } if (radioButton3.Checked) // statistical ensemble { float precip, temp; int numModels; //get statistical data from form try { temp = float.Parse(textBox7.Text) / 100; precip = float.Parse(textBox8.Text) / 100; if (temp < 0 || temp > 1 || precip < 0 || precip > 1) { throw new Exception(); } } catch (Exception) { MessageBox.Show("Something is wrong with the percentiles you entered."); return; } try { numModels = int.Parse(textBox2.Text); if (numModels < 1) { throw new Exception(); } } catch (Exception) { MessageBox.Show("Something is wrong with the number of models per ensemble you entered."); return; } //create new ensemble ProcessData.Ensemble ensemble = new ProcessData.Ensemble(ensembleName); ensemble.statistical = true; ensemble.tempPercent = temp; ensemble.precipPercent = precip; ensemble.numberOfModels = numModels; //add ensemble to custom list customEnsembles.Add(ensemble); } else //custom ensemble { if (modelList.Count == 0) { MessageBox.Show("At least one GCM is required to make an ensemble."); return; } //create new ensemble ProcessData.Ensemble ensemble = new ProcessData.Ensemble(ensembleName); ensemble.statistical = false; ensemble.numberOfModels = modelList.Count; int[,] columnNumbers = new int[1, modelList.Count]; for (int i = 0; i < modelList.Count; i++) { columnNumbers[0, i] = modelList[i].Key + 2; } ensemble.columnNumbers = columnNumbers; // clear list clearCustomEnsemble(); //add ensemble to custom list customEnsembles.Add(ensemble); } //update gui textBox1.Text = ""; updateEnsembleListBox(); updateGraph(); }
public void drawGraph(ZedGraphControl zgc, int period) { if (zgc == null) { zgc = zedGraphControl1; } periodToShow = period; colorIndex = 0; symbolIndex = 0; RectangleF rect = new RectangleF(0, 0, zgc.Size.Width, zgc.Size.Height); String xAxisLabel = "Precipitation Change, %"; String yAxisLabel = "Temperature Change, degC"; dates = datesForm.DateRange; String title = "Changes in Mean Annual Temp & Precip\nComparing " + dates[0].ToString() + " to " + dates[periodToShow + 1].ToString(); zgc.GraphPane = new GraphPane(rect, title, xAxisLabel, yAxisLabel); zgc.GraphPane.Legend.Position = LegendPos.InsideBotRight; zgc.GraphPane.Legend.FontSpec.Size = 8f; // add ensemble points ProcessData.Ensemble[] ensembles = processor.getEnsembles(); for (int i = 0; i < ensembles.Length; i++) { ProcessData.Ensemble ensemble = ensembles[i]; ZedGraph.LineItem curve = zgc.GraphPane.AddCurve(ensemble.ensembleName, ensemble.getEnsemblePoints(periodToShow), getColor(), getSymbol()); curve.Line.IsVisible = false; curve.Symbol.Border.IsVisible = true; curve.Symbol.Fill.IsVisible = false; curve.Symbol.Size = 6; } // add all points pointList = processor.getPoints(); allPointsCurve = zgc.GraphPane.AddCurve(pointList[periodToShow].Count + " GCMs", pointList[periodToShow], Color.Black, SymbolType.Circle); allPointsCurve.Line.IsVisible = false; allPointsCurve.Symbol.Border.IsVisible = false; allPointsCurve.Symbol.Fill.IsVisible = true; allPointsCurve.Symbol.Size = 2; allPointsCurve.Symbol.Fill.Type = FillType.Solid; //change axes to get new mins and maxs for drawing lines zgc.AxisChange(); for (int i = 0; i < ensembles.Length; i++) { ProcessData.Ensemble ensemble = ensembles[i]; if (ensemble.statistical) { //add precip line LineObj line1 = new LineObj(Color.Black, ensemble.center[periodToShow].X, zgc.GraphPane.YAxis.Scale.Min, ensemble.center[periodToShow].X, zgc.GraphPane.YAxis.Scale.Max); line1.Line.Width = 1f; zgc.GraphPane.GraphObjList.Add(line1); //add temp line LineObj line2 = new LineObj(Color.Black, zgc.GraphPane.XAxis.Scale.Min, ensemble.center[periodToShow].Y, zgc.GraphPane.XAxis.Scale.Max, ensemble.center[periodToShow].Y); line2.Line.Width = 1f; zgc.GraphPane.GraphObjList.Add(line2); } } modelNames = processor.getModelNames(); zgc.Refresh(); }
/// <summary> /// Writes the hybrid ensemble data to file (mean quantiles from historical and future used to compute hybridDeltaEnsemble) /// </summary> public void writeHybridEnsemble() { List <string> lines; if (outputFolderName == "") { return; } setNamePadding(); for (int range = 0; range < dates.Count - 1; range++) { lines = new List <string>(); lines.Add(string.Format("{0,-" + (namePadding + 7) + "}", "ensemble") + "\tqtl \tJan \tFeb \tMar \tApr \tMay \tJun \tJul \tAug \tSep \tOct \tNov \tDec"); for (int i = 0; i < 49; i++) { double percentile = (int)i * .02 + .02; for (int j = 0; j < ensembles.Count(); j++) { ProcessData.Ensemble ensemble = ensembles[j]; for (int temp = 0; temp < 2; temp++) { for (int hist = 0; hist < 2; hist++) { string name; if (temp == 0) { if (hist == 0) { name = ensemble.ensembleName + "_mean_hisP"; } else { name = ensemble.ensembleName + "_mean_futP"; } } else { if (hist == 0) { name = ensemble.ensembleName + "_mean_hisT"; } else { name = ensemble.ensembleName + "_mean_futT"; } } //12 months * 49 quantiles .02 - .98 * precip, temp * historical, future * future periods lines.Add(string.Format("{0,-" + (namePadding + 7) + "}", name) + "\t" + percentile.ToString("F2") + "\t" + ensemble.hybridEnsemble[0, i, temp, hist, range].ToString("F2") + "\t" + ensemble.hybridEnsemble[1, i, temp, hist, range].ToString("F2") + "\t" + ensemble.hybridEnsemble[2, i, temp, hist, range].ToString("F2") + "\t" + ensemble.hybridEnsemble[3, i, temp, hist, range].ToString("F2") + "\t" + ensemble.hybridEnsemble[4, i, temp, hist, range].ToString("F2") + "\t" + ensemble.hybridEnsemble[5, i, temp, hist, range].ToString("F2") + "\t" + ensemble.hybridEnsemble[6, i, temp, hist, range].ToString("F2") + "\t" + ensemble.hybridEnsemble[7, i, temp, hist, range].ToString("F2") + "\t" + ensemble.hybridEnsemble[8, i, temp, hist, range].ToString("F2") + "\t" + ensemble.hybridEnsemble[9, i, temp, hist, range].ToString("F2") + "\t" + ensemble.hybridEnsemble[10, i, temp, hist, range].ToString("F2") + "\t" + ensemble.hybridEnsemble[11, i, temp, hist, range].ToString("F2")); } } } } File.WriteAllLines(outputFolderName + @"\Monthly_HePT_Factors_" + dates[range + 1].ToStringWithUnderscores() + ".txt", lines); } }
//Creates a list of MonthlyData objects, one for each month, containing data about each month private void findMonthlyValues(ForcingFormat format) { double totalTemp = 0, avgTemp = 0, totalPrecip = 0; int numOfTimePeriodsThisMonth = 0, month = 0, year = 0, index = 0; double[,,] changeFactors;//temporary array to pass to MonthlyData object Dictionary <int, int>[] precipPercentiles, tempPercentiles; int precipPercentile, tempPercentile; List <KeyValuePair <int, double> >[] precipValues = new List <KeyValuePair <int, double> > [12]; //a list of totalPrecip values by month List <KeyValuePair <int, double> >[] tempValues = new List <KeyValuePair <int, double> > [12]; //a list of average temp values by month //initialize lists monthlyData = new List <MonthlyData>(); for (int i = 0; i < 12; i++) { precipValues[i] = new List <KeyValuePair <int, double> >(); tempValues[i] = new List <KeyValuePair <int, double> >(); } //creates a MonthlyData object for each month in forcingData foreach (KeyValuePair <DateTime, double[]> pair in forcingData) { if ((pair.Key.Day == 1 && (format == ForcingFormat.VIC || format == ForcingFormat.GSFLOW)) || (format == ForcingFormat.DHSVM && pair.Key.Day == 1 && pair.Key.Hour == 0)) //new month { if (numOfTimePeriodsThisMonth != 0) { //add new MonthlyData object to monthlyData avgTemp = totalTemp / numOfTimePeriodsThisMonth; monthlyData.Add(new MonthlyData(index, year, month, totalPrecip, avgTemp)); precipValues[month].Add(new KeyValuePair <int, double>(index, totalPrecip)); tempValues[month].Add(new KeyValuePair <int, double>(index, avgTemp)); index++; } //reset variables month = pair.Key.Month - 1; year = pair.Key.Year; numOfTimePeriodsThisMonth = 0; totalTemp = totalPrecip = 0; } switch (format) { case ForcingFormat.VIC: //value = Precip, MaxTemp, MinTemp, Wind, AvgTemp totalPrecip += pair.Value[0]; totalTemp += pair.Value[4]; break; case ForcingFormat.DHSVM: //value = temp, ?, ?, ?, ?, precip, ?, ? totalPrecip += pair.Value[5]; totalTemp += pair.Value[0]; break; case ForcingFormat.GSFLOW: //values = precip, tmax, tmin, tavg totalPrecip += pair.Value[0]; totalTemp += pair.Value[3]; break; default: throw new InvalidEnumArgumentException(); } numOfTimePeriodsThisMonth++; } //add last MonthlyData object to monthlyData avgTemp = totalTemp / numOfTimePeriodsThisMonth; monthlyData.Add(new MonthlyData(index, year, month, totalPrecip, avgTemp)); precipValues[month].Add(new KeyValuePair <int, double>(index, totalPrecip)); tempValues[month].Add(new KeyValuePair <int, double>(index, avgTemp)); //find percentiles precipPercentiles = getPercentiles(precipValues); tempPercentiles = getPercentiles(tempValues); //get data from ProcessData instance ensembles = processor.getEnsembles(); setNamePadding(); //add percentiles change factors to each monthlyData object for (int range = 0; range < dates.Count - 1; range++) { foreach (MonthlyData md in monthlyData) { if (md.changeFactors == null) { changeFactors = new double[dates.Count - 1, ensembles.Length, 2];//ensembles * precip, temp } else { changeFactors = md.changeFactors; } precipPercentile = precipPercentiles[md.month][md.index]; tempPercentile = tempPercentiles[md.month][md.index]; //hDE = 12 months * 49 quantiles .02 - .98 * precip, temp * future periods //fill changeFactors array for (int i = 0; i < ensembles.Length; i++) { ProcessData.Ensemble ensemble = ensembles[i]; //precip changeFactors[range, i, 0] = ensemble.hybridDeltaEnsemble[md.month, precipPercentile, 0, range]; //temp changeFactors[range, i, 1] = ensemble.hybridDeltaEnsemble[md.month, tempPercentile, 1, range]; } //fill in remaining fields in md md.precipPct = precipPercentile; md.tempPct = tempPercentile; md.changeFactors = changeFactors; } } }