1 import os, sys
2 import traceback
3
4 from park import XmlAttribute, EXSTRING_TAG
5 from park import SetDefault
6 from park import XmlDataArray
7 from park import DATA_TAG, XmlData
8 from park import XmlMetaData, XmlInstrumentData
9
10
11 from park.theory.utilIO import readAsciiData, writeAsciiData, joinDataN
12 from park.theory.chisq import getScaleMatch, getScaleMatchErrorbar
13
14 from reflectometry.model1d.model.dataLoader import FixedResolution
15
16
17
18 REFL_METADATA_TAG = 'meta'
19 REFL_DATA_CLASSNAME = 'reflData.ReflData'
20
21
22 REFL_ARRAY_LABELS = ('Q', 'dQ', 'R', 'dR')
23 REFL_ARRAY_NUM = len(REFL_ARRAY_LABELS)
24
25
27
34
35
41
42
45
46
47 - def _postParse(self):
48 """ Constructor."""
49 self._myDefault()
50
51
53 if not hasattr(self, '_xQ'): self._xQ = []
54 if not hasattr(self, '_xdQ'): self._xdQ = []
55 if not hasattr(self, '_xR'): self._xR = []
56 if not hasattr(self, '_xdR'): self._xdR = []
57
58
60 filename = self.getSource()
61
62 if filename=="" or filename==None:
63 return False
64
65 if filename[-1] == 'A' or filename[-1] == 'a':
66 return True
67 else:
68 return False
69
70
72 """
73 Check the validity of reduction portion.
74 """
75 if self._isMagnetic(): _REFL_ARRAY_NUM = 16
76 else: _REFL_ARRAY_NUM = 4
77
78 cnt = len(reductionData.getXmlDataArray())
79 if cnt < _REFL_ARRAY_NUM:
80 for i in xrange( _REFL_ARRAY_NUM-cnt ):
81 reductionData.add(XmlDataArray())
82
83
84
93
94
96 """ Update the reduction data due to change of data source."""
97 self._readRawData()
98
99 self.update4Meta()
100
101
124
125
127 """
128 Return the original data array: [Q, dQ, R,dR],
129 If don't have dQ, just return list of '0.0'
130 """
131
132 data = readAsciiData(fname)
133
134 if len(data) == 2:
135 _xQ = data[0]; _xdQ = None; _xR = data[1]; _xdR = None
136
137 elif len(data) == 3:
138 _xQ = data[0]; _xdQ = None; _xR = data[1]; _xdR = data[2]
139
140 elif len(data) == 4 or len(data) == 5:
141 _xQ = data[0]; _xdQ = data[1]; _xR = data[2]; _xdR = data[3]
142
143 else:
144 raise TypeError,'Only 3, 4, or 5 lines of refl data is recognized.'
145
146
147 self._xQ.append(_xQ)
148 self._xdQ.append(_xdQ)
149 self._xR.append(_xR)
150 self._xdR.append(_xdR)
151
152
153
155 """
156 Return the original data array: [Q, dQ, R,dR],
157 If don't have dQ, just return list of '0.0'
158 """
159 filename = self.getSource()
160
161 if filename[-1] == 'A': _EndList = [ 'A', 'B', 'C', 'D' ]
162 elif filename[-1] == 'a': _EndList = [ 'a', 'b', 'c', 'd' ]
163 else: _EndList = None
164
165 if _EndList == None:
166 self._readRawData4File( filename)
167 else:
168 for i in _EndList:
169 _filename = filename[:-1] + i
170 self._readRawData4File( _filename)
171
172
174 """ Return the data array: [X,Y]
175 """
176 filename = getattr(self,DATA_FILE_TAG)
177
178 return readAsciiData(filename)
179
180
182 """ Return instrument data, one data has only one instrument data."""
183 try:
184 inst = self.getChildren(REFL_METADATA_TAG)[0]
185 except:
186 inst = ReflMetaData()
187 self.add(inst)
188
189 return inst
190
191
194
195
197 """ Return the label for the returned data array. """
198 return REFL_ARRAY_LABELS[ind]
199
200
201
202
203
226