コード例 #1
0
ファイル: DateRange.cs プロジェクト: usbr/Pisces
        public DateRange(MonthDayRange range, int year, int beginningMonth)
        {
            this.beginningMonth = beginningMonth;
            if (!range.ValidBeginningMonth(beginningMonth))
            {
                throw new ArgumentOutOfRangeException(
                    "Please check the date range you entered. It needs to be consistent\n"
                    +"with the type of year: i.e. 'water year', 'calendar year', or custom year\n"
                    +"your range is "
                    +range.ToString()+ " and your beginning month is "+beginningMonth);
            }

            YearRange yearRng = new YearRange(year, beginningMonth);

            int idx = yearRng.Months.IndexOf(range.Month1);
            if (idx < 0)
            {
                throw new Exception();
            }
            date1 = LeapSafeDate(yearRng.Years[idx], range.Month1, range.Day1);

            idx = yearRng.Months.IndexOf(range.Month2);
            if (idx < 0)
            {
                throw new Exception();
            }
            date2 = LeapSafeDate(yearRng.Years[idx], range.Month2, range.Day2);
            date2 =date2.AddHours(23).AddMinutes(59).AddSeconds(59);

            if (date2 < date1)
            {
                throw new ArgumentOutOfRangeException("The range " + range.ToString() +
                     " is not valid ");
            }
        }
コード例 #2
0
ファイル: TestMonthDayRange.cs プロジェクト: usbr/Pisces
        public void LeapYear()
        {
            MonthDayRange dr = new MonthDayRange(1, 1, 2, 29);
            DateTime d = new DateTime(2000,2,29);
            Assert.IsTrue(dr.Contains(d),"leap year failed");

            d = new DateTime(2001, 3, 1);
            Assert.IsFalse(dr.Contains(d) );
        }
コード例 #3
0
ファイル: TestMonthDayRange.cs プロジェクト: usbr/Pisces
        public void CountPointsInRange()
        {
            MonthDayRange range = new MonthDayRange(1, 1, 2, 29);
            DateRange dr = new DateRange(range, 2000, 1);

            Assert.AreEqual(dr.Count, 60);

            dr = new DateRange(range, 2001, 1);

            Assert.AreEqual(dr.Count, 59);
        }
コード例 #4
0
ファイル: TestMonthDayRange.cs プロジェクト: usbr/Pisces
        public void FullYear()
        {
            // this range includes full year by wrap-around
            MonthDayRange dr = new MonthDayRange(6, 15, 6, 14);

            Series s = TestData.SouthForkBoise;
            Console.WriteLine(s.Count);
            for (int i = 0; i < s.Count; i++)
            {
                Assert.IsTrue(dr.Contains(s[i].DateTime));
            }
        }
コード例 #5
0
ファイル: TestMonthDayRange.cs プロジェクト: usbr/Pisces
        public void Testing()
        {
            MonthDayRange dr = new MonthDayRange(6, 15, 6, 23);

            DateTime d = new DateTime(2006,1,30);
            Assert.IsFalse(dr.Contains(d));
            d = new DateTime(2005, 6, 15);
            Assert.IsTrue(dr.Contains(d));

            d = new DateTime(2005, 6, 23);
            Assert.IsTrue(dr.Contains(d));

            d = new DateTime(2005, 6, 30);
            Assert.IsFalse(dr.Contains(d));

            d = new DateTime(2005, 7, 1);
            Assert.IsFalse(dr.Contains(d));
        }
コード例 #6
0
        private void ReadQUAverage()
        {
            var qua = AverageSeries30Year();
            // we want january --> september (remove other months)..
            MonthDayRange r = new MonthDayRange(1, 1, 9, 30);

            quAverage = Math.Subset(qua, r);
            quSumJuly = quAverage.Clone();

            for (int i = 0; i < 7; i++)
            {
                double sum = 0.0;
                for (int j = i; j < 7; j++) // sum through July
                {
                    sum += quAverage[j].Value;
                }
                var pt = quAverage[i];
                quSumJuly.Add(new DateTime(waterYear, pt.DateTime.Month, pt.DateTime.Day), sum);
            }
            quAverage = Reclamation.TimeSeries.Math.ShiftToYear(quAverage, waterYear);
        }
