Package ucar.nc2.dataset
Interface EnhanceScaleMissingUnsigned
- All Superinterfaces:
IsMissingEvaluator
- All Known Implementing Classes:
CoordinateAxis,CoordinateAxis1D,CoordinateAxis1DTime,CoordinateAxis2D,VariableDS,VariableEnhancer
Deprecated.
use implementations in Filter package
A Variable decorator that handles unsigned data, scale/offset packed data, and missing data. Specifically, it
handles:
- unsigned data using
_Unsigned - packed data using
scale_factorandadd_offset - invalid/missing data using
valid_min,valid_max,valid_range,missing_value, or_FillValue
Standard Use
Implementation rules for unsigned data
- A variable is considered unsigned if it has an
unsigned data typeor an_Unsignedattribute with valuetrue. - Values will be
widened, which effectively reinterprets signed data as unsigned data. - To accommodate the unsigned conversion, the variable's data type will be changed to the
next larger type.
Implementation rules for scale/offset
- If scale_factor and/or add_offset variable attributes are present, then this is a "packed" Variable.
- The data type of the variable will be set to the
largest of:- the original data type
- the unsigned conversion type, if applicable
- the
scale_factorattribute type - the
add_offsetattribute type
getScaledOffsetType()will be unsigned as well. - External (packed) data is converted to internal (unpacked) data transparently during the
applyScaleOffset(Array)call.
Implementation rules for missing data
Here "missing data" is a general name for invalid/never-written/missing values. Use this interface when you don't need to distinguish these variants. See below for a lower-level interface if you do need to distinguish between them.- By default, hasMissing() is true if any of hasValidData(), hasFillValue() or hasMissingValue() are true (see below). You can modify this behavior by calling setInvalidDataIsMissing(), setFillValueIsMissing(), or setMissingDataIsMissing().
- Test specific values through isMissing(double). Note that the data is converted and compared as a double.
- Data values of float or double NaN are considered missing data and will return true if called with isMissing(). (However isMissing() will not detect if you are setting NaNs yourself).
Implementation rules for missing data with scale/offset
- _FillValue and missing_value values are always in the units of the external (packed) data.
- If valid_range is the same type as scale_factor (actually the wider of scale_factor and add_offset) and this is wider than the external data, then it will be interpreted as being in the units of the internal (unpacked) data. Otherwise it is in the units of the external (packed) data.
Low Level Access
The following provide more direct access to missing/invalid data. These are mostly convenience routines for checking the standard attributes. If you set useNaNs = true in the constructor, these routines cannot be used when the data has type float or double.Implementation rules for valid_range
- If valid_range is present, valid_min and valid_max attributes are ignored. Otherwise, the valid_min and/or valid_max is used to construct a valid range. If any of these exist, hasValidData() is true.
- To test a specific value, call isInvalidData(). Note that the data is converted and compared as a double. Or get the range through getValidMin() and getValidMax().
Implementation rules for _FillData
- If the _FillData attribute is present, it must have a scalar value of the same type as the data. In this case, hasFillValue() returns true.
- Test specific values through isFillValue(). Note that the data is converted and compared as a double.
Implementation rules for missing_value
- If the missing_value attribute is present, it must have a scalar or vector value of the same type as the data. In this case, hasMissingValue() returns true.
- Test specific values through isMissingValue(). Note that the data is converted and compared as a double.
Strategies for using EnhanceScaleMissingUnsigned
- Low-level: use the is/has InvalidData/FillValue/MissingValue routines to "roll-your own" tests for the various kinds of missing/invalid data.
- Standard: use is/hasMissing() to test for missing data when you don't need to distinguish between the variants. Use the setXXXisMissing() to customize the behavior if needed.
-
Method Summary
Modifier and TypeMethodDescriptiondoubleapplyScaleOffset(Number value) Deprecated.Apply scale and offset to the specified value ifhasScaleOffset().applyScaleOffset(Array data) Deprecated.Apply scale and offset to each element ofinand return the result as a new Array, but only ifhasScaleOffset().Deprecated.Perform the specified conversions on each element ofinand return the result as a new Array.convertMissing(Number value) Deprecated.convertMissing(Array in) Deprecated.convertUnsigned(Number value) Deprecated.Convertvalueto the next largest integral data type by anunsigned conversion.convertUnsigned(Array in) Deprecated.Performs anunsigned conversionof each element ofinand returns the result as a new Array.doubleDeprecated.return value of _FillValue attributedouble[]Deprecated.return values of missing_value attributesdoubleDeprecated.The number to be added to the data after it is read.Deprecated.Return the data type for values that have undergone scale/offset conversion.doubleDeprecated.The data are to be multiplied by this value after the data are read.Deprecated.Returns the signedness of the decorated variable.Deprecated.Return the data type for values that have undergone unsigned conversion.doubleDeprecated.return the maximum value in the valid rangedoubleDeprecated.return the minimum value in the valid rangebooleanDeprecated.true if Variable has _FillValue attributebooleanDeprecated.true if Variable has missing data valuesbooleanDeprecated.true if Variable has missing_value attributebooleanDeprecated.true if Variable data will be converted using scale and offsetbooleanDeprecated.true if Variable has valid_range, valid_min or valid_max attributesbooleanisFillValue(double val) Deprecated.return true if val equals the _FillValuebooleanisInvalidData(double val) Deprecated.return true if val is outside the valid rangebooleanisMissing(double val) Deprecated.Returnstrueif the argument is a missing value.booleanisMissingValue(double val) Deprecated.return true if val equals a missing_value (low-level)voidsetFillValueIsMissing(boolean b) Deprecated.Do not use.voidsetInvalidDataIsMissing(boolean b) Deprecated.Do not use.voidsetMissingDataIsMissing(boolean b) Deprecated.Do not use.
-
Method Details
-
hasScaleOffset
boolean hasScaleOffset()Deprecated.true if Variable data will be converted using scale and offset -
getScaleFactor
double getScaleFactor()Deprecated.The data are to be multiplied by this value after the data are read. By default it is1.0, i.e. no scaling. It will remain that value if the variable defines noCDM.SCALE_FACTORattribute.- Returns:
- the multiplier to apply to the data.
-
getOffset
double getOffset()Deprecated.The number to be added to the data after it is read. If bothCDM.SCALE_FACTORandCDM.ADD_OFFSETattributes are present, the data are first scaled before the offset is added. By default it is0.0, i.e. no offset. It will remain that value if the variable defines noCDM.SCALE_FACTORattribute.- Returns:
- the number to add to the data.
-
hasMissing
boolean hasMissing()Deprecated.true if Variable has missing data values- Specified by:
hasMissingin interfaceIsMissingEvaluator- Returns:
- true if Variable has missing data values
-
isMissing
boolean isMissing(double val) Deprecated.Returnstrueif the argument is a missing value. Note thatFloat.NaNandDouble.NaNare considered missing data.- Specified by:
isMissingin interfaceIsMissingEvaluator- Parameters:
val- an unpacked value.- Returns:
trueif the argument is a missing value.
-
hasValidData
boolean hasValidData()Deprecated.true if Variable has valid_range, valid_min or valid_max attributes -
getValidMin
double getValidMin()Deprecated.return the minimum value in the valid range -
getValidMax
double getValidMax()Deprecated.return the maximum value in the valid range -
isInvalidData
boolean isInvalidData(double val) Deprecated.return true if val is outside the valid range -
hasFillValue
boolean hasFillValue()Deprecated.true if Variable has _FillValue attribute -
getFillValue
double getFillValue()Deprecated.return value of _FillValue attribute -
isFillValue
boolean isFillValue(double val) Deprecated.return true if val equals the _FillValue -
hasMissingValue
boolean hasMissingValue()Deprecated.true if Variable has missing_value attribute -
getMissingValues
double[] getMissingValues()Deprecated.return values of missing_value attributes -
isMissingValue
boolean isMissingValue(double val) Deprecated.return true if val equals a missing_value (low-level) -
setFillValueIsMissing
Deprecated.Do not use.Set if _FillValue is considered isMissing(). -
setInvalidDataIsMissing
Deprecated.Do not use.set if valid_range is considered isMissing(); better set in constructor if possible -
setMissingDataIsMissing
Deprecated.Do not use.set if missing_data is considered isMissing(); better set in constructor if possible -
getScaledOffsetType
Deprecated.Return the data type for values that have undergone scale/offset conversion. This will benullif the decorated variable lacksscale_factororadd_offsetattributes. You can check withhasScaleOffset().- Returns:
- the data type for values that have undergone scale/offset conversion.
-
getUnsignedConversionType
Deprecated.Return the data type for values that have undergone unsigned conversion. This will never benull, 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.- Returns:
- the data type for values that have undergone unsigned conversion.
-
getSignedness
DataType.Signedness getSignedness()Deprecated.Returns the signedness of the decorated variable.- Returns:
- the signedness of the decorated variable.
-
convertUnsigned
Deprecated.Convertvalueto the next largest integral data type by anunsigned conversion. The conversion only happens if the decorated variableis unsignedandvalueis a negative integer. Otherwise, simply returnvalue.- Parameters:
value- an integral number to convert.- Returns:
- the result of an unsigned conversion of
value.
-
convertUnsigned
Deprecated.Performs anunsigned conversionof each element ofinand returns the result as a new Array. The data type of the returned array will begetUnsignedConversionType().- Parameters:
in- an Array containing integral Numbers to convert.- Returns:
- the result of an unsigned conversion of each element of
in.
-
applyScaleOffset
Deprecated.Apply scale and offset to the specified value ifhasScaleOffset(). Otherwise, just returnvalue. -
applyScaleOffset
Deprecated.Apply scale and offset to each element ofinand return the result as a new Array, but only ifhasScaleOffset(). Otherwise, just returnvalue. Otherwise, just returndata.- Parameters:
data- convert this- Returns:
- converted data.
-
convertMissing
Deprecated. -
convertMissing
Deprecated.- Parameters:
in- an array containing floating-point numbers to convert.- Returns:
- the result of a missing conversion of each element of
in.
-
convert
Deprecated.Perform the specified conversions on each element ofinand return the result as a new Array. Note that this method is more efficient than callingconvertUnsigned(Array), followed byapplyScaleOffset(Array), followed byconvertMissing(Array), as only one copy ofinis made.- Parameters:
in- a numeric array.convertUnsigned-trueif we shouldconvert unsigned.applyScaleOffset-trueif we shouldapply scale/offset.convertMissing-trueif we shouldconvert missing.- Returns:
- a new array, with the specified conversions performed.
-