Skip to content

Commit 703d554

Browse files
committed
update get files for openlab. Files are now sorted
1 parent efc1017 commit 703d554

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

openlab/openlab.py

100644100755
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,20 @@
66
from typeguard import typechecked
77
from typing import List
88

9-
109
@typechecked
1110
def get_files(path: str) -> List[str]:
1211
fs = [os.path.join(path, f) for f in os.listdir(path) if f.endswith(".cdf")]
13-
assert len(fs) > 0, "No files found"
14-
return fs
12+
assert fs, "No files found"
13+
14+
def natkey(p: str):
15+
name = os.path.basename(p)
16+
is_spectra = 1 if "_spectra" in name else 0
17+
base = name.replace("_spectra", "")
18+
parts = re.split(r"(\d+)", base)
19+
parts = [int(x) if x.isdigit() else x.lower() for x in parts]
20+
return (parts, is_spectra)
1521

22+
return sorted(fs, key=natkey)
1623

1724
# Attributes
1825
@typechecked

tests/openlab_test.py

100644100755
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,14 @@ def test_read_attr():
88
assert attr.shape == (12, 49)
99
assert attr["detector_unit"][1] == "mAU"
1010

11-
1211
test_read_attr()
1312

1413

1514
def test_read_ls():
1615
data = bp.read_lc(path)
1716
assert data.shape == (48000, 3)
1817
assert data.columns.tolist() == ["RetentionTime", "DetectorSignal", "wavelength"]
19-
assert all(data["wavelength"].unique() == [254, 550, 280, 450, 210, 230, 366, 580])
20-
18+
assert all(data["wavelength"].unique() == [210, 230, 254, 280, 366, 450, 550, 580])
2119

2220
test_read_ls()
2321

@@ -28,5 +26,4 @@ def test_read_ms():
2826
assert ms[0].shape == (1358778, 3)
2927
assert ms[1].shape == (1324471, 3)
3028

31-
3229
test_read_ms()

0 commit comments

Comments
 (0)