Changes in / [3d6c010:a2e980b] in sasview
- Location:
- src/sas/sascalc/dataloader/readers
- Files:
-
- 4 deleted
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/dataloader/readers/cansas_reader.py
r3beacab4 r8434365 209 209 name = attr.get("name", "") 210 210 type = attr.get("type", "") 211 unit = attr.get("unit", "")212 211 # Get the element name and set the current names level 213 212 tagname = node.tag.replace(self.base_ns, "") … … 249 248 unit = attr.get('unit', '') 250 249 else: 251 data_point, unit = self._get_node_value(node )250 data_point, unit = self._get_node_value(node, tagname) 252 251 253 252 # If this is a dataset, store the data appropriately … … 692 691 return name 693 692 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): 693 def _get_node_value(self, node, tagname): 725 694 """ 726 695 Get the value of a node and any applicable units … … 736 705 else: 737 706 node_value = "" 738 node_value, units = self._get_node_value_from_text(node, 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 739 727 return node_value, units 740 728 … … 940 928 self._write_data_2d(datainfo, entry_node) 941 929 else: 942 if self._check_root(): 943 self._write_data(datainfo, entry_node) 944 else: 945 self._write_data_linearized(datainfo, entry_node) 930 self._write_data(datainfo, entry_node) 946 931 # Transmission Spectrum Info 947 932 # TODO: fix the writer to linearize all data, including T_spectrum … … 1009 994 url = "http://www.cansas.org/formats/1.1/" 1010 995 else: 1011 url = "http:// www.cansas.org/formats/1.0/"996 url = "http://svn.smallangles.net/svn/canSAS/1dwg/trunk/" 1012 997 schema_location = "{0} {1}cansas1d.xsd".format(n_s, url) 1013 998 attrib = {"{" + xsi + "}schemaLocation" : schema_location, … … 1367 1352 {"unit": item.slit_length_unit}) 1368 1353 1354 1369 1355 def _write_process_notes(self, datainfo, entry_node): 1370 1356 """ … … 1414 1400 self.append(node, entry_node) 1415 1401 1416 def _check_ root(self):1402 def _check_origin(self, entry_node, doc): 1417 1403 """ 1418 1404 Return the document, and the SASentry node associated with … … 1425 1411 """ 1426 1412 if not self.frm: 1427 self.frm = inspect.stack()[ 2]1413 self.frm = inspect.stack()[1] 1428 1414 mod_name = self.frm[1].replace("\\", "/").replace(".pyc", "") 1429 1415 mod_name = mod_name.replace(".py", "") 1430 1416 mod = mod_name.split("sas/") 1431 1417 mod_name = mod[1] 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(): 1418 if mod_name != "sascalc/dataloader/readers/cansas_reader": 1445 1419 string = self.to_string(doc, pretty_print=False) 1446 1420 doc = parseString(string)
Note: See TracChangeset
for help on using the changeset viewer.