org.opensha.commons.data.xyz
Class EvenlyDiscrXYZ_DataSet

java.lang.Object
  extended by org.opensha.commons.data.xyz.AbstractXYZ_DataSet
      extended by org.opensha.commons.data.xyz.EvenlyDiscrXYZ_DataSet
All Implemented Interfaces:
Serializable, Cloneable, XYZ_DataSet

public class EvenlyDiscrXYZ_DataSet
extends AbstractXYZ_DataSet

This class represents an evenly discretized XYZ dataset. Data is stored as an array, and set/get operations will use the closest point in the data if it's not exact.

Author:
kevin
See Also:
Serialized Form

Constructor Summary
EvenlyDiscrXYZ_DataSet(double[][] data, double minX, double minY, double gridSpacing)
           
EvenlyDiscrXYZ_DataSet(double[][] data, double minX, double minY, double gridSpacingX, double gridSpacingY)
           
EvenlyDiscrXYZ_DataSet(int nx, int ny, double minX, double minY, double gridSpacing)
           
EvenlyDiscrXYZ_DataSet(int nx, int ny, double minX, double minY, double gridSpacingX, double gridSpacingY)
           
 
Method Summary
 double bilinearInterpolation(double x, double y)
          Bilinear interpolation.
 EvenlyDiscretizedFunc calcMarginalXDist()
           
 EvenlyDiscretizedFunc calcMarginalYDist()
           
 Object clone()
           
 boolean contains(double x, double y)
          Returns true if the dataset contains the given point, false otherwise.
 boolean contains(Point2D point)
          Returns true if the dataset contains the given point, false otherwise.
 XYZ_DataSet copy()
          Returns a shallow copy of this XYZ_DataSet.
 double get(double x, double y)
          Gets the value at the given point.
 double get(int index)
          Gets the value at the given index.
 double get(int xInd, int yInd)
           
 double get(Point2D point)
          Gets the value at the given point.
 EvenlyDiscretizedFunc getCol(int xInd)
           
 double getGridSpacingX()
          Get the grid spacing of this evenly discretized dataset in the x dimension
 double getGridSpacingY()
          Get the grid spacing of this evenly discretized dataset in the y dimension
 double getMaxX()
          Returns the maximum X value in this dataset.
 double getMaxY()
          Returns the maximum Y value in this dataset.
 double getMinX()
          Returns the minimum X value in this dataset.
 double getMinY()
          Returns the minimum Y value in this dataset.
 int getNumX()
           
 int getNumY()
           
 Point2D getPoint(int index)
          Gets the point at the given index.
 EvenlyDiscretizedFunc getRow(int yInd)
           
 double getX(int xIndex)
           
 int getXIndex(double x)
           
 double getY(int yIndex)
           
 int getYIndex(double y)
           
 int indexOf(double x, double y)
          Returns the index of the given point, or -1 if it isn't in the dataset.
 int indexOf(Point2D point)
          Returns the index of the given point, or -1 if it isn't in the dataset.
static EvenlyDiscrXYZ_DataSet readXYZBinFile(String fileNamePrefix)
           
 void set(double x, double y, double z)
          Sets the value at the given point.
 void set(int index, double z)
          Sets the value at the given index.
 void set(int xInd, int yInd, double z)
           
 void set(Point2D point, double z)
          Sets the value at the given point.
 int size()
          Returns the size of this dataset.
 void writeXYZBinFile(String fileNamePrefix)
           
 
Methods inherited from class org.opensha.commons.data.xyz.AbstractXYZ_DataSet
abs, add, exp, exp, getMaxZ, getMinZ, getPointList, getValueList, log, log10, pow, scale, setAll, writeXYZFile, writeXYZFile
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EvenlyDiscrXYZ_DataSet

public EvenlyDiscrXYZ_DataSet(int nx,
                              int ny,
                              double minX,
                              double minY,
                              double gridSpacing)

EvenlyDiscrXYZ_DataSet

public EvenlyDiscrXYZ_DataSet(int nx,
                              int ny,
                              double minX,
                              double minY,
                              double gridSpacingX,
                              double gridSpacingY)

EvenlyDiscrXYZ_DataSet

public EvenlyDiscrXYZ_DataSet(double[][] data,
                              double minX,
                              double minY,
                              double gridSpacing)

EvenlyDiscrXYZ_DataSet

public EvenlyDiscrXYZ_DataSet(double[][] data,
                              double minX,
                              double minY,
                              double gridSpacingX,
                              double gridSpacingY)
Method Detail

getMaxX

public double getMaxX()
Description copied from interface: XYZ_DataSet
Returns the maximum X value in this dataset.

Specified by:
getMaxX in interface XYZ_DataSet
Overrides:
getMaxX in class AbstractXYZ_DataSet
Returns:
maximum X value, or negative infinity if the dataset is empty

getMaxY

public double getMaxY()
Description copied from interface: XYZ_DataSet
Returns the maximum Y value in this dataset.

Specified by:
getMaxY in interface XYZ_DataSet
Overrides:
getMaxY in class AbstractXYZ_DataSet
Returns:
maximum Y value, or negative infinity if the dataset is empty

getMinX

public double getMinX()
Description copied from interface: XYZ_DataSet
Returns the minimum X value in this dataset.

