source: sasview/test/sasdataloader/plugins/test_reader.py @ 441a03f

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since 441a03f was aaf5e49, checked in by andyfaff, 8 years ago

MAINT: few more print instances

  • Property mode set to 100644
File size: 1.9 KB
Line 
1"""
2This software was developed by the University of Tennessee as part of the
3Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
4project funded by the US National Science Foundation.
5
6See the license text in license.txt
7
8copyright 2008, University of Tennessee
9"""
10from __future__ import print_function
11
12import os
13import numpy as np
14from sas.sascalc.dataloader.data_info import Data1D
15
16
17class Reader:
18    """
19        Test reader to check plugin functionality
20    """
21    ## File type
22    type = ["ASCII files (*.test)|*.test"]
23    ## List of allowed extensions
24    ext=['.test'] 
25   
26    def read(self, path):
27        """
28            Load data file
29           
30            @param path: file path
31            @return: Data1D object, or None
32            @raise RuntimeError: when the file can't be opened
33            @raise ValueError: when the length of the data vectors are inconsistent
34        """
35        if os.path.isfile(path):
36            basename  = os.path.basename(path)
37            root, extension = os.path.splitext(basename)
38            if extension.lower() in self.ext:
39                try:
40                    input_f =  open(path,'r')
41                except :
42                    raise  RuntimeError, "ascii_reader: cannot open %s" % path
43                buff = input_f.read()
44                lines = buff.split('\n')
45                x  = np.zeros(0)
46                y  = np.zeros(0)
47                dy = np.zeros(0)
48                output = Data1D(x, y, dy=dy)
49                self.filename = output.filename = basename
50           
51                for line in lines:
52                    x  = np.append(x,  float(line))
53                   
54                output.x = x
55                return output
56        else:
57            raise RuntimeError, "%s is not a file" % path
58        return None
59   
60if __name__ == "__main__": 
61    reader = Reader()
62    output = reader.read("../test/test_data.test")
63    print(output.x)
64   
65   
66                       
Note: See TracBrowser for help on using the repository browser.