ucar.nc2.dt.grid
Class GeoGrid

java.lang.Object
  extended by ucar.nc2.dt.grid.GeoGrid
All Implemented Interfaces:
GridDatatype, NamedObject

public class GeoGrid
extends java.lang.Object
implements NamedObject, GridDatatype

A georeferencing "gridded" VariableEnhanced, that has a GridCoordSys. In VisAD data model, it is a sampled Field. The dimension are put into canonical order: (t, z, y, x).

Implementation note: If the Horizontal axes are 2D, the x and y dimensions are arbitrarily chosen to be gcs.getXHorizAxis().getDimension(1), gcs.getXHorizAxis().getDimension(0) respectively.

Note: these classes should be considered experimental and will likely be refactored in the next release.

Version:
$Revision: 68 $ $Date: 2006-07-13 00:08:20Z $
Author:
caron

Constructor Summary
GeoGrid(GridDataset dataset, VariableEnhanced dsvar, GridCoordSys gcs)
          Constructor.
 
Method Summary
 boolean equals(java.lang.Object oo)
          Instances which have same name and coordinate system are equal.
 Attribute findAttributeIgnoreCase(java.lang.String name)
          Convenience function; lookup Attribute by name.
 java.lang.String findAttValueIgnoreCase(java.lang.String attName, java.lang.String defaultValue)
          Convenience function; lookup Attribute value by name.
 java.util.List getAttributes()
          Get a List of Attribute specific to the Grid
 GridCoordSystem getCoordinateSystem()
          get the GridCoordSys for this GeoGrid.
 Array getDataSlice(int t, int z, int y, int x)
          Deprecated. use readDataSlice
 DataType getDataType()
          get the data type
 java.lang.String getDescription()
          get the standardized description, see VariableStandardized.getDescription()
 Dimension getDimension(int i)
          get the ith dimension
 java.util.List getDimensions()
          Returns an ArrayList containing the dimensions used by this geoGrid.
 Dimension getEnsembleDimension()
          get the ensemble Dimension, if it exists
 int getEnsembleDimensionIndex()
          get the ensemble Dimension index in the geogrid (canonical order)
 java.lang.String getInfo()
          nicely formatted information
 java.util.List getLevels()
          ArrayList of thredds.util.NamedObject, from the GridCoordSys.
 MAMath.MinMax getMinMaxSkipMissingData(Array a)
          Get the minimum and the maximum data value of the previously read Array, skipping missing values as defined by isMissingData(double val).
 java.lang.String getName()
          get the name of the geoGrid.
 ProjectionImpl getProjection()
          get the Projection.
 int getRank()
          get the rank
 Dimension getRunTimeDimension()
          get the run time Dimension, if it exists
 int getRunTimeDimensionIndex()
          get the runtime Dimension index in the geogrid (canonical order)
 int[] getShape()
          get the shape
 Dimension getTimeDimension()
          get the time Dimension, if it exists
 int getTimeDimensionIndex()
          get the time Dimension index in the geogrid (canonical order), or -1 if none
 java.util.List getTimes()
          ArrayList of thredds.util.NamedObject, from the GridCoordSys.
 java.lang.String getUnitsString()
          get the unit as a string, see VariableStandardized.getUnitString()
 java.lang.String getUnitString()
          Deprecated. use getUnitsString()
 VariableEnhanced getVariable()
          get the underlying Variable, if it exists.
 Dimension getXDimension()
          get the x Dimension, if it exists
 int getXDimensionIndex()
          get the x Dimension index in the geogrid (canonical order)
 Dimension getYDimension()
          get the y Dimension, if it exists
 int getYDimensionIndex()
          get the y Dimension index in the geogrid (canonical order)
 Dimension getZDimension()
          get the z Dimension, if it exists
 int getZDimensionIndex()
          get the z Dimension index in the geogrid (canonical order), or -1 if none
 int hashCode()
          Override Object.hashCode() to be consistent with equals.
 boolean hasMissingData()
          true if there may be missing data, see VariableStandardized.hasMissing()
 boolean isMissingData(double val)
          if val is missing data, see VariableStandardized.isMissingData()
 GridDatatype makeSubset(Range t_range, Range z_range, LatLonRect bbox, int z_stride, int y_stride, int x_stride)
          Create a new GeoGrid that is a logical subset of this GeoGrid.
 GridDatatype makeSubset(Range rt_range, Range e_range, Range t_range, Range z_range, Range y_range, Range x_range)
          Create a new GeoGrid that is a logical subset of this GeoGrid.
 Array readDataSlice(int t, int z, int y, int x)
          This reads an arbitrary data slice, returning the data in canonical order (t-z-y-x).
 Array readDataSlice(int rt, int e, int t, int z, int y, int x)
          This reads an arbitrary data slice, returning the data in canonical order (rt-e-t-z-y-x).
 Array readVolumeData(int t)
          Reads in the data "volume" at the given time index.
 Array readYXData(int t, int z)
          Reads a Y-X "horizontal slice" at the given time and vertical index.
 Array readZYData(int t, int x)
          Reads a Z-Y "vertical slice" at the given time and x index.
 float[] setMissingToNaN(float[] values)
          Convert (in place) all values in the given array that are considered as "missing" to Float.NaN, according to isMissingData(val).
 GeoGrid subset(Range t_range, Range z_range, LatLonRect bbox, int z_stride, int y_stride, int x_stride)
          Create a new GeoGrid that is a logical subset of this GeoGrid.
 GeoGrid subset(Range t_range, Range z_range, Range y_range, Range x_range)
          Create a new GeoGrid that is a logical subset of this GeoGrid.
 java.lang.String toString()
          string representation
 void writeFile(java.lang.String filename)
          experimental - do not use
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GeoGrid

