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;

            }

        }
Exemplo n.º 2
0
        public TimeSeriesEditor()
        {
            InitializeComponent();
            timeSeriesGroup = new TimeSeriesGroup();
            timestampSeriesGrid = new TimestampSeriesGrid();
            timestampSeriesGrid.Visible = false;

            timespanSeriesGrid = new TimespanSeriesGrid();
            timespanSeriesGrid.Visible = false;

            tsPlot = new TimeSeriesPlot(timeSeriesGroup);
            //tsPlot.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right)));
            tsPlot.Height = this.mainSplitContainer.Panel1.Height;
            tsPlot.Width = this.mainSplitContainer.Panel1.Width;
            this.mainSplitContainer.Panel1.Controls.Add(tsPlot);
            tsPlot.Anchor = (AnchorStyles.Bottom | AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);

            timestampSeriesGrid.Anchor = (AnchorStyles.Bottom | AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
            timespanSeriesGrid.Anchor = (AnchorStyles.Bottom | AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
            this.mainSplitContainer.Panel2.Controls.Add(timestampSeriesGrid);
            this.mainSplitContainer.Panel2.Controls.Add(timespanSeriesGrid);
            this.tsPlot.Visible = false;
            this.Update();
            
        }
        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"));
        }
        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 };
      

        }
   public TimeSeriesGroupPropertiesDialog(TimeSeriesGroup timeSeriesGroup)
   {
       InitializeComponent();
       propertyGrid1.SelectedObject = timeSeriesGroup;
      
 
      
     
   }
Exemplo n.º 6
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");
    }
        public TimestampGridTestForm()
        {
            InitializeComponent();
            timeSeriesGroup = new TimeSeriesGroup();
            timeSeriesGroup.Items.Add(new TimestampSeries());
            timeSeriesGridControl = new TimestampSeriesGrid((TimestampSeries)timeSeriesGroup.Items[0]);
            timeSeriesGridControl.Visible = true;

            timeSeriesGridControl.Anchor = (AnchorStyles.Bottom | AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
            panel1.Controls.Add(timeSeriesGridControl);
            this.Update();
        }
Exemplo n.º 8
0
        public HideOrShowCurves(TimeSeriesGroup timeSeriesGroup)
        {
            InitializeComponent();
            checkedListBox1.CheckOnClick = true;

            this.timeSeriesGroup = timeSeriesGroup;

            for (int i = 0; i < timeSeriesGroup.Items.Count; i++)
            {
                checkedListBox1.Items.Add(timeSeriesGroup.Items[i].Name, timeSeriesGroup.Items[i].IsVisible);
            }
        }
Exemplo n.º 9
0
        public static TimeSeriesGroup Create(FileStream fileStream)
        {
            DataContractSerializer dc = new DataContractSerializer(typeof(TimeSeriesGroup), null, int.MaxValue, false, true, null);

            //  XmlSerializer serializer = new XmlSerializer(typeof(TimeSeriesGroup));


            TimeSeriesGroup timeSeriesGroup = (TimeSeriesGroup)dc.ReadObject(fileStream);

//            TimeSeriesGroup timeSeriesGroup = (TimeSeriesGroup)serializer.Deserialize(fileStream);
            fileStream.Close();
            return(timeSeriesGroup);
        }
        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]);
            }

            
        }
      /// <summary>
      /// Loads all timeseries found in the File. Will only work if they are stored without preserving references
      /// </summary>
      /// <param name="FileName"></param>
      /// <returns></returns>
        public static TimeSeriesGroup CreateAll(string FileName)
        {
          XDocument doc = XDocument.Load(FileName);
          List<Type> KnownTypes = new List<Type>();
          KnownTypes.Add(typeof(TimespanSeries));
          KnownTypes.Add(typeof(TimestampSeries));

          dc = new DataContractSerializer(typeof(BaseTimeSeries), KnownTypes, int.MaxValue, false, true, null);
          tsg = new TimeSeriesGroup();

          doc.ElementsAfterSelf("BaseTimeSeries");

          foreach (var el in doc.Elements())
          {
            Traverse(el);
          }

          return tsg;
        }
