ucar.nc2.dataset
Class CoordSysBuilder

java.lang.Object
  extended by ucar.nc2.dataset.CoordSysBuilder
All Implemented Interfaces:
CoordSysBuilderIF
Direct Known Subclasses:
ADASConvention, ATDRadarConvention, AWIPSConvention, AWIPSsatConvention, BUFRConvention, COARDSConvention, EpicInsitu, FslWindProfiler, GIEFConvention, IFPSConvention, M3IOConvention, M3IOVGGridConvention, MADISStation, NsslRadarMosaicConvention, NUWGConvention, UnidataObsConvention, WRFConvention

public class CoordSysBuilder
extends java.lang.Object
implements CoordSysBuilderIF

Abstract class for implementing Convention-specific parsing of netCDF files.

You can use an NcML file alone (use registerNcML()) if file uses a convention attribute. If not, you must implement a class that implements isMine() to identify your files, and call wrapNcML in the augmentDataset method (see eg ATDRadarConvention class).

Subclasses Info:

      // identify which variables are coordinate axes
      // default: 1) coordinate variables 2) variables with _coordinateAxisType attribute 3) variables listed
      // in a coordinates attribute on another variable.
      findCoordinateAxes( ncDataset);

      // identify which variables are used to describe coordinate system
      findCoordinateSystems( ncDataset);
      // identify which variables are used to describe coordinate transforms
      findCoordinateTransforms( ncDataset);
      // turn Variables into CoordinateAxis objects
      makeCoordinateAxes( ncDataset);
      // make Coordinate Systems for all Coordinate Systems Variables
      makeCoordinateSystems( ncDataset);

      // Assign explicit CoordinateSystem objects to variables
      assignExplicitCoordinateSystems( ncDataset);
      makeCoordinateSystemsImplicit( ncDataset);
      if (useMaximalCoordSys)
      makeCoordinateSystemsMaximal( ncDataset);

      makeCoordinateTransforms( ncDataset);
      assignCoordinateTransforms( ncDataset);
 

Author:
caron

Nested Class Summary
 class CoordSysBuilder.VarProcess
          Wrap each variable in the dataset with a VarProcess object.
 
Field Summary
protected  java.lang.String conventionName
           
protected  java.util.Map<Dimension,java.util.List<CoordSysBuilder.VarProcess>> coordVarMap
           
protected  boolean debug
           
protected static org.slf4j.Logger log
           
protected  java.lang.StringBuilder parseInfo
           
static java.lang.String resourcesDir
           
protected  boolean showRejects
           
protected  java.lang.StringBuilder userAdvice
           
protected  java.util.List<CoordSysBuilder.VarProcess> varList
           
 
Constructor Summary
CoordSysBuilder()
           
 
Method Summary
static CoordSysBuilderIF addCoordinateSystems(NetcdfDataset ds, CancelTask cancelTask)
          Add Coordinate information to a NetcdfDataset using a registered Convention parsing class.
protected  void addCoordinateVariable(Dimension dim, CoordSysBuilder.VarProcess vp)
           
 void addUserAdvice(java.lang.String advice)
          Give advice for a user trying to figure out why things arent working
protected  void assignCoordinateTransforms(NetcdfDataset ncDataset)
          Assign CoordinateTransform objects to Coordinate Systems.
protected  void assignExplicitCoordinateSystems(NetcdfDataset ncDataset)
          Assign explicit CoordinateSystem objects to variables.
 void augmentDataset(NetcdfDataset ncDataset, CancelTask cancelTask)
          This is where subclasses make changes to the dataset, like adding new variables, attribuites, etc.
 void buildCoordinateSystems(NetcdfDataset ncDataset)
          Heres where the work is to identify coordinate axes and coordinate systems.
protected  void findCoordinateAxes(NetcdfDataset ncDataset)
          Identify coordinate axes, set VarProcess.isCoordinateAxis = true.
protected  CoordSysBuilder.VarProcess findCoordinateAxis(java.lang.String name)
           
protected  void findCoordinateSystems(NetcdfDataset ncDataset)
          Identify coordinate systems, set VarProcess.isCoordinateSystem = true.
