Beispiel #1
0
        public void EstimateSowingWindow_JRC_Spring(Cache cache, SiteItem site)
        {
            DateTime date1;
            DateTime date2;
            DateTime datex;
            int      daynx;
            int      ndays;
            double   tav10d;
            double   pcp3d;

            esd_S = 366;
            lsd_S = 0;
            List <int> esd = new List <int>();
            List <int> lsd = new List <int>();

            var year1 = cache.Start.Value.Year;
            var year2 = cache.End.Value.Year;
            var yy    = site.MaxSowingDate.Year - site.MinSowingDate.Year;

            var TempThr       = site.TempThr;
            var TempSum       = site.TempSum;
            var PcpSum        = site.PcpSum;
            var CheckDaysPcp  = site.CheckDaysPcp;
            var CheckDaysTemp = site.CheckDaysTemp;

            for (var year = year1; year <= year2; ++year)
            {
                date1 = new DateTime(year, site.MinSowingDate.Month, site.MinSowingDate.Day);
                date2 = new DateTime(year + yy, site.MaxSowingDate.Month, site.MaxSowingDate.Day);
                ndays = (int)(date2 - date1).TotalDays;

                if (date2 <= cache.End && date1 >= cache.Start.Value.AddDays(-CheckDaysTemp))
                {
                    for (var dayn = 1; dayn <= ndays; ++dayn)
                    {
                        datex  = date1.AddDays(dayn - 1);
                        daynx  = datex.DayOfYear;
                        tav10d = cache.TemperatureMean(datex.AddDays(-1), CheckDaysTemp);

                        if (tav10d >= TempThr)
                        {
                            pcp3d = cache.Rain(datex.AddDays(-1), CheckDaysPcp);

                            if (pcp3d >= PcpSum)
                            {
                                var xx = datex.Year - year;
                                esd.Add(xx * 365 + daynx);
                                lsd.Add(xx * 365 + daynx);
                                break;
                            }
                        }
                    }
                }
            }

            if (esd.Count == 0)
            {
                date1 = new DateTime(year1, site.MinSowingDate.Month, site.MinSowingDate.Day);
                date2 = new DateTime(year1 + yy, site.MaxSowingDate.Month, site.MaxSowingDate.Day);
                esd_S = (int)(date1.DayOfYear + date2.DayOfYear - 0.5) / 2;
            }
            else
            {
                esd_S = (int)Percentile(esd, 0.25);
            }

            if (lsd.Count == 0)
            {
                date1 = new DateTime(year1, site.MinSowingDate.Month, site.MinSowingDate.Day);
                date2 = new DateTime(year1 + yy, site.MaxSowingDate.Month, site.MaxSowingDate.Day);
                lsd_S = (int)(date1.DayOfYear + date2.DayOfYear + 0.5) / 2;
            }
            else
            {
                lsd_S = (int)Percentile(lsd, 0.75);
            }
        }
Beispiel #2
0
 ///<summary>
 ///Acces to daily rain.
 ///</summary>
 ///<param name="theDate">The date to get infos.</param>
 ///<returns>rain</returns>
 public double Rain(DateTime theDate)
 {
     return(cache.Rain(theDate) * Run.MMwaterToGwater);
 }
Beispiel #3
0
        public void EstimateSowingWindow_Sirius(Cache cache, SiteItem site, ManagementItem management)
        {
            DateTime   date1;
            DateTime   date2;
            DateTime   datex;
            int        daynx;
            int        ndays;
            double     tav10d;
            double     pcp3d;
            int        HalfSowWindow = (int)(InitSowWindow / 2);
            List <int> esd           = new List <int>();
            List <int> lsd           = new List <int>();

            var TempThr       = site.TempThr;
            var TempSum       = site.TempSum;
            var PcpSum        = site.PcpSum;
            var CheckDaysPcp  = site.CheckDaysPcp;
            var CheckDaysTemp = site.CheckDaysTemp;

            var year1 = cache.Start.Value.Year;
            var year2 = cache.End.Value.Year;
            var yy    = management.SowingDate.AddDays(HalfSowWindow).Year - management.SowingDate.AddDays(-HalfSowWindow).Year;

            date1   = new DateTime(year1, management.SowingDate.Month, management.SowingDate.Day);
            esd_Sir = date1.DayOfYear;
            lsd_Sir = date1.DayOfYear;
            esd.Add(esd_Sir);
            lsd.Add(lsd_Sir);

            for (var year = year1; year <= year2; ++year)
            {
                date1 = new DateTime(year, management.SowingDate.Month, management.SowingDate.Day);
                date2 = date1.AddDays(HalfSowWindow);
                ndays = (int)(date2 - date1).TotalDays;

                if (date2 <= cache.End.Value && date1 >= cache.Start.Value)
                {
                    for (var dayn = 1; dayn <= ndays; ++dayn)
                    {
                        datex  = date1.AddDays(dayn - 1);
                        daynx  = datex.DayOfYear;
                        tav10d = cache.TemperatureMean(datex.AddDays(-1), CheckDaysTemp);

                        if (tav10d >= TempThr)
                        {
                            pcp3d = cache.Rain(datex.AddDays(-1), CheckDaysPcp);

                            if (pcp3d >= PcpSum)
                            {
                                var xx = datex.Year - year;
                                lsd.Add(xx * 365 + daynx);
                                break;
                            }
                        }
                    }
                }

                date2 = new DateTime(year, management.SowingDate.Month, management.SowingDate.Day);
                date1 = date2.AddDays(-HalfSowWindow);
                if (date1 < cache.Start.Value)
                {
                    date1 = cache.Start.Value;
                }
                ndays = (int)(date2 - date1).TotalDays;

                if (date2 <= cache.End.Value)
                {
                    for (var dayn = 1; dayn <= ndays; ++dayn)
                    {
                        datex  = date2.AddDays(-dayn + 1);
                        daynx  = datex.DayOfYear;
                        tav10d = cache.TemperatureMean(datex.AddDays(-1), CheckDaysTemp);

                        if (tav10d >= TempThr)
                        {
                            pcp3d = cache.Rain(datex.AddDays(-1), CheckDaysPcp);

                            if (pcp3d >= PcpSum)
                            {
                                var xx = datex.Year - year;
                                esd.Add(xx * 365 + daynx);
                                break;
                            }
                        }
                    }
                }
            }
            esd_Sir = (int)Percentile(esd, 0.25);
            lsd_Sir = (int)Percentile(lsd, 0.75);
        }