Exemplo n.º 12
0
        /// <summary>
        /// Loads all timeseries found in the File. Will only work if they are stored without preserving references
        /// </summary>
        /// <param name="FileName"></param>
        /// <returns></returns>
        public static TimeSeriesGroup CreateAll(string FileName)
        {
            XDocument   doc        = XDocument.Load(FileName);
            List <Type> KnownTypes = new List <Type>();

            KnownTypes.Add(typeof(TimespanSeries));
            KnownTypes.Add(typeof(TimestampSeries));

            dc  = new DataContractSerializer(typeof(BaseTimeSeries), KnownTypes, int.MaxValue, false, true, null);
            tsg = new TimeSeriesGroup();

            doc.ElementsAfterSelf("BaseTimeSeries");

            foreach (var el in doc.Elements())
            {
                Traverse(el);
            }

            return(tsg);
        }
        public void Initialize(System.Collections.Hashtable properties)
        {
            currentTimestep = 0;
            simulationStart = new DateTime(2001,1,1);
            dt = 172800; //timestep length (2 days)
            nt = 80; // number of timesteps
            nx = 2; //number of grid cells in x-direction
            ny = 2; //number of grid cells in y-direction
            grid = new RegularGrid(10, 10, 1000, nx, ny, 0);
            groundwaterHeads = new TimeSeriesGroup();
            infiltrations = new TimeSeriesGroup();
            

            for (int i = 0; i < nx * ny; i++)
            {
                groundwaterHeads.Items.Add(new TimestampSeries("GwHead" + i.ToString(), simulationStart, nt, dt, TimestepUnit.Seconds, 4.9, new HydroNumerics.Core.Unit("meters",1.0,0.0)));
                infiltrations.Items.Add(new TimestampSeries("Infiltration" + i.ToString(), simulationStart, nt, dt, TimestepUnit.Seconds, -9999.9999, new HydroNumerics.Core.Unit("flow",1.0,0.0)));
            }

            Quantity infiltQuantity = new Quantity();
            infiltQuantity.Unit = new HydroNumerics.OpenMI.Sdk.Backbone.Unit("level", 1.0,0.0); 
            infiltQuantity.ID = "Infiltration";
            infiltQuantity.Description = "infiltration";
            infiltQuantity.ValueType = global::OpenMI.Standard.ValueType.Scalar;
            InputExchangeItem infiltExItem = new InputExchangeItem();
            infiltExItem.Quantity = infiltQuantity;
            infiltExItem.ElementSet = grid;
            inputExchangeItems = new List<InputExchangeItem>();
            inputExchangeItems.Add(infiltExItem);
           
            Quantity headQuantity = new Quantity();
            headQuantity.Description = "Groundwater head";
            headQuantity.ID = "Head";
            headQuantity.Unit = new HydroNumerics.OpenMI.Sdk.Backbone.Unit("meters",1,0);
            headQuantity.ValueType = global::OpenMI.Standard.ValueType.Scalar;
            OutputExchangeItem headOutItem = new OutputExchangeItem();
            headOutItem.Quantity = headQuantity;
            headOutItem.ElementSet = grid;
            outputExchangeItems = new List<OutputExchangeItem>();
            outputExchangeItems.Add(headOutItem);
        }
        public TimsspanSeriesPlotForm()
        {
            
            InitializeComponent();

            timeSeriesGroup = new TimeSeriesGroup();

            //TimestampSeries timestampSeries = new TimestampSeries();
            //timestampSeries.AddTimeValueRecord(new TimeValue(new DateTime(2010, 1, 1, 0, 0, 0), 5.0));
            //timestampSeries.AddTimeValueRecord(new TimeValue(new DateTime(2010, 1, 2, 0, 0, 0), 5.0));
            //timestampSeries.AddTimeValueRecord(new TimeValue(new DateTime(2010, 1, 3, 0, 0, 0), 5.0));

            //TimestampSeries timestampSeries1 = new TimestampSeries();
            //timestampSeries1.AddTimeValueRecord(new TimeValue(new DateTime(2010, 1, 1, 0, 0, 0), 2.0));
            //timestampSeries1.AddTimeValueRecord(new TimeValue(new DateTime(2010, 1, 2, 0, 0, 0), 2.0));
            //timestampSeries1.AddTimeValueRecord(new TimeValue(new DateTime(2010, 1, 3, 0, 0, 0), 2.0));
            
            TimespanSeries timespanSeries = new TimespanSeries();
            timespanSeries.Items.Add(new TimespanValue(new Timespan(new DateTime(2010, 1, 1, 0, 0, 0), new DateTime(2010, 1, 2, 0, 0, 0)), 2));
            timespanSeries.Items.Add(new TimespanValue(new Timespan(new DateTime(2010, 1, 2, 0, 0, 0), new DateTime(2010, 1, 3, 0, 0, 0)), 3));
            timespanSeries.Items.Add(new TimespanValue(new Timespan(new DateTime(2010, 1, 3, 0, 0, 0), new DateTime(2010, 1, 4, 0, 0, 0)), 6));
            
            //timeSeriesGroup.TimeSeriesList.Add(timestampSeries);
            //timeSeriesGroup.TimeSeriesList.Add(timestampSeries1);
            timeSeriesGroup.Items.Add(timespanSeries);
            timeSeriesPlot = new TimeSeriesPlot(timeSeriesGroup);
            timeSeriesPlot.Visible = true;


            timeSeriesPlot.Anchor = (AnchorStyles.Bottom | AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
            this.Controls.Add(timeSeriesPlot);
            this.Update();
            

           
           
        }
Exemplo n.º 15
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);
        }
