sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 03/03: Always consider a variable as an axis if the "_CoordinateAxisType" attribute is present.
Date Mon, 30 Nov 2020 17:17:18 GMT
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 da00b49791b40f8400e47ba12032e9b85165642d
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Mon Nov 30 18:15:28 2020 +0100

    Always consider a variable as an axis if the "_CoordinateAxisType" attribute is present.
---
 .../sis/internal/netcdf/impl/ChannelDecoder.java    |  6 +++---
 .../sis/internal/netcdf/impl/VariableInfo.java      |  8 +++++++-
 .../org/apache/sis/internal/netcdf/GridTest.java    | 21 ++++++++++++++++++---
 .../apache/sis/internal/netcdf/VariableTest.java    | 11 +----------
 .../sis/internal/netcdf/impl/GridInfoTest.java      |  9 ++++++++-
 .../sis/internal/netcdf/impl/VariableInfoTest.java  |  3 +--
 6 files changed, 38 insertions(+), 20 deletions(-)

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 5570ebf..6452e53 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
@@ -936,10 +936,10 @@ public final class ChannelDecoder extends Decoder {
      * @param  names       names of variables containing axis data, or {@code null} if none.
      * @param  axes        where to add named variables.
      * @param  dimensions  where to report all dimensions used by added axes.
-     * @return whether {@code names} was non-null.
+     * @return whether {@code names} was non-null and non-empty.
      */
     private boolean listAxes(final CharSequence[] names, final Set<VariableInfo> axes,
final Set<DimensionInfo> dimensions) {
-        if (names == null) {
+        if (names == null || names.length == 0) {
             return false;
         }
         for (final CharSequence name : names) {
@@ -1002,7 +1002,7 @@ nextVar:    for (final VariableInfo variable : variables) {
                 /*
                  * The axes can be inferred in two ways: if the variable contains a "coordinates"
attribute,
                  * that attribute lists explicitly the variables to use as axes. Otherwise
we have to infer
-                 * the axes from the variable dimensions, using the 'dimToVars' map computed
at the beginning
+                 * the axes from the variable dimensions, using the `dimToAxes` map computed
at the beginning
                  * of this method. If and only if we can find all axes, we create the GridGeometryInfo.
                  * This is a "all or nothing" operation.
                  */
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java
b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java
index bd06b4c..f6d4545 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java
@@ -245,11 +245,17 @@ final class VariableInfo extends Variable implements Comparable<VariableInfo>
{
             }
         }
         /*
+         * According CF conventions, a variable is considered a coordinate system axis if
it has the same name
+         * as its dimension. But the "_CoordinateAxisType" attribute is often used for making
explicit that a
+         * variable is an axis. We check that case before to check variable name.
+         */
+        isCoordinateSystemAxis = (dimensions.length == 1 || dimensions.length == 2) &&
(getAxisType() != null);
+        /*
          * If the "_CoordinateAliasForDimension" attribute is defined, then its value will
be used
          * instead of the variable name when determining if the variable is a coordinate
system axis.
          * "_CoordinateVariableAlias" seems to be a legacy attribute name for the same purpose.
          */
-        if (dimensions.length == 1) {
+        if (!isCoordinateSystemAxis && dimensions.length == 1) {
             Object value = getAttributeValue(_Coordinate.AliasForDimension, "_coordinatealiasfordimension");
             if (value == null) {
                 value = getAttributeValue("_CoordinateVariableAlias", "_coordinatevariablealias");
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 ed35f9b..e681a20 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
@@ -36,13 +36,20 @@ import static org.apache.sis.test.TestUtilities.getSingleton;
  * {@link #createDecoder(TestData)} method in order to test a different implementation.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 1.0
+ * @version 1.1
  * @since   0.3
  * @module
  */
 @DependsOn(VariableTest.class)
 public strictfp class GridTest extends TestCase {
     /**
+     * Whether the {@code "runtime"} variable in {@link TestData#NETCDF_4D_PROJECTED} is
used as a target dimension
+     * for the {@code gridToCRS} transform. The UCAR library and Apache SIS implementation
have different behavior
+     * regarding this dimension.
+     */
+    protected boolean includeRuntimeDimension;
+
+    /**
      * Optionally filters out some grid geometries that shall be ignored by the tests.
      * The default implementation returns the given array unmodified. This method is overridden
by
      * {@code GridGeometryInfoTest} in order to ignore one-dimensional coordinate systems
created
@@ -67,9 +74,10 @@ public strictfp class GridTest extends TestCase {
         assertEquals("getSourceDimensions()", 2, geometry.getSourceDimensions());
         assertEquals("getTargetDimensions()", 2, geometry.getTargetDimensions());
 
+        final int n = includeRuntimeDimension ? 5 : 4;
         geometry = getSingleton(filter(selectDataset(TestData.NETCDF_4D_PROJECTED).getGrids()));
         assertEquals("getSourceDimensions()", 4, geometry.getSourceDimensions());
-        assertEquals("getTargetDimensions()", 4, geometry.getTargetDimensions());
+        assertEquals("getTargetDimensions()", n, geometry.getTargetDimensions());
     }
 
     /**
@@ -106,7 +114,7 @@ public strictfp class GridTest extends TestCase {
     @DependsOnMethod("testDimensions")
     public void testAxes4D() throws IOException, DataStoreException {
         final Axis[] axes = getSingleton(filter(selectDataset(TestData.NETCDF_4D_PROJECTED).getGrids())).getAxes(decoder());
-        assertEquals(4, axes.length);
+        assertEquals(includeRuntimeDimension ? 5 : 4, axes.length);
         final Axis x = axes[0];
         final Axis y = axes[1];
         final Axis z = axes[2];
@@ -126,6 +134,13 @@ public strictfp class GridTest extends TestCase {
         assertEquals(19, y.getMainSize().getAsLong());
         assertEquals( 4, z.getMainSize().getAsLong());
         assertEquals( 1, t.getMainSize().getAsLong());
+
+        if (includeRuntimeDimension) {
+            final Axis r = axes[4];
+            assertEquals('t', r.abbreviation);
+            assertArrayEquals(new int[] {0}, r.gridDimensionIndices);
+            assertEquals(1, r.getMainSize().getAsLong());
+        }
     }
 
     /**
diff --git a/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/VariableTest.java
b/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/VariableTest.java
index 3b13e45..d05cf6b 100644
--- a/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/VariableTest.java
+++ b/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/VariableTest.java
@@ -52,18 +52,9 @@ public strictfp class VariableTest extends TestCase {
     private static final int NUM_BASIC_PROPERTY_COLUMNS = 5;
 
     /**
-     * Whether the {@code "runtime"} variable in {@link TestData#NETCDF_4D_PROJECTED} is
considered an axis or not.
-     * The UCAR library considers it as an axis because it has an {@code "_CoordinateAxisType"}
attribute.
-     * Apache SIS does not consider it as an axis because that variable does not match any
dimension and is not used
-     * in any other variable.
-     */
-    protected boolean isRuntimeAnAxis;
-
-    /**
      * Creates a new test.
      */
     public VariableTest() {
-        isRuntimeAnAxis = true;
     }
 
     /**
@@ -109,7 +100,7 @@ public strictfp class VariableTest extends TestCase {
             "y0",             "projection_y_coordinate",       DataType.FLOAT,  1, VariableRole.AXIS,
             "z0",             "Flight levels in 100s of feet", DataType.FLOAT,  1, VariableRole.AXIS,
             "time",           "Data time",                     DataType.DOUBLE, 1, VariableRole.AXIS,
-            "runtime",        "Data generation time",          DataType.DOUBLE, 1, isRuntimeAnAxis
? VariableRole.AXIS : VariableRole.OTHER,
+            "runtime",        "Data generation time",          DataType.DOUBLE, 1, VariableRole.AXIS,
             "CIP",            "Current Icing Product",         DataType.FLOAT,  4, VariableRole.COVERAGE
         }, getVariablesCIP(selectDataset(TestData.NETCDF_4D_PROJECTED)));
     }
diff --git a/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/GridInfoTest.java
b/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/GridInfoTest.java
index 1ae3598..3ed8762 100644
--- a/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/GridInfoTest.java
+++ b/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/GridInfoTest.java
@@ -34,13 +34,20 @@ import org.opengis.test.dataset.TestData;
  * passed.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 1.0
+ * @version 1.1
  * @since   0.3
  * @module
  */
 @DependsOn({VariableInfoTest.class, GridTest.class})
 public final strictfp class GridInfoTest extends GridTest {
     /**
+     * Creates a new test.
+     */
+    public GridInfoTest() {
+        includeRuntimeDimension = true;
+    }
+
+    /**
      * Creates a new decoder for the specified dataset.
      *
      * @return the decoder for the specified dataset.
diff --git a/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/VariableInfoTest.java
b/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/VariableInfoTest.java
index 4bc4e4d..759ea96 100644
--- a/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/VariableInfoTest.java
+++ b/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/VariableInfoTest.java
@@ -30,7 +30,7 @@ import org.opengis.test.dataset.TestData;
  * passed.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 1.0
+ * @version 1.1
  * @since   0.3
  * @module
  */
@@ -40,7 +40,6 @@ public final strictfp class VariableInfoTest extends VariableTest {
      * Creates a new test.
      */
     public VariableInfoTest() {
-        isRuntimeAnAxis = false;
     }
 
     /**


Mime
View raw message