Пример #1
0
        /// <summary>気象レコードを線形補間する</summary>
        /// <param name="wRecord1">気象レコード1</param>
        /// <param name="wRecord2">気象レコード2</param>
        /// <param name="dTime">補間する時刻</param>
        /// <returns>補間した気象レコード</returns>
        private WeatherRecord interpolateWRecord(WeatherRecord wRecord1, WeatherRecord wRecord2, DateTime dTime)
        {
            //両端と一致する場合は複製を返す
            if (wRecord1.DataDTime == dTime) return (WeatherRecord)wRecord1.Clone();
            else if (wRecord2.DataDTime == dTime)return (WeatherRecord)wRecord2.Clone();

            //その他の場合は補間処理
            WeatherRecord wRecord = new WeatherRecord();
            double ts1 = (dTime - wRecord1.DataDTime).TotalHours;
            double ts2 = (wRecord2.DataDTime - dTime).TotalHours;
            ts1 = ts1 / (ts1 + ts2);
            ts2 = 1.0 - ts1;
            foreach (WeatherRecord.RecordType rt in Enum.GetValues(typeof(WeatherRecord.RecordType)))
            {
                WeatherData wd1 = wRecord1.GetData(rt);
                WeatherData wd2 = wRecord2.GetData(rt);
                WeatherData wd = new WeatherData();

                //いずれかが欠測の場合は欠測
                if (wd1.Source == WeatherData.DataSource.MissingValue ||
                    wd2.Source == WeatherData.DataSource.MissingValue) wd.Source = WeatherData.DataSource.MissingValue;
                //その他の場合は推定(補間)値 //単純な線形補間では問題がある要素もある。直せ!
                else wd.Source = WeatherData.DataSource.PredictedValue;
                wd.Value = wd1.Value * ts1 + wd2.Value * ts2;

                wRecord.SetData(rt, wd);
            }

            return wRecord;
        }
Пример #2
0
 /// <summary>気象データを設定する</summary>
 /// <param name="rType">気象データの種類</param>
 /// <param name="wData">気象データ</param>
 public void SetData(RecordType rType, WeatherData wData)
 {
     if (data.ContainsKey(rType)) data[rType] = (WeatherData)wData.Clone();
     else
     {
         data.Add(rType, (WeatherData)wData.Clone());
     }
 }