protected  void findCoordinateTransforms(NetcdfDataset ncDataset)
          Identify coordinate transforms, set VarProcess.isCoordinateTransform = true.
protected  CoordSysBuilder.VarProcess findVarProcess(java.lang.String name)
           
protected  AxisType getAxisType(NetcdfDataset ncDataset, VariableEnhanced v)
          Identify what kind of AxisType the named variable is.
 java.lang.String getConventionUsed()
          Get the name of the Convention.
 java.lang.String getParseInfo()
          Detailed information when the coordinate systems were parsed
static boolean getUseMaximalCoordSys()
          Get whether to make records into Structures.
 java.lang.String getUserAdvice()
          Specific advice to a user about problems with the coordinate information in the file.
protected  boolean hasXY(java.util.List<CoordinateAxis> coordAxes)
           
protected  boolean isCoordinateAxisForVariable(Variable axis, VariableEnhanced v)
          Does this axis "fit" this variable.
protected  void makeCoordinateAxes(NetcdfDataset ncDataset)
          Take previously identified Coordinate Axis and Coordinate Variables and make them into a CoordinateAxis.
protected  void makeCoordinateSystems(NetcdfDataset ncDataset)
          Take all previously identified Coordinate Systems and create a CoordinateSystem object.
protected  void makeCoordinateSystemsImplicit(NetcdfDataset ncDataset)
          Make implicit CoordinateSystem objects for variables that dont already have one, by using the variables' list of coordinate axes, and any coordinateVariables for it.
protected  void makeCoordinateSystemsMaximal(NetcdfDataset ncDataset)
          If a variable still doesnt have a coordinate system, use hueristics to try to find one that was probably forgotten.
protected  CoordinateTransform makeCoordinateTransform(NetcdfDataset ds, Variable ctv)
           
protected  void makeCoordinateTransforms(NetcdfDataset ncDataset)
          Take all previously identified Coordinate Transforms and create a CoordinateTransform object by calling CoordTransBuilder.makeCoordinateTransform().
protected  VariableDS makeCoordinateTransformVariable(NetcdfDataset ds, CoordinateTransform ct)
           
static VariableDS makeDummyTransformVariable(NetcdfDataset ds, CoordinateTransform ct)
          Deprecated. use CoordTransBuilder.makeDummyTransformVariable
static void registerConvention(java.lang.String conventionName, java.lang.Class c)
          Register a class that implements a Convention.
static void registerConvention(java.lang.String conventionName, java.lang.String className)
          Register a class that implements a Convention.
static void registerNcML(java.lang.String conventionName, java.lang.String ncmlLocation)
          Register an NcML file that implements a Convention by wrappping the dataset in the NcML.
 void setConventionUsed(java.lang.String convName)
          Pass in the name of the Convention used to locate this CoordSysBuilderIF.
static void setUseMaximalCoordSys(boolean b)
          If true, assign implicit CoordinateSystem objects to variables that dont have one yet.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

resourcesDir

public static final java.lang.String resourcesDir
See Also:
Constant Field Values

log

protected static org.slf4j.Logger log

conventionName

protected java.lang.String conventionName

varList

protected java.util.List<CoordSysBuilder.VarProcess> varList

coordVarMap

protected java.util.Map<Dimension,java.util.List<CoordSysBuilder.VarProcess>> coordVarMap

parseInfo

protected java.lang.StringBuilder parseInfo

userAdvice

protected java.lang.StringBuilder userAdvice

debug

protected boolean debug

showRejects

protected boolean showRejects
Constructor Detail

CoordSysBuilder

public CoordSysBuilder()
Method Detail

registerNcML

public static void registerNcML(java.lang.String conventionName,
                                java.lang.String ncmlLocation)
Register an NcML file that implements a Convention by wrappping the dataset in the NcML. It is then processed by CoordSysBuilder, using the _Coordinate attributes.

Parameters:
conventionName - name of Convention, must be in the "Conventions" global attribute.
ncmlLocation - location of NcML file, may be local file or URL.
See Also:
NcMLReader.wrapNcML(ucar.nc2.dataset.NetcdfDataset, java.lang.String, ucar.nc2.util.CancelTask)

registerConvention

public static void registerConvention(java.lang.String conventionName,
                                      java.lang.Class c)
