/// <summary> /// 打开数据文件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnOpen_Click(object sender, EventArgs e) { OpenFileDialog openDlg = new OpenFileDialog(); openDlg.Filter = "DataFile(*.bin,*.bz2)|*.bin;*.bz2|All Files(*.*)|*.*"; openDlg.InitialDirectory = Application.StartupPath; openDlg.RestoreDirectory = true; if (openDlg.ShowDialog() == DialogResult.OK) { frmProgress frmpg = new frmProgress(); frmpg.SetText("数据解码中:"); frmpg.StartPosition = FormStartPosition.CenterParent; new Thread(new ThreadStart(delegate { try { while (true) { Thread.Sleep(50); if (frmpg.Visible) { break; } } //frmpg.strProgress = "数据解码中:"; mRadarData = mRadrReader.ReadData(@openDlg.FileName, frmpg); frmpg.nProgress = 85; frmpg.strProgress = "解码完成,绘制中:"; if (bmpMain != null) { bmpMain.Dispose(); } InitBmp(); bmpMain = draw.Draw(mRadarData, nLayer, 0); pbShow.Image = bmpMain; frmpg.nProgress = 95; Action <FlowLayoutPanel, int> actBar = draw.DrawColBar; frmpg.Invoke(actBar, new object[] { flpWp, 0 }); } catch (Exception ex) { } finally { frmpg.nProgress = 100; } })).Start(); frmpg.ShowDialog(); } }
/// <summary> /// Fir对PhiDpCorrect进行滤波 /// </summary> public float[,,] PhiDpFir(frmProgress frmpg) { float[,,] phiCorrect = PhiDpCorrect(); frmpg.nProgress = 60; float[,,] firPhiDp = DataInitial(9, 720, 1200, -999); for (int i = 0; i < phiRaw.GetLength(0); i++) { for (int j = 0; j < phiRaw.GetLength(1); j++) { List <float> phiDpIni_radial = new List <float>(); for (int kk = 0; kk < phiRaw.GetLength(2); kk++) { if (phiCorrect[i, j, kk] != -999) { phiDpIni_radial.Add(phiCorrect[i, j, kk]); } } for (int k = 0; k < phiRaw.GetLength(2) - firOrder / 2; k++) //60阶 { if (phiDpIni_radial.Count == 0) { firPhiDp[i, j, k] = -999; } else { if (k < firOrder / 2) { firPhiDp[i, j, k] = phiDpIni_radial[0]; } else { List <float> firInPut = new List <float>(); for (int mIndex = k - firOrder / 2; mIndex < k + firOrder / 2 + 1; mIndex++) { firInPut.Add(phiCorrect[i, j, mIndex]); } firPhiDp[i, j, k] = FirFilter(firInPut); firInPut.Clear(); } } } phiDpIni_radial.Clear(); } frmpg.nProgress = (int)(60 + (i + 1d) / phiRaw.GetLength(0) * 15); } return(firPhiDp); }
public DprRdaData ReadData(string filePath, frmProgress frmpg) { //float[, ,] DBZ = DataInitial<float>.GetResult(11, 720, 1840, -999); //float[, ,] VEL = DataInitial<float>.GetResult(11, 720, 1200, -999); //float[, ,] SW = DataInitial<float>.GetResult(11, 720, 1200, -999); //float[, ,] ZDR = DataInitial<float>.GetResult(11, 720, 1200, -999); //float[, ,] PHI = DataInitial<float>.GetResult(11, 720, 1200, -999); //float[, ,] RHO = DataInitial<float>.GetResult(11, 720, 1200, -999); //float[, ,] KDP = DataInitial<float>.GetResult(9, 720, 1200, -999); //float[] ElevationData = DataInitial<float>.GetResult(11, -999); //float[, ,] dbz = DataInitial<float>.GetResult(9, 720, 1840, -999); //float[, ,] vel = DataInitial<float>.GetResult(9, 720, 1200, -999); //float[, ,] sw = DataInitial<float>.GetResult(9, 720, 1200, -999); //float[, ,] zdr = DataInitial<float>.GetResult(9, 720, 1200, -999); //float[, ,] phi = DataInitial<float>.GetResult(9, 720, 1200, -999); //float[, ,] rho = DataInitial<float>.GetResult(9, 720, 1200, -999); //float[, ,] kdp = DataInitial<float>.GetResult(9, 720, 1200, -999); float[,,] DBZ = DataInitial(11, 720, 1200, -999); float[,,] VEL = DataInitial(11, 720, 1200, -999); float[,,] SW = DataInitial(11, 720, 1200, -999); float[,,] ZDR = DataInitial(11, 720, 1200, -999); float[,,] PHI = DataInitial(11, 720, 1200, -999); float[,,] RHO = DataInitial(11, 720, 1200, -999); float[,,] KDP = DataInitial(9, 720, 1200, -999); float[] ElevationData = DataInitial(11, -999); float[,,] dbz = DataInitial(9, 720, 1200, -999); float[,,] vel = DataInitial(9, 720, 1200, -999); float[,,] sw = DataInitial(9, 720, 1200, -999); float[,,] zdr = DataInitial(9, 720, 1200, -999); float[,,] phi = DataInitial(9, 720, 1200, -999); float[,,] rho = DataInitial(9, 720, 1200, -999); float[,,] kdp = DataInitial(9, 720, 1200, -999); float[] azimuthAngle = new float[720]; float azimuthNumber = 0; string dataSwitch = filePath.Substring(filePath.Length - 3); DateTime t1 = DateTime.Now; using (FileStream fs = new FileStream(filePath, FileMode.Open)) { using (BZip2InputStream bzip2Stream = new BZip2InputStream(fs)) { float[,] azimuth = DataInitial <float> .GetResult(11, 720, 999); bzip2Stream.Read(new byte[24 + 325888], 0, 24 + 325888); try { int radialStatus = 0; while (radialStatus != 4) { int azIndex = 0; do { //*****Message Header Data *****/// MessageHeader sizeMessHeader = ReadStructure <MessageHeader>(bzip2Stream); //*****Radar Data Generic Format Blocks ***// GenericFormatBlock genericFormatBlock = ReadStructure <GenericFormatBlock>(bzip2Stream); //****Volume Data Contant Type*****// VolumeDataConstantType volumeDataConstantType = ReadStructure <VolumeDataConstantType>(bzip2Stream); //****Elevation Data Constant Type *****// ElevationDataConstantType elevationDataCostantType = ReadStructure <ElevationDataConstantType>(bzip2Stream); //***Radial Data Block *****// RadialDataConstantType radialDataConstantType = ReadStructure <RadialDataConstantType>(bzip2Stream); int elIndex = genericFormatBlock.elevNum - 1; double azResoultion = SwitchResolution(genericFormatBlock.azReSp); azimuth[elIndex, azIndex] = genericFormatBlock.azAngle; azimuthNumber = genericFormatBlock.azimuthNum; radialStatus = genericFormatBlock.radStatus; ElevationData[elIndex] = genericFormatBlock.elevAngle; int momentCount = SwitchDataBlock(genericFormatBlock.dataBlockCount); frmpg.nProgress = (int)(bzip2Stream.Position / (double)bzip2Stream.Length * 100 * 0.4); for (int i = 0; i < momentCount; i++) { DescripOfDataMomentType descripOfDataMomentType = ReadStructure <DescripOfDataMomentType>(bzip2Stream); string typeStr = new string(descripOfDataMomentType.dataMomentName); uint binGates = descripOfDataMomentType.numberOfDataMomentGates; float scale = descripOfDataMomentType.scaLe; float offset = descripOfDataMomentType.offset; int nSize = 0; switch (typeStr) { case "REF": nSize = (int)binGates; byte[] mDBZ = new byte[nSize]; bzip2Stream.Read(mDBZ, 0, nSize); for (int binNum = 0; binNum < 1192; binNum++) { DBZ[elIndex, azIndex, binNum + 8] = Decode(mDBZ[binNum], scale, offset); } break; case "VEL": nSize = (int)binGates; byte[] mVEL = new byte[nSize]; bzip2Stream.Read(mVEL, 0, nSize); for (int binNum = 0; binNum < binGates; binNum++) { VEL[elIndex, azIndex, binNum + 8] = Decode(mVEL[binNum], scale, offset); } break; case "SW ": nSize = (int)binGates; byte[] mSW = new byte[nSize]; bzip2Stream.Read(mSW, 0, nSize); for (int binNum = 0; binNum < binGates; binNum++) { SW[elIndex, azIndex, binNum + 8] = Decode(mSW[binNum], scale, offset); } break; case "RHO": nSize = (int)binGates; byte[] mRHO = new byte[nSize]; bzip2Stream.Read(mRHO, 0, nSize); for (int binNum = 0; binNum < binGates; binNum++) { RHO[elIndex, azIndex, binNum + 8] = Decode(mRHO[binNum], scale, offset); } break; case "PHI": nSize = (int)binGates * 2; byte[] mPHI = new byte[nSize]; bzip2Stream.Read(mPHI, 0, nSize); for (int binNum = 0; binNum < binGates; binNum++) { PHI[elIndex, azIndex, binNum + 8] = DecodeUInt16(mPHI[binNum], scale, offset); } break; case "ZDR": nSize = (int)binGates; byte[] mZDR = new byte[nSize]; bzip2Stream.Read(mZDR, 0, nSize); for (int binNum = 0; binNum < binGates; binNum++) { ZDR[elIndex, azIndex, binNum + 8] = Decode(mZDR[binNum], scale, offset); } break; default: break; } } azIndex = azIndex + 1; } while (radialStatus != 2); } } catch (System.IndexOutOfRangeException) { Console.WriteLine("雷达数据读取故障!!"); } finally { bzip2Stream.Close(); } //**************************内存空间占用490MB*********************************// DateTime t2 = DateTime.Now; var sorted = Sort(azimuth); //Console.WriteLine("ReadStructure函数耗时:" + dTimeTotal_ReadStructure); //Console.WriteLine("ReadMoment函数耗时:" + dTimeTotal_ReadMoment); //Console.WriteLine("以上耗时:" + (t2 - t1).TotalMilliseconds); // 30MB frmpg.nProgress = 40; dbz = Reset("REF", sorted, DBZ); vel = Reset("VEL", sorted, VEL); sw = Reset("SW ", sorted, SW); zdr = Reset("ZDR", sorted, ZDR); rho = Reset("RHO", sorted, RHO); phi = Reset("PHI", sorted, PHI); frmpg.nProgress = 45; DBZ = null; VEL = null; SW = null; ZDR = null; RHO = null; PHI = null; System.GC.Collect(); //************************内存空间占用657.4*************************************// } fs.Close(); } QualityControl qc = new QualityControl(phi, dbz, rho); KDP = qc.GetKdpData(frmpg); return(new DprRdaData(dbz, vel, sw, rho, phi, zdr, KDP, ElevationData)); }
public float[,,] GetKdpData(frmProgress frmpg) { //firPhiDp = DataInitial(9, 720, 1200, -999); firPhiDp = PhiDpFir(frmpg); float[,,] kdpData = DataInitial(9, 720, 1200, -999); int nCount = 0; int nCountX = phiRaw.GetLength(0); int nCountY = phiRaw.GetLength(1); int nCountZ = phiRaw.GetLength(2); for (int i = 0; i < nCountX; i++) { for (int j = 0; j < nCountY; j++) { for (int k = 15; k < nCountZ - 15; k++) { if (dbzRaw[i, j, k] != -999) { if (dbzRaw[i, j, k] < 35 && dbzRaw[i, j, k] != -999) { nCount = 30; float[] y = new float[nCount]; float[] x = new float[nCount]; float[] z = new float[nCount]; int linerCount = 0; for (int linerIndex = k - nCount / 2; linerIndex < k + nCount / 2; linerIndex++) { y[linerCount] = firPhiDp[i, j, linerIndex]; x[linerCount] = (float)(linerIndex * 0.25 + 0.25); z[linerCount] = rhoRaw[i, j, linerIndex]; linerCount++; } kdpData[i, j, k] = LeastSquareMethod(x, y); } else if (dbzRaw[i, j, k] >= 35 && dbzRaw[i, j, k] <= 45) { nCount = 20; float[] y = new float[nCount]; float[] x = new float[nCount]; float[] z = new float[nCount]; int linerCount = 0; for (int linerIndex = k - nCount / 2; linerIndex < k + nCount / 2; linerIndex++) { y[linerCount] = firPhiDp[i, j, linerIndex]; x[linerCount] = (float)(linerIndex * 0.25 + 0.25); z[linerCount] = rhoRaw[i, j, linerIndex]; linerCount++; } kdpData[i, j, k] = LeastSquareMethod(x, y); } else { nCount = 10; float[] y = new float[nCount]; float[] x = new float[nCount]; float[] z = new float[nCount]; int linerCount = 0; for (int linerIndex = k - nCount / 2; linerIndex < k + nCount / 2; linerIndex++) { y[linerCount] = firPhiDp[i, j, linerIndex]; x[linerCount] = (float)(linerIndex * 0.25 + 0.25); z[linerCount] = rhoRaw[i, j, linerIndex]; linerCount++; } kdpData[i, j, k] = LeastSquareMethod(x, y); } } else { kdpData[i, j, k] = -999; } } } frmpg.nProgress = 75 + (int)((i + 1d) / nCountX * 10); } phiRaw = null; dbzRaw = null; rhoRaw = null; return(kdpData); }