public GeoGrid(GridDataset dataset,
               VariableEnhanced dsvar,
               GridCoordSys gcs)
Constructor.

Parameters:
dataset - belongs to this dataset
dsvar - wraps this Variable
gcs - has this grid coordinate system
Method Detail

getDimensions

public java.util.List getDimensions()
Returns an ArrayList containing the dimensions used by this geoGrid. The dimension are put into canonical order: (t, z, y, x). Note that the z and t dimensions are optional. If the Horizontal axes are 2D, the x and y dimensions are arbitrarily chosen to be gcs.getXHorizAxis().getDimension(1), gcs.getXHorizAxis().getDimension(0), respectively.

Specified by:
getDimensions in interface GridDatatype
Returns:
List with objects of type Dimension, in canonical order.

getDimension

public Dimension getDimension(int i)
get the ith dimension

Specified by:
getDimension in interface GridDatatype
Parameters:
i - : which dimension
Returns:
ith Dimension

getTimeDimension

public Dimension getTimeDimension()
get the time Dimension, if it exists

Specified by:
getTimeDimension in interface GridDatatype

getZDimension

public Dimension getZDimension()
get the z Dimension, if it exists

Specified by:
getZDimension in interface GridDatatype

getYDimension

public Dimension getYDimension()
get the y Dimension, if it exists

Specified by:
getYDimension in interface GridDatatype

getXDimension

public Dimension getXDimension()
get the x Dimension, if it exists

Specified by:
getXDimension in interface GridDatatype

getEnsembleDimension

public Dimension getEnsembleDimension()
get the ensemble Dimension, if it exists

Specified by:
getEnsembleDimension in interface GridDatatype

getRunTimeDimension

public Dimension getRunTimeDimension()
get the run time Dimension, if it exists

Specified by:
getRunTimeDimension in interface GridDatatype

getTimeDimensionIndex

public int getTimeDimensionIndex()
get the time Dimension index in the geogrid (canonical order), or -1 if none

Specified by:
getTimeDimensionIndex in interface GridDatatype

getZDimensionIndex

public int getZDimensionIndex()
get the z Dimension index in the geogrid (canonical order), or -1 if none

Specified by:
getZDimensionIndex in interface GridDatatype

getYDimensionIndex

public int getYDimensionIndex()
get the y Dimension index in the geogrid (canonical order)

Specified by:
getYDimensionIndex in interface GridDatatype

getXDimensionIndex

public int getXDimensionIndex()
get the x Dimension index in the geogrid (canonical order)

Specified by:
getXDimensionIndex in interface GridDatatype

getEnsembleDimensionIndex

public int getEnsembleDimensionIndex()
get the ensemble Dimension index in the geogrid (canonical order)

Specified by:
getEnsembleDimensionIndex in interface GridDatatype

getRunTimeDimensionIndex

public int getRunTimeDimensionIndex()
get the runtime Dimension index in the geogrid (canonical order)

Specified by:
getRunTimeDimensionIndex in interface GridDatatype

findAttributeIgnoreCase

public Attribute findAttributeIgnoreCase(java.lang.String name)
Convenience function; lookup Attribute by name.

Specified by:
findAttributeIgnoreCase in interface GridDatatype
Parameters:
name - the name of the attribute
Returns:
the attribute, or null if not found

findAttValueIgnoreCase

public java.lang.String findAttValueIgnoreCase(java.lang.String attName,
                                               java.lang.String defaultValue)
Convenience function; lookup Attribute value by name. Must be String valued

