ucar.nc2.dt.grid
Class GridCoordSys

java.lang.Object
  extended by ucar.nc2.dataset.CoordinateSystem
      extended by ucar.nc2.dt.grid.GridCoordSys
All Implemented Interfaces:
GridCoordSystem

public class GridCoordSys
extends CoordinateSystem
implements GridCoordSystem

A georeferencing "gridded" CoordinateSystem. This describes a "grid" of coordinates, which implies a connected topology such that values next to each other in index space are next to each other in coordinate space.

This currently assumes that the CoordinateSystem

  1. is georeferencing (has Lat, Lon or GeoX, GeoY axes)
  2. x, y are 1 or 2-dimensional axes.
  3. rt, z, e are 1-dimensional axes.
  4. t is 1 or 2 dimensional. if 2d, then rt exists

This is the common case for georeferencing coordinate systems. Mathematically it is a product set: {X,Y} x {Z} x {T}. The x and y axes may be 1 or 2 dimensional.

A CoordinateSystem may have multiple horizontal and vertical axes. GridCoordSys chooses one axis corresponding to X, Y, Z, and T. It gives preference to one dimensional axes (CoordinateAxis1D).

Author:
caron

Field Summary
 
Fields inherited from class ucar.nc2.dataset.CoordinateSystem
aziAxis, coordAxes, coordTrans, dataType, domain, ds, elevAxis, ensAxis, hAxis, isImplicit, latAxis, lonAxis, name, pAxis, radialAxis, tAxis, xAxis, yAxis, zAxis
 
Constructor Summary
GridCoordSys(CoordinateSystem cs, Formatter sbuff)
          Create a GridCoordSys from an existing Coordinate System.
GridCoordSys(GridCoordSys from, Range t_range, Range z_range, Range y_range, Range x_range)
          Create a GridCoordSys as a section of an existing GridCoordSys.
GridCoordSys(GridCoordSys from, Range rt_range, Range e_range, Range t_range, Range z_range, Range y_range, Range x_range)
          Create a GridCoordSys as a section of an existing GridCoordSys.
 
Method Summary
 int findTimeIndexFromDate(Date d)
          Deprecated. use CoordinateAxis1DTime.findTimeIndexFromDate
 int[] findXYCoordElement(double x_coord, double y_coord, int[] result)
          Deprecated. use findXYindexFromCoord
 int[] findXYindexFromCoord(double x_coord, double y_coord, int[] result)
          Given a point in x,y coordinate space, find the x,y index in the coordinate system.
 int[] findXYindexFromCoordBounded(double x_coord, double y_coord, int[] result)
          Given a point in x,y coordinate space, find the x,y index in the coordinate system.
 int[] findXYindexFromLatLon(double lat, double lon, int[] result)
          Given a lat,lon point, find the x,y index in the coordinate system.
 int[] findXYindexFromLatLonBounded(double lat, double lon, int[] result)
          Given a lat,lon point, find the x,y index in the coordinate system.
 ProjectionRect getBoundingBox()
          Get the x,y bounding box in projection coordinates.
 DateRange getDateRange()
          If there is a time coordinate, get the time covered.
 DateUnit getDateUnit()
           
 CoordinateAxis1D getEnsembleAxis()
          get the Ensemble axis, else null
 LatLonPoint getLatLon(double xcoord, double ycoord)
           
 LatLonPoint getLatLon(int xindex, int yindex)
          Get the Lat/Lon coordinates of the midpoint of a grid cell, using the x,y indices
 LatLonRect getLatLonBoundingBox()
          Get horizontal bounding box in lat, lon coordinates.
 List<Range> getLatLonBoundingBox(LatLonRect rect)
          Deprecated. use getRangesFromLatLonRect.
 int getLevelIndex(String name)
          Get the index corresponding to the level name.
 String getLevelName(int index)
          Get the String name for the ith level(z) coordinate.
 List<NamedObject> getLevels()
          Get the list of level names, to be used for user selection.
 ProjectionImpl getProjection()
          get the projection
 List<Range> getRangesFromLatLonRect(LatLonRect rect)
          Get Index Ranges for the given lat, lon bounding box.
 CoordinateAxis1DTime getRunTimeAxis()
          get the RunTime axis, else null
 CoordinateAxis getTimeAxis()
          get the Time axis
 CoordinateAxis1DTime getTimeAxis1D()
          get the Time axis, if its 1-dimensional
 CoordinateAxis1DTime getTimeAxisForRun(int run_index)
          This is the case of a 2D time axis, which depends on the run index.
 Date[] getTimeDates()
          Get the list of times as Dates.
 int getTimeIndex(String name)
          Deprecated.  
 String getTimeName(int index)
          Deprecated.  
 TimeUnit getTimeResolution()
          Get the resolution of the time coordinate.
 List<NamedObject> getTimes()
          Get the list of time names, to be used for user selection.
 CoordinateAxis1D getVerticalAxis()
          get the Vertical axis (either Geoz, Height, or Pressure)
 VerticalCT getVerticalCT()
          Get the Coordinate Transform description.
 VerticalTransform getVerticalTransform()
          Get the vertical transform function, or null if none
 CoordinateAxis getXHorizAxis()
          get the X Horizontal axis (either GeoX or Lon)
 CoordinateAxis getYHorizAxis()
          get the Y Horizontal axis (either GeoY or Lat)
 boolean hasTimeAxis()
          True if there is a Time Axis.
 boolean hasTimeAxis1D()
          True if there is a Time Axis and it is 1D.
 boolean isDate()
           