Exemplo n.º 16
0
 public TimespanSeriesPlot(TimeSeriesGroup timeSeriesDataSet)
 {
     InitializeComponent();
     TimeSeriesDataSet = timeSeriesDataSet; 
    
 }
Exemplo n.º 17
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 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 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

        }
Exemplo n.º 20
0
        public HydroCatEngine()
        {
            isConfigurated = false;

            //--- Default values ----
            SimulationStartTime = new DateTime(2010, 1, 1);
            SimulationEndTime = new DateTime(2011, 1, 1);

            OutputTimeSeries = new TimeSeriesGroup();

            //-- Default values (parameters)
            this.CatchmentArea = 160000000;
            this.SnowmeltCoefficient = 2.0;
            this.SurfaceStorageCapacity = 18;
            this.RootZoneStorageCapacity = 250;
            this.OverlandFlowCoefficient = 0.61;
            this.InterflowCoefficient = 0.6;
            this.OverlandFlowTreshold = 0.38;
            this.InterflowTreshold = 0.08;
            this.OverlandFlowTimeConstant = 0.3;
            this.InterflowTimeConstant = 30;
            this.BaseflowTimeConstant = 2800;

        }
Exemplo n.º 21
0
        public void PropertyChangedEvent()
        {
            TimeSeriesGroup timeSeriesGroup = new TimeSeriesGroup();
            timeSeriesGroup.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(timeSeriesGroup_PropertyChanged);
            eventWasRaised = false;
            timeSeriesGroup.Items.Add(new TimestampSeries());
            Assert.IsTrue(eventWasRaised); eventWasRaised = false;
            ((TimestampSeries)timeSeriesGroup.Items[0]).AppendValue(4.3);

            Assert.IsTrue(eventWasRaised); eventWasRaised = false;
            ((TimestampSeries)timeSeriesGroup.Items[0]).Items[0].Value = 2.1;
            Assert.IsTrue(eventWasRaised); eventWasRaised = false;
            ((TimestampSeries)timeSeriesGroup.Items[0]).Items[0].Time = new System.DateTime(2010, 1, 1, 0, 0, 0);
            Assert.IsTrue(eventWasRaised); eventWasRaised = false;
            //TODO: more testing needed
        }
