Skip to content

Commit

Permalink
Corrected files' mode. Refs #9573.
Browse files Browse the repository at this point in the history
  • Loading branch information
wdzhou committed Jun 19, 2014
1 parent 853d97f commit 54f59fd
Show file tree
Hide file tree
Showing 11 changed files with 6,215 additions and 13 deletions.
34 changes: 34 additions & 0 deletions Code/Mantid/docs/source/algorithms/CreateLeBailFitInput-v1.rst
Expand Up @@ -43,4 +43,38 @@ This algorithm is designed to work with other algorithms to do Le Bail
fit. The introduction can be found in the wiki page of `Le Bail
Fit <Le Bail Fit>`__.

Usage
-----

**Example - create inputs for LeBail fit of Pg3:**

.. testcode:: ExCreateLBInputs

CreateLeBailFitInput(ReflectionsFile=r'LB4854b3.hkl',
FullprofParameterFile=r'2013A_HR60b3.irf',
Bank='3',
LatticeConstant='4.1568899999999998',
InstrumentParameterWorkspace='PG3_Bank3_ParTable',
BraggPeakParameterWorkspace='LaB6_HKL_Table')

# Examine
partablews = mtd["PG3_Bank3_ParTable"]
braggtablews = mtd["LaB6_HKL_Table"]
print "Number Bragg peaks from .hkl file is %d. Number of peak profile parameters is %d. " % ( braggtablews.rowCount(), partablews.rowCount())


.. testcleanup:: ExCreateLBInputs

DeleteWorkspace(partablews)
DeleteWorkspace(braggtablews)
DeleteWorkspace("TempXXX")


Output:

.. testoutput:: ExCreateLBInputs

Number Bragg peaks from .hkl file is 76. Number of peak profile parameters is 30.


.. categories::
45 changes: 45 additions & 0 deletions Code/Mantid/docs/source/algorithms/ExportExperimentLog-v1.rst
Expand Up @@ -72,4 +72,49 @@ must have an extension as ".csv". If a user gives the name of a log
file, which is in csv format, does not have an extension as .csv, the
algorithm will correct it automatically.

Usage
-----

**Example - Export several experiment logs to a csv file:**

.. testcode:: ExExportExpLogs

import os

nxsfilename = "HYS_11092_event.nxs"
wsname = "HYS_11092_event"

savefile = os.path.join(config["default.savedirectory"], "testlog.txt")
print "default save directory: ", config["default.savedirectory"]
print "File %s created: %s" %(savefile, str(os.path.exists(savefile)))


Load(Filename = nxsfilename,
OutputWorkspace = wsname,
MetaDataOnly = True,
LoadLogs = True)

ExportExperimentLog(
InputWorkspace = wsname,
OutputFilename = savefile,
FileMode = "new",
SampleLogNames = "run_start, run_title",
SampleLogTitles = "AA, BB",
SampleLogOperation = "None, None",
FileFormat = "tab",
TimeZone = "America/New_York")

.. testcleanup:: ExExportExpLogs

import os
os.remove(savefile)


Output:

.. testoutput:: ExExportExpLogs


.. categories::


Expand Up @@ -25,4 +25,53 @@ CSV File format
- Column 2 to (2 + n) - 1: log values in the order determined by input
*SampleLogNames*

Usage
-----

**Example - Export a time series sample log to a tsv file:**

.. testcode:: ExExportSampleToTSV

import os

nxsfilename = "/Users/wzz/Mantid/Test/AutoTestData/UsageData/HYS_11092_event.nxs"
wsname = "HYS_11092_event"

savefile = os.path.join(config["default.savedirectory"], "testphase4.txt")
print "default save directory: ", config["default.savedirectory"]
print "File %s created: %s" %(savefile, str(os.path.exists(savefile)))


Load(Filename = nxsfilename,
OutputWorkspace = wsname,
MetaDataOnly = True,
LoadLogs = True)

ExportSampleLogsToCSVFile(
InputWorkspace = wsname,
OutputFilename = savefile,
SampleLogNames = "Phase1, Phase2, Phase3, Phase4",
WriteHeaderFile = True,
Header = "Test sample log: Phase1-Phase4",
TimeZone = "America/New_York",
TimeTolerance = 0.01)



.. testcleanup:: ExExportSampleToTSV

import os

