Class VariableDS

java.lang.Object
ucar.nc2.CDMNode
ucar.nc2.Variable
ucar.nc2.dataset.VariableDS
All Implemented Interfaces:
Comparable<VariableSimpleIF>, Iterable<Attribute>, IsMissingEvaluator, AttributeContainer, ucar.nc2.dataset.Enhancements, ucar.nc2.dataset.EnhanceScaleMissingUnsigned, VariableEnhanced, ProxyReader, VariableSimpleIF
Direct Known Subclasses:
CoordinateAxis

public class VariableDS extends Variable implements VariableEnhanced, ucar.nc2.dataset.EnhanceScaleMissingUnsigned
A wrapper around a Variable, creating an "enhanced" Variable. The original Variable is used for the I/O. There are several distinct uses:
  1. Handle scale/offset/missing/enum/unsigned conversion; this can change DataType and data values
  2. Container for coordinate system information
  3. NcML modifications to underlying Variable
See Also:
  • Method Details

    • getNetcdfFile

      public NetcdfFile getNetcdfFile()
      Description copied from class: Variable
      Get the NetcdfFile that this variable is contained in. May be null.
      Overrides:
      getNetcdfFile in class Variable
    • 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

      public Variable getOriginalVariable()
      A VariableDS usually wraps another Variable.
      Specified by:
      getOriginalVariable in interface VariableEnhanced
      Returns:
      original Variable or null
    • getOriginalDataType

      public DataType getOriginalDataType()
      When this wraps another Variable, get the original Variable's DataType.
      Returns:
      original Variable's DataType, or current data type if it doesnt wrap another variable
    • getOriginalName

      public String getOriginalName()
      When this wraps another Variable, get the original Variable's name.
      Specified by:
      getOriginalName in interface VariableEnhanced
      Returns:
      original Variable's name
    • lookupEnumString

      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 class Variable
      Parameters:
      val - the integer value of this enum
      Returns:
      the String value
    • toStringDebug

      public String toStringDebug()
      Description copied from class: Variable
      String representation of Variable and its attributes.
      Overrides:
      toStringDebug in class Variable
    • getDatasetLocation

      public String getDatasetLocation()
      Description copied from class: Variable
      The location of the dataset this belongs to. Labeling purposes only.
      Overrides:
      getDatasetLocation in class Variable
    • reallyRead

      public Array reallyRead(Variable client, CancelTask cancelTask) throws IOException
      Description copied from class: Variable
      public by accident, do not call directly.
      Specified by:
      reallyRead in interface ProxyReader
      Overrides:
      reallyRead in class Variable
      Parameters:
      client - the client Variable
      cancelTask - user may cancel
      Returns:
      Array
      Throws:
      IOException - on error
    • reallyRead

      public Array reallyRead(Variable client, Section section, CancelTask cancelTask) throws IOException, InvalidRangeException
      Description copied from class: Variable
      public by accident, do not call directly.
      Specified by:
      reallyRead in interface ProxyReader
      Overrides:
      reallyRead in class Variable
      Parameters:
      client - the client Variable
      section - the section of data to read.
      cancelTask - user may cancel
      Returns:
      Array
      Throws:
      IOException - on error
      InvalidRangeException - if section has incorrect rank or illegal shape.
    • readToStream

      public long readToStream(Section section, OutputStream out) throws IOException, InvalidRangeException
      Description copied from class: Variable
      Read variable data to a stream. Support for NcStreamWriter.
      Overrides:
      readToStream in class Variable
      Throws:
      IOException
      InvalidRangeException
    • getMissingDataArray

      public Array getMissingDataArray(int[] shape)
      Return Array with missing data
      Parameters:
      shape - of this shape
      Returns:
      Array with given shape
    • showScaleMissingProxy

      public void showScaleMissingProxy(Formatter f)
      public for debugging
      Parameters:
      f - put info here
    • 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 interface ucar.nc2.dataset.Enhancements
      Specified by:
      getDescription in interface VariableSimpleIF
      Overrides:
      getDescription in class Variable
      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 interface ucar.nc2.dataset.Enhancements
      Specified by:
      getUnitsString in interface VariableSimpleIF
      Overrides:
      getUnitsString in class Variable
      Returns:
      unit string, or null if not found.
    • getCoordinateSystems

      public com.google.common.collect.ImmutableList<CoordinateSystem> getCoordinateSystems()
      Description copied from interface: Enhancements
      Get the list of Coordinate Systems for this Variable.
      Specified by:
      getCoordinateSystems in interface ucar.nc2.dataset.Enhancements
      Returns:
      list of type CoordinateSystem; may be empty but not null.
    • hasScaleOffset

      public boolean hasScaleOffset()
      Description copied from interface: EnhanceScaleMissingUnsigned
      true if Variable data will be converted using scale and offset
      Specified by:
      hasScaleOffset in interface ucar.nc2.dataset.EnhanceScaleMissingUnsigned
    • getScaleFactor

      public double getScaleFactor()
      Description copied from interface: EnhanceScaleMissingUnsigned
      The data are to be multiplied by this value after the data are read. By default it is 1.0, i.e. no scaling. It will remain that value if the variable defines no CDM.SCALE_FACTOR attribute.
      Specified by:
      getScaleFactor in interface ucar.nc2.dataset.EnhanceScaleMissingUnsigned
      Returns:
      the multiplier to apply to the data.
    • getOffset

      public double getOffset()
      Description copied from interface: EnhanceScaleMissingUnsigned
      The number to be added to the data after it is read. If both CDM.SCALE_FACTOR and CDM.ADD_OFFSET attributes are present, the data are first scaled before the offset is added. By default it is 0.0, i.e. no offset. It will remain that value if the variable defines no CDM.SCALE_FACTOR attribute.
      Specified by:
      getOffset in interface ucar.nc2.dataset.EnhanceScaleMissingUnsigned
      Returns:
      the number to add to the data.
    • hasMissing

      public boolean hasMissing()
      Description copied from interface: EnhanceScaleMissingUnsigned
      true if Variable has missing data values
      Specified by:
      hasMissing in interface ucar.nc2.dataset.EnhanceScaleMissingUnsigned
      Specified by:
      hasMissing in interface IsMissingEvaluator
      Returns:
      true if Variable has missing data values
    • isMissing

      public boolean isMissing(double val)
      Description copied from interface: EnhanceScaleMissingUnsigned
      Returns true if the argument is a missing value. Note that Float.NaN and Double.NaN are considered missing data.
      Specified by:
      isMissing in interface ucar.nc2.dataset.EnhanceScaleMissingUnsigned
      Specified by:
      isMissing in interface IsMissingEvaluator
      Parameters:
      val - an unpacked value.
      Returns:
      true if the argument is a missing value.
    • hasValidData

      public boolean hasValidData()
      Description copied from interface: EnhanceScaleMissingUnsigned
      true if Variable has valid_range, valid_min or valid_max attributes
      Specified by:
      hasValidData in interface ucar.nc2.dataset.EnhanceScaleMissingUnsigned
    • getValidMin

      public double getValidMin()
      Description copied from interface: EnhanceScaleMissingUnsigned
      return the minimum value in the valid range
      Specified by:
      getValidMin in interface ucar.nc2.dataset.EnhanceScaleMissingUnsigned
    • getValidMax

      public double getValidMax()
      Description copied from interface: EnhanceScaleMissingUnsigned
      return the maximum value in the valid range
      Specified by:
      getValidMax in interface ucar.nc2.dataset.EnhanceScaleMissingUnsigned
    • isInvalidData

      public boolean isInvalidData(double val)
      Description copied from interface: EnhanceScaleMissingUnsigned
      return true if val is outside the valid range
      Specified by:
      isInvalidData in interface ucar.nc2.dataset.EnhanceScaleMissingUnsigned
    • hasFillValue

      public boolean hasFillValue()
      Description copied from interface: EnhanceScaleMissingUnsigned
      true if Variable has _FillValue attribute
      Specified by:
      hasFillValue in interface ucar.nc2.dataset.EnhanceScaleMissingUnsigned
    • getFillValue

      public double getFillValue()
      Description copied from interface: EnhanceScaleMissingUnsigned
      return value of _FillValue attribute
      Specified by:
      getFillValue in interface ucar.nc2.dataset.EnhanceScaleMissingUnsigned
    • isFillValue

      public boolean isFillValue(double val)
      Description copied from interface: EnhanceScaleMissingUnsigned
      return true if val equals the _FillValue
      Specified by:
      isFillValue in interface ucar.nc2.dataset.EnhanceScaleMissingUnsigned
    • hasMissingValue

      public boolean hasMissingValue()
      Description copied from interface: EnhanceScaleMissingUnsigned
      true if Variable has missing_value attribute
      Specified by:
      hasMissingValue in interface ucar.nc2.dataset.EnhanceScaleMissingUnsigned
    • getMissingValues

      public double[] getMissingValues()
      Description copied from interface: EnhanceScaleMissingUnsigned
      return values of missing_value attributes
      Specified by:
      getMissingValues in interface ucar.nc2.dataset.EnhanceScaleMissingUnsigned
    • isMissingValue

      public boolean isMissingValue(double val)
      Description copied from interface: EnhanceScaleMissingUnsigned
      return true if val equals a missing_value (low-level)
      Specified by:
      isMissingValue in interface ucar.nc2.dataset.EnhanceScaleMissingUnsigned
    • missingDataIsMissing

      public boolean missingDataIsMissing()
    • fillValueIsMissing

      public boolean fillValueIsMissing()
    • invalidDataIsMissing

      public boolean invalidDataIsMissing()
    • getScaledOffsetType

      @Nullable public DataType getScaledOffsetType()
      Description copied from interface: EnhanceScaleMissingUnsigned
      Return the data type for values that have undergone scale/offset conversion. This will be null if the decorated variable lacks scale_factor or add_offset attributes. You can check with EnhanceScaleMissingUnsigned.hasScaleOffset().
      Specified by:
      getScaledOffsetType in interface ucar.nc2.dataset.EnhanceScaleMissingUnsigned
      Returns:
      the data type for values that have undergone scale/offset conversion.
    • getUnsignedConversionType

      public DataType getUnsignedConversionType()
      Description copied from interface: EnhanceScaleMissingUnsigned
      Return the data type for values that have undergone unsigned conversion. This will never be null, even when no unsigned conversion is necessary (because the underlying variable isn't unsigned). In such cases, this data type will be the same as that of the underlying variable.
      Specified by:
      getUnsignedConversionType in interface ucar.nc2.dataset.EnhanceScaleMissingUnsigned
      Returns:
      the data type for values that have undergone unsigned conversion.
    • getSignedness

      public DataType.Signedness getSignedness()
      Description copied from interface: EnhanceScaleMissingUnsigned
      Returns the signedness of the decorated variable.
      Specified by:
      getSignedness in interface ucar.nc2.dataset.EnhanceScaleMissingUnsigned
      Returns:
      the signedness of the decorated variable.
    • applyScaleOffset

      public double applyScaleOffset(Number value)
      Description copied from interface: EnhanceScaleMissingUnsigned
      Apply scale and offset to the specified value if EnhanceScaleMissingUnsigned.hasScaleOffset(). Otherwise, just return value.
      Specified by:
      applyScaleOffset in interface ucar.nc2.dataset.EnhanceScaleMissingUnsigned
    • applyScaleOffset

      public Array applyScaleOffset(Array data)
      Description copied from interface: EnhanceScaleMissingUnsigned
      Apply scale and offset to each element of in and return the result as a new Array, but only if EnhanceScaleMissingUnsigned.hasScaleOffset(). Otherwise, just return value. Otherwise, just return data.
      Specified by:
      applyScaleOffset in interface ucar.nc2.dataset.EnhanceScaleMissingUnsigned
      Parameters:
      data - convert this
      Returns:
      converted data.
    • convertUnsigned

      public Number convertUnsigned(Number value)
      Description copied from interface: EnhanceScaleMissingUnsigned
      Convert value to the next largest integral data type by an unsigned conversion. The conversion only happens if the decorated variable is unsigned and value is a negative integer. Otherwise, simply return value.
      Specified by:
      convertUnsigned in interface ucar.nc2.dataset.EnhanceScaleMissingUnsigned
      Parameters:
      value - an integral number to convert.
      Returns:
      the result of an unsigned conversion of value.
    • convertUnsigned

      public Number convertUnsigned(Number value, DataType dataType)
    • convertUnsigned

      public Array convertUnsigned(Array in)
      Description copied from interface: EnhanceScaleMissingUnsigned
      Performs an unsigned conversion of each element of in and returns the result as a new Array. The data type of the returned array will be EnhanceScaleMissingUnsigned.getUnsignedConversionType().
      Specified by:
      convertUnsigned in interface ucar.nc2.dataset.EnhanceScaleMissingUnsigned
      Parameters:
      in - an Array containing integral Numbers to convert.
      Returns:
      the result of an unsigned conversion of each element of in.
    • convertMissing

      public Number convertMissing(Number value)
      Description copied from interface: EnhanceScaleMissingUnsigned
      If value is missing, return Double.NaN. Otherwise, simply return value
      Specified by:
      convertMissing in interface ucar.nc2.dataset.EnhanceScaleMissingUnsigned
    • convertMissing

      public Array convertMissing(Array in)
      Description copied from interface: EnhanceScaleMissingUnsigned
      Returns a copy of in, except that each missing value is replaced by Double.NaN.
      Specified by:
      convertMissing in interface ucar.nc2.dataset.EnhanceScaleMissingUnsigned
      Parameters:
      in - an array containing floating-point numbers to convert.
      Returns:
      the result of a missing conversion of each element of in.
    • toBuilder

      public VariableDS.Builder<?> toBuilder()
      Description copied from class: Variable
      Turn into a mutable Builder. Can use toBuilder().build() to copy.
      Overrides:
      toBuilder in class Variable
    • builder

      public static VariableDS.Builder<?> builder()
      Get Builder for this class that allows subclassing.
      See Also:
      • "https://community.oracle.com/blogs/emcmanus/2010/10/24/using-builder-pattern-subclasses"