public void GetTsTest()
    {
      ZoomTimeSeries target = new ZoomTimeSeries();

      target.GetTs(TimeStepUnit.Month).AddRange(new DateTime(2010, 1, 1), new List<double>() { 1, 2, 3, 4, 6 });

      var year = target.GetTs(TimeStepUnit.Year);
    
    
    }
Esempio n. 2
0
    private void StatWriter(string FilenName, string ObsColumn, string SimColumn, DateTime Start, DateTime End, bool Yearly, bool SendFactorUpstream)
    {
      //        var obs = StateVariables.ExtractTimeSeries("ObservedNitrate");
      //      var sim = StateVariables.ExtractTimeSeries("DownStreamOutput");

      var obs = StateVariables.ExtractTimeSeries(ObsColumn);
      var sim = StateVariables.ExtractTimeSeries(SimColumn);


      using (ShapeWriter sw = new ShapeWriter(FilenName) { Projection = projection })
      {
        DataTable data = new DataTable();

        data.Columns.Add("ID15", typeof(int));
        data.Columns.Add("ME", typeof(double));
        data.Columns.Add("MAE", typeof(double));
        data.Columns.Add("RMSE", typeof(double));
        data.Columns.Add("FBAL", typeof(double));
        data.Columns.Add("R2", typeof(double));
        data.Columns.Add("bR2", typeof(double));
        data.Columns.Add("NValues", typeof(int));
        data.Columns.Add("OBS", typeof(double));
        data.Columns.Add("SIM", typeof(double));
        data.Columns.Add("BiasFactor", typeof(double));

        foreach (var kvp in obs)
        {
          ZoomTimeSeries obsr = new ZoomTimeSeries() { Accumulate = true };
          obsr.GetTs(TimeStepUnit.Month).AddRange(Start, kvp.Value.GetValues(Start, End));

          ZoomTimeSeries simr = new ZoomTimeSeries() { Accumulate = true };
          simr.GetTs(TimeStepUnit.Month).AddRange(Start, sim[kvp.Key].GetValues(Start, End));

          FixedTimeStepSeries obsreduced;
          FixedTimeStepSeries simreduced;
          if (Yearly)
          {
            obsreduced = obsr.GetTs(TimeStepUnit.Year);
            simreduced = simr.GetTs(TimeStepUnit.Year);
          }
          else
          {
            obsreduced = obsr.GetTs(TimeStepUnit.Month);
            simreduced = simr.GetTs(TimeStepUnit.Month);
          }

          double? me = obsreduced.ME(simreduced);
          if (me.HasValue)
          {
            GeoRefData gd = new GeoRefData() { Geometry = AllCatchments[kvp.Key].Geometry };
            gd.Data = data.NewRow();
            gd.Data[0] = kvp.Key;
            gd.Data[1] = me;
            gd.Data[2] = obsreduced.MAE(simreduced);
            gd.Data[3] = obsreduced.RMSE(simreduced);
            gd.Data[4] = obsreduced.FBAL(simreduced);
            gd.Data[5] = obsreduced.R2(simreduced);
            var bR2 = obsreduced.bR2(simreduced);
            if (bR2.HasValue)
              gd.Data[6] = bR2;
            else
              gd.Data[6] = DBNull.Value;

            double[] val1;
            double[] val2;
            obsreduced.AlignRemoveDeletevalues(simreduced, out val1, out val2);
            gd.Data[7] = val1.Count();
            gd.Data[8] = val1.Average();
            gd.Data[9] = val2.Average();
            gd.Data[10] = val1.Average() / val2.Average();
            sw.Write(gd);

            if(SendFactorUpstream)
              RecursiveWriter(AllCatchments[kvp.Key], sw, data, "BiasFactor", (double)gd.Data[10]);
            
          }
        }
      }
    }