Skip to content

Commit

Permalink
refs #8733. Merge master in and fix conflicts on branch.
Browse files Browse the repository at this point in the history
Merge branch 'master' into feature/8733_polarisation_correction_gui

Conflicts:
	Code/Mantid/scripts/Interface/ui/reflectometer/refl_gui.py
	Code/Mantid/scripts/Reflectometry/isis_reflectometry/quick.py
  • Loading branch information
OwenArnold committed Jan 31, 2014
2 parents 68a6927 + 6e2023f commit bcfe764
Show file tree
Hide file tree
Showing 85 changed files with 4,029 additions and 2,816 deletions.
2 changes: 2 additions & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/ExperimentInfo.h
Expand Up @@ -120,6 +120,8 @@ namespace API
void saveExperimentInfoNexus(::NeXus::File * file) const;
/// Loads an experiment description from the open NeXus file
void loadExperimentInfoNexus(::NeXus::File * file, std::string & parameterStr);
/// Load the instrument from an open NeXus file.
void loadInstrumentInfoNexus(::NeXus::File * file, std::string & parameterStr);
/// Load the sample and log info from an open NeXus file.
void loadSampleAndLogInfoNexus(::NeXus::File * file);
/// Populate the parameter map given a string
Expand Down
14 changes: 13 additions & 1 deletion Code/Mantid/Framework/API/src/ExperimentInfo.cpp
Expand Up @@ -899,6 +899,19 @@ namespace API
// load sample and log info
loadSampleAndLogInfoNexus(file);

loadInstrumentInfoNexus(file, parameterStr);
}

//--------------------------------------------------------------------------------------------
/** Load the instrument from an open NeXus file.
* @param file :: open NeXus file
* @param[out] parameterStr :: special string for all the parameters.
* Feed that to ExperimentInfo::readParameterMap() after the instrument is done.
* @throws Exception::NotFoundError If instrument definition is not in the nexus file and cannot
* be loaded from the IDF.
*/
void ExperimentInfo::loadInstrumentInfoNexus(::NeXus::File * file, std::string & parameterStr)
{
std::string instrumentName;
std::string instrumentXml;
std::string instrumentFilename;
Expand Down Expand Up @@ -1003,7 +1016,6 @@ namespace API
}
}


//-------------------------------------------------------------------------------------------------
/** Parse the result of ParameterMap.asString() into the ParameterMap
* of the current instrument. The instrument needs to have been loaded
Expand Down
@@ -1,3 +1,12 @@
/*WIKI*
GSAS instrument is required to have exact 80 characters each line.
FixGSASInstrument will check the input GSAS instrument file whether each line of it will
have 80 characters. If any line contains fewer than 80 characters, this algorithm will fill
the line with space to 80 characters.
*WIKI*/

#include "MantidAlgorithms/FixGSASInstrumentFile.h"

#include "MantidAPI/FileProperty.h"
Expand Down
94 changes: 50 additions & 44 deletions Code/Mantid/Framework/Algorithms/src/ReflectometryWorkflowBase.cpp
Expand Up @@ -59,8 +59,9 @@ namespace Mantid
new PropertyWithValue<int>("I0MonitorIndex", Mantid::EMPTY_INT(), mandatoryWorkspaceIndex),
"I0 monitor index");

declareProperty(new PropertyWithValue<std::string>("ProcessingInstructions", "",
boost::make_shared<MandatoryValidator<std::string> >(), Direction::Input),
declareProperty(
new PropertyWithValue<std::string>("ProcessingInstructions", "",
boost::make_shared<MandatoryValidator<std::string> >(), Direction::Input),
"Processing instructions on workspace indexes to yield only the detectors of interest. See [[PerformIndexOperations]] for details.");
}

Expand Down Expand Up @@ -119,8 +120,7 @@ namespace Mantid
new PropertyWithValue<double>("StartOverlap", Mantid::EMPTY_DBL(), Direction::Input),
"Start wavelength for stitching transmission runs together");

