-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrasx2xy.py
More file actions
executable file
·43 lines (36 loc) · 1.22 KB
/
rasx2xy.py
File metadata and controls
executable file
·43 lines (36 loc) · 1.22 KB
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
38
39
40
41
42
#!/usr/bin/env python3
import sys
import zipfile
import argparse
parser = argparse.ArgumentParser(
description="Extract diffraction profile from .rasx file as .xy")
parser.add_argument("-p", action="store_true", help="print result to stdout instead of saving")
parser.add_argument("filename",help="name of rasx file")
args = parser.parse_args()
if not zipfile.is_zipfile(args.filename):
print("Error:",args.filename,"is not recognised as a rasx file.")
sys.exit(1)
with zipfile.ZipFile(args.filename) as rasx:
try:
with rasx.open('Data0/Profile0.txt') as xy:
lines = xy.readlines()
except:
print("Error: could not find profile data in ", args.filename,".", sep="")
sys.exit(1)
if (args.p):
for line in lines:
f = line.rstrip().decode().split()
print(f[0],f[1],sep=" ")
else:
fno = args.filename
if fno.endswith((".rasx", ".RASX", ".Rasx")):
fno = fno[:-5]
fno = fno + ".xy"
try:
with open(fno,"w") as of:
for line in lines:
f = line.rstrip().decode().split()
print(f[0],f[1],sep=" ", file=of)
except:
print("Error: could not write ", fno, ".", sep="")
sys.exit(1)