public override bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler)
        {
            DataCubeStreamReader ds = new DataCubeStreamReader(CloudCoverFileName);

            ds.LoadDataCube();
            var           cloudcover  = ds.DataCube;
            CSVFileStream locationcsv = new CSVFileStream(LocationFileName);
            var           locations   = locationcsv.Load <double>();
            StreamReader  sr_dates    = new StreamReader(DateTimeFileName);
            int           ndays       = cloudcover.Size[1];
            int           nlocation   = cloudcover.Size[2];
            var           dates       = new DateTime[ndays];
            int           progress    = 0;
            int           np          = 1;
            var           swmat       = new DataCube <float>(cloudcover.Size[0], cloudcover.Size[1], cloudcover.Size[2]);

            swmat.Name = OutputName;
            for (int i = 0; i < ndays; i++)
            {
                var line = sr_dates.ReadLine();
                dates[i] = DateTime.Parse(line);
            }
            sr_dates.Close();
            for (int i = 0; i < ndays; i++)
            {
                for (int j = 0; j < nlocation; j++)
                {
                    swmat[0, i, j] = (float)_ShortWaveRadiation.DailyIncomingRadiationIntensity(locations.GetValue(j, 1), locations.GetValue(j, 0), dates[i], cloudcover[0, i, j]);
                }
                progress = i * 100 / ndays;
                if (progress == 5 * np)
                {
                    cancelProgressHandler.Progress("Package_Tool", progress, "Processing step: " + progress + "%");
                    np++;
                }
            }
            Workspace.Add(swmat);
            return(true);
        }
예제 #2
0
        public override bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler)
        {
            var           fs_source = FeatureSet.Open(SourceFeatureFile);
            var           fs_target = FeatureSet.Open(TargetFeatureFile);
            CSVFileStream csv       = new CSVFileStream(DataFileName);
            var           ts_data   = csv.Load <double>();

            cancelProgressHandler.Progress("Package_Tool", 1, "Time series at known sites loaded");
            int    nsource_sites = fs_source.DataTable.Rows.Count;
            int    ntar_sites    = fs_target.DataTable.Rows.Count;
            int    nstep         = ts_data.Size[0];
            int    nsite_data    = ts_data.Size[1];
            int    progress      = 0;
            double sumOfDis      = 0;
            double sumOfVa       = 0;

            if (nsite_data != nsource_sites)
            {
                cancelProgressHandler.Progress("Package_Tool", 100, "the number of sites in the data file dose not match to that in the source feature file");
                return(false);
            }
            else
            {
                if (Neighbors > nsource_sites)
                {
                    Neighbors = nsource_sites;
                }
                var known_sites      = new Site[nsource_sites];
                DataCube <float> mat = new DataCube <float>(1, nstep, ntar_sites);
                mat.DateTimes      = new DateTime[nstep];
                mat.Name           = OutputMatrix;
                mat.TimeBrowsable  = true;
                mat.AllowTableEdit = false;

                double[][] xvalues = new double[nsource_sites][];
                double[]   yvalues = new double[nsource_sites];
                for (int i = 0; i < nsource_sites; i++)
                {
                    var cor = fs_source.Features[i].Geometry.Coordinate;
                    var ele = double.Parse(fs_source.Features[i].DataRow[_ValueField].ToString());
                    xvalues[i]     = new double[3];
                    known_sites[i] = new Site()
                    {
                        LocalX    = cor.X,
                        LocalY    = cor.Y,
                        ID        = i,
                        Elevation = ele
                    };
                    xvalues[i][0] = cor.X;
                    xvalues[i][1] = cor.Y;
                    xvalues[i][2] = ele;
                }
                for (int i = 0; i < nsource_sites; i++)
                {
                    var    count = 0;
                    double sum   = 0;
                    for (int t = 0; t < nstep; t++)
                    {
                        if (ts_data.GetValue(t, i) < MaximumValue)
                        {
                            sum += ts_data.GetValue(t, i);
                            count++;
                        }
                    }
                    yvalues[i] = sum / count;
                }
                MultipleLinearRegression mlineRegrsn = new MultipleLinearRegression(xvalues, yvalues, true);
                Matrix result = new Matrix();
                mlineRegrsn.ComputeFactorCoref(result);
                double[] coeffs = result[0, Matrix.mCol];
                var      cx     = coeffs[0];
                var      cy     = coeffs[1];
                var      ce     = coeffs[2];
                cancelProgressHandler.Progress("Package_Tool", 2, "Regression coefficients calculated");

                for (int i = 0; i < ntar_sites; i++)
                {
                    var cor        = fs_target.Features[i].Geometry.Coordinate;
                    var site_intep = new Site()
                    {
                        LocalX    = cor.X,
                        LocalY    = cor.Y,
                        ID        = i,
                        Elevation = double.Parse(fs_target.Features[i].DataRow[_ValueField].ToString())
                    };
                    var neighborSites = FindNeareastSites(Neighbors, known_sites, site_intep);
                    for (int j = 0; j < nstep; j++)
                    {
                        sumOfDis = 0;
                        sumOfVa  = 0;
                        foreach (var nsite in neighborSites)
                        {
                            var vv = ts_data.GetValue(j, nsite.ID);
                            if (vv < MaximumValue)
                            {
                                double temp = 1 / System.Math.Pow(nsite.Distance, Power);
                                double gd   = (site_intep.LocalX - nsite.LocalX) * cx + (site_intep.LocalY - nsite.LocalY) * cy + (site_intep.Elevation - nsite.Elevation) * ce;
                                sumOfVa  += vv * temp;
                                sumOfDis += temp;
                            }
                        }
                        if (sumOfDis != 0)
                        {
                            mat[0, j, i] = (float)(sumOfVa / sumOfDis);
                            if (!AllowNegative && mat[0, j, i] < 0)
                            {
                                mat[0, j, i] = MinmumValue;
                            }
                        }
                        else
                        {
                            mat[0, j, i] = MinmumValue;
                        }
                    }
                    progress = (i + 1) * 100 / ntar_sites;
                    cancelProgressHandler.Progress("Package_Tool", progress, "Caculating Cell: " + (i + 1));
                }
                for (int j = 0; j < nstep; j++)
                {
                    mat.DateTimes[j] = Start.AddSeconds(j * TimeStep);
                }
                cancelProgressHandler.Progress("Package_Tool", 100, "");
                Workspace.Add(mat);
                fs_source.Close();
                fs_target.Close();
                return(true);
            }
        }
