Ejemplo n.º 1
0
        internal void PlotEsps(FcPlotUI ui, FloodControlPoint pt, FcOpsMenu opsUI)
        {
            opsUI.toolStripStatusLabel1.Text = "Plotting Esps...";

            // Get required variables from the available resources
            string inflowYear = opsUI.numericUpDownInflowYear.Value.ToString();

            var sItem    = opsUI.comboBoxEspTraces.SelectedItem;
            var selIndex = opsUI.yearList.IndexOf(sItem.ToString());
            var s        = opsUI.espList[selIndex - 1];

            inflowYear = (sItem.ToString());

            int      yr = Convert.ToInt32(ui.textBoxWaterYear.Text);
            DateTime t1 = new DateTime(), t2 = new DateTime();

            ui.SetupDates(yr, ref t1, ref t2, false);
            t2 = ui.GetWyEnd(t2);

            var sInflow        = new Reclamation.TimeSeries.Hydromet.HydrometDailySeries("", "");
            var sInflowShifted = new Series();

            sInflow.Table  = s.Table;
            sInflowShifted = Reclamation.TimeSeries.Math.ShiftToYear(sInflow, Convert.ToInt16(ui.textBoxWaterYear.Text) - 1);
            sInflowShifted = sInflowShifted.Subset(t1, t2);
            CreateSeries(espColors[espColorCounter], inflowYear + "-ESP Inflow", sInflowShifted, "right", true);
            espColorCounter++;
            if (espColorCounter >= espColors.Count)
            {
                espColorCounter = 0;
            }
            SetupTChartTools();
        }