コード例 #7
0
ファイル: MaxStat.cs プロジェクト: usbr/HydrometTools
        private void buttonGo_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            Application.DoEvents();
            try
            {
                MonthDayRange range = monthDayRangePicker1.MonthDayRange;



                string cbtt  = multiWaterYearSelector1.cbtt;
                string pcode = multiWaterYearSelector1.pcode;

                //var s = Reclamation.TimeSeries.Math.HydrometDaily(cbtt, pcode);

                var          t1  = multiWaterYearSelector1.T1;
                var          t2  = multiWaterYearSelector1.T2;
                HydrometHost svr = HydrometInfoUtility.HydrometServerFromPreferences();

                var s = HydrometDailySeries.Read(cbtt, pcode, t1, t2, svr);

                var rvalMax = Reclamation.TimeSeries.Math.AnnualMax(s, range, range.Month1);
                var rvalMin = Reclamation.TimeSeries.Math.AnnualMin(s, range, range.Month1);

                rvalMax.Appearance.LegendText = cbtt.ToUpper() + " " + pcode.ToUpper() + " Maximum in Range";
                rvalMin.Appearance.LegendText = cbtt.ToUpper() + " " + pcode.ToUpper() + " Minimum in Range";

                var list = new SeriesList();

                list.Add(rvalMax);
                list.Add(rvalMin);

                view.SeriesList = list;
                view.Draw();
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }
コード例 #8
0
ファイル: SnowGG.cs プロジェクト: muguangyuze/HydrometTools
        private void buttonToggleMonths_Click(object sender, EventArgs e)
        {
            var startMonth    = this.monthRangePicker1.BeginningMonth;
            var selectedRange = this.monthRangePicker1.MonthDayRange;

            if (startMonth == 1)
            {
                this.monthRangePicker1.BeginningMonth = 10;
                this.buttonToggleMonths.Text          = "Use CY";
                selectedRange = new MonthDayRange(10, 1, 9, 30);
                cySelected    = false;
            }
            else
            {
                this.monthRangePicker1.BeginningMonth = 1;
                this.buttonToggleMonths.Text          = "Use WY";
                selectedRange = new MonthDayRange(1, 1, 12, 31);
                cySelected    = true;
            }
            this.monthRangePicker1.Update();
            this.monthRangePicker1.MonthDayRange = selectedRange;
        }
コード例 #9
0
ファイル: SnowGG.cs プロジェクト: woohn/Pisces
        private static SeriesList FilterBySelectedRange(MonthDayRange range, SeriesList wyList)
        {
            SeriesList list = new SeriesList();

            foreach (Series item in wyList)
            {
                //// bug fix: leap years shifted to year 2000
                ////          have extra data point in October of next year.
                ////          delete this.
                //if (item.Count > 0 && item[0].DateTime.Month == 10
                //    && item[item.Count - 1].DateTime.Month == 10
                //    && range.Month2 != 10)
                //{
                //    item.ReadOnly = false;
                //    item.RemoveAt(item.Count - 1);

                //}

                list.Add(Math.ShiftToYear(Math.Subset(item, range), 2000));
            }

            return(list);
        }
コード例 #10
0
        /*
         * CHECK > run
         *
         *
         *      MAX/MIN SUMMARY          PROCESS DATE: 18-JUL-06
         *
         * Station name        RIR                Begin and end year  1963-2006
         * Parameter code      QD                 Begin and end date  OCT  1-SEP 30
         * Option              MAX
         *
         * YEAR   DATE        MAXIMUM     DATE        MINIMUM  MISS
         *
         * 1963  FEB  3        700.00    AUG 30          6.10     0
         * 1964  MAY 15       1570.00    OCT  5         17.00     0
         * 1965  APR 24       1740.00    OCT  1         39.00     0
         * 1966  APR 18        628.00    AUG 12         10.00     0
         * 1967  MAY 11       1090.00    AUG 28         17.00     0
         * 1968  MAY  3        814.00    NOV 28         21.00     0
         * 1969  APR 25       2300.00    NOV 27         27.00     0
         * 1970  MAY 19       1820.00    DEC  6         23.00     0
         * 1971  MAY  4       2660.00    JAN  7         24.00     0
         * 1972  MAY  9       1510.00    JAN  4         44.00     0
         * 1973  MAY  6       1320.00    AUG 31         36.00     0
         * 1974  APR 26       2170.00    AUG 12          1.20     0
         * 1975  MAY 20       2290.00    MAY  7         23.00     0
         * 1976  MAY  8       1520.00    JAN  6          0.27     0
         * 1977  OCT 28        310.00    FEB 22          8.70     0
         * 1978  AUG  3        206.00    NOV 30          4.50     0
         * 1979  SEP 19        396.00    JAN  9          0.10     0
         * 1980  JUN  4        415.00    JAN  1          0.00     0
         * 1981  OCT 10        503.00    DEC 10          0.73     3
         * 1982  MAY 20       1284.11    FEB 24          0.00     0
         * 1983  MAY 27       1320.13    DEC 30          0.00     0
         * 1984  MAY 22       1720.05    FEB 16          0.00     0
         * 1985  APR 19        729.47    MAR 31          0.00     1
         * 1986  MAY  7       1230.00    NOV 22          0.00     0
         * 1987  OCT 11        592.00    DEC 11          0.00     0
         * 1988  SEP 23        847.00    NOV 17          0.00     0
         * 1989  SEP 23        871.00    NOV  2          0.00     0
         * 1990  OCT  1        807.00    NOV  2          0.00     0
         * 1991  SEP 24        571.00    NOV 23          0.00     0
         * 1992  OCT  5        872.00    NOV  1          0.00     0
         * 1993  SEP 29        773.00    NOV  3          0.00     0
         * 1994  AUG  5        750.00    NOV  1          0.00     0
         * 1995  MAY 26        478.00    NOV  1          0.00     0
         * 1996  MAY 20        888.00    NOV  2          0.00     0
         * 1997  MAY  7       1750.00    NOV 22          0.00     0
         * 1998  MAY 24        745.00    NOV 13          0.00     0
         * 1999  MAY  6        885.00    NOV 14          0.00     0
         * 2000  OCT  6        414.00    NOV 30          0.00     0
         * 2001  AUG 18        429.00    NOV 16          0.00     0
         * 2002  AUG 29        455.00    OCT  1          0.00     0
         * 2003  AUG 26        439.00    OCT  1          0.00     0
         * 2004  AUG 31        348.20    OCT  1          0.00     0
         * 2005  SEP 21        202.02    OCT 13          0.00     0
         * 2006  MAY  2       1119.98    NOV 22          0.00    75
         *
         * Avg of 44 yrs       1010.95                    6.88
         * */

        /// <summary>
        /// Test annual sum and compare to check program
        /// VOLAF option for heise unregulated flow
        /// </summary>
        public void Vol_AF_HEII()
        {
            //heii_quAF.csv
            string     fn = TestData.DataPath + @"\heii_quAF.csv";
            TextSeries ts = new TextSeries(fn);

            ts.Read();

            Assert.AreEqual(28916, ts.Count, "file has changed");
            MonthDayRange r   = new MonthDayRange(3, 12, 5, 1);
            Series        sum = Math.AnnualSum(ts, r, 10);

            double[] expected = { 380313.47, 424559.03, 476518.66, 522272.94, 451835.38, 702204.13 };

//            sum.WriteToConsole();
            for (int yr = 2001; yr <= 2006; yr++)
            {
                DateTime t1    = new DateTime(yr, 1, 1);
                DateTime t2    = new DateTime(yr, 12, 31);
                Series   sYear = Math.Subset(sum, t1, t2);
                Assert.AreEqual(expected[yr - 2001], sYear[0].Value, 3);
            }
        }
