1 | import os.path |
---|
2 | |
---|
3 | def readPlotList(filename): |
---|
4 | ''' |
---|
5 | Reads in a text file with run numbers to plot. 8 first characters of each line are nexus file |
---|
6 | names without extension that must be loaded. |
---|
7 | |
---|
8 | Returns a list of nexus file names to load |
---|
9 | ''' |
---|
10 | if not os.path.exists( filename ): |
---|
11 | raise Exception('Cannot find file ' + filename) |
---|
12 | |
---|
13 | dir = os.path.dirname( filename ) |
---|
14 | fileList = [] |
---|
15 | |
---|
16 | f = open(filename,'r') |
---|
17 | for line in f: |
---|
18 | if len(line) >= 8: |
---|
19 | runName = os.path.join( dir, line[:8] + '.nxs' ) |
---|
20 | fileList.append( runName ) |
---|
21 | f.close() |
---|
22 | |
---|
23 | return fileList |
---|
24 | |
---|
25 | def setNumericAxis(wsname): |
---|
26 | from mantidsimple import createNumericAxis, mtd |
---|
27 | thPlot = mtd[wsname] |
---|
28 | axis = createNumericAxis(thPlot.getNumberHistograms()) |
---|
29 | thPlot.replaceAxis( 1, axis ) |
---|
30 | |
---|
31 | def createThermoWS( fileList ): |
---|
32 | ''' |
---|
33 | Loads the nexus files in fileList. The files must contain workspace groups, each member |
---|
34 | workspace must contain 1 spectrum. |
---|
35 | ''' |
---|
36 | i = 0 |
---|
37 | nEntries = -1 |
---|
38 | groups = [] |
---|
39 | thermoWS = [] |
---|
40 | |
---|
41 | # load the file |
---|
42 | for f in fileList: |
---|
43 | wsName = '_thermo_plot_' + str(i) |
---|
44 | i += 1 |
---|
45 | ws = Load( f, OutputWorkspace = wsName ) |
---|
46 | # check that all workspaces have the same size |
---|
47 | n = ws.getNumberOfEntries() |
---|
48 | if nEntries < 0: |
---|
49 | nEntries = n |
---|
50 | elif n != nEntries: |
---|
51 | raise Exception('Workspace groups have different sizes') |
---|
52 | groups.append( wsName ) |
---|
53 | |
---|
54 | for i in range( 1, nEntries+1 ): |
---|
55 | # construct a comma-separated list of member workspace names |
---|
56 | workspaces = ('_'+str(i)+',').join(groups)+'_'+str(i) |
---|
57 | thPlot = ConjoinSpectra(InputWorkspaces=workspaces,OutputWorkspace='ThermoPlot_'+str(i),WorkspaceIndex=0) |
---|
58 | thermoWS.append( thPlot.getName() ) |
---|
59 | setNumericAxis(thPlot.getName()) |
---|
60 | ax1 = thPlot.getAxis(1) |
---|
61 | for i in range(ax1.length()): |
---|
62 | ax1.setValue(i,i) |
---|
63 | |
---|
64 | # for ws in groups: |
---|
65 | # DeleteWorkspace( ws ) |
---|
66 | |
---|
67 | return thermoWS |
---|
68 | |
---|
69 | if __name__ == "__main__": |
---|
70 | fileList = readPlotList(r'PlotList.txt') |
---|
71 | workspaces = createThermoWS( fileList ) |
---|
72 | m = importMatrixWorkspace(workspaces[0]) |
---|
73 | m.plotGraph2D() |
---|
74 | m.plotGraph3D() |
---|
75 | |
---|