Class Grid

All Implemented Interfaces:
Cloneable, ValueSource
Direct Known Subclasses:
CachedGrid, OpendapGrid, SubsetGrid, TileCachedGrid

public class Grid extends DataVariable
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
  • Field Details

  • 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. The rows and cols specify the grid dimensions. The inital affine transform is set to the identity.
      See Also:
    • Grid

      public Grid(Grid 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

      public Grid(Grid grid, int rows, int cols)
      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

      public TilingScheme getTilingScheme()
      Gets the tiling scheme for this grid if one is available.
      Returns:
      the tiling scheme or null for none.
      Since:
      3.4.0
    • getNavigation

      public AffineTransform getNavigation()
      Gets the navigation correction affine transform.
    • setNavigation

      public void setNavigation(AffineTransform nav)
      Sets the navigation correction affine transform.
    • 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 is Double.NaN and 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. The Double.NaN value is used if the data value is missing or data coordinate is not valid.
      See Also:
    • setValue

      public void setValue(DataLocation loc, double val)
      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:
      setValue in class DataVariable
      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 is Double.NaN and the missing value is non-null, the missing value is written to the array.
      See Also:
    • getValue

      public double getValue(DataLocation loc)
      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:
      getValue in interface ValueSource
      Overrides:
      getValue in class DataVariable
      Parameters:
      loc - the data value location.
      Returns:
      the scaled data value as a double. The Double.NaN value is used if the data value is missing or navigated data coordinate is not valid.
      See Also:
    • interpolate

      public double interpolate(DataLocation loc)
      Description copied from class: DataVariable
      Reads an interpolated data value.
      Specified by:
      interpolate in class DataVariable
      Parameters:
      loc - the data value location.
      Returns:
      the scaled data value as a double. The Double.NaN value 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 to System.arraycopy but 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

      public void setData(Object subset, int[] start, int[] count)
      Sets a subset of grid data values. This method is similar to DataVariable.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

      public Object getData(int[] start, int[] count)
      Gets a subset of grid data values. This method is similar to getData(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

      public Grid getSubset(int[] start, int[] dims)
      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

      public static void main(String[] argv) throws Exception
      Tests this class.
      Parameters:
      argv - the array of command line parameters.
      Throws:
      Exception