public void MyTestInitialize()
        {
            filename       = "HydroNumerics.Time.OpenMI.UnitTest.LinkableTimeSeriesGroupTest.xts";
            outputFilename = "HydroNumerics.Time.OpenMI.UnitTest.LinkableTimeSeriesGroupTest.out.xts";

            TimespanSeries timespanSeries = new TimespanSeries("Flow", new System.DateTime(2010, 1, 1), 10, 2, TimestepUnit.Days, 4.3);

            timespanSeries.Unit = new HydroNumerics.Core.Unit("Liters pr. sec", 0.001, 0.0, "Liters pr second");
            timespanSeries.Unit.Dimension.Length = 3;
            timespanSeries.Unit.Dimension.Time   = -1;
            timespanSeries.Description           = "Measured Flow";
            TimestampSeries timestampSeries = new TimestampSeries("Water Level", new System.DateTime(2010, 1, 1), 6, 2, TimestepUnit.Days, 6.3);

            timestampSeries.Unit = new HydroNumerics.Core.Unit("cm", 0.01, 0.0, "centimeters");
            timestampSeries.Unit.Dimension.Length = 1;
            timestampSeries.Description           = "Measured Head";

            TimeSeriesGroup tsg = new TimeSeriesGroup();

            tsg.Name = "MyTsGroup";
            tsg.Items.Add(timespanSeries);
            tsg.Items.Add(timestampSeries);
            tsg.Save(filename);

            Argument filenameArgument       = new Argument("Filename", filename, true, "someDescription");
            Argument outputFilenameArgument = new Argument("OutputFilename", outputFilename, true, "someDescription");

            arguments = new Argument[2] {
                filenameArgument, outputFilenameArgument
            };
        }
Esempio n. 2
0
        /// <summary>
        /// Small program that extracts a time series from a time variant dfs2.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            TimespanSeries PrecipTS = new TimespanSeries();

            PrecipTS.Name        = "Precipitation";
            PrecipTS.Description = "Precipitation extracted from dfs2";
            PrecipTS.Unit        = UnitFactory.Instance.GetUnit(NamedUnits.millimeterperday);

            //Open the DFS2-file
            DFS2 precip = new DFS2(@"C:\Users\Jacob\Projekter\MikeSheWrapperForGEUS\novomr6\2-layer-filer\Standard_korrigeret_Prec_DK_10km_1990-2008.dfs2");

            //UTM-coordinates for Gjeller sø
            double XUTM = 456198;
            double YUTM = 6272321;

            //Get column and row index from UTM- coordinates
            int col = precip.GetColumnIndex(XUTM);
            int row = precip.GetRowIndex(YUTM);

            //Loop all the time steps
            for (int i = 0; i < precip.NumberOfTimeSteps; i++)
            {
                //Extract the value
                var val = precip.GetData(i, 1)[row, col];
                //Insert into timeseries
                PrecipTS.AddValue(precip.TimeSteps[i].Subtract(TimeSpan.FromDays(1)), precip.TimeSteps[i], val);
            }
            precip.Dispose();

            //Now do the same for evaporation. DFS2-file may have another grid and timesteps
            DFS2           evap   = new DFS2(@"C:\Users\Jacob\Projekter\MikeSheWrapperForGEUS\novomr6\2-layer-filer\Novana_DK_EPmak_40km_1990-1998_20km_1999-2008_ed.dfs2");
            TimespanSeries EvapTS = new TimespanSeries();

            EvapTS.Name        = "Evaporation";
            EvapTS.Description = "Evaporation extracted from dfs2";
            EvapTS.Unit        = UnitFactory.Instance.GetUnit(NamedUnits.millimeterperday);


            //Get column and row index from UTM- coordinates
            col = evap.GetColumnIndex(XUTM);
            row = evap.GetRowIndex(YUTM);

            for (int i = 0; i < evap.NumberOfTimeSteps; i++)
            {
                //Extract the value
                var val = evap.GetData(i, 1)[row, col];
                //Insert into timeseries
                EvapTS.AddValue(evap.TimeSteps[i].Subtract(TimeSpan.FromDays(1)), evap.TimeSteps[i], val);
            }


            //Put all time series into a group and save
            TimeSeriesGroup tsgroup = new TimeSeriesGroup();

            tsgroup.Items.Add(PrecipTS);
            tsgroup.Items.Add(EvapTS);
            tsgroup.Save(@"C:\Users\Jacob\Projekter\GWSW-Interaction\Gjeller Sø\climate.xts");
        }
Esempio n. 3
0
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Windows.Forms.SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.Filter = "Time Series file (*.xts)|*.xts";
            saveFileDialog.ShowDialog();
            if (saveFileDialog.FileName.Length > 3)
            {
                timeSeriesGroup.Save(saveFileDialog.FileName);
            }

            // Save OMI file
            HydroNumerics.Time.OpenMI.LinkableTimeSeriesGroup linkableTimeSeriesGroup = new HydroNumerics.Time.OpenMI.LinkableTimeSeriesGroup();
            linkableTimeSeriesGroup.WriteOmiFile(saveFileDialog.FileName);
        }
        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]);
            }
        }
