1 import os, sys
2 import traceback
3
4 from park import XmlDataArray
5 from park import XmlDataSource
6 from park import XmlDataset
7 from park import XmlReductionData
8 from park import SetDefault
9 from park import DATA_TAG, DATASET_TAG
10
11
12 from park.theory.utilIO import readAsciiData, writeAsciiData, joinDataN
13 from park.theory.chisq import getScaleMatch, getScaleMatchErrorbar
14 from reflData import ReflData
15
16
17
18 REFL_ARRAY_LABELS = ('Q', 'dQ', 'R','dR', 'L')
19
20 """ Data structure for reflectometry. """
21 REFL_DATASRC_CLASSNAME = 'reflDataset.ReflDataSource'
22 REFL_DATASET_CLASSNAME = 'reflDataset.ReflDataset'
23
24
26
30
31
34
35
37 if nodename == DATASET_TAG:
38 return ReflDataset()
39 else:
40 return super(ReflDataSource, self)._getNodeObject(nodename)
41
42
43
44
49
50
52 if nodename == DATA_TAG:
53 return ReflData()
54 else:
55 return super(ReflDataset, self)._getNodeObject(nodename)
56
57
60
61
63 """ Return the joined data. """
64 try:
65 dataarray = []
66 for data in self.getData():
67 dataarray.append(data.getOriginalDataArray())
68 return joinDataN(dataarray)
69 except:
70 return None
71
72
74 """ Return the joined data. """
75 try:
76 dataarray = []
77 for data in self.getXmlData():
78 dataarray.append(data.getDataArray())
79 return joinDataN(dataarray)
80 except:
81 print 'exception:', traceback.format_exc()
82 return None
83
84
86 if filename is None:
87 myfilename = getattr(self, DATA_FILE_TAG)
88 else:
89 myfilename = filename
90 setattr(self, DATA_FILE_TAG, myfilename)
91
92 writeAsciiData(myfilename, self.getJoinedDataArray())
93
94
96 """ Automatch the dataset. """
97 mydata = []
98 for data in self.getData():
99 orgdata = data.getOriginalDataArray()
100 mydata.append(orgdata[0])
101 mydata.append(orgdata[1])
102
103 scale = getScaleMatch(mydata)
104
105 ind = 0
106 for data in self.getData():
107 data.getInstrumentData().scale = scale[ind]
108 ind += 1
109
110
114
115
117 """ Return the label for the returned data array. """
118 return REFL_ARRAY_LABELS[ind]
119
120
122
123 filename = self.getXmlData()[0].getSource()
124
125 if filename=="" or filename==None:
126 return False
127
128 if filename[-1] == 'A' or filename[-1] == 'a':
129 return True
130 else:
131 return False
132
133
135 """ Check to make sure there is a valid reduction data"""
136
137 if self._isMagnetic(): _REFL_ARRAY_NUM = 16
138 else: _REFL_ARRAY_NUM = 4
139
140
141 cnt = len(reductionData.getXmlDataArray())
142 total = len(self.getXmlData()) * _REFL_ARRAY_NUM
143 if cnt < total:
144 for ind in xrange(total - cnt):
145 reductionData.add(XmlDataArray())
146 elif cnt > total:
147 for ind in xrange(cnt-total):
148 reductionData.remove(0)
149
150
152 """ Update the reduction data for the whole dataset. """
153 dataarray = []
154 for data in self.getXmlData():
155 dataarray.extend(data.getDataList())
156
157 return dataarray
158
159
160
162 """
163 return the xml string.
164
165 HERE we overwrite the _getChildrenXmlString() in xmlDataset.
166 just because we don't want the profile information to be sent
167 to server to fit.
168
169 FIXME! Find a good solution for this
170 """
171
172 if self.isUserSrc():
173 return self.getUserDefinedXmlString()
174
175 if self.isImbedSrc() or self.isReductionSrc():
176
177 self.removeChild( 'profile' )
178 return super(XmlDataset, self)._getChildrenXmlString()
179
180 else:
181 if (hasattr(self, '_text') and self._text is not None) \
182 and (not self._text.isspace()):
183 s0 = self._text
184 else:
185 s0 = ''
186
187 for node in self._children:
188 if hasattr(node, 'name'):
189
190 if getattr(node, 'name').startswith(EXSTRING_TAG):
191 continue
192 if getattr(node, 'name') == 'profile':
193 continue
194
195 if isinstance(node, XmlReductionData):
196 continue
197
198 if hasattr(node, 'toXml'):
199 s0 = ''.join( (s0, node.toXml(False)))
200 else:
201 s0 = ''.join( (s0, str(node)) )
202
203 return s0
204