org.gcube.dataanalysis.environment.thredds
Class NoDatasetFiles

java.lang.Object
  extended by org.gcube.dataanalysis.environment.thredds.NoDatasetFiles

public class NoDatasetFiles
extends Object

Class for obtaining altimetry and bathymetry values from a netCDF file. Requires the netCDF libraries (see here: http://www.unidata.ucar.edu/software/netcdf-java/documentation.htm) You should use the class in the following way:

   VTIBathymetry bath = new VTIBathymetry("/path/to/bath.nc");   // e.g. gebco_08.nc
   bath.open();                                                  // file must be explicitly opened, this takes a short time, avoid opening it several times
   short value1 = bath.getZ(142.2, 11.35);                       // e.g. Mariana Trench
   short value2 = bath.getZ(0, 0);
   // ...
   bath.close();                                                 // file should be closed when not needed any longer
 

Author:
Frank Loeschau, Terradue Srl.

Field Summary
static int GRID_COLS
           
static int GRID_ROWS
           
 
Constructor Summary
NoDatasetFiles(String filename)
          Creates an instance of VTIBathymetry with the specified file.
 
Method Summary
 void close()
          Closes the netCDF file.
static double getVarPoint(ucar.nc2.Variable var, double x, double y)
           
 short getZ(double x, double y)
          Returns the altimetric/bathymetric value of the given geographical coordinates.
 short getZ(Point2D.Double point)
          Returns the altimetric/bathymetric value of the given geographical coordinates.
 short[] getZ(Point2D.Double[] points)
          Returns the altimetric/bathymetric values of the given array of geographical coordinates.
 void open()
          Opens the netCDF file and loads the data array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GRID_COLS

public static final int GRID_COLS
See Also:
Constant Field Values

GRID_ROWS

public static final int GRID_ROWS
See Also:
Constant Field Values
Constructor Detail

NoDatasetFiles

public NoDatasetFiles(String filename)
Creates an instance of VTIBathymetry with the specified file.

Parameters:
filename - the netCDF filename containing the altimetry/bathymetry data
Method Detail

open

public void open()
          throws IOException
Opens the netCDF file and loads the data array. This operation is somewhat slow and requires the creation of a big object in memory. Ideally, this method is called only once, before the altrimetry/bathymetry values are needed.

Throws:
IOException

close

public void close()
           throws IOException
Closes the netCDF file.

Throws:
IOException

getZ

public short getZ(Point2D.Double point)
           throws IOException
Returns the altimetric/bathymetric value of the given geographical coordinates. The value derives from the corresponding cell in the coordinate grid (120 x 120 cells per degree). If a coordinate is close to the cell border (< 0.1 * arc cell size), the result value is averaged with the value from the adjacent cell.

Parameters:
point - the geographical coordinates (x = longitude value (-180 to 180), y = latitude value (-90 to 90))
Returns:
the altimetric/bathymetric value for the coordinate (in meters)
Throws:
IOException - if the netCDF variable z could not been read

getZ

public short[] getZ(Point2D.Double[] points)
             throws IOException
Returns the altimetric/bathymetric values of the given array of geographical coordinates. The value derives from the corresponding cell in the coordinate grid (120 x 120 cells per degree). If a coordinate is close to the cell border (< 0.1 * arc cell size), the result value is averaged with the value from the adjacent cell.

Parameters:
points - array of geographical coordinates (x = longitude value (-180 to 180), y = latitude value (-90 to 90))
Returns:
an array of the same shape as points, containing the altimetric/bathymetric value for the coordinate (in meters)
Throws:
IOException - if the netCDF variable z could not been read

getZ

public short getZ(double x,
                  double y)
           throws NullPointerException,
                  IOException
Returns the altimetric/bathymetric value of the given geographical coordinates. The value derives from the corresponding cell in the coordinate grid (120 x 120 cells per degree). If a coordinate is close to the cell border (< 0.1 * arc cell size), the result value is averaged with the value from the adjacent cell.

Parameters:
x - longitude coordinate (-180 to 180)
y - latitude coordinate (-90 to 90)
Returns:
the altimetric/bathymetric value for the coordinate (in meters)
Throws:
NullPointerException - if the netCDF file has not been opened or the variable z (containing the altimetry/bathymetry values) is not found
IOException - if the netCDF variable z could not been read

getVarPoint

public static double getVarPoint(ucar.nc2.Variable var,
                                 double x,
                                 double y)
                          throws NullPointerException,
                                 IOException
Throws:
NullPointerException
IOException


Copyright © 2012. All Rights Reserved.