Changeset fcba29a in sasview for src/sas/sascalc/dataloader/readers/cansas_reader.py
- Timestamp:
- Aug 8, 2016 8:17:11 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:
- 98d32be
- Parents:
- 3931ea14 (diff), ab06de7 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/dataloader/readers/cansas_reader.py
r8976865 rfcba29a 34 34 from xml.dom.minidom import parseString 35 35 36 ## TODO: Refactor to load multiple <SASData> as separate Data1D objects 37 ## TODO: Refactor to allow invalid XML, but give a useful warning when loaded 38 36 39 _ZERO = 1e-16 37 40 PREPROCESS = "xmlpreprocess" … … 133 136 return False 134 137 135 def load_file_and_schema(self, xml_file ):138 def load_file_and_schema(self, xml_file, schema_path=""): 136 139 """ 137 140 Loads the file and associates a schema, if a known schema exists … … 149 152 # Generic values for the cansas file based on the version 150 153 cansas_defaults = CANSAS_NS.get(self.cansas_version, "1.0") 151 schema_path = "{0}/sas/sascalc/dataloader/readers/schema/{1}".format\ 154 if schema_path == "": 155 schema_path = "{0}/sas/sascalc/dataloader/readers/schema/{1}".format\ 152 156 (base, cansas_defaults.get("schema")).replace("\\", "/") 153 157 … … 156 160 return cansas_defaults 157 161 158 def read(self, xml_file): 162 ## TODO: Test loading invalid CanSAS XML files and see if this works 163 ## TODO: Once works, try adding a warning that the data is invalid 164 def read(self, xml_file, schema_path=""): 159 165 """ 160 166 Validate and read in an xml_file file in the canSAS format. … … 174 180 if extension in self.ext or self.allow_all: 175 181 # Get the file location of 176 cansas_defaults = self.load_file_and_schema(xml_file )182 cansas_defaults = self.load_file_and_schema(xml_file, schema_path) 177 183 178 184 # Try to load the file, but raise an error if unable to. … … 225 231 except: 226 232 # If the file does not match the schema, raise this error 227 raise RuntimeError, "%s cannot be read" % xml_file 233 schema_path = "{0}/sas/sascalc/dataloader/readers/schema/cansas1d_invalid.xsd" 234 invalid_xml = self.find_invalid_xml() 235 invalid_xml = "\n\nThe loaded xml file does not fully meet the CanSAS v1.x specification. SasView " + \ 236 "loaded as much of the data as possible.\n\n" + invalid_xml 237 self.errors.add(invalid_xml) 238 self.set_schema(schema_path) 239 if self.is_cansas(): 240 output = self.read(xml_file, schema_path) 241 else: 242 raise RuntimeError, "%s cannot be read" % xml_file 228 243 return output 229 244 # Return a list of parsed entries that dataloader can manage
Note: See TracChangeset
for help on using the changeset viewer.