Class NetCDFUtilities
- Object
-
- NetCDFUtilities
-
public class NetCDFUtilities extends Object
Set of NetCDF utility methods.- Author:
- Alessio Fabiani, GeoSolutions SAS, Daniele Romagnoli, GeoSolutions SAS, Simone Giannecchini, GeoSolutions SAS
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
NetCDFUtilities.Axis
Global attribute for coordinate coverageDescriptorsCache.static class
NetCDFUtilities.CheckType
static class
NetCDFUtilities.FileFormat
static class
NetCDFUtilities.ParameterBehaviour
-
Field Summary
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static NetcdfDataset
acquireDataset(URI uri)
static NetcdfDataset
acquireFeatureCollection(String path)
static void
addIgnoredDimension(String dimensionName)
Adds a dimension to the ignored dimensions set.static void
clearCaches()
Clear all the internal caches.static SimpleFeatureType
createFeatureType(String schemaName, String schemaDef, CoordinateReferenceSystem crs)
static void
disableNetCDFFileCaches()
static void
enableNetCDFFileCaches()
static Array
getArray(int[] dimensions, DataType varDataType)
Get an Array of proper size and type.static Format
getAxisFormat(AxisType type, String prototype)
Returns a format to use for parsing values along the specified axis type.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.static NetcdfDataset
getDataset(Object input)
Returns aNetcdfDataset
given an input object the input object (usually aFile
, aString
or a {@code FileImageInputStreamExt).static DatasetUrl
getDatasetUrl(String uriString)
static int
getDimensionLength(Variable var, int dimensionIndex)
static File
getFile(Object input)
Checks if the input is file based, and if yes, returns the file.static NetCDFUtilities.FileFormat
getFormat(URI uri)
static Set<String>
getIgnoredDimensions()
static DataType
getNetCDFDataType(String classDataType)
Return the propery NetCDF dataType for the input datatype classstatic FileCacheIF
getNetCDFFileCache()
static Number
getNodata(Variable var)
Utility method for getting NoData from an inputVariable
static NetCDFUtilities.ParameterBehaviour
getParameterBehaviour(String parameter)
static FileCacheIF
getRafFileCache()
static NumberRange
getRange(Variable var)
Utility method for getting Range from an inputVariable
static int
getRawDataType(VariableSimpleIF variable)
Returns the data type which most closely represents the "raw" internal data of the variable.static Set<String>
getUnsupportedDimensions()
static int
getZDimensionLength(Variable var)
Get Z Dimension Lenght for standard CF variablesstatic boolean
isATime(String classDataType)
Return true in case that dataType refers to something which need to be handled as a Time (TimeStamp, Date)static boolean
isCheckCoordinatePlugins()
static boolean
isFile(String location)
static boolean
isGribAvailable()
static boolean
isNC4CAvailable()
static boolean
isValidDir(File file)
static boolean
isVariableAccepted(String name, NetCDFUtilities.CheckType checkType)
NetCDF files may contain a wide set of coverageDescriptorsCache.static boolean
isVariableAccepted(Variable var, NetCDFUtilities.CheckType checkType)
NetCDF files may contains a wide set of coverageDescriptorsCache.static boolean
isVariableAccepted(Variable var, NetCDFUtilities.CheckType checkType, NetcdfDataset dataset)
NetCDF files may contains a wide set of coverageDescriptorsCache.static void
refreshParameterBehaviors()
static DataType
transcodeImageDataType(int dataType)
Transcode a DataBuffer type into a NetCDF DataType .static int
transcodeNetCDFDataType(DataType type, boolean unsigned)
Transcode a NetCDF data type into a java2D DataBuffer type.static Number
transcodeNumber(DataType type, Number value)
Transcode a NetCDF Number into a proper Number instance.static boolean
useCache()
static boolean
useMemoryMapping()
-
-
-
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
-
NETCDF4_MIMETYPE
public static final String NETCDF4_MIMETYPE
- See Also:
- Constant Field Values
-
NETCDF3_MIMETYPE
public static final String NETCDF3_MIMETYPE
- See Also:
- Constant Field Values
-
NETCDF
public static final String NETCDF
- See Also:
- Constant Field Values
-
NETCDF4
public static final String NETCDF4
- See Also:
- Constant Field Values
-
NETCDF_4C
public static final String NETCDF_4C
- See Also:
- Constant Field Values
-
NETCDF_3
public static final String NETCDF_3
- 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
-
INVERSE_FLATTENING
public static final String INVERSE_FLATTENING
- See Also:
- Constant Field Values
-
UNKNOWN
public static final String UNKNOWN
- See Also:
- Constant Field Values
-
DEFAULT_EARTH_RADIUS
public static final double DEFAULT_EARTH_RADIUS
- See Also:
- Constant Field Values
-
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
-
NETCDF_DATA_DIR
public static final String NETCDF_DATA_DIR
- See Also:
- Constant Field Values
-
FILL_VALUE
public static final String FILL_VALUE
- See Also:
- Constant Field Values
-
MISSING_VALUE
public static final String MISSING_VALUE
- See Also:
- Constant Field Values
-
ACTUAL_RANGE
public static final String ACTUAL_RANGE
- See Also:
- Constant Field Values
-
VALID_RANGE
public static final String VALID_RANGE
- See Also:
- Constant Field Values
-
VALID_MIN
public static final String VALID_MIN
- See Also:
- Constant Field Values
-
VALID_MAX
public static final String VALID_MAX
- See Also:
- Constant Field Values
-
LOWER_LEFT_LONGITUDE
public static final String LOWER_LEFT_LONGITUDE
- See Also:
- Constant Field Values
-
LOWER_LEFT_LATITUDE
public static final String LOWER_LEFT_LATITUDE
- See Also:
- Constant Field Values
-
UPPER_RIGHT_LONGITUDE
public static final String UPPER_RIGHT_LONGITUDE
- See Also:
- Constant Field Values
-
UPPER_RIGHT_LATITUDE
public static final String UPPER_RIGHT_LATITUDE
- See Also:
- Constant Field Values
-
COORDSYS
public static final String COORDSYS
- See Also:
- Constant Field Values
-
Y
public static final String Y
- See Also:
- Constant Field Values
-
Y_COORD_PROJ
public static final String Y_COORD_PROJ
- See Also:
- Constant Field Values
-
Y_PROJ_COORD
public static final String Y_PROJ_COORD
- See Also:
- Constant Field Values
-
X
public static final String X
- See Also:
- Constant Field Values
-
X_COORD_PROJ
public static final String X_COORD_PROJ
- See Also:
- Constant Field Values
-
X_PROJ_COORD
public static final String X_PROJ_COORD
- See Also:
- Constant Field Values
-
LATITUDE
public static final String LATITUDE
- See Also:
- Constant Field Values
-
LAT
public static final String LAT
- See Also:
- Constant Field Values
-
LONGITUDE
public static final String LONGITUDE
- See Also:
- Constant Field Values
-
LON
public static final String LON
- See Also:
- Constant Field Values
-
GRID_LATITUDE
public static final String GRID_LATITUDE
- See Also:
- Constant Field Values
-
RLAT
public static final String RLAT
- See Also:
- Constant Field Values
-
GRID_LONGITUDE
public static final String GRID_LONGITUDE
- See Also:
- Constant Field Values
-
RLON
public static final String RLON
- See Also:
- Constant Field Values
-
DEPTH
public static final String DEPTH
- See Also:
- Constant Field Values
-
ZETA
public static final String ZETA
- See Also:
- Constant Field Values
-
BOUNDS
public static final String BOUNDS
- See Also:
- Constant Field Values
-
HEIGHT
public static final String HEIGHT
- See Also:
- Constant Field Values
-
TIME
public static final String TIME
- See Also:
- Constant Field Values
-
POSITIVE
public static final String POSITIVE
- See Also:
- Constant Field Values
-
UNITS
public static final String UNITS
- See Also:
- Constant Field Values
-
NAME
public static final String NAME
- See Also:
- Constant Field Values
-
LONG_NAME
public static final String LONG_NAME
- See Also:
- Constant Field Values
-
ELEVATION_DIM
public static final String ELEVATION_DIM
-
TIME_DIM
public static final String TIME_DIM
-
STANDARD_NAME
public static final String STANDARD_NAME
- See Also:
- Constant Field Values
-
DESCRIPTION
public static final String DESCRIPTION
- See Also:
- Constant Field Values
-
M
public static final String M
- See Also:
- Constant Field Values
-
BOUNDS_SUFFIX
public static final String BOUNDS_SUFFIX
- See Also:
- Constant Field Values
-
LON_UNITS
public static final String LON_UNITS
- See Also:
- Constant Field Values
-
LAT_UNITS
public static final String LAT_UNITS
- See Also:
- Constant Field Values
-
RLATLON_UNITS
public static final String RLATLON_UNITS
- See Also:
- Constant Field Values
-
NO_COORDS
public static final String NO_COORDS
- See Also:
- Constant Field Values
-
TIME_ORIGIN
public static final String TIME_ORIGIN
- See Also:
- Constant Field Values
-
START_TIME
public static final long START_TIME
-
BOUNDARY_DIMENSION
public static final String BOUNDARY_DIMENSION
- See Also:
- Constant Field Values
-
UTC
public static final TimeZone UTC
-
GRID_MAPPING
public static final String GRID_MAPPING
- See Also:
- Constant Field Values
-
GRID_MAPPING_NAME
public static final String GRID_MAPPING_NAME
- See Also:
- Constant Field Values
-
COORDINATE_AXIS_TYPE
public static final String COORDINATE_AXIS_TYPE
- See Also:
- Constant Field Values
-
CONVENTIONS
public static final String CONVENTIONS
- See Also:
- Constant Field Values
-
COORD_SYS_BUILDER
public static final String COORD_SYS_BUILDER
- See Also:
- Constant Field Values
-
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
-
COORDINATES
public static final String COORDINATES
- See Also:
- Constant Field Values
-
SPATIAL_REF
public static final String SPATIAL_REF
- See Also:
- Constant Field Values
-
GEO_TRANSFORM
public static final String GEO_TRANSFORM
- See Also:
- Constant Field Values
-
CERP_ESRI_PE_STRING
public static final String CERP_ESRI_PE_STRING
- 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
-
STORE_NAME
public static final String STORE_NAME
- See Also:
- Constant Field Values
-
URI_FORMAT_CACHE
protected static final Map<URI,NetCDFUtilities.FileFormat> URI_FORMAT_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 isvariable.getRank() - X_DIMENSION
. Is hard-coded because the loop in theread
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 isvariable.getRank() - Y_DIMENSION
. Is hard-coded because the loop in theread
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 isvariable.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.
-
NC4_ERROR_MESSAGE
public static final String NC4_ERROR_MESSAGE
- See Also:
- Constant Field Values
-
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
-
PARAMS_MIN_KEY
public static final String PARAMS_MIN_KEY
- 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 ofNetcdfImageReader#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
- theDataType
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 returnstrue
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 returnstrue
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 returnstrue
if the specified variable is accepted.
-
getFormat
public static NetCDFUtilities.FileFormat getFormat(URI uri) throws IOException
- Throws:
IOException
-
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 aNetcdfDataset
given an input object the input object (usually aFile
, aString
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.
- For time axis, a
-
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.
-
createFeatureType
public static SimpleFeatureType createFeatureType(String schemaName, String schemaDef, CoordinateReferenceSystem crs)
-
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 inputVariable
- Parameters:
var
- Variable instance- Returns:
- a Number representing NoData
-
getRange
public static NumberRange getRange(Variable var)
Utility method for getting Range from an inputVariable
- 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 beamProductData
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 dimensionsvarDataType
- 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
- theDataType
to transcode.- Returns:
- the proper number instance
-
refreshParameterBehaviors
public static void refreshParameterBehaviors()
-
getParameterBehaviour
public static NetCDFUtilities.ParameterBehaviour getParameterBehaviour(String parameter)
-
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()
-
-