Specified by:
getMinX in interface XYZ_DataSet
Overrides:
getMinX in class AbstractXYZ_DataSet
Returns:
minimum X value, or positive infinity if the dataset is empty

getMinY

public double getMinY()
Description copied from interface: XYZ_DataSet
Returns the minimum Y value in this dataset.

Specified by:
getMinY in interface XYZ_DataSet
Overrides:
getMinY in class AbstractXYZ_DataSet
Returns:
minimum Y value, or positive infinity if the dataset is empty

getGridSpacingX

public double getGridSpacingX()
Get the grid spacing of this evenly discretized dataset in the x dimension

Returns:

getGridSpacingY

public double getGridSpacingY()
Get the grid spacing of this evenly discretized dataset in the y dimension

Returns:

getNumX

public int getNumX()

getNumY

public int getNumY()

writeXYZBinFile

public void writeXYZBinFile(String fileNamePrefix)
                     throws IOException
Throws:
IOException

readXYZBinFile

public static EvenlyDiscrXYZ_DataSet readXYZBinFile(String fileNamePrefix)
                                             throws IOException
Throws:
IOException

getX

public double getX(int xIndex)

getY

public double getY(int yIndex)

getYIndex

public int getYIndex(double y)

getXIndex

public int getXIndex(double x)

set

public void set(Point2D point,
                double z)
Description copied from interface: XYZ_DataSet
Sets the value at the given point. If the point doesn't exist, it will be added to the dataset.

Parameters:
point - - the point at which to set
z - - the value to set

set

public void set(double x,
                double y,
                double z)
Description copied from interface: XYZ_DataSet
Sets the value at the given point. If the point doesn't exist, it will be added to the dataset.

Parameters:
x - - the x value of the point at which to set
y - - the y value of the point at which to set
z - - the value to set

set

public void set(int index,
                double z)
Description copied from interface: XYZ_DataSet
Sets the value at the given index. If index < 0 or index >= size(), then an exception is thrown.

Parameters:
index - - the index of the point to be set
z - - the value to set

get

public double get(double x,
                  double y)
Description copied from interface: XYZ_DataSet
Gets the value at the given point. If the point doesn't exist, null will be returned.

Parameters:
x - - the x value of the point at which to get
y - - the y value of the point at which to get
Returns:
the value at the given point

bilinearInterpolation

public double bilinearInterpolation(double x,
                                    double y)
Bilinear interpolation. Algorithm taken from:
http://docs.oracle.com/cd/E17802_01/products/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/InterpolationBilinear.html

Parameters:
x -
y -
Returns:
Throws:
IllegalArgumentException - if x or y is outside of the allowable range

get

public double get(int index)
Description copied from interface: XYZ_DataSet
Gets the value at the given index. If index < 0 or index >= size(), then an exception is thrown.

Parameters:
index - - the index of the point at which to get
Returns:
the value at the given index

size

public int size()
Description copied from interface: XYZ_DataSet
Returns the size of this dataset.

Returns:
size of this dataset

set

public void set(int xInd,
                int yInd,
                double z)

get

public double get(int xInd,
                  int yInd)

get

public double get(Point2D point)
Description copied from interface: XYZ_DataSet
Gets the value at the given point. If the point doesn't exist, null will be returned.

Parameters:
point - - the point at which to get
Returns:
the value at the given point, or null if the point is not contained in the dataset

getPoint

public Point2D getPoint(int index)
Description copied from interface: XYZ_DataSet
Gets the point at the given index. If index < 0 or index >= size(), then an exception is thrown.

Parameters:
index - - the index of the point to get
Returns:
the point at the given index

indexOf

public int indexOf(Point2D point)
Description copied from interface: XYZ_DataSet
Returns the index of the given point, or -1 if it isn't in the dataset.

Parameters:
point - - the point at which to return the index
Returns:
index of the given point, or -1 if it isn't in the dataset.

contains

public boolean contains(Point2D point)
Description copied from interface: XYZ_DataSet
Returns true if the dataset contains the given point, false otherwise.

Parameters:
point - - the point to check
Returns:
true if point is not null and is contained by the dataset, false otherwise

contains

public boolean contains(double x,
                        double y)
Description copied from interface: XYZ_DataSet
Returns true if the dataset contains the given point, false otherwise.

Parameters:
x - - the x value of the point to check
y - - the y value of the point to check
Returns:
true if the dataset contains the given point, false otherwise

clone

public Object clone()
Overrides:
clone in class Object

copy

public XYZ_DataSet copy()
Description copied from interface: XYZ_DataSet
Returns a shallow copy of this XYZ_DataSet. Internal points are not cloned.

Returns:
shallow copy of this XYZ_DataSet

indexOf

public int indexOf(double x,
                   double y)
Description copied from interface: XYZ_DataSet
Returns the index of the given point, or -1 if it isn't in the dataset.

Parameters:
x - - the x value of the point at which to return the index
y - - the y value of the point at which to return the index
Returns:
index of the given point, or -1 if it isn't in the dataset.

calcMarginalXDist

public EvenlyDiscretizedFunc calcMarginalXDist()

calcMarginalYDist

public EvenlyDiscretizedFunc calcMarginalYDist()

getRow

public EvenlyDiscretizedFunc getRow(int yInd)

getCol

public EvenlyDiscretizedFunc getCol(int xInd)