コード例 #11
0
ファイル: PiscesSettings.cs プロジェクト: govtmirror/Pisces
        private void Defaults(TimeSeriesDatabase db)
        {
            //  m_siteCatalog = sc;
            m_db = db;
            //ScenarioNames = m_db.Scenario;

            m_thirtyYearAverage         = false;
            m_selectedSeries            = new Series[] { };
            m_analysisList              = new AnalysisCollection(this);
            m_multiYearMonthlyAggregate = true;
//            HasTraces = false;
            _monthDayRange          = new MonthDayRange(10, 1, 9, 30);
            this.StatisticalMethods = StatisticalMethods.None;
            WaterYearBeginningMonth = 10;// october
            WaterYears               = new int[] { 2001, 2002, 2003, 2004, 2005, 2006 };
            ExceedanceLevels         = new int[] { 10, 50, 90 };
            AlsoPlotYear             = false;
            AlsoPlotTrace            = false;
            PlotYear                 = 2006;
            PlotTrace                = "";
            PlotMin                  = false;
            PlotAvg                  = false;
            PlotMax                  = false;
            traceExceedanceAnalysis  = true;
            traceAggregationAnalysis = false;
            sumCYRadio               = true;
            sumWYRadio               = false;
            sumCustomRangeRadio      = false;
            PlotMax                  = false;
            PlotMin                  = false;
            PlotAvg                  = false;
            TimeWindow               = new TimeWindow();
            SelectedAnalysisType     = AnalysisType.TimeSeries;
            //SelectedScenarios = new string[] { };
            m_subtractFromBaseline = false;
        }
コード例 #12
0
ファイル: DateRange.cs プロジェクト: woohn/Pisces
        public DateRange(MonthDayRange range, int year, int beginningMonth)
        {
            this.beginningMonth = beginningMonth;
            if (!range.ValidBeginningMonth(beginningMonth))
            {
                throw new ArgumentOutOfRangeException(
                          "Please check the date range you entered. It needs to be consistent\n"
                          + "with the type of year: i.e. 'water year', 'calendar year', or custom year\n"
                          + "your range is "
                          + range.ToString() + " and your beginning month is " + beginningMonth);
            }

            YearRange yearRng = new YearRange(year, beginningMonth);

            int idx = yearRng.Months.IndexOf(range.Month1);

            if (idx < 0)
            {
                throw new Exception();
            }
            date1 = LeapSafeDate(yearRng.Years[idx], range.Month1, range.Day1);

            idx = yearRng.Months.IndexOf(range.Month2);
            if (idx < 0)
            {
                throw new Exception();
            }
            date2 = LeapSafeDate(yearRng.Years[idx], range.Month2, range.Day2);
            date2 = date2.AddHours(23).AddMinutes(59).AddSeconds(59);

            if (date2 < date1)
            {
                throw new ArgumentOutOfRangeException("The range " + range.ToString() +
                                                      " is not valid ");
            }
        }