headerfilename = os.path.join(config["default.savedirectory"], "testphase4_header.txt")
os.remove(savefile)
os.remove(headerfilename)


Output:

.. testoutput:: ExExportSampleToTSV




.. categories::
126 changes: 113 additions & 13 deletions Code/Mantid/docs/source/algorithms/FitPeak-v1.rst
Expand Up @@ -20,17 +20,85 @@ Subalgorithms used

- Fit

Treating weak peaks vs. high background
#######################################

FindPeaks uses a more complicated approach to fit peaks if
**HighBackground** is flagged. In this case, FindPeak will fit the
background first, and then do a Gaussian fit the peak with the fitted
background removed. This procedure will be repeated for a couple of
times with different guessed peak widths. And the parameters of the best
result is selected. The last step is to fit the peak with a combo
function including background and Gaussian by using the previously
recorded best background and peak parameters as the starting values.
Input and Output
################

FitPeak is designed to fit the parameters of a peak function with background function in a given region.
In order to provide convenient UI to both user interactively and algorithms calling this algorithm automatically,
a various formats for the input of the starting values of functions and output of the fitted values of the functions are
implemented.

Peak profile
############

All peak profiles supported by Mantid are supported by FitPeak.

Starting parameter values specified by user should be close to the real values,
unless the automatic starting values determination algorithm works well with that
profile type.

But only [[Gaussian]] has been well tested with this functionalities.

Background
##########

There are only three types of backgrounds that are supported, including
FlatBackground, LinearBackground and Quadratic.

Default function parameters' names
##################################

Input function parameters' names should be exactly the same as those defined in Mantid.
This brings some inconvenience to users through MantidPlot GUI.
Thus user can input function parameters values in the default order,
which is instructed in the list of functions.
For example, one background function type is defined as 'Linear (A0, A1)'.
As user chooses this function, he does not need to input background function parameter names,
but writes values of A0 and A1, respectively.

Output of function parameters
#############################

The output [[TableWorkspace]] contains the following columns...
* parameter name
* fitted parameter value
* error


Fitting algorithm
#################

FindPeaks uses a more complicated approach to fit peaks if '''HighBackground''' is flagged. In this case, FindPeak will fit the background first, and then do a Gaussian fit the peak with the fitted background removed. This procedure will be repeated for a couple of times with different guessed peak widths. And the parameters of the best result is selected. The last step is to fit the peak with a combo function including background and Gaussian by using the previously recorded best background and peak parameters as the starting values.

Simple fit
##########
In the 'simple fit' mode, the algorithm will make a composite function including
peak and background function and fit it agains the observed data.

It works well with good starting values of the peak and background function,
especially when the peak is significant with low background.


High background fit
###################

In the 'high background fit' mode, the background will be removed first;
then the fitting is focussed on the 'pure' peak function;
and a composite function is fit agains the original data as the last step.

This approach is developed due to the failure of 'simple fit' mode on the cases
that background level is much higher than the peak height.
Without the background being removed, the optimizer intends to favor the background
rather than the peak function.


Starting values of the peak function
####################################

* Peak height is estimated by the maximum value, with background removed, inside the peak range;
* Peak position can be set up either to the X value of the maximum Y value in the peak range, or to the vlaue specified by user accordin to user's selection. For example, in the case of calibrating the offsets of detectors of powder diffractometers, the peak positons are unknown. Then it is better to use the X value with the maximum Y value as the starting peak centre. While in the case of striping vanadium peaks, all peaks' centres should be exactly same as the theortical values.



Criteria To Validate Peaks Found
################################
Expand All @@ -46,6 +114,9 @@ fitted peak position must be within a short distance to the give one.
2. Peak height. In the certain number of trial, peak height can be used
to select the best fit among various starting sigma values.

3. Peak width: Peak width cannot be equal or wider than the given fit window.


Fit Window and Peak Range
#########################

Expand All @@ -58,7 +129,36 @@ FitPeak might be able to estimate the peak centre in this situation by
locating the X-value whose corresponding Y-value is largest within
user-defined peak range.

What's new
----------
-----

**Example - Fit a single peak with rough estimation on staring parameter values:**

.. testcode:: ExFitPeak

