-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimportAliScan.py
More file actions
53 lines (43 loc) · 1.83 KB
/
importAliScan.py
File metadata and controls
53 lines (43 loc) · 1.83 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
43
44
45
46
47
48
49
50
51
52
53
#
# import function for Allison scanner data
# John Wieland
###############################################################################
import re
import numpy as np
# Imports raw alison scanner data, no conversions included
def importRaw(fn):
#search for slice headers, and pull metadata from file
f = open(fn,"r")
sliceArr = []
for i,line in enumerate(f):
if re.match("Slice\s[0-9]{3}",line):
sliceArr.append(i)
elif re.match("Angle\sStart",line):
angIni = float(line.split(",")[-1])
elif re.match("Angle\sStop",line):
angFin = float(line.split(",")[-1])
elif re.match("Angle\sDelta",line):
angDel = float(line.split(",")[-1])
elif re.match("Position\sStart",line):
posIni = float(line.split(",")[-1])
elif re.match("Position\sStop",line):
posFin = float(line.split(",")[-1])
elif re.match("Position\sDelta",line):
posDel = float(line.split(",")[-1])
elif re.match("Number\sBins",line):
binN = int(float(line.split(",")[-1]))
f.close()
#construct arrays of positional and angle data
#assuming angle is in milliradians
angArr = np.arange(angIni,angFin+angDel/2,angDel)*1e-3
posArr = -np.arange(posIni,posFin+posDel/2,posDel)
#store number of position and agular sample points for slicing
angN = angArr.shape[0]
posN = posArr.shape[0]
#extract data from csv, slice index by slice index
#depends on the exact format of the outuput file
#if output changes this whole read operation needs to change
fullDat = np.zeros([binN,angN,posN])
for i,s in enumerate(sliceArr):
fullDat[i] = -np.genfromtxt(fn,delimiter=",",usecols=np.arange(1,posN+1),max_rows=angN,skip_header=s+14)
return(fullDat,posArr,angArr)