コード例 #13
0
        public void AnnualSumFullWaterYear()
        {
            // using RIR QD from hydromet
            // compare to check program
            DataTable checkProgram = new DataTable();

            checkProgram.Columns.Add("Year", typeof(int));
            checkProgram.Columns.Add("Sum", typeof(double));
            checkProgram.Columns.Add("missing", typeof(int));
            checkProgram.Columns.Add("maxDate", typeof(DateTime));
            checkProgram.Columns.Add("max", typeof(double));
            checkProgram.Columns.Add("minDate", typeof(DateTime));
            checkProgram.Columns.Add("min", typeof(double));
//            Year	sum	missing	Maxdate	max	MinDate	min



            checkProgram.Rows.Add(1963, 32137.7, 0, DateTime.Parse("2/03/2006"), 700, DateTime.Parse("8/30/2006"), 6.1);
            checkProgram.Rows.Add(1964, 63817.0, 0, DateTime.Parse("5/15/2006"), 1570, DateTime.Parse("10/05/2006"), 17);
            checkProgram.Rows.Add(1965, 77084.0, 0, DateTime.Parse("4/24/2006"), 1740, DateTime.Parse("10/01/2006"), 39);
            checkProgram.Rows.Add(1966, 34863.0, 0, DateTime.Parse("4/18/2006"), 628, DateTime.Parse("8/12/2006"), 10);
            checkProgram.Rows.Add(1967, 39152.0, 0, DateTime.Parse("5/11/2006"), 1090, DateTime.Parse("8/28/2006"), 17);
            checkProgram.Rows.Add(1968, 41857.0, 0, DateTime.Parse("5/03/2006"), 814, DateTime.Parse("11/28/2006"), 21);
            checkProgram.Rows.Add(1969, 69656.0, 0, DateTime.Parse("4/25/2006"), 2300, DateTime.Parse("11/27/2006"), 27);
            checkProgram.Rows.Add(1970, 56442.0, 0, DateTime.Parse("5/19/2006"), 1820, DateTime.Parse("12/06/2006"), 23);
            checkProgram.Rows.Add(1971, 102310.0, 0, DateTime.Parse("5/04/2006"), 2660, DateTime.Parse("1/07/2006"), 24);
            checkProgram.Rows.Add(1972, 92143.0, 0, DateTime.Parse("5/09/2006"), 1510, DateTime.Parse("1/04/2006"), 44);
            checkProgram.Rows.Add(1973, 61642.0, 0, DateTime.Parse("5/06/2006"), 1320, DateTime.Parse("8/31/2006"), 36);
            checkProgram.Rows.Add(1974, 76544.5, 0, DateTime.Parse("4/26/2006"), 2170, DateTime.Parse("8/12/2006"), 1.2);
            checkProgram.Rows.Add(1975, 78953.0, 0, DateTime.Parse("5/20/2006"), 2290, DateTime.Parse("5/07/2006"), 23);
            checkProgram.Rows.Add(1976, 87413.1, 0, DateTime.Parse("5/08/2006"), 1520, DateTime.Parse("1/06/2006"), 0.27);
            checkProgram.Rows.Add(1977, 14110.9, 0, DateTime.Parse("10/28/2006"), 310, DateTime.Parse("2/22/2006"), 8.7);
            checkProgram.Rows.Add(1978, 22459.3, 0, DateTime.Parse("8/03/2006"), 206, DateTime.Parse("11/30/2006"), 4.5);
            checkProgram.Rows.Add(1979, 33610.8, 0, DateTime.Parse("9/19/2006"), 396, DateTime.Parse("1/09/2006"), 0.1);
            checkProgram.Rows.Add(1980, 37074.0, 0, DateTime.Parse("6/04/2006"), 415, DateTime.Parse("1/01/2006"), 0);
            checkProgram.Rows.Add(1981, -999.0, 3, DateTime.Parse("10/10/2006"), 503, DateTime.Parse("12/10/2006"), 0.73);
            checkProgram.Rows.Add(1982, 87835.9, 0, DateTime.Parse("5/20/2006"), 1284.11, DateTime.Parse("2/24/2006"), 0);
            checkProgram.Rows.Add(1983, 98116.5, 0, DateTime.Parse("5/27/2006"), 1320.13, DateTime.Parse("12/30/2006"), 0);
            checkProgram.Rows.Add(1984, 114705.8, 0, DateTime.Parse("5/22/2006"), 1720.05, DateTime.Parse("2/16/2006"), 0);
            checkProgram.Rows.Add(1985, -999.0, 1, DateTime.Parse("4/19/2006"), 729.47, DateTime.Parse("3/31/2006"), 0);
            checkProgram.Rows.Add(1986, 82530.0, 0, DateTime.Parse("5/07/2006"), 1230, DateTime.Parse("11/22/2006"), 0);
            checkProgram.Rows.Add(1987, 34610.1, 0, DateTime.Parse("10/11/2006"), 592, DateTime.Parse("12/11/2006"), 0);
            checkProgram.Rows.Add(1988, 20880.3, 0, DateTime.Parse("9/23/2006"), 847, DateTime.Parse("11/17/2006"), 0);
            checkProgram.Rows.Add(1989, 29083.8, 0, DateTime.Parse("9/23/2006"), 871, DateTime.Parse("11/02/2006"), 0);
            checkProgram.Rows.Add(1990, 20569.0, 0, DateTime.Parse("10/01/2006"), 807, DateTime.Parse("11/02/2006"), 0);
            checkProgram.Rows.Add(1991, 16571.4, 0, DateTime.Parse("9/24/2006"), 571, DateTime.Parse("11/23/2006"), 0);
            checkProgram.Rows.Add(1992, 26423.0, 0, DateTime.Parse("10/05/2006"), 872, DateTime.Parse("11/01/2006"), 0);
            checkProgram.Rows.Add(1993, 42308.4, 0, DateTime.Parse("9/29/2006"), 773, DateTime.Parse("11/03/2006"), 0);
            checkProgram.Rows.Add(1994, 35480.0, 0, DateTime.Parse("8/05/2006"), 750, DateTime.Parse("11/01/2006"), 0);
            checkProgram.Rows.Add(1995, 28779.0, 0, DateTime.Parse("5/26/2006"), 478, DateTime.Parse("11/01/2006"), 0);
            checkProgram.Rows.Add(1996, 51189.0, 0, DateTime.Parse("5/20/2006"), 888, DateTime.Parse("11/02/2006"), 0);
            checkProgram.Rows.Add(1997, 107622.1, 0, DateTime.Parse("5/07/2006"), 1750, DateTime.Parse("11/22/2006"), 0);
            checkProgram.Rows.Add(1998, 72138.0, 0, DateTime.Parse("5/24/2006"), 745, DateTime.Parse("11/13/2006"), 0);
            checkProgram.Rows.Add(1999, 64000.0, 0, DateTime.Parse("5/06/2006"), 885, DateTime.Parse("11/14/2006"), 0);
            checkProgram.Rows.Add(2000, 29604.0, 0, DateTime.Parse("10/06/2006"), 414, DateTime.Parse("11/30/2006"), 0);
            checkProgram.Rows.Add(2001, 28381.0, 0, DateTime.Parse("8/18/2006"), 429, DateTime.Parse("11/16/2006"), 0);
            checkProgram.Rows.Add(2002, 11817.0, 0, DateTime.Parse("8/29/2006"), 455, DateTime.Parse("10/01/2006"), 0);
            checkProgram.Rows.Add(2003, 14270.0, 0, DateTime.Parse("8/26/2006"), 439, DateTime.Parse("10/01/2006"), 0);
            checkProgram.Rows.Add(2004, 16328.2, 0, DateTime.Parse("8/31/2006"), 348.2, DateTime.Parse("10/01/2006"), 0);
            checkProgram.Rows.Add(2005, 11442.2, 0, DateTime.Parse("9/21/2006"), 202.02, DateTime.Parse("10/13/2006"), 0);
            checkProgram.Rows.Add(2006, -999.0, 91, DateTime.Parse("5/02/2006"), 1119.98, DateTime.Parse("11/22/2006"), 0);

            string     fn = TestData.DataPath + @"\rire hydromet daily.txt";
            TextSeries ts = new TextSeries(fn);

            ts.Read();

            Assert.AreEqual(16814, ts.Count, fn + " has been modified");

            MonthDayRange rr  = new MonthDayRange(10, 1, 9, 30);
            Series        sum = Math.AnnualSum(ts, rr, 10);
            Series        min = Math.AnnualMin(ts, rr, 10);
            Series        max = Math.AnnualMax(ts, rr, 10);

            Assert.AreEqual(sum.TimeInterval, TimeInterval.Yearly);
            Assert.AreEqual(min.TimeInterval, TimeInterval.Yearly);
            Assert.AreEqual(max.TimeInterval, TimeInterval.Yearly);

            Assert.IsTrue(sum.Count == min.Count && sum.Count == max.Count, "counts for sum,min,max are not the same");

            for (int i = 0; i < sum.Count; i++)
            {
                Point ptSum = sum[i];
                Point ptMin = min[i];
                Point ptMax = max[i];
                int   yr    = ptSum.DateTime.Year;

                DataRow[] rows = checkProgram.Select("Year=" + yr);
                if (rows.Length > 0)
                {
                    double dsum       = Convert.ToDouble(rows[0]["Sum"]);
                    double dmin       = Convert.ToDouble(rows[0]["min"]);
                    double dmax       = Convert.ToDouble(rows[0]["max"]);
                    int    numMissing = Convert.ToInt32(rows[0]["missing"]);

                    Console.WriteLine("yr = " + yr + " sum = '" + sum + "'");
                    if (dsum != Point.MissingValueFlag)
                    { // we compute sum anyway, but flag it.
                        Assert.AreEqual(dsum, ptSum.Value, 0.25, "sum different in year " + yr);
                    }
                    if (numMissing == 0)
                    {
                        Assert.AreEqual("", ptSum.Flag);
                    }
                    else
                    {
                        Assert.AreEqual(numMissing + " missing", ptSum.Flag);
                    }
                    Assert.AreEqual(dmin, ptMin.Value, 0.01, "min different in year " + yr);
                    Assert.AreEqual(dmax, ptMax.Value, 0.01, "max different in year " + yr);
                }
            }
            //min.WriteToConsole();
            //max.WriteToConsole();
        }
