mcsas.mcsas.mcsas module

class McSAS[source]

Bases: bases.algorithm.algorithmbase.AlgorithmBase

Main class containing all functions required to do Monte Carlo fitting.

Required:

  • data: The dataset to fit.
    Has to be an instance of :py:class:SASData
  • model: The scattering model object to assume.
    It has to be an instance of ScatteringModel.

For more settings, see mcsas/mcsasparameters.json

Returns:

A McSAS object with the following Results stored in the result member attribute. These can be extracted using McSAS.result[<parameterIndexNumber>][‘<Keyword>’] where the parameterIndexNumber indicates which shape parameter information is requested. E.g. an ellipsoid has 3: width, height and orientation. (Some information is only stored in parameterIndexNumber = 0 (default)).

Keyword may be one of the following:

fitMeasValMean: 1D array (common result)
The fitted measVal, given as the mean of all numReps Results.
fitX0: 1D array (common result)
Corresponding q values (may be different than the input q if X0Bounds was used).
fitMeasValStd: array (common result)
Standard deviation of the fitted I(q), calculated as the standard deviation of all numReps results.
contribs: size array (numContribs x numReps) (common result)
Collection of numContribs contributions fitted to best represent the provided I(q) data. Contains the Results of each of numReps iterations. This can be used for rebinning without having to re-optimize.
scalingFactors: size array (2 x numReps) (common result)
Scaling and background values for each repetition. Used to display background level in data and fit plot.
histogramXLowerEdge: array
histogram bin left edge position (x-axis in histogram).
histogramXMean: array
Center positions for the size histogram bins (x-axis in histogram, used for errorbars).
histogramXWidth: array
histogram bin width (x-axis in histogram, defines bar plot bar widths).
volumeHistogramYMean: array
Volume-weighted particle size distribution values for all numReps Results (y-axis bar height).
numberHistogramYMean: array
Number-weighted analogue of the above volumeHistogramYMean.
volumeHistogramRepetitionsY: size array (self.histogramBins x numReps)
Volume-weighted particle size distribution bin values for each fit repetition (the mean of which is volumeHistogramYMean, and the sample standard deviation is volumeHistogramYStd).
numberHistogramRepetitionsY: size array (self.histogramBins x numReps)
Number-weighted particle size distribution bin values for each MC fit repetition.
volumeHistogramYStd: array
Standard deviations of the corresponding volume-weighted size distribution bins, calculated from numReps repetitions of the model fitting function.
numberHistogramYStd: array
Standard deviation for the number-weigthed distribution.
volumeFraction: size array (numContribs x numReps)
Volume fractions for each of numContribs contributions in each of numReps iterations.
numberFraction: size array (numContribs x numReps)
Number fraction for each contribution.
totalVolumeFraction: size array (numReps)
Total scatterer volume fraction for each of the numReps iterations.
totalNumberFraction: size array (numReps)
Total number fraction.
minimumRequiredVolume: size array (numContribs x numReps)
Minimum required volume fraction for each contribution to become statistically significant.
minimumRequiredNumber: size array (numContribs x numReps)
Number-weighted analogue to minimumRequiredVolume.
volumeHistogramMinimumRequired: size array (histogramXMean)
Array with the minimum required volume fraction per bin to become statistically significant. Used to display minimum required level in histogram.
numberHistogramMinimumRequired: size array (histogramXMean)
Number-weighted analogue to volumeHistogramMinimumRequired.
scalingFactors: size array (2 x numReps)
Scaling and background values for each repetition. Used to display background level in data and fit plot.
totalVolumeFraction: size array (numReps)
Total scatterer volume fraction for each of the numReps iterations.
minimumRequiredVolume: size array (numContribs x numReps)
Minimum required volube fraction for each contribution to become statistically significant.
volumeHistogramMinimumRequired: size array (histogramXMean)
Array with the minimum required volume fraction per bin to become statistically significant. Used to display minimum required level in histogram.

Creates instances from defined parameters and replaces the class attributes accordingly.

analyse()[source]

This function runs the Monte Carlo optimisation a multitude (numReps) of times. If convergence is not achieved, it will try again for a maximum of maxRetries attempts.

calc(**kwargs)[source]

Warning

method ‘mcsas.mcsas.McSAS.calc’ undocumented

data = None
classmethod factory()[source]

Warning

method ‘mcsas.mcsas.McSAS.factory’ undocumented

gen2DMeasVal()[source]

This function is optionally run after the histogram procedure for anisotropic images, and will calculate the MC fit measVal in image form

histogram(contribs=None)[source]

Takes the contribs result from the McSAS.analyse() function and calculates the corresponding volume- and number fractions for each contribution as well as the minimum observability limits. It will subsequently bin the Result across the range for histogramming purposes.

While the volume-weighted distribution will be in absolute units (providing volume fractions of material within a given size range), the number distributions have been normalized to 1.

Output a list of dictionaries with one dictionary per shape parameter:

histogramXLowerEdge: array
histogram bin left edge position (x-axis in histogram)
histogramXMean: array
Center positions for the size histogram bins (x-axis in histogram, used for errorbars)
histogramXWidth: array
histogram bin width (x-axis in histogram, defines bar plot bar widths)
volumeHistogramYMean: array
Volume-weighted particle size distribution values for all numReps Results (y-axis bar height)
numberHistogramYMean: array
Number-weighted analogue of the above volumeHistogramYMean
volumeHistogramRepetitionsY: size (histogramBins x numReps)
array Volume-weighted particle size distribution bin values for each MC fit repetition (whose mean is volumeHistogramYMean, and whose sample standard deviation is volumeHistogramYStd)
numberHistogramRepetitionsY: size (histogramBins x numReps)
array Number-weighted particle size distribution bin values for each MC fit repetition
volumeHistogramYStd: array
Standard deviations of the corresponding volume-weighted size distribution bins, calculated from numReps repetitions of the model fitting function
numberHistogramYStd: array
Standard deviation for the number-weigthed distribution
volumeFraction: size (numContribs x numReps) array
Volume fractions for each of numContribs contributions in each of numReps iterations
numberFraction: size (numContribs x numReps) array
Number fraction for each contribution
totalVolumeFraction: size (numReps) array
Total scatterer volume fraction for each of the numReps iterations
totalNumberFraction: size (numReps) array
Total number fraction
minimumRequiredVolume: size (numContribs x numReps) array
minimum required volume fraction for each contribution to become statistically significant.
minimumRequiredNumber: size (numContribs x numReps) array
number-weighted analogue to minimumRequiredVolume
volumeHistogramMinimumRequired: size (histogramXMean) array
array with the minimum required volume fraction per bin to become statistically significant. Used to display minimum required level in histogram.
numberHistogramMinimumRequired: size (histogramXMean) array
number-weighted analogue to volumeHistogramMinimumRequired
scalingFactors: size (2 x numReps) array
Scaling and background values for each repetition. Used to display background level in data and fit plot.
mcFit(numContribs, minConvergence, outputMeasVal=False, outputDetails=False, nRun=None)[source]

Object-oriented, shape-flexible core of the Monte Carlo procedure. Takes optional arguments:

outputMeasVal:
Returns the fitted measVal besides the Result
outputDetails:
details of the fitting procedure, number of iterations and so on
nRun: “serial number” of run. Used to store results in parameters
in the right place
model = None
plot(axisMargin=0.3, outputFilename=None, autoClose=False)[source]

Expects outputFilename to be of type gui.calc.OutputFilename.

result = None
array(value)

Warning

function ‘mcsas.mcsas.array’ undocumented