Exemple #1
0
        public void EstimateSowingWindow_JRC_Winter(Cache cache, SiteItem site)
        {
            DateTime date1;
            DateTime date2;
            DateTime datex;
            int      dayn1;
            int      dayn2;
            int      daynx;
            int      ndays;
            double   tempsum;

            esd_W = 366;
            lsd_W = 0;

            var MinLength     = site.MinSowWinLength;
            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;

            for (var year = year1; year <= year2; ++year)
            {
                date1 = new DateTime(year, 12, 30);
                date2 = new DateTime(year, 09, 01);
                dayn1 = date1.DayOfYear;
                dayn2 = date2.DayOfYear;
                ndays = dayn1 - dayn2 + 1;

                if (date1 <= cache.End && date2 >= cache.Start)
                {
                    tempsum = 0;

                    for (var dayn = 1; dayn <= ndays; ++dayn)
                    {
                        datex = date1.AddDays(-dayn + 1);
                        daynx = datex.DayOfYear;

                        tempsum += Math.Max(0, cache.TemperatureMean(datex) - TempThr);

                        if (tempsum >= TempSum || dayn == ndays)
                        {
                            if (datex.DayOfYear > lsd_W)
                            {
                                lsd_W = datex.DayOfYear;
                            }
                            break;
                        }
                    }
                }
            }
            esd_W = lsd_W - MinLength;
        }
Exemple #2
0
        ///<summary>
        ///Get the mean temperature for a given period.
        ///</summary>
        ///<param name="theDate">The end date of the period.</param>
        ///<param name="nbDays">The number of days in the perdiod</param>
        ///<returns>The mean temperature for the period</returns>

        /*public double GetMeanTemperature(DateTime theDate, int nbDays)
         * {
         *  return cache.TemperatureMean(theDate, nbDays);
         * }*/

        #endregion

        public static void Clear()
        {
            Cache.Clear();
        }
Exemple #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);
        }
Exemple #4
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);
            }
        }
Exemple #5
0
        ///<summary>
        ///Read the weather file and compute weekTemp, threeDayRain and weekRain.
        ///</summary>
        public void Init(SiteItem site, ManagementItem management)
        {
            isUnlimitedTemperature = false;

            var weatherFiles = site.WeatherFiles;

            if (site.Format == WeatherFileFormat.YearJdayMinMaxRainRad)
            {
                format = NoWindVp;
            }
            else
            {
                if (site.Format == WeatherFileFormat.YearJdayMinMaxRainRadWindVp)
                {
                    format = WindVp;
                }
                else
                {
                    format = WindVpHourly;
                }
            }

            var input = new WeatherInput {
                Files = new List <string>(), Format = format, MaxConsecutiveMissingValuesAllowed = 5
            };

            foreach (var file in weatherFiles)
            {
                input.Files.Add(file.AbsoluteFile);
            }

            cache = Cache.Get(site.GeoPosition, input);
            if (!cache.Start.HasValue)
            {
                throw new InvalidOperationException("Weather has no starting date.");
            }
            if (cache.Start.Value > management.SowingDate.AddDays(-(NumberOfFirstDays + 1)))
            {
                throw new InvalidOperationException("Sowing date - number of first days needed by DeepLayer " + management.SowingDate.ToString("u").Split()[0] + " - (" + NumberOfFirstDays + ")" + " is before the first daily weather data " + cache.Start.Value.ToString("u").Split()[0] + ".");
            }
            if (cache.Start.Value.AddDays(cache.Count) <= management.SowingDate)
            {
                throw new InvalidOperationException("Sowing date " + management.SowingDate.ToString("u").Split()[0] + " is after the last daily weather data " + cache.Start.Value.AddDays(cache.Count).ToString("u").Split()[0] + ".");
            }

            ///<Behnam>
            if (management.IsSowDateEstimate & site.SowingWindowType != 1 & site.SowingWindowType != 3 &
                site.MinSowingDate > site.MaxSowingDate)
            {
                throw new InvalidOperationException("Minimum sowing date " +
                                                    site.MinSowingDate.ToString("u").Split()[0] +
                                                    " is after maximum sowing date " + site.MaxSowingDate.ToString("u").Split()[0] + ".");
            }
            if (management.IsSowDateEstimate & site.SowingWindowType != 1 & site.SowingWindowType != 3 &
                site.MinSowingDate.AddDays(-management.SkipDays - NumberOfFirstDays - 1) < cache.Start.Value)
            {
                throw new InvalidOperationException("First date of simulation " +
                                                    site.MinSowingDate.AddDays(-management.SkipDays - NumberOfFirstDays - 1).ToString("u").Split()[0] +
                                                    " is before the first daily weather data " + cache.Start.Value.ToString("u").Split()[0] + ".");
            }
            if (management.IsSowDateEstimate & site.SowingWindowType != 1 & site.SowingWindowType != 3 &
                site.MaxSowingDate >= cache.Start.Value.AddDays(cache.Count))
            {
                throw new InvalidOperationException("Maximum sowing date " + site.MaxSowingDate.ToString("u").Split()[0] +
                                                    " is after the last daily weather data " +
                                                    cache.Start.Value.AddDays(cache.Count).ToString("u").Split()[0] + ".");
            }
        }