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
    • Field Detail

      • CHECK_COORDINATE_PLUGINS

        public static final boolean CHECK_COORDINATE_PLUGINS
      • CHECK_COORDINATE_PLUGINS_KEY

        public static final String CHECK_COORDINATE_PLUGINS_KEY
        See Also:
        Constant Field Values
      • STANDARD_PARALLEL_1

        public static final String STANDARD_PARALLEL_1
      • STANDARD_PARALLEL_2

        public static final String STANDARD_PARALLEL_2
      • CENTRAL_MERIDIAN

        public static final String CENTRAL_MERIDIAN
      • LATITUDE_OF_ORIGIN

        public static final String LATITUDE_OF_ORIGIN
      • SCALE_FACTOR

        public static final String SCALE_FACTOR
      • FALSE_EASTING

        public static final String FALSE_EASTING
      • FALSE_NORTHING

        public static final String FALSE_NORTHING
      • SEMI_MINOR

        public static final String SEMI_MINOR
      • SEMI_MAJOR

        public static final String SEMI_MAJOR
      • TRACE_ENABLED

        public static final Boolean TRACE_ENABLED
        When true, the stack trace that created a reader that wasn't closed is recorded and then printed out when warning the user about this.
      • DEFAULT_ENHANCE_MODE

        public static final Set<NetcdfDataset.Enhance> DEFAULT_ENHANCE_MODE
      • EXTERNAL_DATA_DIR

        public static final String EXTERNAL_DATA_DIR
      • UPPER_RIGHT_LONGITUDE

        public static final String UPPER_RIGHT_LONGITUDE
        See Also:
        Constant Field Values
      • ELEVATION_DIM

        public static final String ELEVATION_DIM
      • TIME_DIM

        public static final String TIME_DIM
      • START_TIME

        public static final long START_TIME
      • UTC

        public static final TimeZone UTC
      • COORD_SYS_BUILDER_CONVENTION

        public static final String COORD_SYS_BUILDER_CONVENTION
        See Also:
        Constant Field Values
      • COORDINATE_TRANSFORM_TYPE

        public static final String COORDINATE_TRANSFORM_TYPE
        See Also:
        Constant Field Values
      • UNIQUE_TIME_ATTRIBUTE

        public static final String UNIQUE_TIME_ATTRIBUTE
        See Also:
        Constant Field Values
      • ENHANCE_COORD_SYSTEMS

        public static final String ENHANCE_COORD_SYSTEMS
        See Also:
        Constant Field Values
      • ENHANCE_SCALE_MISSING

        public static final String ENHANCE_SCALE_MISSING
        See Also:
        Constant Field Values
      • ENHANCE_CONVERT_ENUMS

        public static final String ENHANCE_CONVERT_ENUMS
        See Also:
        Constant Field Values
      • ENHANCE_SCALE_OFFSET

        public static boolean ENHANCE_SCALE_OFFSET
      • DATASET_URL_CACHE

        protected static final Map<String,​DatasetUrl> DATASET_URL_CACHE
      • X_DIMENSION

        public static final int X_DIMENSION
        The dimension relative to the rank in #variable to use as image width. The actual dimension is variable.getRank() - X_DIMENSION. Is hard-coded because the loop in the read method expects this order.
        See Also:
        Constant Field Values
      • Y_DIMENSION

        public static final int Y_DIMENSION
        The dimension relative to the rank in #variable to use as image height. The actual dimension is variable.getRank() - Y_DIMENSION. Is hard-coded because the loop in the read method expects this order.
        See Also:
        Constant Field Values
      • Z_DIMENSION

        public static final int Z_DIMENSION
        The default dimension relative to the rank in #variable to use as Z dimension. The actual dimension is variable.getRank() - Z_DIMENSION.

        See Also:
        Constant Field Values
      • VALID_TYPES

        public static final Set<DataType> VALID_TYPES
        The data type to accept in images. Used for automatic detection of which coverageDescriptorsCache to assign to images.
      • PARAMS_MAX_KEY

        public static final String PARAMS_MAX_KEY
        Default parameter behavior properties TODO: better way of handling configuration settings, such as read parameters.
        See Also:
        Constant Field Values
    • 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.
      • getDatasetUrl

        public static DatasetUrl getDatasetUrl​(String uriString)
                                        throws IOException
        Throws:
        IOException
      • isFile

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