AM1DRunningAverageFilterAB::AM1DRunningAverageFilterAB(int filterSize, const QString &outputName, QObject *parent) :
	AMStandardAnalysisBlock(outputName, parent)
{
	inputSource_ = 0;
	filterSize_ = filterSize;

	axes_ << AMAxisInfo("invalid", 0, "No input data");
	setState(AMDataSource::InvalidFlag);
}
Esempio n. 2
0
// Returns a bunch of information about a particular axis.
AMAxisInfo AM1DExpressionAB::axisInfoAt(int axisNumber) const {
	if(axisNumber != 0)
		return AMAxisInfo("invalid", 0);

	axisInfo_.size = size_;
	/// \todo: optimization: the axis is uniform if its a direct output of the axisValue() of a source with a uniform axis.
	axisInfo_.isUniform = false;
	return axisInfo_;
}
Esempio n. 3
0
AM1DInterpolationAB::AM1DInterpolationAB(int interpolationPoints, const QString &outputName, QObject *parent) :
	AMStandardAnalysisBlock(outputName, parent)
{
	inputSource_ = 0;
	interpolationPoints_ = interpolationPoints;

	axes_ << AMAxisInfo("invalid", 0, "No input data");
	setState(AMDataSource::InvalidFlag);
}
Esempio n. 4
0
AMDeadTimeAB::AMDeadTimeAB(const QString &outputName, QObject *parent)
	: AMStandardAnalysisBlock(outputName, parent)
{
	spectra_ = 0;
	icr_ = 0;
	ocr_ = 0;

	axes_ << AMAxisInfo("invalid", 0, "No input data");
	setState(AMDataSource::InvalidFlag);
}
Esempio n. 5
0
AM1DDerivativeAB::AM1DDerivativeAB(const QString &outputName, QObject *parent) :
	AMStandardAnalysisBlock(outputName, parent)
{
	inputSource_ = 0;
	analyzedName_ = "";
	canAnalyze_ = false;

	axes_ << AMAxisInfo("invalid", 0, "No input data");
	setState(AMDataSource::InvalidFlag);
}
Esempio n. 6
0
AM4DBinningAB::AM4DBinningAB(AMDatabase *db, int id)
	: AMStandardAnalysisBlock("tempName")
{
	sumAxis_ = 3;
	sumRangeMin_ = 0;
	sumRangeMax_ = 0;

	inputSource_ = 0;
	cacheCompletelyInvalid_ = true;
	// leave sources_ empty for now.

	axes_ << AMAxisInfo("invalid", 0, "No input data") << AMAxisInfo("invalid", 0, "No input data") << AMAxisInfo("invalid", 0, "No input data");
	setState(AMDataSource::InvalidFlag);

	loadFromDb(db, id);
		// will restore sumAxis, sumRangeMin, and sumRangeMax. We'll remain invalid until we get connected.

	AMDataSource::name_ = AMDbObject::name();	// normally it's not okay to change a dataSource's name. Here we get away with it because we're within the constructor, and nothing's watching us yet.
}
void REIXSXESImageInterpolationAB::setInputDataSourcesImplementation(const QList<AMDataSource *> &dataSources)
{
	// disconnect connections from old source, if it exists.
	if(inputSource_) {
		disconnect(inputSource_->signalSource(), SIGNAL(valuesChanged(AMnDIndex,AMnDIndex)), this, SLOT(onInputSourceValuesChanged(AMnDIndex,AMnDIndex)));
		disconnect(inputSource_->signalSource(), SIGNAL(sizeChanged(int)), this, SLOT(onInputSourceSizeChanged()));
		disconnect(inputSource_->signalSource(), SIGNAL(stateChanged(int)), this, SLOT(onInputSourceStateChanged()));
		inputSource_ = 0;
	}

	if(dataSources.isEmpty()) {
		inputSource_ = 0;
		sources_.clear();

		axes_[0] = AMAxisInfo("invalid", 0, "No input data");
	}

	// we know that this will only be called with one valid input source
	else {
		inputSource_ = dataSources.at(0);
		sources_ = dataSources;

		axes_[0] = inputSource_->axisInfoAt(0);	// take the X axis info from the data source.
		axes_[0].description = "Emission Energy";
		axes_[0].units = "eV";
		axes_[0].size /= binningLevel_;

		cacheUpdateRequired_ = true;
		axisValueCacheInvalid_ = true;
		cachedData_ = QVector<double>(axes_.at(0).size);
		cachedAxisValues_ = QVector<double>(axes_.at(0).size);

		if(shiftValues1_.isEmpty()) {
			for(int i=0,cc=inputSource_->size(1); i<cc; i++)
				shiftValues1_ << 0;	// make a null shift list, matching the size of the input data. Don't do this if we already have a shift list.
		}
		if(shiftValues2_.isEmpty()) {
			for(int i=0,cc=inputSource_->size(1); i<cc; i++)
				shiftValues2_ << 0;	// make a null shift list, matching the size of the input data. Don't do this if we already have a shift list.
		}


		connect(inputSource_->signalSource(), SIGNAL(valuesChanged(AMnDIndex,AMnDIndex)), this, SLOT(onInputSourceValuesChanged(AMnDIndex,AMnDIndex)));
		connect(inputSource_->signalSource(), SIGNAL(sizeChanged(int)), this, SLOT(onInputSourceSizeChanged()));
		connect(inputSource_->signalSource(), SIGNAL(stateChanged(int)), this, SLOT(onInputSourceStateChanged()));

	}

	reviewState();

	emitSizeChanged();
	emitValuesChanged();
	emitAxisInfoChanged();
	emitInfoChanged();
}
VESPERSEnergyScanActionController::VESPERSEnergyScanActionController(VESPERSEnergyScanConfiguration *configuration, QObject *parent)
	: AMStepScanActionController(configuration, parent), VESPERSScanController(configuration)
{
	configuration_ = configuration;

	scan_ = new AMXASScan();
	scan_->setName(configuration_->name());
	scan_->setScanConfiguration(configuration_);
	scan_->setFileFormat("amCDFv1");
	scan_->setIndexType("fileSystem");
	scan_->setNotes(buildNotes());
	scan_->rawData()->addScanAxis(AMAxisInfo("eV", 0, "Incident Energy", "eV"));

	useFeedback_ = true;
	originalEnergy_ = VESPERSBeamline::vespers()->mono()->energy();

	AMControlInfoList list;
	list.append(VESPERSBeamline::vespers()->energy()->toInfo());
	configuration_->setAxisControlInfos(list);

	AMDetectorInfoSet detectors;
	detectors.addDetectorInfo(VESPERSBeamline::vespers()->exposedDetectorByName("SplitIonChamber")->toInfo());
	detectors.addDetectorInfo(VESPERSBeamline::vespers()->exposedDetectorByName("PreKBIonChamber")->toInfo());
	detectors.addDetectorInfo(VESPERSBeamline::vespers()->exposedDetectorByName("MiniIonChamber")->toInfo());
	detectors.addDetectorInfo(VESPERSBeamline::vespers()->exposedDetectorByName("PostIonChamber")->toInfo());
	detectors.addDetectorInfo(VESPERSBeamline::vespers()->exposedDetectorByName("EnergySetpoint")->toInfo());
	detectors.addDetectorInfo(VESPERSBeamline::vespers()->exposedDetectorByName("MasterDwellTime")->toInfo());
	detectors.addDetectorInfo(VESPERSBeamline::vespers()->exposedDetectorByName("RingCurrent")->toInfo());

	VESPERS::CCDDetectors ccdDetector = configuration_->ccdDetector();

	if (ccdDetector.testFlag(VESPERS::Roper))
		detectors.addDetectorInfo(VESPERSBeamline::vespers()->exposedDetectorByName("RoperFileNumber")->toInfo());

	if (ccdDetector.testFlag(VESPERS::Mar))
		detectors.addDetectorInfo(VESPERSBeamline::vespers()->exposedDetectorByName("MarFileNumber")->toInfo());

	if (ccdDetector.testFlag(VESPERS::Pilatus))
		detectors.addDetectorInfo(VESPERSBeamline::vespers()->exposedDetectorByName("PilatusFileNumber")->toInfo());

	configuration_->setDetectorConfigurations(detectors);

	secondsElapsed_ = 0;
	secondsTotal_ = configuration_->totalTime();
	elapsedTime_.setInterval(1000);
	connect(this, SIGNAL(started()), &elapsedTime_, SLOT(start()));
	connect(this, SIGNAL(cancelled()), &elapsedTime_, SLOT(stop()));
	connect(this, SIGNAL(paused()), &elapsedTime_, SLOT(stop()));
	connect(this, SIGNAL(resumed()), &elapsedTime_, SLOT(start()));
	connect(this, SIGNAL(failed()), &elapsedTime_, SLOT(stop()));
	connect(this, SIGNAL(finished()), &elapsedTime_, SLOT(stop()));
	connect(&elapsedTime_, SIGNAL(timeout()), this, SLOT(onScanTimerUpdate()));
}
AM1DDarkCurrentCorrectionAB::AM1DDarkCurrentCorrectionAB(const QString &outputName, QObject *parent)
	: AMStandardAnalysisBlock(outputName, parent)
{
	data_ = 0;
	dwellTime_ = 0;
	darkCurrent_ = 0;
	canAnalyze_ = false;
	dataName_ = "";
	dwellTimeName_ = "";
	axes_ << AMAxisInfo("invalid", 0, "No input data");
	setState(AMDataSource::InvalidFlag);
}
Esempio n. 10
0
void AMAdditionAB::setInputDataSourcesImplementation(const QList<AMDataSource*>& dataSources)
{
    // disconnect connections from old sources, if they exist.
    if(!sources_.isEmpty()) {

        for (int i = 0; i < sources_.size(); i++) {

            disconnect(sources_.at(i)->signalSource(), SIGNAL(valuesChanged(AMnDIndex,AMnDIndex)), this, SLOT(onInputSourceValuesChanged(AMnDIndex,AMnDIndex)));
            disconnect(sources_.at(i)->signalSource(), SIGNAL(sizeChanged(int)), this, SLOT(onInputSourceSizeChanged()));
            disconnect(sources_.at(i)->signalSource(), SIGNAL(stateChanged(int)), this, SLOT(onInputSourceStateChanged()));
        }
    }

    if(dataSources.isEmpty()) {

        sources_.clear();

        for (int i = 0, size = rank(); i < size; i++)
            axes_[i] = AMAxisInfo("invalid", 0, "No input data");

        setDescription("-- No input data --");
    }

    // we know that this will only be called with valid input source
    else {

        sources_ = dataSources;

        for (int i = 0, size = rank(); i < size; i++)
            axes_[i] = sources_.at(0)->axisInfoAt(i);

        cacheUpdateRequired_ = true;
        cachedData_ = QVector<double>(size().product());

        setDescription(QString("Sum of spectra from %1 maps").arg(sources_.size()));

        for (int i = 0; i < sources_.size(); i++) {

            connect(sources_.at(i)->signalSource(), SIGNAL(valuesChanged(AMnDIndex,AMnDIndex)), this, SLOT(onInputSourceValuesChanged(AMnDIndex,AMnDIndex)));
            connect(sources_.at(i)->signalSource(), SIGNAL(sizeChanged(int)), this, SLOT(onInputSourceSizeChanged()));
            connect(sources_.at(i)->signalSource(), SIGNAL(stateChanged(int)), this, SLOT(onInputSourceStateChanged()));
        }
    }

    reviewState();

    emitSizeChanged();
    emitValuesChanged();
    emitAxisInfoChanged();
    emitInfoChanged();
}
Esempio n. 11
0
AM1DNormalizationAB::AM1DNormalizationAB(const QString &outputName, QObject *parent)
	: AMStandardAnalysisBlock(outputName, parent)
{
	data_ = 0;
	normalizer_ = 0;
	canAnalyze_ = false;
	dataName_ = "";
	normalizationName_ = "";
	cacheUpdateRequired_ = false;
	cachedDataRange_ = AMRange();

	axes_ << AMAxisInfo("invalid", 0, "No input data");
	setState(AMDataSource::InvalidFlag);
}
REIXSXESImageInterpolationAB::REIXSXESImageInterpolationAB(const QString &outputName, QObject *parent) :
	AMStandardAnalysisBlock(outputName, parent)
{
	// Live correlation turned off by default. Prevents correlation while loading from db and no shift is really better than a random shift, initially.
	liveCorrelation_ = false;

	curve1Smoother_ = 0;
	curve2Smoother_ = 0;

	sumRangeMinY_ = 10;
	sumRangeMaxY_ = 53;
	sumRangeMinX_ = 75;
	sumRangeMaxX_ = 925;
	rangeRound_ = 0.6;
	curve2Disabled_ = false;
	correlation1CenterPx_ = 250;
	correlation2CenterPx_ = 700;
	correlation1HalfWidth_ = 40;
	correlation2HalfWidth_ = 40;
	setCorrelation1Smoothing(QPair<int,int>(3,5)); //poly,quadratic
	setCorrelation2Smoothing(QPair<int,int>(3,5)); //poly,quadratic

	energyCalibrationOffset_ = 0;
	tiltCalibrationOffset_ = 0;

	interpolationLevel_ = 10;
	binningLevel_ = 2;

	inputSource_ = 0;
	cacheUpdateRequired_ = false;
	cachedDataRange_ = AMRange();
	axisValueCacheInvalid_ = true;
	axisValuesInvalid_ = false;

	// leave sources_ empty for now.

	axes_ << AMAxisInfo("invalid", 0, "No input data");
	connect(&callCorrelation_, SIGNAL(executed()), this, SLOT(correlateNow()));
	setDescription("XES Interpolated Spectrum");

	// shift values can start out empty.
	shiftValues1_ << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0;
	shiftValues2_ << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0;

}
Esempio n. 13
0
// Set the data source inputs.
void AM1DSummingAB::setInputDataSourcesImplementation(const QList<AMDataSource*>& dataSources)
{
	// disconnect connections from old sources, if they exist.
	if(!sources_.isEmpty()) {

		for (int i = 0; i < sources_.size(); i++){

			disconnect(sources_.at(i)->signalSource(), SIGNAL(valuesChanged(AMnDIndex,AMnDIndex)), this, SLOT(onInputSourceValuesChanged(AMnDIndex,AMnDIndex)));
			disconnect(sources_.at(i)->signalSource(), SIGNAL(sizeChanged(int)), this, SLOT(onInputSourceSizeChanged()));
			disconnect(sources_.at(i)->signalSource(), SIGNAL(stateChanged(int)), this, SLOT(onInputSourceStateChanged()));
		}
	}

	if(dataSources.isEmpty()) {

		sources_.clear();
		axes_[0] = AMAxisInfo("invalid", 0, "No input data");
		setDescription("-- No input data --");
	}

	// we know that this will only be called with valid input source
	else {

		sources_ = dataSources;

		axes_[0] = sources_.at(0)->axisInfoAt(0);

		setDescription(QString("Sum of %1 spectra").arg(sources_.size()));

		for (int i = 0; i < sources_.size(); i++){

			connect(sources_.at(i)->signalSource(), SIGNAL(valuesChanged(AMnDIndex,AMnDIndex)), this, SLOT(onInputSourceValuesChanged(AMnDIndex,AMnDIndex)));
			connect(sources_.at(i)->signalSource(), SIGNAL(sizeChanged(int)), this, SLOT(onInputSourceSizeChanged()));
			connect(sources_.at(i)->signalSource(), SIGNAL(stateChanged(int)), this, SLOT(onInputSourceStateChanged()));
		}
	}

	reviewState();

	emitSizeChanged(0);
	emitValuesChanged();
	emitAxisInfoChanged(0);
	emitInfoChanged();
}
VESPERSEnergyDacqScanController::VESPERSEnergyDacqScanController(VESPERSEnergyScanConfiguration *cfg, QObject *parent)
    : AMDacqScanController(cfg, parent), VESPERSScanController(cfg)
{
    config_ = cfg;

    secondsElapsed_ = 0;
    secondsTotal_ = config_->totalTime();
    elapsedTime_.setInterval(1000);
    connect(this, SIGNAL(started()), &elapsedTime_, SLOT(start()));
    connect(this, SIGNAL(cancelled()), &elapsedTime_, SLOT(stop()));
    connect(this, SIGNAL(paused()), &elapsedTime_, SLOT(stop()));
    connect(this, SIGNAL(resumed()), &elapsedTime_, SLOT(start()));
    connect(this, SIGNAL(failed()), &elapsedTime_, SLOT(stop()));
    connect(this, SIGNAL(finished()), &elapsedTime_, SLOT(stop()));
    connect(&elapsedTime_, SIGNAL(timeout()), this, SLOT(onScanTimerUpdate()));

    scan_ = new AMXASScan(); 	// MB: Moved from line 363 in startImplementation.
    scan_->setName(config_->name());
    scan_->setScanConfiguration(config_);
    scan_->setRunId(AMUser::user()->currentRunId());
    scan_->setIndexType("fileSystem");
    scan_->setFilePath(AMUserSettings::defaultRelativePathForScan(QDateTime::currentDateTime())+".cdf");
    scan_->setFileFormat("amCDFv1");
    scan_->replaceRawDataStore(new AMCDFDataStore(AMUserSettings::userDataFolder % scan_->filePath(), false));
    scan_->rawData()->addScanAxis(AMAxisInfo("eV", 0, "Incident Energy", "eV"));

    scan_->setNotes(buildNotes());

    AMOldDetectorSet *ionChambers = VESPERSBeamline::vespers()->ionChambers();
    AMMeasurementInfo temp = AMMeasurementInfo("", "");

    for (int i = 0; i < ionChambers->count(); i++) {

        temp = AMMeasurementInfo(*(ionChambers->detectorAt(i)->toInfo()));
        temp.name = ionChambers->detectorAt(i)->detectorName();
        scan_->rawData()->addMeasurement(temp);
        scan_->addRawDataSource(new AMRawDataSource(scan_->rawData(), scan_->rawData()->measurementCount() - 1), true, false);
    }

    addExtraDatasources();
    useDwellTimes(VESPERSBeamline::vespers()->dwellTimeTrigger(), VESPERSBeamline::vespers()->dwellTimeConfirmed());
}
// Set the data source inputs.
void AM1DRunningAverageFilterAB::setInputDataSourcesImplementation(const QList<AMDataSource*>& dataSources) {

	// disconnect connections from old source, if it exists.
	if(inputSource_) {
		disconnect(inputSource_->signalSource(), SIGNAL(valuesChanged(AMnDIndex,AMnDIndex)), this, SLOT(onInputSourceValuesChanged(AMnDIndex,AMnDIndex)));
		disconnect(inputSource_->signalSource(), SIGNAL(sizeChanged(int)), this, SLOT(onInputSourceSizeChanged()));
		disconnect(inputSource_->signalSource(), SIGNAL(stateChanged(int)), this, SLOT(onInputSourceStateChanged()));
	}

	if(dataSources.isEmpty()) {
		inputSource_ = 0;
		sources_.clear();

		axes_[0] = AMAxisInfo("invalid", 0, "No input data");
		setDescription("-- No input data --");
	}

	// we know that this will only be called with valid input source
	else {
		inputSource_ = dataSources.at(0);
		sources_ = dataSources;

		axes_[0] = inputSource_->axisInfoAt(0);

		setDescription(QString("Running Average of %1")
					   .arg(inputSource_->name()));

		connect(inputSource_->signalSource(), SIGNAL(valuesChanged(AMnDIndex,AMnDIndex)), this, SLOT(onInputSourceValuesChanged(AMnDIndex,AMnDIndex)));
		connect(inputSource_->signalSource(), SIGNAL(sizeChanged(int)), this, SLOT(onInputSourceSizeChanged()));
		connect(inputSource_->signalSource(), SIGNAL(stateChanged(int)), this, SLOT(onInputSourceStateChanged()));

	}

	reviewState();

	emitSizeChanged(0);
	emitValuesChanged();
	emitAxisInfoChanged(0);
	emitInfoChanged();
}
Esempio n. 16
0
void AM1DDerivativeAB::setInputDataSourcesImplementation(const QList<AMDataSource*>& dataSources)
{
	// disconnect connections from old source, if it exists.
	if(inputSource_) {

		disconnect(inputSource_->signalSource(), SIGNAL(valuesChanged(AMnDIndex,AMnDIndex)), this, SLOT(onInputSourceValuesChanged(AMnDIndex,AMnDIndex)));
		disconnect(inputSource_->signalSource(), SIGNAL(sizeChanged(int)), this, SLOT(onInputSourceSizeChanged()));
		disconnect(inputSource_->signalSource(), SIGNAL(stateChanged(int)), this, SLOT(onInputSourceStateChanged()));
		inputSource_ = 0;
	}

	if(dataSources.isEmpty()) {

		inputSource_ = 0;
		sources_.clear();
		canAnalyze_ = false;

		axes_[0] = AMAxisInfo("invalid", 0, "No input data");
		setDescription("Derivative");
	}

	// we know that this will only be called with valid input source
	else if (dataSources.count() == 1){

		inputSource_ = dataSources.at(0);
		sources_ = dataSources;
		canAnalyze_ = true;

		axes_[0] = inputSource_->axisInfoAt(0);

        cacheUpdateRequired_ = true;
        cachedData_ = QVector<double>(size(0));

		setDescription(QString("Derivative of %1").arg(inputSource_->name()));

		connect(inputSource_->signalSource(), SIGNAL(valuesChanged(AMnDIndex,AMnDIndex)), this, SLOT(onInputSourceValuesChanged(AMnDIndex,AMnDIndex)));
		connect(inputSource_->signalSource(), SIGNAL(sizeChanged(int)), this, SLOT(onInputSourceSizeChanged()));
		connect(inputSource_->signalSource(), SIGNAL(stateChanged(int)), this, SLOT(onInputSourceStateChanged()));
	}
bool ALSBL8XASFileLoaderPlugin::load(AMScan *scan, const QString &userDataFolder, AMErrorMon *errorMonitor){

	if(columns2fileFormatHeaders_.count() == 0) {
		columns2fileFormatHeaders_.set("eV", "Mono Energy");
		columns2fileFormatHeaders_.set("ringCurrent", "Beam Current");
		columns2fileFormatHeaders_.set("I0", "Counter 0");
		columns2fileFormatHeaders_.set("TEY", "Counter 1");
		columns2fileFormatHeaders_.set("TFY", "Counter 2");
	}

	if(!scan)
		return false;

	// Clear the old scan axes to ensure we don't have any extras.
	scan->clearRawDataCompletely();
	scan->rawData()->addScanAxis( AMAxisInfo("eV", 0, "Incident Energy", "eV") );

	QFileInfo sourceFileInfo(scan->filePath());
	if(sourceFileInfo.isRelative()){
		sourceFileInfo.setFile(userDataFolder + "/" + scan->filePath());
	}

	// used in parsing the data file
	QString line;
	QStringList lp;

	// names of the columns, taken from headers in the data file.
	QStringList colNames1;

	// open the file:
	QFile f(sourceFileInfo.filePath());
	if(!f.open(QIODevice::ReadOnly)) {
		errorMonitor->exteriorReport(AMErrorReport(0, AMErrorReport::Serious, ALSBL8XASFileLoaderPLUGIN_CANNOT_OPEN_FILE, "ALSBL8XASFileLoader parse error while loading scan data from file. Missing file."));
		return false;
	}
	QTextStream fs(&f);

	// find out what columns exist. Looking for line starting with 'Time (s)'
	while(!fs.atEnd() && !line.startsWith("Time (s)"))
		line = fs.readLine();
	if(fs.atEnd()) {
		errorMonitor->exteriorReport(AMErrorReport(0, AMErrorReport::Serious, ALSBL8XASFileLoaderPLUGIN_BAD_FORMAT_NO_EVENT1_HEADER, "ALSBL8XASFileLoader parse error while loading scan data from file. Missing the Column Header line."));
		return false;	// bad format. Missing the column header
	}
	colNames1 = line.split(QChar('\t'));

	// translate header names into meaningful column names (ex: "Counter 0" ---> "I0".... "Counter1"--->"tey")
	for(int i=0; i<colNames1.count(); i++)
		header2columnName(colNames1[i]);

	// ensure that we have the basic "eV" column
	int eVIndex = colNames1.indexOf("eV");
	if(eVIndex < 0) {
		errorMonitor->exteriorReport(AMErrorReport(0, AMErrorReport::Serious, ALSBL8XASFileLoaderPLUGIN_BAD_FORMAT_NO_ENERGY_COLUMN, "ALSBL8XASFileLoader parse error while loading scan data from file. I couldn't find the energy (eV) column."));
		return false;	// bad format. No primary column

	}

	scan->clearRawDataPointsAndMeasurements();

	// There is a rawData scan axis called "eV" created in the constructor.  AMAxisInfo("eV", 0, "Incident Energy", "eV")
	/// \todo What if there isn't? Should we check, and create the axis if none exist? What if there's more than one scan axis? Can't remove from AMDataStore... [The rest of this code assumes a single scan axis]

	// add scalar (0D) measurements to the raw data store, for each data column.  Also add raw data sources to the scan, which expose this data.
	foreach(QString colName, colNames1) {
		if(colName != "eV" && colName != "Event-ID") {
			scan->rawData()->addMeasurement(AMMeasurementInfo(colName, colName));	/// \todo nice descriptions for the common column names. Not just 'tey' or 'tfy'.
		}
	}

	int eVAxisIndex = 0;	// counter for each datapoint along the scan axis.

	// read all the data. Add to data columns or scan properties depending on the event-ID.
	while(!fs.atEnd()) {

		line = fs.readLine();

		// Data line. If there are the correct number of columns:
		if( (lp = line.split('\t', QString::SkipEmptyParts)).count() == colNames1.count() ) {

			// append a new datapoint to the data tree (supply primary eV value here)
			scan->rawData()->beginInsertRows(1, -1);
			scan->rawData()->setAxisValue(0, eVAxisIndex, lp.at(eVIndex).toDouble());	// insert eV

			// add all columns (but ignore the eV column)
			int measurementId = 0;
			for(int i=1; i<colNames1.count(); i++) {
				if(i!=eVIndex)
					scan->rawData()->setValue(eVAxisIndex, measurementId++, AMnDIndex(), lp.at(i).toDouble());
			}
			eVAxisIndex++;
			scan->rawData()->endInsertRows();
		}
	}

	/// Not supposed to create the raw data sources.  Do an integrity check on the pre-existing data sources instead... If there's a raw data source, but it's pointing to a non-existent measurement in the data store, that's a problem. Remove it.  \todo Is there any way to incorporate this at a higher level, so that import-writers don't need to bother?

	for(int i=0; i<scan->rawDataSources()->count(); i++) {
		if(scan->rawDataSources()->at(i)->measurementId() >= scan->rawData()->measurementCount()) {
			errorMonitor->exteriorReport(AMErrorReport(scan, AMErrorReport::Debug, ALSBL8XASFileLoaderPLUGIN_DATA_COLUMN_MISMATCH, QString("The data in the file didn't match the raw data columns we were expecting. Removing the raw data column '%1')").arg(scan->rawDataSources()->at(i)->name())));
			scan->deleteRawDataSource(i);
		}
	}

	return true;
}
bool VESPERS2012SpatialLineScanFileLoaderPlugin::load(AMScan *scan, const QString &userDataFolder, AMErrorMon *errorMonitor)
{
	// Check for null scan reference.
	if (!scan)
		return false;

	QFileInfo sourceFileInfo(scan->filePath());
	if(sourceFileInfo.isRelative())
		sourceFileInfo.setFile(userDataFolder + "/" + scan->filePath());

	QFile file(sourceFileInfo.filePath());
	if(!file.open(QIODevice::ReadOnly)) {
		errorMonitor->exteriorReport(AMErrorReport(0, AMErrorReport::Serious, VESPERS201SPATIALLINESCANFILELOADERPLUGIN_CANNOT_OPEN_FILE, "Line Scan File Loader parse error while loading scan data from file."));
		return false;
	}

	QTextStream in(&file);
	QString line;
	QStringList lineTokenized;

	bool usingSingleElement = false;
	bool usingFourElement = false;

	if (scan->fileFormat() == "vespers2012LineScanXRF1El" || scan->fileFormat() == "vespers2012LineScanXRF1ElXRD")
		usingSingleElement = true;
	else if (scan->fileFormat() == "vespers2012LineScanXRF4El" || scan->fileFormat() == "vespers2012LineScanXRF4ElXRD")
		usingFourElement = true;
	else if (scan->fileFormat() == "vespers2012LineScan1Eln4El" || scan->fileFormat() == "vespers2012LineScan1Eln4ElXRD"){

		usingSingleElement = true;
		usingFourElement = true;
	}

	in.readLine();
	in.readLine();
	in.readLine();

	// Grab the first PV, it tells us what the axis was.
	line = in.readLine();
	lineTokenized = line.split(" ");
	line = lineTokenized.at(2);

	QString temp = sourceFileInfo.filePath();
	temp.replace(".dat", ".cdf");
	AMCDFDataStore *cdfData = new AMCDFDataStore(temp, false);

	if (line == "TS1607-2-B21-01:H:user:mm")
		cdfData->addScanAxis(AMAxisInfo("H", 0, "Horizontal Position", "mm"));
	else if (line == "TS1607-2-B21-01:V:user:mm")
		cdfData->addScanAxis(AMAxisInfo("V", 0, "Vertical Position", "mm"));
	else if (line == "SVM1607-2-B21-02:mm")
		cdfData->addScanAxis(AMAxisInfo("X", 0, "Horizontal Position", "mm"));
	else if (line == "SVM1607-2-B21-01:mm")
		cdfData->addScanAxis(AMAxisInfo("Z", 0, "Vertical Position", "mm"));
	else if (line == "07B2_Mono_SineB_Egec:eV")
		cdfData->addScanAxis(AMAxisInfo("eV", 0, "Incident Energy", "eV"));

	in.readLine();
	in.readLine();
	in.readLine();

	// Clear any old data so we can start fresh.
	scan->clearRawDataPointsAndMeasurements();
	int axisValueIndex = 0;
	int count = scan->rawDataSourceCount();

	// Note!  Not general!
	QList<AMAxisInfo> axisInfo;
	AMAxisInfo ai("Energy", 2048, "Energy", "eV");
	ai.increment = 10;
	ai.start = AMNumber(0);
	ai.isUniform = true;
	axisInfo << ai;

	if (usingSingleElement && usingFourElement){

		// The last 6 raw data sources are spectra.
		for (int i = 0; i < count-6; i++)
			cdfData->addMeasurement(AMMeasurementInfo(scan->rawDataSources()->at(i)->name(), scan->rawDataSources()->at(i)->description()));

		for (int i = count-6; i < count; i++)
			cdfData->addMeasurement(AMMeasurementInfo(scan->rawDataSources()->at(i)->name(), scan->rawDataSources()->at(i)->description(), "eV", axisInfo));
	}

	else if (usingSingleElement){

		// The last raw data source is a spectrum.
		for (int i = 0; i < count-1; i++)
			cdfData->addMeasurement(AMMeasurementInfo(scan->rawDataSources()->at(i)->name(), scan->rawDataSources()->at(i)->description()));

		cdfData->addMeasurement(AMMeasurementInfo(scan->rawDataSources()->at(scan->rawDataSourceCount()-1)->name(), scan->rawDataSources()->at(scan->rawDataSourceCount()-1)->description(), "eV", axisInfo));
	}

	else if (usingFourElement){

		// The last 5 raw data sources are spectra.
		for (int i = 0; i < count-5; i++)
			cdfData->addMeasurement(AMMeasurementInfo(scan->rawDataSources()->at(i)->name(), scan->rawDataSources()->at(i)->description()));

		for (int i = count-5; i < count; i++)
			cdfData->addMeasurement(AMMeasurementInfo(scan->rawDataSources()->at(i)->name(), scan->rawDataSources()->at(i)->description(), "eV", axisInfo));
	}

	else{

		for (int i = 0; i < count; i++)
			cdfData->addMeasurement(AMMeasurementInfo(scan->rawDataSources()->at(i)->name(), scan->rawDataSources()->at(i)->description()));

	}

	lineTokenized.clear();

	QStringList fileLines;
	while(!in.atEnd())
		fileLines << in.readLine();

	file.close();

	// Add in the data at the right spot.
	cdfData->beginInsertRows(fileLines.size(), -1);

	foreach(QString currentLine, fileLines){

		lineTokenized = currentLine.split(", ");

		cdfData->setAxisValue(0, axisValueIndex, lineTokenized.at(1).toDouble());

		// This isn't the most efficient way of putting the spectra data in, but it will do for the time being.
		if (usingSingleElement && usingFourElement){

			// Only going to rawDataSourceCount-6 because the last 6 raw data sources are the 2D spectra scan and requires its own method of entering the data.
			for (int i = 0; i < count-6; i++)
				cdfData->setValue(axisValueIndex, i, AMnDIndex(), lineTokenized.at(i+2).toDouble());
		}

		else if (usingSingleElement){

			// Only going to rawDataSourceCount-1 because the last raw data source is the 2D spectra scan and requires its own method of entering the data.
			for (int i = 0; i < count-1; i++)
				cdfData->setValue(axisValueIndex, i, AMnDIndex(), lineTokenized.at(i+2).toDouble());
		}

		else if (usingFourElement){

			// Only going to rawDataSourceCount-5 because the last 5 raw data sources are the 2D spectra scan and requires its own method of entering the data.
			for (int i = 0; i < count-5; i++)
				cdfData->setValue(axisValueIndex, i, AMnDIndex(), lineTokenized.at(i+2).toDouble());
		}

		else{

			for (int i = 0; i < count; i++)
				cdfData->setValue(axisValueIndex, i, AMnDIndex(), lineTokenized.at(i+2).toDouble());
		}

		// Advance to the next spot.
		axisValueIndex++;
	}
bool SGM2013FastFileLoaderPlugin::load(AMScan *scan, const QString &userDataFolder, AMErrorMon *errorMonitor){
	if(!scan)
		return false;

	// Clear the old scan axes to ensure we don't have any extras.
	scan->clearRawDataCompletely();
	scan->rawData()->addScanAxis( AMAxisInfo("eV", 0, "Incident Energy", "eV") );

	QFileInfo sourceFileInfo(scan->filePath());
	if(sourceFileInfo.isRelative())
		sourceFileInfo.setFile(userDataFolder + "/" + scan->filePath());

	// open the file:
	QFile f(sourceFileInfo.filePath());
	if(!f.open(QIODevice::ReadOnly)) {
		errorMonitor->exteriorReport(AMErrorReport(0, AMErrorReport::Serious, SGM2013FASTFILELOADERPLUGIN_CANNOT_OPEN_FILE, "SGM2013FastFileLoader parse error while loading scan data from file. Missing file."));
		return false;
	}
	QTextStream fs(&f);

	QMap<int, QList<int> > measurementOrderByRank;

	// used in parsing the data file
	QString line;
	QStringList lp;
	QString versionString;
	int index;
	double dataValue;
	int insertionIndex = 0;
	bool informationSection = false;
	bool finishedHeader = false;
	while(!fs.atEnd()){
		if(!finishedHeader)
			line = fs.readLine();
		if(line == "Start Info")
			informationSection = true;
		else if(line.contains("Version: "))
			versionString = line.remove("Version: ");
		else if(line == "End Info"){
			informationSection = false;
			finishedHeader = true;
			line = "";
		}
		else if(informationSection){
			if(versionString == "SGM Generic Fast 0.1"){
				if(!line.contains("Encoder Start Value:") && !line.contains("SpacingParam:") && !line.contains("C1Param:") && !line.contains("C2Param:") && !line.contains("SParam:") && !line.contains("ThetaParam:")){
					lp = line.split("|!|!|");
					index = lp.at(0).toInt();
					if(index >= 0){
						QString oneString = lp.at(1);
						AMTextStream measurementInfoStreamOut(&oneString);
						AMMeasurementInfo oneMeasurementInfo = AMMeasurementInfo(QString(), QString());
						measurementInfoStreamOut.read(oneMeasurementInfo);

						if(measurementOrderByRank.contains(oneMeasurementInfo.rank())){
							QList<int> thisRankList = measurementOrderByRank.value(oneMeasurementInfo.rank());
							thisRankList.append(index);
							measurementOrderByRank.insert(oneMeasurementInfo.rank(), thisRankList);
						}
						else{
							QList<int> newRankList;
							newRankList.append(index);
							measurementOrderByRank.insert(oneMeasurementInfo.rank(), newRankList);
						}

						scan->rawData()->addMeasurement(oneMeasurementInfo);
					}
				}
			}
		}
		else{
			if(!fs.atEnd()){
				fs >> dataValue;
				if(!fs.atEnd()){
					scan->rawData()->beginInsertRows(1, -1);
					scan->rawData()->setAxisValue(0, insertionIndex, dataValue); // insert eV
					QList<int> rank0Measurements = measurementOrderByRank.value(0);
					for(int x = 0; x < rank0Measurements.count(); x++){
						fs >> dataValue;
						scan->rawData()->setValue(AMnDIndex(insertionIndex), rank0Measurements.at(x), AMnDIndex(), dataValue);
					}
					scan->rawData()->endInsertRows();
					insertionIndex++;
				}
			}
		}
Esempio n. 20
0
bool ALSBL8XASFileLoader::loadFromFile(const QString& filepath, bool setMetaData, bool setRawDataSources, bool createDefaultAnalysisBlocks) {

	// not initialized to have a scan target, or scan target is not an AMXASScan...
	AMXASScan* scan = qobject_cast<AMXASScan*>(scan_);
	if(!scan)
		return false;

	// Clear the old scan axes to ensure we don't have any extras.
	scan->clearRawDataCompletely();
	scan->rawData()->addScanAxis( AMAxisInfo("eV", 0, "Incident Energy", "eV") );

	// information about the scan we hope to locate:
	QString comments;
	double integrationTime;

	// used in parsing the data file
	QString line;
	QStringList lp;

	// names of the columns, taken from headers in the data file.
	QStringList colNames1;

	// open the file:
	QFile f(filepath);
	if(!f.open(QIODevice::ReadOnly)) {
		AMErrorMon::report(AMErrorReport(0, AMErrorReport::Serious, -1, "ALSBL8XASFileLoader parse error while loading scan data from file. Missing file."));
		return false;
	}
	QTextStream fs(&f);

	if(setMetaData) {
		// Start reading the file. look for the count-time line.
		while( !fs.atEnd() && !(line = fs.readLine()).startsWith("Count Time (s):") )
			;
		if(fs.atEnd()) {
			AMErrorMon::report(AMErrorReport(0, AMErrorReport::Debug, -2, "ALSBL8XASFileLoader parse error while loading scan data from file. Could not find the count time (integration time)."));
			fs.seek(0);
			// return false;	// bad format; missing the count time string
		}
		else {
			// read it
			integrationTime = line.split(':').at(1).trimmed().toDouble();
		}


		// Keep reading the file. look for the comment line.
		while( !fs.atEnd() && !(line = fs.readLine()).startsWith("Description Length:") )
			;
		if(fs.atEnd()) {
			AMErrorMon::report(AMErrorReport(0, AMErrorReport::Debug, -2, "ALSBL8XASFileLoader parse error while loading scan data from file. Could not find the description."));
			fs.seek(0);
			// return false;	// bad format; missing the comment string
		}
		else {

			// read the comment
			bool descriptionLengthOk;
			int descriptionLength = line.split(':').at(1).trimmed().toInt(&descriptionLengthOk);
			// read this many characters now...
			if(descriptionLengthOk)
				comments = fs.read(descriptionLength);
		}
	}


	// find out what columns exist. Looking for line starting with 'Time (s)'
	line.clear();
	while(!fs.atEnd() && !line.startsWith("Time (s)"))
		line = fs.readLine();
	if(fs.atEnd()) {
		AMErrorMon::report(AMErrorReport(0, AMErrorReport::Serious, -2, "ALSBL8XASFileLoader parse error while loading scan data from file. Missing the Column Header line."));
		return false;	// bad format; missing the column header
	}
	colNames1 = line.split(QChar('\t'));

	// translate header names into meaningful column names (ex: "Counter 0" ---> "I0".... "Counter1"--->"tey")
	for(int i=0; i<colNames1.count(); i++)
		header2columnName(colNames1[i]);

	// ensure that we have the basic "eV" column
	int eVIndex = colNames1.indexOf("eV");
	if(eVIndex < 0) {
		AMErrorMon::report(AMErrorReport(0, AMErrorReport::Serious, -3, "ALSBL8XASFileLoader parse error while loading scan data from file. I couldn't find the energy (eV) column."));
		return false;	// bad format; no primary column

	}

	// clear the existing raw data (and raw data sources, if we're supposed to)
	if(setRawDataSources)
		scan->clearRawDataPointsAndMeasurementsAndDataSources();
	else
		scan->clearRawDataPointsAndMeasurements();

	// There is a rawData scan axis called "eV" created in the constructor.  AMAxisInfo("eV", 0, "Incident Energy", "eV")
	/// \todo What if there isn't? Should we check, and create the axis if none exist? What if there's more than one scan axis? Can't remove from AMDataStore... [The rest of this code assumes a single scan axis]

	// add scalar (0D) measurements to the raw data store, for each data column.  Also add raw data sources to the scan, which expose this data.
	foreach(QString colName, colNames1) {
		if(colName != "eV" && colName != "Event-ID") {
			scan->rawData()->addMeasurement(AMMeasurementInfo(colName, colName));	/// \todo nice descriptions for the common column names; not just 'tey' or 'tfy'.
		}
	}

	int eVAxisIndex = 0;	// counter for each datapoint along the scan axis.

	// read all the data. Add to data columns or scan properties depending on the event-ID.
	while(!fs.atEnd()) {

		line = fs.readLine();

		// Data line. If there are the correct number of columns:
		if( (lp = line.split('\t', QString::SkipEmptyParts)).count() == colNames1.count() ) {

			// append a new datapoint to the data tree (supply primary eV value here)
			scan->rawData()->beginInsertRows(1, -1);
			scan->rawData()->setAxisValue(0, eVAxisIndex, lp.at(eVIndex).toDouble());	// insert eV

			// add all columns (but ignore the eV column)
			int measurementId = 0;
			for(int i=1; i<colNames1.count(); i++) {
				if(i!=eVIndex)
					scan->rawData()->setValue(eVAxisIndex, measurementId++, AMnDIndex(), lp.at(i).toDouble());
			}
			eVAxisIndex++;
			scan->rawData()->endInsertRows();
		}
	}


	if(setMetaData) {
		scan->setNotes(comments);
		// for a date-time, there is no information saved inside the file format, so the best we can do is look at the file's creation date-time...
		QFileInfo fi(filepath);
		scan->setDateTime(fi.lastModified());
		/// \todo integration time... do what with?
	}

	// If we need to create the raw data sources...
	if(setRawDataSources) {
		// expose the raw data that might be useful to the users
		foreach(QString visibleColumn, defaultUserVisibleColumns_) {
			int measurementId = scan->rawData()->idOfMeasurement(visibleColumn);
			if(measurementId >= 0)
				scan->addRawDataSource(new AMRawDataSource(scan->rawData(), measurementId));
		}
	}
Esempio n. 21
0
bool VESPERSXASDataLoader::loadFromFile(const QString &filepath, bool setMetaData, bool setRawDataSources, bool createDefaultAnalysisBlocks)
{
    // Currently don't have meta data.
    Q_UNUSED(setMetaData)
    Q_UNUSED(setRawDataSources)
    Q_UNUSED(createDefaultAnalysisBlocks)

    AMXASScan *scan = qobject_cast<AMXASScan *>(scan_);

    if (!scan) {

        AMErrorMon::alert(0, 0, "VESPERS XAS File Loader: Could not load XAS data into a non-XAS scan.");
        return false;
    }

    // Clear the old scan axes to ensure we don't have any extras.
    scan->clearRawDataCompletely();
    scan->rawData()->addScanAxis( AMAxisInfo("eV", 0, "Incident Energy", "eV") );

    QFile file(filepath);
    if(!file.open(QIODevice::ReadOnly)) {
        AMErrorMon::error(0, -1, "XASFileLoader parse error while loading scan data from file.");
        return false;
    }

    QFile spectra;
    QVector<int> data;

    QTextStream in(&file);
    QString line;
    QStringList lineTokenized;

    // Need to determine if the single element or four element vortex detector was used.  Also need to determine which ion chambers were used for I0 and It.
    // First two lines are useless.
    line = in.readLine();
    line = in.readLine();

    line = in.readLine();

    if (line.contains("#(2)"))
        line = in.readLine();

    bool usingVortex = line.contains("IOC1607-004") || line.contains("dxp1607-B21-04");

    if (usingVortex) {

        data.resize(2048);
        QString temp(filepath);
        temp.chop(4);
        spectra.setFileName(temp+"_spectra.dat");

        if(!spectra.open(QIODevice::ReadOnly)) {
            AMErrorMon::error(0, -1, QString("XASFileLoader parse error while loading scan spectra data from %1.").arg(spectra.fileName()));
            return false;
        }
    }
    else
        spectra.setFileName("");

    QTextStream spectraStream(&spectra);
    QString spectraLine;
    QStringList spectraTokenized;

    while ((line = in.readLine()).contains("#")) {
        //Do nothing
    }

    // Clear any old data so we can start fresh.
    scan->clearRawDataPointsAndMeasurements();

    // Some setup variables.
    int axisValueIndex = 0;

    if (usingVortex) {

        for (int i = 0; i < scan_->rawDataSourceCount()-1; i++)
            scan_->rawData()->addMeasurement(AMMeasurementInfo(scan_->rawDataSources()->at(i)->name(), scan_->rawDataSources()->at(i)->description()));

        QList<AMAxisInfo> axisInfo;
        AMAxisInfo ai("Energy", 2048, "Energy", "eV");
        ai.increment = 10;
        ai.start = AMNumber(0);
        ai.isUniform = true;
        axisInfo << ai;

        scan_->rawData()->addMeasurement(AMMeasurementInfo(scan_->rawDataSources()->at(scan_->rawDataSourceCount()-1)->name(), scan_->rawDataSources()->at(scan_->rawDataSourceCount()-1)->description(), "eV", axisInfo));
    }

    else {

        for (int i = 0; i < scan_->rawDataSourceCount(); i++)
            scan_->rawData()->addMeasurement(AMMeasurementInfo(scan_->rawDataSources()->at(i)->name(), scan_->rawDataSources()->at(i)->description()));

    }
    while (!in.atEnd()) {

        lineTokenized << line.split(", ");

        scan->rawData()->beginInsertRows(1, -1);

        scan_->rawData()->setAxisValue(0, axisValueIndex, lineTokenized.at(1).toDouble());

        // This isn't the most efficient way of putting the spectra data in, but it will do for the time being.
        if (usingVortex) {

            // Only going to rawDataSourceCount-1 because the last raw data source is the 2D spectra scan and requires its own method of entering the data.
            for (int i = 0; i < scan_->rawDataSourceCount()-1; i++)
                scan_->rawData()->setValue(axisValueIndex, i, AMnDIndex(), lineTokenized.at(i+2).toDouble());

            spectraTokenized.clear();
            spectraLine = spectraStream.readLine();
            spectraTokenized << spectraLine.split(",");

            for (int j = 0; j < 2048; j++)
                data[j] = spectraTokenized.at(j).toInt();

            scan_->rawData()->setValue(axisValueIndex, scan_->rawDataSourceCount()-1, data.constData());
        }

        else {

            // In transmission, there is no 2D spectra.  Go through all the data sources.
            for (int i = 0; i < scan_->rawDataSourceCount(); i++)
                scan_->rawData()->setValue(axisValueIndex, i, AMnDIndex(), lineTokenized.at(i+2).toDouble());
        }

        scan->rawData()->endInsertRows();

        axisValueIndex++;
        line = in.readLine();
        lineTokenized.clear();
    }

    file.close();

    if (usingVortex)
        spectra.close();

    return true;
}
Esempio n. 22
0
// Set the data source inputs.
void AM4DBinningAB::setInputDataSourcesImplementation(const QList<AMDataSource*>& dataSources) {

    // disconnect connections from old source, if it exists.
    if(inputSource_) {
        disconnect(inputSource_->signalSource(), SIGNAL(valuesChanged(AMnDIndex,AMnDIndex)), this, SLOT(onInputSourceValuesChanged(AMnDIndex,AMnDIndex)));
        disconnect(inputSource_->signalSource(), SIGNAL(sizeChanged(int)), this, SLOT(onInputSourceSizeChanged()));
        disconnect(inputSource_->signalSource(), SIGNAL(stateChanged(int)), this, SLOT(onInputSourceStateChanged()));
        inputSource_ = 0;
    }

    if(dataSources.isEmpty()) {
        inputSource_ = 0;
        sources_.clear();
        canAnalyze_ = false;

        axes_[0] = AMAxisInfo("invalid", 0, "No input data");
        axes_[1] = AMAxisInfo("invalid", 0, "No input data");
        axes_[2] = AMAxisInfo("invalid", 0, "No input data");
        setDescription("-- No input data --");
    }

    // we know that this will only be called with valid input source
    else if (dataSources.count() == 1) {

        inputSource_ = dataSources.at(0);
        sources_ = dataSources;
        canAnalyze_ = true;

        switch (sumAxis_) {

        case 0:
            axes_[0] = inputSource_->axisInfoAt(1);
            axes_[1] = inputSource_->axisInfoAt(2);
            axes_[2] = inputSource_->axisInfoAt(3);
            break;

        case 1:
            axes_[0] = inputSource_->axisInfoAt(0);
            axes_[1] = inputSource_->axisInfoAt(2);
            axes_[2] = inputSource_->axisInfoAt(3);
            break;

        case 2:
            axes_[0] = inputSource_->axisInfoAt(0);
            axes_[1] = inputSource_->axisInfoAt(1);
            axes_[2] = inputSource_->axisInfoAt(3);
            break;

        case 3:
            axes_[0] = inputSource_->axisInfoAt(0);
            axes_[1] = inputSource_->axisInfoAt(1);
            axes_[2] = inputSource_->axisInfoAt(2);
        }

        cacheUpdateRequired_ = true;
        cachedData_ = QVector<double>(size().product());

        setDescription(QString("%1 Summed (over %2)")
                       .arg(inputSource_->name())
                       .arg(inputSource_->axisInfoAt(sumAxis_).name));

        connect(inputSource_->signalSource(), SIGNAL(valuesChanged(AMnDIndex,AMnDIndex)), this, SLOT(onInputSourceValuesChanged(AMnDIndex,AMnDIndex)));
        connect(inputSource_->signalSource(), SIGNAL(sizeChanged(int)), this, SLOT(onInputSourceSizeChanged()));
        connect(inputSource_->signalSource(), SIGNAL(stateChanged(int)), this, SLOT(onInputSourceStateChanged()));

    }
Esempio n. 23
0
AM1DSummingAB::AM1DSummingAB(const QString &outputName, QObject *parent)
	: AMStandardAnalysisBlock(outputName, parent)
{
	axes_ << AMAxisInfo("invalid", 0, "No input data");
	setState(AMDataSource::InvalidFlag);
}
bool VESPERS2011XASFileLoaderPlugin::load(AMScan *scan, const QString &userDataFolder, AMErrorMon *errorMonitor)
{
	// Check for null scan reference.
	if (!scan)
		return false;

	QFileInfo sourceFileInfo(scan->filePath());
	if(sourceFileInfo.isRelative())
		sourceFileInfo.setFile(userDataFolder + "/" + scan->filePath());

	QFile file(sourceFileInfo.filePath());
	if(!file.open(QIODevice::ReadOnly)) {
		errorMonitor->exteriorReport(AMErrorReport(0, AMErrorReport::Serious, VESPERS2011XASFILELOADERPLUGIN_CANNOT_OPEN_FILE, "XASFileLoader parse error while loading scan data from file."));
		return false;
	}

	QString temp = sourceFileInfo.filePath();
	temp.replace(".dat", ".cdf");
	AMCDFDataStore *cdfData = new AMCDFDataStore(temp, false);
	cdfData->addScanAxis( AMAxisInfo("eV", 0, "Incident Energy", "eV") );

	QTextStream in(&file);
	QString line;
	QStringList lineTokenized;

	// Need to determine if the single element or four element vortex detector was used.  Also need to determine which ion chambers were used for I0 and It.
	// First two lines are useless.
	line = in.readLine();
	line = in.readLine();

	line = in.readLine();

	if (line.contains("#(2)"))
		line = in.readLine();

	bool usingSingleElement = line.contains("IOC1607-004");
	bool usingFourElement = line.contains("dxp1607-B21-04");

	while ((line = in.readLine()).contains("#")){
		//Do nothing
	}

	// Clear any old data so we can start fresh.
	scan->clearRawDataPointsAndMeasurements();

	// Some setup variables.
	int axisValueIndex = 0;
	int count = scan->rawDataSourceCount();
	// Note!  Not general!
	QList<AMAxisInfo> axisInfo;
	AMAxisInfo ai("Energy", 2048, "Energy", "eV");
	ai.increment = 10;
	ai.start = AMNumber(0);
	ai.isUniform = true;
	axisInfo << ai;

	if (usingSingleElement && usingFourElement){

		// The last 6 raw data sources are spectra.
		for (int i = 0; i < count-6; i++)
			cdfData->addMeasurement(AMMeasurementInfo(scan->rawDataSources()->at(i)->name(), scan->rawDataSources()->at(i)->description()));

		for (int i = count-6; i < count; i++)
			cdfData->addMeasurement(AMMeasurementInfo(scan->rawDataSources()->at(i)->name(), scan->rawDataSources()->at(i)->description(), "eV", axisInfo));
	}

	else if (usingSingleElement){

		// The last raw data source is a spectrum.
		for (int i = 0; i < count-1; i++)
			cdfData->addMeasurement(AMMeasurementInfo(scan->rawDataSources()->at(i)->name(), scan->rawDataSources()->at(i)->description()));

		cdfData->addMeasurement(AMMeasurementInfo(scan->rawDataSources()->at(scan->rawDataSourceCount()-1)->name(), scan->rawDataSources()->at(scan->rawDataSourceCount()-1)->description(), "eV", axisInfo));
	}

	else if (usingFourElement){

		// The last 5 raw data sources are spectra.
		for (int i = 0; i < count-5; i++)
			cdfData->addMeasurement(AMMeasurementInfo(scan->rawDataSources()->at(i)->name(), scan->rawDataSources()->at(i)->description()));

		for (int i = count-5; i < count; i++)
			cdfData->addMeasurement(AMMeasurementInfo(scan->rawDataSources()->at(i)->name(), scan->rawDataSources()->at(i)->description(), "eV", axisInfo));
	}

	else{

		for (int i = 0; i < count; i++)
			cdfData->addMeasurement(AMMeasurementInfo(scan->rawDataSources()->at(i)->name(), scan->rawDataSources()->at(i)->description()));
	}

	QStringList fileLines;
	fileLines << line;

	while(!in.atEnd())
		fileLines << in.readLine();

	file.close();

	// Add in the data at the right spot.
	cdfData->beginInsertRows(fileLines.size(), -1);

	foreach(QString currentLine, fileLines){

		lineTokenized = currentLine.split(", ");

		cdfData->setAxisValue(0, axisValueIndex, lineTokenized.at(1).toDouble());

		// This isn't the most efficient way of putting the spectra data in, but it will do for the time being.
		if (usingSingleElement && usingFourElement){

			// Only going to rawDataSourceCount-6 because the last 6 raw data sources are the 2D spectra scan and requires its own method of entering the data.
			for (int i = 0; i < count-6; i++)
				cdfData->setValue(axisValueIndex, i, AMnDIndex(), lineTokenized.at(i+2).toDouble());
		}

		else if (usingSingleElement){

			// Only going to rawDataSourceCount-1 because the last raw data source is the 2D spectra scan and requires its own method of entering the data.
			for (int i = 0; i < count-1; i++)
				cdfData->setValue(axisValueIndex, i, AMnDIndex(), lineTokenized.at(i+2).toDouble());
		}

		else if (usingFourElement){

			// Only going to rawDataSourceCount-5 because the last 5 raw data sources are the 2D spectra scan and requires its own method of entering the data.
			for (int i = 0; i < count-5; i++)
				cdfData->setValue(axisValueIndex, i, AMnDIndex(), lineTokenized.at(i+2).toDouble());
		}

		else{

			// In transmission, there is no 2D spectra.  Go through all the data sources.
			for (int i = 0; i < count; i++)
				cdfData->setValue(axisValueIndex, i, AMnDIndex(), lineTokenized.at(i+2).toDouble());
		}

		axisValueIndex++;
	}
Esempio n. 25
0
SGMXASScanController::SGMXASScanController(SGMXASScanConfiguration *cfg){
	config_ = cfg;
	initializationActions_ = 0; //NULL
	cleanUpActions_ = 0; //NULL
	beamlineInitialized_ = false;

	specificScan_ = new AMXASScan();
	specificScan_->setFileFormat("sgm2011XAS");
	specificScan_->setRunId(AMUser::user()->currentRunId());
	specificScan_->setScanConfiguration(config_);
	specificScan_->setSampleId(SGMBeamline::sgm()->currentSampleId());
	specificScan_->setIndexType("fileSystem");
	specificScan_->rawData()->addScanAxis(AMAxisInfo("eV", 0, "Incident Energy", "eV"));

	QString scanName;
	QString sampleName;
	if(specificScan_->sampleId() == -1)
		sampleName = "Unknown Sample";
	else
		sampleName = AMSamplePre2013(specificScan_->sampleId(), AMUser::user()->database()).name();
	if(config_->userScanName() == ""){
		scanName = config_->autoScanName();
		specificScan_->setName(QString("%1 - %2").arg(sampleName).arg(scanName));
	}
	else{
		scanName = config_->userScanName();
		specificScan_->setName(QString("%1 - %2").arg(scanName).arg(sampleName));
	}

	// Create space in raw data store, and create raw data channels, for each detector.
	for(int i = 0; i < config_->allDetectorConfigurations().count(); i++){
		AMOldDetectorInfo* detectorInfo = config_->allDetectorConfigurations().detectorInfoAt(i);
		if(config_->allDetectorConfigurations().isActiveAt(i)){

			if(specificScan_->rawData()->addMeasurement(AMMeasurementInfo(*detectorInfo)))
				specificScan_->addRawDataSource(new AMRawDataSource(specificScan_->rawData(), specificScan_->rawData()->measurementCount()-1));
			else
				AMErrorMon::alert(0, SGMXASSCANCONTROLLER_CANNOT_ADD_MEASUREMENT, QString("Could not add measurement to SGMXASScanController by name %1").arg(detectorInfo->name()) );
		}
	}

	QList<AMDataSource*> raw1DDataSources;
	for(int i=0; i<specificScan_->rawDataSources()->count(); i++)
		if(specificScan_->rawDataSources()->at(i)->rank() == 1)
			raw1DDataSources << specificScan_->rawDataSources()->at(i);

	int rawTeyIndex = specificScan_->rawDataSources()->indexOfKey(SGMBeamline::sgm()->teyDetector()->description().remove(" "));
	int rawTfyIndex = specificScan_->rawDataSources()->indexOfKey(SGMBeamline::sgm()->tfyDetector()->description().remove(" "));
	int rawI0Index = specificScan_->rawDataSources()->indexOfKey(SGMBeamline::sgm()->i0Detector()->description().remove(" "));

	if(rawTeyIndex != -1 && rawI0Index != -1) {
		AM1DExpressionAB* teyChannel = new AM1DExpressionAB(QString("%1Norm").arg(SGMBeamline::sgm()->teyDetector()->description().remove(" ")));
		teyChannel->setDescription("Normalized TEY");
		teyChannel->setInputDataSources(raw1DDataSources);
		teyChannel->setExpression(QString("%1/%2").arg(SGMBeamline::sgm()->teyDetector()->description().remove(" ")).arg(SGMBeamline::sgm()->i0Detector()->description().remove(" ")));

		specificScan_->addAnalyzedDataSource(teyChannel);
	}

	if(rawTfyIndex != -1 && rawI0Index != -1) {
		AM1DExpressionAB* tfyChannel = new AM1DExpressionAB(QString("%1Norm").arg(SGMBeamline::sgm()->tfyDetector()->description().remove(" ")));
		tfyChannel->setDescription("Normalized TFY");
		tfyChannel->setInputDataSources(raw1DDataSources);
		tfyChannel->setExpression(QString("%1/%2").arg(SGMBeamline::sgm()->tfyDetector()->description().remove(" ")).arg(SGMBeamline::sgm()->i0Detector()->description().remove(" ")));

		specificScan_->addAnalyzedDataSource(tfyChannel);
	}

	/*
	if(SGMBeamline::sgm()->pgtDetector()){
		int rawSddIndex = specificScan_->rawDataSources()->indexOfKey(SGMBeamline::sgm()->pgtDetector()->description().remove(" "));
		if(rawSddIndex != -1) {
			AMRawDataSource* sddRaw = specificScan_->rawDataSources()->at(rawSddIndex);
			AM2DSummingAB* pfy = new AM2DSummingAB("PFY");
			QList<AMDataSource*> pfySource;
			pfySource << sddRaw;
			pfy->setInputDataSources(pfySource);
			pfy->setSumAxis(1);
			pfy->setSumRangeMax(sddRaw->size(1)-1);
			specificScan_->addAnalyzedDataSource(pfy);
			if(rawSddIndex != -1 && rawI0Index != -1) {
				AM1DExpressionAB* ipfyChannel = new AM1DExpressionAB(QString("IPFY"));
				ipfyChannel->setDescription("IPFY");
				QList<AMDataSource*> ipfySources;
				ipfySources.append(raw1DDataSources);
				ipfySources.append(pfy);
				ipfyChannel->setInputDataSources(ipfySources);
				ipfyChannel->setExpression(QString("%1/%2").arg(SGMBeamline::sgm()->i0Detector()->description().remove(" ")).arg("PFY"));

				specificScan_->addAnalyzedDataSource(ipfyChannel);
			}
		}
	}
	*/

	if(SGMBeamline::sgm()->oos65000Detector()){
		int rawOOSIndex = specificScan_->rawDataSources()->indexOfKey(SGMBeamline::sgm()->oos65000Detector()->description().remove('\n'));
		if(rawOOSIndex != -1) {
			AMRawDataSource* oosRaw = specificScan_->rawDataSources()->at(rawOOSIndex);
			AM2DSummingAB* ply = new AM2DSummingAB("PLY");
			QList<AMDataSource*> plySource;
			plySource << oosRaw;
			ply->setInputDataSources(plySource);
			ply->setSumAxis(1);
			ply->setSumRangeMax(oosRaw->size(1)-1);
			specificScan_->addAnalyzedDataSource(ply);
			if(rawOOSIndex != -1 && rawI0Index != -1) {
				AM1DExpressionAB* plyNormChannel = new AM1DExpressionAB(QString("PLYNorm"));
				plyNormChannel->setDescription("PLYNorm");
				QList<AMDataSource*> plyNormSources;
				plyNormSources.append(raw1DDataSources);
				plyNormSources.append(ply);
				plyNormChannel->setInputDataSources(plyNormSources);
				plyNormChannel->setExpression(QString("%1/%2").arg("PLY").arg(SGMBeamline::sgm()->i0Detector()->description().remove(" ")));

				specificScan_->addAnalyzedDataSource(plyNormChannel);
			}
		}
	}
}