Specified by:
findAttValueIgnoreCase in interface GridDatatype
Parameters:
attName - name of the attribute
defaultValue - if not found, use this as the default
Returns:
Attribute string value, or default if not found.

getRank

public int getRank()
get the rank

Specified by:
getRank in interface GridDatatype

getShape

public int[] getShape()
get the shape

Specified by:
getShape in interface GridDatatype

getDataType

public DataType getDataType()
get the data type

Specified by:
getDataType in interface GridDatatype

getAttributes

public java.util.List getAttributes()
Description copied from interface: GridDatatype
Get a List of Attribute specific to the Grid

Specified by:
getAttributes in interface GridDatatype

getVariable

public VariableEnhanced getVariable()
Description copied from interface: GridDatatype
get the underlying Variable, if it exists.

Specified by:
getVariable in interface GridDatatype

getName

public java.lang.String getName()
get the name of the geoGrid.

Specified by:
getName in interface GridDatatype
Specified by:
getName in interface NamedObject

getCoordinateSystem

public GridCoordSystem getCoordinateSystem()
get the GridCoordSys for this GeoGrid.

Specified by:
getCoordinateSystem in interface GridDatatype

getProjection

public ProjectionImpl getProjection()
get the Projection.

Specified by:
getProjection in interface GridDatatype

getLevels

public java.util.List getLevels()
ArrayList of thredds.util.NamedObject, from the GridCoordSys.


getTimes

public java.util.List getTimes()
ArrayList of thredds.util.NamedObject, from the GridCoordSys.


getDescription

public java.lang.String getDescription()
get the standardized description, see VariableStandardized.getDescription()

Specified by:
getDescription in interface GridDatatype
Specified by:
getDescription in interface NamedObject

getUnitsString

public java.lang.String getUnitsString()
get the unit as a string, see VariableStandardized.getUnitString()

Specified by:
getUnitsString in interface GridDatatype

getUnitString

public java.lang.String getUnitString()
Deprecated. use getUnitsString()


hasMissingData

public boolean hasMissingData()
true if there may be missing data, see VariableStandardized.hasMissing()

Specified by:
hasMissingData in interface GridDatatype

isMissingData

public boolean isMissingData(double val)
if val is missing data, see VariableStandardized.isMissingData()

Specified by:
isMissingData in interface GridDatatype

setMissingToNaN

public float[] setMissingToNaN(float[] values)
Convert (in place) all values in the given array that are considered as "missing" to Float.NaN, according to isMissingData(val).

Specified by:
setMissingToNaN in interface GridDatatype
Parameters:
values - input array
Returns:
input array, with missing values converted to NaNs.

getMinMaxSkipMissingData

public MAMath.MinMax getMinMaxSkipMissingData(Array a)
Get the minimum and the maximum data value of the previously read Array, skipping missing values as defined by isMissingData(double val).

Specified by:
getMinMaxSkipMissingData in interface GridDatatype
Parameters:
a - Array to get min/max values
Returns:
both min and max value.

readVolumeData

public Array readVolumeData(int t)
                     throws java.io.IOException
Reads in the data "volume" at the given time index. If its a product set, put into canonical order (z-y-x). If not a product set, reorder to (z,i,j), where i, j are from the original

Specified by:
readVolumeData in interface GridDatatype
Parameters:
t - time index; ignored if no time axis.
Returns:
data[z,y,x] or data[y,x] if no z axis.
Throws:
java.io.IOException

readYXData

public Array readYXData(int t,
                        int z)
                 throws java.io.IOException
Reads a Y-X "horizontal slice" at the given time and vertical index. If its a product set, put into canonical order (y-x).

Parameters:
t - time index; ignored if no time axis.
z - vertical index; ignored if no z axis.
Returns:
data[y,x]
Throws:
java.io.IOException

readZYData

public Array readZYData(int t,
                        int x)
                 throws java.io.IOException
Reads a Z-Y "vertical slice" at the given time and x index. If its a product set, put into canonical order (z-y).

Parameters:
t - time index; ignored if no time axis.
x - x index; ignored if no x axis.
Returns:
data[z,y]
Throws:
java.io.IOException

getDataSlice

public Array getDataSlice(int t,
                          int z,
                          int y,
                          int x)
                   throws java.io.IOException
Deprecated. use readDataSlice

Throws:
java.io.IOException

readDataSlice

public Array readDataSlice(int t,
                           int z,
                           int y,
                           int x)
                    throws java.io.IOException
This reads an arbitrary data slice, returning the data in canonical order (t-z-y-x). If any dimension does not exist, ignore it.