Esempio n. 5
0
        public void Save()
        {
            string filename = "HydroNumerics.Time.Core.UnitTest.TimeSeriesGroupTest.Save.xts";

            TimespanSeries timespanSeries = new TimespanSeries("Flow", new System.DateTime(2010, 1, 1), 10, 2, TimestepUnit.Days, 4.3);

            timespanSeries.Unit = new HydroNumerics.Core.Unit("Liters pr. sec", 0.001, 0.0, "Liters pr second");
            timespanSeries.Unit.Dimension.Length = 3;
            timespanSeries.Unit.Dimension.Time   = -1;
            timespanSeries.Description           = "Measured Flow";
            TimestampSeries timestampSeries = new TimestampSeries("Water Level", new System.DateTime(2010, 1, 1), 6, 2, TimestepUnit.Days, 6.3);

            timestampSeries.Unit = new HydroNumerics.Core.Unit("cm", 0.01, 0.0, "centimeters");
            timestampSeries.Unit.Dimension.Length = 1;
            timestampSeries.Description           = "Measured Head";

            TimeSeriesGroup tsg = new TimeSeriesGroup();

            tsg.Name = "MyTsGroup";
            tsg.Items.Add(timespanSeries);
            tsg.Items.Add(timestampSeries);
            tsg.Save(filename);
        }
Esempio n. 6
0
 public void Finish()
 {
     groundwaterHeads.Save("groundwaterheads.xts");
     infiltrations.Save("infiltrations.xts");
 }