コード例 #14
0
ファイル: MonthDayRangePicker.cs プロジェクト: woohn/Pisces
 public MonthDayRangePicker()
 {
     InitializeComponent();
     range         = new MonthDayRange(10, 1, 9, 30);
     MonthDayRange = range;
 }
コード例 #15
0
        private void buttonSort_Click(object sender, EventArgs e)
        {
            var sName = comboBoxSelectedSeries.SelectedItem.ToString();

            if (!(sName == "Run Index"))
            {
                // Get selected series
                var sParentId = Convert.ToInt32(sName.Split('.')[2]);

                //var s = m_db.GetSeriesFromName(sName);
                var s = m_db.GetSeries(sParentId);
                s.Read();

                // Resolve sorting time window
                int year1 = s.MinDateTime.Year;
                int year2 = year1;
                if (radioButtonYear2.Checked)
                {
                    year2 = s.MinDateTime.Year + Convert.ToInt16(comboBoxOutYear.SelectedItem);
                }
                var mdRange = new MonthDayRange();
                var tRange  = new DateRange();
                if (radioButtonWY.Checked)
                {
                    mdRange = new MonthDayRange(10, 1, 9, 30);
                    tRange  = new DateRange(new DateTime(year1 - 1, mdRange.Month1, mdRange.Day1, 23, 59, 59),
                                            new DateTime(year2, mdRange.Month2, mdRange.Day2, 23, 59, 59));
                }
                else
                {
                    mdRange = new MonthDayRange(1, 1, 12, 31);
                    tRange  = new DateRange(new DateTime(year1, mdRange.Month1, mdRange.Day1, 23, 59, 59),
                                            new DateTime(year2, mdRange.Month2, mdRange.Day2, 23, 59, 59));
                }

                // Sort!
                for (int i = 0; i < scenarioTable.Rows.Count; i++)
                {
                    var ithScenario = s.CreateScenario(m_db.GetScenarios()[i]);
                    ithScenario.Read();

                    // Sort by custom sum
                    if (radioButtonSum.Checked)
                    {
                        Series sSum = new Series();
                        if (radioButtonCY.Checked || radioButtonWY.Checked)
                        {
                            sSum = Reclamation.TimeSeries.Math.AnnualSum(ithScenario.Subset(tRange.DateTime1, tRange.DateTime2),
                                                                         mdRange, mdRange.Month1);
                        }
                        scenarioTable.Rows[i]["SortMetric"] = Convert.ToInt32(Reclamation.TimeSeries.Math.Sum(sSum));
                    }
                    // Sort by a value
                    else if (radioButtonEOP.Checked)
                    {
                        scenarioTable.Rows[i]["SortMetric"] = ithScenario[tRange.DateTime2].Value;
                    }
                    // Others
                    else
                    {
                    }
                }
                scenarioTable.DefaultView.Sort            = "SortMetric DESC";
                dataGridView.Columns["SortOrder"].Visible = false;
            }
            else
            {
                scenarioTable.DefaultView.Sort = "SortOrder ASC";
            }
        }
