public double[] WindowStat(int i, int j) { int index_p = 0; int new_r = 0, new_c = 0; var stat = new double[7]; var hsv = ToDouble(i, j); stat[0] = hsv[0]; stat[1] = hsv[1]; stat[2] = hsv[2]; double[][] window = new double[3][]; for (int c = 0; c < 3; c++) { window[c] = new double[9]; } for (int r = i - 1; r <= i + 1; r++) { for (int c = j - 1; c <= j + 1; c++) { new_r = r; new_c = c; if (r < 0) { new_r = 0; } if (r == _nrow) { new_r = _nrow - 1; } if (c < 0) { new_c = 0; } if (c == _ncol) { new_c = _ncol - 1; } var pp = ToDouble(new_r, new_c); window[0][index_p] = pp[0]; window[1][index_p] = pp[1]; window[2][index_p] = pp[2]; index_p++; } } stat[0] = window[0][5]; stat[1] = window[1][5]; stat[2] = window[2][5]; stat[3] = MyStatisticsMath.StandardDeviation(window[0]); stat[4] = MyStatisticsMath.StandardDeviation(window[1]); stat[5] = MyStatisticsMath.StandardDeviation(window[2]); stat[6] = window[1].Average(); return(stat); }
public My3DMat <float> StandardDeviation(My3DMat <float> source) { var mat = new My3DMat <float>(source.Size[0], source.Size[1], source.Size[2]); int nrow = source.Size[1]; int ncol = source.Size[2]; int ncol_1 = ncol - 1; int nrow_1 = nrow - 1; var mat_source = source.Value[0]; var vec5 = new float[5]; // the first and the last columns for (int r = 1; r < nrow - 1; r++) { vec5[0] = mat_source[r - 1][0]; vec5[1] = mat_source[r - 1][1]; vec5[2] = mat_source[r][1]; vec5[3] = mat_source[r + 1][1]; vec5[4] = mat_source[r + 1][0]; mat.Value[0][r][0] = MyStatisticsMath.StandardDeviation(vec5); vec5[0] = mat_source[r - 1][ncol_1]; vec5[1] = mat_source[r - 1][ncol_1 - 1]; vec5[2] = mat_source[r][ncol_1 - 1]; vec5[3] = mat_source[r + 1][ncol_1 - 1]; vec5[4] = mat_source[r + 1][ncol_1]; mat.Value[0][r][ncol_1] = MyStatisticsMath.StandardDeviation(vec5); } // the first and the last rows for (int c = 1; c < ncol - 1; c++) { vec5[0] = mat_source[0][c - 1]; vec5[1] = mat_source[1][c - 1]; vec5[2] = mat_source[1][c]; vec5[3] = mat_source[1][c + 1]; vec5[4] = mat_source[0][c + 1]; mat.Value[0][0][c] = MyStatisticsMath.StandardDeviation(vec5); vec5[0] = mat_source[nrow_1][c - 1]; vec5[1] = mat_source[nrow_1 - 1][c - 1]; vec5[2] = mat_source[nrow_1 - 1][c]; vec5[3] = mat_source[nrow_1 - 1][c + 1]; vec5[4] = mat_source[nrow_1][c + 1]; mat.Value[0][nrow_1][c] = MyStatisticsMath.StandardDeviation(vec5); } float[] vec8 = new float[8]; for (int r = 1; r < nrow - 1; r++) { for (int c = 1; c < ncol - 1; c++) { vec8[0] = mat_source[r - 1][c - 1]; vec8[1] = mat_source[r - 1][c]; vec8[2] = mat_source[r - 1][c + 1]; vec8[3] = mat_source[r][c - 1]; vec8[4] = mat_source[r][c + 1]; vec8[5] = mat_source[r + 1][c - 1]; vec8[6] = mat_source[r + 1][c]; vec8[7] = mat_source[r + 1][c + 1]; mat.Value[0][r][c] = MyStatisticsMath.StandardDeviation(vec8); } } return(mat); }
public My3DMat <double> StandardDeviation(My3DMat <double> source) { int nvar = source.Size[0]; int nrow = source.Size[1]; int ncol = source.Size[2]; var mat = new My3DMat <double>(nvar, nrow, ncol); int ncol_1 = ncol - 1; int nrow_1 = nrow - 1; for (int v = 0; v < nvar; v++) { var mat_source = source.Value[v]; var vec5 = new double[5]; // the first and the last columns for (int r = 1; r < nrow - 1; r++) { vec5[0] = mat_source[r - 1][0]; vec5[1] = mat_source[r - 1][1]; vec5[2] = mat_source[r][1]; vec5[3] = mat_source[r + 1][1]; vec5[4] = mat_source[r + 1][0]; mat.Value[v][r][0] = MyStatisticsMath.StandardDeviation(vec5); vec5[0] = mat_source[r - 1][ncol_1]; vec5[1] = mat_source[r - 1][ncol_1 - 1]; vec5[2] = mat_source[r][ncol_1 - 1]; vec5[3] = mat_source[r + 1][ncol_1 - 1]; vec5[4] = mat_source[r + 1][ncol_1]; mat.Value[v][r][ncol_1] = MyStatisticsMath.StandardDeviation(vec5); } // the first and the last rows for (int c = 1; c < ncol - 1; c++) { vec5[0] = mat_source[0][c - 1]; vec5[1] = mat_source[1][c - 1]; vec5[2] = mat_source[1][c]; vec5[3] = mat_source[1][c + 1]; vec5[4] = mat_source[0][c + 1]; mat.Value[v][0][c] = MyStatisticsMath.StandardDeviation(vec5); vec5[0] = mat_source[nrow_1][c - 1]; vec5[1] = mat_source[nrow_1 - 1][c - 1]; vec5[2] = mat_source[nrow_1 - 1][c]; vec5[3] = mat_source[nrow_1 - 1][c + 1]; vec5[4] = mat_source[nrow_1][c + 1]; mat.Value[v][nrow_1][c] = MyStatisticsMath.StandardDeviation(vec5); } double[] vec8 = new double[8]; for (int r = 1; r < nrow - 1; r++) { for (int c = 1; c < ncol - 1; c++) { vec8[0] = mat_source[r - 1][c - 1]; vec8[1] = mat_source[r - 1][c]; vec8[2] = mat_source[r - 1][c + 1]; vec8[3] = mat_source[r][c - 1]; vec8[4] = mat_source[r][c + 1]; vec8[5] = mat_source[r + 1][c - 1]; vec8[6] = mat_source[r + 1][c]; vec8[7] = mat_source[r + 1][c + 1]; mat.Value[v][r][c] = MyStatisticsMath.StandardDeviation(vec8); } } } return(mat); }
public override bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler) { FileStream fs = new FileStream(_OutputFileName, FileMode.Create, FileAccess.Write); BinaryWriter bw = new BinaryWriter(fs); var var_index = 0; var mat = Get3DMat(Source, ref var_index); int progress = 0; int nsteps = mat.Size[1]; var grid = ProjectService.Project.Model.Grid as RegularGrid; if (grid != null) { float[][] lonlat = null; if (CoornidateSystem == CS.GCS) { lonlat = grid.GetLonLatAxis(); } else if (CoornidateSystem == CS.PCS) { lonlat = grid.GetPCSAxis(); } var nrow = grid.RowCount; var ncol = grid.ColumnCount; var times = new float[nsteps]; if (mat.DateTimes != null) { for (int t = 0; t < nsteps; t++) { times[t] = (float)mat.DateTimes[t].ToOADate(); } } else { for (int t = 0; t < nsteps; t++) { times[t] = (float)DateTime.Now.AddDays(t).ToOADate(); } } bw.Write(nrow); bw.Write(ncol); bw.Write(nsteps); for (int i = 0; i < ncol; i++) { bw.Write(lonlat[0][i]); } for (int i = 0; i < nrow; i++) { bw.Write(lonlat[1][i]); } for (int t = 0; t < nsteps; t++) { bw.Write(times[t]); var vec = mat[var_index, t.ToString(), ":"]; bw.Write(vec.Max()); bw.Write(vec.Min()); bw.Write(vec.Average()); bw.Write(MyStatisticsMath.StandardDeviation(vec)); var mat_step = grid.ToMatrix <float>(vec, 0); for (int r = 0; r < nrow; r++) { for (int c = 0; c < ncol; c++) { bw.Write(mat_step[r][c]); } } progress = t * 100 / nsteps; cancelProgressHandler.Progress("Package_Tool", progress, "Processing step:" + t); } fs.Close(); bw.Close(); return(true); } else { return(false); } }