Class Histo2DData
Data coordinates are binned into a uniform grid of nx * ny cells over
[xmin, xmax] and [ymin, ymax].
Bin conventions
- Bins are uniform in x and y.
- Values strictly below min or strictly above max are out of range.
- Values exactly equal to max are included in the last bin.
Under/over handling
Like HistoData, values outside the range are not binned; instead
they are counted in under/over counters. In 2D there are edge regions and
corners (both x and y out of range).
Threading
This class is safe to fill from a worker thread while the EDT paints by usingsnapshotBins() in the painter. All mutations and snapshots are guarded
by an internal lock.- Author:
- heddle
-
Constructor Summary
ConstructorsConstructorDescriptionHisto2DData(String name, double xmin, double xmax, int nx, double ymin, double ymax, int ny) Constructor for 2D histogram data. -
Method Summary
Modifier and TypeMethodDescriptiondoublebin(double x, double y) Get the bin content for data coordinates.doublebin(int ix, int iy) Get the bin content.voidclear()intentries()Backwards-compatible name: this returns the in-range (good) fill count.voidfill(double x, double y) Fill the histogram with weight 1.0.voidfill(double x, double y, double weight) Fill the histogram.longlonglonglonglonglonglonglonglonglonglongdoublelocalMean3x3(double datax, double datay) Compute the local 3x3 neighborhood average around the bin containing the given data coordinate.doublemaxBin()Get the maximum bin value.static doublemaxZ(double[][] bins) Static utility to get the maximum z value from a 2D bins array.doublemeanBin()Get the mean bin value (average of in-range bins).doubleGet the minimum non-zero bin value.name()intnx()intny()doublepercentile(double datax, double datay) Get the percentile rank of the bin containing the given data coordinate.Return a human-readable summary of in-range and out-of-range fills.voidsetBinsForDeserialization(double[][] bins, long goodCount, long xUnderCount, long xOverCount, long yUnderCount, long yOverCount, long xUnder_yUnder, long xUnder_yOver, long xOver_yUnder, long xOver_yOver) INTERNAL: set bin contents and counts during deserialization/persistence restore.double[][]Deep-copy bins for safe use during painting.double[]xBinRange(double x) Get the x bin range for a data x.doubleintxIndex(double x) Get the x-bin index for a data x.doublexMax()doublexMin()double[]yBinRange(double y) Get the y bin range for a data y.doubleintyIndex(double y) Get the y-bin index for a data y.doubleyMax()doubleyMin()
-
Constructor Details
-
Histo2DData
Constructor for 2D histogram data.- Parameters:
name- histogram namexmin- the minimum x valuexmax- the maximum x valuenx- number of x binsymin- the minimum y valueymax- the maximum y valueny- number of y bins
-
-
Method Details
-
name
-
nx
public int nx()- Returns:
- number of x bins
-
ny
public int ny()- Returns:
- number of y bins
-
xMin
public double xMin()- Returns:
- minimum x value
-
xMax
public double xMax()- Returns:
- maximum x value
-
yMin
public double yMin()- Returns:
- minimum y value
-
yMax
public double yMax()- Returns:
- maximum y value
-
xBinWidth
public double xBinWidth()- Returns:
- x bin width
-
yBinWidth
public double yBinWidth()- Returns:
- y bin width
-
xIndex
public int xIndex(double x) Get the x-bin index for a data x. Returns -1 if out of range. Includes x==xMax in the last bin. -
yIndex
public int yIndex(double y) Get the y-bin index for a data y. Returns -1 if out of range. Includes y==yMax in the last bin. -
fill
public void fill(double x, double y) Fill the histogram with weight 1.0. -
fill
public void fill(double x, double y, double weight) Fill the histogram.Out-of-range points increment under/over counters; in-range points increment the appropriate bin. Weight may be any finite value (including negative), but note that negative weights make "max" less meaningful.
-
bin
public double bin(double x, double y) Get the bin content for data coordinates. Returns 0 for out-of-range.- Parameters:
x- data xy- data y- Returns:
- bin content (the "z" value)
-
bin
public double bin(int ix, int iy) Get the bin content. Returns 0 for out-of-range indices.- Parameters:
ix- x bin indexiy- y bin index- Returns:
- bin content (the "z" value)
-
xBinRange
public double[] xBinRange(double x) Get the x bin range for a data x.- Parameters:
x- data x- Returns:
- [x0, x1] bin range, or null if out of range
-
yBinRange
public double[] yBinRange(double y) Get the y bin range for a data y.- Parameters:
y- data y- Returns:
- [y0, y1] bin range, or null if out of range
-
entries
public int entries()Backwards-compatible name: this returns the in-range (good) fill count. -
getGoodCount
public long getGoodCount()- Returns:
- in-range fill count (good points).
-
getTotalCount
public long getTotalCount()- Returns:
- total fills including out-of-range.
-
getXUnderCount
public long getXUnderCount()- Returns:
- x-underflow count (y in range).
-
getXOverCount
public long getXOverCount()- Returns:
- x-overflow count (y in range).
-
getYUnderCount
public long getYUnderCount()- Returns:
- y-underflow count (x in range).
-
getYOverCount
public long getYOverCount()- Returns:
- y-overflow count (x in range).
-
getXUnderYUnderCount
public long getXUnderYUnderCount()- Returns:
- corner: x under, y under.
-
getXUnderYOverCount
public long getXUnderYOverCount()- Returns:
- corner: x under, y over.
-
getXOverYUnderCount
public long getXOverYUnderCount()- Returns:
- corner: x over, y under.
-
getXOverYOverCount
public long getXOverYOverCount()- Returns:
- corner: x over, y over.
-
getEmptyBinCount
public long getEmptyBinCount()- Returns:
- number of non-empty bins.
-
maxBin
public double maxBin()Get the maximum bin value.- Returns:
- maximum bin value, or 0 if none
-
minNonZero
public double minNonZero()Get the minimum non-zero bin value.- Returns:
- minimum non-zero bin value, or 0 if none
-
clear
public void clear() -
snapshotBins
public double[][] snapshotBins()Deep-copy bins for safe use during painting. -
maxZ
public static double maxZ(double[][] bins) Static utility to get the maximum z value from a 2D bins array.- Parameters:
bins- 2D array of bin values- Returns:
- maximum finite bin value, or 0 if none
-
meanBin
public double meanBin()Get the mean bin value (average of in-range bins).- Returns:
- mean bin value, or 0 if none
-
percentile
public double percentile(double datax, double datay) Get the percentile rank of the bin containing the given data coordinate.Percentile is computed over the distribution of occupied bins (non-zero, finite bin values). The returned value is in the range
[0, 100]where 0 means "empty or no occupied bins" and 100 means "at or above the maximum occupied bin".- Parameters:
datax- data x coordinatedatay- data y coordinate- Returns:
- percentile rank in
[0, 100]
-
localMean3x3
public double localMean3x3(double datax, double datay) Compute the local 3x3 neighborhood average around the bin containing the given data coordinate.The neighborhood includes the center bin and all valid in-range neighbors. The average is computed over finite values; non-finite values are ignored.
- Parameters:
datax- data x coordinatedatay- data y coordinate- Returns:
- local 3x3 average, or 0 if the coordinate is out of range or no finite bins are available
-
setBinsForDeserialization
public void setBinsForDeserialization(double[][] bins, long goodCount, long xUnderCount, long xOverCount, long yUnderCount, long yOverCount, long xUnder_yUnder, long xUnder_yOver, long xOver_yUnder, long xOver_yOver) INTERNAL: set bin contents and counts during deserialization/persistence restore.This performs a defensive deep-copy of
binsand replaces the internal counts in a single synchronized block.- Parameters:
bins- bin contents sized[nx][ny]goodCount- in-range fill countxUnderCount- x-underflow count (y in-range)xOverCount- x-overflow count (y in-range)yUnderCount- y-underflow count (x in-range)yOverCount- y-overflow count (x in-range)xUnder_yUnder- corner count (x under, y under)xUnder_yOver- corner count (x under, y over)xOver_yUnder- corner count (x over, y under)xOver_yOver- corner count (x over, y over)
-
rangeSummary
Return a human-readable summary of in-range and out-of-range fills.Only non-zero out-of-range categories are reported.
- Returns:
- summary string
-