コード例 #16
0
ファイル: ScenarioSelector.cs プロジェクト: usbr/Pisces
        private void buttonSort_Click(object sender, EventArgs e)
        {
            var sName = comboBoxSelectedSeries.SelectedItem.ToString();

            if (!(sName == "Run Index"))
            {
                // Get selected series
                var sParentId = Convert.ToInt32(sName.Split('.')[2]);

                //var s = m_db.GetSeriesFromName(sName);
                var s = m_db.GetSeries(sParentId);
                s.Read();

                // Resolve sorting time window
                int year1 = s.MinDateTime.Year;
                int year2 = year1;
                if (radioButtonYear2.Checked)
                { year2 = s.MinDateTime.Year + Convert.ToInt16(comboBoxOutYear.SelectedItem); }
                var mdRange = new MonthDayRange();
                var tRange = new DateRange();
                if (radioButtonWY.Checked)
                {
                    mdRange = new MonthDayRange(10, 1, 9, 30);
                    tRange = new DateRange(new DateTime(year1 - 1, mdRange.Month1, mdRange.Day1, 23, 59, 59),
                            new DateTime(year2, mdRange.Month2, mdRange.Day2, 23, 59, 59));
                }
                else
                {
                    mdRange = new MonthDayRange(1, 1, 12, 31);
                    tRange = new DateRange(new DateTime(year1, mdRange.Month1, mdRange.Day1, 23, 59, 59),
                            new DateTime(year2, mdRange.Month2, mdRange.Day2, 23, 59, 59));
                }

                // Sort!
                for (int i = 0; i < scenarioTable.Rows.Count; i++)
                {
                    var ithScenario = s.CreateScenario(m_db.GetScenarios()[i]);
                    ithScenario.Read();

                    // Sort by custom sum
                    if (radioButtonSum.Checked)
                    {
                        Series sSum = new Series();
                        if (radioButtonCY.Checked || radioButtonWY.Checked)
                        {
                            sSum = Reclamation.TimeSeries.Math.AnnualSum(ithScenario.Subset(tRange.DateTime1, tRange.DateTime2),
                                mdRange, mdRange.Month1);
                        }
                        scenarioTable.Rows[i]["SortMetric"] = Convert.ToInt32(Reclamation.TimeSeries.Math.Sum(sSum));
                    }
                    // Sort by a value
                    else if (radioButtonEOP.Checked)
                    { scenarioTable.Rows[i]["SortMetric"] = ithScenario[tRange.DateTime2].Value; }
                    // Others
                    else
                    { }
                }
                scenarioTable.DefaultView.Sort = "SortMetric DESC";
                dataGridView.Columns["SortOrder"].Visible = false;
            }
            else
            {
                scenarioTable.DefaultView.Sort = "SortOrder ASC";
            }
        }
