/* File: TableAveragePeakRebinner.java * Copyright (C) 2002-2003 The University of Iowa * * Created on November 12, 2003, 4:25 PM * by Edward West * * This file is part of the das2 library. * * das2 is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package org.das2.dataset; import java.util.Arrays; import org.das2.datum.Units; import org.das2.qds.DDataSet; import org.das2.qds.JoinDataSet; import org.das2.qds.QDataSet; import org.das2.qds.SemanticOps; import org.das2.qds.ops.Ops; /** * * @author Edward West */ public class AveragePeakTableRebinner implements DataSetRebinner { /* adds additional planes for debugging */ private boolean debug= false; /** Creates a new instance of TableAveragePeakRebinner */ public AveragePeakTableRebinner() { } @Override public String toString() { return "averagePeakRebinner"; } @Override public QDataSet rebin( QDataSet ds, RebinDescriptor ddX, RebinDescriptor ddY, RebinDescriptor z) throws IllegalArgumentException { QDataSet tds; JoinDataSet tds3= new JoinDataSet(3); // for AverageTableRebinner. if ( ds.rank()==2 ) { tds3.join(ds); tds= ds; } else if ( ds.rank()==3 ) { throw new IllegalArgumentException("dataset must be rank 2"); } else { throw new IllegalArgumentException("dataset must be rank 2"); } QDataSet weights = org.das2.qds.DataSetUtil.weightsDataSet(ds); QDataSet peaks = (QDataSet) ds.property( QDataSet.BIN_MAX ); if ( peaks==null ) { QDataSet binPlus= (QDataSet) ds.property( QDataSet.BIN_PLUS ); if ( binPlus!=null ) peaks= Ops.add( ds, binPlus ); } //long timer= System.currentTimeMillis(); int nx= (ddX == null ? tds.length() : ddX.numberOfBins()); int ny= (ddY == null ? tds.length(0) : ddY.numberOfBins()); double[][] averageData= new double[nx][ny]; double[][] averageWeights= new double[nx][ny]; double[][] peakData = new double[nx][ny]; AverageTableRebinner.average(tds3, weights, averageData, averageWeights, ddX, ddY, AverageTableRebinner.Interpolate.NearestNeighbor ); QDataSet xtds= SemanticOps.xtagsDataSet(tds); QDataSet ytds= SemanticOps.ytagsDataSet(tds); Units xunits= SemanticOps.getUnits(xtds); double[] xTags; double[] xTagMin, xTagMax; if (ddX != null) { xTags = ddX.binCenters(); xTagMin = ddX.binStops(); xTagMax = ddX.binStarts(); for ( int i=0; i-1 && ibin