-
Notifications
You must be signed in to change notification settings - Fork 3
/
LoadSpectrum.py
34 lines (28 loc) · 991 Bytes
/
LoadSpectrum.py
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
import numpy as np
def read_spa(filepath):
'''
Input
Read a file (string) *.spa
----------
Output
Return spectra, wavelenght (nm), titles
'''
with open(filepath, 'rb') as f:
f.seek(564)
Spectrum_Pts = np.fromfile(f, np.int32,1)[0]
f.seek(30)
SpectraTitles = np.fromfile(f, np.uint8,255)
SpectraTitles = ''.join([chr(x) for x in SpectraTitles if x!=0])
f.seek(576)
Max_Wavenum=np.fromfile(f, np.single, 1)[0]
Min_Wavenum=np.fromfile(f, np.single, 1)[0]
# print(Min_Wavenum, Max_Wavenum, Spectrum_Pts)
Wavenumbers = np.flip(np.linspace(Min_Wavenum, Max_Wavenum, Spectrum_Pts))
f.seek(288);
Flag=0
while Flag != 3:
Flag = np.fromfile(f, np.uint16, 1)
DataPosition=np.fromfile(f,np.uint16, 1)
f.seek(DataPosition[0])
Spectra = np.fromfile(f, np.single, Spectrum_Pts)
return Spectra, 1e7/Wavenumbers, SpectraTitles