public abstract class DataVariable extends MetadataContainer implements ValueSource
TreeMap
functions, where it is expected that the key
be a Java String
object.Modifier and Type | Field and Description |
---|---|
protected java.lang.Object |
data
Array of data values.
|
protected int[] |
dims
Array of data dimension sizes.
|
protected boolean |
isUnsigned
The unsigned flag, true if the data values are unsigned.
|
protected double[] |
lookup
The lookup table.
|
protected int |
unsignedType
The unsigned type.
|
Constructor and Description |
---|
DataVariable(java.lang.String name,
java.lang.String longName,
java.lang.String units,
int[] dimensions,
java.lang.Object data,
java.text.NumberFormat format,
double[] scaling,
java.lang.Object missing)
Constructs a new data variable with the specified properties.
|
Modifier and Type | Method and Description |
---|---|
void |
convertUnits(java.lang.String newUnitSpec)
Converts the units of this variable to the new units.
|
void |
dispose()
Disposes of any resources used by this variable prior to being
finalized.
|
java.lang.String |
format(DataLocation loc)
Formats a data value to a string.
|
java.lang.String |
format(double val)
Formats a data value to a string.
|
java.lang.String |
format(int index)
Formats a data value to a string.
|
static int |
getClassBits(java.lang.Class c)
Gets the memory required by a primitive class.
|
java.lang.Object |
getData()
Gets the variable data array.
|
java.lang.Class |
getDataClass()
Gets the class associated with components of the data array.
|
static int |
getDecimals(java.lang.String number)
Gets the number of digits after the decimal place in a string
representing a fractional number with possible exponential part.
|
int[] |
getDimensions()
Gets the variable data array dimensions.
|
java.text.NumberFormat |
getFormat()
Gets the data number format.
|
java.lang.String |
getLongName()
Gets the descriptive variable name.
|
java.lang.Object |
getMissing()
Gets the data missing value.
|
java.lang.String |
getName()
Gets the short variable name.
|
int[] |
getOptimalStride(DataLocation start,
DataLocation end,
double factor,
int minCount)
Gets the optimal statistical sampling stride for this variable
based on a desired sampling factor and minimum number of values.
|
int |
getRank()
Gets the variable data array rank.
|
double[] |
getScaling()
Gets the scaling factor and offset.
|
Statistics |
getStatistics(DataLocation start,
DataLocation end,
double factor)
Gets the data variable statistics.
|
Statistics |
getStatistics(DataLocation start,
DataLocation end,
int[] stride)
Gets the data variable statistics.
|
Statistics |
getStatistics(double factor)
Gets the data variable statistics.
|
Statistics |
getStatistics(int[] stride)
Gets the data variable statistics.
|
java.lang.String |
getUnits()
Gets the variable units.
|
boolean |
getUnsigned()
Gets the unsigned flag.
|
double |
getValue(DataLocation loc)
Reads a scaled data value.
|
double |
getValue(int index)
Reads a scaled data value.
|
protected double |
getValue(int index,
java.lang.Object data)
Reads a scaled data value.
|
int |
getValues()
Gets the total number of data values indicated by the dimensions.
|
abstract double |
interpolate(DataLocation loc)
Reads an interpolated data value.
|
void |
setAccessHint(int[] start,
int[] end,
int[] stride)
Sets a hint to the variable that subsequent data access will
only read/write values within the specified data extents.
|
void |
setData(java.lang.Object data)
Sets the variable data array.
|
void |
setFormat(java.text.NumberFormat format)
Sets the data number format.
|
void |
setLongName(java.lang.String longName)
Sets the descriptive variable name.
|
void |
setLookup(double[] lookup)
Sets the lookup table.
|
void |
setMissing(java.lang.Object missing)
Sets the data missing value.
|
void |
setName(java.lang.String name)
Sets the short variable name.
|
void |
setUnits(java.lang.String units)
Sets the variable units.
|
void |
setUnsigned(boolean flag)
Sets the unsigned data flag.
|
void |
setValue(DataLocation loc,
double val)
Writes a scaled data value.
|
void |
setValue(int index,
double val)
Writes a scaled data value.
|
protected void |
setValue(int index,
java.lang.Object data,
double val)
Writes a scaled data value.
|
java.lang.String |
toString()
Gets a string representation of this variable.
|
clone, getMetadataMap
protected int[] dims
protected java.lang.Object data
protected boolean isUnsigned
protected int unsignedType
protected double[] lookup
public DataVariable(java.lang.String name, java.lang.String longName, java.lang.String units, int[] dimensions, java.lang.Object data, java.text.NumberFormat format, double[] scaling, java.lang.Object missing)
name
- a short variable name. The variable name should
reflect what the data values represent without being overly
verbose. For example, avhrr_ch4
would describe data
from the AVHRR sensor, channel 4.longName
- a long variable name. The long name is a verbose
string to describe the variable in common terms. For example,
the variable named sst
might have the long name
sea surface temperature
.units
- the real world variable units. For example if the
variable data describes a temperature in Celsius, the variable
units might be Celsius
.dimensions
- the variable data array dimensions. For a 2D
image data array, the dimensions would be the number of rows and
columns in the image.data
- the variable data array. The data should be stored
as a 1D array of values. It is up to the subclass to determine
the mapping between data coordinate and index into the data array
for data with dimensions greater than 1. If the passed array is
null
, data get/set/format methods are undefined.format
- a number format specification. The number format
will be used to convert data values from their numerical
representation to a string representation.scaling
- the scaling factor and offset. These values will
be used to convert between data stored in the data array and real
world values. In general, scaling is only necessary when
floating point data is stored as integers. When data is
retrieved from the data array, the following formula is used to
scale the values: (val - scaling[1])*scaling[0]
.
When setting values in the data array, the following formula is
used: val/scaling[0] + scaling[1]
. If
scaling
is null
, no scaling is
performed.missing
- the missing data value. The missing value is used
to represent data values in the data array that have purposely
not been recorded or were flagged as invalid. If
missing
is null
, no missing value is
used.public java.lang.String getName()
public void setName(java.lang.String name)
public java.lang.String getLongName()
public void setLongName(java.lang.String longName)
public java.lang.String getUnits()
public void setUnits(java.lang.String units)
public int[] getDimensions()
public int getRank()
public java.lang.Object getData()
public void setData(java.lang.Object data)
public double[] getScaling()
public java.text.NumberFormat getFormat()
public void setFormat(java.text.NumberFormat format)
public java.lang.Object getMissing()
public void setMissing(java.lang.Object missing)
public void setLookup(double[] lookup)
setValue()
may not be used. If both
lookup and scaling are set, the lookup takes precedence over the
scaling and the scaling is ignored.lookup
- the lookup table to use.public java.lang.Class getDataClass()
public void setUnsigned(boolean flag)
flag
- the unsigned flag, true is the data array contains
unsigned data.java.lang.IllegalArgumentException
- if the data class is not allowed
to be unsigned.getDataClass()
,
getUnsigned()
public boolean getUnsigned()
public static int getClassBits(java.lang.Class c)
c
- the primitive class.public abstract double interpolate(DataLocation loc)
loc
- the data value location.double
. The
Double.NaN
value is used if the data value is
missing.getValue(int)
,
getValue(DataLocation)
public double getValue(DataLocation loc)
getValue
in interface ValueSource
loc
- the data value location.double
. The
Double.NaN
value is used if the data value is
missing.getValue(int)
public int getValues()
protected double getValue(int index, java.lang.Object data)
index
- the index into the data array.data
- the data array to use for raw data.double
. The
Double.NaN
value is used if the data value is
missing.public double getValue(int index)
index
- the index into the data array.double
. The
Double.NaN
value is used if the data value is
missing.getValue(DataLocation)
public void setValue(DataLocation loc, double val)
loc
- the data location.val
- the data value as a double. If the data value is
Double.NaN
and the missing value is non-null, the
missing value is written to the array.setValue(int,double)
public void setValue(int index, double val)
index
- the index into the data array.val
- the data value as a double. If the data value is
Double.NaN
and the missing value is non-null, the
missing value is written to the array.setValue(DataLocation,double)
protected void setValue(int index, java.lang.Object data, double val)
index
- the index into the data array.data
- the data array to use for raw data.val
- the data value as a double. If the data value is
Double.NaN
and the missing value is non-null, the
missing value is written to the array.public java.lang.String format(DataLocation loc)
loc
- the data value location.format
,
format(int)
public java.lang.String format(int index)
index
- the index into the data array.format
,
format(DataLocation)
public java.lang.String format(double val)
val
- the data value as a double.format(DataLocation)
,
format(int)
public Statistics getStatistics(double factor)
factor
- the sample size as a fraction of the total number of
values. For example, to sample 1 percent of the data the sample
size is 0.01. The sample size is used to compute an optimal
stride while preserving sample frequency uniformity in each
dimension. The total number of sampled values is guaranteed to
be bounded below by the requested sample size.getStatistics(int[])
public int[] getOptimalStride(DataLocation start, DataLocation end, double factor, int minCount)
start
- the starting data location.end
- the ending data location.factor
- the sampling factor as a value in the range [0..1].minCount
- the minimum desired number of values. The stride
should ensure that the number of values actually sampled is
greater than this quantity.getStatistics(DataLocation,DataLocation,double)
,
getStatistics(DataLocation,DataLocation,int[])
public Statistics getStatistics(DataLocation start, DataLocation end, double factor)
start
- the starting data location. If null, the start is
the first location.end
- the ending data location. If null, the end is
the last location.factor
- the sample size as a fraction of the total number of
values. For example, to sample 1 percent of the data the sample
size is 0.01. The sample size is used to compute an optimal
stride while preserving sample frequency uniformity in each
dimension. The total number of sampled values is guaranteed to
be bounded below by the requested sample size.getStatistics(DataLocation,DataLocation,int[])
public Statistics getStatistics(int[] stride)
stride
- the data location stride in each dimension. The
stride is used to reduce the number of calculations required to
compute the statistics. The data variable is sampled at every
nth value along each dimension. For example if the stride is 4,
every 4th value is sampled. If null, the stride is 1 in each
dimension.getStatistics(double)
public Statistics getStatistics(DataLocation start, DataLocation end, int[] stride)
start
- the starting data location. If null, the start is
the first location.end
- the ending data location. If null, the end is
the last location.stride
- the data location stride in each dimension. The
stride is used to reduce the number of calculations required to
compute the statistics. The data variable is sampled at every
nth value along each dimension. For example if the stride is 4,
every 4th value is sampled. If null, the stride is 1 in each
dimension.Double.NaN
.java.lang.RuntimeException
- if the start or end locations are
invalid.getStatistics(DataLocation,DataLocation,double)
public static int getDecimals(java.lang.String number)
number
- the fractional number string.public void convertUnits(java.lang.String newUnitSpec)
newUnitSpec
- the new units to convert to.java.lang.IllegalArgumentException
- if the existing or new data
units cannot be recognized, or if the new units are incompatible
with the existing units.public void setAccessHint(int[] start, int[] end, int[] stride)
start
- the starting data coordinates.end
- the ending data coordinates.stride
- the data stride along each dimension.public java.lang.String toString()
toString
in class java.lang.Object
public void dispose()