static boolean isGridCoordSys(Formatter sbuff, CoordinateSystem cs, VariableEnhanced v)
          Determine if this CoordinateSystem can be made into a GridCoordSys.
 boolean isLatLon()
          is this a Lat/Lon coordinate system?
 boolean isRegularSpatial()
          true if x and y axes are CoordinateAxis1D and are regular
 boolean isZPositive()
          true if increasing z coordinate values means "up" in altitude
static void main(String[] args)
           
static GridCoordSys makeGridCoordSys(Formatter sbuff, CoordinateSystem cs, VariableEnhanced v)
          Determine if the CoordinateSystem cs can be made into a GridCoordSys for the Variable v.
 void setProjectionBoundingBox()
          Use the bounding box to set the defaule map are of the projection.
 String toString()
          String representation.
 
Methods inherited from class ucar.nc2.dataset.CoordinateSystem
addCoordinateTransform, addCoordinateTransforms, containsAxes, containsAxis, containsAxisType, containsAxisTypes, containsDomain, equals, findAxis, getAzimuthAxis, getCoordinateAxes, getCoordinateTransforms, getDomain, getElevationAxis, getHeightAxis, getLatAxis, getLonAxis, getName, getNetcdfDataset, getPressureAxis, getProjectionCT, getRadialAxis, getRankDomain, getRankRange, getTaxis, getXaxis, getYaxis, getZaxis, hashCode, hasVerticalAxis, isComplete, isCoordinateSystemFor, isGeoReferencing, isGeoXY, isImplicit, isProductSet, isRadial, isRegular, isSubset, makeDomain, makeName, setImplicit
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ucar.nc2.dt.GridCoordSystem
getCoordinateAxes, getCoordinateTransforms, getDomain, getName, getProjectionCT, isProductSet
 

Constructor Detail

GridCoordSys

public GridCoordSys(CoordinateSystem cs,
                    Formatter sbuff)
Create a GridCoordSys from an existing Coordinate System. This will choose which axes are the XHoriz, YHoriz, Vertical, Time, RunTIme, Ensemble. If theres a Projection, it will set its map area

Parameters:
cs - create from this Coordinate System
sbuff - place information messages here, may be null

GridCoordSys

public GridCoordSys(GridCoordSys from,
                    Range t_range,
                    Range z_range,
                    Range y_range,
                    Range x_range)
             throws InvalidRangeException
Create a GridCoordSys as a section of an existing GridCoordSys. This will create sections of the corresponding CoordinateAxes.

Parameters:
from - copy this GridCoordSys
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
Throws:
InvalidRangeException - if any of the ranges are illegal

