Class BinGrid

java.lang.Object
uk.ac.starlink.ttools.plot.BinGrid

public class BinGrid extends Object
Stores a grid of bins which contain sums, which may be simple counts or weighted sums. This is effectively the data model for a two-dimensional possibly weighted histogram or, to put it another way, it's an image.
Since:
1 Dec 2005
Author:
Mark Taylor
  • Constructor Summary

    Constructors
    Constructor
    Description
    BinGrid(int xsize, int ysize)
    Constructs a new grid.
  • Method Summary

    Modifier and Type
    Method
    Description
    byte[]
    getBytes(double loCut, double hiCut, boolean log)
    Returns an array of bytes representing the values in this grid.
    double
    getCut(double frac)
    Returns the cut value associated with a given fractional value (between 0 and 1).
    double
    Returns the largest value which exists in any of the bins.
    double
    Returns the smallest value which exists in any of the bins.
    int
    Returns the number of bins (pixels) in the X direction.
    int
    Returns the number of bins (pixels) in the Y direction.
    double
    getSum(int ix, int iy)
    Returns the sum in a given bin (value at a given pixel).
    double[]
    Returns the raw histogram data held by this grid.
    void
    Recalculates invariants.
    void
    submitDatum(int ix, int iy, double weight)
    Adds a data point to this histogram.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • BinGrid

      public BinGrid(int xsize, int ysize)
      Constructs a new grid.
      Parameters:
      xsize - number of bins (pixels) in X direction
      ysize - number of bins (pixels) in Y direction
  • Method Details

    • getSizeX

      public int getSizeX()
      Returns the number of bins (pixels) in the X direction.
      Returns:
      x dimension
    • getSizeY

      public int getSizeY()
      Returns the number of bins (pixels) in the Y direction.
      Returns:
      y dimension
    • getSum

      public double getSum(int ix, int iy)
      Returns the sum in a given bin (value at a given pixel).
      Parameters:
      ix - x coordinate
      iy - y coordinate
    • getMaxSum

      public double getMaxSum()
      Returns the largest value which exists in any of the bins.
      Returns:
      maximum pixel value
    • getMinSum

      public double getMinSum()
      Returns the smallest value which exists in any of the bins.
      Returns:
      minimum pixel value
    • getCut

      public double getCut(double frac)
      Returns the cut value associated with a given fractional value (between 0 and 1). If frac=0.25 you'll get the first quartile of sum values currently in the histogram.
      Parameters:
      frac - fraction for which cut is required (0..1)
      Returns:
      value below which frac of the bins have occupancies
    • submitDatum

      public void submitDatum(int ix, int iy, double weight)
      Adds a data point to this histogram. The sum in the bin (ix,iy) is incremented by weight.
      Parameters:
      ix - X grid coordinate
      iy - Y grid coordinate
      weight - weight
    • recalculate

      public void recalculate()
      Recalculates invariants. This must be called if the sums arrray is modified directly.
    • getBytes

      public byte[] getBytes(double loCut, double hiCut, boolean log)
      Returns an array of bytes representing the values in this grid. The values are scaled to occupy the full range 0-255 or roughly so. Cut values are supplied; any bin values below loCut will get a result value of 0, any ones above hiCut will get a result value of 255. The ordering of pixels is that X values change most rapidly and Y values decrease. This is the order suitable for AWT images.

      Note the values must be interpreted as unsigned 8-bit values (value = 0x000000ff & (int)getBytes()[i]).

      Parameters:
      loCut - lowest distinguished sum value
      hiCut - highest distinguished sum value
      log - true iff you want logarithmic scalling of the colours
      Returns:
      scaled array of unsigned byte values representing grid data
    • getSums

      public double[] getSums()
      Returns the raw histogram data held by this grid. The result is an array where each element holds the number of points which have fallen in the corresponding bin. Note the ordering is image-like, as for getBytes(double, double, boolean) - X values change most rapidly and Y values decrease.
      Returns:
      sum array