Specified by:
readDataSlice in interface GridDatatype
Parameters:
t - if < 0, get all of time dim; if valid index, fix slice to that value.
z - if < 0, get all of z dim; if valid index, fix slice to that value.
y - if < 0, get all of y dim; if valid index, fix slice to that value.
x - if < 0, get all of x dim; if valid index, fix slice to that value.
Returns:
data[t,z,y,x], eliminating missing or fixed dimension.
Throws:
java.io.IOException

readDataSlice

public Array readDataSlice(int rt,
                           int e,
                           int t,
                           int z,
                           int y,
                           int x)
                    throws java.io.IOException
This reads an arbitrary data slice, returning the data in canonical order (rt-e-t-z-y-x). If any dimension does not exist, ignore it.

Specified by:
readDataSlice in interface GridDatatype
Parameters:
rt - if < 0, get all of runtime dim; if valid index, fix slice to that value.
e - if < 0, get all of ensemble dim; if valid index, fix slice to that value.
t - if < 0, get all of time dim; if valid index, fix slice to that value.
z - if < 0, get all of z dim; if valid index, fix slice to that value.
y - if < 0, get all of y dim; if valid index, fix slice to that value.
x - if < 0, get all of x dim; if valid index, fix slice to that value.
Returns:
data[rt,e,t,z,y,x], eliminating missing or fixed dimension.
Throws:
java.io.IOException

subset

public GeoGrid subset(Range t_range,
                      Range z_range,
                      LatLonRect bbox,
                      int z_stride,
                      int y_stride,
                      int x_stride)
               throws InvalidRangeException
Create a new GeoGrid that is a logical subset of this GeoGrid.

Parameters:
t_range - subset the time dimension, or null if you want all of it
z_range - subset the vertical dimension, or null if you want all of it
bbox - a lat/lon bounding box, or null if you want all x,y
z_stride - use only if z_range is null, then take all z with this stride (1 means all)
y_stride - use this stride on the y coordinate (1 means all)
x_stride - use this stride on the x coordinate (1 means all)
Returns:
subsetted GeoGrid
Throws:
InvalidRangeException

makeSubset

public GridDatatype makeSubset(Range t_range,
                               Range z_range,
                               LatLonRect bbox,
                               int z_stride,
                               int y_stride,
                               int x_stride)
                        throws InvalidRangeException
Description copied from interface: GridDatatype
Create a new GeoGrid that is a logical subset of this GeoGrid. For backwards compatibility for grids with no runtime or ensemble dimensions.

Specified by:
makeSubset in interface GridDatatype
Parameters:
t_range - subset the time dimension, or null if you want all of it
z_range - subset the vertical dimension, or null if you want all of it
bbox - a lat/lon bounding box, or null if you want all x,y
z_stride - use only if z_range is null, then take all z with this stride (1 means all)
y_stride - use this stride on the y coordinate (1 means all)
x_stride - use this stride on the x coordinate (1 means all)
Returns:
subsetted GeoGrid
Throws:
InvalidRangeException

subset

public GeoGrid subset(Range t_range,
                      Range z_range,
                      Range y_range,
                      Range x_range)
               throws InvalidRangeException
Create a new GeoGrid that is a logical subset of this GeoGrid.

Parameters:
t_range - subset the time dimension, or null if you want all of it
z_range - subset the vertical dimension, or null if you want all of it
y_range - subset the y dimension, or null if you want all of it
x_range - subset the x dimension, or null if you want all of it
Returns:
subsetted GeoGrid
Throws:
InvalidRangeException

makeSubset

public GridDatatype makeSubset(Range rt_range,
                               Range e_range,
                               Range t_range,
                               Range z_range,
                               Range y_range,
                               Range x_range)
                        throws InvalidRangeException
Description copied from interface: GridDatatype
Create a new GeoGrid that is a logical subset of this GeoGrid.

Specified by:
makeSubset in interface GridDatatype
Parameters:
rt_range - subset the runtime dimension, or null if you want all of it
e_range - subset the ensemble dimension, or null if you want all of it
t_range - subset the time dimension, or null if you want all of it
z_range - subset the vertical dimension, or null if you want all of it
y_range - subset the y dimension, or null if you want all of it
x_range - subset the x dimension, or null if you want all of it
Returns:
subsetted GeoGrid
Throws:
InvalidRangeException

writeFile

public void writeFile(java.lang.String filename)
               throws java.io.IOException
experimental - do not use

Throws:
java.io.IOException

equals

public boolean equals(java.lang.Object oo)
Instances which have same name and coordinate system are equal.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Override Object.hashCode() to be consistent with equals.

Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
string representation

Overrides:
toString in class java.lang.Object

getInfo

public java.lang.String getInfo()
nicely formatted information

Specified by:
getInfo in interface GridDatatype