当前位置: 首页>>代码示例>>C#>>正文


C# Series.Subset方法代码示例

本文整理汇总了C#中Series.Subset方法的典型用法代码示例。如果您正苦于以下问题:C# Series.Subset方法的具体用法?C# Series.Subset怎么用?C# Series.Subset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Series的用法示例。


在下文中一共展示了Series.Subset方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Average

        /// <summary>
        /// Function that averages a series based on a defined Time-Interval
        /// </summary>
        /// <param name="s">Input Series</param>
        /// <param name="tInterval">Averaging Time-Interval</param>
        /// <returns></returns>
        public static Series Average(Series s, TimeInterval tInterval)
        {
            Series rval = s.Clone();
            if (s.Count == 0)
                return rval;

            // Define starting date of averaging process
            DateTime t = new DateTime(s[0].DateTime.Year, s[0].DateTime.Month, s[0].DateTime.Day,
                s[0].DateTime.Hour, 0, 0);

            // Find which averaging process to accomplish
            if (tInterval == TimeInterval.Daily)
            {
                // Define series time-interval
                rval.TimeInterval = TimeInterval.Daily;
                // Loop through the dates
                while (t < s[s.Count - 1].DateTime.Date)
                {
                    // Get the series subset based on the averaging time-interval
                    Series sTemp = s.Subset(t, t.AddDays(1));
                    // Average the values of the subset
                    DoAverage(rval, t, sTemp);
                    // Increment DateTime by averaging time-interval
                    t = t.AddDays(1);
                }
            }
            // Ditto on the other processes below
            else if (tInterval == TimeInterval.Monthly)
            {
                rval.TimeInterval = TimeInterval.Monthly;
                while (t < s[s.Count - 1].DateTime.Date)
                {
                    Series sTemp = s.Subset(t, t.AddMonths(1));
                    DoAverage(rval, t, sTemp);
                    t = t.AddMonths(1);
                }
            }
            else if (tInterval == TimeInterval.Hourly)
            {
                rval.TimeInterval = TimeInterval.Hourly;
                while (t < s.MaxDateTime)
                {

                    Series sTemp = Math.Subset(s, new DateRange(t, t.AddHours(1)), false);
                    DoAverage(rval, t, sTemp);
                    t = t.AddHours(1);

                }
            }
            else
            { throw new Exception("Time Interval " + tInterval.ToString() + " not supported!"); }

            return rval;
        }
开发者ID:usbr,项目名称:Pisces,代码行数:60,代码来源:Math.cs

示例2: InterpolateWithStyleMain

        /// <summary>
        /// Main Calculation for Interpolate with Style
        /// </summary>
        /// <param name="sReal"></param>
        /// <param name="sEst"></param>
        /// <param name="t1"></param>
        /// <param name="t2"></param>
        /// <returns></returns>
        private static Series InterpolateWithStyleMain(Series sReal, Series sEst, DateTime t1, DateTime t2)
        {
            // Get subsets of data for interpolation
            Series sRealTemp, sEstTemp;
            // Old workaround due to the difference in column names between Pisces and Series()
            //try
            //{ sRealTemp = sReal.Subset(string.Format("{0} >= '{1}' AND {2} <= '{3}'", "[datetime]", t1, "[datetime]", t2)); }
            //catch
            //{ sRealTemp = sReal.Subset(string.Format("{0} >= '{1}' AND {2} <= '{3}'", "[Date]", t1, "[Date]", t2)); }
            //try
            //{ sEstTemp = sEst.Subset(string.Format("{0} >= '{1}' AND {2} <= '{3}'", "[datetime]", t1, "[datetime]", t2)); }
            //catch
            //{ sEstTemp = sEst.Subset(string.Format("{0} >= '{1}' AND {2} <= '{3}'", "[Date]", t1, "[Date]", t2)); }
            sRealTemp = sReal.Subset(t1, t2);
            sEstTemp = sEst.Subset(t1, t2);

            // Get sum of values from data subset
            double sRealTempSum = sRealTemp.Values.Sum();
            double sEstTempSum = sEstTemp.Values.Sum();
            // Get source subset incremental ratios
            Series sRealTempRatio = sRealTemp / sRealTempSum;
            // Produce series with interpolated values based on source subset ratio
            Series sEstInterpQ = sRealTempRatio * sEstTempSum;
            // Merge interpolated series with original estimated series
            Series sEstInterpQOut = Reclamation.TimeSeries.Math.Merge(sEstInterpQ, sEst);

            return sEstInterpQOut;
        }
