Changeset da8bb53 in sasview for src/sas/sascalc/dataloader/readers
- Timestamp:
- Apr 17, 2017 4:30:10 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.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- ad92c5a
- Parents:
- 8ffafd1
- git-author:
- Jeff Krzywon <krzywon@…> (04/17/17 16:30:10)
- git-committer:
- krzywon <krzywon@…> (04/17/17 16:30:10)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/dataloader/readers/ascii_reader.py
r8ffafd1 rda8bb53 17 17 from sas.sascalc.dataloader.file_reader_base_class import FileReader 18 18 from sas.sascalc.dataloader.data_info import DataInfo, plottable_1D 19 from sas.sascalc.dataloader.loader_exceptions import FileContentsException,\ 20 DefaultReaderException 19 21 20 22 logger = logging.getLogger(__name__) … … 110 112 line_no += 1 111 113 except ValueError: 114 # ValueError is raised when non numeric strings conv. to float 112 115 # It is data and meet non - number, then stop reading 113 116 if is_data: … … 121 124 # Reset # of lines of data candidates 122 125 candidate_lines = 0 123 except Exception:124 # Handle any unexpected exceptions125 raise126 126 127 127 if not is_data: 128 # TODO: Check file extension - primary reader, throw error. 129 # TODO: Secondary check, pass and try next reader 130 msg = "ascii_reader: x has no data" 131 raise RuntimeError(msg) 128 self.set_all_to_none() 129 if self.extension in self.ext: 130 msg = "ASCII Reader error: Fewer than five Q data points found " 131 msg += "in {}.".format(filepath) 132 raise FileContentsException(msg) 133 else: 134 msg = "ASCII Reader could not load the file {}".format(filepath) 135 raise DefaultReaderException(msg) 132 136 # Sanity check 133 137 if has_error_dy and not len(self.current_dataset.y) == \ 134 138 len(self.current_dataset.dy): 135 msg = "ascii_reader: y and dy have different length" 136 raise RuntimeError(msg) 139 msg = "ASCII Reader error: Number of I and dI data points are" 140 msg += " different in {}.".format(filepath) 141 # TODO: Add error to self.current_datainfo.errors instead? 142 self.set_all_to_none() 143 raise FileContentsException(msg) 137 144 if has_error_dx and not len(self.current_dataset.x) == \ 138 145 len(self.current_dataset.dx): 139 msg = "ascii_reader: y and dy have different length" 140 raise RuntimeError(msg) 141 # If the data length is zero, consider this as 142 # though we were not able to read the file. 143 if len(self.current_dataset.x) < 1: 144 raise RuntimeError("ascii_reader: could not load file") 146 msg = "ASCII Reader error: Number of Q and dQ data points are" 147 msg += " different in {}.".format(filepath) 148 # TODO: Add error to self.current_datainfo.errors instead? 149 self.set_all_to_none() 150 raise FileContentsException(msg) 145 151 146 # Data152 # Remove any point where Q == 0 147 153 x = self.current_dataset.x 148 154 self.current_dataset.x = self.current_dataset.x[x != 0]
Note: See TracChangeset
for help on using the changeset viewer.