福亮度转换
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user