예제 #1
0
/*!
 * \brief Smooth data
 */
void Data2D::smooth(int avgSize, int skip)
{
	// First, create a new dataset using Y-averages of the current data
	Data2D avg;
	double y;
	int n, m, i = avgSize/2;
	for (n=i; n < x_.nItems()-i; n += (1+skip))
	{
		y = 0.0;
		for (m=n-i; m <= n+i; ++m) y += y_[m];
		y /= avgSize;
		
		avg.addPoint(x_[n], y);
	}

	avg.interpolate();

	// Now go through old data, setting new Y values from the interpolation
	for (n=0; n<x_.nItems(); ++n) y_[n] = avg.interpolated(x_[n]);
}
예제 #2
0
/*!
 * \brief Convolute this data with the supplied data, by products
 */
bool Data2D::convoluteProduct(Data2D& data)
{
	// Check compatibility of datasets
	if (data.nPoints() != nPoints())
	{
		msg.print("Refusing to convolute by product two datasets of different sizes.\n");
		return false;
	}
	for (int n=0; n<nPoints(); ++n)
	{
		if (fabs(data.x(n) - x_[n]) > 1.0e-5)
		{
			msg.print("Refusing to convolute by product two datasets with different x-values.\n");
			return false;
		}
	}

	// Ready to go...
	for (int n=0; n<nPoints(); ++n) y_[n] *= data.y(n);
	
	return true;
}
예제 #3
0
/*!
 * \brief Subtract interpolated data
 */
void Data2D::subtractInterpolated(Data2D& source)
{
	for (int n=0; n<x_.nItems(); ++n) addY(n, -source.interpolated(x_.value(n)));
}
예제 #4
0
파일: box.cpp 프로젝트: trisyoungs/duq
// Calculate the RDF normalisation for the Box
bool Box::calculateRDFNormalisation(ProcessPool& procPool, Data2D& boxNorm, double rdfRange, double rdfBinWidth, int nPoints) const
{
	// Setup array - we will use a nominal bin width of 0.1 Angstroms and then interpolate to the rdfBinWidth afterwards
	const double binWidth = 0.1;
	const double rBinWidth = 1.0/binWidth;
	int bin, nBins = rdfRange / binWidth;
	Data2D normData;
	normData.initialise(nBins);
	Array<double>& y = normData.arrayY();
	for (int n=0; n<nBins; ++n) normData.arrayX()[n] = (n+0.5)*binWidth;
	
	Vec3<double> centre = axes_*Vec3<double>(0.5,0.5,0.5);

	// Divide points over processes
	const int nPointsPerProcess = nPoints / procPool.nProcesses();
	Messenger::print("--> Number of insertion points (per process) is %i\n", nPointsPerProcess);
	y = 0.0;
	for (int n=0; n<nPointsPerProcess; ++n)
	{
		bin = (randomCoordinate() - centre).magnitude() * rBinWidth;
		if (bin < nBins) y[bin] += 1.0;
	}
	if (!procPool.allSum(y.array(), nBins)) return false;

	// Normalise histogram data, and scale by volume and binWidth ratio
	y /= double(nPointsPerProcess*procPool.nProcesses());
	y *= volume_ * (rdfBinWidth / binWidth);
	normData.interpolate();

	// Write histogram data for random distribution
	if (procPool.isMaster()) normData.save("duq.box.random");
	
	// Now we have the interpolated data, create the proper interpolated data
	nBins = rdfRange/rdfBinWidth;
	boxNorm.clear();

	// Rescale against expected volume for spherical shells
	double shellVolume, r = 0.0, maxHalf = inscribedSphereRadius(), x = 0.5*rdfBinWidth;
	for (int n=0; n<nBins; ++n)
	{
		// We know that up to the maximum (orthogonal) half-cell width the normalisation should be exactly 1.0...
		if (x < maxHalf) boxNorm.addPoint(x, 1.0);
		else
		{
			shellVolume = (4.0/3.0)*PI*(pow(r+rdfBinWidth,3.0) - pow(r,3.0));
			boxNorm.addPoint(x,  shellVolume / normData.interpolated(x));
// 			boxNorm[n] = normData.interpolated(r);
		}
		r += rdfBinWidth;
		x += rdfBinWidth;
	}
	
	// Interpolate normalisation array
	boxNorm.interpolate();

	// Write final box normalisation file
	if (procPool.isMaster()) boxNorm.save("duq.box.norm");

	return true;
}
예제 #5
0
void Osciloscope::on_pushButton_clicked(){
    unsigned long int retCount;
    QCheckBox * boxes[8] = {ui->checkBox,ui->checkBox_2,ui->checkBox_3,ui->checkBox_4,
                            ui->func1checkBox,ui->func2checkBox,ui->func3checkBox,ui->func3checkBox};
    QStringList chstrings;
    chstrings << "CH1" <<"CH2" <<"CH3" <<"CH4" << "MATH"
                 << "FUNCTION2" <<"FUNCTION3" << "FUNCTION4";
    QVariant vi = data->parameter("gpib_vi");
    GPIBBus *bus = GPIBBus::instance();
    QVariant devId = data->parameter("deviceID");
    vi =bus->openDev(devId);
    data->setParameter("gpib_vi",vi);
    Data2D* data = (Data2D*)this->data;
    data->startEdit();

    for(int i = 1; i<=8;i++){
        QString chstring =chstrings[i-1];
        if(boxes[i-1]->isChecked()){
            ui->label->setText("Reading "+chstring+" ...");
            ui->progressBar->setValue(0);
            bus->gpib_command(vi,"DATa:SOUrce "+chstring+";DATa:ENCdg RIBinary;DATa:WIDth 1;DATa:STARt 1;DATa:STOP 2500\n");
            QString res =bus->gpib_query(vi,"WFMPre?\n");
            QStringList wfpreamp = res.split(";");
            if(wfpreamp.size()>5 && wfpreamp.size()<16){
                char tmp[1000];
                char * buff = tmp;
                unsigned long ret;
                bus->readBlock(vi,buff,1000,&ret);
                QString add = buff;
                res.append(add);
                wfpreamp = res.split(";");
                qDebug(res.toLocal8Bit().data());
                if(wfpreamp.size()<16){
                    ui->label->setText("Failed to read data from the device");
                    break;
                }
            }
            if(wfpreamp.size()>5){
                ui->progressBar->setValue(25);
                boxes[i-1]->setText(wfpreamp[6]);
                double xmult, ymult,offset;
                xmult = wfpreamp[8].toDouble();
                ymult =wfpreamp[12].toDouble();
                offset = wfpreamp[14].toDouble();
                char databuff_[2507];
                ui->progressBar->setValue(50);
                bus->queryBlock(vi, "Curve?\n",databuff_,2507,&retCount);
                for(int j=6; j<2506;j++){
                    data->addPoint(chstring,j*1.0*xmult,(databuff_[j]-offset)*ymult); //TODO::ADDconsts
                }
            }else{
                boxes[i-1]->setText(chstring);
            }
            ui->progressBar->setValue(100);
        }else{
            boxes[i-1]->setText(chstring);
        }
    }
    bus->closeDev(vi);
    ui->label->setText("Done");
    data->stopEdit();
}