예제 #3
0
        public override bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler)
        {
            IFeatureSet fs_source = null;
            IFeatureSet fs_target = null;

            if (SourceFeatureLayer != null)
            {
                fs_source = SourceFeatureLayer.DataSet as IFeatureSet;
            }
            else if (TypeConverterEx.IsNotNull(SourceFeatureFile))
            {
                fs_source = FeatureSet.Open(SourceFeatureFile);
            }

            if (TargetFeatureLayer != null)
            {
                fs_target = TargetFeatureLayer.DataSet as IFeatureSet;
            }
            else if (TypeConverterEx.IsNotNull(TargetFeatureFile))
            {
                fs_target = FeatureSet.Open(TargetFeatureFile);
            }

            if (fs_source == null || fs_target == null)
            {
                cancelProgressHandler.Progress("Package_Tool", 100, "Failed. The inputs are invalid.");
                return(false);
            }

            CSVFileStream csv     = new CSVFileStream(DataFileName);
            var           ts_data = csv.Load <double>();

            cancelProgressHandler.Progress("Package_Tool", 1, "Time series at known sites loaded");
            int    nsource_sites = fs_source.DataTable.Rows.Count;
            int    ntar_sites    = fs_target.DataTable.Rows.Count;
            int    nstep         = ts_data.Size[0];
            int    nsite_data    = ts_data.Size[1];
            int    progress      = 0;
            int    count         = 1;
            double sumOfDis      = 0;
            double sumOfVa       = 0;

            if (nsite_data != nsource_sites)
            {
                cancelProgressHandler.Progress("Package_Tool", 100, "the number of sites in the data file dose not match to that in the source feature file");
                return(false);
            }
            else
            {
                if (Neighbors > nsource_sites)
                {
                    Neighbors = nsource_sites;
                }
                var known_sites      = new Site[nsource_sites];
                DataCube <float> mat = new DataCube <float>(1, nstep, ntar_sites);
                mat.DateTimes      = new DateTime[nstep];
                mat.Name           = OutputDataCube;
                mat.TimeBrowsable  = true;
                mat.AllowTableEdit = false;
                for (int i = 0; i < nsource_sites; i++)
                {
                    var cor = fs_source.Features[i].Geometry.Coordinate;
                    known_sites[i] = new Site()
                    {
                        LocalX = cor.X,
                        LocalY = cor.Y,
                        ID     = i
                    };
                }
                for (int i = 0; i < ntar_sites; i++)
                {
                    var cor        = fs_target.Features[i].Geometry.Coordinate;
                    var site_intep = new Site()
                    {
                        LocalX = cor.X,
                        LocalY = cor.Y,
                        ID     = i
                    };
                    var neighborSites = FindNeareastSites(Neighbors, known_sites, site_intep);
                    for (int j = 0; j < nstep; j++)
                    {
                        sumOfDis = 0;
                        sumOfVa  = 0;
                        foreach (var nsite in neighborSites)
                        {
                            var vv = ts_data.GetValue(j, nsite.ID);
                            if (vv < MaximumValue)
                            {
                                double temp = 1 / System.Math.Pow(nsite.Distance, Power);
                                sumOfVa  += vv * temp;
                                sumOfDis += temp;
                            }
                        }
                        if (sumOfDis != 0)
                        {
                            mat[0, j, i] = (float)(sumOfVa / sumOfDis);
                            if (!AllowNegative && mat[0, j, i] < 0)
                            {
                                mat[0, j, i] = MinmumValue;
                            }
                        }
                        else
                        {
                            mat[0, j, i] = MinmumValue;
                        }
                    }
                    progress = (i + 1) * 100 / ntar_sites;
                    if (progress > count)
                    {
                        cancelProgressHandler.Progress("Package_Tool", progress, "Caculating Cell: " + (i + 1));
                        count++;
                    }
                }
                for (int j = 0; j < nstep; j++)
                {
                    mat.DateTimes[j] = Start.AddSeconds(j * TimeStep);
                }
                cancelProgressHandler.Progress("Package_Tool", 100, "");
                Workspace.Add(mat);
                fs_source.Close();
                fs_target.Close();
                return(true);
            }
        }