Example #1
0
        private void openFileButton_Click(object sender, EventArgs e)
        {
            System.Windows.Forms.OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Title  = "Open time series file file";
            openFileDialog.Filter = "Open time series file (*.xts; *.xml)|*.xts; *.xml";
            openFileDialog.ShowDialog();

            if (openFileDialog.FileName.Length > 3)
            {
                if (System.IO.Path.GetExtension(openFileDialog.FileName).ToLower().Equals(".xml"))
                {
                    timeSeriesGroup = TimeSeriesGroupFactory.CreateAll(openFileDialog.FileName);
                }
                else
                {
                    timeSeriesGroup = TimeSeriesGroupFactory.Create(openFileDialog.FileName);
                }


                foreach (BaseTimeSeries timeSeries in timeSeriesGroup.Items)
                {
                    itemSelectionComboBox.Items.Add(timeSeries.Name);
                }

                itemSelectionComboBox.SelectedIndex = 0;
                OkButton.Enabled = true;
            }
        }
Example #2
0
        // -- Open menu ---
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Windows.Forms.OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Title  = "Open time series file file";
            openFileDialog.Filter = "Open time series file (*.xts;*.xml)|*.xts;*.xml";
            openFileDialog.ShowDialog();

            if (openFileDialog.FileName.Length > 3)
            {
                foreach (TimestampSeries timeSeriesData in timeSeriesGroup.Items)
                {
                    while (timeSeriesData.Items.Count > 0)
                    {
                        timeSeriesData.Items.RemoveAt(0);
                    }
                }
                while (timeSeriesGroup.Items.Count > 0)
                {
                    timeSeriesGroup.Items.RemoveAt(0);
                }
                this.bottomStatusStrip.Items[0].Text = "Loading time series file. Please wait...";
                if (System.IO.Path.GetExtension(openFileDialog.FileName).ToLower().Equals(".xml"))
                {
                    timeSeriesGroup = TimeSeriesGroupFactory.CreateAll(openFileDialog.FileName);
                }
                else
                {
                    timeSeriesGroup = TimeSeriesGroupFactory.Create(openFileDialog.FileName);
                }

                this.tsPlot.TimeSeriesDataSet        = this.timeSeriesGroup;
                this.tsPlot.Visible                  = true;
                this.bottomStatusStrip.Items[0].Text = "Ready...";

                this.tsPlot.Repaint();
                if (this.timeSeriesGroup.Items[0] is TimestampSeries)
                {
                    this.timespanSeriesGrid.Visible         = false;
                    this.timestampSeriesGrid.Visible        = true;
                    this.timestampSeriesGrid.TimeSeriesData = (TimestampSeries)this.timeSeriesGroup.Items[0];
                }
                else if (this.timeSeriesGroup.Items[0] is TimespanSeries)
                {
                    this.timestampSeriesGrid.Visible       = false;
                    this.timespanSeriesGrid.Visible        = true;
                    this.timespanSeriesGrid.TimeSeriesData = (TimespanSeries)this.timeSeriesGroup.Items[0];
                }
            }
        }
        public void Create()
        {
            string          filename        = "HydroNumerics.Time.Core.UnitTest.TimeSeriesGroupFactoryTest.Create.xts";
            TimeSeriesGroup tsg             = new TimeSeriesGroup();
            TimespanSeries  timespanSeries  = new TimespanSeries("timespanseriesname", new System.DateTime(2010, 1, 1), 10, 2, TimestepUnit.Days, 4.3);
            TimestampSeries timestampSeries = new TimestampSeries("timestampseriesname", new System.DateTime(2010, 1, 1), 10, 2, TimestepUnit.Days, 4.3);

            tsg.Items.Add(timespanSeries);
            tsg.Items.Add(timestampSeries);
            tsg.Save(filename);

            TimeSeriesGroup tsg2 = TimeSeriesGroupFactory.Create(filename);

            for (int i = 0; i < tsg.Items.Count; i++)
            {
                Assert.AreEqual(tsg.Items[i], tsg2.Items[i]);
            }
        }