Register a class that implements a Convention.

Parameters:
conventionName - name of Convention. This name will be used to look in the "Conventions" global attribute. Otherwise, you must implement the isMine() static method.
c - implementation of CoordSysBuilderIF that parses those kinds of netcdf files.

registerConvention

public static void registerConvention(java.lang.String conventionName,
                                      java.lang.String className)
                               throws java.lang.ClassNotFoundException
Register a class that implements a Convention.

Parameters:
conventionName - name of Convention. This name will be used to look in the "Conventions" global attribute. Otherwise, you must implement the isMine() static method.
className - name of class that implements CoordSysBuilderIF.
Throws:
java.lang.ClassNotFoundException - if class could not be loaded

setUseMaximalCoordSys

public static void setUseMaximalCoordSys(boolean b)
If true, assign implicit CoordinateSystem objects to variables that dont have one yet. Default value is false.

Parameters:
b - true if if you want to guess at Coordinate Systems
See Also:
makeCoordinateSystemsMaximal(ucar.nc2.dataset.NetcdfDataset)

getUseMaximalCoordSys

public static boolean getUseMaximalCoordSys()
Get whether to make records into Structures.

Returns:
whether to make records into Structures.

addCoordinateSystems

public static CoordSysBuilderIF addCoordinateSystems(NetcdfDataset ds,
                                                     CancelTask cancelTask)
                                              throws java.io.IOException
Add Coordinate information to a NetcdfDataset using a registered Convention parsing class.

Parameters:
ds - the NetcdfDataset to modify
cancelTask - allow user to bail out.
Returns:
the builder used
Throws:
java.io.IOException - on io error

setConventionUsed

public void setConventionUsed(java.lang.String convName)
Description copied from interface: CoordSysBuilderIF
Pass in the name of the Convention used to locate this CoordSysBuilderIF.

Specified by:
setConventionUsed in interface CoordSysBuilderIF
Parameters:
convName - the name of the Convention

getConventionUsed

public java.lang.String getConventionUsed()
Description copied from interface: CoordSysBuilderIF
Get the name of the Convention. In the case where the Convention attribute is not set in the file, this name cannot be used to identify the Convention. The isMine() method is called instead.

Specified by:
getConventionUsed in interface CoordSysBuilderIF
Returns:
Convention name

addUserAdvice

public void addUserAdvice(java.lang.String advice)
Description copied from interface: CoordSysBuilderIF
Give advice for a user trying to figure out why things arent working

Specified by:
addUserAdvice in interface CoordSysBuilderIF
Parameters:
advice - add this advice to the User Advice String

getParseInfo

public java.lang.String getParseInfo()
Description copied from interface: CoordSysBuilderIF
Detailed information when the coordinate systems were parsed

Specified by:
getParseInfo in interface CoordSysBuilderIF
Returns:
String containing parsing info

getUserAdvice

public java.lang.String getUserAdvice()
Description copied from interface: CoordSysBuilderIF
Specific advice to a user about problems with the coordinate information in the file.

Specified by:
getUserAdvice in interface CoordSysBuilderIF
Returns:
String containing advice to a user about problems with the coordinate information in the file.

augmentDataset

public void augmentDataset(NetcdfDataset ncDataset,
                           CancelTask cancelTask)
                    throws java.io.IOException
This is where subclasses make changes to the dataset, like adding new variables, attribuites, etc.

Specified by:
augmentDataset in interface CoordSysBuilderIF
Parameters:
ncDataset - modify this dataset
cancelTask - give user a chance to bail out
Throws:
java.io.IOException

getAxisType

protected AxisType getAxisType(NetcdfDataset ncDataset,
                               VariableEnhanced v)
Identify what kind of AxisType the named variable is. Only called for variables already identified as Coordinate Axes. Default null - subclasses can override.

Parameters:
ncDataset - for this dataset
v - a variable alreaddy identified as a Coodinate Axis
Returns:
AxisType or null if unknown.

buildCoordinateSystems

public void buildCoordinateSystems(NetcdfDataset ncDataset)
Heres where the work is to identify coordinate axes and coordinate systems.

Specified by:
buildCoordinateSystems in interface CoordSysBuilderIF
Parameters:
ncDataset - modify this dataset

