sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 01/03: Provide warning in some situations where the netCDF reader can not create a GridGeometry or a SampleDimension.
Date Sat, 23 Feb 2019 13:36:52 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 40b7f1b2e7e365fa78caf6e6336de96b867d1571
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Sat Feb 23 13:40:47 2019 +0100

    Provide warning in some situations where the netCDF reader can not create a GridGeometry
or a SampleDimension.
---
 .../java/org/apache/sis/internal/netcdf/Axis.java  |  2 ++
 .../org/apache/sis/internal/netcdf/Convention.java |  3 +++
 .../org/apache/sis/internal/netcdf/Resources.java  | 24 +++++++++++++++++++---
 .../sis/internal/netcdf/Resources.properties       |  7 +++++--
 .../sis/internal/netcdf/Resources_fr.properties    |  7 +++++--
 .../org/apache/sis/internal/netcdf/Variable.java   | 11 ++++++++--
 .../apache/sis/internal/netcdf/impl/GridInfo.java  |  2 +-
 .../apache/sis/storage/netcdf/GridResource.java    | 16 ++++++++++++---
 8 files changed, 59 insertions(+), 13 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 f9ca69b..3073098 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
@@ -662,6 +662,8 @@ main:   switch (getDimension()) {
      * @param  exception  the exception that occurred, or {@code null} if none.
      * @param  key        one or {@link Errors.Keys} constants.
      * @param  arguments  values to be formatted in the {@link java.text.MessageFormat} pattern.
+     *
+     * @see Variable#warning(Class, String, short, Object...)
      */
     private void warning(final Exception exception, final short key, final Object... arguments)
{
         coordinates.error(Variable.class, "getGridGeometry", exception, key, arguments);
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Convention.java
b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Convention.java
index 8cfa6e6..fdb654e 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Convention.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Convention.java
@@ -401,6 +401,9 @@ public class Convention {
      * Pad values should be first in the map, followed by missing values.
      * The same value may have more than one role.
      *
+     * <p>The default implementation returns a modifiable {@link LinkedHashMap}.
+     * Subclasses can add their own entries to the returned map.</p>
+     *
      * @param  data  the variable for which to get no-data values.
      * @return no-data values with bitmask of their roles or textual descriptions.
      */
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Resources.java
b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Resources.java
index 2e81e3a..f2f84e9 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Resources.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Resources.java
@@ -81,6 +81,12 @@ public final class Resources extends IndexedResourceBundle {
         public static final short CanNotCreateGridGeometry_3 = 12;
 
         /**
+         * Can not relate dimension “{2}” of variable “{1}” to a coordinate system
dimension in netCDF
+         * file “{0}”.
+         */
+        public static final short CanNotRelateVariableDimension_3 = 15;
+
+        /**
          * Can not render an image for “{0}”. The reason is: {1}
          */
         public static final short CanNotRender_2 = 14;
@@ -96,12 +102,18 @@ public final class Resources extends IndexedResourceBundle {
         public static final short DimensionNotFound_3 = 1;
 
         /**
-         * Duplicated reference to “{1}” in netCDF file “{0}”.
+         * Duplicated axis “{1}” in a grid of netCDF file “{0}”.
          */
-        public static final short DuplicatedReference_2 = 7;
+        public static final short DuplicatedAxis_2 = 7;
 
         /**
-         * The declared size of variable “{1}” in netCDF file “{0}” is {2} bytes
greater than expected.
+         * Illegal value range {2,number} … {3,number} for variable “{1}” in netCDF
file “{0}”.
+         */
+        public static final short IllegalValueRange_4 = 16;
+
+        /**
+         * The declared size of variable “{1}” in netCDF file “{0}” is {2,number}}
bytes greater than
+         * expected.
          */
         public static final short MismatchedVariableSize_3 = 8;
 
@@ -111,6 +123,12 @@ public final class Resources extends IndexedResourceBundle {
         public static final short MismatchedVariableType_3 = 13;
 
         /**
+         * Variable “{1}” or netCDF file “{0}” has a different size than its coordinate
system, but no
+         * resampling interval is specified.
+         */
+        public static final short ResamplingIntervalNotFound_2 = 17;
+
+        /**
          * Reference system of type ‘{1}’ can not have {2} axes. The axes found in the
“{0}” netCDF
          * file are: {3}.
          */
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Resources.properties
b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Resources.properties
index a8062b0..4b39a7b 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Resources.properties
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Resources.properties
@@ -23,12 +23,15 @@ AmbiguousAxisDirection_4          = NetCDF file \u201c{0}\u201d provides
an ambi
 CanNotComputeVariablePosition_2   = Can not compute data location for \u201c{1}\u201d variable
in the \u201c{0}\u201d netCDF file.
 CanNotCreateCRS_3                 = Can not create the Coordinate Reference System for grid
geometry \u201c{1}\u201d in the \u201c{0}\u201d netCDF file. The reason is: {2}
 CanNotCreateGridGeometry_3        = Can not create the grid geometry \u201c{1}\u201d in the
\u201c{0}\u201d netCDF file. The reason is: {2}
+CanNotRelateVariableDimension_3   = Can not relate dimension \u201c{2}\u201d of variable
\u201c{1}\u201d to a coordinate system dimension in netCDF file \u201c{0}\u201d.
 CanNotRender_2                    = Can not render an image for \u201c{0}\u201d. The reason
is: {1}
 CanNotUseUCAR                     = Can not use UCAR library for netCDF format. Fallback
on Apache SIS implementation.
 DimensionNotFound_3               = Dimension \u201c{2}\u201d declared by attribute \u201c{1}\u201d
is not found in the \u201c{0}\u201d file.
-DuplicatedReference_2             = Duplicated reference to \u201c{1}\u201d in netCDF file
\u201c{0}\u201d.
-MismatchedVariableSize_3          = The declared size of variable \u201c{1}\u201d in netCDF
file \u201c{0}\u201d is {2} bytes greater than expected.
+DuplicatedAxis_2                  = Duplicated axis \u201c{1}\u201d in a grid of netCDF file
\u201c{0}\u201d.
+IllegalValueRange_4               = Illegal value range {2,number} \u2026 {3,number} for
variable \u201c{1}\u201d in netCDF file \u201c{0}\u201d.
+MismatchedVariableSize_3          = The declared size of variable \u201c{1}\u201d in netCDF
file \u201c{0}\u201d is {2,number}} bytes greater than expected.
 MismatchedVariableType_3          = Variables \u201c{1}\u201d and \u201c{2}\u201d in netCDF
file \u201c{0}\u201d does not have the same type.
+ResamplingIntervalNotFound_2      = Variable \u201c{1}\u201d or netCDF file \u201c{0}\u201d
has a different size than its coordinate system, but no resampling interval is specified.
 UnexpectedAxisCount_4             = Reference system of type \u2018{1}\u2019 can not have
{2}\u00a0axes. The axes found in the \u201c{0}\u201d netCDF file are: {3}.
 UnexpectedDimensionForVariable_4  = Variable \u201c{1}\u201d in file \u201c{0}\u201d has
a dimension \u201c{3}\u201d while we expected \u201c{2}\u201d.
 UnsupportedDataType_3             = NetCDF file \u201c{0}\u201d uses unsupported data type
{2} for variable \u201c{1}\u201d.
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Resources_fr.properties
b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Resources_fr.properties
index 6d5c18d..ba3888e 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Resources_fr.properties
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Resources_fr.properties
@@ -28,12 +28,15 @@ AmbiguousAxisDirection_4          = Le fichier netCDF \u00ab\u202f{0}\u202f\u00b
 CanNotComputeVariablePosition_2   = Ne peut pas calculer la position des donn\u00e9es de
la variable \u00ab\u202f{1}\u202f\u00bb dans le fichier netCDF \u00ab\u202f{0}\u202f\u00bb.
 CanNotCreateCRS_3                 = Ne peut pas cr\u00e9er le syst\u00e8me de r\u00e9f\u00e9rence
des coordonn\u00e9es pour la g\u00e9om\u00e9trie de grille \u00ab\u202f{1}\u202f\u00bb dans
le fichier netCDF \u00ab\u202f{0}\u202f\u00bb. La raison est\u2008: {2}
 CanNotCreateGridGeometry_3        = Ne peut pas cr\u00e9er la g\u00e9om\u00e9trie de grille
\u00ab\u202f{1}\u202f\u00bb dans le fichier netCDF \u00ab\u202f{0}\u202f\u00bb. La raison
est\u2008: {2}
+CanNotRelateVariableDimension_3   = Ne peut pas relier la dimension \u00ab\u202f{2}\u202f\u00bb
de la variable \u00ab\u202f{1}\u202f\u00bb \u00e0 une dimension d\u2019un syst\u00e8me de
coordonn\u00e9es du fichier netCDF \u00ab\u202f{0}\u202f\u00bb.
 CanNotRender_2                    = Ne peut pas produire une image pour \u00ab\u202f{0}\u202f\u00bb.
La raison est\u2008: {1}
 CanNotUseUCAR                     = Ne peut pas utiliser la biblioth\u00e8que de l\u2019UCAR
pour le format netCDF. L\u2019impl\u00e9mentation de Apache SIS sera utilis\u00e9e \u00e0
la place.
 DimensionNotFound_3               = La dimension \u00ab\u202f{2}\u202f\u00bb d\u00e9clar\u00e9e
par l\u2019attribut \u00ab\u202f{1}\u202f\u00bb n\u2019a pas \u00e9t\u00e9 trouv\u00e9e dans
le fichier \u00ab\u202f{0}\u202f\u00bb.
-DuplicatedReference_2             = R\u00e9f\u00e9rence vers \u00ab\u202f{1}\u202f\u00bb
dupliqu\u00e9e dans le fichier netCDF \u00ab\u202f{0}\u202f\u00bb.
-MismatchedVariableSize_3          = La longueur d\u00e9clar\u00e9e de la variable \u00ab\u202f{1}\u202f\u00bb
dans le fichier netCDF \u00ab\u202f{0}\u202f\u00bb d\u00e9passe de {2} octets la valeur attendue.
+DuplicatedAxis_2                  = Axe \u00ab\u202f{1}\u202f\u00bb dupliqu\u00e9 dans une
grille du fichier netCDF \u00ab\u202f{0}\u202f\u00bb.
+IllegalValueRange_4               = Plage de valeurs {2,number} \u2026 {3,number} ill\u00e9gale
pour la variable \u00ab\u202f{1}\u202f\u00bb dans le fichier netCDF \u00ab\u202f{0}\u202f\u00bb.
+MismatchedVariableSize_3          = La longueur d\u00e9clar\u00e9e de la variable \u00ab\u202f{1}\u202f\u00bb
dans le fichier netCDF \u00ab\u202f{0}\u202f\u00bb d\u00e9passe de {2,number}} octets la valeur
attendue.
 MismatchedVariableType_3          = Les variables \u00ab\u202f{1}\u202f\u00bb et \u00ab\u202f{2}\u202f\u00bb
dans le fichier netCDF \u00ab\u202f{0}\u202f\u00bb ne sont pas du m\u00eame type.
+ResamplingIntervalNotFound_2      = La variable \u00ab\u202f{1}\u202f\u00bb du fichier netCDF
\u00ab\u202f{0}\u202f\u00bb a une taille diff\u00e9rente de celle de son syst\u00e8me de coordonn\u00e9es,
mais l\u2019intervalle d\u2019\u00e9chantillonnage n\u2019a pas \u00e9t\u00e9 sp\u00e9cifi\u00e9.
 UnexpectedAxisCount_4             = Les syst\u00e8mes de r\u00e9f\u00e9rence de type \u2018{1}\u2019
ne peuvent pas avoir {2}\u00a0axes. Les axes trouv\u00e9s dans le fichier netCDF \u00ab\u202f{0}\u202f\u00bb
sont\u2008: {3}.
 UnexpectedDimensionForVariable_4  = La variable \u00ab\u202f{1}\u202f\u00bb dans le fichier
\u00ab\u202f{0}\u202f\u00bb a une dimension \u00ab\u202f{3}\u202f\u00bb alors qu\u2019on attendait
\u00ab\u202f{2}\u202f\u00bb.
 UnsupportedDataType_3             = Le fichier netCDF \u00ab\u202f{0}\u202f\u00bb utilise
un type de donn\u00e9es non-support\u00e9 {2} pour la variable \u00ab\u202f{1}\u202f\u00bb.
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java
b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java
index fe9084c..1438698 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java
@@ -437,6 +437,7 @@ public abstract class Variable extends NamedElement {
                                             if (!isRequested && requestedByConvention.contains(dim))
{
                                                 domain.put(name, previous);
                                             } else {
+                                                error(Variable.class, "getGridGeometry",
null, Errors.Keys.DuplicatedIdentifier_1, name);
                                                 return null;
                                             }
                                         }
@@ -447,6 +448,8 @@ public abstract class Variable extends NamedElement {
                     }
                 }
                 if ((dimensions[i] = domain.remove(label)) == null) {
+                    warning(Variable.class, "getGridGeometry",        // Caller (indirectly)
for this method.
+                            Resources.Keys.CanNotRelateVariableDimension_3, getFilename(),
getName(), label);
                     return null;        // Can not to relate that variable dimension to a
grid dimension.
                 }
             }
@@ -505,7 +508,10 @@ public abstract class Variable extends NamedElement {
             if (needsResize) {
                 if (gridToDataIndices != null) {
                     for (final double s : gridToDataIndices) {
-                        if (!(s > 0)) return null;                  // "resampling_interval"
attributes not found.
+                        if (!(s > 0)) {
+                            warning(Variable.class, "getGridGeometry", Resources.Keys.ResamplingIntervalNotFound_2,
getFilename(), getName());
+                            return null;
+                        }
                     }
                 }
                 extent = extent.resize(sizes);
@@ -877,13 +883,14 @@ public abstract class Variable extends NamedElement {
 
     /**
      * Reports a warning to the listeners specified at construction time.
+     * This method is for Apache SIS internal purpose only since resources may change at
any time.
      *
      * @param  caller     the caller class to report, preferably a public class.
      * @param  method     the caller method to report, preferable a public method.
      * @param  key        one or {@link Resources.Keys} constants.
      * @param  arguments  values to be formatted in the {@link java.text.MessageFormat} pattern.
      */
-    protected final void warning(final Class<?> caller, final String method, final
short key, final Object... arguments) {
+    public final void warning(final Class<?> caller, final String method, final short
key, final Object... arguments) {
         warning(decoder.listeners, caller, method, null, null, key, arguments);
     }
 
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 f232f86..8eae907 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
@@ -232,7 +232,7 @@ next:       for (final String name : axisNames) {
         for (int i=0; i<range.length; i++) {
             final VariableInfo v = range[i];
             if (variables.put(v, i) != null) {
-                throw new DataStoreContentException(Resources.format(Resources.Keys.DuplicatedReference_2,
getFilename(), v.getName()));
+                throw new DataStoreContentException(Resources.format(Resources.Keys.DuplicatedAxis_2,
getFilename(), v.getName()));
             }
         }
         /*
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/GridResource.java
b/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/GridResource.java
index bc17a45..8f59aff 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/GridResource.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/GridResource.java
@@ -317,9 +317,19 @@ final class GridResource extends AbstractGridResource implements ResourceOnFileS
                     range = NumberRange.create(minimum, isMinIncluded, maximum, isMaxIncluded);
                 }
             }
-            String name = data.getDescription();
-            if (name == null) name = data.getName();
-            builder.addQuantitative(name, range, mt, data.getUnit());
+            /*
+             * Range may be empty if min/max values declared in the netCDF files are erroneous,
+             * or if we have not read them correctly (edu.ucar:cdm:4.6.13 sometime confuses
an
+             * unsigned integer with a signed one).
+             */
+            if (range.isEmpty()) {
+                data.warning(GridResource.class, "getSampleDimensions", Resources.Keys.IllegalValueRange_4,
+                        data.getFilename(), data.getName(), range.getMinValue(), range.getMaxValue());
+            } else {
+                String name = data.getDescription();
+                if (name == null) name = data.getName();
+                builder.addQuantitative(name, range, mt, data.getUnit());
+            }
         }
         /*
          * Adds the "missing value" or "fill value" as qualitative categories.  If a value
has both roles, use "missing value"


Mime
View raw message