forked from AmbaPant/mantid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Porod.py
53 lines (44 loc) · 1.48 KB
/
Porod.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Mantid Repository : https://github.com/mantidproject/mantid
#
# Copyright © 2007 ISIS Rutherford Appleton Laboratory UKRI,
# NScD Oak Ridge National Laboratory, European Spallation Source,
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
# pylint: disable=no-init,invalid-name
'''
@author Mathieu Doucet, ORNL
@date Oct 13, 2014
'''
import math
import numpy as np
from mantid.api import IFunction1D, FunctionFactory
class Porod(IFunction1D):
"""
Provide a Porod model for SANS
I(q) = C/q^4 + background
"""
def category(self):
return "SANS"
def init(self):
# Active fitting parameters
self.declareParameter("Scale", 1.0, 'Scale')
self.declareParameter("Background", 0.0, 'Background')
def function1D(self, xvals):
"""
Evaluate the model
@param xvals: numpy array of q-values
"""
return self.getParameterValue("Scale") * np.power(xvals, -4) + self.getParameterValue('Background')
def functionDeriv1D(self, xvals, jacobian):
"""
Evaluate the first derivatives
@param xvals: numpy array of q-values
@param jacobian: Jacobian object
"""
i = 0
for x in xvals:
jacobian.set(i, 0, math.pow(x, -4))
jacobian.set(i, 1, 1.0)
i += 1
# Required to have Mantid recognise the new function
FunctionFactory.subscribe(Porod)