diff --git a/.gitignore b/.gitignore index a6ea22e..340e7c6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ ./0easySifProject ./0sifRawData -./MyComputers.xml \ No newline at end of file +./MyComputers.xml +./packages \ No newline at end of file diff --git a/mainProgram/Form1.Designer.cs b/mainProgram/Form1.Designer.cs index 3a3f3db..a8c8fc7 100644 --- a/mainProgram/Form1.Designer.cs +++ b/mainProgram/Form1.Designer.cs @@ -37,6 +37,7 @@ this.preprocessToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.RadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.sifComputeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.statusStrip1 = new System.Windows.Forms.StatusStrip(); this.menuStrip1.SuspendLayout(); this.SuspendLayout(); // @@ -66,27 +67,27 @@ // NewProjectToolStripMenuItem // this.NewProjectToolStripMenuItem.Name = "NewProjectToolStripMenuItem"; - this.NewProjectToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.NewProjectToolStripMenuItem.Size = new System.Drawing.Size(108, 22); this.NewProjectToolStripMenuItem.Text = "New"; this.NewProjectToolStripMenuItem.Click += new System.EventHandler(this.newToolStripMenuItem_Click); // // OpenProjectToolStripMenuItem // this.OpenProjectToolStripMenuItem.Name = "OpenProjectToolStripMenuItem"; - this.OpenProjectToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.OpenProjectToolStripMenuItem.Size = new System.Drawing.Size(108, 22); this.OpenProjectToolStripMenuItem.Text = "Open"; this.OpenProjectToolStripMenuItem.Click += new System.EventHandler(this.OpenProjectToolStripMenuItem_Click); // // addToolStripMenuItem // this.addToolStripMenuItem.Name = "addToolStripMenuItem"; - this.addToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.addToolStripMenuItem.Size = new System.Drawing.Size(108, 22); this.addToolStripMenuItem.Text = "Add"; // // SaveProjectToolStripMenuItem // this.SaveProjectToolStripMenuItem.Name = "SaveProjectToolStripMenuItem"; - this.SaveProjectToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.SaveProjectToolStripMenuItem.Size = new System.Drawing.Size(108, 22); this.SaveProjectToolStripMenuItem.Text = "Save"; // // preprocessToolStripMenuItem @@ -100,7 +101,7 @@ // RadToolStripMenuItem // this.RadToolStripMenuItem.Name = "RadToolStripMenuItem"; - this.RadToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.RadToolStripMenuItem.Size = new System.Drawing.Size(99, 22); this.RadToolStripMenuItem.Text = "Rad"; this.RadToolStripMenuItem.Click += new System.EventHandler(this.RadToolStripMenuItem_Click); // @@ -110,11 +111,20 @@ this.sifComputeToolStripMenuItem.Size = new System.Drawing.Size(87, 21); this.sifComputeToolStripMenuItem.Text = "SifCompute"; // + // statusStrip1 + // + this.statusStrip1.Location = new System.Drawing.Point(0, 428); + this.statusStrip1.Name = "statusStrip1"; + this.statusStrip1.Size = new System.Drawing.Size(800, 22); + this.statusStrip1.TabIndex = 1; + this.statusStrip1.Text = "statusStrip1"; + // // main // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.statusStrip1); this.Controls.Add(this.menuStrip1); this.MainMenuStrip = this.menuStrip1; this.Name = "main"; @@ -137,6 +147,7 @@ private System.Windows.Forms.ToolStripMenuItem preprocessToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem RadToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem sifComputeToolStripMenuItem; + private System.Windows.Forms.StatusStrip statusStrip1; } } diff --git a/mainProgram/Form1.cs b/mainProgram/Form1.cs index 862fabe..c4ca342 100644 --- a/mainProgram/Form1.cs +++ b/mainProgram/Form1.cs @@ -8,6 +8,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.IO; +using System.Threading; namespace mainProgram { @@ -18,7 +19,7 @@ namespace mainProgram InitializeComponent(); } - private ProjectManager mProjectManager;//保存打开的/新建的工程对象 + private ProjectManager mProjectManager = null;//保存打开的/新建的工程对象 public void RecieveProjectManager(ProjectManager value) { @@ -47,53 +48,25 @@ namespace mainProgram private void RadToolStripMenuItem_Click(object sender, EventArgs e) { - //SpectralDataReaderWriter xx = new SpectralDataReaderWriter(@"D:\Desktop\0easySifProject\1raw\2021_12_16\beijing_17_57_44.csv"); + if (mProjectManager is null) + { + MessageBox.Show(this, "请先打开工程!", "提示"); + return; + } - //SpectralData tmp1 = xx.GetSpectral(1); - //for (int ii = 0; ii < tmp1.spectralDataLength; ii++) - //{ - // tmp1.spectral[ii] = 1; - //} - //xx.UpdateSpectral(1, tmp1); + RadCorrectionWindow w = new RadCorrectionWindow(); + //w.TransferEvent += RecieveProjectManager; - //SpectralData tmp3 = xx.GetSpectral(3); - //for (int ii = 0; ii < tmp3.spectralDataLength; ii++) - //{ - // tmp3.spectral[ii] = 3; - //} - //xx.UpdateSpectral(3, tmp3); + //w.Show();//不阻塞 + w.ShowDialog();//阻塞 - //SpectralData tmp7 = xx.GetSpectral(7); - //for (int ii = 0; ii < tmp7.spectralDataLength; ii++) - //{ - // tmp7.spectral[ii] = 7; - //} - //xx.UpdateSpectral(7, tmp7); + //mProjectManager.Rad(); - //SpectralData tmp10 = xx.GetSpectral(10); - //for (int ii = 0; ii < tmp10.spectralDataLength; ii++) - //{ - // tmp10.spectral[ii] = 10; - //} - //xx.UpdateSpectral(10, tmp10); + Thread t1 = new Thread(new ThreadStart(mProjectManager.Rad)); + t1.Start(); - //xx.SaveCSV(@"D:\Desktop\0easySifProject\1raw\2021_12_16\beijing_17_57_44__.csv"); - - - - //SpectralDataReaderWriter xx = new SpectralDataReaderWriter(@"D:\Desktop\0easySifProject\1raw\2021_12_13\beijing_15_53_16.csv"); - - //SpectralData tmp1 = xx.GetSpectral(1); - //for (int ii = 0; ii < tmp1.spectralDataLength; ii++) - //{ - // tmp1.spectral[ii] = 1; - //} - //xx.UpdateSpectral(1, tmp1); - - //xx.SaveCSV(@"D:\Desktop\0easySifProject\1raw\2021_12_13\beijing_15_53_16__.csv"); - - mProjectManager.Rad(); } + } } diff --git a/mainProgram/Form1.resx b/mainProgram/Form1.resx index d5494e3..e85277a 100644 --- a/mainProgram/Form1.resx +++ b/mainProgram/Form1.resx @@ -120,4 +120,7 @@ 17, 17 + + 137, 17 + \ No newline at end of file diff --git a/mainProgram/NewProjectWindow.cs b/mainProgram/NewProjectWindow.cs index a6e6f36..407c5b8 100644 --- a/mainProgram/NewProjectWindow.cs +++ b/mainProgram/NewProjectWindow.cs @@ -8,6 +8,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.IO; +using System.Threading; namespace mainProgram { diff --git a/mainProgram/ProjectManager.cs b/mainProgram/ProjectManager.cs index c38ef8f..680a57e 100644 --- a/mainProgram/ProjectManager.cs +++ b/mainProgram/ProjectManager.cs @@ -374,18 +374,67 @@ namespace mainProgram } } + public int getTxtFileCount() + { + string[] metaFilesPath = Directory.GetFileSystemEntries(mMetadataPath); + int txtFileCount = 0; + for (int i = 0; i < metaFilesPath.Length; i++)// + { + if (metaFilesPath[i].Contains("txt")) + { + txtFileCount++; + } + } + return txtFileCount; + } + + public int getDatFileCount() + { + string[] metaFilesPath = Directory.GetFileSystemEntries(mMetadataPath); + int datFileCount = 0; + for (int i = 0; i < metaFilesPath.Length; i++)// + { + if (metaFilesPath[i].Contains("dat")) + { + datFileCount++; + } + } + + return datFileCount; + } - //处理工程中的数据 public void Rad() { + //读取标定文件:辐射定标文件 + 非线性校正文件 + int datFileCount = getDatFileCount(); + int txtFileCount = getTxtFileCount(); + + CalData[] calDatas = new CalData[datFileCount]; + NonLinearData[] nonLinearDatas = new NonLinearData[txtFileCount]; + + int d1 = 0, d2 = 0; + string[] metaFilesPath = Directory.GetFileSystemEntries(mMetadataPath); + for (int i = 0; i < datFileCount + txtFileCount; i++) + { + if (metaFilesPath[i].Contains("txt")) + { + nonLinearDatas[d1] = ReadNonLinearFile(metaFilesPath[i]); + d1++; + } + else if (metaFilesPath[i].Contains("dat")) + { + calDatas[d2] = ReadCalFile(metaFilesPath[i]); + d2++; + } + } + + //对文件夹中的文件遍历处理:非线性校正 + 辐射定标 Console.WriteLine("工程目录为" + mProjectPath); - DelectDir(mRadPath); - string[] sourceFilesPath = Directory.GetFileSystemEntries(mRawPath); - for (int i = 0; i < sourceFilesPath.Length; i++) + for (int i = 0; i < sourceFilesPath.Length; i++)//mRawPath下的日期文件夹 { string sourceFilePath = sourceFilesPath[i]; string[] forlders = sourceFilePath.Split('\\'); @@ -397,32 +446,142 @@ namespace mainProgram { Directory.CreateDirectory(dest); } + //福亮度转换 string[] rawFiles = Directory.GetFileSystemEntries(Path.Combine(mRawPath, lastDirectory)); - foreach (string rawFileName in rawFiles)//文件夹下的文件 + foreach (string rawFileName in rawFiles)//日期文件夹下的文件 { string[] nameTmp = rawFileName.Split('\\'); string name = nameTmp[nameTmp.Length - 1]; - SpectralDataReaderWriter SpectralData = new SpectralDataReaderWriter(rawFileName); - for (int j = 1; j <= SpectralData.TotalSpectralCount; j++)//处理 csv文件中的每条光谱 + SpectralDataReaderWriter spectralDataReaderWriter = new SpectralDataReaderWriter(rawFileName); + for (int j = 1; j <= spectralDataReaderWriter.TotalSpectralCount; j++)//处理 csv文件中的每条光谱 { - SpectralData tmp1 = SpectralData.GetSpectral(j); - for (int ii = 0; ii < tmp1.spectralDataLength; ii++) + SpectralData spectralData = spectralDataReaderWriter.GetSpectral(j); + + int nonLinearData_index = GetnonLinearDataIndex(spectralData, nonLinearDatas); + int calData_index = GetCalDataIndex(spectralData, calDatas); + + SpectralProcessor sp = new SpectralProcessor(); + + if (nonLinearData_index >= 0)//非线性校正 { - tmp1.spectral[ii] = j; + sp.NonLinearCorrection(nonLinearDatas[nonLinearData_index].nonLinearData, spectralData.spectral, spectralData.spectralDataLength); } - SpectralData.UpdateSpectral(j, tmp1); - - + if (nonLinearData_index >= 0)//福亮度转换 + { + sp.NonLinearCorrection(nonLinearDatas[nonLinearData_index].nonLinearData, spectralData.spectral, spectralData.spectralDataLength); + } + spectralDataReaderWriter.UpdateSpectral(j, spectralData); } string destFileName = Path.Combine(dest, name); - SpectralData.SaveCSV(destFileName); + spectralDataReaderWriter.SaveCSV(destFileName); } } } + + /* + 返回值:-1代表没有匹配项 + */ + public int GetnonLinearDataIndex(SpectralData spectralData, NonLinearData[] nonLinearData) + { + for (int i = 0; i < nonLinearData.GetLength(0); i++) + { + if (nonLinearData[i].SN.Contains(spectralData.SN)) + { + return i; + } + } + return -1; + } + + /* + 返回值:-1代表没有匹配项 + */ + public int GetCalDataIndex(SpectralData spectralData, CalData[] calData) + { + for (int i = 0; i < calData.GetLength(0); i++) + { + if (calData[i].SN.Contains(spectralData.SN)) + { + return i; + } + } + return -1; + } + + + public CalData ReadCalFile(string calFilePath) + { + CalData calFile; + + string[] forlders = calFilePath.Split('\\'); + calFile.SN = forlders[forlders.Length - 1]; + + FileStream fs2 = new FileStream(calFilePath, FileMode.Open, FileAccess.Read); + BinaryReader br = new BinaryReader(fs2); + calFile.exposureTime = br.ReadInt32(); + calFile.pixelCount = br.ReadInt32(); + calFile.temperature = br.ReadInt32(); + calFile.waveLengthInNM = new float[calFile.pixelCount]; + calFile.gain = new double[calFile.pixelCount]; + + for (int ii = 0; ii < calFile.pixelCount; ii++) + { + calFile.waveLengthInNM[ii] = br.ReadSingle(); + } + for (int ii = 0; ii < calFile.pixelCount; ii++) + { + calFile.gain[ii] = br.ReadDouble(); + } + + return calFile; + } + + public NonLinearData ReadNonLinearFile(string nonLinearFilePath) + { + NonLinearData nonLinearData; + string[] forlders = nonLinearFilePath.Split('\\'); + nonLinearData.SN = forlders[forlders.Length - 1]; + + + int lineCount = FindMaxRowCount(nonLinearFilePath); + nonLinearData.nonLinearData = new double[lineCount]; + + FileStream fs = new FileStream(nonLinearFilePath, FileMode.Open, FileAccess.Read); + StreamReader sr = new StreamReader(fs); + string strLine = "";//记录每次读取的一行记录 + + int i = 0; + while ((strLine = sr.ReadLine()) != null)//逐行读取CSV中的数据 + { + nonLinearData.nonLinearData[i] = double.Parse(strLine); + i++; + } + + return nonLinearData; + } + + public int FindMaxRowCount(string filePath) + { + FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read); + StreamReader sr = new StreamReader(fs); + + string strLine = ""; + int maxColunmCount = 0; + + while ((strLine = sr.ReadLine()) != null) + { + maxColunmCount++; + } + + sr.Close(); + fs.Close(); + + return maxColunmCount; + } } } diff --git a/mainProgram/SpectralProcessor.cs b/mainProgram/SpectralProcessor.cs index 9bf81fd..6f8606b 100644 --- a/mainProgram/SpectralProcessor.cs +++ b/mainProgram/SpectralProcessor.cs @@ -59,6 +59,22 @@ namespace mainProgram public double[] spectral;//long or double ????????????????????????? } + public struct CalData + { + public int exposureTime; + public int pixelCount; + public int temperature; + public float[] waveLengthInNM; + public double[] gain; + public string SN; + } + + public struct NonLinearData + { + public double[] nonLinearData; + public string SN; + } + public class SpectralDataReaderWriter { @@ -140,14 +156,10 @@ namespace mainProgram FileStream fs = new FileStream(mCsvPath, FileMode.Open, FileAccess.Read); StreamReader sr = new StreamReader(fs, encoding); + string strLine = "";//记录每次读取的一行记录 + string[] aryLine = null;//记录每行记录中的各字段内容 - //记录每次读取的一行记录 - string strLine = ""; - //记录每行记录中的各字段内容 - string[] aryLine = null; - - //逐行读取CSV中的数据 - while ((strLine = sr.ReadLine()) != null) + while ((strLine = sr.ReadLine()) != null)//逐行读取CSV中的数据 { aryLine = strLine.Split(','); DataRow dr = mDataTable.NewRow(); diff --git a/mainProgram/bin/Debug/mainProgram.exe b/mainProgram/bin/Debug/mainProgram.exe index 597fe87..8b41702 100644 Binary files a/mainProgram/bin/Debug/mainProgram.exe and b/mainProgram/bin/Debug/mainProgram.exe differ diff --git a/mainProgram/bin/Debug/mainProgram.pdb b/mainProgram/bin/Debug/mainProgram.pdb index 5a411ff..9abaaeb 100644 Binary files a/mainProgram/bin/Debug/mainProgram.pdb and b/mainProgram/bin/Debug/mainProgram.pdb differ diff --git a/mainProgram/mainProgram.csproj b/mainProgram/mainProgram.csproj index 46bf8db..d48a42d 100644 --- a/mainProgram/mainProgram.csproj +++ b/mainProgram/mainProgram.csproj @@ -34,6 +34,27 @@ 4 + + ..\packages\IronPython.2.7.11\lib\net45\IronPython.dll + + + ..\packages\IronPython.2.7.11\lib\net45\IronPython.Modules.dll + + + ..\packages\IronPython.2.7.11\lib\net45\IronPython.SQLite.dll + + + ..\packages\IronPython.2.7.11\lib\net45\IronPython.Wpf.dll + + + ..\packages\DynamicLanguageRuntime.1.3.0\lib\net45\Microsoft.Dynamic.dll + + + ..\packages\DynamicLanguageRuntime.1.3.0\lib\net45\Microsoft.Scripting.dll + + + ..\packages\DynamicLanguageRuntime.1.3.0\lib\net45\Microsoft.Scripting.Metadata.dll + @@ -74,6 +95,12 @@ ProjectManagerWindow.cs + + Form + + + RadCorrectionWindow.cs + Form1.cs @@ -96,6 +123,10 @@ True Resources.resx + + RadCorrectionWindow.cs + + SettingsSingleFileGenerator Settings.Designer.cs diff --git a/mainProgram/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/mainProgram/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache index 7e55ce7..870c0bf 100644 Binary files a/mainProgram/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache and b/mainProgram/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/mainProgram/obj/Debug/mainProgram.csproj.CoreCompileInputs.cache b/mainProgram/obj/Debug/mainProgram.csproj.CoreCompileInputs.cache index 25d91d4..daf15c3 100644 --- a/mainProgram/obj/Debug/mainProgram.csproj.CoreCompileInputs.cache +++ b/mainProgram/obj/Debug/mainProgram.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -7dc7907b9853e35973e35c6121d47468f84fe1a6 +023a461d68b4dca20dabec5434f4046ae8e60704 diff --git a/mainProgram/obj/Debug/mainProgram.csproj.FileListAbsolute.txt b/mainProgram/obj/Debug/mainProgram.csproj.FileListAbsolute.txt index 42e636f..91516ce 100644 --- a/mainProgram/obj/Debug/mainProgram.csproj.FileListAbsolute.txt +++ b/mainProgram/obj/Debug/mainProgram.csproj.FileListAbsolute.txt @@ -11,3 +11,19 @@ D:\csharp_vs2017\easySif\mainProgram\obj\Debug\mainProgram.main.resources D:\csharp_vs2017\easySif\mainProgram\obj\Debug\mainProgram.NewProjectWindow.resources D:\csharp_vs2017\easySif\mainProgram\obj\Debug\mainProgram.ProjectManagerWindow.resources D:\csharp_vs2017\easySif\mainProgram\obj\Debug\mainProgram.OpenProjectWindow.resources +D:\csharp_vs2017\easySif\mainProgram\bin\Debug\IronPython.dll +D:\csharp_vs2017\easySif\mainProgram\bin\Debug\IronPython.Modules.dll +D:\csharp_vs2017\easySif\mainProgram\bin\Debug\IronPython.SQLite.dll +D:\csharp_vs2017\easySif\mainProgram\bin\Debug\IronPython.Wpf.dll +D:\csharp_vs2017\easySif\mainProgram\bin\Debug\Microsoft.Dynamic.dll +D:\csharp_vs2017\easySif\mainProgram\bin\Debug\Microsoft.Scripting.dll +D:\csharp_vs2017\easySif\mainProgram\bin\Debug\Microsoft.Scripting.Metadata.dll +D:\csharp_vs2017\easySif\mainProgram\bin\Debug\IronPython.xml +D:\csharp_vs2017\easySif\mainProgram\bin\Debug\IronPython.Modules.xml +D:\csharp_vs2017\easySif\mainProgram\bin\Debug\IronPython.SQLite.xml +D:\csharp_vs2017\easySif\mainProgram\bin\Debug\IronPython.Wpf.xml +D:\csharp_vs2017\easySif\mainProgram\bin\Debug\Microsoft.Dynamic.xml +D:\csharp_vs2017\easySif\mainProgram\bin\Debug\Microsoft.Scripting.xml +D:\csharp_vs2017\easySif\mainProgram\bin\Debug\Microsoft.Scripting.Metadata.xml +D:\csharp_vs2017\easySif\mainProgram\obj\Debug\mainProgram.csproj.CopyComplete +D:\csharp_vs2017\easySif\mainProgram\obj\Debug\mainProgram.RadCorrectionWindow.resources diff --git a/mainProgram/obj/Debug/mainProgram.csproj.GenerateResource.cache b/mainProgram/obj/Debug/mainProgram.csproj.GenerateResource.cache index 1711aeb..81187e3 100644 Binary files a/mainProgram/obj/Debug/mainProgram.csproj.GenerateResource.cache and b/mainProgram/obj/Debug/mainProgram.csproj.GenerateResource.cache differ diff --git a/mainProgram/obj/Debug/mainProgram.csprojAssemblyReference.cache b/mainProgram/obj/Debug/mainProgram.csprojAssemblyReference.cache index b8bcb16..06882e5 100644 Binary files a/mainProgram/obj/Debug/mainProgram.csprojAssemblyReference.cache and b/mainProgram/obj/Debug/mainProgram.csprojAssemblyReference.cache differ diff --git a/mainProgram/obj/Debug/mainProgram.exe b/mainProgram/obj/Debug/mainProgram.exe index 597fe87..8b41702 100644 Binary files a/mainProgram/obj/Debug/mainProgram.exe and b/mainProgram/obj/Debug/mainProgram.exe differ diff --git a/mainProgram/obj/Debug/mainProgram.pdb b/mainProgram/obj/Debug/mainProgram.pdb index 5a411ff..9abaaeb 100644 Binary files a/mainProgram/obj/Debug/mainProgram.pdb and b/mainProgram/obj/Debug/mainProgram.pdb differ