Example #4
0
        public override void Initialize()
        {
            Dictionary <string, string> argumentsDictionary = new Dictionary <string, string>();

            //TODO: Check that you can assume that e.g. a configuration editor will populate the Argumenst, based on data from the OMI file
            foreach (IArgument argument in this.Arguments)
            {
                argumentsDictionary.Add(argument.Id, argument.ValueAsString);
            }
            filename = argumentsDictionary["Filename"];
            //outputFilename = argumentsDictionary["OutputFilename"];

            timeSeriesGroup = TimeSeriesGroupFactory.Create(filename);

            Outputs = new List <IBaseOutput>();


            foreach (var ts in timeSeriesGroup.Items)
            {
                Dimension dimention = new Dimension();
                dimention.SetPower(DimensionBase.AmountOfSubstance, ts.Unit.Dimension.AmountOfSubstance);
                dimention.SetPower(DimensionBase.Currency, ts.Unit.Dimension.Currency);
                dimention.SetPower(DimensionBase.ElectricCurrent, ts.Unit.Dimension.ElectricCurrent);
                dimention.SetPower(DimensionBase.Length, ts.Unit.Dimension.Length);
                dimention.SetPower(DimensionBase.LuminousIntensity, ts.Unit.Dimension.LuminousIntensity);
                dimention.SetPower(DimensionBase.Mass, ts.Unit.Dimension.Mass);
                dimention.SetPower(DimensionBase.Time, ts.Unit.Dimension.Time);

                Unit unit = new Unit(ts.Unit.ID);
                unit.Description          = ts.Unit.Description;
                unit.ConversionFactorToSI = ts.Unit.ConversionFactorToSI;
                unit.OffSetToSI           = ts.Unit.OffSetToSI;
                unit.Dimension            = dimention;

                Quantity quantity = new Quantity();
                quantity.Caption     = ts.Name;
                quantity.Description = ts.Description;
                quantity.Unit        = unit;

                ElementSet elementSet = new ElementSet("IDBased");
                elementSet.Description = "IDBased";
                elementSet.ElementType = global::OpenMI.Standard2.TimeSpace.ElementType.IdBased;
                Element element = new Element();
                element.Caption = "IDBased";
                elementSet.AddElement(element);



                Output o = new Output(ts.Name, quantity, elementSet);

                o.TimeSet = new TimeSet();
                o.Values  = new HydroNumerics.OpenMI.Sdk.Backbone.Generic.TimeSpaceValueSet <double>();

                if (ts is TimespanSeries)
                {
                    foreach (var tsi in ((TimespanSeries)ts).Items)
                    {
                        o.TimeSet.Times.Add(new HydroNumerics.OpenMI.Sdk.Backbone.Time(ts.StartTime, ts.EndTime));
                        o.Values.Values2D.Add(new List <double> {
                            tsi.Value
                        });
                    }
                }
                else
                {
                    foreach (var tsi in ((TimestampSeries)ts).Items)
                    {
                        o.TimeSet.Times.Add(new HydroNumerics.OpenMI.Sdk.Backbone.Time(ts.StartTime));
                        o.Values.Values2D.Add(new List <double> {
                            tsi.Value
                        });
                    }
                }

                Outputs.Add(o);
            }

            Caption     = timeSeriesGroup.Name;
            Description = timeSeriesGroup.Name;
        }
        public override void Initialize(IArgument[] properties)
        {
            SendEvent(new Event(EventType.Informative, this, "Started initialization.."));
            Dictionary <string, string> arguments = new Dictionary <string, string>();

            for (int i = 0; i < properties.Length; i++)
            {
                arguments.Add(properties[i].Key, properties[i].Value);
            }
            filename       = arguments["Filename"];
            outputFilename = arguments["OutputFilename"];

            tsGroup = TimeSeriesGroupFactory.Create(filename);

            foreach (BaseTimeSeries baseTimeSeries in tsGroup.Items)
            {
                HydroNumerics.OpenMI.Sdk.Backbone.Dimension dimention = new HydroNumerics.OpenMI.Sdk.Backbone.Dimension();
                dimention.AmountOfSubstance = baseTimeSeries.Unit.Dimension.AmountOfSubstance;
                dimention.Currency          = baseTimeSeries.Unit.Dimension.Currency;
                dimention.ElectricCurrent   = baseTimeSeries.Unit.Dimension.ElectricCurrent;
                dimention.Length            = baseTimeSeries.Unit.Dimension.Length;
                dimention.LuminousIntensity = baseTimeSeries.Unit.Dimension.LuminousIntensity;
                dimention.Mass = baseTimeSeries.Unit.Dimension.Mass;
                dimention.Time = baseTimeSeries.Unit.Dimension.Time;

                HydroNumerics.OpenMI.Sdk.Backbone.Unit unit = new HydroNumerics.OpenMI.Sdk.Backbone.Unit();
                unit.ID                   = baseTimeSeries.Unit.ID;
                unit.Description          = baseTimeSeries.Unit.Description;
                unit.ConversionFactorToSI = baseTimeSeries.Unit.ConversionFactorToSI;
                unit.OffSetToSI           = baseTimeSeries.Unit.OffSetToSI;

                TsQuantity quantity = new TsQuantity();
                quantity.ID             = baseTimeSeries.Name;
                quantity.Description    = baseTimeSeries.Description;
                quantity.Dimension      = dimention;
                quantity.Unit           = unit;
                quantity.BaseTimeSeries = baseTimeSeries;

                ElementSet elementSet = new ElementSet();
                elementSet.ID               = "IDBased";
                elementSet.Description      = "IDBased";
                elementSet.ElementType      = global::OpenMI.Standard.ElementType.IDBased;
                elementSet.SpatialReference = new SpatialReference("Undefined");
                Element element = new Element();
                element.ID = "IDBased";
                elementSet.AddElement(element);

                OutputExchangeItem outputExchangeItem = new OutputExchangeItem();
                outputExchangeItem.Quantity   = quantity;
                outputExchangeItem.ElementSet = elementSet;
                this.AddOutputExchangeItem(outputExchangeItem);

                InputExchangeItem inputExchangeItem = new InputExchangeItem();
                inputExchangeItem.Quantity   = quantity;
                inputExchangeItem.ElementSet = elementSet;
                this.AddInputExchangeItem(inputExchangeItem);
            }

            initializeWasInvoked = true;
            SendEvent(new Event(EventType.Informative, this, "Completed initialization"));
        }
