Last active 1742231427

wksp2data.py Raw
1# import mantid algorithms, numpy and matplotlib
2from mantid.simpleapi import *
3import matplotlib.pyplot as plt
4import numpy as np
5import os
6from pathlib import Path
7
8nxs_file = "./SofQ/NOM_Si_640e.nxs"
9out_dir = "./texture_proc"
10
11stem_name = os.path.basename(nxs_file).split(".")[0]
12
13if stem_name not in mtd:
14 LoadNexus(
15 Filename=nxs_file,
16 OutputWorkspace=stem_name
17 )
18
19Path(out_dir).mkdir(parents=True, exist_ok=True)
20
21for 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]))