コード例 #17
0
ファイル: TestYearRange.cs プロジェクト: usbr/Pisces
        public void Contains()
        {
            MonthDayRange mdr = new MonthDayRange(9,1,1,1);

            Assert.IsFalse(mdr.ValidBeginningMonth(1));
        }
コード例 #18
0
ファイル: TestMonthDayRange.cs プロジェクト: usbr/Pisces
 public void WaterAndLeapYear()
 {
     MonthDayRange dr = new MonthDayRange(10, 1, 9, 30);
     Assert.IsTrue(dr.Contains(new DateTime(1948,2,29)));
 }
コード例 #19
0
ファイル: TestAverageAggregate.cs プロジェクト: woohn/Pisces
        public void AprilAverageHrsi()
        {
            Series s = new TextSeries(Path.Combine(TestData.DataPath, "hrsiDailyModsim.csv"));

            s.Read();
            Assert.AreEqual(5418, s.Count, "reading file");

            double[] expected =
            {
                11133.3,
                8613.8,
                14385.9,
                10328.0,
                9689.5,
                12839.8,
                10611.5,
                13445.1,
                13052.1,
                10152.5,
                12536.3,
                7573.6,
                11985.8,
                10534.4,
                9936.5,
                12047.7,
                13240.2,
                10389.1,
                13993.5,
                10028.9,
                9384.8,
                12515.8,
                14188.1,
                7887.3,
                9998.4,
                13970.7,
                7438.4,
                10280.7,
                9050.2,
                10602.3,
                10659.1,
                7180.2,
                11815.6,
                14941.5,
                11761.7,
                10830.9,
                11825.9,
                11968.4,
                9618.7,
                9729.7,
                10152.0,
                14670.9,
                12391.5,
                16330.4,
                14960.8,
                14946.8,
                16466.4,
                10045.9,
                17344.9,
                10593.5,
                15629.1,
                10727.6,
                11894.0,
                11303.9,
                10471.4,
                10555.0,
                15624.5,
                13681.5,
                14531.3,
                10780.0,
                13061.1,
                11222.4,
                14146.1
            };

            MonthDayRange range = new MonthDayRange(4, 1, 4, 30);
            Series        s2    = Reclamation.TimeSeries.Math.AggregateAndSubset(StatisticalMethods.Average, s, range, 10);

            Assert.AreEqual(63, s2.Count);

            Assert.AreEqual(1944, s2[0].DateTime.Year);

            for (int i = 0; i < s2.Count; i++)
            {
                Assert.AreEqual(expected[i], s2[i].Value, 0.1);
            }
        }
コード例 #20
0
ファイル: TimeSeriesSettings.cs プロジェクト: usbr/Pisces
 private void Defaults()
 {
     DatabaseList = new TimeSeriesDatabaseList();
     FullPeriodOfRecord = false;
     Range = new MonthDayRange(10, 1, 9, 30);
     this.AggregateOption = AggregateType.None;
     WaterYearBeginningMonth = 10;// october
     WaterYears = new int[] { 2001, 2002, 2003, 2004, 2005, 2006 };
     ExceedanceLevels = new int[] { 10, 50, 90 };
     ExceedanceAlsoPlotYear = false;
     ExceedancePlotYear = 2006;
     ExceedancePlotMax = false;
     ExceedancePlotMin = false;
     AnalysisType = AnalysisType.TimeSeries;
 }
