ucar.nc2.dt.grid
Class GeoGrid

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

public class GeoGrid
extends 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: (rt, e, 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.

Author:
caron

Constructor Summary
GeoGrid(GridDataset dataset, VariableDS dsvar, GridCoordSys gcs)
          Constructor.
 
Method Summary
 int compareTo(GridDatatype g)
           
 boolean equals(Object oo)
          Instances which have same name and coordinate system are equal.
 Attribute findAttributeIgnoreCase(String name)
          Convenience function; lookup Attribute by name.
 String findAttValueIgnoreCase(String attName, String defaultValue)
          Convenience function; lookup Attribute value by name.
 List<Attribute> 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
 String getDescription()
          get the standardized description
 Dimension getDimension(int i)
          get the ith dimension
 List<Dimension> 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)
 String getFullName()
          Get the full, unescaped name of the Grid
 String getInfo()
          nicely formatted information
 List<NamedObject> getLevels()
           
 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).
 String getName()
          Get the object's name
 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
 List<NamedObject> getTimes()
           
 String getUnitsString()
          get the unit as a string
 String getUnitString()
          Deprecated. use getUnitsString()
 VariableDS 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 VariableDS.hasMissing()
 boolean isMissingData(double val)
          if val is missing data, see VariableDS.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.
 String toString()
          string representation
 void writeFile(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,
               VariableDS dsvar,
               GridCoordSys gcs)
Constructor.

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

getDimensions

public List<Dimension> getDimensions()
Returns an ArrayList containing the dimensions used by this geoGrid. The dimension are put into canonical order: (rt, e, 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
Returns:
the time Dimension, or null

getZDimension

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

Specified by:
getZDimension in interface GridDatatype
Returns:
the z Dimension, or null

getYDimension

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

Specified by:
getYDimension in interface GridDatatype
Returns:
the y Dimension, or null

getXDimension

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

Specified by:
getXDimension in interface GridDatatype
Returns:
the x Dimension, or null

getEnsembleDimension

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

Specified by:
getEnsembleDimension in interface GridDatatype
Returns:
the ensemble Dimension, or null

getRunTimeDimension

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

Specified by:
getRunTimeDimension in interface GridDatatype
Returns:
the runtime Dimension, or null

getTimeDimensionIndex

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

Specified by:
getTimeDimensionIndex in interface GridDatatype
Returns:
the time Dimension index in canonical order, or -1

getZDimensionIndex

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

Specified by:
getZDimensionIndex in interface GridDatatype
Returns:
the z Dimension index in canonical order, or -1

getYDimensionIndex

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

Specified by:
getYDimensionIndex in interface GridDatatype
Returns:
the y Dimension index in canonical order, or -1

getXDimensionIndex

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

Specified by:
getXDimensionIndex in interface GridDatatype
Returns:
the x Dimension index in canonical order, or -1

getEnsembleDimensionIndex

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

Specified by:
getEnsembleDimensionIndex in interface GridDatatype
Returns:
the ensemble Dimension index in canonical order, or -1

getRunTimeDimensionIndex

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

Specified by:
getRunTimeDimensionIndex in interface GridDatatype
Returns:
the runtime Dimension index in canonical order, or -1

findAttributeIgnoreCase

public Attribute findAttributeIgnoreCase(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 String findAttValueIgnoreCase(String attName,
                                     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
Returns:
the rank

getShape

public int[] getShape()
get the shape

Specified by:
getShape in interface GridDatatype
Returns:
the shape (canonical ordering)

getDataType

public DataType getDataType()
get the data type

Specified by:
getDataType in interface GridDatatype
Returns:
the data type

getAttributes

public List<Attribute> getAttributes()
Description copied from interface: GridDatatype
Get a List of Attribute specific to the Grid

Specified by:
getAttributes in interface GridDatatype
Returns:
a List of Attribute

getVariable

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

Specified by:
getVariable in interface GridDatatype
Returns:
the underlying Variable, if it exists, else null

getFullName

public String getFullName()
Description copied from interface: GridDatatype
Get the full, unescaped name of the Grid

Specified by:
getFullName in interface GridDatatype
Returns:
the full, unescaped name of the Grid

getName

public String getName()
Description copied from interface: NamedObject
Get the object's name

Specified by:
getName in interface GridDatatype
Specified by:
getName in interface NamedObject
Returns:
object's name

getCoordinateSystem

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

Specified by:
getCoordinateSystem in interface GridDatatype
Returns:
the Grid's Coordinate System.

getProjection

public ProjectionImpl getProjection()
get the Projection.

Specified by:
getProjection in interface GridDatatype
Returns:
the Projection, or null

getLevels

public List<NamedObject> getLevels()
Returns:
ArrayList of thredds.util.NamedObject, from the GridCoordSys.

getTimes

public List<NamedObject> getTimes()
Returns:
ArrayList of thredds.util.NamedObject, from the GridCoordSys.

getDescription

public String getDescription()
get the standardized description

Specified by:
getDescription in interface GridDatatype
Specified by:
getDescription in interface NamedObject
Returns:
object's description

getUnitsString

public String getUnitsString()
get the unit as a string

Specified by:
getUnitsString in interface GridDatatype
Returns:
the unit string

getUnitString

public String getUnitString()
Deprecated. use getUnitsString()

Returns:
getUnitsString()

hasMissingData

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

Specified by:
hasMissingData in interface GridDatatype
Returns:
true if there may be missing data

isMissingData

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

Specified by:
isMissingData in interface GridDatatype
Parameters:
val - test this value
Returns:
true if val is missing data

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 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:
IOException - on io error

readYXData

public Array readYXData(int t,
                        int z)
                 throws 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:
IOException - on read error

readZYData

public Array readZYData(int t,
                        int x)
                 throws 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:
IOException - on read error

getDataSlice

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

Throws:
IOException - on read error

readDataSlice

public Array readDataSlice(int t,
                           int z,
                           int y,
                           int x)
                    throws 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:
IOException - on io error

readDataSlice

public Array readDataSlice(int rt,
                           int e,
                           int t,
                           int z,
                           int y,
                           int x)
                    throws 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:
IOException - on io error

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 - if bbox does not intersect GeoGrid

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 - if ranges are invlaid

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 - if any of the ranges are invalid

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 - if ranges are invlaid

writeFile

public void writeFile(String filename)
               throws IOException
experimental - do not use

Parameters:
filename - write to this file
Throws:
IOException - on i/o error

equals

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

Overrides:
equals in class Object

hashCode

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

Overrides:
hashCode in class Object

toString

public String toString()
string representation

Overrides:
toString in class Object

getInfo

public String getInfo()
nicely formatted information

Specified by:
getInfo in interface GridDatatype
Returns:
human readable information about this Grid.

compareTo

public int compareTo(GridDatatype g)
Specified by:
compareTo in interface Comparable<GridDatatype>


Copyright © 1999-2011 UCAR/Unidata. All Rights Reserved.