예제 #1
0
        private IExtractResult CLDExtractAlgorithm(Action <int, string> progressTracker)
        {
            string info = _argumentProvider.GetArg("DataSets") as string;

            if (String.IsNullOrWhiteSpace(info))
            {
                MessageBox.Show("没有选择数据集");
                return(null);
            }
            ValArguments args = _argumentProvider.GetArg("DataArgs") as ValArguments;

            if (args == null)
            {
                return(null);
            }
            string[]             files     = Directory.GetFiles(args.InputDir, "FY3*L2*.hdf", SearchOption.AllDirectories);
            float                minX      = Convert.ToSingle(args.MinX);
            float                maxX      = Convert.ToSingle(args.MaxX);
            float                minY      = Convert.ToSingle(args.MinY);
            float                maxY      = Convert.ToSingle(args.MaxY);
            float                res       = Convert.ToSingle(args.OutRes);
            string               outdir    = args.Outdir;
            string               regionNam = args.RegionNam;
            PrjEnvelope          env       = new PrjEnvelope(minX, maxX, minY, maxY);
            UniversalDataProcess cldGlobal = new UniversalDataProcess();

            foreach (string file in files)
            {
                cldGlobal.ExtractFile(file, info, env, regionNam, outdir);
            }
            return(null);
        }
예제 #2
0
 private IExtractResult DataVal(ValArguments args)
 {
     //获取待验证数据时间
     //1.若为逐时数据需要合成(仅合成在待验证数据范围内的)
     //2.若当日数据仅存在某一时次,则直接取值
     //foreach (string file in args.FileNamesForVal)
     //{
     //    RasterIdentify rid = new RasterIdentify(file);
     //    string[] file2Vals=
     //}
     return(null);
 }
예제 #3
0
        private IExtractResult MODLSTAlgorithm(Action <int, string> progressTracker)
        {
            ValArguments args = _argumentProvider.GetArg("DataArgs") as ValArguments;

            if (args == null)
            {
                return(null);
            }
            string[]             files     = Directory.GetFiles(args.InputDir, "MOD11A1*.hdf", SearchOption.AllDirectories);//args.FileNamesForVal;
            float                minX      = Convert.ToSingle(args.MinX);
            float                maxX      = Convert.ToSingle(args.MaxX);
            float                minY      = Convert.ToSingle(args.MinY);
            float                maxY      = Convert.ToSingle(args.MaxY);
            float                res       = Convert.ToSingle(args.OutRes);
            string               outdir    = args.Outdir;
            PrjEnvelope          env       = new PrjEnvelope(minX, maxX, minY, maxY);
            string               regionNam = args.RegionNam;
            UniversalDataProcess modLST    = new UniversalDataProcess();

            foreach (string file in files)
            {
                string prjfile = modLST.PrjMODSIN(file, outdir, env, res, regionNam, progressTracker);//投影
                //提取出文件日期编名
                string dateString = "0000000";
                foreach (Regex dt in DataReg)
                {
                    Match m = dt.Match(Path.GetFileName(prjfile));
                    if (m.Success)
                    {
                        dateString = m.Value;
                    }
                }
                if (dateString.Length == 8 && !dateString.Contains("A"))
                {
                    int      year     = Int16.Parse(dateString.Substring(0, 4));
                    int      month    = Int16.Parse(dateString.Substring(4, 2));
                    int      day      = Int16.Parse(dateString.Substring(6, 2));
                    DateTime datetime = new DateTime(year, month, day);
                    string   days     = Convert.ToString(datetime.DayOfYear);
                    dateString = Convert.ToString(year) + days;
                    dateString = "A" + dateString;
                }
                string outfile = outdir + "\\" + "MOD11A1." + dateString + "." + regionNam + ".join.ldf"; //形如MOD11A1.A2013231.China.join.ldf
                modLST.MODJoin(prjfile, outdir, res, regionNam, outfile);
            }
            return(null);
        }
예제 #4
0
        public object GetArgumentValue()
        {
            ValArguments args = new ValArguments();

            if (!string.IsNullOrEmpty(txtToValDir.Text))
            {
                args.FileNamesToVal = new string[] { txtToValDir.Text }
            }
            ;
            if (lstForValFiles.Items.Count > 1)
            {
                List <string> fileList = new List <string>();
                foreach (string item in lstForValFiles.Items)
                {
                    fileList.Add(item);
                }
                args.FileNamesForVal = fileList.ToArray();
            }
            args.CreatScatter   = chbScatter.Checked;
            args.CreatTimeSeq   = chbTimeSeq.Checked;
            args.CreatHistogram = chbHistogram.Checked;
            args.CreatRMSE      = chbRmse.Checked;
            return(args);
        }