开发者ID:usbr,项目名称:Pisces,代码行数:36,代码来源:Math.Estimation.cs

示例3: Subset

        public static Series Subset(Series s, DateRange  dateRange, bool includeEndDateTimes=true)
        {
            string dateColumnName = s.Table.Columns[0].ColumnName;
            Series rval = s.Clone();
            var sql = "";
            if (includeEndDateTimes)
            {
                sql = "[" + dateColumnName + "] >= '" + dateRange.DateTime1 + "'"
                               + " and "
                               + "[" + dateColumnName + "] <= '" + dateRange.DateTime2 + "'"
                               + " ";

            }
            else
            {
                sql = "[" + dateColumnName + "] >= '" + dateRange.DateTime1 + "'"
                              + " and "
                              + "[" + dateColumnName + "] < '" + dateRange.DateTime2 + "'"
                              + " ";
            }

            rval = s.Subset(sql);

            return rval;
        }
开发者ID:usbr,项目名称:Pisces,代码行数:25,代码来源:Math.cs

示例4: SplineInterpUofI

        /// <summary>
        /// Finds month-end transitions where the difference is past a particular threshold and calls the 
        /// Spline Interpolation procedure
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        private static void SplineInterpUofI(Series s)
        {
            Series sInterp = new Series();
            double threshold = 0.10;

            // Loop to identify EOM dates that require interpolation
            // Threshold and ratio equation taken from UofI's disaggregation method procedure
            for (DateTime t = s.MinDateTime; t < s.MaxDateTime.AddMonths(-1); t = t.AddMonths(1))
            // Magic number so last month's entry doesn't get evaluated.
            {
                t = new DateTime(t.Year, t.Month, DateTime.DaysInMonth(t.Year, t.Month));
                int eomIDX = s.IndexOf(t);
                double diffRatio = (s[eomIDX].Value - s[eomIDX + 1].Value) / s[eomIDX].Value;

                // Build series of interpolated data points
                if (System.Math.Abs(diffRatio) > threshold)
                {
                    Series sInterpTemp = s.Subset(t.AddDays(-15), t.AddDays(15));
                    sInterp = SplineCalc(sInterpTemp);
                    for (int i = 0; i < sInterp.Count; i++)
                    {
                        Point pt = sInterp[i];
                        s[pt.DateTime] = pt;
                    }
                }
            }
        }
开发者ID:usbr,项目名称:Pisces,代码行数:33,代码来源:Math.DissagregationUofI.cs