GridCoordSys

public GridCoordSys(GridCoordSys from,
                    Range rt_range,
                    Range e_range,
                    Range t_range,
                    Range z_range,
                    Range y_range,
                    Range x_range)
             throws InvalidRangeException
Create a GridCoordSys as a section of an existing GridCoordSys. This will create sections of the corresponding CoordinateAxes.

Parameters:
from - copy this GridCoordSys
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
Throws:
InvalidRangeException - if any of the ranges are illegal
Method Detail

isGridCoordSys

public static boolean isGridCoordSys(Formatter sbuff,
                                     CoordinateSystem cs,
                                     VariableEnhanced v)
Determine if this CoordinateSystem can be made into a GridCoordSys. Optionally for a given variable. This currently assumes that the CoordinateSystem:
  1. is georeferencing (cs.isGeoReferencing())
  2. x, y are 1 or 2-dimensional axes.
  3. z, t, if they exist, are 1-dimensional axes.
  4. domain rank > 1

Parameters:
sbuff - place information messages here, may be null
cs - the CoordinateSystem to test
v - can it be used for this variable; v may be null
Returns:
true if it can be made into a GridCoordSys.
See Also:
CoordinateSystem.isGeoReferencing()

makeGridCoordSys

public static GridCoordSys makeGridCoordSys(Formatter sbuff,
                                            CoordinateSystem cs,
                                            VariableEnhanced v)
Determine if the CoordinateSystem cs can be made into a GridCoordSys for the Variable v.

Parameters:
sbuff - put debug information into this StringBuffer; may be null.
cs - CoordinateSystem to check.
v - Variable to check.
Returns:
the GridCoordSys made from cs, else null.

getVerticalTransform

public VerticalTransform getVerticalTransform()
Get the vertical transform function, or null if none

Specified by:
getVerticalTransform in interface GridCoordSystem
Returns:
the vertical transform function, or null if none

getVerticalCT

public VerticalCT getVerticalCT()
Get the Coordinate Transform description.

Specified by:
getVerticalCT in interface GridCoordSystem
Returns:
Coordinate Transform description, or null if none

getXHorizAxis

public CoordinateAxis getXHorizAxis()
get the X Horizontal axis (either GeoX or Lon)

Specified by:
getXHorizAxis in interface GridCoordSystem
Returns:
X CoordinateAxis, may not be null.

getYHorizAxis

public CoordinateAxis getYHorizAxis()
get the Y Horizontal axis (either GeoY or Lat)

Specified by:
getYHorizAxis in interface GridCoordSystem
Returns:
Y CoordinateAxis, may not be null.

getVerticalAxis

public CoordinateAxis1D getVerticalAxis()
get the Vertical axis (either Geoz, Height, or Pressure)

Specified by:
getVerticalAxis in interface GridCoordSystem
Returns:
Y CoordinateAxis, may be null.

getTimeAxis

public CoordinateAxis getTimeAxis()
get the Time axis

Specified by:
getTimeAxis in interface GridCoordSystem
Returns:
the time coordinate axis, may be null.

getTimeAxis1D

public CoordinateAxis1DTime getTimeAxis1D()
get the Time axis, if its 1-dimensional

Specified by:
getTimeAxis1D in interface GridCoordSystem
Returns:
the time coordinate axis, may be null.

getRunTimeAxis

public CoordinateAxis1DTime getRunTimeAxis()
get the RunTime axis, else null

Specified by:
getRunTimeAxis in interface GridCoordSystem
Returns:
RunTime CoordinateAxis, may be null.

getEnsembleAxis

public CoordinateAxis1D getEnsembleAxis()
get the Ensemble axis, else null

Specified by:
getEnsembleAxis in interface GridCoordSystem
Overrides:
getEnsembleAxis in class CoordinateSystem
Returns:
axis of type AxisType.Ensemble, or null if none

getProjection

public ProjectionImpl getProjection()
get the projection

Specified by:
getProjection in interface GridCoordSystem
Overrides:
getProjection in class CoordinateSystem
Returns:
ProjectionImpl or null if none.

