/* * AvergeNoInterpolateTableRebinner.java * * Created on September 19, 2005, 12:49 PM * * */ package org.das2.dataset; import org.das2.DasException; import org.das2.datum.Datum; import org.das2.datum.DatumRange; import org.das2.datum.DatumVector; import org.das2.datum.Units; import org.das2.datum.UnitsUtil; import org.das2.system.DasLogger; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.logging.Logger; /** * This rebinner will bin average elements that fall on the same bin, and will enlarge cells that * cover multiple bins. This is done efficiently, and also does not introduce half-pixel aliasing because * input cells covering multiple output cells are averaged weighting by overlap. * * @author Jeremy */ public class AverageNoInterpolateTableRebinner { // { implements DataSetRebinner { Logger logger; boolean nearestNeighbor= false; static class BinDescriptor { int length; int[] inputBins; // which bin to get int[] outputBins; // where to put it double[] weights; // what weight to apply public String toString() { StringBuffer result= new StringBuffer(); int ll= length < 30 ? length : 30; for ( int i=0; i "+outputBins[i]+"\n" ); } if ( length==0 ) { result.append( "(no rebinning)\n" ); } else if ( length>30 ) { result.append( "("+(length-30)+" more)" ); } return result.toString(); } } private static DatumRange[] getXTagRanges( DataSet ds, int i0, int i1 ) { Datum tagWidth= DataSetUtil.guessXTagWidth(ds).divide(2); DatumRange[] result= new DatumRange[ i1-i0 ]; for ( int i=0; i1 ) throw new IllegalArgumentException( "null yRebinDescriptor not allowed for non-simple table datasets." ); ybd= getIdentityBinDescriptor( tds.getYLength(itable) ); } logger.finest("apply rebinning"); logger.finest("ybd.length="+ybd.length); int x0= tds.tableStart(itable); if ( nearestNeighbor ) { for ( int i=0; i weights[xbd.outputBins[i]][ybd.outputBins[j]] ) { sum[xbd.outputBins[i]][ybd.outputBins[j]]= z; weights[xbd.outputBins[i]][ybd.outputBins[j]]= w * w2; } } } } else { for ( int i=0; i0. ) { sum[i][j]/= weights[i][j]; } else { sum[i][j]= fill; } } } } logger.finest("calculate dataset"); double[][][] zValues = {sum,weights}; int[] tableOffsets = {0}; Units[] zUnits = {tds.getZUnits(), Units.dimensionless}; String[] planeIDs = {"", DataSet.PROPERTY_PLANE_WEIGHTS }; Map properties= new HashMap(ds.getProperties()); if ( ddx!=null ) properties.put( DataSet.PROPERTY_X_TAG_WIDTH, ddx.binWidthDatum() ); if ( ddy!=null ) properties.put( DataSet.PROPERTY_Y_TAG_WIDTH, ddy.binWidthDatum() ); double[] xTags; if (ddx != null) { xTags = ddx.binCenters(); } else { xTags = new double[nx]; for (int i = 0; i < nx; i++) { xTags[i] = tds.getXTagDouble(i, tds.getXUnits()); } } double[][] yTags; if (ddy != null) { yTags = new double[][]{ddy.binCenters()}; } else { yTags = new double[1][ny]; for (int j = 0; j < ny; j++) { yTags[0][j] = tds.getYTagDouble(0, j, tds.getYUnits()); } } TableDataSet result= new DefaultTableDataSet( xTags, ddx.getUnits(), yTags, ddy.getUnits(), zValues, zUnits, planeIDs, tableOffsets, properties ); logger.finest("done, exiting AverageNoInterpolateTableRebinner.rebin"); return result; } public boolean isNearestNeighbor( ) { return this.nearestNeighbor; } public void setNearestNeighbor( boolean v ) { this.nearestNeighbor= v; } }