-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnet2txt.py
More file actions
38 lines (27 loc) · 810 Bytes
/
Copy pathnet2txt.py
File metadata and controls
38 lines (27 loc) · 810 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
## This program used to conv .net(generate by mxa) to .txt
import sys
import numpy as np
import os
if len(sys.argv) < 2:
print("Usage: python net2txt.py <filename_without_ext>")
sys.exit(1)
base = sys.argv[1]
infile = base + ".net"
outfile = base + ".txt"
if not os.path.exists(infile):
print(f"Input file not found: {infile}")
sys.exit(1)
nbin = 4096
emin = 0.0
emax = 2048.0
header_size = 1024
bin_width = (emax - emin) / nbin
with open(infile, "rb") as f:
f.seek(header_size)
counts = np.fromfile(f, dtype=np.int32, count=nbin)
energy = emin + (np.arange(nbin) + 0.5) * bin_width # bin 中心
with open(outfile, "w") as f:
f.write("# Energy_keV Counts\n")
for e, c in zip(energy, counts):
f.write(f"{e:.3f} {c}\n")
print(f"Saved spectrum to {outfile}")