Esempio n. 7
0
        public void BuildConcFromCSV()
        {
            TimeSeriesGroup tsg = new TimeSeriesGroup();

            TimestampSeries ts1 = new TimestampSeries();

            ts1.Name = "Alkalinitet";
            TimestampSeries ts2 = new TimestampSeries();

            ts2.Name = "Nitrate";
            TimestampSeries ts3 = new TimestampSeries();

            ts3.Name = "Total nitrogen";
            TimestampSeries ts4 = new TimestampSeries();

            ts4.Name = "Chlorid";
            TimestampSeries ts5 = new TimestampSeries();

            ts5.Name = "Phosphor";
            TimestampSeries ts6 = new TimestampSeries();

            ts6.Name = "Suspenderet stof";

            tsg.Items.Add(ts1);
            tsg.Items.Add(ts2);
            tsg.Items.Add(ts3);
            tsg.Items.Add(ts4);
            tsg.Items.Add(ts5);
            tsg.Items.Add(ts6);

            using (StreamReader sr = new StreamReader(@"..\..\..\TestData\gjeller_analyse.csv"))
            {
                sr.ReadLine();
                sr.ReadLine();
                sr.ReadLine();
                sr.ReadLine();
                sr.ReadLine();
                sr.ReadLine();

                while (!sr.EndOfStream)
                {
                    var arr = sr.ReadLine().Split(';');

                    DateTime date = DateTime.Parse(arr[0]);

                    double d;
                    if (double.TryParse(arr[9], out d))
                    {
                        ts6.AddSiValue(date, d);
                    }
                    if (double.TryParse(arr[15], out d))
                    {
                        ts1.AddSiValue(date, d);
                    }
                    if (double.TryParse(arr[23], out d))
                    {
                        ts2.AddSiValue(date, d);
                    }
                    if (double.TryParse(arr[25], out d))
                    {
                        ts3.AddSiValue(date, d);
                    }
                    if (double.TryParse(arr[29], out d))
                    {
                        ts4.AddSiValue(date, d);
                    }
                    if (double.TryParse(arr[31], out d))
                    {
                        ts5.AddSiValue(date, d);
                    }
                }
            }

            tsg.Save(@"..\..\..\TestData\GjellerObservations.xts");
        }
        public void GetValues_AsAcceptor()
        {
            filename = "HydroNumerics.Time.OpenMI.UnitTest.LinkableTimeSeriesGroupTest.GetValues_AsAcceptor.xts";
            string acceptorOutputFilename = "HydroNumerics.Time.OpenMI.UnitTest.LinkableTimeSeriesGroupTest.GetValues_AsAcceptor.out.xts";

            TimespanSeries timespanSeries = new TimespanSeries("Flow", new System.DateTime(2010, 1, 1), 10, 2, TimestepUnit.Days, 10.2);

            timespanSeries.Unit = new HydroNumerics.Core.Unit("Liters pr. sec", 0.001, 0.0, "Liters pr second");
            timespanSeries.Unit.Dimension.Length = 3;
            timespanSeries.Unit.Dimension.Time   = -1;
            timespanSeries.Description           = "Measured Flow";
            TimestampSeries timestampSeries = new TimestampSeries("Water Level", new System.DateTime(2010, 1, 1), 6, 2, TimestepUnit.Days, 12.2);

            timestampSeries.Unit = new HydroNumerics.Core.Unit("cm", 0.01, 0.0, "centimeters");
            timestampSeries.Unit.Dimension.Length = 1;
            timestampSeries.Description           = "Measured Head";

            TimeSeriesGroup tsg = new TimeSeriesGroup();

            tsg.Name = "Acceptor";
            tsg.Items.Add(timespanSeries);
            tsg.Items.Add(timestampSeries);
            tsg.Save(filename);

            Argument filenameArgument       = new Argument("Filename", filename, true, "someDescription");
            Argument outputFilenameArgument = new Argument("OutputFilename", acceptorOutputFilename, true, "someDescription");

            Argument[] acceptorArguments = new Argument[2] {
                filenameArgument, outputFilenameArgument
            };

            LinkableTimeSeriesGroup acceptorTs = new LinkableTimeSeriesGroup();

            acceptorTs.Initialize(acceptorArguments);
            acceptorTs.WriteOmiFile(filename);

            LinkableTimeSeriesGroup linkableTimeSeriesGroup = new LinkableTimeSeriesGroup();

            linkableTimeSeriesGroup.Initialize(arguments);


            Link ts2tsLink1 = new Link();

            ts2tsLink1.SourceComponent  = linkableTimeSeriesGroup;
            ts2tsLink1.TargetComponent  = acceptorTs;
            ts2tsLink1.SourceQuantity   = linkableTimeSeriesGroup.GetOutputExchangeItem(0).Quantity;
            ts2tsLink1.SourceElementSet = linkableTimeSeriesGroup.GetOutputExchangeItem(0).ElementSet;
            ts2tsLink1.TargetQuantity   = acceptorTs.GetInputExchangeItem(0).Quantity;
            ts2tsLink1.TargetElementSet = acceptorTs.GetInputExchangeItem(0).ElementSet;
            ts2tsLink1.ID = "ts2ts1";
            linkableTimeSeriesGroup.AddLink(ts2tsLink1);
            acceptorTs.AddLink(ts2tsLink1);

            Link ts2tsLink2 = new Link();

            ts2tsLink2.SourceComponent  = linkableTimeSeriesGroup;
            ts2tsLink2.TargetComponent  = acceptorTs;
            ts2tsLink2.SourceQuantity   = linkableTimeSeriesGroup.GetOutputExchangeItem(1).Quantity;
            ts2tsLink2.SourceElementSet = linkableTimeSeriesGroup.GetOutputExchangeItem(1).ElementSet;
            ts2tsLink2.TargetQuantity   = acceptorTs.GetInputExchangeItem(1).Quantity;
            ts2tsLink2.TargetElementSet = acceptorTs.GetInputExchangeItem(1).ElementSet;
            ts2tsLink2.ID = "ts2ts2";
            linkableTimeSeriesGroup.AddLink(ts2tsLink2);
            acceptorTs.AddLink(ts2tsLink2);


            //setting up the work arround type of trigger
            InputExchangeItem targetExchangeItem = new InputExchangeItem();
            Quantity          targetQuantity     = new Quantity();

            targetQuantity.ID   = "Water Level";
            targetQuantity.Unit = new HydroNumerics.OpenMI.Sdk.Backbone.Unit("meter", 1, 0, "meter");
            ElementSet targetElementSet = new ElementSet("inputLocation", "Location", ElementType.IDBased, new SpatialReference(""));

            Link triggerLink = new Link();

            triggerLink.SourceComponent  = acceptorTs;
            triggerLink.TargetComponent  = null;
            triggerLink.SourceQuantity   = acceptorTs.GetOutputExchangeItem(0).Quantity;
            triggerLink.SourceElementSet = acceptorTs.GetOutputExchangeItem(0).ElementSet;
            triggerLink.TargetQuantity   = targetQuantity;
            triggerLink.TargetElementSet = targetElementSet;
            triggerLink.ID = "TriggerLink";

            acceptorTs.AddLink(triggerLink);

            TimespanSeries  tss1 = (TimespanSeries)acceptorTs.TimeSeriesGroup.Items[0];
            TimestampSeries tss2 = (TimestampSeries)acceptorTs.TimeSeriesGroup.Items[1];

            Assert.AreEqual(10.2, tss1.Items[0].Value);
            Assert.AreEqual(12.2, tss2.Items[0].Value);

            acceptorTs.GetValues(new TimeStamp(new System.DateTime(2010, 1, 3)), triggerLink.ID);

            Assert.AreEqual(4.3, tss1.Items[0].Value);
            Assert.AreEqual(6.3, tss2.Items[0].Value);

            linkableTimeSeriesGroup.Finish(); //save file
            acceptorTs.Finish();              //save file
        }