Load(Filename=r'focussed.nxs', OutputWorkspace='focussed')
FitPeak(InputWorkspace='focussed', OutputWorkspace='peak4', ParameterTableWorkspace='peak4result',
WorkspaceIndex='3',PeakFunctionType='Gaussian (Height, PeakCentre, Sigma)',
PeakParameterValues='2000,2.1,0.01',BackgroundType='Linear (A0, A1)',
BackgroundParameterValues='2500,2000',FitWindow='2,2.3',PeakRange='2.1,2.25')

tbws = mtd["peak4result"]
chi2 = tbws.cell(0, 1)
peakcentre = tbws.cell(2, 1)
peakheight = tbws.cell(3, 1)
sigma = tbws.cell(4, 1)
print "Chi-square = %f: Peak centre = %f, Height = %f, Sigma = %f " % (chi2, peakcentre, peakheight, sigma)


.. testcleanup:: ExFitPeak

DeleteWorkspace(Workspace='focussed')
DeleteWorkspace(Workspace=tbws)

Output:

.. testoutput:: ExFitPeak

Chi-square = 7.138740: Peak centre = 8365.836316, Height = 2.141713, Sigma = 0.005644


.. categories::
71 changes: 71 additions & 0 deletions Code/Mantid/docs/source/algorithms/LoadFullprofFile-v1.rst
Expand Up @@ -43,4 +43,75 @@ This algorithm is designed to work with other algorithms to do Le Bail
fit. The introduction can be found in the wiki page of
:ref:`algm-LeBailFit`.


Usage
-----

**Example - load a Fullprof .prf file:**

.. testcode:: ExLoadPrf

LoadFullprofFile(Filename=r'LaB6_1bank3_C.prf',
PeakParameterWorkspace='LaB6_InfoTable',
OutputWorkspace='PG3_LaB6_Bank3')

infotablews = mtd["LaB6_InfoTable"]
dataws = mtd["PG3_LaB6_Bank3"]

print "LaB6: A = B = C = %.5f, Alpha = Beta = Gamma = %.5f" % (infotablews.cell(0, 1), infotablews.cell(5, 1))

maxy = max(dataws.readY(1))
print "Maximum peak value (calculated) = %.5f" % (maxy)


.. testcleanup:: ExLoadPrf

DeleteWorkspace(infotablews)
DeleteWorkspace(dataws)

Output:

.. testoutput:: ExLoadPrf

Data set counter = 5431
Data Size = 5431
LaB6: A = B = C = 4.15689, Alpha = Beta = Gamma = 90.00000
Maximum peak value (calculated) = 13.38550

**Example - load a Fullprof .irf file:**

.. testcode:: ExLoadIrf

LoadFullprofFile(Filename=r'LB4854b3.hkl',
PeakParameterWorkspace='LaB6_Ref_Table',
OutputWorkspace='Fake')

fakedataws = mtd["Fake"]
reftablews = mtd["LaB6_Ref_Table"]

print "Reflection table imported %d peaks. Faked data workspace contains %d data points." % (
reftablews.rowCount(), len(fakedataws.readX(0)))

index = 0
print "Peak %d of (%d, %d, %d): Alpha = %.5f, Beta = %.5f, FWHM = %.5f" % (index, reftablews.cell(index, 0),
reftablews.cell(index, 1), reftablews.cell(index, 2), reftablews.cell(index, 3), reftablews.cell(index, 4), reftablews.cell(index, 7))
index = 75
print "Peak %d of (%d, %d, %d): Alpha = %.5f, Beta = %.5f, FWHM = %.5f" % (index, reftablews.cell(index, 0),
reftablews.cell(index, 1), reftablews.cell(index, 2), reftablews.cell(index, 3), reftablews.cell(index, 4), reftablews.cell(index, 7))


.. testcleanup:: ExLoadIrf

DeleteWorkspace(fakedataws)
DeleteWorkspace(reftablews)

Output:

.. testoutput:: ExLoadIrf

Import Fullprof reflection file /Users/wzz/Projects/Tickets/Doc/LeBailFit_Related/Test2013D_August/Reflections/LB4854b3.hkl successfully.
Reflection table imported 76 peaks. Faked data workspace contains 1 data points.
Peak 0 of (1, 1, 0): Alpha = 0.01963, Beta = 0.01545, FWHM = 289.07450
Peak 75 of (9, 3, 0): Alpha = 0.25569, Beta = 0.13821, FWHM = 14.67480

.. categories::

0 comments on commit 54f59fd

Please sign in to comment.