declareProperty(
new PropertyWithValue<double>("EndOverlap", Mantid::EMPTY_DBL(), Direction::Input),
declareProperty(new PropertyWithValue<double>("EndOverlap", Mantid::EMPTY_DBL(), Direction::Input),
"End wavelength (angstroms) for stitching transmission runs together");

}
Expand Down Expand Up @@ -228,54 +228,61 @@ namespace Mantid
* Throws if any of the property values do not make sense.
* @param firstTransmissionInWavelength: Indicates that the first transmission run is in units of wavlength.
*/
void ReflectometryWorkflowBase::validateSecondTransmissionInputs(const bool firstTransmissionInWavelength) const
void ReflectometryWorkflowBase::validateSecondTransmissionInputs(
const bool firstTransmissionInWavelength) const
{
// Verify that all the required inputs for the second transmission run are now given.
if (isPropertyDefault("FirstTransmissionRun"))
{
throw std::invalid_argument(
"A SecondTransmissionRun is only valid if a FirstTransmissionRun is provided.");
if (firstTransmissionInWavelength)
{
this->g_log.warning(
"The first transmission run is in wavelength so is assumed to be correctly stitched in wavelength. "
"The second transmission run and associated inputs will be ignored."
"Run CreateTransmissionWorkspace to create a transmission workspace from TOF runs.");
return;
}
}
if (isPropertyDefault("Params"))
{
throw std::invalid_argument(
"If a SecondTransmissionRun has been given, then stitching Params for the transmission runs are also required.");
}
if (isPropertyDefault("StartOverlap"))
{
throw std::invalid_argument(
"If a SecondTransmissionRun has been given, then a stitching StartOverlap for the transmission runs is also required.");
}
if (isPropertyDefault("EndOverlap"))
{
throw std::invalid_argument(
"If a SecondTransmissionRun has been given, then a stitching EndOverlap for the transmission runs is also required.");
}
const double startOverlap = this->getProperty("StartOverlap");
const double endOverlap = this->getProperty("EndOverlap");
if (startOverlap >= endOverlap)
{
throw std::invalid_argument("EndOverlap must be > StartOverlap");
}

if( !isPropertyDefault("SecondTransmissionRun") )
else
{
throw std::invalid_argument(
"A SecondTransmissionRun is only valid if a FirstTransmissionRun is provided.");
}
}
else
{
MatrixWorkspace_sptr trans1 = this->getProperty("FirstTransmissionRun");
MatrixWorkspace_sptr trans2 = this->getProperty("SecondTransmissionRun");
if (isPropertyDefault("Params"))
{
throw std::invalid_argument(
"If a SecondTransmissionRun has been given, then stitching Params for the transmission runs are also required.");
}
if (isPropertyDefault("StartOverlap"))
{
throw std::invalid_argument(
"If a SecondTransmissionRun has been given, then a stitching StartOverlap for the transmission runs is also required.");
}
if (isPropertyDefault("EndOverlap"))
{
throw std::invalid_argument(
"If a SecondTransmissionRun has been given, then a stitching EndOverlap for the transmission runs is also required.");
}
const double startOverlap = this->getProperty("StartOverlap");
const double endOverlap = this->getProperty("EndOverlap");
if (startOverlap >= endOverlap)
{
throw std::invalid_argument("EndOverlap must be > StartOverlap");
}

auto firstMap = trans1->getSpectrumToWorkspaceIndexMap();
auto secondMap = trans2->getSpectrumToWorkspaceIndexMap();
if(firstMap != secondMap)
if (!isPropertyDefault("SecondTransmissionRun"))
{
throw std::invalid_argument("Spectrum maps differ between the transmission runs. They must be the same.");
MatrixWorkspace_sptr trans1 = this->getProperty("FirstTransmissionRun");
MatrixWorkspace_sptr trans2 = this->getProperty("SecondTransmissionRun");

auto firstMap = trans1->getSpectrumToWorkspaceIndexMap();
auto secondMap = trans2->getSpectrumToWorkspaceIndexMap();
if (firstMap != secondMap)
{
throw std::invalid_argument(
"Spectrum maps differ between the transmission runs. They must be the same.");
}
}
}

