Last active 1742231427

yuanpeng's Avatar yuanpeng revised this gist 1742231427. Go to revision

1 file changed, 33 insertions

wksp2data.py(file created)

@@ -0,0 +1,33 @@
1 + # import mantid algorithms, numpy and matplotlib
2 + from mantid.simpleapi import *
3 + import matplotlib.pyplot as plt
4 + import numpy as np
5 + import os
6 + from pathlib import Path
7 +
8 + nxs_file = "./SofQ/NOM_Si_640e.nxs"
9 + out_dir = "./texture_proc"
10 +
11 + stem_name = os.path.basename(nxs_file).split(".")[0]
12 +
13 + if stem_name not in mtd:
14 + LoadNexus(
15 + Filename=nxs_file,
16 + OutputWorkspace=stem_name
17 + )
18 +
19 + Path(out_dir).mkdir(parents=True, exist_ok=True)
20 +
21 + for i in range(mtd[stem_name].getNumberHistograms()):
22 + x_tmp = mtd[stem_name].readX(i)
23 + y_tmp = mtd[stem_name].readY(i)
24 + y_tmp = np.insert(y_tmp, 0, y_tmp[0])
25 + spec_id = mtd[stem_name].getSpectrum(i).getSpectrumNo()
26 + out_file = os.path.join(
27 + out_dir,
28 + f"{stem_name}_bank{spec_id}.dat"
29 + )
30 + with open(out_file, "w") as f:
31 + f.write(f"{len(x_tmp)}\n\n")
32 + for j, item in enumerate(x_tmp):
33 + f.write("{0:10.4F}{1:20.5F}\n".format(item, y_tmp[j]))
Newer Older