[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" |
---|
| 33 | |
---|
| 34 | ## Define parameters |
---|
| 35 | self.params = {} |
---|
| 36 | self.params['c1'] = -30.0 |
---|
| 37 | self.params['c2'] = 5000.0 |
---|
| 38 | self.params['scale'] = 0.1 |
---|
[3db3895] | 39 | self.params['background'] = 0.0 |
---|
[829eee9] | 40 | |
---|
| 41 | ## Parameter details [units, min, max] |
---|
| 42 | self.details = {} |
---|
| 43 | self.details['c1'] = ['', None, None ] |
---|
| 44 | self.details['c2'] = ['', None, None ] |
---|
| 45 | self.details['scale'] = ['', None, None] |
---|
[3db3895] | 46 | self.details['background'] = ['', None, None] |
---|
[829eee9] | 47 | |
---|
| 48 | |
---|
| 49 | def _TeubnerStrey(self, x): |
---|
| 50 | """ |
---|
| 51 | Evaluate F(x) = 1/( scale + c1*(x)^(2)+ c2*(x)^(4)) + bkd |
---|
| 52 | |
---|
| 53 | """ |
---|
| 54 | return 1/( self.params['scale']+ self.params['c1'] * math.pow(x ,2)\ |
---|
[f629e346] | 55 | + self.params['c2'] * math.pow(x ,4) ) + self.params['background'] |
---|
[829eee9] | 56 | |
---|
| 57 | |
---|
| 58 | def run(self, x = 0.0): |
---|
| 59 | """ Evaluate the model |
---|
[3db3895] | 60 | @param x: input q-value (float or [float, float] as [r, theta]) |
---|
[829eee9] | 61 | @return: (PowerLaw value) |
---|
| 62 | """ |
---|
| 63 | if x.__class__.__name__ == 'list': |
---|
| 64 | return self._TeubnerStrey(x[0]*math.cos(x[1]))\ |
---|
| 65 | *self._TeubnerStrey(x[0]*math.sin(x[1])) |
---|
| 66 | elif x.__class__.__name__ == 'tuple': |
---|
| 67 | raise ValueError, "Tuples are not allowed as input to BaseComponent models" |
---|
| 68 | else: |
---|
| 69 | return self._TeubnerStrey(x) |
---|
| 70 | |
---|
| 71 | def runXY(self, x = 0.0): |
---|
| 72 | """ Evaluate the model |
---|
[3db3895] | 73 | @param x: input q-value (float or [float, float] as [qx, qy]) |
---|
[829eee9] | 74 | @return: PowerLaw value |
---|
| 75 | """ |
---|
| 76 | if x.__class__.__name__ == 'list': |
---|
| 77 | return self._TeubnerStrey(x[0])*self._TeubnerStrey(x[1]) |
---|
| 78 | elif x.__class__.__name__ == 'tuple': |
---|
| 79 | raise ValueError, "Tuples are not allowed as input to BaseComponent models" |
---|
| 80 | else: |
---|
| 81 | return self._TeubnerStrey(x) |
---|
| 82 | |
---|
[3db3895] | 83 | def teubnerStreyLengths(self): |
---|
[829eee9] | 84 | """ |
---|
| 85 | Calculate the correlation length (L) |
---|
| 86 | @return L: the correlation distance |
---|
| 87 | """ |
---|
[3db3895] | 88 | return math.pow( 1/2 * math.pow( (self.params['scale']/self.params['c2']), 1/2 )\ |
---|
[829eee9] | 89 | +(self.params['c1']/(4*self.params['c2'])),-1/2 ) |
---|
[3db3895] | 90 | def teubnerStreyDistance(self): |
---|
[829eee9] | 91 | """ |
---|
| 92 | Calculate the quasi-periodic repeat distance (D/(2*pi)) |
---|
| 93 | @return D: quasi-periodic repeat 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 ) |
---|