예제 #5
0
        private IExtractResult SiteValAlgorithm(Action <int, string> progressTracker)
        {
            object siteArgs = _argumentProvider.GetArg("SiteArgs");

            if (siteArgs == null)
            {
                return(null);
            }
            ValArguments args = siteArgs as ValArguments;

            if (args == null)
            {
                return(null);
            }
            if (args.FileNamesForVal == null || args.FileNamesForVal.Length < 1)
            {
                return(null);
            }
            if (args.FileNamesToVal == null || args.FileNamesToVal.Length < 1)
            {
                return(null);
            }
            return(DataVal(args));
        }
예제 #6
0
        private IExtractResult SiteValAlgorithm(Action <int, string> progressTracker)
        {
            ValArguments args = _argumentProvider.GetArg("SateArgs") as ValArguments;

            return(null);//new FileExtractResult("HIST", histfilename);
        }
예제 #7
0
        private IExtractResult SateValAlgorithm(Action <int, string> progressTracker)
        {
            ValArguments args = _argumentProvider.GetArg("SateArgs") as ValArguments;

            if (args == null)
            {
                return(null);
            }
            string toValFile  = args.FileNamesToVal[0];
            string forValFile = args.FileNamesForVal[0];
            string invalid    = args.Invalid;
            //先判断时间是否一样
            string toValDate  = "0000";
            string forValDate = "0000";

            try
            {
                foreach (Regex dt in DataReg)
                {
                    Match m1 = dt.Match(Path.GetFileName(toValFile));
                    Match m2 = dt.Match(Path.GetFileName(forValFile));
                    if (m1.Success)
                    {
                        toValDate = m1.Value;
                    }
                    if (m2.Success)
                    {
                        forValDate = m2.Value;
                    }
                }
                if (toValDate == "0000" || forValDate == "0000")
                {
                    MessageBox.Show("数据文件时间为空,默认两文件时间相符");
                }
                else
                {
                    int      year     = Convert.ToInt32(toValDate.Substring(0, 4));
                    int      month    = Convert.ToInt32(toValDate.Substring(4, 2));
                    int      day      = Convert.ToInt32(toValDate.Substring(6, 2));
                    DateTime datetime = new DateTime(year, month, day);
                    string   days     = Convert.ToString(datetime.DayOfYear);

                    if (days != forValDate.Substring(1))
                    {
                        MessageBox.Show("提示:对比数据时间不同");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("异常信息:" + ex.Message);
            }
            //再看两个数据范围是否相同
            IRasterDataProvider forValRaster = GeoDataDriver.Open(forValFile) as IRasterDataProvider;
            IRasterDataProvider toValRaster  = GeoDataDriver.Open(toValFile) as IRasterDataProvider;

            if (forValRaster.CoordEnvelope.MaxX != toValRaster.CoordEnvelope.MaxX ||
                forValRaster.CoordEnvelope.MinX != toValRaster.CoordEnvelope.MinX ||
                forValRaster.CoordEnvelope.MaxY != toValRaster.CoordEnvelope.MaxY ||
                forValRaster.CoordEnvelope.MinY != toValRaster.CoordEnvelope.MinY ||
                toValRaster.Height != forValRaster.Height || toValRaster.Width != toValRaster.Width)
            {
                MessageBox.Show("两个数据空间范围不一致");
                //这里也可修改为读取两数据的交差范围,做直方图
                return(null);
            }
            #region//读取数据
            Int16[]     toValbuffer  = new Int16[toValRaster.Height * toValRaster.Width];
            Int16[]     forValbuffer = new Int16[toValRaster.Height * toValRaster.Width];
            Int16[]     toVal        = new Int16[toValRaster.Height * toValRaster.Width];
            Int16[]     forVal       = new Int16[toValRaster.Height * toValRaster.Width];
            IRasterBand toValBand    = toValRaster.GetRasterBand(1);
            IRasterBand forValBand   = forValRaster.GetRasterBand(1);
            unsafe
            {
                fixed(Int16 *pointer = toValbuffer)
                {
                    IntPtr ptr = new IntPtr(pointer);

                    toValBand.Read(0, 0, toValRaster.Width, toValRaster.Height, ptr, toValRaster.DataType,
                                   toValRaster.Width, toValRaster.Height);
                    for (int i = 0; i < toValRaster.Height * toValRaster.Width; i++)
                    {
                        toVal[i] = toValbuffer[i];
                    }
                }

                fixed(Int16 *pointer = forValbuffer)
                {
                    IntPtr ptr = new IntPtr(pointer);

                    forValBand.Read(0, 0, forValRaster.Width, forValRaster.Height, ptr, forValRaster.DataType,
                                    forValRaster.Width, forValRaster.Height);
                    for (int i = 0; i < forValRaster.Height * forValRaster.Width; i++)
                    {
                        forVal[i] = forValbuffer[i];
                    }
                }
            }
            #endregion
            IExtractResultArray array = new ExtractResultArray("统计表格");
            if (args.CreatHistogram)
            {
                List <string[]> listRowHist  = new List <string[]>();
                string          histfilename = "";
                IStatResult     fresult      = null;
                int             maxcol       = 10;
                if (!String.IsNullOrEmpty(args.MaxColumns))
                {
                    maxcol = Convert.ToInt32(args.MaxColumns);
                }
                IStaticComputer <Int16> computer = new StaticComputerInt16();
                listRowHist = computer.ComputeDeviation(toVal, forVal, GetInvalidArray(args.Invalid), GetInvalidArray(args.ForInvalid), maxcol);
                string   sentitle = "统计日期:" + DateTime.Now.ToShortDateString();
                string[] columns  = new string[] { "偏差值", "累加值" };
                fresult = new StatResult(sentitle, columns, listRowHist.ToArray());
                string title = "陆表温度产品偏差直方图";
                histfilename = StatResultToFile(new string[] { toValFile }, fresult, "VAL", "HIST", title, null, 1, true, 1);
                IFileExtractResult res = new FileExtractResult("HIST", histfilename);
                array.Add(res);
            }
            if (args.CreatRMSE)
            {
                IStaticComputer <Int16> computer = new StaticComputerInt16();
                double rmse = computer.ComputeRMSE(toVal, forVal, GetInvalidArray(args.Invalid), GetInvalidArray(args.ForInvalid));
                MessageBox.Show("数据均方根误差是:" + Convert.ToString(rmse));
            }
            #region  用这种方式出栅格数据的散点图
            //if (args.CreatScatter)
            //{
            //    List<string[]> listRow = new List<string[]>();    //散点图
            //    for (int i = 0; i < toValRaster.Height * toValRaster.Width; i++)
            //    {
            //        //剔除无效值
            //        if (!String.IsNullOrEmpty(args.invalid))
            //        {
            //            if (args.invalid.Contains(Convert.ToString(toVal[i])) || args.invalid.Contains(Convert.ToString(forVal[i])))
            //            {
            //            }
            //            else
            //            {
            //                string[] row = new string[] { Convert.ToString(toVal[i]), Convert.ToString(forVal[i]) };
            //                listRow.Add(row);

            //            }
            //        }
            //        else
            //        {
            //            string[] row = new string[] { Convert.ToString(toVal[i]), Convert.ToString(forVal[i]) };
            //            listRow.Add(row);
            //        }
            //    }
            //    string[][] rows = listRow.ToArray();
            //    IStatResult result = new StatResult("统计时间:", new string[] { "待验证云参数", "MOD06云产品" }, rows);
            //    string title = "陆表温度数据与MODIS LST对比";
            //    string filename = "";
            //    try
            //    {
            //        using (StatResultToChartInExcelFile excelControl = new StatResultToChartInExcelFile())
            //        {
            //            excelControl.Init(masExcelDrawStatType.xlXYScatter);
            //            excelControl.Add("数据对比", result, true, 0, false, result.Columns[0], result.Columns[1
            //                ]);
            //            filename = StatResultToFile(new string[] { toValFile }, result, "VAL", "SCAT", title, null, 1, true, 1);
            //            if (!filename.ToUpper().EndsWith(".XLSX"))
            //                filename += ".XLSX";
            //            excelControl.SaveFile(filename);
            //            IFileExtractResult res = new FileExtractResult("SCAT", filename);
            //            array.Add(res);
            //        }
            //    }
            //    catch (Exception ex)
            //    {

            //    }
            //}
            #endregion
            return(array);
        }
예제 #8
0
        private IExtractResult DataVal(ValArguments args)
        {
            //分波长,每个波长多时次进行验证(前提各时次地理位置相同)
            //2,3,4
            IVectorFeatureDataReader reader = AeronetDataReaderFactory.GetVectorFeatureDataReader(args.FileNamesToVal[0], new object[] { "LEV20" });

            Dictionary <string, List <AslDataSet> >[] fieldValue = new Dictionary <string, List <AslDataSet> >[] { new Dictionary <string, List <AslDataSet> > {
                                                                                                                   },
                                                                                                                   new Dictionary <string, List <AslDataSet> > {
                                                                                                                   }, new Dictionary <string, List <AslDataSet> > {
                                                                                                                   } }; ///分别为470,550,650波长,每个字典分别为站点名为关键字,值为观测站点值的时间序列
            foreach (string item in args.FileNamesForVal)
            {
                RasterIdentify rid = new RasterIdentify(item);
                using (IRasterDataProvider dataPrd2Val = GeoDataDriver.Open(item) as IRasterDataProvider)
                {
                    //470
                    for (int bandNo = 2; bandNo < 5; bandNo++)
                    {
                        string description = dataPrd2Val.GetRasterBand(bandNo).Description;
                        string key         = Regex.Match(description, pattern).ToString();
                        int    bandLength  = Int32.Parse(key);
                        int    fieldIndex  = 0;
                        //求验证数据中的Field
                        for (int i = 5; i < 20; i++)
                        {
                            if (bandLength >= GetBandLength(reader.Fields[i]) &&
                                bandLength < GetBandLength(reader.Fields[i - 1]))
                            {
                                fieldIndex = i;
                                break;
                            }
                        }
                        //验证数据中在范围内时间内的Feature
                        string    timeString   = rid.OrbitDateTime.ToString("dd:MM:yyyy");
                        string    t3           = rid.OrbitDateTime.ToString("yyyy/MM/dd");
                        Feature[] feature4Vals = GetValFeature(reader.Features, dataPrd2Val.CoordEnvelope, timeString);
                        foreach (Feature fet in feature4Vals)
                        {
                            //已存在该站点
                            string location  = fet.FieldValues[0];
                            double value4Val = StringToDouble(fet.FieldValues, fieldIndex);
                            if (value4Val == -9999)
                            {
                                continue;
                            }
                            double value2Val = ReadDataValueInRaster(dataPrd2Val, fet.Geometry.Envelope.MinX, fet.Geometry.Envelope.MinY, bandNo);
                            if (value2Val < 0)//去除无效值
                            {
                                continue;
                            }
                            if (fieldValue[bandNo - 2].ContainsKey(location))
                            {
                                fieldValue[bandNo - 2][location].Add(new AslDataSet(t3, new double[] { value2Val, value4Val }));
                            }
                            else
                            {
                                fieldValue[bandNo - 2].Add(location, new List <AslDataSet> {
                                    new AslDataSet(t3, new double[] { value2Val, value4Val })
                                });
                            }
                        }
                    }
                }
            }
            IExtractResultArray array = new ExtractResultArray("统计表格");

            //生成结果
            if (args.CreatScatter)
            {
                for (int i = 0; i < fieldValue.Length; i++)
                {
                    foreach (string key in fieldValue[i].Keys)
                    {
                        List <string[]> rowList = new List <string[]>();
                        foreach (AslDataSet set in fieldValue[i][key])
                        {
                            rowList.Add(new string[] { set.DateString, set.SiteValue[0].ToString(), set.SiteValue[1].ToString() });
                        }
                        string[][]  rows     = rowList.ToArray();
                        IStatResult result   = new StatResult("站点名称:" + key + "波长:" + GetBandLength(i), new string[] { "时间", "待验证ASL", "Aeronet LST" }, rows);
                        string      title    = "气溶胶产品数据对比";
                        string      filename = GetOutputFileName(args.FileNamesForVal, "SCAT", key, GetBandLength(i));
                        try
                        {
                            using (StatResultToChartInExcelFile excelControl = new StatResultToChartInExcelFile())
                            {
                                excelControl.Init(masExcelDrawStatType.xlXYScatter);
                                excelControl.Add(title, result, true, 1, false, result.Columns[1], result.Columns[2]);
                                if (!filename.ToUpper().EndsWith(".XLSX"))
                                {
                                    filename += ".XLSX";
                                }
                                excelControl.SaveFile(filename);
                                IFileExtractResult res = new FileExtractResult("SCAT", filename);
                                array.Add(res);
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
            }
            if (args.CreatTimeSeq)
            {
                for (int i = 0; i < fieldValue.Length; i++)
                {
                    foreach (string key in fieldValue[i].Keys)
                    {
                        List <string[]> rowList = new List <string[]>();
                        foreach (AslDataSet set in fieldValue[i][key])
                        {
                            rowList.Add(new string[] { set.DateString, set.SiteValue[0].ToString(), set.SiteValue[1].ToString() });
                        }
                        string[][]  rows     = rowList.ToArray();
                        IStatResult result   = new StatResult("站点名称:" + key + "波长:" + GetBandLength(i), new string[] { "时间", "待验证ASL", "Aeronet LST" }, rows);
                        string      title    = "气溶胶产品数据对比";
                        string      filename = GetOutputFileName(args.FileNamesForVal, "SEQD", key, GetBandLength(i));
                        try
                        {
                            using (StatResultToChartInExcelFile excelControl = new StatResultToChartInExcelFile())
                            {
                                excelControl.Init(masExcelDrawStatType.xlLineMarkers);
                                excelControl.Add(title, result, true, 0, true, result.Columns[0], "ASL");
                                if (!filename.ToUpper().EndsWith(".XLSX"))
                                {
                                    filename += ".XLSX";
                                }
                                excelControl.SaveFile(filename);
                                IFileExtractResult res = new FileExtractResult("SEQD", filename);
                                array.Add(res);
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
            }
            return(array);
        }