Example #6
0
        public void TestMethod1()
        {
            Lake Gjeller = LakeFactory.GetLake("Gjeller Sø");

            Gjeller.Depth      = 1.2;
            Gjeller.WaterLevel = 0.4;

            WaterPacket GjellerWater = new WaterPacket(1, 1);

            GjellerWater.AddChemical(ChemicalFactory.Instance.GetChemical(ChemicalNames.Cl), 1);

            TimeSeriesGroup climate = TimeSeriesGroupFactory.Create("climate.xts");

            foreach (var I in climate.Items)
            {
                I.ExtrapolationMethod = ExtrapolationMethods.RecycleYear;
                I.AllowExtrapolation  = true;
            }

            EvaporationRateBoundary evap = new EvaporationRateBoundary((TimespanSeries)climate.Items[1]);

            evap.ContactGeometry = Gjeller.Geometry;
            Gjeller.EvaporationBoundaries.Add(evap);

            SinkSourceBoundary precip = new SinkSourceBoundary(climate.Items[0]);

            precip.ContactGeometry = Gjeller.Geometry;
            Gjeller.Precipitation.Add(precip);
            precip.ID          = 2;
            precip.WaterSample = GjellerWater.DeepClone();
            precip.WaterSample.IDForComposition = precip.ID;;

            GroundWaterBoundary GWIN = new GroundWaterBoundary(Gjeller, 1e-5, 2, 0.45, XYPolygon.GetSquare(Gjeller.Area / 2));

            GWIN.WaterSample = GjellerWater.DeepClone();
            GWIN.ID          = 3;
            GWIN.WaterSample.IDForComposition = GWIN.ID;
            GWIN.Name = "Inflow";
            Gjeller.GroundwaterBoundaries.Add(GWIN);

            GroundWaterBoundary GWout = new GroundWaterBoundary(Gjeller, 1e-5, 2, 0.35, XYPolygon.GetSquare(Gjeller.Area / 2));

            GWout.Name = "Outflow";
            Gjeller.GroundwaterBoundaries.Add(GWout);


            TimespanSeries pumping = new TimespanSeries();

            pumping.AddSiValue(new DateTime(1990, 01, 01), new DateTime(2010, 01, 01), 0);
            pumping.AddSiValue(new DateTime(2010, 01, 01), new DateTime(2010, 05, 01), 0.05);
            pumping.AddSiValue(new DateTime(2010, 05, 01), DateTime.Now, 0);


            SinkSourceBoundary DrainageWater = new SinkSourceBoundary(pumping);

            DrainageWater.ID          = 4;
            DrainageWater.WaterSample = GjellerWater.DeepClone();
            DrainageWater.WaterSample.IDForComposition = DrainageWater.ID;
            DrainageWater.Name = "Indpumpet Drænvand";
            Gjeller.Sources.Add(DrainageWater);


            var tsg = TimeSeriesGroupFactory.Create(@"..\..\..\TestData\GjellerObservations.xts");

            foreach (var ts in tsg.Items)
            {
                Chemical c = new Chemical(ts.Name, 1);
                Gjeller.RealData.AddChemicalTimeSeries(c);
                Gjeller.RealData.ChemicalConcentrations[c] = (TimestampSeries)ts;
            }

            Model M = new Model();

            M._waterBodies.Add(Gjeller);
            Gjeller.Output.LogAllChemicals = true;
            Gjeller.Output.LogComposition  = true;

            M.SetState("Initial", new DateTime(1995, 1, 1), GjellerWater);


            M.MoveInTime(DateTime.Now, TimeSpan.FromDays(10));
            M.Save(@"..\..\..\TestData\Gjeller.xml");
        }