1 | import numpy as np |
---|
2 | |
---|
3 | |
---|
4 | def getLarmorRowColumn(index): |
---|
5 | return index%512,index/512 |
---|
6 | |
---|
7 | def getSansIndexFromLarmor(index): |
---|
8 | row, column = getLarmorRowColumn(index) |
---|
9 | row_sans = int((row * 192) / 512) |
---|
10 | column_sans = int( (column * 192) / 80) |
---|
11 | return column_sans * 192 + row_sans |
---|
12 | |
---|
13 | def createLarmorData(sansrun, larmorfile): |
---|
14 | larmor = LoadEmptyInstrument('/apps/mantid/mantid_develop2/Code/Mantid/instrument/LARMOR_Definition.xml') |
---|
15 | larmor = larmor.rebin('5.0, 200, 100000') |
---|
16 | |
---|
17 | sans2d = LoadNexus(sansrun) |
---|
18 | sans2d = sans2d.rebin('5.0, 200, 100000') |
---|
19 | |
---|
20 | for i in [0,1]: |
---|
21 | larmor.getAxis(i).setUnit(sans2d.getAxis(i).getUnit().unitID()) |
---|
22 | |
---|
23 | for i in range(8): |
---|
24 | larmor.setY(i, sans2d.readY(i)) |
---|
25 | larmor.setE(i, sans2d.readE(i)) |
---|
26 | |
---|
27 | for i in range(40960): |
---|
28 | t_index = getSansIndexFromLarmor(i) + 8 |
---|
29 | larmor.setY(i+10, sans2d.readY(t_index)) |
---|
30 | larmor.setE(i+10, sans2d.readE(t_index)) |
---|
31 | |
---|
32 | |
---|
33 | cloned_sans = CropWorkspace(sans2d,EndWorkspaceIndex=40969) |
---|
34 | |
---|
35 | for i in range(40970): |
---|
36 | cloned_sans.setY(i, larmor.readY(i)) |
---|
37 | cloned_sans.setE(i, larmor.readE(i)) |
---|
38 | |
---|
39 | LoadInstrument(cloned_sans, InstrumentName='LARMOR') |
---|
40 | |
---|
41 | #SaveNexus(cloned_sans, larmorfile) |
---|
42 | SaveNexus(larmor, larmorfile) |
---|
43 | |
---|
44 | |
---|
45 | |
---|
46 | createLarmorData('SANS2D14273','LARMOR00000073.nxs') |
---|
47 | createLarmorData('SANS2D14253', 'LARMOR00000053.nxs') |
---|
48 | createLarmorData('SANS2D14270', 'LARMOR00000070.nxs') |
---|
49 | createLarmorData('SANS2D14272', 'LARMOR00000072.nxs') |
---|
50 | |
---|
51 | full_path = FileFinder.getFullPath('LARMOR00000073.nxs') |
---|
52 | import h5py |
---|
53 | h5f = h5py.File(full_path, 'r+') |
---|
54 | sample = h5f['mantid_workspace_1/sample'] |
---|
55 | sample['geom_height'][:] = 8.0 |
---|
56 | sample['geom_id'][:] = 3 |
---|
57 | sample['geom_thickness'][:] = 2.0 |
---|
58 | sample['geom_width'] [:]= 8.0 |
---|
59 | h5f.close() |
---|
60 | |
---|
61 | |
---|