private double?AdjustedRmsZ(Grid2DPhenotype other) { RegularGrid2D adjusted_grid = AdjustedGrid(other); double? adjustedRmsZ = grid.RmsDifference(adjusted_grid); return(adjustedRmsZ); }
/// <summary> /// Divide the Grids into tiles, and compute the adjusted height fitness /// for each tile. /// </summary> /// <param name="other">The grid to be compared against this.</param> /// <returns>An array of tile fitnesses</returns> private double[] CompareTiledAdjustedHeight(Grid2DPhenotype other) { List <double> result = new List <double>(); const int numTilesI = 2; const int numTilesJ = 2; RegularGrid2D adjusted_grid = AdjustedGrid(other); int tileSizeI = this.grid.SizeI / numTilesI; int tileSizeJ = this.grid.SizeJ / numTilesJ; for (int tileI = 0; tileI < numTilesI; ++tileI) { int beginI = tileI * tileSizeI; int endI = (tileI + 1) * tileSizeI; for (int tileJ = 0; tileJ < numTilesJ; ++tileJ) { int beginJ = tileJ * tileSizeJ; int endJ = (tileJ + 1) * tileSizeJ; double?adjustedRmsZ = grid.RmsDifference(adjusted_grid, beginI, endI, beginJ, endJ); if (adjustedRmsZ.HasValue) { result.Add(adjustedRmsZ.Value); } } } return(result.ToArray()); }
public double this[int i, int j] { set { if (grid == null) { // TODO: Assert on complete set of parameters here grid = new RegularGrid2D(xOrigin, yOrigin, iInc, jInc, iNum, jNum); } grid[i, j] = value; } }
private RegularGrid2D AdjustedGrid(Grid2DPhenotype other) { double mean = grid.Mean(); double other_mean = other.Grid.Mean(); double difference = other_mean - mean; RegularGrid2D adjusted_grid = (RegularGrid2D)other.Grid.Clone(); for (int i = 0; i < adjusted_grid.SizeI; ++i) { for (int j = 0; j < adjusted_grid.SizeJ; ++j) { adjusted_grid[i, j] -= difference; } } return(adjusted_grid); }
public IRegularGrid2D CreatePartialDerivativeJGrid() { RegularGrid2D result = new RegularGrid2D(Origin, Spacing, SizeI, SizeJ); for (int i = 0; i < SizeI; ++i) { for (int j = 0; j < SizeJ; ++j) { //int trailing = Math.Max(j - 1, 0); int trailing = j; int leading = Math.Min(j + 1, SizeJ - 1); double h = (leading - trailing) * spacing.DeltaY; if (h > 0.0) { result[i, j] = (this[i, leading] - this[i, trailing]) / h; } else { result[i, j] = null; } } } return(result); }
public static RegularGrid2D Create(StreamReader reader) { RegularGrid2D grid = null; try { // Line 1 - the identifier string header1 = reader.ReadLine(); if (!header1.StartsWith("DSAA")) { return(null); } // Line 2 - the number of points along the I and J axes string header2 = reader.ReadLine(); string[] fields2 = header2.Split(); int sizeI = int.Parse(fields2[0]); int sizeJ = int.Parse(fields2[1]); // Line 3 - the extent in the I direction string header3 = reader.ReadLine(); string[] fields3 = header3.Split(); double minX = double.Parse(fields3[0]); double maxX = double.Parse(fields3[1]); // Line 4 - the extent in the J direction string header4 = reader.ReadLine(); string[] fields4 = header4.Split(); double minY = double.Parse(fields4[0]); double maxY = double.Parse(fields4[1]); // Line 4 - the extent in the J direction string header5 = reader.ReadLine(); string[] fields5 = header5.Split(); double minZ = double.Parse(fields5[0]); double maxZ = double.Parse(fields5[1]); double spacingX = (maxX - minX) / (sizeI - 1); double spacingY = (maxY - minY) / (sizeJ - 1); grid = new RegularGrid2D(minX, minY, spacingX, spacingY, sizeI, sizeJ); string line; int counter = 0; while ((line = reader.ReadLine()) != null) { string[] fields = line.Split(); foreach (string field in fields) { double z; if (double.TryParse(field, out z)) { int i = counter % sizeI; int j = counter / sizeI; if (z == goldenNullValue || z < minZ || z > maxZ) { grid[i, j] = null; } else { grid[i, j] = z; } ++counter; } } } } catch (System.FormatException) { grid = null; } return(grid); }
public RegularGrid2D(RegularGrid2D other) { this.origin = other.origin; this.spacing = other.spacing; this.zs = (double?[, ])other.zs.Clone(); }
public IGridCoordinateTransformation CreateHypsometricGrid() { Debug.Assert(MinZ.HasValue); Debug.Assert(MaxZ.HasValue); // Build a histogram of the point elevations const int numClasses = 100; List <int> histogram = new List <int>(numClasses); for (int i = 0; i < numClasses; ++i) { histogram.Add(0); } Debug.Assert(histogram.Count == numClasses); double minZ = MinZ.Value; double maxZ = MaxZ.Value; double classInterval = (maxZ - minZ) / numClasses; // Now accumulate the histogram foreach (double?z in zs) { if (z.HasValue) { // Compute the bin number from the z value double offset = z.Value - minZ; int index = (int)Math.Floor(offset / classInterval); // Put the maxZ values into the top class if (index == histogram.Count) { Debug.Assert(z == maxZ); --index; } Debug.Assert(index >= 0 && index < histogram.Count); ++histogram[index]; } } // Now convert to a cumulative histogram for (int i = 1; i < histogram.Count; ++i) { histogram[i] += histogram[i - 1]; } // Create the result grid RegularGrid2D result = new RegularGrid2D(Origin, Spacing, SizeI, SizeJ); for (int i = 0; i < SizeI; ++i) { for (int j = 0; j < SizeJ; ++j) { double?z = zs[i, j]; if (z.HasValue) { double offset = z.Value - minZ; int index = (int)Math.Floor(offset / classInterval); // Put the maxZ values into the top class if (index == histogram.Count) { Debug.Assert(z == maxZ); --index; } int lower = (index > 0) ? histogram[index - 1] : 0; int higher = histogram[index]; double classOffset = offset - (index * classInterval); double classOffsetProportion = classOffset / classInterval; result[i, j] = lower + classOffsetProportion * (higher - lower); } else { result[i, j] = null; } } } return(result); }