Ejemplo n.º 2
0
 private void buttonOpsMenu_Click(object sender, EventArgs e)
 {
     // Check if a valid FloodControl object is selected and if the form is already open
     if (this.comboBoxSite.SelectedItem == null || this.comboBoxSite.SelectedItem.ToString().IndexOf("--") != -1)
     {
         return;
     }
     CheckOpsMenuOpen();
     // Open form
     fcOpsMenu = new FcOpsMenu(this);
     fcOpsMenu.Show();
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Method to perform operations given an inflow and an outflow
        /// [JR] Need to refactor this code! Maybe make a new class like FloodOperation? something like SimulationOperation?
        /// </summary>
        /// <param name="ui"></param>
        internal void FcOps(FcPlotUI ui, FloodControlPoint pt, FcOpsMenu opsUI)
        {
            opsUI.toolStripStatusLabel1.Text = "Performing operations simulation...";

            // Get required variables from the available resources
            string inflowCode  = opsUI.textBoxInflowCode.Text;
            string outflowCode = opsUI.textBoxOutflowCode.Text;
            string inflowYear  = opsUI.numericUpDownInflowYear.Value.ToString();
            string outflowYear = opsUI.numericUpDownOutflowYear.Value.ToString();

            string[] resCodes     = pt.UpstreamReservoirs;
            double   maxSpace     = pt.TotalUpstreamActiveSpace;
            decimal  inflowShift  = opsUI.numericUpDownInflowShift.Value;
            decimal  outflowShift = opsUI.numericUpDownOutflowShift.Value;
            string   inflowScale  = opsUI.textBoxInflowScale.Text;
            string   outflowScale = opsUI.textBoxOutflowScale.Text;

            // redraw the main graph
            if (opsUI.checkBoxRedrawGraph.Checked)
            {
                ui.GraphData();
            }
            PlotCurrentData(ui, inflowCode, outflowCode);

            var      sOutflow = new Reclamation.TimeSeries.Hydromet.HydrometDailySeries("", "");
            var      sOutflowShifted = new Series();
            var      sInflow = new Reclamation.TimeSeries.Hydromet.HydrometDailySeries("", "");
            var      sInflowShifted = new Series();
            DateTime t1, t2;
            int      yr;

            // Get observed storage contents
            // [JR] we only need the last value so we can streamline this code...
            //      or keep it as is and allow the user to start the simulation from a past date...
            var ithStorage = new Reclamation.TimeSeries.Hydromet.HydrometDailySeries(resCodes[0], "AF");

            t1 = DateTime.Now;
            t2 = DateTime.Now;
            yr = Convert.ToInt32(ui.textBoxWaterYear.Text);
            ui.SetupDates(yr, ref t1, ref t2, false);
            ithStorage.Read(t1, t2);
            Series sStorage = new Series(ithStorage.Table, "content", TimeInterval.Daily);

            for (int i = 1; i < resCodes.Count(); i++)
            {
                ithStorage = new Reclamation.TimeSeries.Hydromet.HydrometDailySeries(resCodes[i], "AF");
                t1         = DateTime.Now;
                t2         = DateTime.Now;
                yr         = Convert.ToInt32(ui.textBoxWaterYear.Text);
                ui.SetupDates(yr, ref t1, ref t2, false);
                ithStorage.Read(t1, t2);
                Series sStorageTemp = new Series(ithStorage.Table, "content", TimeInterval.Daily);
                sStorage = sStorage + sStorageTemp;
            }
            //Reclamation.TimeSeries.Point lastPt = sStorage[sStorage.Count() - 1]; // could potentially start simulation from any past date...
            Reclamation.TimeSeries.Point lastPt = sStorage[opsUI.dateTimePickerSimStart.Value.AddDays(-1)];

            // Process simulation outflow curve
            double outflowScaleValue;

            try { outflowScaleValue = Convert.ToDouble(outflowScale); }
            catch { outflowScaleValue = 1.0; }
            sOutflow = new Reclamation.TimeSeries.Hydromet.HydrometDailySeries(outflowCode.Split(' ')[0], outflowCode.Split(' ')[1]);
            t1       = DateTime.Now;
            t2       = DateTime.Now;
            yr       = Convert.ToInt32(outflowYear);
            ui.SetupDates(yr, ref t1, ref t2, false);
            sOutflow.Read(t1, t2);
            sOutflowShifted = Reclamation.TimeSeries.Math.ShiftToYear(sOutflow, Convert.ToInt16(ui.textBoxWaterYear.Text) - 1);
            t1 = sOutflowShifted.MinDateTime;
            t2 = sOutflowShifted.MaxDateTime;
            sOutflowShifted = Reclamation.TimeSeries.Math.Shift(sOutflowShifted, Convert.ToInt32(outflowShift));
            sOutflowShifted = sOutflowShifted.Subset(t1, t2);
            sOutflowShifted = sOutflowShifted * outflowScaleValue;
            if (opsUI.checkBoxUseCustomOutflow.Checked) //apply custom outflow
            {
                DateTime customT1 = opsUI.dateTimePickerCustomOutflow1.Value;
                DateTime customT2 = opsUI.dateTimePickerCustomOutflow2.Value;
                DateTime customT3 = opsUI.dateTimePickerCustomOutflow3.Value;
                var      customV1 = Convert.ToInt32(opsUI.textBoxCustomOutflow1.Text);
                var      customV2 = Convert.ToInt32(opsUI.textBoxCustomOutflow2.Text);

                Series rval = sOutflowShifted.Clone();
                foreach (var item in sOutflowShifted)
                {
                    DateTime sDate1 = new DateTime(customT1.Year, customT1.Month, customT1.Day);
                    DateTime sDate2 = new DateTime(customT2.Year, customT2.Month, customT2.Day);
                    DateTime sDate3 = new DateTime(customT3.Year, customT3.Month, customT3.Day);

                    var ithDate = item.DateTime;
                    if (ithDate >= sDate1 && ithDate < sDate2 && customV1 >= 0)
                    {
                        rval.Add(ithDate, customV1);
                    }
                    else if (ithDate >= sDate2 && ithDate < sDate3 && customV2 >= 0)
                    {
                        rval.Add(ithDate, customV2);
                    }
                    else
                    {
                        rval.Add(item);
                    }
                }
                sOutflowShifted = rval;
            }
            CreateSeries(System.Drawing.Color.Plum, outflowYear + "-Outflow", sOutflowShifted, "right", true);

            // Process simulation inflow curve
            double inflowScaleValue;

            try { inflowScaleValue = Convert.ToDouble(inflowScale); }
            catch { inflowScaleValue = 1.0; }
            if (opsUI.checkBoxUseCustomInflow.Checked && opsUI.yearList.Count() > 0)
            {
                var sItem    = opsUI.comboBoxEspTraces.SelectedItem;
                var selIndex = opsUI.yearList.IndexOf(sItem.ToString());
                var s        = opsUI.espList[selIndex - 1];
                inflowYear     = (sItem.ToString());
                sInflow.Table  = s.Table;
                sInflowShifted = Reclamation.TimeSeries.Math.Shift(sInflow, Convert.ToInt32(inflowShift));
                sInflowShifted = sInflowShifted.Subset(sOutflowShifted.MinDateTime, sOutflowShifted.MaxDateTime);
                sInflowShifted = sInflowShifted * inflowScaleValue;
                CreateSeries(System.Drawing.Color.LawnGreen, inflowYear + "-ESP Inflow", sInflowShifted, "right", true);
            }
            else
            {
                sInflow = new Reclamation.TimeSeries.Hydromet.HydrometDailySeries(inflowCode.Split(' ')[0], inflowCode.Split(' ')[1]);
                t1      = DateTime.Now;
                t2      = DateTime.Now;
                yr      = Convert.ToInt32(inflowYear);
                ui.SetupDates(yr, ref t1, ref t2, false);
                sInflow.Read(t1, t2);
                sInflowShifted = Reclamation.TimeSeries.Math.ShiftToYear(sInflow, Convert.ToInt16(ui.textBoxWaterYear.Text) - 1);
                t1             = sInflowShifted.MinDateTime;
                t2             = sInflowShifted.MaxDateTime;
                sInflowShifted = Reclamation.TimeSeries.Math.Shift(sInflowShifted, Convert.ToInt32(inflowShift));
                sInflowShifted = sInflowShifted.Subset(t1, t2);
                sInflowShifted = sInflowShifted * inflowScaleValue;
                CreateSeries(System.Drawing.Color.LawnGreen, inflowYear + "-Inflow", sInflowShifted, "right", true);
            }

            // Process simulated storage curve and run storage simulation forward
            DateTime minDate = new DateTime(System.Math.Min(sOutflowShifted.MaxDateTime.Ticks, sInflowShifted.MaxDateTime.Ticks)); //day-shifting misaligns the max-dates of each series

            if (lastPt.DateTime < minDate)
            {
                var t          = lastPt.DateTime;
                var stor       = lastPt.Value;
                var simStorage = new Series();
                var simSpill   = new Series();
                var simShort   = new Series();
                simStorage.Add(lastPt);
                while (t < minDate)
                {
                    t = t.AddDays(1);
                    var volIn    = (sInflowShifted[t].Value * 86400.0 / 43560.0);
                    var volOut   = (sOutflowShifted[t].Value * 86400.0 / 43560.0);
                    var tempStor = stor + volIn - volOut;
                    if (tempStor >= maxSpace)
                    {
                        var spill = (tempStor - maxSpace) * 43560.0 / 86400.0;
                        simSpill.Add(t, spill);
                        stor = maxSpace;
                    }
                    else if (tempStor <= 0)
                    {
                        var shrt = (0 - tempStor) * 43560.0 / 86400.0;
                        simShort.Add(t, shrt);
                        stor = 0;
                    }
                    else
                    {
                        stor = tempStor;
                    }
                    simStorage.Add(t, stor);
                }
                // Add series items to chart
                CreateSeries(System.Drawing.Color.DodgerBlue, "Simulated Storage (" + inflowYear + "-Qin | " + outflowYear + "-Qout)", simStorage, "left", true);
                if (simSpill.Count() > 0)
                {
                    CreateSeries(System.Drawing.Color.OrangeRed, "Simulated Spill (" + inflowYear + "-Qin | " + outflowYear + "-Qout)", simSpill, "right", true);
                }
                if (simShort.Count() > 0)
                {
                    CreateSeries(System.Drawing.Color.Cyan, "Simulated Shortage (" + inflowYear + "-Qin | " + outflowYear + "-Qout)", simShort, "right", true);
                }
            }
            tChart1.Axes.Right.Grid.Visible   = false;
            tChart1.Axes.Right.Title.Caption  = "Flow (cfs)";
            tChart1.Axes.Right.FixedLabelSize = false;
            SetupTChartTools();
            opsUI.toolStripStatusLabel1.Text = "Showing results for (" + inflowYear + "-Qin | " + outflowYear + "-Qout)";
        }