Changeset 58a255b in sasview
- Timestamp:
- Jul 20, 2017 11:38:31 AM (7 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:
- 0f010c9
- Parents:
- f25328a5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/file_converter/ascii2d_loader.py
rf25328a5 r58a255b 7 7 8 8 # ISIS 2D ASCII File Format 9 # http://www.isis.stfc.ac.uk/instruments/loq/software/colette-ascii-file-format-descriptions9808.pdf 9 10 # line: property 10 11 # 0: File header … … 23 24 24 25 def __init__(self, data_path): 26 """ 27 :param data_path: The path to the file to load 28 """ 25 29 self.data_path = data_path 26 30 27 31 def load(self): 32 """ 33 Load the data from the file into a Data2D object 34 35 :return: A Data2D instance containing data from the file 36 :raises ValueError: Raises a ValueError if the file is incorrectly formatted 37 """ 28 38 file_handle = open(self.data_path, 'r') 29 39 file_buffer = file_handle.read() 30 40 all_lines = file_buffer.splitlines() 31 41 32 def _load_qs(lines, start_line, num_points): 42 # Load num_points line-by-line from lines into a numpy array, starting 43 # on line number start_line 44 def _load_points(lines, start_line, num_points): 33 45 qs = np.zeros(num_points) 34 46 n = start_line … … 41 53 return n, qs 42 54 43 # Skip nUseRec lines44 55 current_line = 4 45 56 try: 57 # Skip nUseRec lines 46 58 nUseRec = int(all_lines[current_line].strip()[0]) 47 59 current_line += nUseRec + 1 … … 49 61 num_qs = int(all_lines[current_line].strip()) 50 62 current_line += 1 51 current_line, qx = _load_ qs(all_lines, current_line, num_qs)63 current_line, qx = _load_points(all_lines, current_line, num_qs) 52 64 53 65 # Read qy data 54 66 num_qs = int(all_lines[current_line].strip()) 55 67 current_line += 1 56 current_line, qy = _load_ qs(all_lines, current_line, num_qs)68 current_line, qy = _load_points(all_lines, current_line, num_qs) 57 69 except ValueError as e: 58 70 err_msg = "File incorrectly formatted.\n" … … 105 117 current_line += 1 106 118 107 current_line, I = _load_ qs(all_lines, current_line, width*height)119 current_line, I = _load_points(all_lines, current_line, width*height) 108 120 dI = np.zeros(width*height) 109 121 122 # Load error data if it's provided 110 123 if iflag == 3: 111 _, dI = _load_ qs(all_lines, current_line, width*height)124 _, dI = _load_points(all_lines, current_line, width*height) 112 125 113 126 # Format data for use with Data2D
Note: See TracChangeset
for help on using the changeset viewer.