Changeset 83c09af in sasview for src/sas/sasgui
- Timestamp:
- Jan 3, 2017 1:12:00 PM (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:
- af08e55
- Parents:
- c1681ea
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/fitting/pagestate.py
rc8e1996 r83c09af 1034 1034 return self._read_cansas(path) 1035 1035 1036 def _data2d_to_xml_doc(self, datainfo):1037 """1038 Create an XML document to contain the content of a Data2D1039 1040 :param datainfo: Data2D object1041 1042 """1043 if not issubclass(datainfo.__class__, Data2D):1044 raise RuntimeError, "The cansas writer expects a Data2D instance"1045 1046 title = "cansas1d/%s" % self.version1047 title += "http://svn.smallangles.net/svn/canSAS/1dwg/trunk/cansas1d.xsd"1048 doc = xml.dom.minidom.Document()1049 main_node = doc.createElement("SASroot")1050 main_node.setAttribute("version", self.version)1051 main_node.setAttribute("xmlns", "cansas1d/%s" % self.version)1052 main_node.setAttribute("xmlns:xsi",1053 "http://www.w3.org/2001/XMLSchema-instance")1054 main_node.setAttribute("xsi:schemaLocation", title)1055 1056 doc.appendChild(main_node)1057 1058 entry_node = doc.createElement("SASentry")1059 main_node.appendChild(entry_node)1060 1061 write_node(doc, entry_node, "Title", datainfo.title)1062 if datainfo is not None:1063 write_node(doc, entry_node, "data_class",1064 datainfo.__class__.__name__)1065 for item in datainfo.run:1066 runname = {}1067 if item in datainfo.run_name and \1068 len(str(datainfo.run_name[item])) > 1:1069 runname = {'name': datainfo.run_name[item]}1070 write_node(doc, entry_node, "Run", item, runname)1071 # Data info1072 new_node = doc.createElement("SASdata")1073 entry_node.appendChild(new_node)1074 for item in LIST_OF_DATA_2D_ATTR:1075 element = doc.createElement(item[0])1076 element.setAttribute(item[0], str(getattr(datainfo, item[1])))1077 new_node.appendChild(element)1078 1079 for item in LIST_OF_DATA_2D_VALUES:1080 root_node = doc.createElement(item[0])1081 new_node.appendChild(root_node)1082 temp_list = getattr(datainfo, item[1])1083 1084 if temp_list is None or len(temp_list) == 0:1085 element = doc.createElement(item[0])1086 element.appendChild(doc.createTextNode(str(temp_list)))1087 root_node.appendChild(element)1088 else:1089 for value in temp_list:1090 element = doc.createElement(item[0])1091 element.setAttribute(item[0], str(value))1092 root_node.appendChild(element)1093 1094 # Sample info1095 sample = doc.createElement("SASsample")1096 if datainfo.sample.name is not None:1097 sample.setAttribute("name", str(datainfo.sample.name))1098 entry_node.appendChild(sample)1099 write_node(doc, sample, "ID", str(datainfo.sample.ID))1100 write_node(doc, sample, "thickness", datainfo.sample.thickness,1101 {"unit": datainfo.sample.thickness_unit})1102 write_node(doc, sample, "transmission", datainfo.sample.transmission)1103 write_node(doc, sample, "temperature", datainfo.sample.temperature,1104 {"unit": datainfo.sample.temperature_unit})1105 1106 for item in datainfo.sample.details:1107 write_node(doc, sample, "details", item)1108 1109 pos = doc.createElement("position")1110 written = write_node(doc, pos, "x", datainfo.sample.position.x,1111 {"unit": datainfo.sample.position_unit})1112 written = written | write_node(doc, pos, "y",1113 datainfo.sample.position.y,1114 {"unit": datainfo.sample.position_unit})1115 written = written | write_node(doc, pos, "z",1116 datainfo.sample.position.z,1117 {"unit": datainfo.sample.position_unit})1118 if written:1119 sample.appendChild(pos)1120 1121 ori = doc.createElement("orientation")1122 written = write_node(doc, ori, "roll", datainfo.sample.orientation.x,1123 {"unit": datainfo.sample.orientation_unit})1124 written = written | write_node(doc, ori, "pitch",1125 datainfo.sample.orientation.y,1126 {"unit":1127 datainfo.sample.orientation_unit})1128 written = written | write_node(doc, ori, "yaw",1129 datainfo.sample.orientation.z,1130 {"unit":1131 datainfo.sample.orientation_unit})1132 if written:1133 sample.appendChild(ori)1134 1135 # Instrument info1136 instr = doc.createElement("SASinstrument")1137 entry_node.appendChild(instr)1138 1139 write_node(doc, instr, "name", datainfo.instrument)1140 1141 # Source1142 source = doc.createElement("SASsource")1143 if datainfo.source.name is not None:1144 source.setAttribute("name", str(datainfo.source.name))1145 instr.appendChild(source)1146 1147 write_node(doc, source, "radiation", datainfo.source.radiation)1148 write_node(doc, source, "beam_shape", datainfo.source.beam_shape)1149 size = doc.createElement("beam_size")1150 if datainfo.source.beam_size_name is not None:1151 size.setAttribute("name", str(datainfo.source.beam_size_name))1152 written = write_node(doc, size, "x", datainfo.source.beam_size.x,1153 {"unit": datainfo.source.beam_size_unit})1154 written = written | write_node(doc, size, "y",1155 datainfo.source.beam_size.y,1156 {"unit": datainfo.source.beam_size_unit})1157 written = written | write_node(doc, size, "z",1158 datainfo.source.beam_size.z,1159 {"unit": datainfo.source.beam_size_unit})1160 if written:1161 source.appendChild(size)1162 1163 write_node(doc, source, "wavelength", datainfo.source.wavelength,1164 {"unit": datainfo.source.wavelength_unit})1165 write_node(doc, source, "wavelength_min",1166 datainfo.source.wavelength_min,1167 {"unit": datainfo.source.wavelength_min_unit})1168 write_node(doc, source, "wavelength_max",1169 datainfo.source.wavelength_max,1170 {"unit": datainfo.source.wavelength_max_unit})1171 write_node(doc, source, "wavelength_spread",1172 datainfo.source.wavelength_spread,1173 {"unit": datainfo.source.wavelength_spread_unit})1174 1175 # Collimation1176 for item in datainfo.collimation:1177 coll = doc.createElement("SAScollimation")1178 if item.name is not None:1179 coll.setAttribute("name", str(item.name))1180 instr.appendChild(coll)1181 1182 write_node(doc, coll, "length", item.length,1183 {"unit": item.length_unit})1184 1185 for apert in item.aperture:1186 ap = doc.createElement("aperture")1187 if apert.name is not None:1188 ap.setAttribute("name", str(apert.name))1189 if apert.type is not None:1190 ap.setAttribute("type", str(apert.type))1191 coll.appendChild(ap)1192 1193 write_node(doc, ap, "distance", apert.distance,1194 {"unit": apert.distance_unit})1195 1196 size = doc.createElement("size")1197 if apert.size_name is not None:1198 size.setAttribute("name", str(apert.size_name))1199 written = write_node(doc, size, "x", apert.size.x,1200 {"unit": apert.size_unit})1201 written = written | write_node(doc, size, "y", apert.size.y,1202 {"unit": apert.size_unit})1203 written = written | write_node(doc, size, "z", apert.size.z,1204 {"unit": apert.size_unit})1205 if written:1206 ap.appendChild(size)1207 1208 # Detectors1209 for item in datainfo.detector:1210 det = doc.createElement("SASdetector")1211 written = write_node(doc, det, "name", item.name)1212 written = written | write_node(doc, det, "SDD", item.distance,1213 {"unit": item.distance_unit})1214 written = written | write_node(doc, det, "slit_length",1215 item.slit_length,1216 {"unit": item.slit_length_unit})1217 if written:1218 instr.appendChild(det)1219 1220 off = doc.createElement("offset")1221 written = write_node(doc, off, "x", item.offset.x,1222 {"unit": item.offset_unit})1223 written = written | write_node(doc, off, "y", item.offset.y,1224 {"unit": item.offset_unit})1225 written = written | write_node(doc, off, "z", item.offset.z,1226 {"unit": item.offset_unit})1227 if written:1228 det.appendChild(off)1229 1230 center = doc.createElement("beam_center")1231 written = write_node(doc, center, "x", item.beam_center.x,1232 {"unit": item.beam_center_unit})1233 written = written | write_node(doc, center, "y",1234 item.beam_center.y,1235 {"unit": item.beam_center_unit})1236 written = written | write_node(doc, center, "z",1237 item.beam_center.z,1238 {"unit": item.beam_center_unit})1239 if written:1240 det.appendChild(center)1241 1242 pix = doc.createElement("pixel_size")1243 written = write_node(doc, pix, "x", item.pixel_size.x,1244 {"unit": item.pixel_size_unit})1245 written = written | write_node(doc, pix, "y", item.pixel_size.y,1246 {"unit": item.pixel_size_unit})1247 written = written | write_node(doc, pix, "z", item.pixel_size.z,1248 {"unit": item.pixel_size_unit})1249 if written:1250 det.appendChild(pix)1251 1252 ori = doc.createElement("orientation")1253 written = write_node(doc, ori, "roll", item.orientation.x,1254 {"unit": item.orientation_unit})1255 written = written | write_node(doc, ori, "pitch",1256 item.orientation.y,1257 {"unit": item.orientation_unit})1258 written = written | write_node(doc, ori, "yaw", item.orientation.z,1259 {"unit": item.orientation_unit})1260 if written:1261 det.appendChild(ori)1262 1263 # Processes info1264 for item in datainfo.process:1265 node = doc.createElement("SASprocess")1266 entry_node.appendChild(node)1267 1268 write_node(doc, node, "name", item.name)1269 write_node(doc, node, "date", item.date)1270 write_node(doc, node, "description", item.description)1271 for term in item.term:1272 value = term['value']1273 del term['value']1274 write_node(doc, node, "term", value, term)1275 for note in item.notes:1276 write_node(doc, node, "SASprocessnote", note)1277 # Return the document, and the SASentry node associated with1278 # the data we just wrote1279 return doc, entry_node1280 1281 1036 def _parse_state(self, entry): 1282 1037 """ … … 1745 1500 state.data.run_name[0] = state.data.name 1746 1501 1747 if issubclass(state.data.__class__, 1748 sas.sascalc.dataloader.data_info.Data1D): 1749 data = state.data 1750 doc, sasentry = self._to_xml_doc(data) 1751 else: 1752 data = state.data 1753 doc, sasentry = self._data2d_to_xml_doc(data) 1502 data = state.data 1503 doc, sasentry = self._to_xml_doc(data) 1754 1504 1755 1505 if state is not None:
Note: See TracChangeset
for help on using the changeset viewer.