You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2019/04/16 12:51:08 UTC
[sis] branch geoapi-4.0 updated (6fd90af -> 8b63089)
This is an automated email from the ASF dual-hosted git repository.
desruisseaux pushed a change to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git.
from 6fd90af Add a "Satellite ground track" transform (internal only) for trying to make GCOM data a little bit more linear before to let LocalizationGridBuilder to its job.
new 0889fea Tuning of number of itetations and accuracy threshold.
new ccf389e Minor cleanup of debugging code.
new 8b63089 Store localization grids using single precision instead of double precision for reducing memory consumption. We presume that single precision is sufficient because the values stored in the `offsets` array are differences, not absolute coordinates. The absolute coordinates will be computed by adding `double` values to those offsets.
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../operation/builder/LocalizationGridBuilder.java | 16 +++++---
.../operation/builder/ResidualGrid.java | 8 ++--
.../transform/EllipsoidToCentricTransform.java | 4 +-
.../operation/transform/InterpolatedTransform.java | 44 +++++++++++-----------
.../builder/LocalizationGridBuilderTest.java | 6 ++-
.../operation/builder/ResidualGridTest.java | 2 +-
.../apache/sis/storage/geotiff/Localization.java | 2 +
.../java/org/apache/sis/internal/netcdf/Grid.java | 9 +++++
8 files changed, 54 insertions(+), 37 deletions(-)
[sis] 03/03: Store localization grids using single precision
instead of double precision for reducing memory consumption. We presume
that single precision is sufficient because the values stored in the
`offsets` array are differences,
not absolute coordinates. The absolute coordinates will be computed by
adding `double` values to those offsets.
Posted by de...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git
commit 8b63089122c4957c7a4851a15de1330ebbaac869
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Tue Apr 16 14:48:31 2019 +0200
Store localization grids using single precision instead of double precision for reducing memory consumption.
We presume that single precision is sufficient because the values stored in the `offsets` array are differences,
not absolute coordinates. The absolute coordinates will be computed by adding `double` values to those offsets.
---
.../operation/builder/LocalizationGridBuilder.java | 16 ++++++++++------
.../sis/referencing/operation/builder/ResidualGrid.java | 8 +++++---
.../operation/builder/LocalizationGridBuilderTest.java | 6 ++++--
.../referencing/operation/builder/ResidualGridTest.java | 2 +-
4 files changed, 20 insertions(+), 12 deletions(-)
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/LocalizationGridBuilder.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/LocalizationGridBuilder.java
index aca8b7e..206273e 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/LocalizationGridBuilder.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/LocalizationGridBuilder.java
@@ -131,7 +131,7 @@ public class LocalizationGridBuilder extends TransformBuilder {
* precision has been specified. The {@code sourceToGrid} transform shall not be applied on this value.
* This default precision may change in any future SIS version.
*/
- static final double DEFAULT_PRECISION = 1E-7;
+ private static final double DEFAULT_PRECISION = 1E-7;
/**
* The transform created by {@link #create(MathTransformFactory)}.
@@ -627,7 +627,7 @@ public class LocalizationGridBuilder extends TransformBuilder {
} else {
final int width = linear.gridSize(0);
final int height = linear.gridSize(1);
- final double[] residual = new double[SOURCE_DIMENSION * linear.gridLength];
+ final float[] residual = new float [SOURCE_DIMENSION * linear.gridLength];
final double[] grid = new double[SOURCE_DIMENSION * width];
double gridPrecision = precision;
try {
@@ -659,10 +659,14 @@ public class LocalizationGridBuilder extends TransformBuilder {
tmp[0] = 0;
tmp[1] = y;
linear.getControlRow(tmp, grid); // Expected positions.
- coordToGrid.transform(grid, 0, residual, k, width); // As grid coordinate.
- for (int x=0; x<width; x++) {
- isLinear &= (residual[k++] -= x) <= gridPrecision;
- isLinear &= (residual[k++] -= y) <= gridPrecision;
+ coordToGrid.transform(grid, 0, grid, 0, width); // As grid coordinate.
+ for (int i=0,x=0; x<width; x++) {
+ final double dx = grid[i++] - x;
+ final double dy = grid[i++] - y;
+ isLinear &= (dx <= gridPrecision);
+ isLinear &= (dy <= gridPrecision);
+ residual[k++] = (float) dx;
+ residual[k++] = (float) dy;
}
}
} catch (TransformException e) {
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/ResidualGrid.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/ResidualGrid.java
index 4cf8672..46565c3 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/ResidualGrid.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/ResidualGrid.java
@@ -50,7 +50,7 @@ final class ResidualGrid extends DatumShiftGrid<Dimensionless,Dimensionless> {
/**
* For cross-version compatibility.
*/
- private static final long serialVersionUID = -713276314000661839L;
+ private static final long serialVersionUID = 5207799661806374259L;
/**
* Number of source dimensions of the residual grid.
@@ -111,8 +111,10 @@ final class ResidualGrid extends DatumShiftGrid<Dimensionless,Dimensionless> {
/**
* The residual data, as translations to apply on the result of affine transform.
* In this flat array, index of target dimension varies fastest, then column index, then row index.
+ * Single precision instead of double is presumed sufficient because this array contains only differences,
+ * not absolute positions. Absolute positions will be computed by adding {@code double} values to those offsets.
*/
- private final double[] offsets;
+ private final float[] offsets;
/**
* Conversion from translated coordinates (after the datum shift has been applied) to "real world" coordinates.
@@ -139,7 +141,7 @@ final class ResidualGrid extends DatumShiftGrid<Dimensionless,Dimensionless> {
* @param precision desired precision of inverse transformations in unit of grid cells.
*/
ResidualGrid(final LinearTransform sourceToGrid, final LinearTransform gridToTarget,
- final int nx, final int ny, final double[] residuals, final double precision)
+ final int nx, final int ny, final float[] residuals, final double precision)
{
super(Units.UNITY, sourceToGrid, new int[] {nx, ny}, true, Units.UNITY);
this.gridToTarget = gridToTarget;
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/builder/LocalizationGridBuilderTest.java b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/builder/LocalizationGridBuilderTest.java
index 158d283..803cefa 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/builder/LocalizationGridBuilderTest.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/builder/LocalizationGridBuilderTest.java
@@ -84,15 +84,17 @@ public final strictfp class LocalizationGridBuilderTest extends TransformTestCas
public void testQuadratic() throws FactoryException, TransformException {
final AffineTransform reference = new AffineTransform(20, -30, 5, -4, -20, 8);
final LocalizationGridBuilder builder = builder(reference, 5, 4);
+ builder.setDesiredPrecision(1E-6);
transform = builder.create(null);
- tolerance = 1E-13;
+ tolerance = 2E-7;
isInverseTransformSupported = false;
verifyQuadratic();
/*
* The tolerance value specified here should be approximately equal to ResidualGrid.accuracy.
+ * That value was specified in the call to builder.setDesiredPrecision(1E-6).
*/
- tolerance = LocalizationGridBuilder.DEFAULT_PRECISION;
+ tolerance = 1E-6;
isInverseTransformSupported = true;
verifyQuadratic();
}
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/builder/ResidualGridTest.java b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/builder/ResidualGridTest.java
index a5ba367..189348d 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/builder/ResidualGridTest.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/builder/ResidualGridTest.java
@@ -47,7 +47,7 @@ public final strictfp class ResidualGridTest extends TestCase {
* The grid has no "source to grid" or "grid to CRS" transformations.
*/
public ResidualGridTest() {
- grid = new ResidualGrid(MathTransforms.identity(2), MathTransforms.identity(2), 3, 4, new double[] {
+ grid = new ResidualGrid(MathTransforms.identity(2), MathTransforms.identity(2), 3, 4, new float[] {
0,2 , 1,2 , 2,1,
1,3 , 2,2 , 1,1,
0,4 , 2,3 , 3,2,
[sis] 01/03: Tuning of number of itetations and accuracy threshold.
Posted by de...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git
commit 0889fea803b3d3a11c39746a2392150b3d3656dd
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Tue Apr 16 11:51:58 2019 +0200
Tuning of number of itetations and accuracy threshold.
---
.../transform/EllipsoidToCentricTransform.java | 4 ++--
.../operation/transform/InterpolatedTransform.java | 19 ++++++++-----------
.../org/apache/sis/storage/geotiff/Localization.java | 2 ++
.../java/org/apache/sis/internal/netcdf/Grid.java | 9 +++++++++
4 files changed, 21 insertions(+), 13 deletions(-)
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/EllipsoidToCentricTransform.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/EllipsoidToCentricTransform.java
index d3ac78b..f756550 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/EllipsoidToCentricTransform.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/EllipsoidToCentricTransform.java
@@ -710,11 +710,11 @@ next: while (--numPts >= 0) {
* If this code is used on a planet with high eccentricity,
* the φ value may need to be improved by an iterative method.
*/
- for (int it=0; it<Formulas.MAXIMUM_ITERATIONS; it++) {
+ for (int it = Formulas.MAXIMUM_ITERATIONS; it >= 0; it--) {
final double sinφ = sin(φ);
final double ν = 1/sqrt(1 - eccentricitySquared * (sinφ*sinφ));
final double Δφ = φ - (φ = atan((Z + eccentricitySquared * ν * sinφ) / p));
- if (!(abs(Δφ) >= Formulas.ANGULAR_TOLERANCE * (PI/180) * 0.25)) { // Use ! for accepting NaN.
+ if (!(abs(Δφ) >= Formulas.ANGULAR_TOLERANCE * (PI/180) * 0.25)) { // Use ! for accepting NaN.
dstPts[dstOff++] = atan2(Y, X);
dstPts[dstOff++] = φ;
if (withHeight) {
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/InterpolatedTransform.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/InterpolatedTransform.java
index 2044551..a70f625 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/InterpolatedTransform.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/InterpolatedTransform.java
@@ -433,13 +433,9 @@ public class InterpolatedTransform extends DatumShiftTransform {
* Maximum number of iterations. This is set to a higher value than {@link Formulas#MAXIMUM_ITERATIONS} because
* the data used in {@link InterpolatedTransform} grid may come from anywhere, in particular localization grids
* in netCDF files. Deformations in those grids may be much higher than e.g. {@link DatumShiftTransform} grids.
- * We observed that inverse transformations may converge slowly if the grid is far from a linear approximation.
- * It happens when the grids have very high {@link DatumShiftGrid#interpolateInCell(double, double, double[])}
- * values, for example close to 1000 while we usually expect values smaller than 1. Behavior with such grids may
- * be unpredictable, sometime with the {@code abs(xi - ox)} or {@code abs(yi - oy)} errors staying high for a
- * long time before to suddenly fall to zero.
+ * The algorithm in this class converges more slowly in area with very strong curvature.
*/
- private static final int MAXIMUM_ITERATIONS = Formulas.MAXIMUM_ITERATIONS * 4;
+ private static final int MAXIMUM_ITERATIONS = Formulas.MAXIMUM_ITERATIONS * 2;
/**
* The enclosing transform.
@@ -600,14 +596,15 @@ public class InterpolatedTransform extends DatumShiftTransform {
* 1E-7 accuracy (relative to cell size) if we don't really know what the answer should be.
*/
if (--it < 0) {
- if (it < -1) {
+ if (it == -1) {
+ if (forward.grid.isCellInGrid(xi, yi)) {
+ throw new TransformException(Resources.format(Resources.Keys.NoConvergence));
+ }
+ tol = 0.5;
+ } else {
xi = yi = Double.NaN;
break;
}
- if (forward.grid.isCellInGrid(xi, yi)) {
- throw new TransformException(Resources.format(Resources.Keys.NoConvergence));
- }
- tol = 0.5;
}
}
/*
diff --git a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/Localization.java b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/Localization.java
index 66f5278..799cea5 100644
--- a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/Localization.java
+++ b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/Localization.java
@@ -52,6 +52,8 @@ final class Localization {
/**
* The desired precision of coordinate transformations in units of pixels.
* This is an arbitrary value that may be adjusted in any future SIS version.
+ *
+ * @todo compute the value based on the cell size in order to have an accuracy of about 1 cm on Earth.
*/
private static final double PRECISION = 1E-6;
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Grid.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Grid.java
index ac5301c..ea4c3d2 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Grid.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Grid.java
@@ -439,6 +439,15 @@ findFree: for (int srcDim : axis.sourceDimensions) {
Linearizer.applyTo(linearizers, factory, grid, gridAxes);
}
/*
+ * There is usually a one-to-one relationship between localization grid cells and image pixels.
+ * Consequently an accuracy set to a fraction of cell should be enough.
+ *
+ * TODO: take in account the case where Variable.Adjustment.dataToGridIndices() returns a value
+ * smaller than 1. For now we set the desired precision to a value 10 times smaller in order to
+ * take in account the case where dataToGridIndices() returns 0.1.
+ */
+ grid.setDesiredPrecision(0.001);
+ /*
* Replace the first transform by the two-dimensional localization grid and
* remove the other transform. Removals need to be done in arrays too.
*/
[sis] 02/03: Minor cleanup of debugging code.
Posted by de...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git
commit ccf389e934071da3d273ed56d6ce7581188d6fb2
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Tue Apr 16 14:25:43 2019 +0200
Minor cleanup of debugging code.
---
.../operation/transform/InterpolatedTransform.java | 25 +++++++++++-----------
1 file changed, 13 insertions(+), 12 deletions(-)
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/InterpolatedTransform.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/InterpolatedTransform.java
index a70f625..936e070 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/InterpolatedTransform.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/InterpolatedTransform.java
@@ -416,7 +416,9 @@ public class InterpolatedTransform extends DatumShiftTransform {
private static final long serialVersionUID = 4335801994727826360L;
/**
- * Set to {@code true} for debugging.
+ * Whether to enable debugging. If {@code true}, additional but very costly {@code assert} statements will
+ * be enabled, and some information will be printed to the standard output stream. Enabling debugging slows
+ * down considerably the transformations; it should be done only for small set of test data.
*/
private static final boolean DEBUG = false;
@@ -569,19 +571,18 @@ public class InterpolatedTransform extends DatumShiftTransform {
final double dx = (ex * m11 - ey * m01) / det; // Errors in source units.
final double dy = (ey * m00 - ex * m10) / det;
if (DEBUG) {
- Matrix m = forward.grid.derivativeInCell(xi, yi);
- assert m.getElement(0,0) == m00;
- assert m.getElement(0,1) == m01;
- assert m.getElement(1,0) == m10;
- assert m.getElement(1,1) == m11;
-
- m = Matrices.inverse(m);
- double[] c = ((MatrixSIS) m).multiply(new double[] {ex, ey});
- assert Math.abs(dx - c[0]) < 1E-5 : Arrays.toString(c) + " : " + dx;
- assert Math.abs(dy - c[1]) < 1E-5 : Arrays.toString(c) + " : " + dy;
-
System.out.printf(" source=(%9.3f %9.3f) target=(%9.3f %9.3f) error=(%11.6f %11.6f) → (%11.6f %11.6f)%n",
xi, yi, (xi+tx), (yi+ty), ex, ey, dx, dy);
+
+ Matrix m = forward.grid.derivativeInCell(xi, yi);
+ assert m.getElement(0,0) == m00 & // Expect `m` computed in exact same way.
+ m.getElement(0,1) == m01 &
+ m.getElement(1,0) == m10 &
+ m.getElement(1,1) == m11 : m;
+
+ final double[] d = Matrices.inverse(m).multiply(new double[] {ex, ey});
+ assert Math.abs(dx - d[0]) < tol &
+ Math.abs(dy - d[1]) < tol : Arrays.toString(d) + " versus [" + dx + ", " + dy + "]";
}
xi -= dx;
yi -= dy;