wksp2data.py
· 943 B · Python
Bruto
# import mantid algorithms, numpy and matplotlib
from mantid.simpleapi import *
import matplotlib.pyplot as plt
import numpy as np
import os
from pathlib import Path
nxs_file = "./SofQ/NOM_Si_640e.nxs"
out_dir = "./texture_proc"
stem_name = os.path.basename(nxs_file).split(".")[0]
if stem_name not in mtd:
LoadNexus(
Filename=nxs_file,
OutputWorkspace=stem_name
)
Path(out_dir).mkdir(parents=True, exist_ok=True)
for i in range(mtd[stem_name].getNumberHistograms()):
x_tmp = mtd[stem_name].readX(i)
y_tmp = mtd[stem_name].readY(i)
y_tmp = np.insert(y_tmp, 0, y_tmp[0])
spec_id = mtd[stem_name].getSpectrum(i).getSpectrumNo()
out_file = os.path.join(
out_dir,
f"{stem_name}_bank{spec_id}.dat"
)
with open(out_file, "w") as f:
f.write(f"{len(x_tmp)}\n\n")
for j, item in enumerate(x_tmp):
f.write("{0:10.4F}{1:20.5F}\n".format(item, y_tmp[j]))
| 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])) |