setProjectionBoundingBox

public void setProjectionBoundingBox()
Description copied from interface: GridCoordSystem
Use the bounding box to set the defaule map are of the projection. This can be expensive if its a 2D coordinate system.

Specified by:
setProjectionBoundingBox in interface GridCoordSystem

getTimeDates

public Date[] getTimeDates()
Get the list of times as Dates. Only valid if isDate() is true. If 2D, return list of unique dates.

Returns:
array of java.util.Date, or null.

isLatLon

public boolean isLatLon()
is this a Lat/Lon coordinate system?

Specified by:
isLatLon in interface GridCoordSystem
Overrides:
isLatLon in class CoordinateSystem
Returns:
true if it has Lat and Lon CoordinateAxis

isDate

public boolean isDate()

isZPositive

public boolean isZPositive()
true if increasing z coordinate values means "up" in altitude

Specified by:
isZPositive in interface GridCoordSystem
Returns:
true if increasing z coordinate values means "up" in altitude

isRegularSpatial

public boolean isRegularSpatial()
true if x and y axes are CoordinateAxis1D and are regular

Specified by:
isRegularSpatial in interface GridCoordSystem
Returns:
true if both X and Y axes are 1 dimensional and are regularly spaced.

findXYindexFromCoord

public int[] findXYindexFromCoord(double x_coord,
                                  double y_coord,
                                  int[] result)
Given a point in x,y coordinate space, find the x,y index in the coordinate system. Not implemented yet for 2D.

Specified by:
findXYindexFromCoord in interface GridCoordSystem
Parameters:
x_coord - position in x coordinate space.
y_coord - position in y coordinate space.
result - put result (x,y) index in here, may be null
Returns:
int[2], 0=x,1=y indices in the coordinate system of the point. These will be -1 if out of range.

findXYindexFromCoordBounded

public int[] findXYindexFromCoordBounded(double x_coord,
                                         double y_coord,
                                         int[] result)
Given a point in x,y coordinate space, find the x,y index in the coordinate system. If outside the range, the closest point is returned Not implemented yet for 2D.

Specified by:
findXYindexFromCoordBounded in interface GridCoordSystem
Parameters:
x_coord - position in x coordinate space.
y_coord - position in y coordinate space.
result - put result in here, may be null
Returns:
int[2], 0=x,1=y indices in the coordinate system of the point.

findXYindexFromLatLon

public int[] findXYindexFromLatLon(double lat,
                                   double lon,
                                   int[] result)
Given a lat,lon point, find the x,y index in the coordinate system.

Specified by:
findXYindexFromLatLon in interface GridCoordSystem
Parameters:
lat - latitude position.
lon - longitude position.
result - put result in here, may be null
Returns:
int[2], 0=x,1=y indices in the coordinate system of the point. These will be -1 if out of range.

findXYindexFromLatLonBounded

public int[] findXYindexFromLatLonBounded(double lat,
                                          double lon,
                                          int[] result)
Given a lat,lon point, find the x,y index in the coordinate system. If outside the range, the closest point is returned

Specified by:
findXYindexFromLatLonBounded in interface GridCoordSystem
Parameters:
lat - latitude position.
lon - longitude position.
result - put result in here, may be null
Returns:
int[2], 0=x,1=y indices in the coordinate system of the point.

findXYCoordElement

public int[] findXYCoordElement(double x_coord,
                                double y_coord,
                                int[] result)
Deprecated. use findXYindexFromCoord

Given a point in x,y coordinate space, find the x,y index in the coordinate system.


getDateRange

public DateRange getDateRange()
Description copied from interface: GridCoordSystem
If there is a time coordinate, get the time covered.

Specified by:
getDateRange in interface GridCoordSystem
Returns:
DateRange or null if no time coordinate

hasTimeAxis

public boolean hasTimeAxis()
True if there is a Time Axis.

Specified by:
hasTimeAxis in interface GridCoordSystem
Overrides:
hasTimeAxis in class CoordinateSystem
Returns:
true if has Time axis

hasTimeAxis1D

public boolean hasTimeAxis1D()
True if there is a Time Axis and it is 1D.

