Class NetcdfDataset
- All Implemented Interfaces:
Closeable,AutoCloseable,ucar.nc2.util.cache.FileCacheable
NetcdfDataset extends the netCDF API, adding standard attribute parsing such as
scale and offset, and explicit support for Coordinate Systems.
A NetcdfDataset wraps a NetcdfFile, or is defined by an NcML document.
Be sure to close the dataset when done.
Using statics in NetcdfDatets, best practice is to use try-with-resource:
try (NetcdfDataset ncd = NetcdfDatasets.openDataset(fileName)) {
...
}
By default @code NetcdfDataset} is opened with all enhancements turned on. The default "enhance mode" can be set through setDefaultEnhanceMode(). One can also explicitly set the enhancements you want in the dataset factory methods. The enhancements are:
- ConvertEnums: convert enum values to their corresponding Strings. If you want to do this manually, you can call Variable.lookupEnumString().
- ConvertUnsigned: reinterpret the bit patterns of any negative values as unsigned.
- ApplyScaleOffset: process scale/offset attributes, and automatically convert the data.
- ConvertMissing: replace missing data with NaNs, for efficiency.
- CoordSystems: extract CoordinateSystem using the CoordSysBuilder plug-in mechanism.
Automatic scale/offset processing has some overhead that you may not want to incur up-front. If so, open the
NetcdfDataset without ApplyScaleOffset. The VariableDS data type is not promoted and the data is not
converted on a read, but you can call the convertScaleOffset() routines to do the conversion later.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classNetcdfDataset.Builder<T extends NetcdfDataset.Builder<T>>static enumPossible enhancements for a NetcdfDataset -
Field Summary
Fields inherited from class ucar.nc2.NetcdfFile
IOSP_MESSAGE_GET_NETCDF_FILE_FORMAT, IOSP_MESSAGE_RANDOM_ACCESS_FILE -
Method Summary
Modifier and TypeMethodDescriptionstatic NetcdfDataset.Builder<?>builder()Get Builder for this class that allows subclassing.static NetcdfDataset.Builderbuilder(NetcdfFile from) voidclose()Close all resources (files, sockets, etc) associated with this dataset.findCoordinateAxis(String fullName) Retrieve the CoordinateAxis with the specified type.findCoordinateAxis(AxisType type) Retrieve the CoordinateAxis with the specified Axis Type.findCoordinateSystem(String name) Retrieve the CoordinateSystem with the specified name.Retrieve the CoordinateTransform with the specified name.Get conventions used to analyse coordinate systems.com.google.common.collect.ImmutableList<CoordinateAxis>Get the list of all CoordinateAxis objects used by this dataset.com.google.common.collect.ImmutableList<CoordinateSystem>Get the list of all CoordinateSystem objects used by this dataset.com.google.common.collect.ImmutableList<CoordinateTransform>Get the list of all CoordinateTransform objects used by this dataset.static Set<NetcdfDataset.Enhance>voidShow debug / underlying implementation detailsstatic Set<NetcdfDataset.Enhance>Get the current state of dataset enhancement.static Set<NetcdfDataset.Enhance>Get a human-readable description for this file type.Get the file type id for the underlying data source.longstatic voidSet the default set of Enhancements to do for all subsequent dataset opens and acquires.Turn into a mutable Builder.Methods inherited from class ucar.nc2.NetcdfFile
findAttribute, findDimension, findGlobalAttribute, findGlobalAttributeIgnoreCase, findGroup, findVariable, getDetailInfo, getFileTypeVersion, getGlobalAttributes, getId, getLocation, getRootGroup, getTitle, getUnlimitedDimension, getVariables, hasUnlimitedDimension, readSection, sendIospMessage, toNcml, toString, writeNcml, writeNcmlMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface ucar.nc2.util.cache.FileCacheable
reacquire, release, setFileCache
-
Method Details
-
getEnhanceAll
-
getEnhanceNone
-
getDefaultEnhanceMode
-
setDefaultEnhanceMode
Set the default set of Enhancements to do for all subsequent dataset opens and acquires.- Parameters:
mode- the default set of Enhancements for open and acquire factory methods
-
getCoordinateSystems
Get the list of all CoordinateSystem objects used by this dataset.- Returns:
- list of type CoordinateSystem; may be empty, not null.
-
getConventionUsed
Get conventions used to analyse coordinate systems.- Returns:
- conventions used to analyse coordinate systems
-
getEnhanceMode
Get the current state of dataset enhancement.- Returns:
- the current state of dataset enhancement.
-
getCoordinateTransforms
Get the list of all CoordinateTransform objects used by this dataset.- Returns:
- list of type CoordinateTransform; may be empty, not null.
-
getCoordinateAxes
Get the list of all CoordinateAxis objects used by this dataset.- Returns:
- list of type CoordinateAxis; may be empty, not null.
-
findCoordinateAxis
Retrieve the CoordinateAxis with the specified Axis Type.- Parameters:
type- axis type- Returns:
- the first CoordinateAxis that has that type, or null if not found
-
findCoordinateAxis
Retrieve the CoordinateAxis with the specified type.- Parameters:
fullName- full escaped name of the coordinate axis- Returns:
- the CoordinateAxis, or null if not found
-
findCoordinateSystem
Retrieve the CoordinateSystem with the specified name.- Parameters:
name- String which identifies the desired CoordinateSystem- Returns:
- the CoordinateSystem, or null if not found
-
findCoordinateTransform
Retrieve the CoordinateTransform with the specified name.- Parameters:
name- String which identifies the desired CoordinateSystem- Returns:
- the CoordinateSystem, or null if not found
-
close
Close all resources (files, sockets, etc) associated with this dataset. If the underlying file was acquired, it will be released, otherwise closed.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceucar.nc2.util.cache.FileCacheable- Overrides:
closein classNetcdfFile- Throws:
IOException- if error when closing
-
getLastModified
public long getLastModified() -
getDetailInfo
Show debug / underlying implementation details- Overrides:
getDetailInfoin classNetcdfFile
-
getFileTypeId
Description copied from class:NetcdfFileGet the file type id for the underlying data source.- Overrides:
getFileTypeIdin classNetcdfFile- Returns:
- registered id of the file type
- See Also:
-
- "https://www.unidata.ucar.edu/software/netcdf-java/formats/FileTypes.html"
-
getFileTypeDescription
Description copied from class:NetcdfFileGet a human-readable description for this file type.- Overrides:
getFileTypeDescriptionin classNetcdfFile- Returns:
- description of the file type
- See Also:
-
- "https://www.unidata.ucar.edu/software/netcdf-java/formats/FileTypes.html"
-
toBuilder
Description copied from class:NetcdfFileTurn into a mutable Builder. Can use toBuilder().build() to copy.- Overrides:
toBuilderin classNetcdfFile
-
builder
Get Builder for this class that allows subclassing.- See Also:
-
- "https://community.oracle.com/blogs/emcmanus/2010/10/24/using-builder-pattern-subclasses"
-
builder
-