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/01/30 12:15:58 UTC

[sis] branch geoapi-4.0 updated (08904cd -> bc48507)

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 08904cd  Range of valid values provided by the UCAR library are converted values, not packed values.
     new 244183a  Move a helper method.
     new bc48507  Control more clearly order of axes read from a netCDF file.

The 2 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:
 .../apache/sis/coverage/grid/GridDerivation.java   | 25 +++----------------
 .../org/apache/sis/coverage/grid/GridExtent.java   | 18 ++++++++++++++
 .../java/org/apache/sis/internal/netcdf/Axis.java  |  6 ++---
 .../java/org/apache/sis/internal/netcdf/Grid.java  | 28 +++++++++++-----------
 .../sis/internal/netcdf/impl/ChannelDecoder.java   |  3 ++-
 .../apache/sis/internal/netcdf/impl/GridInfo.java  |  9 +++----
 .../sis/internal/netcdf/ucar/GridWrapper.java      | 18 +++++++++++++-
 .../apache/sis/storage/netcdf/MetadataReader.java  | 11 ++++-----
 .../org/apache/sis/internal/netcdf/GridTest.java   | 12 +++++-----
 9 files changed, 73 insertions(+), 57 deletions(-)


[sis] 02/02: Control more clearly order of axes read from a netCDF file.

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 bc48507775ef93f471df1e29425c46b9af649acb
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Wed Jan 30 13:00:05 2019 +0100

    Control more clearly order of axes read from a netCDF file.
---
 .../java/org/apache/sis/internal/netcdf/Axis.java  |  6 ++---
 .../java/org/apache/sis/internal/netcdf/Grid.java  | 28 +++++++++++-----------
 .../sis/internal/netcdf/impl/ChannelDecoder.java   |  3 ++-
 .../apache/sis/internal/netcdf/impl/GridInfo.java  |  9 +++----
 .../sis/internal/netcdf/ucar/GridWrapper.java      | 18 +++++++++++++-
 .../apache/sis/storage/netcdf/MetadataReader.java  | 11 ++++-----
 .../org/apache/sis/internal/netcdf/GridTest.java   | 12 +++++-----
 7 files changed, 52 insertions(+), 35 deletions(-)

diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Axis.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Axis.java
index ed97e08..12b6378 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Axis.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Axis.java
@@ -410,15 +410,15 @@ public final class Axis extends NamedElement implements Comparable<Axis> {
 
     /**
      * Compares this axis with the given axis for ordering based on the dimensions declared in a variable.
-     * This is used for sorting axes in the same order than the dimension order on the variable using axes.
-     * This order is not necessarily the same than the order in which variables are listed in the netCDF file.
+     * This is used for sorting axes in the reverse order than the dimension order on the variable using axes.
+     * This order is not necessarily related to the order in which axis variables are listed in the netCDF file.
      *
      * @param  other  the other axis to compare to this axis.
      * @return -1 if this axis should be before {@code other}, +1 if it should be after.
      */
     @Override
     public int compareTo(final Axis other) {
-        return sourceDimensions[0] - other.sourceDimensions[0];
+        return other.sourceDimensions[0] - sourceDimensions[0];         // Reverse of netCDF order.
     }
 
     /**
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 b957391..28585d3 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
@@ -135,11 +135,12 @@ public abstract class Grid extends NamedElement {
     /**
      * Returns the axes of the coordinate reference system. The size of this array is expected equals to the
      * value returned by {@link #getTargetDimensions()}, but the caller should be robust to inconsistencies.
-     * The axis order is as declared in the netCDF file (reverse of "natural" order).
+     * The axis order is CRS order (reverse of netCDF order) for consistency with the common practice in the
+     * {@code "coordinates"} attribute.
      *
      * <p>This method returns a direct reference to the cached array; do not modify.</p>
      *
-     * @return the CRS axes, in netCDF order (reverse of "natural" order).
+     * @return the CRS axes, in "natural" order (reverse of netCDF order).
      * @throws IOException if an I/O operation was necessary but failed.
      * @throws DataStoreException if a logical error occurred.
      * @throws ArithmeticException if the size of an axis exceeds {@link Integer#MAX_VALUE}, or other overflow occurs.
@@ -183,8 +184,9 @@ public abstract class Grid extends NamedElement {
 
     /**
      * Creates the axes to be returned by {@link #getAxes()}. This method is invoked only once when first needed.
+     * Axes shall be returned in the order they will appear in the Coordinate Reference System.
      *
-     * @return the CRS axes, in netCDF order (reverse of "natural" order).
+     * @return the CRS axes, in "natural" order (reverse of CRS order).
      * @throws IOException if an I/O operation was necessary but failed.
      * @throws DataStoreException if a logical error occurred.
      * @throws ArithmeticException if the size of an axis exceeds {@link Integer#MAX_VALUE}, or other overflow occurs.
@@ -204,9 +206,8 @@ public abstract class Grid extends NamedElement {
         if (!isCRSDetermined) try {
             isCRSDetermined = true;                             // Set now for avoiding new attempts if creation fail.
             final List<CRSBuilder<?,?>> builders = new ArrayList<>();
-            final Axis[] axes = getAxes();
-            for (int i=axes.length; --i >= 0;) {                // NetCDF order is reverse of "natural" order.
-                CRSBuilder.dispatch(builders, axes[i]);
+            for (final Axis axis : getAxes()) {
+                CRSBuilder.dispatch(builders, axis);
             }
             final SingleCRS[] components = new SingleCRS[builders.size()];
             for (int i=0; i < components.length; i++) {
@@ -229,6 +230,7 @@ public abstract class Grid extends NamedElement {
      * if a dimension has unlimited length. The dimension names are informative only.
      *
      * @param  axes  value of {@link #getAxes()}. Should be the same as {@link #axes}.
+     *               Order does not matter for this method.
      */
     @SuppressWarnings("fallthrough")
     private GridExtent getExtent(final Axis[] axes) {
@@ -273,7 +275,7 @@ public abstract class Grid extends NamedElement {
     public final GridGeometry getGridGeometry(final Decoder decoder) throws IOException, DataStoreException {
         if (!isGeometryDetermined) try {
             isGeometryDetermined = true;        // Set now for avoiding new attempts if creation fail.
-            final Axis[] axes = getAxes();      // In netCDF order (reverse of "natural" order).
+            final Axis[] axes = getAxes();      // In CRS order (reverse of netCDF order).
             /*
              * Creates the "grid to CRS" transform. The number of columns is the number of dimensions in the grid
              * (the source) +1, and the number of rows is the number of dimensions in the CRS (the target) +1.
@@ -285,10 +287,9 @@ public abstract class Grid extends NamedElement {
             final List<MathTransform> nonLinears = new ArrayList<>(axes.length);
             final Matrix affine = Matrices.createZero(lastTgtDim + 1, lastSrcDim + 1);
             affine.setElement(lastTgtDim--, lastSrcDim--, 1);
-            for (int i=axes.length; --i >= 0;) {
-                final int tgtDim = lastTgtDim - i;                          // Convert from netCDF to "natural" order.
-                if (!axes[i].trySetTransform(affine, lastSrcDim, tgtDim, nonLinears)) {
-                    deferred[nonLinears.size() - 1] = i;
+            for (int tgtDim=0; tgtDim < axes.length; tgtDim++) {
+                if (!axes[tgtDim].trySetTransform(affine, lastSrcDim, tgtDim, nonLinears)) {
+                    deferred[nonLinears.size() - 1] = tgtDim;
                 }
             }
             /*
@@ -299,8 +300,8 @@ public abstract class Grid extends NamedElement {
             final int[] sourceDimensions = new int[nonLinears.size()];
             Arrays.fill(sourceDimensions, -1);
             for (int i=0; i<sourceDimensions.length; i++) {
-                final int d = deferred[i];
-                final Axis axis = axes[d];
+                final int tgtDim = deferred[i];
+                final Axis axis = axes[tgtDim];
 findFree:       for (int srcDim : axis.sourceDimensions) {
                     srcDim = lastSrcDim - srcDim;
                     for (int j=affine.getNumRow(); --j>=0;) {
@@ -309,7 +310,6 @@ findFree:       for (int srcDim : axis.sourceDimensions) {
                         }
                     }
                     sourceDimensions[i] = srcDim;
-                    final int tgtDim = lastTgtDim - d;
                     affine.setElement(tgtDim, srcDim, 1);
                     break;
                 }
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java
index 0620282..5e845ed 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java
@@ -943,7 +943,8 @@ nextVar:    for (final VariableInfo variable : variables) {
                  * incomplete attributes, so we check for other dimensions even if the above loop did some work.
                  */
                 int mixedFlag = axes.isEmpty() ? 0 : 1;
-                for (final Dimension dimension : variable.dimensions) {
+                for (int i=variable.dimensions.length; --i >= 0;) {                     // Reverse of netCDF order.
+                    final Dimension dimension = variable.dimensions[i];
                     if (usedDimensions.add(dimension)) {
                         final List<VariableInfo> axis = dimToAxes.get(dimension);       // Should have only 1 element.
                         if (axis == null) {
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/GridInfo.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/GridInfo.java
index 2a03a29..8553a30 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/GridInfo.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/GridInfo.java
@@ -86,7 +86,8 @@ final class GridInfo extends Grid {
 
     /**
      * Describes the output values calculated by the function converting grid indices to geodetic coordinates.
-     * They are the coordinate values expressed in the CRS.
+     * They are the coordinate values expressed in the CRS. Order should be the order to be declared in the CRS.
+     * This is often, but not necessarily, the reverse order than the {@link #domain} dimension.
      */
     private final VariableInfo[] range;
 
@@ -100,7 +101,7 @@ final class GridInfo extends Grid {
      * The {@code domain} and {@code range} arrays often have the same length, but not necessarily.
      *
      * @param  domain    describes the input values of the "grid to CRS" conversion, in netCDF order.
-     * @param  range     the output values of the "grid to CRS" conversion.
+     * @param  range     the output values of the "grid to CRS" conversion, in CRS order as much as possible.
      * @param  sortAxes  whether axes should be sorted instead than relying on the order found in netCDF file.
      */
     GridInfo(final Dimension[] domain, final VariableInfo[] range, final boolean sortAxes) {
@@ -190,7 +191,7 @@ final class GridInfo extends Grid {
      * In particular, the relationship is not straightforward when the coordinate system contains
      * "two-dimensional axes" (in {@link ucar.nc2.dataset.CoordinateAxis2D} sense).</p>
      *
-     * @return the CRS axes, in netCDF order (reverse of "natural" order).
+     * @return the CRS axes, in "natural" order (reverse of netCDF order).
      * @throws IOException if an I/O operation was necessary but failed.
      * @throws DataStoreException if a logical error occurred.
      * @throws ArithmeticException if the size of an axis exceeds {@link Integer#MAX_VALUE}, or other overflow occurs.
@@ -199,7 +200,7 @@ final class GridInfo extends Grid {
     protected Axis[] createAxes() throws IOException, DataStoreException {
         /*
          * Process the variables in the order the appear in the sequence of bytes that make the netCDF files.
-         * This is often the same order than the indices, but not necessarily. The intent is to reduce the
+         * This is often the reverse order of range indices, but not necessarily. The intent is to reduce the
          * amount of disk seek operations. Data loading may happen in this method through Axis constructor.
          */
         final SortedMap<VariableInfo,Integer> variables = new TreeMap<>();
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/GridWrapper.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/GridWrapper.java
index 7bd7b59..1f78edd 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/GridWrapper.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/GridWrapper.java
@@ -123,7 +123,7 @@ final class GridWrapper extends Grid {
      * In particular, the relationship is not straightforward when the coordinate system contains instances
      * of {@link CoordinateAxis2D}.</p>
      *
-     * @return the CRS axes, in netCDF order (reverse of "natural" order).
+     * @return the CRS axes, in "natural" order (reverse of netCDF order).
      * @throws IOException if an I/O operation was necessary but failed.
      * @throws DataStoreException if a logical error occurred.
      * @throws ArithmeticException if the size of an axis exceeds {@link Integer#MAX_VALUE}, or other overflow occurs.
@@ -184,6 +184,22 @@ final class GridWrapper extends Grid {
             axes[targetDim] = new Axis(abbreviation, axis.getPositive(),
                     ArraysExt.resize(indices, i), ArraysExt.resize(sizes, i), decoder.getWrapperFor(axis));
         }
+        /*
+         * We want axes in "natural" order. But the netCDF UCAR library sometime provides axes already
+         * in that order and sometime in reverse order (netCDF order). I'm not aware of a reliable way
+         * to determine whether axis order provided by UCAR library needs to be reverted since I don't
+         * know what determines that order (the file format? the presence of "coordinates" attribute?).
+         * For now we compare axis order with dimension order, and if the axis contains all dimensions
+         * in the same order we presume that this is the "netCDF" order (as opposed to a "coordinates"
+         * attribute value order).
+         */
+        for (int i = Math.min(domain.size(), range.size()); --i >= 0;) {
+            final List<Dimension> dimensions = range.get(i).getDimensions();
+            if (dimensions.size() != 1 || !dimensions.get(0).equals(domain.get(i))) {
+                return axes;
+            }
+        }
+        ArraysExt.reverse(axes);
         return axes;
     }
 }
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java b/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
index 056ee2a..73d31b5 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
@@ -715,9 +715,8 @@ split:  while ((start = CharSequences.skipLeadingWhitespaces(value, start, lengt
      */
     private void addSpatialRepresentationInfo(final Grid cs) throws IOException, DataStoreException {
         final Axis[] axes = cs.getAxes();
-        for (int i=axes.length; i>0;) {
-            final int dim = axes.length - i;
-            final Axis axis = axes[--i];
+        for (int i=0; i<axes.length; i++) {
+            final Axis axis = axes[i];
             /*
              * Axes usually have exactly one dimension. However some netCDF axes are backed by a two-dimensional
              * conversion grid. In such case, our Axis constructor should have ensured that the first element in
@@ -725,7 +724,7 @@ split:  while ((start = CharSequences.skipLeadingWhitespaces(value, start, lengt
              * oriented toward the axis direction.
              */
             if (axis.getDimension() >= 1) {
-                setAxisSize(dim, axis.getSize());
+                setAxisSize(i, axis.getSize());
             }
             final AttributeNames.Dimension attributeNames;
             switch (axis.abbreviation) {
@@ -736,7 +735,7 @@ split:  while ((start = CharSequences.skipLeadingWhitespaces(value, start, lengt
                 default : continue;
             }
             final DimensionNameType name = attributeNames.DEFAULT_NAME_TYPE;
-            setAxisName(dim, name);
+            setAxisName(i, name);
             final String res = stringValue(attributeNames.RESOLUTION);
             if (res != null) try {
                 /*
@@ -757,7 +756,7 @@ split:  while ((start = CharSequences.skipLeadingWhitespaces(value, start, lengt
                         warning(Errors.Keys.CanNotAssignUnitToDimension_2, name, units, e);
                     }
                 }
-                setAxisResolution(dim, value, units);
+                setAxisResolution(i, value, units);
             } catch (NumberFormatException e) {
                 warning(e);
             }
diff --git a/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/GridTest.java b/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/GridTest.java
index b8f7280..e31292e 100644
--- a/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/GridTest.java
+++ b/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/GridTest.java
@@ -81,8 +81,8 @@ public strictfp class GridTest extends TestCase {
     public void testAxes2D() throws IOException, DataStoreException {
         final Axis[] axes = getSingleton(filter(selectDataset(TestData.NETCDF_2D_GEOGRAPHIC).getGridGeometries())).getAxes();
         assertEquals(2, axes.length);
-        final Axis x = axes[1];
-        final Axis y = axes[0];
+        final Axis x = axes[0];
+        final Axis y = axes[1];
 
         assertEquals('λ', x.abbreviation);
         assertEquals('φ', y.abbreviation);
@@ -105,10 +105,10 @@ public strictfp class GridTest extends TestCase {
     public void testAxes4D() throws IOException, DataStoreException {
         final Axis[] axes = getSingleton(filter(selectDataset(TestData.NETCDF_4D_PROJECTED).getGridGeometries())).getAxes();
         assertEquals(4, axes.length);
-        final Axis x = axes[3];
-        final Axis y = axes[2];
-        final Axis z = axes[1];
-        final Axis t = axes[0];
+        final Axis x = axes[0];
+        final Axis y = axes[1];
+        final Axis z = axes[2];
+        final Axis t = axes[3];
 
         assertEquals('x', x.abbreviation);
         assertEquals('y', y.abbreviation);


[sis] 01/02: Move a helper method.

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 244183a42ffe3598848ad5f18f1399d0305953b8
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Wed Jan 30 11:23:19 2019 +0100

    Move a helper method.
---
 .../apache/sis/coverage/grid/GridDerivation.java   | 25 +++-------------------
 .../org/apache/sis/coverage/grid/GridExtent.java   | 18 ++++++++++++++++
 2 files changed, 21 insertions(+), 22 deletions(-)

diff --git a/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridDerivation.java b/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridDerivation.java
index e4ffb09..0e5adff 100644
--- a/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridDerivation.java
+++ b/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridDerivation.java
@@ -685,7 +685,7 @@ public class GridDerivation {
      * grid coordinates, 1 maps to {@linkplain GridExtent#getHigh(int) high grid coordinates} and 0.5 maps the median point.
      * The slicing is applied on all dimensions except the specified dimensions to keep.
      *
-     * @param  sliceRatio        the ration to apply on all grid dimensions except the ones to keep.
+     * @param  sliceRatio        the ratio to apply on all grid dimensions except the ones to keep.
      * @param  dimensionsToKeep  the grid dimension to keep unchanged.
      * @return {@code this} for method call chaining.
      * @throws IncompleteGridGeometryException if the base grid geometry has no extent.
@@ -697,32 +697,13 @@ public class GridDerivation {
         subGridSetter = "sliceByRatio";
         final GridExtent extent = (baseExtent != null) ? baseExtent : base.getExtent();
         final GeneralDirectPosition slicePoint = new GeneralDirectPosition(extent.getDimension());
-        baseExtent = sliceByRatio(extent, slicePoint, sliceRatio, dimensionsToKeep);
+        baseExtent = extent.sliceByRatio(slicePoint, sliceRatio, dimensionsToKeep);
         if (subsampledExtent != null) {
-            subsampledExtent = sliceByRatio(subsampledExtent, slicePoint, sliceRatio, dimensionsToKeep);
+            subsampledExtent = subsampledExtent.sliceByRatio(slicePoint, sliceRatio, dimensionsToKeep);
         }
         return this;
     }
 
-    /**
-     * Returns a slice of the given grid extent computed by a ratio between 0 and 1 inclusive.
-     * This is for {@link #sliceByRatio(double, int...)} implementation only.
-     *
-     * @param  extent      the extent to slice.
-     * @param  slicePoint  a pre-allocated direct position to be overwritten by this method.
-     */
-    private static GridExtent sliceByRatio(final GridExtent extent, final GeneralDirectPosition slicePoint,
-            final double sliceRatio, final int[] dimensionsToKeep)
-    {
-        for (int i=0; i<slicePoint.ordinates.length; i++) {
-            slicePoint.ordinates[i] = sliceRatio * (extent.getSize(i) - 1) + extent.getLow(i);
-        }
-        for (int i=0; i<dimensionsToKeep.length; i++) {
-            slicePoint.ordinates[dimensionsToKeep[i]] = Double.NaN;
-        }
-        return extent.slice(slicePoint, null);
-    }
-
     /*
      * RATIONAL FOR NOT PROVIDING reduce(int... dimensions) METHOD HERE: that method would need to be the last method invoked,
      * otherwise it makes more complicated to implement other methods in this class.  Forcing users to invoke 'build()' before
diff --git a/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridExtent.java b/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridExtent.java
index 73f976d..b3cc40b 100644
--- a/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridExtent.java
+++ b/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridExtent.java
@@ -969,6 +969,24 @@ public class GridExtent implements Serializable {
     }
 
     /**
+     * Returns a slice of this given grid extent computed by a ratio between 0 and 1 inclusive.
+     * This is a helper method for {@link GridDerivation#sliceByRatio(double, int...)} implementation.
+     *
+     * @param  slicePoint        a pre-allocated direct position to be overwritten by this method.
+     * @param  sliceRatio        the ratio to apply on all grid dimensions except the ones to keep.
+     * @param  dimensionsToKeep  the grid dimension to keep unchanged.
+     */
+    final GridExtent sliceByRatio(final DirectPosition slicePoint, final double sliceRatio, final int[] dimensionsToKeep) {
+        for (int i=slicePoint.getDimension(); --i >= 0;) {
+            slicePoint.setOrdinate(i, sliceRatio * (getSize(i) - 1) + getLow(i));
+        }
+        for (int i=0; i<dimensionsToKeep.length; i++) {
+            slicePoint.setOrdinate(dimensionsToKeep[i], Double.NaN);
+        }
+        return slice(slicePoint, null);
+    }
+
+    /**
      * Creates a new grid extent which represent a slice of this grid at the given point.
      * The given point may have less dimensions than this grid extent, in which case the
      * dimensions must be specified in the {@code modifiedDimensions} array. Coordinates