rainbow-api 1.0.6__tar.gz → 1.0.8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {rainbow-api-1.0.6/rainbow_api.egg-info → rainbow_api-1.0.8}/PKG-INFO +1 -1
- {rainbow-api-1.0.6 → rainbow_api-1.0.8}/pyproject.toml +1 -1
- {rainbow-api-1.0.6 → rainbow_api-1.0.8}/rainbow/agilent/chemstation.py +94 -48
- {rainbow-api-1.0.6 → rainbow_api-1.0.8}/rainbow/waters/masslynx.py +25 -0
- {rainbow-api-1.0.6 → rainbow_api-1.0.8/rainbow_api.egg-info}/PKG-INFO +1 -1
- {rainbow-api-1.0.6 → rainbow_api-1.0.8}/COPYING +0 -0
- {rainbow-api-1.0.6 → rainbow_api-1.0.8}/README.md +0 -0
- {rainbow-api-1.0.6 → rainbow_api-1.0.8}/rainbow/__init__.py +0 -0
- {rainbow-api-1.0.6 → rainbow_api-1.0.8}/rainbow/agilent/__init__.py +0 -0
- {rainbow-api-1.0.6 → rainbow_api-1.0.8}/rainbow/agilent/masshunter.py +0 -0
- {rainbow-api-1.0.6 → rainbow_api-1.0.8}/rainbow/datadirectory.py +0 -0
- {rainbow-api-1.0.6 → rainbow_api-1.0.8}/rainbow/datafile.py +0 -0
- {rainbow-api-1.0.6 → rainbow_api-1.0.8}/rainbow/waters/__init__.py +0 -0
- {rainbow-api-1.0.6 → rainbow_api-1.0.8}/rainbow_api.egg-info/SOURCES.txt +0 -0
- {rainbow-api-1.0.6 → rainbow_api-1.0.8}/rainbow_api.egg-info/dependency_links.txt +0 -0
- {rainbow-api-1.0.6 → rainbow_api-1.0.8}/rainbow_api.egg-info/requires.txt +0 -0
- {rainbow-api-1.0.6 → rainbow_api-1.0.8}/rainbow_api.egg-info/top_level.txt +0 -0
- {rainbow-api-1.0.6 → rainbow_api-1.0.8}/setup.cfg +0 -0
- {rainbow-api-1.0.6 → rainbow_api-1.0.8}/tests/test_agilent.py +0 -0
- {rainbow-api-1.0.6 → rainbow_api-1.0.8}/tests/test_datadirectory.py +0 -0
- {rainbow-api-1.0.6 → rainbow_api-1.0.8}/tests/test_datafile.py +0 -0
- {rainbow-api-1.0.6 → rainbow_api-1.0.8}/tests/test_waters.py +0 -0
|
@@ -88,14 +88,14 @@ def parse_ch(path):
|
|
|
88
88
|
"""
|
|
89
89
|
with open(path, 'rb') as f:
|
|
90
90
|
head = read_string(f, offset=0, gap=1)
|
|
91
|
-
if head
|
|
92
|
-
return parse_ch_fid(path)
|
|
93
|
-
elif head
|
|
91
|
+
if head in ['179', '181']:
|
|
92
|
+
return parse_ch_fid(path, head)
|
|
93
|
+
elif head in ['130', '30']:
|
|
94
94
|
return parse_ch_other(path, head)
|
|
95
95
|
return None
|
|
96
96
|
|
|
97
97
|
|
|
98
|
-
def parse_ch_fid(path):
|
|
98
|
+
def parse_ch_fid(path, head):
|
|
99
99
|
"""
|
|
100
100
|
Parses an Agilent .ch file with FID channel data.
|
|
101
101
|
|
|
@@ -110,21 +110,43 @@ def parse_ch_fid(path):
|
|
|
110
110
|
DataFile with FID data, if the file can be parsed. Otherwise, None.
|
|
111
111
|
|
|
112
112
|
"""
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
113
|
+
if head == '181':
|
|
114
|
+
data_offsets = {
|
|
115
|
+
'num_times': 0x116,
|
|
116
|
+
'scaling_factor': 0x127C,
|
|
117
|
+
'data_start': 0x1800
|
|
118
|
+
}
|
|
119
|
+
metadata_offsets = {
|
|
120
|
+
'notebook': 0x35A,
|
|
121
|
+
'date': 0x957,
|
|
122
|
+
'method': 0xA0E,
|
|
123
|
+
'instrument': 0xC11,
|
|
124
|
+
'unit': 0x104C,
|
|
125
|
+
}
|
|
126
|
+
gap = 2
|
|
127
|
+
elif head == '179':
|
|
128
|
+
data_offsets = {
|
|
129
|
+
'num_times': 0x116,
|
|
130
|
+
'scaling_factor': 0x127C,
|
|
131
|
+
'data_start': 0x1800
|
|
132
|
+
}
|
|
133
|
+
metadata_offsets = {
|
|
134
|
+
'notebook': 0x35A,
|
|
135
|
+
'date': 0x957,
|
|
136
|
+
'method': 0xA0E,
|
|
137
|
+
'instrument': 0xC11,
|
|
138
|
+
'unit': 0x104C,
|
|
139
|
+
'signal': 0x1075
|
|
140
|
+
}
|
|
118
141
|
|
|
119
142
|
f = open(path, 'rb')
|
|
120
143
|
raw_bytes = f.read()
|
|
144
|
+
file_size = f.tell()
|
|
121
145
|
|
|
122
146
|
# Extract the number of retention times.
|
|
123
|
-
|
|
124
|
-
num_times = struct.unpack(">I", f.read(4))[0]
|
|
125
|
-
if num_times == 0:
|
|
126
|
-
return None
|
|
147
|
+
num_times = (file_size - data_offsets['data_start']) // 8
|
|
127
148
|
|
|
149
|
+
f.seek(data_offsets['num_times'] + 4)
|
|
128
150
|
# Compute retention times using the first and last times.
|
|
129
151
|
start_time = struct.unpack(">f", f.read(4))[0]
|
|
130
152
|
end_time = struct.unpack(">f", f.read(4))[0]
|
|
@@ -132,8 +154,10 @@ def parse_ch_fid(path):
|
|
|
132
154
|
times = np.arange(start_time, end_time + 1e-3, delta_time)
|
|
133
155
|
|
|
134
156
|
# Extract the raw data values.
|
|
135
|
-
|
|
136
|
-
|
|
157
|
+
if head == '181':
|
|
158
|
+
data = np.array(decode_double_delta(f, data_offsets['data_start']), dtype=np.float64)
|
|
159
|
+
else:
|
|
160
|
+
data = np.ndarray(num_times, '<d', raw_bytes, data_offsets['data_start'], 8)
|
|
137
161
|
data = data.copy().reshape(-1, 1)
|
|
138
162
|
|
|
139
163
|
# Convert times into minutes.
|
|
@@ -148,14 +172,6 @@ def parse_ch_fid(path):
|
|
|
148
172
|
ylabels = np.array([''])
|
|
149
173
|
|
|
150
174
|
# Extract metadata from file header.
|
|
151
|
-
metadata_offsets = {
|
|
152
|
-
'notebook': 0x35A,
|
|
153
|
-
'date': 0x957,
|
|
154
|
-
'method': 0xA0E,
|
|
155
|
-
'instrument': 0xC11,
|
|
156
|
-
'unit': 0x104C,
|
|
157
|
-
'signal': 0x1075
|
|
158
|
-
}
|
|
159
175
|
metadata = read_header(f, metadata_offsets)
|
|
160
176
|
f.close()
|
|
161
177
|
|
|
@@ -218,31 +234,10 @@ def parse_ch_other(path, head):
|
|
|
218
234
|
int_unpack = struct.Struct('>i').unpack
|
|
219
235
|
|
|
220
236
|
# Extract the raw data values.
|
|
221
|
-
# Count the total number of retention times.
|
|
222
|
-
f.seek(data_offsets['data_start'])
|
|
223
|
-
absorbances = []
|
|
224
|
-
absorb_accum = 0
|
|
225
|
-
while True:
|
|
226
|
-
# If the segment header is invalid, stop reading.
|
|
227
|
-
head = byte_unpack(f.read(1))[0]
|
|
228
|
-
if head != 0x10:
|
|
229
|
-
break
|
|
230
|
-
num_times_seg = byte_unpack(f.read(1))[0]
|
|
231
|
-
|
|
232
|
-
# If the next short is equal to -0x8000
|
|
233
|
-
# then the next absorbance value is the next integer.
|
|
234
|
-
# Otherwise, the short is a delta from the last absorbance value.
|
|
235
|
-
for _ in range(num_times_seg):
|
|
236
|
-
check_int = short_unpack(f.read(2))[0]
|
|
237
|
-
if check_int == -0x8000:
|
|
238
|
-
absorb_accum = int_unpack(f.read(4))[0]
|
|
239
|
-
else:
|
|
240
|
-
absorb_accum += check_int
|
|
241
|
-
absorbances.append(absorb_accum)
|
|
242
|
-
|
|
237
|
+
# Count the total number of retention times.
|
|
243
238
|
# Process the extracted values.
|
|
244
|
-
# If no values are extracted, this file is invalid.
|
|
245
|
-
data = np.array(
|
|
239
|
+
# If no values are extracted, this file is invalid.
|
|
240
|
+
data = np.array(decode_delta(f, data_offsets['data_start']))
|
|
246
241
|
num_times = data.size
|
|
247
242
|
if num_times == 0:
|
|
248
243
|
return None
|
|
@@ -279,6 +274,57 @@ def parse_ch_other(path, head):
|
|
|
279
274
|
|
|
280
275
|
return DataFile(path, detector, times, ylabels, data, metadata)
|
|
281
276
|
|
|
277
|
+
def decode_delta(f, offset):
|
|
278
|
+
byte_unpack = struct.Struct('>B').unpack
|
|
279
|
+
short_unpack = struct.Struct('>h').unpack
|
|
280
|
+
int_unpack = struct.Struct('>i').unpack
|
|
281
|
+
# Extract the raw data values.
|
|
282
|
+
# Count the total number of retention times.
|
|
283
|
+
f.seek(offset)
|
|
284
|
+
absorbances = []
|
|
285
|
+
absorb_accum = 0
|
|
286
|
+
while True:
|
|
287
|
+
# If the segment header is invalid, stop reading.
|
|
288
|
+
head = byte_unpack(f.read(1))[0]
|
|
289
|
+
if head != 0x10:
|
|
290
|
+
break
|
|
291
|
+
num_times_seg = byte_unpack(f.read(1))[0]
|
|
292
|
+
|
|
293
|
+
# If the next short is equal to -0x8000
|
|
294
|
+
# then the next absorbance value is the next integer.
|
|
295
|
+
# Otherwise, the short is a delta from the last absorbance value.
|
|
296
|
+
for _ in range(num_times_seg):
|
|
297
|
+
check_int = short_unpack(f.read(2))[0]
|
|
298
|
+
if check_int == -0x8000:
|
|
299
|
+
absorb_accum = int_unpack(f.read(4))[0]
|
|
300
|
+
else:
|
|
301
|
+
absorb_accum += check_int
|
|
302
|
+
absorbances.append(absorb_accum)
|
|
303
|
+
|
|
304
|
+
return absorbances
|
|
305
|
+
|
|
306
|
+
def decode_double_delta(f, offset):
|
|
307
|
+
byte_unpack = struct.Struct('>B').unpack
|
|
308
|
+
short_unpack = struct.Struct('>h').unpack
|
|
309
|
+
int_unpack = struct.Struct('>i').unpack
|
|
310
|
+
f.seek(0, 2)
|
|
311
|
+
file_size = f.tell()
|
|
312
|
+
f.seek(offset)
|
|
313
|
+
signals = []
|
|
314
|
+
count = 1
|
|
315
|
+
buffer = [0, 0, 0]
|
|
316
|
+
|
|
317
|
+
while f.tell() < file_size:
|
|
318
|
+
buffer[2] = short_unpack(f.read(2))[0]
|
|
319
|
+
if buffer[2] == 0x7fff:
|
|
320
|
+
buffer[0] = short_unpack(f.read(2))[0] << 32 | int_unpack(f.read(4))[0]
|
|
321
|
+
buffer[1] = 0
|
|
322
|
+
else:
|
|
323
|
+
buffer[1] += buffer[2]
|
|
324
|
+
buffer[0] += buffer[1]
|
|
325
|
+
signals.append(buffer[0])
|
|
326
|
+
|
|
327
|
+
return signals
|
|
282
328
|
|
|
283
329
|
"""
|
|
284
330
|
.uv PARSING METHODS
|
|
@@ -559,7 +605,7 @@ def parse_ms(path, prec=0):
|
|
|
559
605
|
num_times = int_unpack(f.read(4))[0]
|
|
560
606
|
else:
|
|
561
607
|
f.seek(data_offsets['gc_num_times'])
|
|
562
|
-
num_times = struct.unpack('<
|
|
608
|
+
num_times = struct.unpack('<H', f.read(2))[0]
|
|
563
609
|
|
|
564
610
|
# Go to the data start offset.
|
|
565
611
|
f.seek(data_offsets['data_start'])
|
|
@@ -6,6 +6,7 @@ import os
|
|
|
6
6
|
import re
|
|
7
7
|
import numpy as np
|
|
8
8
|
from rainbow.datafile import DataFile
|
|
9
|
+
import pandas as pd
|
|
9
10
|
|
|
10
11
|
"""
|
|
11
12
|
SPECTRUM PARSING METHODS
|
|
@@ -664,3 +665,27 @@ def parse_metadata(path):
|
|
|
664
665
|
if not value.isspace():
|
|
665
666
|
metadata['vialpos'] = value
|
|
666
667
|
return metadata
|
|
668
|
+
|
|
669
|
+
|
|
670
|
+
|
|
671
|
+
def parse_compound_names(path):
|
|
672
|
+
with open(os.path.join(path, "_FUNC001.CMP"), "rb") as f:
|
|
673
|
+
data = f.read().decode("ascii", "ignore")
|
|
674
|
+
data = data[7:]
|
|
675
|
+
data = data.split("\x00")
|
|
676
|
+
data = list(filter(lambda x: x != "", data))
|
|
677
|
+
# loop through the da{}ta and remove the byte sequences x18
|
|
678
|
+
data = [re.sub(r'\x18', '', x) for x in data]
|
|
679
|
+
data
|
|
680
|
+
|
|
681
|
+
compounds = []
|
|
682
|
+
transition = []
|
|
683
|
+
for i in range(0, len(data), 3):
|
|
684
|
+
compounds.append(data[i])
|
|
685
|
+
transition.append(data[i+1])
|
|
686
|
+
df = pd.DataFrame({"compounds": compounds, "transition": transition})
|
|
687
|
+
|
|
688
|
+
df["index"] = [i for i in range(1, len(transition)+1)]
|
|
689
|
+
df["measurments"] = df["compounds"] + df["index"].astype(str)
|
|
690
|
+
|
|
691
|
+
return df
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|