Changes in / [a2e980b:3d6c010] in sasview
- Location:
- src/sas/sascalc/dataloader/readers
- Files:
-
- 4 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/dataloader/readers/cansas_reader.py
r8434365 r3beacab4 209 209 name = attr.get("name", "") 210 210 type = attr.get("type", "") 211 unit = attr.get("unit", "") 211 212 # Get the element name and set the current names level 212 213 tagname = node.tag.replace(self.base_ns, "") … … 248 249 unit = attr.get('unit', '') 249 250 else: 250 data_point, unit = self._get_node_value(node , tagname)251 data_point, unit = self._get_node_value(node) 251 252 252 253 # If this is a dataset, store the data appropriately … … 691 692 return name 692 693 693 def _get_node_value(self, node, tagname): 694 def _get_node_value_from_text(self, node, node_text): 695 """ 696 Get the value of a node and any applicable units 697 698 :param node: The XML node to get the value of 699 :param tagname: The tagname of the node 700 """ 701 units = "" 702 # If the value is a float, compile with units. 703 if self.ns_list.ns_datatype == "float": 704 # If an empty value is given, set as zero. 705 if node_text is None or node_text.isspace() \ 706 or node_text.lower() == "nan": 707 node_text = "0.0" 708 # Convert the value to the base units 709 tag = node.tag.replace(self.base_ns, "") 710 node_text, units = self._unit_conversion(node, tag, node_text) 711 712 # If the value is a timestamp, convert to a datetime object 713 elif self.ns_list.ns_datatype == "timestamp": 714 if node_text is None or node_text.isspace(): 715 pass 716 else: 717 try: 718 node_text = \ 719 datetime.datetime.fromtimestamp(node_text) 720 except ValueError: 721 node_text = None 722 return node_text, units 723 724 def _get_node_value(self, node): 694 725 """ 695 726 Get the value of a node and any applicable units … … 705 736 else: 706 737 node_value = "" 707 708 # If the value is a float, compile with units. 709 if self.ns_list.ns_datatype == "float": 710 # If an empty value is given, set as zero. 711 if node_value is None or node_value.isspace() \ 712 or node_value.lower() == "nan": 713 node_value = "0.0" 714 #Convert the value to the base units 715 node_value, units = self._unit_conversion(node, tagname, node_value) 716 717 # If the value is a timestamp, convert to a datetime object 718 elif self.ns_list.ns_datatype == "timestamp": 719 if node_value is None or node_value.isspace(): 720 pass 721 else: 722 try: 723 node_value = \ 724 datetime.datetime.fromtimestamp(node_value) 725 except ValueError: 726 node_value = None 738 node_value, units = self._get_node_value_from_text(node, node_value) 727 739 return node_value, units 728 740 … … 928 940 self._write_data_2d(datainfo, entry_node) 929 941 else: 930 self._write_data(datainfo, entry_node) 942 if self._check_root(): 943 self._write_data(datainfo, entry_node) 944 else: 945 self._write_data_linearized(datainfo, entry_node) 931 946 # Transmission Spectrum Info 932 947 # TODO: fix the writer to linearize all data, including T_spectrum … … 994 1009 url = "http://www.cansas.org/formats/1.1/" 995 1010 else: 996 url = "http:// svn.smallangles.net/svn/canSAS/1dwg/trunk/"1011 url = "http://www.cansas.org/formats/1.0/" 997 1012 schema_location = "{0} {1}cansas1d.xsd".format(n_s, url) 998 1013 attrib = {"{" + xsi + "}schemaLocation" : schema_location, … … 1352 1367 {"unit": item.slit_length_unit}) 1353 1368 1354 1355 1369 def _write_process_notes(self, datainfo, entry_node): 1356 1370 """ … … 1400 1414 self.append(node, entry_node) 1401 1415 1402 def _check_ origin(self, entry_node, doc):1416 def _check_root(self): 1403 1417 """ 1404 1418 Return the document, and the SASentry node associated with … … 1411 1425 """ 1412 1426 if not self.frm: 1413 self.frm = inspect.stack()[ 1]1427 self.frm = inspect.stack()[2] 1414 1428 mod_name = self.frm[1].replace("\\", "/").replace(".pyc", "") 1415 1429 mod_name = mod_name.replace(".py", "") 1416 1430 mod = mod_name.split("sas/") 1417 1431 mod_name = mod[1] 1418 if mod_name != "sascalc/dataloader/readers/cansas_reader": 1432 return mod_name == "sascalc/dataloader/readers/cansas_reader" 1433 1434 def _check_origin(self, entry_node, doc): 1435 """ 1436 Return the document, and the SASentry node associated with 1437 the data we just wrote. 1438 If the calling function was not the cansas reader, return a minidom 1439 object rather than an lxml object. 1440 1441 :param entry_node: lxml node ElementTree object to be appended to 1442 :param doc: entire xml tree 1443 """ 1444 if not self._check_root(): 1419 1445 string = self.to_string(doc, pretty_print=False) 1420 1446 doc = parseString(string)
Note: See TracChangeset
for help on using the changeset viewer.