コード例 #21
0
ファイル: MonthRangePicker.cs プロジェクト: usbr/Pisces
 void dataGridView1_SelectionChanged(object sender, EventArgs e)
 {
     if (dataGridView1.ColumnCount < 12 || dataGridView1.RowCount <1)
         return;
     int idx1 = -1;
     int idx2 = -1;
     for (int i = 0; i < 12; i++)
     {
         if (dataGridView1[i, 0].Selected && idx1 == -1)
         {
             idx1 = i;
             idx2 = idx1;
         }
         else if( dataGridView1[i,0].Selected )
         {
             idx2 = i;
         }
     }
     if(idx1 >=0)
     m_monthDayRange = new MonthDayRange(this.months[idx1], 1,
                                         this.months[idx2], DateTime.DaysInMonth(2000, months[idx2]));
 }
コード例 #22
0
ファイル: TestMonthDayRange.cs プロジェクト: woohn/Pisces
        public void WaterAndLeapYear()
        {
            MonthDayRange dr = new MonthDayRange(10, 1, 9, 30);

            Assert.IsTrue(dr.Contains(new DateTime(1948, 2, 29)));
        }
コード例 #23
0
ファイル: TestMonthDayRange.cs プロジェクト: usbr/Pisces
        public void WaterYear()
        {
            MonthDayRange r = new MonthDayRange(10, 1, 9, 30);
            DateTime d = new DateTime(2000, 1, 1);

            Assert.IsTrue(r.Contains(d));
        }
コード例 #24
0
ファイル: TestDateRange.cs プロジェクト: govtmirror/Pisces
 public void BadRange()
 {
     MonthDayRange range = new MonthDayRange(12, 3, 2, 2);
     DateRange     dr    = new DateRange(range, 2001, 1);
 }
コード例 #25
0
        public void Contains()
        {
            MonthDayRange mdr = new MonthDayRange(9, 1, 1, 1);

            Assert.IsFalse(mdr.ValidBeginningMonth(1));
        }
コード例 #26
0
ファイル: TestMonthDayRange.cs プロジェクト: usbr/Pisces
        public void TimeSeries()
        {
            Series s = TestData.SouthForkBoise;
            MonthDayRange dr = new MonthDayRange(10, 1, 9, 30);
            MonthDayRange d2 = new MonthDayRange(11, 1, 1, 31);
            for (int i = 0; i < s.Count; i++)
            {
                DateTime t = s[i].DateTime;
                Assert.IsTrue(dr.Contains(t),t.ToString());

                bool inRange2 = (t.Month > 10 || t.Month == 1);
                Assert.AreEqual(inRange2, d2.Contains(t));
            }
        }
コード例 #27
0
ファイル: TestAverageAggregate.cs プロジェクト: usbr/Pisces
        public void AprilAverageHrsi()
        {
            Series s = new TextSeries(Path.Combine(TestData.DataPath, "hrsiDailyModsim.csv"));
            s.Read();
            Assert.AreEqual(5418, s.Count,"reading file");

            double[] expected ={
            11133.3,
            8613.8,
            14385.9,
            10328.0,
            9689.5,
            12839.8,
            10611.5,
            13445.1,
            13052.1,
            10152.5,
            12536.3,
            7573.6,
            11985.8,
            10534.4,
            9936.5,
            12047.7,
            13240.2,
            10389.1,
            13993.5,
            10028.9,
            9384.8,
            12515.8,
            14188.1,
            7887.3,
            9998.4,
            13970.7,
            7438.4,
            10280.7,
            9050.2,
            10602.3,
            10659.1,
            7180.2,
            11815.6,
            14941.5,
            11761.7,
            10830.9,
            11825.9,
            11968.4,
            9618.7,
            9729.7,
            10152.0,
            14670.9,
            12391.5,
            16330.4,
            14960.8,
            14946.8,
            16466.4,
            10045.9,
            17344.9,
            10593.5,
            15629.1,
            10727.6,
            11894.0,
            11303.9,
            10471.4,
            10555.0,
            15624.5,
            13681.5,
            14531.3,
            10780.0,
            13061.1,
            11222.4,
            14146.1};

            MonthDayRange range = new MonthDayRange(4, 1, 4, 30);
            Series s2 = Reclamation.TimeSeries.Math.AggregateAndSubset(StatisticalMethods.Average, s, range, 10);

            Assert.AreEqual(63, s2.Count);

            Assert.AreEqual(1944, s2[0].DateTime.Year);

            for (int i = 0; i < s2.Count; i++)
            {
                Assert.AreEqual(expected[i], s2[i].Value, 0.1);
            }
        }
コード例 #28
0
ファイル: Math.cs プロジェクト: usbr/Pisces
 /// <summary>
 /// Returns new series with dates included in a DateRange
 /// </summary>
 public static Series Subset(Series s, MonthDayRange range)
 {
     Series rval = s.Clone();
     int sz = s.Count;
     for (int i = 0; i < sz; i++)
     {
         Point pt = s[i];
         if (range.Contains(pt.DateTime))
         {
             rval.Add(pt);
         }
     }
     return rval;
 }