ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change
on this file since 4101eea was
de9483d,
checked in by Mathieu Doucet <doucetm@…>, 16 years ago
|
added data loader
|
-
Property mode set to
100644
|
File size:
1.2 KB
|
Line | |
---|
1 | import os |
---|
2 | import wx |
---|
3 | |
---|
4 | def choose_data_file(parent, location=None): |
---|
5 | path = None |
---|
6 | if location==None: |
---|
7 | location = os.getcwd() |
---|
8 | dlg = wx.FileDialog(parent, "Choose a file", location, "", "*.txt", wx.OPEN) |
---|
9 | if dlg.ShowModal() == wx.ID_OK: |
---|
10 | path = dlg.GetPath() |
---|
11 | mypath = os.path.basename(path) |
---|
12 | dlg.Destroy() |
---|
13 | |
---|
14 | return path |
---|
15 | |
---|
16 | |
---|
17 | def load_ascii_1D(path): |
---|
18 | """ |
---|
19 | Load a 1D ascii file, with errors |
---|
20 | """ |
---|
21 | |
---|
22 | if path and os.path.isfile(path): |
---|
23 | |
---|
24 | file_x = [] |
---|
25 | file_y = [] |
---|
26 | file_dy = [] |
---|
27 | |
---|
28 | input_f = open(path,'r') |
---|
29 | buff = input_f.read() |
---|
30 | lines = buff.split('\n') |
---|
31 | for line in lines: |
---|
32 | try: |
---|
33 | toks = line.split() |
---|
34 | x = float(toks[0]) |
---|
35 | y = float(toks[1]) |
---|
36 | if len(toks)==3: |
---|
37 | err = float(toks[2]) |
---|
38 | else: |
---|
39 | err = 0.0 |
---|
40 | file_x.append(x) |
---|
41 | file_y.append(y) |
---|
42 | file_dy.append(err) |
---|
43 | except: |
---|
44 | print "READ ERROR", line |
---|
45 | |
---|
46 | return file_x, file_y, file_dy |
---|
47 | return None, None, None |
---|
Note: See
TracBrowser
for help on using the repository browser.