/
DU640_spectrum.py
66 lines (53 loc) · 1.33 KB
/
DU640_spectrum.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python
# coding: utf-8
# # Processing UV-Vis spectra obtained from the Beckman Coulter DU-640 spectrophotometer
#
# 0. Imports
# In[2]:
import os
from .util import isFloat
# 1. The following is an example of an absorption spectrum text file obtained form the Beckman Coulter DU-640 spectrophotometer.
# User ID: DU600
#
# Method ID: A:\DEFAULT
#
# Date: 07/25/00
#
# Time: 12:02
#
# 200.0 0.25060
#
# 201.0 0.25706
#
# 202.0 0.25690
#
# 203.0 0.26161
#
# 204.0 0.26775
#
# 205.0 0.27486
#
# 206.0 0.27792
#
# 207.0 0.28106
# In[3]:
def readSpectrumFromFile(path_to_file):
'''Extracts the absorption spectrum from the text file generated by a Beckman Coulter DU-640 spectrophotometer
Parameters
----------
path_to_file : string
Path used to locate the spectrum text file.
Returns
-------
array of tuples
absorption spectrum
The first element of each tuple is the wavelength in nanometers.
The second element is the absorbance measurement in absorbance units.
'''
with open(path_to_file) as f:
spectrum = [
tuple(map(float, line.strip().split()))
for line in f.readlines()
if (line.strip() and all([isFloat(word) for word in line.strip().split()]))
]
return spectrum