private void cmbObsVars_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (ODM != null)
     {
         var pck  = Package as IDataPackage;
         var site = cmbObsSite.SelectedItem as Site;
         var varb = cmbObsVars.SelectedItem as Variable;
         var ts   = ODM.GetTimeSeries(new QueryCriteria()
         {
             Start        = pck.StartOfLoading,
             End          = pck.EndOfLoading,
             SiteID       = site.ID,
             VariableID   = varb.ID,
             VariableName = varb.Name
         });
         if (ts != null)
         {
             var    derieved_ts = TimeSeriesAnalyzer.Derieve(ts, pck.NumericalDataType, pck.TimeUnits);
             string sereis      = string.Format("{1} at {0}", site.Name, varb.Name);
             if (btnCompareMode.Checked)
             {
                 var sim_site = cmbSimSite.SelectedItem as Site;
                 if (sim_site != null && sim_site.TimeSeries != null)
                 {
                     TimeSeriesAnalyzer.Compensate(derieved_ts, sim_site.TimeSeries);
                     winChart_timeseries.Plot <double>(derieved_ts.DateTimes, derieved_ts[0, ":", "0"], sereis);
                 }
             }
             else
             {
                 winChart_timeseries.Plot <double>(derieved_ts.DateTimes, derieved_ts[0, ":", "0"], sereis);
             }
         }
     }
 }
        private void cmbSimVars_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbSimSite.SelectedItem != null && cmbSimVars.SelectedItem != null)
            {
                var sim_site    = cmbSimSite.SelectedItem as Site;
                var pck         = Package as IDataPackage;
                var ts          = pck.DataCube.GetDoubleSeriesBetween(SelectedVariableIndex, cmbSimSite.SelectedIndex, pck.StartOfLoading, pck.EndOfLoading);
                var series_anme = sim_site.Name;
                if (ts != null)
                {
                    if (btnCompareMode.Checked)
                    {
                        winChart_timeseries.Clear();
                    }
                    var    derieved_ts = TimeSeriesAnalyzer.Derieve(ts, pck.NumericalDataType, pck.TimeUnits);
                    string sereis      = string.Format("{1} at {0}", sim_site.Name, cmbSimSite.SelectedItem.ToString());
                    sim_site.TimeSeries = derieved_ts;
                    winChart_timeseries.Plot <double>(derieved_ts.DateTimes, derieved_ts[0, ":", "0"], sereis);

                    var sites = cmbObsSite.DataSource as Site[];
                    if (sites != null)
                    {
                        var selected_site = from ss in sites where ss.ID == sim_site.ID select ss;
                        if (selected_site.Count() > 0)
                        {
                            cmbObsSite.SelectedItem = selected_site.First();
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public override bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler)
        {
            cancelProgressHandler.Progress("Package_Tool", 10, "Begin to calculate");
            PenmanMonteithET pet = new PenmanMonteithET();
            StreamReader     sr  = new StreamReader(InputDataFile);
            List <float>     et0 = new List <float>();
            int nrow             = 0;

            sr = new StreamReader(InputDataFile);
            List <DateTime> dates = new List <DateTime>();
            List <float[]>  meto  = new List <float[]>();
            List <float>    tav   = new List <float>();

            while (!sr.EndOfStream)
            {
                var line = sr.ReadLine();
                if (!TypeConverterEx.IsNull(line))
                {
                    var strs = TypeConverterEx.Split <string>(line);
                    var date = DateTime.Parse(strs[0]);
                    var vv   = TypeConverterEx.SkipSplit <float>(line, 1);
                    dates.Add(date);
                    meto.Add(vv);
                    tav.Add(vv[0]);
                    nrow++;
                }
            }
            sr.Close();

            var ts      = new DataCube <float>(tav.ToArray(), dates.ToArray());
            var tav_mon = TimeSeriesAnalyzer.GetMonthlyMean(ts, NumericalDataType.Average);

            pet.MonthTemperature = Array.ConvertAll(tav_mon, x => (double)x);
            for (int i = 0; i < nrow; i++)
            {
                var vv = meto[i];
                et0.Add((float)pet.ET0(Latitude, Longitude, vv[0], vv[1], vv[2], vv[3], vv[4], vv[5], dates[i], CloudCover));
            }
            DataCube <float> mat_out = new DataCube <float>(1, 1, et0.Count);

            mat_out[0, "0", ":"] = et0.ToArray();
            mat_out.Name         = PET;
            cancelProgressHandler.Progress("Package_Tool", 100, "Calculated");
            Workspace.Add(mat_out);
            return(true);
        }
Ejemplo n.º 4
0
 private void cmbObsVars_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (ODM != null)
     {
         var site = cmbSite.SelectedItem as Site;
         var varb = cmbObsVars.SelectedItem as Variable;
         var ts   = ODM.GetTimeSeries(new QueryCriteria()
         {
             Start        = _SFROutputPackage.StartOfLoading,
             End          = _SFROutputPackage.EndOfLoading,
             SiteID       = site.ID,
             VariableID   = varb.ID,
             VariableName = varb.Name
         });
         if (ts != null)
         {
             var    derieved_ts = TimeSeriesAnalyzer.Derieve(ts, _SFROutputPackage.NumericalDataType, _SFROutputPackage.TimeUnits);
             string sereis      = string.Format("{1} at {0}", site.Name, varb.Name);
             winChart_timeseries.Plot <double>(derieved_ts.DateTimes, derieved_ts[0, ":", "0"], sereis);
         }
     }
 }
Ejemplo n.º 5
0
        public DataCube <float> GetTimeSeries(int segIndex, int varid)
        {
            DataCube <float> ts = null;

            if (DataCube != null)
            {
                var        scaleFactor = ScaleFactor;
                var        vector      = DataCube.GetVector(varid, ":", segIndex.ToString());
                DateTime[] dates       = new DateTime[DataCube.Size[1]];
                for (int t = 0; t < DataCube.Size[1]; t++)
                {
                    dates[t] = DataCube.DateTimes[t];
                }
                MatrixOperation.Mulitple(vector, (float)scaleFactor);
                ts = new DataCube <float>(vector, dates);
                if (TimeUnits != Core.TimeUnits.Day)
                {
                    ts = TimeSeriesAnalyzer.Derieve(ts, NumericalDataType, TimeUnits);
                }
            }
            else if (DataCube != null)
            {
                var        scaleFactor = ScaleFactor;
                var        vector      = DataCube.GetVector(varid, ":", segIndex.ToString());
                DateTime[] dates       = new DateTime[DataCube.Size[1]];
                for (int t = 0; t < DataCube.Size[1]; t++)
                {
                    dates[t] = DataCube.DateTimes[t];
                }
                MatrixOperation.Mulitple(vector, (float)scaleFactor);
                ts = new DataCube <float>(vector, dates);
                if (TimeUnits != Core.TimeUnits.Day)
                {
                    ts = TimeSeriesAnalyzer.Derieve(ts, NumericalDataType, TimeUnits);
                }
            }
            return(ts);
        }
Ejemplo n.º 6
0
        public override bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler)
        {
            var    var_index = 0;
            var    mat       = Get3DMat(Source, ref var_index);
            double prg       = 0;
            int    count     = 1;

            if (mat != null)
            {
                int nstep   = mat.Size[1];
                int ncell   = mat.Size[2];
                var vec     = mat[var_index, ":", "0"];
                var dou_vec = MatrixOperation.ToDouble(vec);

                var date_source = new DateTime[nstep];
                if (mat.DateTimes != null && mat.DateTimes.Length >= nstep)
                {
                    for (int i = 0; i < nstep; i++)
                    {
                        date_source[i] = mat.DateTimes[i];
                    }
                }
                else
                {
                    for (int i = 0; i < nstep; i++)
                    {
                        date_source[i] = ModelService.Start.AddDays(i);
                    }
                }
                var ts             = new DataCube <float>(vec, date_source);
                var derieved_ts    = TimeSeriesAnalyzer.Derieve(ts, NumericalDataType, TimeUnits);
                var derieved_steps = derieved_ts.DateTimes.Length;
                var mat_out        = new DataCube <float>(1, derieved_steps, ncell);

                mat_out.Name          = Derived;
                mat_out.Variables     = new string[] { "Derived" };
                mat_out.DateTimes     = derieved_ts.DateTimes.ToArray();
                mat_out.TimeBrowsable = true;
                for (int c = 0; c < ncell; c++)
                {
                    vec         = mat[var_index, ":", c.ToString()];
                    ts          = new DataCube <float>(vec, date_source);
                    derieved_ts = TimeSeriesAnalyzer.Derieve(ts, NumericalDataType, TimeUnits);
                    for (int t = 0; t < derieved_steps; t++)
                    {
                        mat_out[0, t, c] = derieved_ts[0, t, 0];
                    }
                    prg = (c + 1) * 100.0 / ncell;
                    if (prg > count)
                    {
                        cancelProgressHandler.Progress("Package_Tool", (int)prg, "Caculating Cell: " + (c + 1));
                        count++;
                    }
                }

                Workspace.Add(mat_out);
                return(true);
            }
            else
            {
                return(false);
            }
        }