[829eee9] | 1 | #!/usr/bin/env python |
---|
| 2 | """ |
---|
| 3 | Provide F(x) = 1/( scale + c1*(x)^(2)+ c2*(x)^(4)) + bkd |
---|
| 4 | Teubner-Strey function as a BaseComponent model |
---|
| 5 | |
---|
| 6 | """ |
---|
| 7 | |
---|
| 8 | from sans.models.BaseComponent import BaseComponent |
---|
| 9 | import math |
---|
| 10 | |
---|
| 11 | class TeubnerStreyModel(BaseComponent): |
---|
| 12 | |
---|
| 13 | """ |
---|
| 14 | Class that evaluates the TeubnerStrey model. |
---|
| 15 | |
---|
| 16 | F(x) = 1/( scale + c1*(x)^(2)+ c2*(x)^(4)) + bkd |
---|
| 17 | |
---|
| 18 | The model has Four parameters: |
---|
| 19 | scale = scale factor |
---|
| 20 | c1 = constant |
---|
| 21 | c2 = constant |
---|
| 22 | bkd = incoherent background |
---|
| 23 | """ |
---|
| 24 | |
---|
| 25 | def __init__(self): |
---|
| 26 | """ Initialization """ |
---|
| 27 | |
---|
| 28 | # Initialize BaseComponent first, then sphere |
---|
| 29 | BaseComponent.__init__(self) |
---|
| 30 | |
---|
| 31 | ## Name of the model |
---|
| 32 | self.name = "Teubner Strey" |
---|
[753552d] | 33 | self.description="""The TeubnerStrey model. |
---|
| 34 | F(x) = 1/( scale + c1*(x)^(2)+ c2*(x)^(4)) + bkd |
---|
| 35 | The model has Four parameters: |
---|
| 36 | scale = scale factor |
---|
| 37 | c1 = constant |
---|
| 38 | c2 = constant |
---|
| 39 | bkd = incoherent background""" |
---|
[829eee9] | 40 | ## Define parameters |
---|
| 41 | self.params = {} |
---|
| 42 | self.params['c1'] = -30.0 |
---|
| 43 | self.params['c2'] = 5000.0 |
---|
| 44 | self.params['scale'] = 0.1 |
---|
[3db3895] | 45 | self.params['background'] = 0.0 |
---|
[829eee9] | 46 | |
---|
| 47 | ## Parameter details [units, min, max] |
---|
| 48 | self.details = {} |
---|
| 49 | self.details['c1'] = ['', None, None ] |
---|
| 50 | self.details['c2'] = ['', None, None ] |
---|
| 51 | self.details['scale'] = ['', None, None] |
---|
[3db3895] | 52 | self.details['background'] = ['', None, None] |
---|
[988130c6] | 53 | #list of parameter that cannot be fitted |
---|
| 54 | self.fixed= [] |
---|
[829eee9] | 55 | |
---|
| 56 | def _TeubnerStrey(self, x): |
---|
| 57 | """ |
---|
| 58 | Evaluate F(x) = 1/( scale + c1*(x)^(2)+ c2*(x)^(4)) + bkd |
---|
| 59 | |
---|
| 60 | """ |
---|
| 61 | return 1/( self.params['scale']+ self.params['c1'] * math.pow(x ,2)\ |
---|
[f629e346] | 62 | + self.params['c2'] * math.pow(x ,4) ) + self.params['background'] |
---|
[829eee9] | 63 | |
---|
| 64 | |
---|
| 65 | def run(self, x = 0.0): |
---|
| 66 | """ Evaluate the model |
---|
[3db3895] | 67 | @param x: input q-value (float or [float, float] as [r, theta]) |
---|
[829eee9] | 68 | @return: (PowerLaw value) |
---|
| 69 | """ |
---|
| 70 | if x.__class__.__name__ == 'list': |
---|
[a55fac1] | 71 | return self._TeubnerStrey(x[0]) |
---|
[829eee9] | 72 | elif x.__class__.__name__ == 'tuple': |
---|
| 73 | raise ValueError, "Tuples are not allowed as input to BaseComponent models" |
---|
| 74 | else: |
---|
| 75 | return self._TeubnerStrey(x) |
---|
| 76 | |
---|
| 77 | def runXY(self, x = 0.0): |
---|
| 78 | """ Evaluate the model |
---|
[3db3895] | 79 | @param x: input q-value (float or [float, float] as [qx, qy]) |
---|
[829eee9] | 80 | @return: PowerLaw value |
---|
| 81 | """ |
---|
| 82 | if x.__class__.__name__ == 'list': |
---|
[a55fac1] | 83 | q = math.sqrt(x[0]**2 + x[1]**2) |
---|
| 84 | return self._TeubnerStrey(q) |
---|
[829eee9] | 85 | elif x.__class__.__name__ == 'tuple': |
---|
| 86 | raise ValueError, "Tuples are not allowed as input to BaseComponent models" |
---|
| 87 | else: |
---|
| 88 | return self._TeubnerStrey(x) |
---|
| 89 | |
---|
[3db3895] | 90 | def teubnerStreyLengths(self): |
---|
[829eee9] | 91 | """ |
---|
| 92 | Calculate the correlation length (L) |
---|
| 93 | @return L: the correlation distance |
---|
| 94 | """ |
---|
[3db3895] | 95 | return math.pow( 1/2 * math.pow( (self.params['scale']/self.params['c2']), 1/2 )\ |
---|
[829eee9] | 96 | +(self.params['c1']/(4*self.params['c2'])),-1/2 ) |
---|
[3db3895] | 97 | def teubnerStreyDistance(self): |
---|
[829eee9] | 98 | """ |
---|
| 99 | Calculate the quasi-periodic repeat distance (D/(2*pi)) |
---|
| 100 | @return D: quasi-periodic repeat distance |
---|
| 101 | """ |
---|
[3db3895] | 102 | return math.pow( 1/2 * math.pow( (self.params['scale']/self.params['c2']), 1/2 )\ |
---|
[829eee9] | 103 | -(self.params['c1']/(4*self.params['c2'])),-1/2 ) |
---|