Changeset 58a255b in sasview for src/sas


Ignore:
Timestamp:
Jul 20, 2017 11:38:31 AM (7 years ago)
Author:
lewis
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
Message:

Better comments & add docstrings

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/file_converter/ascii2d_loader.py

    rf25328a5 r58a255b  
    77 
    88# ISIS 2D ASCII File Format 
     9# http://www.isis.stfc.ac.uk/instruments/loq/software/colette-ascii-file-format-descriptions9808.pdf 
    910# line: property 
    1011# 0: File header 
     
    2324 
    2425    def __init__(self, data_path): 
     26        """ 
     27        :param data_path: The path to the file to load 
     28        """ 
    2529        self.data_path = data_path 
    2630 
    2731    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        """ 
    2838        file_handle = open(self.data_path, 'r') 
    2939        file_buffer = file_handle.read() 
    3040        all_lines = file_buffer.splitlines() 
    3141 
    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): 
    3345            qs = np.zeros(num_points) 
    3446            n = start_line 
     
    4153            return n, qs 
    4254 
    43         # Skip nUseRec lines 
    4455        current_line = 4 
    4556        try: 
     57            # Skip nUseRec lines 
    4658            nUseRec = int(all_lines[current_line].strip()[0]) 
    4759            current_line += nUseRec + 1 
     
    4961            num_qs = int(all_lines[current_line].strip()) 
    5062            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) 
    5264 
    5365            # Read qy data 
    5466            num_qs = int(all_lines[current_line].strip()) 
    5567            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) 
    5769        except ValueError as e: 
    5870            err_msg = "File incorrectly formatted.\n" 
     
    105117        current_line += 1 
    106118 
    107         current_line, I = _load_qs(all_lines, current_line, width*height) 
     119        current_line, I = _load_points(all_lines, current_line, width*height) 
    108120        dI = np.zeros(width*height) 
    109121 
     122        # Load error data if it's provided 
    110123        if iflag == 3: 
    111             _, dI = _load_qs(all_lines, current_line, width*height) 
     124            _, dI = _load_points(all_lines, current_line, width*height) 
    112125 
    113126        # Format data for use with Data2D 
Note: See TracChangeset for help on using the changeset viewer.