ESS_GUIESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change
on this file since 2f55df6 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 | """ |
---|
2 | This software was developed by the University of Tennessee as part of the |
---|
3 | Distributed Data Analysis of Neutron Scattering Experiments (DANSE) |
---|
4 | project funded by the US National Science Foundation. |
---|
5 | |
---|
6 | See the license text in license.txt |
---|
7 | |
---|
8 | copyright 2008, University of Tennessee |
---|
9 | """ |
---|
10 | from __future__ import print_function |
---|
11 | |
---|
12 | import os |
---|
13 | import numpy as np |
---|
14 | from sas.sascalc.dataloader.data_info import Data1D |
---|
15 | |
---|
16 | |
---|
17 | class 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 | |
---|
60 | if __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.