Changeset af08e55 in sasview for src/sas/sasgui
- Timestamp:
- Jan 12, 2017 9:01:09 AM (8 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 1905128
- Parents:
- 83c09af
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/fitting/pagestate.py
r83c09af raf08e55 1109 1109 """ 1110 1110 node = dom.xpath('ns:data_class', namespaces={'ns': CANSAS_NS}) 1111 if not node or node[0].text.lstrip().rstrip() != "Data2D": 1112 return_value, _ = self._parse_entry(dom) 1113 numpy.trim_zeros(return_value.x) 1114 numpy.trim_zeros(return_value.y) 1115 numpy.trim_zeros(return_value.dy) 1116 size_dx = return_value.dx.size 1117 size_dxl = return_value.dxl.size 1118 size_dxw = return_value.dxw.size 1119 if size_dxl == 0 and size_dxw == 0: 1120 return_value.dxl = None 1121 return_value.dxw = None 1122 numpy.trim_zeros(return_value.dx) 1123 elif size_dx == 0: 1124 return_value.dx = None 1125 size_dx = size_dxl 1126 numpy.trim_zeros(return_value.dxl) 1127 numpy.trim_zeros(return_value.dxw) 1128 1129 return return_value, _ 1130 1131 # Parse 2D 1132 data_info = Data2D() 1133 1134 # Look up title 1135 self._store_content('ns:Title', dom, 'title', data_info) 1136 1137 # Look up run number 1138 nodes = dom.xpath('ns:Run', namespaces={'ns': CANSAS_NS}) 1139 for item in nodes: 1140 if item.text is not None: 1141 value = item.text.strip() 1142 if len(value) > 0: 1143 data_info.run.append(value) 1144 if item.get('name') is not None: 1145 data_info.run_name[value] = item.get('name') 1146 1147 # Look up instrument name 1148 self._store_content('ns:SASinstrument/ns:name', dom, 1149 'instrument', data_info) 1150 1151 # Notes 1152 note_list = dom.xpath('ns:SASnote', namespaces={'ns': CANSAS_NS}) 1153 for note in note_list: 1154 try: 1155 if note.text is not None: 1156 note_value = note.text.strip() 1157 if len(note_value) > 0: 1158 data_info.notes.append(note_value) 1159 except Exception: 1160 err_mess = "cansas_reader.read: error processing entry notes\n" 1161 err_mess += " %s" % sys.exc_value 1162 self.errors.append(err_mess) 1163 logging.error(err_mess) 1164 1165 # Sample info ################### 1166 entry = get_content('ns:SASsample', dom) 1167 if entry is not None: 1168 data_info.sample.name = entry.get('name') 1169 1170 self._store_content('ns:SASsample/ns:ID', dom, 'ID', data_info.sample) 1171 self._store_float('ns:SASsample/ns:thickness', dom, 'thickness', 1172 data_info.sample) 1173 self._store_float('ns:SASsample/ns:transmission', dom, 'transmission', 1174 data_info.sample) 1175 self._store_float('ns:SASsample/ns:temperature', dom, 'temperature', 1176 data_info.sample) 1177 1178 nodes = dom.xpath('ns:SASsample/ns:details', 1179 namespaces={'ns': CANSAS_NS}) 1180 for item in nodes: 1181 try: 1182 if item.text is not None: 1183 detail_value = item.text.strip() 1184 if len(detail_value) > 0: 1185 data_info.sample.details.append(detail_value) 1186 except Exception: 1187 err_mess = "cansas_reader.read: error processing entry notes\n" 1188 err_mess += " %s" % sys.exc_value 1189 self.errors.append(err_mess) 1190 logging.error(err_mess) 1191 1192 # Position (as a vector) 1193 self._store_float('ns:SASsample/ns:position/ns:x', dom, 'position.x', 1194 data_info.sample) 1195 self._store_float('ns:SASsample/ns:position/ns:y', dom, 'position.y', 1196 data_info.sample) 1197 self._store_float('ns:SASsample/ns:position/ns:z', dom, 'position.z', 1198 data_info.sample) 1199 1200 # Orientation (as a vector) 1201 self._store_float('ns:SASsample/ns:orientation/ns:roll', 1202 dom, 'orientation.x', data_info.sample) 1203 self._store_float('ns:SASsample/ns:orientation/ns:pitch', 1204 dom, 'orientation.y', data_info.sample) 1205 self._store_float('ns:SASsample/ns:orientation/ns:yaw', 1206 dom, 'orientation.z', data_info.sample) 1207 1208 # Source info ################### 1209 entry = get_content('ns:SASinstrument/ns:SASsource', dom) 1210 if entry is not None: 1211 data_info.source.name = entry.get('name') 1212 1213 self._store_content('ns:SASinstrument/ns:SASsource/ns:radiation', 1214 dom, 'radiation', data_info.source) 1215 self._store_content('ns:SASinstrument/ns:SASsource/ns:beam_shape', 1216 dom, 'beam_shape', data_info.source) 1217 self._store_float('ns:SASinstrument/ns:SASsource/ns:wavelength', 1218 dom, 'wavelength', data_info.source) 1219 self._store_float('ns:SASinstrument/ns:SASsource/ns:wavelength_min', 1220 dom, 'wavelength_min', data_info.source) 1221 self._store_float('ns:SASinstrument/ns:SASsource/ns:wavelength_max', 1222 dom, 'wavelength_max', data_info.source) 1223 self._store_float('ns:SASinstrument/ns:SASsource/ns:wavelength_spread', 1224 dom, 'wavelength_spread', data_info.source) 1225 1226 # Beam size (as a vector) 1227 entry = get_content('ns:SASinstrument/ns:SASsource/ns:beam_size', dom) 1228 if entry is not None: 1229 data_info.source.beam_size_name = entry.get('name') 1230 1231 self._store_float('ns:SASinstrument/ns:SASsource/ns:beam_size/ns:x', 1232 dom, 'beam_size.x', data_info.source) 1233 self._store_float('ns:SASinstrument/ns:SASsource/ns:beam_size/ns:y', 1234 dom, 'beam_size.y', data_info.source) 1235 self._store_float('ns:SASinstrument/ns:SASsource/ns:beam_size/ns:z', 1236 dom, 'beam_size.z', data_info.source) 1237 1238 # Collimation info ################### 1239 nodes = dom.xpath('ns:SASinstrument/ns:SAScollimation', 1240 namespaces={'ns': CANSAS_NS}) 1241 for item in nodes: 1242 collim = Collimation() 1243 if item.get('name') is not None: 1244 collim.name = item.get('name') 1245 self._store_float('ns:length', item, 'length', collim) 1246 1247 # Look for apertures 1248 apert_list = item.xpath('ns:aperture', 1249 namespaces={'ns': CANSAS_NS}) 1250 for apert in apert_list: 1251 aperture = Aperture() 1252 1253 # Get the name and type of the aperture 1254 aperture.name = apert.get('name') 1255 aperture.type = apert.get('type') 1256 1257 self._store_float('ns:distance', apert, 'distance', aperture) 1258 1259 entry = get_content('ns:size', apert) 1260 if entry is not None: 1261 aperture.size_name = entry.get('name') 1262 1263 self._store_float('ns:size/ns:x', apert, 'size.x', aperture) 1264 self._store_float('ns:size/ns:y', apert, 'size.y', aperture) 1265 self._store_float('ns:size/ns:z', apert, 'size.z', aperture) 1266 1267 collim.aperture.append(aperture) 1268 1269 data_info.collimation.append(collim) 1270 1271 # Detector info ###################### 1272 nodes = dom.xpath('ns:SASinstrument/ns:SASdetector', 1273 namespaces={'ns': CANSAS_NS}) 1274 for item in nodes: 1275 1276 detector = Detector() 1277 1278 self._store_content('ns:name', item, 'name', detector) 1279 self._store_float('ns:SDD', item, 'distance', detector) 1280 1281 # Detector offset (as a vector) 1282 self._store_float('ns:offset/ns:x', item, 'offset.x', detector) 1283 self._store_float('ns:offset/ns:y', item, 'offset.y', detector) 1284 self._store_float('ns:offset/ns:z', item, 'offset.z', detector) 1285 1286 # Detector orientation (as a vector) 1287 self._store_float('ns:orientation/ns:roll', item, 1288 'orientation.x', detector) 1289 self._store_float('ns:orientation/ns:pitch', item, 1290 'orientation.y', detector) 1291 self._store_float('ns:orientation/ns:yaw', item, 1292 'orientation.z', detector) 1293 1294 # Beam center (as a vector) 1295 self._store_float('ns:beam_center/ns:x', item, 1296 'beam_center.x', detector) 1297 self._store_float('ns:beam_center/ns:y', item, 1298 'beam_center.y', detector) 1299 self._store_float('ns:beam_center/ns:z', item, 1300 'beam_center.z', detector) 1301 1302 # Pixel size (as a vector) 1303 self._store_float('ns:pixel_size/ns:x', item, 1304 'pixel_size.x', detector) 1305 self._store_float('ns:pixel_size/ns:y', item, 1306 'pixel_size.y', detector) 1307 self._store_float('ns:pixel_size/ns:z', item, 1308 'pixel_size.z', detector) 1309 1310 self._store_float('ns:slit_length', item, 'slit_length', detector) 1311 1312 data_info.detector.append(detector) 1313 1314 # Processes info ###################### 1315 nodes = dom.xpath('ns:SASprocess', namespaces={'ns': CANSAS_NS}) 1316 for item in nodes: 1317 process = Process() 1318 self._store_content('ns:name', item, 'name', process) 1319 self._store_content('ns:date', item, 'date', process) 1320 self._store_content('ns:description', item, 'description', process) 1321 1322 term_list = item.xpath('ns:term', namespaces={'ns': CANSAS_NS}) 1323 for term in term_list: 1324 try: 1325 term_attr = {} 1326 for attr in term.keys(): 1327 term_attr[attr] = term.get(attr).strip() 1328 if term.text is not None: 1329 term_attr['value'] = term.text.strip() 1330 process.term.append(term_attr) 1331 except: 1332 err_mess = "cansas_reader.read: error processing " 1333 err_mess += "entry notes\n %s" % sys.exc_value 1334 self.errors.append(err_mess) 1335 logging.error(err_mess) 1336 1337 note_list = item.xpath('ns:SASprocessnote', 1338 namespaces={'ns': CANSAS_NS}) 1339 for note in note_list: 1340 if note.text is not None: 1341 process.notes.append(note.text.strip()) 1342 1343 data_info.process.append(process) 1344 1345 # Data info ###################### 1346 nodes = dom.xpath('ns:SASdata', namespaces={'ns': CANSAS_NS}) 1347 if len(nodes) > 1: 1348 raise RuntimeError, "CanSAS reader is not compatible with" + \ 1349 " multiple SASdata entries" 1350 1351 for entry in nodes: 1352 for item in LIST_OF_DATA_2D_ATTR: 1353 # get node 1354 node = get_content('ns:%s' % item[0], entry) 1355 setattr(data_info, item[1], parse_entry_helper(node, item)) 1356 1357 for item in LIST_OF_DATA_2D_VALUES: 1358 field = get_content('ns:%s' % item[0], entry) 1359 value_list = [] 1360 if field is not None: 1361 value_list = \ 1362 [parse_entry_helper(node, item) for node in field] 1363 if len(value_list) < 2: 1364 setattr(data_info, item[0], None) 1365 else: 1366 setattr(data_info, item[0], numpy.array(value_list)) 1367 1368 return data_info 1111 return_value, _ = self._parse_entry(dom) 1112 return return_value, _ 1369 1113 1370 1114 def _read_cansas(self, path):
Note: See TracChangeset
for help on using the changeset viewer.