Expand Down Expand Up @@ -386,9 +393,9 @@ namespace Mantid
* @param wavelengthStep : Wavelength step for rebinning
* @return Detector workspace in wavelength
*/
MatrixWorkspace_sptr ReflectometryWorkflowBase::toLamDetector(
const std::string& processingCommands, const MatrixWorkspace_sptr& toConvert,
const MinMax& wavelengthMinMax, const double& wavelengthStep)
MatrixWorkspace_sptr ReflectometryWorkflowBase::toLamDetector(const std::string& processingCommands,
const MatrixWorkspace_sptr& toConvert, const MinMax& wavelengthMinMax,
const double& wavelengthStep)
{
// Process the input workspace according to the processingCommands to get a detector workspace
auto performIndexAlg = this->createChildAlgorithm("PerformIndexOperations");
Expand Down Expand Up @@ -438,9 +445,8 @@ namespace Mantid
* @return Tuple of detector and monitor workspaces
*/
ReflectometryWorkflowBase::DetectorMonitorWorkspacePair ReflectometryWorkflowBase::toLam(
MatrixWorkspace_sptr toConvert, const std::string& processingCommands,
const int monitorIndex, const MinMax& wavelengthMinMax, const MinMax& backgroundMinMax,
const double& wavelengthStep)
MatrixWorkspace_sptr toConvert, const std::string& processingCommands, const int monitorIndex,
const MinMax& wavelengthMinMax, const MinMax& backgroundMinMax, const double& wavelengthStep)
{
// Detector Workspace Processing
MatrixWorkspace_sptr detectorWS = toLamDetector(processingCommands, toConvert, wavelengthMinMax,
Expand Down
27 changes: 17 additions & 10 deletions Code/Mantid/Framework/CurveFitting/src/LeBailFit.cpp
Expand Up @@ -4,30 +4,37 @@ This algorithm performs [[Le Bail Fit]] to powder diffraction data, and also sup
This algorithm will refine a specified set of the powder instrumental profile parameters with a previous refined background model.
=== Peak profile function for fit ===
==== Back to back exponential convoluted with pseudo-voigt ====
Here is the list of the peak profile function supported by this algorithm.
* Thermal neutron back-to-back exponential convoluted with pseudo-voigt
** geometry-related parameters: Dtt1, Dtt2, Zero
** back-to-back exponential parameters: Alph0, Alph1, Beta0, Beta1
** pseudo-voigt parameters: Sig0, Sig1, Sig2, Gam0, Gam1, Gam2
==== Thermal neutron back to back exponential convoluted with pseudo-voigt ====
Here is the list of the peak profile function supported by this algorithm.
* Thermal neutron back-to-back exponential convoluted with pseudo-voigt
** geometry-related parameters: Dtt1, Zero, Dtt1t, Dtt2t, Width, Tcross
** back-to-back exponential parameters: Alph0, Alph1, Beta0, Beta1, Alph0t, Alph1t, Beta0t, Beta1t
** pseudo-voigt parameters: Sig0, Sig1, Sig2, Gam0, Gam1, Gam2
=== Optimization ===
''LeBailFit'' supports regular minimizes in GSL library and a tailored simulated annealing optimizer.
It is very difficult to achieve reasonable good result by non-linear minimizers such as Simplex or Levenber-Marquardt, because the parameters
''LeBailFit'' supports a tailored simulated annealing optimizer (using Monte Carlo random walk algorithm).
In future, regular minimizes in GSL library might be supported.
The experience to use non-linear minimizes such as Simplex or
=== Supported functionalities ===
* LeBailFit: fit profile parameters by Le bail algorithm;
* Calculation: pattern calculation by Le bail algorithm;
* MonteCarlo: fit profile parameters by Le bail algorithm with Monte Carlo random wal;
* RefineBackground: refine background parameters
=== Background ===
This algorithm does not refine background.
It takes a previous refined background model, for instance, from ProcessBackground().
Background fitting is not included in LeBailFit() because the mathematics problem is not well-defined
as peak heights are calculated but not refined but highly correlated to background model.
=== Further Information ===
See [[Le Bail Fit]].
*WIKI*/

/* COMMIT NOTES *
1. Rename calculateDiffractionPatternMC to calculateDiffractionPattern
2.
Expand Down
30 changes: 24 additions & 6 deletions Code/Mantid/Framework/CurveFitting/src/ProcessBackground.cpp
@@ -1,17 +1,35 @@
/*WIKI*
The algorithm ProcessBackground() provides several functions for user to process background to prepare Le Bail Fit.
The algorithm ProcessBackground() provides several functions for user to process background to prepare Le Bail Fit.
==== Simple Remove Peaks ====
This algorithm is designed for refining the background based on the assumption that the all peaks have been fitted reasonably well. Then by removing the peaks by function 'X0 +/- n*FWHM', the rest data points are background in a very high probability.
An arbitrary background function can be fitted against this background by standard optimizer.
This algorithm is designed for refining the background based on the assumption that the all peaks have been fitted reasonably well. Then by removing the peaks by function 'X0 +/- n*FWHM', the rest data points are background in a very high probability.
An arbitrary background function can be fitted against this background by standard optimizer.
==== Automatic Background Points Selection ====
This feature is designed to select many background points with user's simple input.
User is required to select only a few background points in the middle of two adjacent peaks.
This feature is designed to select many background points with user's simple input.
User is required to select only a few background points in the middle of two adjacent peaks.
Algorithm will fit these few points (''BackgroundPoints'') to a background function of specified type.
== Examples ==
==== Selecting background ====
Here is a good example to select background points from a powder diffraction pattern by calling ProcessBackground() in a self-consistent manner.
1. Select a set of background points (X values only), which can roughly describes the background, manually;
2. Call ProcessBackground with Option='SelectBackgroundPoints' and SelectionMode='UserSpecifyBackground'.
A good choice for background function to enter is 6-th order polynomial;
3. Plot spectra 2 to 4 in UserBackgroundWorkspace to check whether 'Tolerance' is proper or not.
If not then reset the tolerance and run ProcessBackground again with previous setup;
4. Fit OutputWorkspace (the selected background) with a background function;
5. Call ProcessBackground with Option='SelectBackgroundPoints' and SelectionMode='UserFunction'.
Set the background parameter workspace as the output parameter table workspace obtained in the last step;
6. Repeat step 4 and 5 for a few times until the background plot by fitted background function
from selected background points is close enough to real background.
*WIKI*/
#include "MantidCurveFitting/ProcessBackground.h"
Expand Down
Expand Up @@ -5,6 +5,7 @@
// Includes
//----------------------------------------------------------------------
#include "MantidAPI/IFileLoader.h"
#include "MantidAPI/ITableWorkspace.h"

#include "MantidNexus/NexusClasses.h"
#include <nexus/NeXusFile.hpp>
Expand Down Expand Up @@ -92,6 +93,13 @@ namespace Mantid

API::Workspace_sptr loadTableEntry(Mantid::NeXus::NXEntry& entry);

/// Loads a vector column to the TableWorkspace.
template<typename Type>
void loadVectorColumn(const Mantid::NeXus::NXData& tableData,
const std::string& dataSetName,
const API::ITableWorkspace_sptr& tableWs,
const std::string& columnType);

API::Workspace_sptr loadPeaksEntry(Mantid::NeXus::NXEntry & entry);

API::MatrixWorkspace_sptr loadEventEntry(Mantid::NeXus::NXData & wksp_cls,Mantid::NeXus::NXDouble & xbins,
Expand Down
Expand Up @@ -75,7 +75,7 @@ void LoadIDFFromNexus::exec()
nxfile.openPath(instrumentParentPath);

std::string parameterString;
localWorkspace->loadExperimentInfoNexus( &nxfile, parameterString );
localWorkspace->loadInstrumentInfoNexus( &nxfile, parameterString );
localWorkspace->readParameterMap(parameterString);

runLoadParameterFile(localWorkspace);
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/DataHandling/src/LoadMcStas.cpp
Expand Up @@ -409,7 +409,7 @@ namespace DataHandling

// grap title to use to e.g. create workspace name
std::string nameAttrValueTITLE;
nxFile.getAttr("title", nameAttrValueTITLE);
nxFile.getAttr("filename", nameAttrValueTITLE);

if ( nxFile.hasAttr("ylabel") )
{
Expand Down

0 comments on commit bcfe764

Please sign in to comment.