Package noaa.coastwatch.util
Class Grid
java.lang.Object
noaa.coastwatch.util.MetadataContainer
noaa.coastwatch.util.DataVariable
noaa.coastwatch.util.Grid
- All Implemented Interfaces:
Cloneable,ValueSource
- Direct Known Subclasses:
CachedGrid,OpendapGrid,SubsetGrid,TileCachedGrid
The 2D grid class is a special form of data variable with
two dimensions -- rows and columns. The grid is associated with a
navigation correction in the form of an affine transform. The
affine transform is used to translate between "desired" data
coordinates and "actual" data coordinates. Suppose that the data
value at row, column coordinate
(r,c) is desired.
Then the actual coordinate in the variable data array is
calculated as (r',c') = affine ((r,c)) where
affine() is the application of the affine transform to
the data coordinate.- Since:
- 3.1.0
- Author:
- Peter Hollemans
-
Nested Class Summary
Nested classes/interfaces inherited from class noaa.coastwatch.util.DataVariable
DataVariable.AccessType -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intIndex of columns dimension (singular).static final intIndex of columns dimension.static final intIndex of rows dimension (singular).static final intIndex of rows dimension.Fields inherited from class noaa.coastwatch.util.DataVariable
data, dims, isUnsigned, lookup, unsignedType -
Constructor Summary
ConstructorsConstructorDescriptionGrid(String name, String longName, String units, int rows, int cols, Object data, NumberFormat format, double[] scaling, Object missing) Constructs a new 2D grid with the specified properties.Constructs a new 2D grid from the specified grid.Constructs a new 2D grid from the specified grid and dimensions. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidarraycopy(Object src, int[] srcDims, int[] srcPos, Object dest, int[] destDims, int[] destPos, int[] length) Performs an array copy of 2D data stored in 1D arrays.booleancheckSubset(int[] start, int[] count) Checks the subset specification for errors.getData(int[] start, int[] count) Gets a subset of grid data values.Gets the navigation correction affine transform.getSubset(int[] start, int[] dims) Gets a new subset of this grid using the specified parameters.Gets the tiling scheme for this grid if one is available.doublegetValue(int row, int col) Reads a scaled data value with no navigation.doublegetValue(DataLocation loc) Reads a scaled data value with navigation.doubleinterpolate(DataLocation loc) Reads an interpolated data value.static voidTests this class.navigate(DataLocation loc) Applies the navigation transform to the specified data coordinate.voidSets a subset of grid data values.voidSets the navigation correction affine transform.voidsetValue(int row, int col, double val) Writes a scaled data value with no navigation.voidsetValue(DataLocation loc, double val) Writes a scaled data value with navigation.Methods inherited from class noaa.coastwatch.util.DataVariable
convertUnits, dispose, format, format, format, getClassBits, getData, getDataClass, getDecimals, getDimensions, getFormat, getLongName, getMissing, getName, getOptimalStride, getRank, getScaling, getStatistics, getStatistics, getStatistics, getStatistics, getUnits, getUnsigned, getValue, getValue, getValues, setAccessHint, setAccessType, setData, setFormat, setLongName, setLookup, setMissing, setName, setUnits, setUnsigned, setValue, setValue, toStringMethods inherited from class noaa.coastwatch.util.MetadataContainer
clone, getMetadataMap
-
Field Details
-
ROWS
public static final int ROWSIndex of rows dimension.- See Also:
-
COLS
public static final int COLSIndex of columns dimension.- See Also:
-
ROW
public static final int ROWIndex of rows dimension (singular).- See Also:
-
COL
public static final int COLIndex of columns dimension (singular).- See Also:
-
-
Constructor Details
-
Grid
public Grid(String name, String longName, String units, int rows, int cols, Object data, NumberFormat format, double[] scaling, Object missing) Constructs a new 2D grid with the specified properties. Therowsandcolsspecify the grid dimensions. The inital affine transform is set to the identity.- See Also:
-
Grid
Constructs a new 2D grid from the specified grid. All properties are copied, but the data array contains no actual data values.- Parameters:
grid- the grid to use for properties.
-
Grid
Constructs a new 2D grid from the specified grid and dimensions. All properties are copied, but the data array contains no actual data values.- Parameters:
grid- the grid to use for properties.rows- the grid rows dimension.cols- the grid columns dimension.
-
-
Method Details
-
getTilingScheme
Gets the tiling scheme for this grid if one is available.- Returns:
- the tiling scheme or null for none.
- Since:
- 3.4.0
-
setValue
public void setValue(int row, int col, double val) Writes a scaled data value with no navigation. The data value is scaled according to the scaling factor and offset and written to the data array. No navigation transform is applied to correct the data location.- Parameters:
row- the data location row.col- the data location column.val- the data value as a double. If the data value isDouble.NaNand the missing value is non-null, the missing value is written to the array.- See Also:
-
getValue
public double getValue(int row, int col) Reads a scaled data value with no navigation. The data value is read from the data array and scaled according to the scaling factor and offset. No navigation transform is applied to correct the data location.- Parameters:
row- the data location row.col- the data location column.- Returns:
- the scaled data value as a
double. TheDouble.NaNvalue is used if the data value is missing or data coordinate is not valid. - See Also:
-
setValue
Writes a scaled data value with navigation. The data value is scaled according to the scaling factor and offset and written to the data array. The navigation transform is applied to correct the data location prior to writing the data value.- Overrides:
setValuein classDataVariable- Parameters:
loc- the data location. If the location does not navigate to a valid data coordinate, no value is written.val- the data value as a double. If the data value isDouble.NaNand the missing value is non-null, the missing value is written to the array.- See Also:
-
getValue
Reads a scaled data value with navigation. The data value is read from the data array and scaled according to the scaling factor and offset. The navigation transform is applied to correct the data location prior to reading the data value.- Specified by:
getValuein interfaceValueSource- Overrides:
getValuein classDataVariable- Parameters:
loc- the data value location.- Returns:
- the scaled data value as a
double. TheDouble.NaNvalue is used if the data value is missing or navigated data coordinate is not valid. - See Also:
-
interpolate
Description copied from class:DataVariableReads an interpolated data value.- Specified by:
interpolatein classDataVariable- Parameters:
loc- the data value location.- Returns:
- the scaled data value as a
double. TheDouble.NaNvalue is used if the data value is missing. - See Also:
-
checkSubset
public boolean checkSubset(int[] start, int[] count) Checks the subset specification for errors.- Parameters:
start- the starting [row, column].count- the subset dimension [rows, columns].- Returns:
- true if the subset is good, false otherwise.
-
arraycopy
public static void arraycopy(Object src, int[] srcDims, int[] srcPos, Object dest, int[] destDims, int[] destPos, int[] length) Performs an array copy of 2D data stored in 1D arrays. This method is similar toSystem.arraycopybut works with 2D data stored in 1D arrays in row-major order.- Parameters:
src- the source array.srcDims- the source array dimensions as [rows, columns].srcPos- the source starting position as [row, column].dest- the destination array.destDims- the destination array dimensions as [rows, columns].destPos- the destination starting position as [row, column].length- the copy length as [rows, columns].
-
setData
Sets a subset of grid data values. This method is similar toDataVariable.setData(Object), but sets only a subset of data values in the raw, unscaled form.- Parameters:
subset- the subset array of unscaled data values.start- the subset starting [row, column].count- the subset dimensions [rows, columns].- Throws:
IndexOutOfBoundsException- if the subset falls outside the grid dimensions.- Since:
- 3.4.0
-
getData
Gets a subset of grid data values. This method is similar togetData(int[], int[]), but retrieves only a subset of data values in the raw, unscaled form.- Parameters:
start- the subset starting [row, column].count- the subset dimension [rows, columns].- Returns:
- an array containing the unscaled data values.
- Throws:
IndexOutOfBoundsException- if the subset falls outside the grid dimensions.- See Also:
-
getSubset
Gets a new subset of this grid using the specified parameters.- Parameters:
start- the starting data location for the subset as[row, column].dims- the subset dimensions as[rows, columns].- Returns:
- the new subset of this grid.
-
main
Tests this class.- Parameters:
argv- the array of command line parameters.- Throws:
Exception
-