Exemplo n.º 22
0
        private TimeSeriesGroup CreateTimeSeriesGroup()
        {
            TimeSeriesGroup tsg = new TimeSeriesGroup();
            tsg.Items.Add(new TimestampSeries("test1", new System.DateTime(1965, 2, 3), 10, 1, TimestepUnit.Years, 1));
            tsg.Items.Add(new TimestampSeries("test2", new System.DateTime(1955, 2, 3), 10, 1, TimestepUnit.Years, 1));
            tsg.Items.Add(new TimespanSeries("test2", new System.DateTime(1967, 2, 3), 10, 1, TimestepUnit.Years, 1));

            return tsg;

        }
Exemplo n.º 23
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");



    }
Exemplo n.º 24
0
 public void Name()
 {
     TimeSeriesGroup timeSeriesGroup = new TimeSeriesGroup();
     timeSeriesGroup.Name = "test name";
     Assert.AreEqual("test name", timeSeriesGroup.Name);
 }
Exemplo n.º 25
0
 public void Current()
 {
     TimeSeriesGroup timeSeriesGroup = new TimeSeriesGroup();
     timeSeriesGroup.Items.Add(new TimestampSeries());
     timeSeriesGroup.Items.Add(new TimestampSeries());
     timeSeriesGroup.Items.Add(new TimestampSeries());
     Assert.AreEqual(0, timeSeriesGroup.Current);
     timeSeriesGroup.Current = 2;
     Assert.AreEqual(2, timeSeriesGroup.Current);
     timeSeriesGroup.Current = 3;
     Assert.AreEqual(2, timeSeriesGroup.Current);
     timeSeriesGroup.Current = -1;
     Assert.AreEqual(0, timeSeriesGroup.Current);
 }
Exemplo n.º 26
0
        public void Overlap()
        {
            TimeSeriesGroup tsg = CreateTimeSeriesGroup();
            Assert.AreEqual(null, tsg.Overlap); // no overlap between all timeseries 

            tsg = new TimeSeriesGroup();
            tsg.Items.Add(new TimestampSeries("test1", new System.DateTime(1965, 2, 3), 10, 1, TimestepUnit.Years, 1));
            tsg.Items.Add(new TimestampSeries("test2", new System.DateTime(1962, 2, 3), 10, 1, TimestepUnit.Years, 1));
            tsg.Items.Add(new TimespanSeries("test2", new System.DateTime(1967, 2, 3), 10, 1, TimestepUnit.Years, 1));
            Assert.AreEqual(new System.DateTime(1967, 2, 3), tsg.Overlap.Start);
            Assert.AreEqual(new System.DateTime(1971, 2, 3), tsg.Overlap.End);
        }
Exemplo n.º 27
0
 //=====================================================================================================
 //  Menu: File | New... 
 //=====================================================================================================
 private void newToolStripMenuItem_Click(object sender, EventArgs e)
 {
     TimeSeriesCreationDialog timeSeriesCreationDialog = new TimeSeriesCreationDialog();
     timeSeriesCreationDialog.ShowDialog();
     this.timeSeriesGroup = new TimeSeriesGroup();
     BaseTimeSeries timeseries = timeSeriesCreationDialog.TimeSeries;
     timeSeriesGroup.Items.Add(timeseries);
     if (timeseries is TimestampSeries)
     {
         this.timestampSeriesGrid.TimeSeriesData = (TimestampSeries)timeseries;
         this.timespanSeriesGrid.Visible = false;
         this.timestampSeriesGrid.Visible = true;
     }
     else if (timeseries is TimespanSeries)
     {
         this.timespanSeriesGrid.TimeSeriesData = (TimespanSeries)timeseries;
         this.timestampSeriesGrid.Visible = false;
         this.timespanSeriesGrid.Visible = true;
     }
     this.tsPlot.TimeSeriesDataSet = this.timeSeriesGroup;
     this.tsPlot.Repaint();
     this.tsPlot.Visible = true;
     
 }