Class NetCDFUtilities


  • public class NetCDFUtilities
    extends Object
    Set of NetCDF utility methods.
    Author:
    Alessio Fabiani, GeoSolutions SAS, Daniele Romagnoli, GeoSolutions SAS, Simone Giannecchini, GeoSolutions SAS
    • Method Detail

      • isValidDir

        public static boolean isValidDir​(File file)
      • getZDimensionLength

        public static int getZDimensionLength​(Variable var)
        Get Z Dimension Lenght for standard CF variables
      • getDimensionLength

        public static int getDimensionLength​(Variable var,
                                             int dimensionIndex)
      • getRawDataType

        public static int getRawDataType​(VariableIF variable)
        Returns the data type which most closely represents the "raw" internal data of the variable. This is the value returned by the default implementation of NetcdfImageReader#getRawDataType.
        Parameters:
        variable - The variable.
        Returns:
        The data type, or DataBuffer.TYPE_UNDEFINED if unknown.
        See Also:
        NetcdfImageReader#getRawDataType
      • transcodeNetCDFDataType

        public static int transcodeNetCDFDataType​(DataType type,
                                                  boolean unsigned)
        Transcode a NetCDF data type into a java2D DataBuffer type.
        Parameters:
        type - the DataType to transcode.
        unsigned - if the original data is unsigned or not
        Returns:
        an int representing the correct DataBuffer type.
      • isVariableAccepted

        public static boolean isVariableAccepted​(Variable var,
                                                 NetCDFUtilities.CheckType checkType)
        NetCDF files may contains a wide set of coverageDescriptorsCache. Some of them are unuseful for our purposes. The method returns true if the specified variable is accepted.
      • isVariableAccepted

        public static boolean isVariableAccepted​(Variable var,
                                                 NetCDFUtilities.CheckType checkType,
                                                 NetcdfDataset dataset)
        NetCDF files may contains a wide set of coverageDescriptorsCache. Some of them are unuseful for our purposes. The method returns true if the specified variable is accepted.
      • isVariableAccepted

        public static boolean isVariableAccepted​(String name,
                                                 NetCDFUtilities.CheckType checkType)
        NetCDF files may contain a wide set of coverageDescriptorsCache. Some of them are unuseful for our purposes. The method returns true if the specified variable is accepted.
      • acquireFeatureCollection

        public static NetcdfDataset acquireFeatureCollection​(String path)
                                                      throws IOException
        Throws:
        IOException
      • acquireDataset

        public static NetcdfDataset acquireDataset​(URI uri)
                                            throws IOException
        Throws:
        IOException
      • getDataset

        public static NetcdfDataset getDataset​(Object input)
                                        throws IOException
        Returns a NetcdfDataset given an input object the input object (usually a File, a String or a {@code FileImageInputStreamExt).
        Returns:
        NetcdfDataset in case of success. if some error occur while opening the dataset.
        Throws:
        IOException
      • getFile

        public static File getFile​(Object input)
                            throws IOException
        Checks if the input is file based, and if yes, returns the file.
        Parameters:
        input - the input to check.
        Returns:
        the file or null if it is not file based.
        Throws:
        IOException
      • getAxisFormat

        public static Format getAxisFormat​(AxisType type,
                                           String prototype)
        Returns a format to use for parsing values along the specified axis type. This method is invoked when parsing the date part of axis units like "days since 1990-01-01 00:00:00". Subclasses should override this method if the date part is formatted in a different way. The default implementation returns the following formats:

        • For time axis, a DateFormat using the "yyyy-MM-dd HH:mm:ss" pattern in UTC timezone.
        • For all other kind of axis, a NumberFormat.

        The English locale is used by default for most formats because it is relatively close to ISO (for example regarding days and months order in dates) while using the English symbols.

        Parameters:
        type - The type of the axis.
        prototype - An example of the values to be parsed. Implementations may parse this prototype when the axis type alone is not sufficient. For example the time axis type should uses the "yyyy-MM-dd" date pattern, but some files do not follow this convention and use the default local instead.
        Returns:
        The format for parsing values along the axis.
      • getCheckType

        public static NetCDFUtilities.CheckType getCheckType​(NetcdfDataset dataset)
        Depending on the type of model/netcdf file, we will check for the presence of some coverageDescriptorsCache rather than some others. The method returns the type of check on which we need to leverage to restrict the set of interesting coverageDescriptorsCache. The method will check for some KEY/FLAGS/ATTRIBUTES within the input dataset in order to define the proper check type to be performed.
        Parameters:
        dataset - the input dataset.
        Returns:
        the proper NetCDFUtilities.CheckType to be performed on the specified dataset.
      • isGribAvailable

        public static boolean isGribAvailable()
        Returns:
        true if the GRIB library is available
      • isNC4CAvailable

        public static boolean isNC4CAvailable()
        Returns:
        true if the C Native NetCDF 4 library is available
      • isCheckCoordinatePlugins

        public static boolean isCheckCoordinatePlugins()
      • getUnsupportedDimensions

        public static Set<String> getUnsupportedDimensions()
        Returns:
        An unmodifiable Set of Unsupported Dimension names
      • getIgnoredDimensions

        public static Set<String> getIgnoredDimensions()
        Returns:
        an unmodifiable Set of the Dimensions to be ignored by the Coordinate parsing machinery
      • addIgnoredDimension

        public static void addIgnoredDimension​(String dimensionName)
        Adds a dimension to the ignored dimensions set.
      • getNodata

        public static Number getNodata​(Variable var)
        Utility method for getting NoData from an input Variable
        Parameters:
        var - Variable instance
        Returns:
        a Number representing NoData
      • getRange

        public static NumberRange getRange​(Variable var)
        Utility method for getting Range from an input Variable
        Parameters:
        var - Variable instance
        Returns:
        a Range representing actual_range or valid_min/valid_max range or valid_range
      • getNetCDFDataType

        public static DataType getNetCDFDataType​(String classDataType)
        Return the propery NetCDF dataType for the input datatype class
      • transcodeImageDataType

        public static DataType transcodeImageDataType​(int dataType)
        Transcode a DataBuffer type into a NetCDF DataType .
        Parameters:
        dataType - the beam ProductData type to transcode.
        Returns:
        an NetCDF DataType type.
      • isATime

        public static final boolean isATime​(String classDataType)
        Return true in case that dataType refers to something which need to be handled as a Time (TimeStamp, Date)
      • getArray

        public static Array getArray​(int[] dimensions,
                                     DataType varDataType)
        Get an Array of proper size and type.
        Parameters:
        dimensions - the dimensions
        varDataType - the DataType of the required array
      • transcodeNumber

        public static Number transcodeNumber​(DataType type,
                                             Number value)
        Transcode a NetCDF Number into a proper Number instance.
        Parameters:
        type - the DataType to transcode.
        Returns:
        the proper number instance
      • refreshParameterBehaviors

        public static void refreshParameterBehaviors()
      • clearCaches

        public static void clearCaches()
        Clear all the internal caches. Call this method if the datastore config has been updated or the NetCDF XML file has been modified.