示例#1
0
        /// <summary>Creates a long term weather file.</summary>
        /// <param name="fileName">Name of the file to create.</param>
        /// <param name="stationNumber">The SILO station number to use.</param>
        /// <param name="startDate">The start date of the weather file.</param>
        /// <param name="nowDate">The end date for using observed data.</param>
        /// <param name="observedData">The observed data to use. Can be null.</param>
        /// <returns>The list of file names that were created.</returns>
        public static string[] CreatePOAMA(string fileName, int stationNumber,
                                           DateTime startDate,
                                           DateTime nowDate,
                                           DataTable observedData)
        {
            // Get the SILO weather data from the start date
            Data weatherFileData = ExtractDataFromSILO(stationNumber, startDate, nowDate);

            // Overlay the observed data over the SILO data.
            OverlayData(observedData, weatherFileData.Table);

            // Get the POAMA data beginning from the last date of SILO data.
            Data poamaData = ExtractDataFromPOAMA(stationNumber, weatherFileData.LastDate);

            // Looks like a bug in POAMA where if we ask for date 2016-05-11, poama returns data for that
            // date in the first year only. Subsequent years the poama data starts on the 2016-05-12.
            // To get around this we ask for the 2016-05-10 and remove the first row. All years should
            // then be fine.
            poamaData.Table.Rows.RemoveAt(0);

            // Redate the POAMA data. For some reason the year is 100 years in the future e.g. 2116.
            RedateData(poamaData.Table, poamaData.FirstDate.AddYears(-100));
            if (weatherFileData.LastDate != poamaData.FirstDate.AddDays(-1))
            {
                throw new Exception("The end of the SILO data doesn't match the beginning of the POAMA data");
            }

            // copy the silo data to the front of the poama data.
            DataTableUtilities.InsertRowsAt(weatherFileData.Table, poamaData.Table, 0);

            // overlay the silo data on top of the poama data for all years.
            OverlayDataAllYears(weatherFileData.Table, poamaData.Table);

            List <string> filesCreated = new List <string>();

            for (DateTime date = poamaData.FirstDate; date < poamaData.LastDate; date = date.AddYears(1))
            {
                // Get a view of the data for this year up until the NaN data starts.
                DataView  yearlyView     = CreateView(poamaData.Table, date, date.AddYears(1).AddDays(-1));
                DateTime  startOfNaNDate = FindStartOfNaNData(yearlyView);
                DataTable yearlyGoodData = CreateView(poamaData.Table, date, startOfNaNDate.AddDays(-1)).ToTable();

                // Change the years to always be the first year of poama data.
                RedateData(yearlyGoodData, poamaData.FirstDate);

                // Write the file.
                string extension      = Path.GetExtension(fileName);
                string yearlyFileName = fileName.Replace(extension, date.Year + extension);
                WriteWeatherFile(yearlyGoodData, yearlyFileName, weatherFileData.Latitude, weatherFileData.Longitude, weatherFileData.TAV, weatherFileData.AMP);
                filesCreated.Add(yearlyFileName);
            }

            return(filesCreated.ToArray());
        }