findCoordinateAxes

protected void findCoordinateAxes(NetcdfDataset ncDataset)
Identify coordinate axes, set VarProcess.isCoordinateAxis = true. Default is to look for those referenced by _CoordinateAxes attribute. Note coordinate variables are already identified.

Parameters:
ncDataset - why

findCoordinateSystems

protected void findCoordinateSystems(NetcdfDataset ncDataset)
Identify coordinate systems, set VarProcess.isCoordinateSystem = true. Default is to look for those referenced by _CoordinateSystems attribute.

Parameters:
ncDataset - why

findCoordinateTransforms

protected void findCoordinateTransforms(NetcdfDataset ncDataset)
Identify coordinate transforms, set VarProcess.isCoordinateTransform = true. Default is to look for those referenced by _CoordinateTransforms attribute ( or has a _CoordinateTransformType attribute, done in VarProcess constructor)

Parameters:
ncDataset - why

makeCoordinateAxes

protected void makeCoordinateAxes(NetcdfDataset ncDataset)
Take previously identified Coordinate Axis and Coordinate Variables and make them into a CoordinateAxis. Uses the getAxisType() method to figure out the type, if not already set.

Parameters:
ncDataset - containing dataset

makeCoordinateSystems

protected void makeCoordinateSystems(NetcdfDataset ncDataset)
Take all previously identified Coordinate Systems and create a CoordinateSystem object.

Parameters:
ncDataset - why

assignExplicitCoordinateSystems

protected void assignExplicitCoordinateSystems(NetcdfDataset ncDataset)
Assign explicit CoordinateSystem objects to variables.

Parameters:
ncDataset - why

makeCoordinateSystemsImplicit

protected void makeCoordinateSystemsImplicit(NetcdfDataset ncDataset)
Make implicit CoordinateSystem objects for variables that dont already have one, by using the variables' list of coordinate axes, and any coordinateVariables for it. Must be at least 2 axes.

Parameters:
ncDataset - why

makeCoordinateSystemsMaximal

protected void makeCoordinateSystemsMaximal(NetcdfDataset ncDataset)
If a variable still doesnt have a coordinate system, use hueristics to try to find one that was probably forgotten. Look through all existing CS. create a subset of axes that fits the variable. Choose the one with highest rank. It must have X,Y or lat,lon. If so, add it.

Parameters:
ncDataset - why

isCoordinateAxisForVariable

protected boolean isCoordinateAxisForVariable(Variable axis,
                                              VariableEnhanced v)
Does this axis "fit" this variable. True if all of the dimensions in the axis also appear in the variable. If char variable, last dimension is left out.

Parameters:
axis - check if this axis is ok for the given variable
v - the given variable
Returns:
true if all of the dimensions in the axis also appear in the variable.

hasXY

protected boolean hasXY(java.util.List<CoordinateAxis> coordAxes)

makeCoordinateTransforms

protected void makeCoordinateTransforms(NetcdfDataset ncDataset)
Take all previously identified Coordinate Transforms and create a CoordinateTransform object by calling CoordTransBuilder.makeCoordinateTransform().

Parameters:
ncDataset - why

makeCoordinateTransform

protected CoordinateTransform makeCoordinateTransform(NetcdfDataset ds,
                                                      Variable ctv)

assignCoordinateTransforms

protected void assignCoordinateTransforms(NetcdfDataset ncDataset)
Assign CoordinateTransform objects to Coordinate Systems.

Parameters:
ncDataset - why

findVarProcess

protected CoordSysBuilder.VarProcess findVarProcess(java.lang.String name)

findCoordinateAxis

protected CoordSysBuilder.VarProcess findCoordinateAxis(java.lang.String name)

addCoordinateVariable

protected void addCoordinateVariable(Dimension dim,
                                     CoordSysBuilder.VarProcess vp)

makeCoordinateTransformVariable

protected VariableDS makeCoordinateTransformVariable(NetcdfDataset ds,
                                                     CoordinateTransform ct)

makeDummyTransformVariable

public static VariableDS makeDummyTransformVariable(NetcdfDataset ds,
                                                    CoordinateTransform ct)
Deprecated. use CoordTransBuilder.makeDummyTransformVariable