Specified by:
hasTimeAxis1D in interface GridCoordSystem
Returns:
true if there is a Time Axis and it is 1D.

getTimeAxisForRun

public CoordinateAxis1DTime getTimeAxisForRun(int run_index)
Description copied from interface: GridCoordSystem
This is the case of a 2D time axis, which depends on the run index. A time coordinate must be a udunit date or ISO String, so it can always be converted to a Date.

Specified by:
getTimeAxisForRun in interface GridCoordSystem
Parameters:
run_index - which run?
Returns:
1D time axis for that run. Null if not 2D time

getDateUnit

public DateUnit getDateUnit()
                     throws Exception
Throws:
Exception

getTimeResolution

public TimeUnit getTimeResolution()
                           throws Exception
Get the resolution of the time coordinate. must be regular

Returns:
null if !isRegular()
Throws:
Exception - if parsing the time unit fails

getBoundingBox

public ProjectionRect getBoundingBox()
Get the x,y bounding box in projection coordinates.

Specified by:
getBoundingBox in interface GridCoordSystem
Returns:
ProjectionRect bounding box.

getLatLon

public LatLonPoint getLatLon(int xindex,
                             int yindex)
Get the Lat/Lon coordinates of the midpoint of a grid cell, using the x,y indices

Specified by:
getLatLon in interface GridCoordSystem
Parameters:
xindex - x index
yindex - y index
Returns:
lat/lon coordinate of the midpoint of the cell

getLatLon

public LatLonPoint getLatLon(double xcoord,
                             double ycoord)

getLatLonBoundingBox

public LatLonRect getLatLonBoundingBox()
Get horizontal bounding box in lat, lon coordinates.

Specified by:
getLatLonBoundingBox in interface GridCoordSystem
Returns:
lat, lon bounding box.

getLatLonBoundingBox

public List<Range> getLatLonBoundingBox(LatLonRect rect)
                                 throws InvalidRangeException
Deprecated. use getRangesFromLatLonRect.

Get Index Ranges for the given lat, lon bounding box.

Throws:
InvalidRangeException

getRangesFromLatLonRect

public List<Range> getRangesFromLatLonRect(LatLonRect rect)
                                    throws InvalidRangeException
Get Index Ranges for the given lat, lon bounding box. For projection, only an approximation based on latlon corners. Must have CoordinateAxis1D or 2D for x and y axis.

Specified by:
getRangesFromLatLonRect in interface GridCoordSystem
Parameters:
rect - the requested lat/lon bounding box
Returns:
list of 2 Range objects, first y then x.
Throws:
InvalidRangeException - if llbb generates bad ranges

toString

public String toString()
String representation.

Overrides:
toString in class CoordinateSystem

getLevels

public List<NamedObject> getLevels()
Get the list of level names, to be used for user selection. The ith one refers to the ith level coordinate.

Returns:
List of ucar.nc2.util.NamedObject, or empty list.

getLevelName

public String getLevelName(int index)
Get the String name for the ith level(z) coordinate.

Parameters:
index - which level coordinate
Returns:
level name

getLevelIndex

public int getLevelIndex(String name)
Get the index corresponding to the level name.

Parameters:
name - level name
Returns:
level index, or -1 if not found

getTimes

public List<NamedObject> getTimes()
Get the list of time names, to be used for user selection. The ith one refers to the ith time coordinate.

Returns:
List of ucar.nc2.util.NamedObject, or empty list.

getTimeName

public String getTimeName(int index)
Deprecated. 

Get the string name for the ith time coordinate.

Parameters:
index - which time coordinate
Returns:
time name.

getTimeIndex

public int getTimeIndex(String name)
Deprecated. 

Get the index corresponding to the time name.

Parameters:
name - time name
Returns:
time index, or -1 if not found

findTimeIndexFromDate

public int findTimeIndexFromDate(Date d)
Deprecated. use CoordinateAxis1DTime.findTimeIndexFromDate

Only works if coordsys has 1d time axis


main

public static void main(String[] args)
                 throws IOException
Throws:
IOException


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