void AM4DBinningABEditor::placeRangeRectangle()
{
	AMDataSource* inputSource;

	if(analysisBlock_->inputDataSourceCount() > 0 && (inputSource=analysisBlock_->inputDataSourceAt(0))) {

		int sumAxis = analysisBlock_->sumAxis();

		double dataMin = inputSource->axisValue(sumAxis,0);
		double sumMin = inputSource->axisValue(sumAxis, analysisBlock_->sumRangeMin());
		double sumMax = inputSource->axisValue(sumAxis, analysisBlock_->sumRangeMax());
		double dataMax = inputSource->axisValue(sumAxis, inputSource->size(sumAxis)-1);

		rangeRectangle1_->setYAxisTarget(plot_->axisScaleVerticalRelative());	// note: does nothing if already correct
		rangeRectangle2_->setYAxisTarget(plot_->axisScaleVerticalRelative());	// note: does nothing if already correct
		rangeRectangle1_->setXAxisTarget(plot_->axisScaleBottom());	// note: does nothing if already correct
		rangeRectangle2_->setXAxisTarget(plot_->axisScaleBottom());	// note: does nothing if already correct

		rangeRectangle1_->setRect(QRectF(QPointF(dataMin,0), QPointF(sumMin,1)).normalized());
		rangeRectangle2_->setRect(QRectF(QPointF(sumMax,0), QPointF(dataMax,1)).normalized());

		rangeRectangle1_->setVisible(true);
		rangeRectangle2_->setVisible(true);
	}

	else {

		rangeRectangle1_->setVisible(false);
		rangeRectangle2_->setVisible(false);
	}
}
void AMAnalysisBlock::onInputSourceDeleted(void* deletedSource) {
	// this implementation is just like calling setInputDataSources() with an empty list, except we don't want to call deregisterObserver() on the deleted input source. (In a single-threaded situation, this would be okay, but if the deleted() signal came through a queued signal-slot connection, then that object might already be deleted)
	for(int i=0; i<inputDataSourceCount(); i++) {
		AMDataSource* oldSource = inputDataSourceAt(i);
		if(oldSource != deletedSource) {
			disconnect(oldSource->signalSource(), SIGNAL(deleted(void*)), this, SLOT(onInputSourceDeleted(void*)));
			oldSource->deregisterObserver(this);
		}
	}
void AMDataSourcesEditor::onDataSourceDescriptionChanged()
{
	QModelIndex index = scanSetView_->currentIndex();
	AMDataSource *dataSource = model_->dataSourceAt(index.parent().row(), index.row());
	if (dataSource){

		descriptionEdit_->setText(dataSource->description());
		scanSetView_->update(index);
	}
}
void AM2DSummingABEditor::onAnalysisBlockInputDataSourcesChanged() {

	if(image_) {
		delete image_;
		image_ = 0;
	}

	AMDataSource* inputSource;
	if(analysisBlock_->inputDataSourceCount() > 0 && (inputSource=analysisBlock_->inputDataSourceAt(0))) {

		// inputSource is a valid data source

		axisSelector_->setEnabled(false);
		rangeMinControl_->setEnabled(true);
		rangeMaxControl_->setEnabled(true);

		QList<AMAxisInfo> inputSourceAxes = inputSource->axes();
		// we know (according to AM2DSummingAB's check of input source validity) that there are two axes here.

		axisSelector_->setItemText(0, inputSourceAxes.at(0).name + ": " + inputSourceAxes.at(0).description);
		axisSelector_->setItemText(1, inputSourceAxes.at(1).name + ": " + inputSourceAxes.at(1).description);

		// set the current status of the controls to reflect the (but don't have then trigger our slots)
		int sumAxis = analysisBlock_->sumAxis();
		axisSelector_->blockSignals(true);
		axisSelector_->setCurrentIndex(sumAxis);
		axisSelector_->blockSignals(false);

		rangeMinControl_->blockSignals(true);
		rangeMinControl_->setMaximum(inputSourceAxes.at(sumAxis).size-1);
		rangeMinControl_->setValue(analysisBlock_->sumRangeMin());
		rangeMinControl_->blockSignals(false);

		rangeMaxControl_->blockSignals(true);
		rangeMaxControl_->setMaximum(inputSourceAxes.at(sumAxis).size-1);
		rangeMaxControl_->setValue(analysisBlock_->sumRangeMax());
		rangeMaxControl_->blockSignals(false);

		image_ = new MPlotImageBasic();
		AMDataSourceImageData *model = new AMDataSourceImageData;
		model->setDataSource(inputSource);
		image_->setModel(model, true);
		plot_->addItem(image_);
	}

	else {
		// no input source. Not much we can do.
		axisSelector_->setEnabled(false);
		rangeMinControl_->setEnabled(false);
		rangeMaxControl_->setEnabled(false);
	}

	placeRangeRectangle();
}
void AM4DBinningABEditor::populateComboBox()
{
	AMDataSource *tempSource = 0;

	for (int i = 0; i < analysisBlock_->inputDataSourceCount(); i++){

		tempSource = analysisBlock_->inputDataSourceAt(i);

		if (analysisBlock_->name() != tempSource->name())
			names_->addItem(tempSource->description(), tempSource->name());
	}
}
void AM1DBasicIntegralABEditor::populateComboBox()
{
    AMDataSource *tempSource = 0;

    for (int i = 0; i < analysisBlock_->inputDataSourceCount(); i++) {

        tempSource = analysisBlock_->inputDataSourceAt(i);

        if (analysisBlock_->name() != tempSource->name() && !tempSource->hiddenFromUsers())
            names_->addItem(tempSource->description(), tempSource->name());
    }
}
void AM4DBinningABEditor::onAnalysisBlockInputDataSourcesChanged()
{
	AMDataSource* inputSource;

	if(analysisBlock_->inputDataSourceCount() > 0 && (inputSource=analysisBlock_->inputDataSourceAt(0))) {

		// inputSource is a valid data source

		axisSelector_->setEnabled(true);
		rangeMinControl_->setEnabled(true);
		rangeMaxControl_->setEnabled(true);

		QList<AMAxisInfo> inputSourceAxes = inputSource->axes();
		// we know (according to AM3DBinningAB's check of input source validity) that there are two axes here.

		axisSelector_->setItemText(0, inputSourceAxes.at(0).name + ": " + inputSourceAxes.at(0).description);
		axisSelector_->setItemText(1, inputSourceAxes.at(1).name + ": " + inputSourceAxes.at(1).description);
		axisSelector_->setItemText(2, inputSourceAxes.at(2).name + ": " + inputSourceAxes.at(2).description);
		axisSelector_->setItemText(2, inputSourceAxes.at(3).name + ": " + inputSourceAxes.at(3).description);

		// set the current status of the controls to reflect the (but don't have then trigger our slots)
		int sumAxis = analysisBlock_->sumAxis();
		axisSelector_->blockSignals(true);
		axisSelector_->setCurrentIndex(sumAxis);
		axisSelector_->blockSignals(false);

		rangeMinControl_->blockSignals(true);
		rangeMinControl_->setMaximum(inputSourceAxes.at(sumAxis).size-1);
		rangeMinControl_->setValue(analysisBlock_->sumRangeMin());
		rangeMinControl_->blockSignals(false);

		rangeMaxControl_->blockSignals(true);
		rangeMaxControl_->setMaximum(inputSourceAxes.at(sumAxis).size-1);
		rangeMaxControl_->setValue(analysisBlock_->sumRangeMax());
		rangeMaxControl_->blockSignals(false);

		updateSeriesData();
	}

	else {
		// no input source. Not much we can do.
		axisSelector_->setEnabled(false);
		rangeMinControl_->setEnabled(false);
		rangeMaxControl_->setEnabled(false);
	}

	placeRangeRectangle();
}
void AMDataSourcesEditor::onCloseButtonClicked(const QModelIndex &index) {

	// handle data source-level indexes only:
	if(!index.parent().isValid())
		return;

	int dataSourceIndex = index.row();
	int scanIndex = index.parent().row();

	AMScan* scan = model_->scanAt(scanIndex);
	if(!scan || dataSourceIndex >= scan->dataSourceCount())
		return;

	if (dataSourceIndex < scan->rawDataSourceCount()){

		QMessageBox::warning(this, "Can not remove raw data sources.", QString("Acquaman does not allow the deletion of raw data sources."));
		return;
	}

	AMDataSource* dataSource = scan->dataSourceAt(dataSourceIndex);
	int response = QMessageBox::question(this, "Remove Data Source?", QString("Remove this data source? \n\n'%1' (%2)\n\nThe data source will be deleted, and no longer visible in any plots. Any other data sources that depend on this data source will be reset.  Raw data will NOT be deleted, and you can re-create the data source later if you need it.").arg(dataSource->description()).arg(dataSource->name()), QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Ok);

	if(response == QMessageBox::Ok)
		scan->deleteDataSourceAt(dataSourceIndex);
}
void AMOrderReductionABEditor::populateComboBox()
{
	AMDataSource *source = 0;

	for (int i = 0, size = analysisBlock_->inputDataSourceCount(); i < size; i++){

		source = analysisBlock_->inputDataSourceAt(i);

		if (analysisBlock_->name() != source->name())
			sourceNames_->addItem(source->description(), source->name());
	}

	if (analysisBlock_->rank() != 0){

		for (int i = 0, size = analysisBlock_->currentInputSource()->rank(); i < size; i++)
			reducedAxisOptions_->insertItem(i, analysisBlock_->currentInputSource()->axisInfoAt(i).description, i);
	}
}
void AMExternalScanDataSourceAB::copyValues(int dataSourceIndex)
{
	AMDataSource* ds = scan_->dataSourceAt(dataSourceIndex);
	const AMnDIndex size = ds->size();

	switch(ds->rank()) {
	case 0:
		values_.clear();
		values_ << ds->value(AMnDIndex());
		break;

	case 1: {
		values_.resize(size.i());
		for(int i=0; i<size.i(); i++)
			values_[i] = ds->value(i);
		break;
	}
	case 2: {
		values_.resize(size.i()*size.j());
		for(int i=0; i<size.i(); i++)
			for(int j=0; j<size.j(); j++)
				values_[i*size.j() + j] = ds->value(AMnDIndex(i,j));
		break;
	}
	case 3: {
		values_.resize(size.i()*size.j()*size.k());
		for(int i=0; i<size.i(); i++)
			for(int j=0; j<size.j(); j++)
				for(int k=0; k<size.k(); k++)
					values_[i*size.j()*size.k() + j*size.k() + k] = ds->value(AMnDIndex(i,j,k));
		break;
	}
	case 4: {
		values_.resize(size.i()*size.j()*size.k()*size.l());
		for(int i=0; i<size.i(); i++)
			for(int j=0; j<size.j(); j++)
				for(int k=0; k<size.k(); k++)
					for(int l=0; l<size.l(); l++)
						values_[i*size.j()*size.k()*size.l() + j*size.k()*size.l() + k*size.l() + l] = ds->value(AMnDIndex(i,j,k,l));
		break;
	}
	case 5: {
		values_.resize(size.i()*size.j()*size.k()*size.l()*size.m());
		for(int i=0; i<size.i(); i++)
			for(int j=0; j<size.j(); j++)
				for(int k=0; k<size.k(); k++)
					for(int l=0; l<size.l(); l++)
						for(int m=0; m<size.m(); m++)
							values_[i*size.j()*size.k()*size.l()*size.m() + j*size.k()*size.l()*size.m() + k*size.l()*size.m() + l*size.m() + m] = ds->value(AMnDIndex(i,j,k,l,m));
		/// \todo oh god, we really need a block copy or a multi-dimensional iterator for AMDataSource::value()...
		break;
	}
	}
}
void AMDataSourcesEditor::onSetViewIndexChanged(const QModelIndex &selected, const QModelIndex &deselected) {

	removeDetailEditor();

	// Nothing selected?
	////////////////////////
	if(!selected.isValid()) {
		nameEdit_->clear();
		descriptionEdit_->clear();
		descriptionEdit_->setReadOnly(true);
		addDataSourceButton_->setDisabled(true);
		return;
	}

	addDataSourceButton_->setEnabled(true);

	// Scan selected? (No selected data source)
	/////////////////////////
	if(!selected.parent().isValid()) {
		nameEdit_->clear();
		descriptionEdit_->clear();
		descriptionEdit_->setReadOnly(true);
		return;
	}


	// Data source selected.
	/////////////////

	// Remove old connection to the data source description.
	int oldSi = deselected.parent().row();
	int oldDi = deselected.row();
	AMDataSource *oldDataSource = model_->dataSourceAt(oldSi, oldDi);
	if (oldDataSource)
		disconnect(oldDataSource->signalSource(), SIGNAL(infoChanged()), this, SLOT(onDataSourceDescriptionChanged()));

	// Setup new data source.
	int si = selected.parent().row();
	int di = selected.row();
	AMDataSource* dataSource = model_->dataSourceAt(si, di);
	if(!dataSource)
		return;

	connect(dataSource->signalSource(), SIGNAL(infoChanged()), this, SLOT(onDataSourceDescriptionChanged()));

	nameEdit_->setText(dataSource->name());
	descriptionEdit_->setText(dataSource->description());
	descriptionEdit_->setReadOnly(false);

	installDetailEditor(dataSource->createEditorWidget());

	// Set the new selected data source as the exclusive view preference.
	model_->setExclusiveDataSourceByName(dataSource->name());
}
// responds to GUI events
void AM2DSummingABEditor::onSumAxisControlChanged(int newSumAxis) {

	if(newSumAxis == analysisBlock_->sumAxis())
		return;

	// adjust the maximums for the ranges

	AMDataSource* inputSource;
	if(analysisBlock_->inputDataSourceCount() > 0 && (inputSource=analysisBlock_->inputDataSourceAt(0))) {

		int newRangeMax = inputSource->size(newSumAxis)-1;
		rangeMinControl_->setMaximum(newRangeMax);
		rangeMaxControl_->setMaximum(newRangeMax);
	}

	analysisBlock_->setSumAxis(newSumAxis);

	placeRangeRectangle();
}
void AMExternalScanDataSourceAB::copyAxisValues(int dataSourceIndex)
{
	AMDataSource* ds = scan_->dataSourceAt(dataSourceIndex);
	const AMnDIndex size = ds->size();

	axisValues_.clear();

	for(int mu=0; mu<size.rank(); mu++) {	// for each axis
		QVector<AMNumber> av;

		if(!axes_.at(mu).isUniform) {
			int axisLength = size.at(mu);
			for(int i=0; i<axisLength; i++)	// copy all the axis values
				av << axisValue(mu, i);
		}

		axisValues_ << av;
	}
}
Exemple #14
0
AMnDIndex AM2DScanView::getIndex(const QPointF &point) const
{
	int x = -1;
	int y = -1;
	AMDataSource *datasource = currentScan_->dataSourceAt(currentScan_->indexOfDataSource(scansModel_->exclusiveDataSourceName()));

	// This assumes 2D maps where the size is greater than 1x1, 1xN, or Nx1.
	double delX = (double(datasource->axisValue(0, 1)) - double(datasource->axisValue(0, 0)))/2;
	double delY = (double(datasource->axisValue(1, 1)) - double(datasource->axisValue(1, 0)))/2;

	for (int i = 0; i < currentScan_->scanSize(0); i++)
		if (fabs(point.x() - double(datasource->axisValue(0, i))) < delX)
			x = i;

	for (int i = 0; i < currentScan_->scanSize(1); i++)
		if (fabs(point.y() - double(datasource->axisValue(1, i))) < delY)
			y = i;

	return AMnDIndex(x, y);
}
Exemple #15
0
bool AMAnalysisBlock::setInputDataSources(const QList<AMDataSource*>& dataSources) {
	// if a non-empty set of data sources has been provided, and they are not acceptable, return false.  (An empty list must always be acceptable)
	if(!dataSources.isEmpty() && !areInputDataSourcesAcceptable(dataSources)) {
		AMErrorMon::report(AMErrorReport(this, AMErrorReport::Alert, -98, QString("There was an error connecting the input data sources to this analysis component '%1: %2'. The data sources provided weren't acceptable. This can happen if they have the wrong dimension, don't provide enough data, etc.").arg(name()).arg(description())));
		return false;
	}

	for(int i=0; i<inputDataSourceCount(); i++) {
		AMDataSource* oldSource = inputDataSourceAt(i);
		disconnect(oldSource->signalSource(), SIGNAL(deleted(void*)), this, SLOT(onInputSourceDeleted(void*)));
		oldSource->deregisterObserver(this);
	}

	for(int i=0; i<dataSources.count(); i++) {
		AMDataSource* newSource = dataSources.at(i);
		connect(newSource->signalSource(), SIGNAL(deleted(void*)), this, SLOT(onInputSourceDeleted(void*)));
		dataSources.at(i)->registerObserver(this);
	}

	setInputDataSourcesImplementation(dataSources);

	emit inputSourcesChanged();
	return true;
}
void AM3DNormalizationABEditor::populateComboBox()
{
	AMDataSource *tempSource = 0;
	int inputCount = analysisBlock_->inputDataSourceCount();

	for (int i = 0; i < inputCount; i++){

		tempSource = analysisBlock_->inputDataSourceAt(i);

		if (analysisBlock_->name() != tempSource->name()){

			dataNames_->addItem(tempSource->description(), tempSource->name());
			normalizationNames_->addItem(tempSource->description(), tempSource->name());
		}
	}
}
void REIXSAppController::onScanAddedToEditor(AMGenericScanEditor *editor, AMScan *scan)
{
	QString exclusiveName = QString();

	for (int i = 0, count = scan->analyzedDataSourceCount(); i < count && exclusiveName.isNull(); i++){

		AMDataSource *source = scan->analyzedDataSources()->at(i);

		if (source->name().contains("TEYNorm") && !source->hiddenFromUsers())
			exclusiveName = source->name();

		if (source->name().contains("xesSpectrum") && !source->hiddenFromUsers())
			exclusiveName = source->name();
	}

	if (!exclusiveName.isNull())
		editor->setExclusiveDataSourceByName(exclusiveName);

	else if (editor->scanAt(0)->analyzedDataSourceCount())
		editor->setExclusiveDataSourceByName(editor->scanAt(0)->analyzedDataSources()->at(editor->scanAt(0)->analyzedDataSourceCount()-1)->name());
}
bool AMExporter2DAscii::writeSeparateFiles(const QString &destinationFolderPath)
{
	if (option_->higherDimensionsInRows()){

		for (int s = 0, sSize = separateFileDataSources_.size(); s < sSize; s++) {

			setCurrentDataSource(separateFileDataSources_.at(s));	// sets currentDataSourceIndex_
			AMDataSource* source = currentScan_->dataSourceAt(currentDataSourceIndex_);

			QFile output;
			QString separateFileName = parseKeywordString( destinationFolderPath % "/" % option_->separateSectionFileName() );
			separateFileName = removeNonPrintableCharacters(separateFileName);

			if(!openFile(&output, separateFileName)) {
				AMErrorMon::report(AMErrorReport(this, AMErrorReport::Alert, -4, "Export failed (partially): You selected to create separate files for certain data sets. Could not open the file '" % separateFileName % "' for writing.  Check that you have permission to save files there, and that a file with that name doesn't already exists."));
				return false;
			}

			int spectraSize = source->size(2);
			QString columnDelimiter = option_->columnDelimiter();
			QString newLineDelimiter = option_->newlineDelimiter();
			QTextStream out(&output);
			int yRange = yRange_ == -1 ? currentScan_->scanSize(1) : (yRange_-1);
			int xRange = currentScan_->scanSize(0);

			for (int y = 0; y < yRange; y++){

				for (int x = 0; x < xRange; x++){

					QVector<double> data(spectraSize);
					source->values(AMnDIndex(x, y, 0), AMnDIndex(x, y, spectraSize-1), data.data());

					for (int i = 0; i < spectraSize; i++)
						out << data.at(i) << columnDelimiter;

					out << newLineDelimiter;
				}
			}

			if (yRange_ != -1 && xIndex_ != -1){

				for (int i = 0; i < xIndex_; i++){

					QVector<double> data(spectraSize);
					source->values(AMnDIndex(i, yRange_-1, 0), AMnDIndex(i, yRange_-1, spectraSize-1), data.data());

					for (int i = 0; i < spectraSize; i++)
						out << data.at(i) << columnDelimiter;

					out << newLineDelimiter;
				}

				out << newLineDelimiter;
			}

			output.close();
		}
	}

	else{

		for (int s = 0, sSize = separateFileDataSources_.size(); s < sSize; s++) {

			setCurrentDataSource(separateFileDataSources_.at(s));	// sets currentDataSourceIndex_
			AMDataSource* source = currentScan_->dataSourceAt(currentDataSourceIndex_);

			QFile output;
			QString separateFileName = parseKeywordString( destinationFolderPath % "/" % option_->separateSectionFileName() );
			separateFileName = removeNonPrintableCharacters(separateFileName);

			if(!openFile(&output, separateFileName)) {
				AMErrorMon::report(AMErrorReport(this, AMErrorReport::Alert, -4, "Export failed (partially): You selected to create separate files for certain data sets. Could not open the file '" % separateFileName % "' for writing.  Check that you have permission to save files there, and that a file with that name doesn't already exists."));
				return false;
			}

			int spectraSize = source->size(2);
			QString columnDelimiter = option_->columnDelimiter();
			QString newLineDelimiter = option_->newlineDelimiter();
			QTextStream out(&output);
			int yRange = yRange_ == -1 ? currentScan_->scanSize(1) : (yRange_-1);
			int xRange = currentScan_->scanSize(0);

			for (int i = 0; i < spectraSize; i++){

				for (int y = 0; y < yRange; y++)
					for (int x = 0; x < xRange; x++)
						out << double(source->value(AMnDIndex(x, y, i))) << columnDelimiter;

				if (yRange_ != -1 && xIndex_ != -1){

					for (int x = 0; x < xIndex_; x++)
						out << double(source->value(AMnDIndex(x, yRange_-1, i))) << columnDelimiter;
				}

				out << newLineDelimiter;
			}

			output.close();
		}
	}

	return true;
}
Exemple #19
0
void AMExporterGeneralAscii::writeSeparateSections()
{
	QTextStream ts(file_);

	for(int s=0; s<separateSectionDataSources_.count(); s++) {

		ts << option_->newlineDelimiter();

		setCurrentDataSource(separateSectionDataSources_.at(s));	// sets currentDataSourceIndex_
		AMDataSource* ds = currentScan_->dataSourceAt(currentDataSourceIndex_);

		// section header?
		if(option_->sectionHeaderIncluded()) {
			ts << parseKeywordString(option_->sectionHeader());
			ts << option_->newlineDelimiter();
		}

		// column header?
		if(option_->columnHeaderIncluded()) {
			// 1D data sources:
			if(ds->rank() == 0) {
				ts << parseKeywordString(option_->columnHeader()) << option_->columnDelimiter();
			}
			else if(ds->rank() == 1) {
				if(separateSectionIncludeX_.at(s))
					ts << parseKeywordString(option_->columnHeader()) << ".X" << option_->columnDelimiter();
				ts << parseKeywordString(option_->columnHeader()) << option_->columnDelimiter();
			}
			else if(ds->rank() == 2) {	// 2D
				if(separateSectionIncludeX_.at(s))
					ts << parseKeywordString(option_->columnHeader()) << ".X" << option_->columnDelimiter();
				// need a loop over the second axis columns
				for(int cc=0; cc<ds->size(1); cc++) {
					setCurrentColumnIndex(cc);
					ts << parseKeywordString(option_->columnHeader()) << "[" << ds->axisValue(1, cc).toString() << ds->axisInfoAt(1).units << "]" << option_->columnDelimiter();
				}
			}
			ts << option_->newlineDelimiter() << option_->columnHeaderDelimiter() << option_->newlineDelimiter();
		}

		// table
		switch(ds->rank()) {
		case 0:
			ts << ds->value(AMnDIndex()).toString() << option_->columnDelimiter() << option_->newlineDelimiter();
			break;
		case 1: {
			int maxTableRows = ds->size(0);
			for(int r=0; r<maxTableRows; r++) {
				if(separateSectionIncludeX_.at(s)) {
					ts << ds->axisValue(0,r).toString() << option_->columnDelimiter();
				}
				ts << ds->value(r).toString() << option_->columnDelimiter() << option_->newlineDelimiter();
			}
		}
		break;
		case 2: {
			int maxTableRows = ds->size(0);
			for(int r=0; r<maxTableRows; r++) {
				if(separateSectionIncludeX_.at(s))
					ts << ds->axisValue(0,r).toString() << option_->columnDelimiter();
				// need a loop over the second axis columns
				for(int cc=0; cc<ds->size(1); cc++) {
					ts << ds->value(AMnDIndex(r,cc)).toString() << option_->columnDelimiter();
				}
				ts << option_->newlineDelimiter();
			}
		}
		break;
		default:
			/// \todo Implement 3D
			break;
		}
	}
}
void AMDataSourcesEditor::onNewDataSourceNamed() {

	if(!editingNewDataSourceName_)
		return;

	editingNewDataSourceName_ = false;
	QString chName = nameEdit_->text();
	disconnect(nameEdit_, SIGNAL(editingFinished()), this, SLOT(onNewDataSourceNamed()));
	nameEdit_->clearFocus();
	nameEdit_->setReadOnly(true);


	int si = currentScanIndex();
	if(si < 0 || si >= model_->scanCount()) {
		// this should have never happened. How did we get here? You shouldn't have been able to press the addNewChannel button without a current scan.
		return;
	}

	if(chName.isEmpty())
		return;


	if(model_->scanAt(si)->indexOfDataSource(chName) != -1) {
		AMErrorMon::report(AMErrorReport(this, AMErrorReport::Alert, -1, QString("Couldn't create a new data source with the name \"%1\". Make sure to choose a name that doesn't exist already in this scan.").arg(chName)));
		scanSetView_->setCurrentIndex(scanSetView_->currentIndex());
		return;
	}

	AMScan* scan = model_->scanAt(si);
	QList<AMDataSource*> singleDimDataSources;
	QList<AMDataSource *> twoDimDataSources;
	QList<AMDataSource *> threeDimDataSources;
	AMAnalysisBlock *newAnalysisBlock = 0;
	AMDataSource *tempSource = 0;

	// find out all the available 1D and 2D data sources, to use for inputs on this new data source.
	/// \todo Currently this only provides access to the raw data sources, until we can figure out a way to detect or work-around the circular reference problem if analyzed data sources could be used as input.
	/// \note DH: I have changed this to use all of the data sources.  There currently is still no work-around for the circular reference problem.  We are just going to have to be careful about using this.

	for(int i=0; i<scan->dataSourceCount(); i++){

		tempSource = scan->dataSourceAt(i);

		if(tempSource->rank() == 1)
			singleDimDataSources << tempSource;

		else if(tempSource->rank() == 2)
			twoDimDataSources << tempSource;

		else if (tempSource->rank() == 3)
			threeDimDataSources << tempSource;
	}

	newAnalysisBlock = qobject_cast<AMAnalysisBlock *>(AMDbObjectSupport::s()->objectInfoForClass(nameOfAnalysisBlockToBeAdded_)->metaObject->newInstance(Q_ARG(QString, chName)));

	// This should always happen.  But just to be safe.
	if (newAnalysisBlock){

		if (newAnalysisBlock->desiredInputRank() == 1)
			newAnalysisBlock->setInputDataSources(singleDimDataSources);

		else if (newAnalysisBlock->desiredInputRank() == 2)
			newAnalysisBlock->setInputDataSources(twoDimDataSources);

		else if (newAnalysisBlock->desiredInputRank() == 3)
			newAnalysisBlock->setInputDataSources(threeDimDataSources);

		scan->addAnalyzedDataSource(newAnalysisBlock);
	}

	int di = scan->dataSourceCount()-1;
	scanSetView_->setCurrentIndex(model_->indexForDataSource(si, di));
		// this should automatically create a new detail editor for this new scan.
}
void AMExporter2DAscii::writeMainTable()
{
	QTextStream ts(file_);

	// 1. Column header.
	if(option_->columnHeaderIncluded()) {

		ts << "# ";

		for(int c=0; c<mainTableDataSources_.count(); c++) {

			setCurrentDataSource(mainTableDataSources_.at(c));

			if(mainTableIncludeX_.at(c))
				ts << currentScan_->rawData()->scanAxisAt(0).name << option_->columnDelimiter() << currentScan_->rawData()->scanAxisAt(1).name << option_->columnDelimiter();

			ts << parseKeywordString(option_->columnHeader()) << option_->columnDelimiter();
		}
	}

	ts << option_->newlineDelimiter() << option_->columnHeaderDelimiter() << option_->newlineDelimiter();

	// 2. rows
	int yRange = yRange_ == -1 ? currentScan_->scanSize(1) : (yRange_-1);
	int xRange = currentScan_->scanSize(0);

	for(int y = 0; y < yRange; y++) {

		for (int x = 0; x < xRange; x++){

			// over rows within columns
			for(int c=0; c<mainTableDataSources_.count(); c++) {
				setCurrentDataSource(mainTableDataSources_.at(c));
				AMDataSource* ds = currentScan_->dataSourceAt(currentDataSourceIndex_);

				// print x and y column?
				if(mainTableIncludeX_.at(c)) {

					ts << ds->axisValue(0, x).toString();
					ts << option_->columnDelimiter();
					ts << ds->axisValue(1, y).toString();
					ts << option_->columnDelimiter();
				}

				ts << ds->value(AMnDIndex(x, y)).toString();

				ts << option_->columnDelimiter();
			}

			ts << option_->newlineDelimiter();
		}
	}

	if (yRange_ != -1 && xIndex_ != -1){

		for (int i = 0; i < xIndex_; i++){

			// over rows within columns
			for(int c=0; c<mainTableDataSources_.count(); c++) {
				setCurrentDataSource(mainTableDataSources_.at(c));
				AMDataSource* ds = currentScan_->dataSourceAt(currentDataSourceIndex_);

				// print x and y column?
				if(mainTableIncludeX_.at(c)) {

					ts << ds->axisValue(0,i).toString();
					ts << option_->columnDelimiter();
					ts << ds->axisValue(1, yRange_-1).toString();
					ts << option_->columnDelimiter();
				}

				ts << ds->value(AMnDIndex(i, yRange_-1)).toString();

				ts << option_->columnDelimiter();
			}

			ts << option_->newlineDelimiter();
		}
	}

	ts << option_->newlineDelimiter();
}
Exemple #22
0
bool AMExporterGeneralAscii::prepareDataSources() {

	mainTableDataSources_.clear();
	mainTableIncludeX_.clear();
	separateSectionDataSources_.clear();
	separateSectionIncludeX_.clear();
	separateFileDataSources_.clear();
	separateFileIncludeX_.clear();

	if(option_->includeAllDataSources() && !option_->firstColumnOnly()) {
		// assumptions: 1D goes in main table. 0D, 2D and higher goes in separate section.
		for(int i=0; i<currentScan_->dataSourceCount(); i++) {
			switch(currentScan_->dataSourceAt(i)->rank()) {
			case 0:
				separateSectionDataSources_ << i;
				separateSectionIncludeX_ << false;	// default false for 0D (scalar point) data
				break;
			case 1:
				mainTableDataSources_ << i;
				mainTableIncludeX_ << true;
				break;
			default:

				if (option_->includeHigherDimensionSources()){

					if (option_->separateHigherDimensionalSources()){

						separateFileDataSources_ << i;
						separateFileIncludeX_ << false;
					}
					else{

						separateSectionDataSources_ << i;
						separateSectionIncludeX_ << true;
					}
				}
				break;
			}
		}
	}

	else if (option_->includeAllDataSources() && option_->firstColumnOnly()){

		// assumptions: 1D goes in main table. 0D, 2D and higher goes in separate section.
		for(int i=0; i<currentScan_->dataSourceCount(); i++) {
			switch(currentScan_->dataSourceAt(i)->rank()) {
			case 0:
				separateSectionDataSources_ << i;
				separateSectionIncludeX_ << false;	// default false for 0D (scalar point) data
				break;
			case 1:
				mainTableDataSources_ << i;
				mainTableIncludeX_ << (i == 0 ? true : false);
				break;
			default:

				if (option_->includeHigherDimensionSources()){

					if (option_->separateHigherDimensionalSources()){

						separateFileDataSources_ << i;
						separateFileIncludeX_ << false;
					}
					else{

						separateSectionDataSources_ << i;
						separateSectionIncludeX_ << true;
					}
				}

				break;
			}
		}
	}

	// otherwise look at what the user specified
	else {
		QStringList dataSources = option_->dataSources();
		for(int i=0; i<dataSources.count(); i++) {	// i iterates through data sources in the option: these are ones that the user requested to include

			int dataSourceIndex = currentScan_->indexOfDataSource(dataSources.at(i));

			if(dataSourceIndex == -1) {	// missing data source?
				if(option_->isDataSourceRequired(i)) {
					AMErrorMon::report(AMErrorReport(this,
													 AMErrorReport::Alert,
													 -3,
													 "Export failed: The scan '" % currentScan_->fullName() % "' does not contain the required data set '" % dataSources.at(i) % "'."));
					return false;
				}
				else
					continue;
			}

			AMDataSource* dataSource = currentScan_->dataSourceAt(dataSourceIndex);

			switch(option_->dataSourceOrganizeMode(i)) {
			case  AMExporterOptionGeneralAscii::CombineInColumnsMode:
				if(dataSource->rank() > 0 && dataSource->rank() < 3) {
					mainTableDataSources_ << dataSourceIndex;
					mainTableIncludeX_ << !option_->isDataSourceAxisValueColumnOmitted(i);
				}
				else {
					separateSectionDataSources_ << dataSourceIndex;	// only 1D and 2D data allowed in the main table.  I don't know how else to break it to you...
					separateSectionIncludeX_ << !option_->isDataSourceAxisValueColumnOmitted(i);
					AMErrorMon::report(AMErrorReport(this, AMErrorReport::Alert, 0, "Moving " % QString::number(dataSource->rank()) % "D data to its own section in the exported file.  Only 1D and 2D data is allowed in the main table."));
				}
				break;

			case AMExporterOptionGeneral::SeparateSectionsMode:
				separateSectionDataSources_ << dataSourceIndex;
				separateSectionIncludeX_ << !option_->isDataSourceAxisValueColumnOmitted(i);
				break;
			case AMExporterOptionGeneral::SeparateFilesMode:
				separateFileDataSources_ << dataSourceIndex;
				separateFileIncludeX_ << !option_->isDataSourceAxisValueColumnOmitted(i);
			}
		}
	}

	return true;
}
void AMExporterGeneralAscii::writeSeparateSections()
{
	QTextStream ts(file_);

	if (option_->higherDimensionsInRows()){

		for(int s=0; s<separateSectionDataSources_.count(); s++) {

			ts << option_->newlineDelimiter();

			setCurrentDataSource(separateSectionDataSources_.at(s));	// sets currentDataSourceIndex_
			AMDataSource* ds = currentScan_->dataSourceAt(currentDataSourceIndex_);
			int precision = option_->exportPrecision(ds->name());

			// section header?
			if(option_->sectionHeaderIncluded()) {
				ts << parseKeywordString(option_->sectionHeader());
				ts << option_->newlineDelimiter();
			}

			// column header?
			if(option_->columnHeaderIncluded()) {
				// 1D data sources:
				if(ds->rank() == 0) {
					ts << parseKeywordString(option_->columnHeader()) << option_->columnDelimiter();
				}
				else if(ds->rank() == 1) {
					if(separateSectionIncludeX_.at(s))
						ts << parseKeywordString(option_->columnHeader()) << ".X" << option_->columnDelimiter();
					ts << parseKeywordString(option_->columnHeader()) << option_->columnDelimiter();
				}
				else if(ds->rank() == 2) {	// 2D
					if(separateSectionIncludeX_.at(s))
						ts << parseKeywordString(option_->columnHeader()) << ".X" << option_->columnDelimiter();
					// need a loop over the second axis columns
					for(int cc=0; cc<ds->size(1); cc++) {
						setCurrentColumnIndex(cc);
						ts << parseKeywordString(option_->columnHeader()) << "[" << ds->axisValue(1, cc).toString(precision) << ds->axisInfoAt(1).units << "]" << option_->columnDelimiter();
					}
				}
				ts << option_->newlineDelimiter() << option_->columnHeaderDelimiter() << option_->newlineDelimiter();
			}

			// table
			switch(ds->rank()) {
			case 0:
				ts << ds->value(AMnDIndex()).toString(precision) << option_->columnDelimiter() << option_->newlineDelimiter();
				break;
			case 1: {
				int maxTableRows = ds->size(0);
				for(int r=0; r<maxTableRows; r++) {
					if(separateSectionIncludeX_.at(s)) {
						ts << ds->axisValue(0,r).toString(precision) << option_->columnDelimiter();
					}
					ts << ds->value(r).toString(precision) << option_->columnDelimiter() << option_->newlineDelimiter();
				}
			}
				break;
			case 2: {
				int maxTableRows = ds->size(0);
				for(int r=0; r<maxTableRows; r++) {
					if(separateSectionIncludeX_.at(s))
						ts << ds->axisValue(0,r).toString(precision) << option_->columnDelimiter();
					// need a loop over the second axis columns
					for(int cc=0; cc<ds->size(1); cc++) {
						ts << ds->value(AMnDIndex(r,cc)).toString(precision) << option_->columnDelimiter();
					}
					ts << option_->newlineDelimiter();
				}
			}
				break;
			default:
				/// \todo Implement 3D
				break;
			}
		}
	}

	// For writing out in columns.  Essentially transposing the file.
	else{

		for(int s=0; s<separateSectionDataSources_.count(); s++) {

			setCurrentDataSource(separateSectionDataSources_.at(s));	// sets currentDataSourceIndex_
			AMDataSource* ds = currentScan_->dataSourceAt(currentDataSourceIndex_);
			int precision = option_->exportPrecision(ds->name());

			// section header?
			if(option_->sectionHeaderIncluded()) {
				ts << parseKeywordString(option_->sectionHeader());
				ts << option_->newlineDelimiter();
			}

			// If including the X values.
			if (separateSectionIncludeX_.at(s)){

				switch(ds->rank()){

				case 0:
					break;

				case 1:
				case 2:{

					ts << parseKeywordString(option_->columnHeader()) << ".X" << option_->columnDelimiter();

					int maxTableColumns = ds->size(0);

					for(int column = 0; column < maxTableColumns; column++)
						ts << ds->axisValue(0,column).toString(precision) << option_->columnDelimiter();

					ts << option_->newlineDelimiter();

					break;
				}

				default:
					/// \todo 3D.
					break;
				}
			}

			// Main table with column headers prefacing rows.
			switch (ds->rank()){

			case 0:{

				if(option_->columnHeaderIncluded())
					ts << parseKeywordString(option_->columnHeader()) << option_->columnDelimiter();

				ts << ds->value(AMnDIndex()).toString(precision) << option_->columnDelimiter() << option_->newlineDelimiter();

				break;
			}

			case 1:{

				if (option_->columnHeaderIncluded())
					ts << parseKeywordString(option_->columnHeader()) << option_->columnDelimiter();

				int maxTableColumns = ds->size(0);

				for(int column = 0; column < maxTableColumns; column++)
					ts << ds->value(column).toString(precision) << option_->columnDelimiter();

				ts << option_->newlineDelimiter();

				break;
			}

			case 2:{

				for (int cc = 0; cc < ds->size(1); cc++){

					if (option_->columnHeaderIncluded())
						ts << parseKeywordString(option_->columnHeader()) << "[" << ds->axisValue(1, cc).toString(precision) << ds->axisInfoAt(1).units << "]" << option_->columnDelimiter();

					int maxTableColumns = ds->size(0);

					for (int column = 0; column < maxTableColumns; column++)
						ts << ds->value(AMnDIndex(column, cc)).toString(precision) << option_->columnDelimiter();

					ts << option_->newlineDelimiter();
				}

				break;
			}

			default:
				/// \todo 3D
				break;
			}
		}
	}
}
void AM4DBinningABEditor::updateSeriesData()
{
	AMDataSource *source = analysisBlock_->inputDataSourceAt(0);

	if (source){

		int sumAxis = analysisBlock_->sumAxis();
		int sumAxisSize = source->size(sumAxis);
		QVector<double> xAxis(sumAxisSize);
		QVector<double> yAxis(sumAxisSize, 0);

		for (int i = 0; i < sumAxisSize; i++)
			xAxis[i] = double(source->axisValue(sumAxis, i));

		switch (sumAxis){

		case 0:{

			for (int i = 0, iSize = analysisBlock_->size(0); i < iSize; i++){

				for (int j = 0, jSize = analysisBlock_->size(1); j < jSize; j++){

					for (int k = 0, kSize = analysisBlock_->size(2); k < kSize; k++){

						QVector<double> temp(sumAxisSize);
						source->values(AMnDIndex(0, i, j, k), AMnDIndex(sumAxisSize-1, i, j, k), temp.data());

						for (int l = 0; l < sumAxisSize; l++)
							yAxis[l] += temp.at(l);
					}
				}
			}

			break;
		}

		case 1:{

			for (int i = 0, iSize = analysisBlock_->size(0); i < iSize; i++){

				for (int j = 0, jSize = analysisBlock_->size(1); j < jSize; j++){

					for (int k = 0, kSize = analysisBlock_->size(2); k < kSize; k++){

						QVector<double> temp(sumAxisSize);
						source->values(AMnDIndex(i, 0, j, k), AMnDIndex(i, sumAxisSize-1, j, k), temp.data());

						for (int l = 0; l < sumAxisSize; l++)
							yAxis[l] += temp.at(l);
					}
				}
			}

			break;
		}

		case 2:{

			for (int i = 0, iSize = analysisBlock_->size(0); i < iSize; i++){

				for (int j = 0, jSize = analysisBlock_->size(1); j < jSize; j++){

					for (int k = 0, kSize = analysisBlock_->size(2); k < kSize; k++){

						QVector<double> temp(sumAxisSize);
						source->values(AMnDIndex(i, j, 0, k), AMnDIndex(i, j, sumAxisSize-1, k), temp.data());

						for (int l = 0; l < sumAxisSize; l++)
							yAxis[l] += temp.at(l);
					}
				}
			}

			break;
		}

		case 3:{

			for (int i = 0, iSize = analysisBlock_->size(0); i < iSize; i++){

				for (int j = 0, jSize = analysisBlock_->size(1); j < jSize; j++){

					for (int k = 0, kSize = analysisBlock_->size(2); k < kSize; k++){

						QVector<double> temp(sumAxisSize);
						source->values(AMnDIndex(i, j, k, 0), AMnDIndex(i, j, k, sumAxisSize-1), temp.data());

						for (int l = 0; l < sumAxisSize; l++)
							yAxis[l] += temp.at(l);
					}
				}
			}

			break;
		}
		}

		seriesData_->setValues(xAxis, yAxis);
	}
}
Exemple #25
0
void AMExporterGeneralAscii::writeMainTable()
{
	QTextStream ts(file_);

	// 1. Column header.
	int maxTableRows = 0;
	if(option_->columnHeaderIncluded()) {
		for(int c=0; c<mainTableDataSources_.count(); c++) {
			setCurrentDataSource(mainTableDataSources_.at(c));
			AMDataSource* ds = currentScan_->dataSourceAt(currentDataSourceIndex_);

			if(ds->size(0) > maxTableRows)
				maxTableRows = ds->size(0); // convenient... lets figure this out while we're looping through anyway

			// 1D data sources:
			if(ds->rank() == 1) {
				if(mainTableIncludeX_.at(c))
					ts << parseKeywordString(option_->columnHeader()) << ".X" << option_->columnDelimiter();
				ts << parseKeywordString(option_->columnHeader()) << option_->columnDelimiter();
			}
			else {	// 2D
				if(mainTableIncludeX_.at(c))
					ts << parseKeywordString(option_->columnHeader()) << ".X" << option_->columnDelimiter();
				// need a loop over the second axis columns
				for(int cc=0; cc<ds->size(1); cc++) {
					setCurrentColumnIndex(cc);
					ts << parseKeywordString(option_->columnHeader()) << "[" << ds->axisValue(1, cc).toString() << ds->axisInfoAt(1).units << "]" << option_->columnDelimiter();
				}
			}
		}
		ts << option_->newlineDelimiter() << option_->columnHeaderDelimiter() << option_->newlineDelimiter();
	}


	// 2. rows
	for(int r=0; r<maxTableRows; r++) {

		// over rows within columns
		for(int c=0; c<mainTableDataSources_.count(); c++) {
			setCurrentDataSource(mainTableDataSources_.at(c));
			AMDataSource* ds = currentScan_->dataSourceAt(currentDataSourceIndex_);

			bool doPrint = (ds->size(0) > r);

			// print x column?
			if(mainTableIncludeX_.at(c)) {
				if(doPrint)
					ts << ds->axisValue(0,r).toString();
				ts << option_->columnDelimiter();
			}

			// 1D data sources:
			if(ds->rank() == 1) {
				if(doPrint)
					ts << ds->value(r).toString();
				ts << option_->columnDelimiter();
			}
			else if(ds->rank() == 2) {
				// need a loop over the second axis columns
				for(int cc=0; cc<ds->size(1); cc++) {
					if(doPrint)
						ts << ds->value(AMnDIndex(r,cc)).toString();
					ts << option_->columnDelimiter();
				}
			}
		}
		ts << option_->newlineDelimiter();
	}
}
Exemple #26
0
QVariant AMScanSetModel::data(const QModelIndex & index, int role) const {
	if(!index.isValid())
		return QVariant();

	// scan-level index:
	///////////////////////////
	if(index.internalId() == -1 && index.row() < scans_.count() && index.column() == 0) {
		AMScan* scan = scans_.at(index.row());

		switch(role) {
		case Qt::DisplayRole: {
				QString rv = scan->fullName();
				if(scan->modified())
					rv.append( " (modified)");
				return rv;
			}
			break;
		case Qt::DecorationRole:
			/// \bug this is temporary and meaningless. It's just the color of the first data source in the scan.
			if(scan->dataSourceCount() > 0)
				return sourcePlotSettings_.at(index.row()).at(0).linePen.color();
			else
				return QVariant();
			break;
		case Qt::ToolTipRole:
			return QString("%1, #%2 (sample: %3): %4").arg(scan->name()).arg(scan->number()).arg(scan->sampleName()).arg(AMDateTimeUtils::prettyDateTime(scan->dateTime(), "h:mm:ssap"));
			break;
		case AM::DescriptionRole:
			return QString("%1, on %2").arg(AMDateTimeUtils::prettyDateTime(scan->dateTime())).arg(scan->sampleName());
		case AM::DateTimeRole:
			return scan->dateTime();
		case Qt::CheckStateRole:
			return QVariant();	/// \todo For now... No checking/unchecking scans.
			break;
		case AM::PointerRole:
			return qVariantFromValue(scan);
			break;
		case AM::ModifiedRole:
			return scan->modified();
		case AM::CanCloseRole:	// allows views to show the 'close' button beside each scan, to delete it. Do we want this on?
			return true;
		case AM::NameRole: {
				return scan->fullName();
			}
			break;
		default:
			return QVariant();
			break;
		}
	}


	// data source-level index:
	////////////////////////////
	if(index.internalId() >= 0 && index.internalId() < scans_.count() ) {
		AMScan* scan = scans_.at(index.internalId());

		if(index.row() < scan->dataSourceCount() && index.column() == 0) {
			AMDataSource* dataSource = scan->dataSourceAt(index.row());

			switch(role) {
			case Qt::DisplayRole:
				return QString("%1 (%2)").arg(dataSource->description(), dataSource->name());
				break;
			case Qt::DecorationRole:
				return sourcePlotSettings_.at(index.internalId()).at(index.row()).linePen.color();
				break;
			case Qt::ToolTipRole:
			case AM::NameRole:
				return dataSource->name();
			case AM::DescriptionRole:
				return dataSource->description();
			case AM::DetailedDescriptionRole:
				return QString("%1 (%2) From scan: %3\n%4").arg(dataSource->description(),
																dataSource->name(),
																scan->name(),
																//scan->evaluatedName(),
																dataSource->typeDescription());
				break;
			case Qt::CheckStateRole:	// this controls visibility on plots.
				if(isVisible(index.internalId(), index.row()))
					return Qt::Checked;
				else
					return Qt::Unchecked;
				break;
			case AM::PointerRole:
				return qVariantFromValue(dataSource);
				break;
			case AM::PriorityRole:
				return sourcePlotSettings_.at(index.internalId()).at(index.row()).priority;
				break;
			case AM::CanCloseRole:	// allows views to show the 'close' button beside each scan, to delete it.
				return true;
			case AM::LinePenRole:
				return sourcePlotSettings_.at(index.internalId()).at(index.row()).linePen;
			case AM::RankRole:
				return dataSource->rank();
			case AMScanSetModel::ColorMapRole:
				return qVariantFromValue(sourcePlotSettings_.at(index.internalId()).at(index.row()).colorMap);
			case AMScanSetModel::MarkerColorRole:
				return qVariantFromValue(sourcePlotSettings_.at(index.internalId()).at(index.row()).markerColor);
			case AMScanSetModel::MarkerShapeRole:
				return QVariant(sourcePlotSettings_.at(index.internalId()).at(index.row()).markerShape);
			default:
				return QVariant();
				break;
			}
		}
	}

	return QVariant();
}
void BioXASXASScanActionController::buildScanControllerImplementation()
{
	BioXASBeamline *bioxas = BioXASBeamline::bioXAS();

	// Identify current beamline settings.
	scan_->setScanInitialConditions(bioxas->defaultXASScanControlInfos());

	// Identify exporter option.
	AMExporterOptionXDIFormat *exportXDI = 0;
	if (bioXASConfiguration_) {

		exportXDI = BioXAS::buildStandardXDIFormatExporterOption("BioXAS XAS (XDI Format)", bioXASConfiguration_->edge().split(" ").first(), bioXASConfiguration_->edge().split(" ").last(), true);

		if (exportXDI->id() > 0)
			AMAppControllerSupport::registerClass<BioXASXASScanConfiguration, AMExporterXDIFormat, AMExporterOptionXDIFormat>(exportXDI->id());

		// Clear the option of any previous data sources.

		exportXDI->clearDataSources();
	}

	// Identify and setup the zebra trigger source.
	AMZebraDetectorTriggerSource *zebraTriggerSource = bioxas->zebraTriggerSource();
	if (zebraTriggerSource) {
		zebraTriggerSource->removeAllDetectors();
		zebraTriggerSource->removeAllDetectorManagers();

		if (usingDetector(bioxas->i0Detector()))
			zebraTriggerSource->addDetector(bioxas->i0Detector());

		if (usingDetector(bioxas->i1Detector()))
			zebraTriggerSource->addDetector(bioxas->i1Detector());

		if (usingDetector(bioxas->i2Detector()))
			zebraTriggerSource->addDetector(bioxas->i2Detector());

		if (usingScaler())
			zebraTriggerSource->addDetectorManager(bioxas->scaler());

		AMDetectorSet *geDetectors = bioxas->ge32ElementDetectors();

		for (int i = 0, count = geDetectors->count(); i < count; i++) {
			AMDetector *detector = geDetectors->at(i);

			if (usingDetector(detector)) {
				zebraTriggerSource->addDetector(geDetectors->at(i));
				zebraTriggerSource->addDetectorManager(geDetectors->at(i));
			}
		}
	}

	// Identify data sources for the scaler channels and the scaler dwell time.
	AMDataSource *i0DetectorSource = detectorDataSource(bioxas->i0Detector());
	AMDataSource *i1DetectorSource = detectorDataSource(bioxas->i1Detector());
	AMDataSource *i2DetectorSource = detectorDataSource(bioxas->i2Detector());
	AMDataSource *diodeDetectorSource = detectorDataSource(bioxas->diodeDetector());
	AMDataSource *pipsDetectorSource = detectorDataSource(bioxas->pipsDetector());
	AMDataSource *lytleDetectorSource = detectorDataSource(bioxas->lytleDetector());
	AMDataSource *dwellTimeSource = detectorDataSource(bioxas->scalerDwellTimeDetector());

	// Create analyzed data source for the absorbance.

	AM1DExpressionAB *absorbanceSource = 0;

	if (i0DetectorSource && i1DetectorSource && i2DetectorSource) {
		absorbanceSource = new AM1DExpressionAB("Absorbance");
		absorbanceSource->setDescription("Absorbance");
		absorbanceSource->setInputDataSources(QList<AMDataSource*>() << i0DetectorSource << i1DetectorSource << i2DetectorSource);
		absorbanceSource->setExpression(QString("ln(%1/%2)").arg(i1DetectorSource->name(), i2DetectorSource->name()));

		scan_->addAnalyzedDataSource(absorbanceSource, true, false);
	}

	// Create analyzed data source for the derivative of the absorbance.

	AM1DDerivativeAB *derivAbsorbanceSource = 0;

	if (absorbanceSource) {
		derivAbsorbanceSource = new AM1DDerivativeAB("DerivAbsorbance");
		derivAbsorbanceSource->setInputDataSources(QList<AMDataSource*>() << absorbanceSource);

		scan_->addAnalyzedDataSource(derivAbsorbanceSource, true, false);
	}

	// Create analyzed data sources for the dark current corrected scaler channel detectors.

	AM1DDarkCurrentCorrectionAB *i0CorrectedDetectorSource = 0;

	if (dwellTimeSource && i0DetectorSource && exportXDI) {
		i0CorrectedDetectorSource = new AM1DDarkCurrentCorrectionAB(QString("%1_DarkCorrect").arg(i0DetectorSource->name()));
		i0CorrectedDetectorSource->setDescription(QString("%1 Dark Current Corrected").arg(i0DetectorSource->name()));
		i0CorrectedDetectorSource->setDataName(i0DetectorSource->name());
		i0CorrectedDetectorSource->setDwellTimeName(dwellTimeSource->name());
		i0CorrectedDetectorSource->setDarkCurrent(bioxas->exposedDetectorByName(i0DetectorSource->name())->darkCurrentValue());
		i0CorrectedDetectorSource->setInputDataSources(QList<AMDataSource*>() << i0DetectorSource << dwellTimeSource);
		i0CorrectedDetectorSource->setTimeUnitMultiplier(0.001);

		connect( bioxas->i0Detector(), SIGNAL(darkCurrentValueChanged(double)), i0CorrectedDetectorSource, SLOT(setDarkCurrent(double)) );

		scan_->addAnalyzedDataSource(i0CorrectedDetectorSource, true, false);

		exportXDI->addDataSource(i0CorrectedDetectorSource->name(), false);
	}
Exemple #28
0
void AM3dDataSourceView::updatePlotFromDataSource()
{
	// Know from previously that the rank of this data source is 2.

	// Or the scan is 0, which means we have no data to show.
	if(scan_ == 0) {
		surfacePlot_->loadFromData(0,0,0);
		return;
	}


	AMDataSource* ds = scan_->dataSourceAt(dataSourceIndex_);

	double minZ = 0, maxZ = 1;
	int sizeX = ds->size(0);
	int sizeY = ds->size(1);

	bool uniformAxisScales = ds->axisInfoAt(0).isUniform && ds->axisInfoAt(1).isUniform;

	if(uniformAxisScales) {
		qDebug() << "Uniform axis scales. Using simplest (uniform) grid filling";
		double** zValues = new2dArray<double>(sizeX, sizeY);

		if(logScaleEnabled_) {
			if(sizeX > 0 && sizeY > 0)
				minZ = maxZ = log(qMax(logMin_,(double)ds->value(AMnDIndex(0,0))));

			for(int i=0; i<sizeX; i++)
				for(int j=0; j<sizeY; j++) {
					double zValue = log(qMax(logMin_,(double)ds->value(AMnDIndex(i,j))));
					minZ = qMin(minZ, zValue);
					maxZ = qMax(maxZ, zValue);
					zValues[i][j] = zValue;
				}
		}
		else {
			if(sizeX > 0 && sizeY > 0)
				minZ = maxZ = ds->value(AMnDIndex(0,0));

			for(int i=0; i<sizeX; i++)
				for(int j=0; j<sizeY; j++) {
					double zValue = ds->value(AMnDIndex(i,j));
					minZ = qMin(minZ, zValue);
					maxZ = qMax(maxZ, zValue);
					zValues[i][j] = zValue;
				}
		}

		surfacePlot_->loadFromData(zValues,
								   sizeX,
								   sizeY,
								   ds->axisValue(0,0),
								   ds->axisValue(0,sizeX-1),
								   ds->axisValue(1,0),
								   ds->axisValue(1,sizeY-1));

		// called from loadFromData(): surfacePlot_->updateData();
		// not necessary?: surfacePlot_->updateGL();

		delete2dArray(zValues);
	}
	else {	// non-uniform axis scale grid
		qDebug() << "Non-uniform axis scale. Using irregular grid";

		Qwt3D::Triple** gridValues = new2dArray<Qwt3D::Triple>(sizeX, sizeY);

		if(logScaleEnabled_) {
			if(sizeX >0 && sizeY > 0)
				minZ = maxZ = log(qMax(logMin_,(double)ds->value(AMnDIndex(0,0))));

			for(int i=0; i<sizeX; i++) {
				double xAxisValue = ds->axisValue(0,i);
				for(int j=0; j<sizeY; j++) {
					double zValue = log(qMax(logMin_,(double)ds->value(AMnDIndex(i,j))));
					minZ = qMin(minZ, zValue);
					maxZ = qMax(maxZ, zValue);
					gridValues[i][j] = Qwt3D::Triple(xAxisValue, ds->axisValue(1,j), zValue);
				}
			}
		}
		else {
			if(sizeX >0 && sizeY > 0)
				minZ = maxZ = ds->value(AMnDIndex(0,0));

			for(int i=0; i<sizeX; i++) {
				double xAxisValue = ds->axisValue(0,i);
				for(int j=0; j<sizeY; j++) {
					double zValue = ds->value(AMnDIndex(i,j));
					minZ = qMin(minZ, zValue);
					maxZ = qMax(maxZ, zValue);
					gridValues[i][j] = Qwt3D::Triple(xAxisValue, ds->axisValue(1,j), zValue);
				}
			}
		}

		surfacePlot_->loadFromData(gridValues, sizeX, sizeY);
		delete2dArray(gridValues);
	}

	// doesnt realy do anyting: surfacePlot_->coordinates()->setAutoScale(true);

	double zRange = maxZ - minZ;
	double xRange = (double)ds->axisValue(0, sizeX-1) - (double)ds->axisValue(0,0);
	double yRange = (double)ds->axisValue(1, sizeY-1) - (double)ds->axisValue(1,0);

	surfacePlot_->setScale(100*zRange/xRange, 100*zRange/yRange, 100);

	double drad = (surfacePlot_->hull().maxVertex-surfacePlot_->hull().minVertex).length();
	drad *= 30/20.;
	surfacePlot_->setLightShift(drad,drad,drad);
	surfacePlot_->setLightRotation(90,0,0);

	AMAxisInfo xInfo = ds->axisInfoAt(0);
	AMAxisInfo yInfo = ds->axisInfoAt(1);

	QString xLabel = xInfo.description % " (" % xInfo.units % ")";
	QString yLabel = yInfo.description % " (" % yInfo.units % ")";
	QString zLabel = ds->description();

	surfacePlot_->coordinates()->axes[Qwt3D::X1].setLabelString(xLabel);
	surfacePlot_->coordinates()->axes[Qwt3D::X2].setLabelString(xLabel);
	surfacePlot_->coordinates()->axes[Qwt3D::X3].setLabelString(xLabel);
	surfacePlot_->coordinates()->axes[Qwt3D::X4].setLabelString(xLabel);

	surfacePlot_->coordinates()->axes[Qwt3D::Y1].setLabelString(yLabel);
	surfacePlot_->coordinates()->axes[Qwt3D::Y2].setLabelString(yLabel);
	surfacePlot_->coordinates()->axes[Qwt3D::Y3].setLabelString(yLabel);
	surfacePlot_->coordinates()->axes[Qwt3D::Y4].setLabelString(yLabel);

	surfacePlot_->coordinates()->axes[Qwt3D::Z1].setLabelString(zLabel);
	surfacePlot_->coordinates()->axes[Qwt3D::Z2].setLabelString(zLabel);
	surfacePlot_->coordinates()->axes[Qwt3D::Z3].setLabelString(zLabel);
	surfacePlot_->coordinates()->axes[Qwt3D::Z4].setLabelString(zLabel);
}
void VESPERSExporterSMAK::writeMainTable()
{
	QTextStream ts(file_);

	// 1. Column header.
	if(option_->columnHeaderIncluded()) {

		ts << "# ";

		for(int c=0; c<mainTableDataSources_.count(); c++) {

			setCurrentDataSource(mainTableDataSources_.at(c));

			if(mainTableIncludeX_.at(c))
				ts << "H" << option_->columnDelimiter() << "V" << option_->columnDelimiter();

			ts << parseKeywordString(option_->columnHeader()) << option_->columnDelimiter();
		}
	}

	ts << option_->newlineDelimiter() << option_->columnHeaderDelimiter() << option_->newlineDelimiter();

	// 2. rows
	VESPERS2DScanConfiguration *config = qobject_cast<VESPERS2DScanConfiguration *>(const_cast<AMScanConfiguration *>(currentScan_->scanConfiguration()));
	if (!config)
		return;

	QString suffix;

	if (config->ccdDetector().testFlag(VESPERS::Roper))
		suffix = "spe";

	else if (config->ccdDetector().testFlag(VESPERS::Mar))
		suffix = "tif";

	else if (config->ccdDetector().testFlag(VESPERS::Pilatus))
		suffix = "tif";

	QString ccdFileName = config->ccdFileName();
	int yRange = yRange_ == -1 ? currentScan_->scanSize(1) : (yRange_-1);
	int xRange = currentScan_->scanSize(0);

	for(int y = 0; y < yRange; y++) {

		for (int x = 0; x < xRange; x++){

			// over rows within columns
			for(int c=0; c<mainTableDataSources_.count(); c++) {

				setCurrentDataSource(mainTableDataSources_.at(c));
				AMDataSource* ds = currentScan_->dataSourceAt(currentDataSourceIndex_);
				int precision = option_->exportPrecision(ds->name());

				// print x and y column?
				if(mainTableIncludeX_.at(c)) {

					ts << ds->axisValue(0,x).toString(precision);
					ts << option_->columnDelimiter();
					ts << ds->axisValue(1, y).toString(precision);
					ts << option_->columnDelimiter();
				}

				if(ds->name().contains("FileNumber"))
					ts << QString("%1_%2.%3").arg(ccdFileName).arg(int(ds->value(AMnDIndex(x, y)))-1).arg(suffix);	// The -1 is because the value stored here is the NEXT number in the scan.  Purely a nomenclature setup from the EPICS interface.

				else
					ts << ds->value(AMnDIndex(x, y)).toString(precision);

				ts << option_->columnDelimiter();
			}

			ts << option_->newlineDelimiter();
		}
	}

	if (yRange_ != -1 && xIndex_ != -1){

		for (int x = 0; x < xIndex_; x++){

			// over rows within columns
			for(int c=0; c<mainTableDataSources_.count(); c++) {

				setCurrentDataSource(mainTableDataSources_.at(c));
				AMDataSource* ds = currentScan_->dataSourceAt(currentDataSourceIndex_);
				int precision = option_->exportPrecision(ds->name());

				// print x and y column?
				if(mainTableIncludeX_.at(c)) {

					ts << ds->axisValue(0,x).toString(precision);
					ts << option_->columnDelimiter();
					ts << ds->axisValue(1, yRange_-1).toString(precision);
					ts << option_->columnDelimiter();
				}

				if(ds->name().contains("FileNumber"))
					ts << QString("%1_%2.%3").arg(ccdFileName).arg(int(ds->value(AMnDIndex(x, yRange_-1)))-1).arg(suffix);	// The -1 is because the value stored here is the NEXT number in the scan.  Purely a nomenclature setup from the EPICS interface.

				else
					ts << ds->value(AMnDIndex(x, yRange_-1)).toString(precision);

				ts << option_->columnDelimiter();
			}


			ts << option_->newlineDelimiter();
		}
	}


	ts << option_->newlineDelimiter();
}
Exemple #30
0
bool AMExporterGeneralAscii::writeSeparateFiles(const QString& destinationFolderPath)
{
	for(int s=0; s<separateFileDataSources_.count(); s++) {

		setCurrentDataSource(separateFileDataSources_.at(s));	// sets currentDataSourceIndex_
		AMDataSource* ds = currentScan_->dataSourceAt(currentDataSourceIndex_);

		QFile file;
		QString separateFileName = parseKeywordString( destinationFolderPath % "/" % option_->separateSectionFileName() );

		if(!openFile(&file, separateFileName)) {
			AMErrorMon::report(AMErrorReport(this, AMErrorReport::Alert, -4, "Export failed (partially): You selected to create separate files for certain data sets. Could not open the file '" % separateFileName % "' for writing.  Check that you have permission to save files there, and that a file with that name doesn't already exists."));
			return false;
		}

		QTextStream ts(&file);

		// section header?
		if(option_->sectionHeaderIncluded()) {
			ts << parseKeywordString(option_->sectionHeader());
			ts << option_->newlineDelimiter();
		}

		// column header?
		if(option_->columnHeaderIncluded()) {
			// 1D data sources:
			if(ds->rank() == 0) {
				ts << parseKeywordString(option_->columnHeader()) << option_->columnDelimiter();
			}
			else if(ds->rank() == 1) {
				if(separateFileIncludeX_.at(s))
					ts << parseKeywordString(option_->columnHeader()) << ".X" << option_->columnDelimiter();
				ts << parseKeywordString(option_->columnHeader()) << option_->columnDelimiter();
			}
			else if(ds->rank() == 2) {	// 2D
				if(separateFileIncludeX_.at(s))
					ts << parseKeywordString(option_->columnHeader()) << ".X" << option_->columnDelimiter();
				// need a loop over the second axis columns
				for(int cc=0; cc<ds->size(1); cc++) {
					setCurrentColumnIndex(cc);
					ts << parseKeywordString(option_->columnHeader()) << "[" << ds->axisValue(1, cc).toString() << ds->axisInfoAt(1).units << "]" << option_->columnDelimiter();
				}
			}
			ts << option_->newlineDelimiter() << option_->columnHeaderDelimiter() << option_->newlineDelimiter();
		}

		// table
		switch(ds->rank()) {
		case 0:
			ts << ds->value(AMnDIndex()).toString() << option_->columnDelimiter() << option_->newlineDelimiter();
			break;
		case 1: {
			int maxTableRows = ds->size(0);
			for(int r=0; r<maxTableRows; r++) {
				if(separateFileIncludeX_.at(s)) {
					ts << ds->axisValue(0,r).toString() << option_->columnDelimiter();
				}
				ts << ds->value(r).toString() << option_->columnDelimiter() << option_->newlineDelimiter();
			}
		}
		break;
		case 2: {
			int maxTableRows = ds->size(0);
			for(int r=0; r<maxTableRows; r++) {
				if(separateFileIncludeX_.at(s))
					ts << ds->axisValue(0,r).toString() << option_->columnDelimiter();
				// need a loop over the second axis columns
				for(int cc=0; cc<ds->size(1); cc++) {
					ts << ds->value(AMnDIndex(r,cc)).toString() << option_->columnDelimiter();
				}
				ts << option_->newlineDelimiter();
			}
		}
		break;
		default:
			/// \todo Implement 3D
			break;
		}
	}

	return true;
}