示例5: RMSEInterp

        /// <summary>
        /// Main Streamflow Disaggregation script
        /// Follows procedures laid out by UofI's A.Acharya and Dr.Ryu
        /// We programmed a monthly-to-daily-disaggregation method in 2012 initially 
        /// based on some research by University of Idaho academics; the paper that the 
        /// program is based can be found in the links below. We've since made several 
        /// modifications to the program mainly to make it more robust in the sense that 
        /// it handles more cases that would have resulted in errors and to 
        /// make the mass-balancing more appropriate. 
        ///
        /// Published Journal Article - http://ascelibrary.org/doi/abs/10.1061/(ASCE)HE.1943-5584.0000818
        ///Article Manuscript - http://water.cals.uidaho.edu/publications/SimpleDisaggregation_Acharya_2013.pdf
        /// </summary>
        /// <param name="daily">daily series (cfs)</param>
        /// <param name="monthly">monthly series (cfs or acre-feet)</param>
        /// <returns></returns>
        public static Series RMSEInterp(Series daily, Series monthly)
        {
            // Generates the monthly totals for the RMS calculations in cu.ft/month
            Series SSmonthTot = MonthSum(MonthlyAverage(daily));
            Series TSmonthTot = MonthSum(ConvertAcreFeetToCfs(monthly));

            // Builds a Series to keep track of the corresponding year with the minimum RMSe
            Series TSrms = RMSEGenerateMatchList(SSmonthTot, TSmonthTot);

            // New series for the estimated daily value
            Series TSdaily = new Series();

            // Loop to calculate the daily estimate
            for (int i = 0; i < TSrms.Count; i++)
            {
                int targetYear = Convert.ToInt16(TSrms[i].Value);
                int sourceYear = TSrms[i].DateTime.Year;

                // Leap Years are fun! Catch leap/non-leap year mismatches.
                // If the target is a leap year, this leaves 2-29 empty
                DateTime tLookup;
                if (TSrms[i].DateTime.Month == 2 && (DateTime.IsLeapYear(targetYear) ^ DateTime.IsLeapYear(sourceYear)))
                    tLookup = new DateTime(targetYear, TSrms[i].DateTime.Month, 28);
                else
                    tLookup = new DateTime(targetYear, TSrms[i].DateTime.Month, TSrms[i].DateTime.Day);

                // Calculates daily ratio of the monthly total for the SS
                double SSmatchMonthly = SSmonthTot.Lookup(tLookup);
                DateTime tStart = new DateTime(targetYear, TSrms[i].DateTime.Month, 1);
                Series SSmatchDaily = TimeSeries.Math.FillMissingWithZero(daily.Subset(tStart,tLookup));
                Series SSratioTemp = SSmatchDaily / SSmatchMonthly;

                // Catches NaN values if the SS monthly data is zero and leap day mass balance problems
                Series SSratio = new Series();
                double leapDayRatio = 0.0;
                for (int x = 0; x < SSratioTemp.Count; x++)
                {
                    Point ptX = SSratioTemp[x];
                    if (ptX.Value.ToString() == "NaN" || SSmatchMonthly == 0.0)
                    {
                        SSratio.Add(ptX.DateTime, 0.0);
                        continue;
                    }
                    // Catches TS leap years and ensures that mass balance is preserved with Feb-29th
                    if (DateTime.IsLeapYear(sourceYear) && !DateTime.IsLeapYear(targetYear) &&
                        SSratio.MinDateTime.Month == 2)
                    {
                        leapDayRatio = leapDayRatio + (ptX.Value / 28.0);
                        SSratio.Add(ptX.DateTime, ptX.Value - (ptX.Value / 28.0));
                    }
                    else if (!DateTime.IsLeapYear(sourceYear) && DateTime.IsLeapYear(targetYear) &&
                        SSratio.MinDateTime.Month == 2)
                    {
                        leapDayRatio = daily[new DateTime(SSratioTemp.MaxDateTime.Year, 2, 29)].Value / SSmatchMonthly;
                        SSratio.Add(ptX.DateTime, ptX.Value + (leapDayRatio / 27.0));
                    }
                    else
                    {
                        SSratio.Add(ptX);
                    }
                }

                // Calculates the estimated daily for the TS given the monthly total and SS ratio
                TSdaily = RMSEGenerateDaily(TSdaily, TSmonthTot.Lookup(TSrms[i].DateTime.Date), SSmatchDaily, SSratio,
                    targetYear, sourceYear, leapDayRatio);
            }

            return TSdaily;
        }
开发者ID:usbr,项目名称:Pisces,代码行数:85,代码来源:Math.DissagregationUofI.cs


注:本文中的Series.Subset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。