福亮度转换

This commit is contained in:
2021-12-22 18:07:40 +08:00
parent 000203f049
commit 8c78a0d715
17 changed files with 277 additions and 70 deletions

View File

@ -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;
}
}

View File

@ -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();
}
}
}

View File

@ -120,4 +120,7 @@
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>137, 17</value>
</metadata>
</root>

View File

@ -8,6 +8,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Threading;
namespace mainProgram
{

View File

@ -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;
}
}
}

View File

@ -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();

View File

@ -34,6 +34,27 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="IronPython, Version=2.7.11.0, Culture=neutral, PublicKeyToken=7f709c5b713576e1, processorArchitecture=MSIL">
<HintPath>..\packages\IronPython.2.7.11\lib\net45\IronPython.dll</HintPath>
</Reference>
<Reference Include="IronPython.Modules, Version=2.7.11.0, Culture=neutral, PublicKeyToken=7f709c5b713576e1, processorArchitecture=MSIL">
<HintPath>..\packages\IronPython.2.7.11\lib\net45\IronPython.Modules.dll</HintPath>
</Reference>
<Reference Include="IronPython.SQLite, Version=2.7.11.0, Culture=neutral, PublicKeyToken=7f709c5b713576e1, processorArchitecture=MSIL">
<HintPath>..\packages\IronPython.2.7.11\lib\net45\IronPython.SQLite.dll</HintPath>
</Reference>
<Reference Include="IronPython.Wpf, Version=2.7.11.0, Culture=neutral, PublicKeyToken=7f709c5b713576e1, processorArchitecture=MSIL">
<HintPath>..\packages\IronPython.2.7.11\lib\net45\IronPython.Wpf.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Dynamic, Version=1.3.0.0, Culture=neutral, PublicKeyToken=7f709c5b713576e1, processorArchitecture=MSIL">
<HintPath>..\packages\DynamicLanguageRuntime.1.3.0\lib\net45\Microsoft.Dynamic.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Scripting, Version=1.3.0.0, Culture=neutral, PublicKeyToken=7f709c5b713576e1, processorArchitecture=MSIL">
<HintPath>..\packages\DynamicLanguageRuntime.1.3.0\lib\net45\Microsoft.Scripting.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Scripting.Metadata, Version=1.3.0.0, Culture=neutral, PublicKeyToken=7f709c5b713576e1, processorArchitecture=MSIL">
<HintPath>..\packages\DynamicLanguageRuntime.1.3.0\lib\net45\Microsoft.Scripting.Metadata.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
@ -74,6 +95,12 @@
<DependentUpon>ProjectManagerWindow.cs</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RadCorrectionWindow.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="RadCorrectionWindow.Designer.cs">
<DependentUpon>RadCorrectionWindow.cs</DependentUpon>
</Compile>
<Compile Include="SpectralProcessor.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
@ -96,6 +123,10 @@
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<EmbeddedResource Include="RadCorrectionWindow.resx">
<DependentUpon>RadCorrectionWindow.cs</DependentUpon>
</EmbeddedResource>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>

View File

@ -1 +1 @@
7dc7907b9853e35973e35c6121d47468f84fe1a6
023a461d68b4dca20dabec5434f4046ae8e60704

View File

@ -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