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

      • useMemoryMapping

        public static boolean useMemoryMapping()
      • useCache

        public static boolean useCache()
      • 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​(VariableSimpleIF 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.
      • isFile

        public static boolean isFile​(String location)
      • 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:

        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()
      • disableNetCDFFileCaches

        public static void disableNetCDFFileCaches()
      • enableNetCDFFileCaches

        public static void enableNetCDFFileCaches()
      • 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.
      • getRafFileCache

        public static FileCacheIF getRafFileCache()
      • getNetCDFFileCache

        public static FileCacheIF getNetCDFFileCache()