Exemplo n.º 1
0
        private new void Insert(Reclamation.TimeSeries.Series series, bool overWrite)
        {
            for (int i = 0; i < series.Count; i++)
            {
                Insert(series[i], overWrite);
            }
            if (Count > 0)
            {//modsim needs dataStartDate as the first entry.
                DateTime dataStartDate = m_mi.TimeStepManager.dataStartDate;
                if (this[0].DateTime != dataStartDate)
                {
                    this.Insert(new Reclamation.TimeSeries.Point(dataStartDate, -999));

                    if (this[0].DateTime != dataStartDate)
                    {
                        throw new Exception("Internal error.");
                    }
                }
            }
            DateTime dataEndDate = m_mi.TimeStepManager.dataEndDate;

            if (series.Count > 0 && series.MaxDateTime > dataEndDate)
            {
                Logger.WriteLine("extending modsim date range");
                m_mi.TimeStepManager.dataEndDate = series.MaxDateTime.AddHours(23).AddMinutes(59);
                m_mi.TimeStepManager.UpdateTimeStepsInfo(m_mi.timeStep);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Reads Modsim Input time series data
        /// </summary>
        private void ModsimInput(string modsimName, DateTime t1, DateTime t2 /*, string timeSeriesName*/)
        {
            try
            {
                if (modsimName.IndexOf(",") >= 0)
                {
                    Series   total = new Series();
                    string[] nodes = modsimName.Split(',');
                    for (int i = 0; i < nodes.Length; i++)
                    {
                        Csu.Modsim.ModsimModel.TimeSeries mts = FindModsimTimeSeries(nodes[i]);
                        DataTable mtbl = mts.GetTable();

                        var s = new Reclamation.TimeSeries.Series(mtbl, Units, TimeInterval);
                        s.ReadOnly = true;
                        s.HasFlags = false;

                        ModsimUtilities.FillModsimStyle(m_mi, s, m_mi.TimeStepManager.dataStartDate,
                                                        m_mi.TimeStepManager.dataEndDate);
                        //DataTable publicTable = CopyModsimDataTableConvertingIntToDouble(rawModsimTable);
                        if (i == 0)
                        {
                            total = s;
                        }
                        else
                        {
                            if (total.Count != s.Count)
                            {
                                string msg = "the node '" + nodes[i] + "' is of different length than " + nodes[i - 1] + " cannot add";
                                Console.WriteLine(msg);
                                Logger.WriteLine(msg);
                                this.Appearance.LegendText = msg;
                                throw new System.DataMisalignedException(msg);
                            }
                            total = total + s;
                        }
                    }
                    // TO-DO: Use Pisces t1 & t2
                    //int timeStartIndex = total.IndexOf(t1);
                    //int timeEndIndex = total.IndexOf(t2)+1;
                    //int modelEndIndex = total.IndexOf(m_mi.TimeStepManager.dataEndDate);
                    //for (int i = 0; i < timeStartIndex; i++)
                    //{
                    //    total.RemoveAt(i);
                    //}
                    //for (int i = timeEndIndex; i <= modelEndIndex; i++)
                    //{
                    //    total.RemoveAt(i);
                    //}
                    InitTimeSeries(total.Table, Units, TimeInterval, true);
                }

                else
                {
                    Csu.Modsim.ModsimModel.TimeSeries ts = FindModsimTimeSeries(modsimName);

                    if (ts != null)
                    {
                        _modsimSeries = ts;
                        // Name = timeSeriesName;
                        // SiteName = modsimName;
                        //CheckVariesByYear();
                        DataTable rawModsimTable = ts.GetTable();
                        var       s = new Reclamation.TimeSeries.Series(rawModsimTable, Units, TimeInterval);
                        s.HasFlags = false;
                        s.ReadOnly = true;
                        ModsimUtilities.FillModsimStyle(m_mi, s, m_mi.TimeStepManager.dataStartDate,
                                                        m_mi.TimeStepManager.dataEndDate);
                        //DataTable publicTable = CopyModsimDataTableConvertingIntToDouble(rawModsimTable);

                        // TO-DO: Use Pisces t1 & t2
                        //int timeStartIndex = s.LookupIndex(t1);
                        //int timeEndIndex = s.LookupIndex(t2,false) + 1;
                        //var a = m_mi.TimeStepManager.Date2Index(m_mi.TimeStepManager.dataEndDate,"TypeIndex????");
                        //int modelEndIndex = s.LookupIndex(m_mi.TimeStepManager.endingDate);
                        //for (int i = 0; i < timeStartIndex; i++)
                        //{
                        //    s.RemoveAt(i);
                        //}
                        //for (int i = timeEndIndex; i <= modelEndIndex; i++)
                        //{
                        //    s.RemoveAt(i);
                        //}
                        InitTimeSeries(s.Table, Units, TimeInterval, true);
                    }
                }

                ApplyDisplayScaling();
                // publicTable.RowChanged += new DataRowChangeEventHandler(tbl_RowChanged);
                this.Table.Columns[1].ColumnName = modsimName + " " + timeSeriesName;
                Appearance = new Reclamation.TimeSeries.TimeSeriesAppearance();
            }
            catch (Exception ex)
            {
                string msg = "Error reading xy file data " + Name + " " + m_mi.fname + "\n" + ex.Message + "\n"
                             + ex.StackTrace;
                throw new Exception(msg);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Reads Modsim Input time series data
        /// </summary>
        private void ModsimInput(string modsimName, DateTime t1, DateTime t2/*, string timeSeriesName*/)
        {
            try
            {
                if (modsimName.IndexOf(",") >= 0)
                {
                    Series total = new Series();
                    string[] nodes = modsimName.Split(',');
                    for (int i = 0; i < nodes.Length; i++)
                    {
                        Csu.Modsim.ModsimModel.TimeSeries mts = FindModsimTimeSeries(nodes[i]);
                        DataTable mtbl = mts.GetTable();

                        var s = new Reclamation.TimeSeries.Series(mtbl, Units, TimeInterval);
                        s.ReadOnly = true;
                        s.HasFlags = false;

                        ModsimUtilities.FillModsimStyle(m_mi, s, m_mi.TimeStepManager.dataStartDate,
                                                        m_mi.TimeStepManager.dataEndDate);
                        //DataTable publicTable = CopyModsimDataTableConvertingIntToDouble(rawModsimTable);
                        if (i == 0)
                        {
                            total = s;
                        }
                        else
                        {
                            if (total.Count != s.Count)
                            {
                                string msg = "the node '" + nodes[i] + "' is of different length than " + nodes[i-1]+ " cannot add";
                                Console.WriteLine(msg);
                                Logger.WriteLine(msg);
                                this.Appearance.LegendText = msg;
                                throw new System.DataMisalignedException(msg);
                            }
                            total = total + s;
                        }

                    }
                    // TO-DO: Use Pisces t1 & t2
                    //int timeStartIndex = total.IndexOf(t1);
                    //int timeEndIndex = total.IndexOf(t2)+1;
                    //int modelEndIndex = total.IndexOf(m_mi.TimeStepManager.dataEndDate);
                    //for (int i = 0; i < timeStartIndex; i++)
                    //{
                    //    total.RemoveAt(i);
                    //}
                    //for (int i = timeEndIndex; i <= modelEndIndex; i++)
                    //{
                    //    total.RemoveAt(i);
                    //}
                    InitTimeSeries(total.Table, Units, TimeInterval, true);
                }

                else
                {
                    Csu.Modsim.ModsimModel.TimeSeries ts = FindModsimTimeSeries(modsimName);

                    if (ts != null)
                    {
                        _modsimSeries = ts;
                       // Name = timeSeriesName;
                       // SiteName = modsimName;
                        //CheckVariesByYear();
                        DataTable rawModsimTable = ts.GetTable();
                        var s = new Reclamation.TimeSeries.Series(rawModsimTable, Units, TimeInterval);
                        s.HasFlags = false;
                        s.ReadOnly = true;
                        ModsimUtilities.FillModsimStyle(m_mi, s, m_mi.TimeStepManager.dataStartDate,
                                                        m_mi.TimeStepManager.dataEndDate);
                        //DataTable publicTable = CopyModsimDataTableConvertingIntToDouble(rawModsimTable);

                        // TO-DO: Use Pisces t1 & t2
                        //int timeStartIndex = s.LookupIndex(t1);
                        //int timeEndIndex = s.LookupIndex(t2,false) + 1;
                        //var a = m_mi.TimeStepManager.Date2Index(m_mi.TimeStepManager.dataEndDate,"TypeIndex????");
                        //int modelEndIndex = s.LookupIndex(m_mi.TimeStepManager.endingDate);
                        //for (int i = 0; i < timeStartIndex; i++)
                        //{
                        //    s.RemoveAt(i);
                        //}
                        //for (int i = timeEndIndex; i <= modelEndIndex; i++)
                        //{
                        //    s.RemoveAt(i);
                        //}
                        InitTimeSeries(s.Table, Units, TimeInterval,true);
                    }
                }

                ApplyDisplayScaling();
                // publicTable.RowChanged += new DataRowChangeEventHandler(tbl_RowChanged);
                this.Table.Columns[1].ColumnName = modsimName + " " + timeSeriesName;
                Appearance = new Reclamation.TimeSeries.TimeSeriesAppearance();
            }
            catch (Exception ex)
            {
                string msg = "Error reading xy file data " + Name + " " + m_mi.fname + "\n" + ex.Message + "\n"
                + ex.StackTrace;
                throw new Exception(msg);
            }
        }
Exemplo n.º 4
0
        public double RunoffToDate(DateTime forecastDate)
        {
            CreateSeriesList();

            ReadFromHydromet(forecastDate);

            DateTime t1;
            DateTime t2;

            ComputeDateRange(forecastDate, out t1, out t2);

            if (t2 > forecastDate)
            {
                t2 = forecastDate;
            }

            bool midMonth = forecastDate.Day != 1;

            var s = Reclamation.TimeSeries.Math.Subset(list[0], t1, t2);

            yData = list[0];
            double runoffSum = 0;

            runoffDetails.Add("  Date   Runoff  Sum");
            for (int i = 0; i < s.Count; i++)
            {
                if (!midMonth && s[i].DateTime >= forecastDate)
                {
                    break;
                }

                if (s[i].IsMissing)
                {
                    runoffDetails.Add("Error: missing data for runoff term " + s[i].DateTime.ToString("MMM yyyy"));
                    runoffSum = Point.MissingValueFlag;
                    break;
                }
                var pt = s[i];

                double val = 0;
                if (pt.Value >= 0)
                {
                    val = pt.Value;
                }

                runoffSum += val;
                string dateString = pt.DateTime.ToString("   MMM yyyy");
                if (midMonth && i == s.Count - 1)
                {
                    dateString = forecastDate.ToString("MMM dd yyyy");
                }

                runoffDetails.Add(dateString
                                  + " " + pt.Value.ToString("F2").PadLeft(6)
                                  + " " + runoffSum.ToString("F2").PadLeft(6));
            }

            runoffDetails.Add("");

            return(runoffSum);
        }