public void WeatherTests_EnsureDataOverlayWorks() { DataTable observedData = new DataTable(); observedData.Columns.Add("Date", typeof(DateTime)); observedData.Columns.Add("Rain", typeof(double)); observedData.Columns.Add("Codes", typeof(string)); observedData.Rows.Add(new object[] { new DateTime(2016, 5, 3), 20.0, "O" }); observedData.Rows.Add(new object[] { new DateTime(2016, 5, 4), 30.0, "O" }); observedData.Rows.Add(new object[] { new DateTime(2016, 5, 5), 40.0, "O" }); observedData.Rows.Add(new object[] { new DateTime(2016, 5, 6), 0.0, "O" }); Weather.Data weatherFile = Weather.ExtractDataFromSILO(77008, new DateTime(2016, 5, 1), new DateTime(2016, 6, 1)); Weather.OverlayData(observedData, weatherFile.Table); Assert.AreEqual(weatherFile.Table.Rows[0]["codes"], "SSSS"); Assert.AreEqual(weatherFile.Table.Rows[1]["codes"], "SSSS"); Assert.AreEqual(weatherFile.Table.Rows[2]["codes"], "SSSO"); Assert.AreEqual(weatherFile.Table.Rows[3]["codes"], "SSSO"); Assert.AreEqual(weatherFile.Table.Rows[4]["codes"], "SSSO"); Assert.AreEqual(weatherFile.Table.Rows[5]["codes"], "SSSO"); Assert.AreEqual(weatherFile.Table.Rows[0]["rain"], 13.0f); // original SILO rainfall Assert.AreEqual(weatherFile.Table.Rows[1]["rain"], 0.0f); Assert.AreEqual(weatherFile.Table.Rows[2]["rain"], 20.0f); Assert.AreEqual(weatherFile.Table.Rows[3]["rain"], 30.0f); // original SILO rainfall was 1.3mm on this day. Assert.AreEqual(weatherFile.Table.Rows[4]["rain"], 40.0f); Assert.AreEqual(weatherFile.Table.Rows[5]["rain"], 0.0f); }
/// <summary>Creates the weather files for all simulations.</summary> /// <param name="simulations">The simulations.</param> /// <param name="workingFolder">The working folder to create the files in.</param> /// <param name="ausfarmNode"></param> private static void CreateWeatherFileForSimulation(AusFarmSpec simulation, string workingFolder) { // Write the .met file for the simulation DateTime earliestStartDate = DateTime.MaxValue; DateTime latestEndDate = DateTime.MinValue; DateTime nowDate = DateTime.MaxValue; DataTable observedData = null; int stationNumber = 0; stationNumber = simulation.StationNumber; if (simulation.StartDate < earliestStartDate) { earliestStartDate = simulation.StartDate; } if (simulation.EndDate > latestEndDate) { latestEndDate = simulation.EndDate; } // Create the weather files. FMetFile = Path.Combine(workingFolder, stationNumber.ToString()) + ".met"; // Create a weather file. Weather.Data weatherFile = Weather.ExtractDataFromSILO(stationNumber, earliestStartDate, nowDate); Weather.OverlayData(observedData, weatherFile.Table); Weather.WriteWeatherFile(weatherFile.Table, FMetFile, weatherFile.Latitude, weatherFile.Longitude, weatherFile.TAV, weatherFile.AMP); // ensure that the run period doesn't exceed the data retrieved if (simulation.EndDate > weatherFile.LastDate) { simulation.EndDate = weatherFile.LastDate; } // calculate the rain deciles from April from the year of the start of the simulation. // this could be improved to use more than a few decades of weather. simulation.RainDeciles = new double[12, 10]; // 12 months, 10 deciles DateTime accumStartDate = new DateTime(simulation.StartDate.Year, 4, 1); if (simulation.StartDate > accumStartDate) // ensure that the start date for decile accum exists in the weather { accumStartDate.AddYears(1); } simulation.RainDeciles = Weather.CalculateRainDeciles(stationNumber, accumStartDate, simulation.EndDate); }
public void WeatherTests_EnsureSILOFetchWorks() { DataTable observedData = new DataTable(); observedData.Columns.Add("Date", typeof(DateTime)); observedData.Columns.Add("Rain", typeof(double)); observedData.Rows.Add(new object[] { new DateTime(2016, 4, 1), 0.0 }); observedData.Rows.Add(new object[] { new DateTime(2016, 4, 2), 0.0 }); observedData.Rows.Add(new object[] { new DateTime(2016, 4, 3), 20.0 }); observedData.Rows.Add(new object[] { new DateTime(2016, 4, 4), 30.0 }); observedData.Rows.Add(new object[] { new DateTime(2016, 4, 5), 40.0 }); observedData.Rows.Add(new object[] { new DateTime(2016, 4, 6), 0.0 }); observedData.Rows.Add(new object[] { new DateTime(2016, 4, 7), 0.0 }); observedData.Rows.Add(new object[] { new DateTime(2016, 4, 8), 0.0 }); observedData.Rows.Add(new object[] { new DateTime(2016, 4, 9), 0.0 }); observedData.Rows.Add(new object[] { new DateTime(2016, 4, 10), 0.0 }); observedData.Rows.Add(new object[] { new DateTime(2016, 4, 20), 0.0 }); observedData.Rows.Add(new object[] { new DateTime(2016, 4, 21), 0.0 }); Weather.Data weatherFile = Weather.ExtractDataFromSILO(77008, new DateTime(2016, 4, 1), new DateTime(2016, 5, 1)); Assert.AreEqual(weatherFile.FirstDate, new DateTime(2016, 4, 1)); Assert.AreEqual(weatherFile.LastDate, new DateTime(2016, 5, 1)); Assert.AreEqual(weatherFile.AMP, 2.77); Assert.AreEqual(weatherFile.Latitude, -35.92); Assert.AreEqual(weatherFile.Longitude, 142.85); Assert.AreEqual(weatherFile.TAV, 16.13); Assert.AreEqual(weatherFile.Table.Columns[0].ColumnName, "Date"); Assert.AreEqual(weatherFile.Table.Columns[1].ColumnName, "radn"); Assert.AreEqual(weatherFile.Table.Columns[2].ColumnName, "maxt");; Assert.AreEqual(weatherFile.Table.Columns[3].ColumnName, "mint"); Assert.AreEqual(weatherFile.Table.Columns[4].ColumnName, "rain"); Assert.AreEqual(weatherFile.Table.Columns[5].ColumnName, "codes"); Assert.AreEqual(weatherFile.Table.Rows.Count, 31); Assert.AreEqual(weatherFile.Table.Rows[0]["codes"], "SSSS"); }