Package ucar.nc2.dataset
Class VariableDS
- java.lang.Object
-
- ucar.nc2.Variable
-
- ucar.nc2.dataset.VariableDS
-
- All Implemented Interfaces:
Comparable<Variable>
,VariableEnhanced
,ProxyReader
- Direct Known Subclasses:
CoordinateAxis
@Immutable public class VariableDS extends Variable implements VariableEnhanced
A wrapper around a Variable, creating an "enhanced" Variable. The original Variable is used for the I/O. There are several distinct uses:- Handle scale/offset/missing/enum/unsigned conversion; this can change DataType and data values
- Container for coordinate system information
- NcML modifications to underlying Variable
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
VariableDS.Builder<T extends VariableDS.Builder<T>>
-
Field Summary
-
Fields inherited from class ucar.nc2.Variable
permitCaching
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static VariableDS.Builder<?>
builder()
Get Builder for this class that allows subclassing.Array<?>
convertArray(Array<?> data)
Convert the data using the VariableDS enhancements.boolean
convertNeeded()
Does data need to be converted?static VariableDS
fromVar(Group group, Variable orgVar, boolean enhance)
Create a VariableDS from orgVar, with default enhancements if requested.ArrayType
getArrayType()
Get the data type of the Variable.List<CoordinateSystem>
getCoordinateSystems()
Get the list of Coordinate Systems for this Variable, larger number of axes first.String
getDatasetLocation()
The location of the dataset this belongs to.String
getDescription()
Get the description of the Variable.Set<NetcdfDataset.Enhance>
getEnhanceMode()
Returns the enhancements applied to this variable.NetcdfFile
getNetcdfFile()
Get the NetcdfFile that this variable is contained in.ArrayType
getOriginalArrayType()
When this wraps another Variable, get the original Variable's ArrayType.String
getOriginalName()
When this wraps another Variable, get the original Variable's name.Variable
getOriginalVariable()
A VariableDS usually wraps another Variable.String
getUnitsString()
Get the Unit String for the Variable.boolean
hasMissing()
true if Variable has missing data valuesboolean
isMissing(double val)
true if the argument is a missing value.String
lookupEnumString(int val)
Lookup the enum string for this value.Array<?>
proxyReadArray(Variable client, Section section, CancelTask cancelTask)
public by accident, do not call directly.Array<?>
proxyReadArray(Variable client, CancelTask cancelTask)
public by accident, do not call directly.Array<?>
readArray()
Read all the data for this Variable and return a memory resident Array.Array<?>
readArray(Section section)
Read a section of the data for this Variable from the netcdf file and return a memory resident Array.ucar.nc2.internal.dataset.EnhanceScaleMissingUnsigned
scaleMissingUnsignedProxy()
Visible for testing, do not use directly.void
setCaching(boolean caching)
Set whether to cache or not.VariableDS.Builder<?>
toBuilder()
Turn into a mutable Builder.String
toString()
-
Methods inherited from class ucar.nc2.Variable
attributes, compareTo, equals, findAttribute, findAttributeString, findDimensionIndex, getDimension, getDimensions, getDimensionSet, getDimensionsString, getElementSize, getEnumTypedef, getFileTypeId, getFullName, getNameAndDimensions, getNameAndDimensions, getParentGroup, getParentStructure, getRank, getSection, getShape, getShape, getShortName, getSize, getSizeToCache, getSPobject, hasCachedData, hashCode, isCaching, isCoordinateVariable, isMemberOfStructure, isMetadata, isScalar, isUnlimited, isVariableLength, readScalarByte, readScalarDouble, readScalarFloat, readScalarInt, readScalarLong, readScalarShort, readScalarString, reduce, section, slice
-
Methods inherited from interface ucar.nc2.dataset.VariableEnhanced
getFullName, getParentGroup, getShortName
-
-
-
-
Method Detail
-
fromVar
public static VariableDS fromVar(Group group, Variable orgVar, boolean enhance)
Create a VariableDS from orgVar, with default enhancements if requested.- Parameters:
group
- Reparent to this Group.orgVar
- Wrap this Variable.enhance
- opriona default enhancements.
-
getArrayType
public ArrayType getArrayType()
Description copied from class:Variable
Get the data type of the Variable.- Overrides:
getArrayType
in classVariable
-
getNetcdfFile
public NetcdfFile getNetcdfFile()
Description copied from class:Variable
Get the NetcdfFile that this variable is contained in. May be null when the Variable is self contained.- Overrides:
getNetcdfFile
in classVariable
-
hasMissing
public boolean hasMissing()
true if Variable has missing data values
-
isMissing
public boolean isMissing(double val)
true if the argument is a missing value. Note thatFloat.NaN
andDouble.NaN
are always considered missing data.- Parameters:
val
- an unpacked value.
-
convertNeeded
public boolean convertNeeded()
Does data need to be converted?
-
convertArray
public Array<?> convertArray(Array<?> data)
Convert the data using the VariableDS enhancements. Generally the user does not have to call this.
-
getEnhanceMode
public Set<NetcdfDataset.Enhance> getEnhanceMode()
Returns the enhancements applied to this variable. If this variable wraps another variable, the returned set will also contain the enhancements applied to the nested variable, recursively.- Returns:
- the enhancements applied to this variable.
-
getOriginalVariable
@Nullable public Variable getOriginalVariable()
A VariableDS usually wraps another Variable.- Specified by:
getOriginalVariable
in interfaceVariableEnhanced
-
getOriginalArrayType
public ArrayType getOriginalArrayType()
When this wraps another Variable, get the original Variable's ArrayType.- Returns:
- original Variable's ArrayType, or current data type if it doesnt wrap another variable
-
getOriginalName
@Nullable public String getOriginalName()
When this wraps another Variable, get the original Variable's name.- Specified by:
getOriginalName
in interfaceVariableEnhanced
- Returns:
- original Variable's name, or null.
-
lookupEnumString
@Nullable public String lookupEnumString(int val)
Description copied from class:Variable
Lookup the enum string for this value. Can only be called on enum types, where dataType.isEnum() is true.- Overrides:
lookupEnumString
in classVariable
- Parameters:
val
- the integer value of this enum- Returns:
- the String value, or null if not exist.
-
getDatasetLocation
public String getDatasetLocation()
Description copied from class:Variable
The location of the dataset this belongs to. Labeling purposes only.- Overrides:
getDatasetLocation
in classVariable
-
setCaching
public void setCaching(boolean caching)
Description copied from class:Variable
Set whether to cache or not. Implies that the entire array will be stored, once read. Normally this is set automatically based on size of data. if false, cachedData is cleared.- Overrides:
setCaching
in classVariable
-
readArray
public Array<?> readArray() throws IOException
Description copied from class:Variable
Read all the data for this Variable and return a memory resident Array. The Array has the same element type and shape as the Variable.- Overrides:
readArray
in classVariable
- Throws:
IOException
-
proxyReadArray
public Array<?> proxyReadArray(Variable client, CancelTask cancelTask) throws IOException
Description copied from class:Variable
public by accident, do not call directly.- Specified by:
proxyReadArray
in interfaceProxyReader
- Overrides:
proxyReadArray
in classVariable
- Throws:
IOException
-
readArray
public Array<?> readArray(Section section) throws IOException, InvalidRangeException
Description copied from class:Variable
Read a section of the data for this Variable from the netcdf file and return a memory resident Array. The Array has the same element type as the Variable, and the requested shape. Note that this does not do rank reduction, so the returned Array has the same rank as the Variable. Use Array.reduce() for rank reduction.- Overrides:
readArray
in classVariable
- Parameters:
section
- The section of data to read. Must be null or same rank as variable. If list is null, assume all data. Each Range corresponds to a Dimension. If the Range object is null, it means use the entire dimension.- Throws:
IOException
InvalidRangeException
-
proxyReadArray
public Array<?> proxyReadArray(Variable client, Section section, CancelTask cancelTask) throws IOException, InvalidRangeException
Description copied from class:Variable
public by accident, do not call directly.- Specified by:
proxyReadArray
in interfaceProxyReader
- Overrides:
proxyReadArray
in classVariable
- Throws:
IOException
InvalidRangeException
-
scaleMissingUnsignedProxy
public ucar.nc2.internal.dataset.EnhanceScaleMissingUnsigned scaleMissingUnsignedProxy()
Visible for testing, do not use directly.
-
getDescription
public String getDescription()
Description copied from class:Variable
Get the description of the Variable. Default is to use CDM.LONG_NAME attribute value. If not exist, look for "description", "title", or "standard_name" attribute value (in that order).- Specified by:
getDescription
in interfaceVariableEnhanced
- Overrides:
getDescription
in classVariable
- Returns:
- description, or null if not found.
-
getUnitsString
public String getUnitsString()
Description copied from class:Variable
Get the Unit String for the Variable. Looks for the CDM.UNITS attribute value- Specified by:
getUnitsString
in interfaceVariableEnhanced
- Overrides:
getUnitsString
in classVariable
- Returns:
- unit string, or null if not found.
-
getCoordinateSystems
public List<CoordinateSystem> getCoordinateSystems()
Description copied from interface:VariableEnhanced
Get the list of Coordinate Systems for this Variable, larger number of axes first.- Specified by:
getCoordinateSystems
in interfaceVariableEnhanced
-
toBuilder
public VariableDS.Builder<?> toBuilder()
Description copied from class:Variable
Turn into a mutable Builder. Can use toBuilder().build() to copy.
-
builder
public static VariableDS.Builder<?> builder()
Get Builder for this class that allows subclassing.
-
-