Skip to content
This repository has been archived by the owner on Nov 5, 2020. It is now read-only.

Commit

Permalink
Order input fields in measurement browser according to measurement (c…
Browse files Browse the repository at this point in the history
…lose #229)
  • Loading branch information
paulmueller committed Nov 7, 2018
1 parent 9ce4bb0 commit ec3dac9
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
0.8.9
- Enhancements:
- Order input fields in measurement browser according to measurement
number (#229)
0.8.8
- Bugfixes:
- "Mean of empty slice" error when attempting to plot bad data
Expand Down
33 changes: 31 additions & 2 deletions shapeout/meta_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,37 @@ def collect_data_tree(directories):
def find_data(path):
"""Find tdms and rtdc data files in a directory"""
path = pathlib.Path(path)
tdmsfiles = sorted(fmt_tdms.get_tdms_files(path))
rtdcfiles = sorted([r for r in path.rglob("*.rtdc") if r.is_file()])

def sort_path(path):
"""Sorting key for intuitive file sorting
This sorts a list of RT-DC files according to measurement number,
e.g. (M2_*.tdms is not sorted after M11_*.tdms):
/path/to/M1_*.tdms
/path/to/M2_*.tdms
/path/to/M10_*.tdms
/path/to/M11_*.tdms
Note that the measurement number of .rtdc files is extracted from
the hdf5 metadata and not from the file name.
"""
try:
# try to get measurement number as an integer
idx = get_run_index(path)
except BaseException:
# just use the given path
name = path.name
else:
# assign new "name" for sorting
name = "{:09d}_{}".format(idx, path.name)
return path.with_name(name)

tdmsfiles = fmt_tdms.get_tdms_files(path)
tdmsfiles = sorted(tdmsfiles, key=sort_path)
rtdcfiles = [r for r in path.rglob("*.rtdc") if r.is_file()]
rtdcfiles = sorted(rtdcfiles, key=sort_path)

files = [pathlib.Path(ff) for ff in rtdcfiles + tdmsfiles]
return files

Expand Down
32 changes: 32 additions & 0 deletions tests/test_meta_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,38 @@ def test_collect_data_tree():
shutil.rmtree(str(edest), ignore_errors=True)


def test_collect_data_tree_order():
features = ["area_um", "deform", "time"]
edest = pathlib.Path(tempfile.mkdtemp(prefix="shapeout_test"))

for ii in range(1, 13):
dat = new_dataset(data=example_data_dict(ii + 10, keys=features))
cfg = {"experiment": {"sample": "test sample",
"run index": ii},
"imaging": {"pixel size": 0.34},
"setup": {"channel width": 20,
"chip region": "channel",
"flow rate": 0.04}
}
dat.config.update(cfg)
dat.export.hdf5(path=edest / "M{}_data.rtdc".format(ii),
features=features)
data = meta_tool.collect_data_tree([edest])[0]
assert pathlib.Path(data[0][1][1]).name == "M1_data.rtdc"
assert pathlib.Path(data[0][2][1]).name == "M2_data.rtdc"
assert pathlib.Path(data[0][3][1]).name == "M3_data.rtdc"
assert pathlib.Path(data[0][4][1]).name == "M4_data.rtdc"
assert pathlib.Path(data[0][5][1]).name == "M5_data.rtdc"
assert pathlib.Path(data[0][6][1]).name == "M6_data.rtdc"
assert pathlib.Path(data[0][7][1]).name == "M7_data.rtdc"
assert pathlib.Path(data[0][8][1]).name == "M8_data.rtdc"
assert pathlib.Path(data[0][9][1]).name == "M9_data.rtdc"
assert pathlib.Path(data[0][10][1]).name == "M10_data.rtdc"
assert pathlib.Path(data[0][11][1]).name == "M11_data.rtdc"
assert pathlib.Path(data[0][12][1]).name == "M12_data.rtdc"
shutil.rmtree(str(edest), ignore_errors=True)


def test_collect_data_tree_unicode():
features = ["area_um", "deform", "time"]
edest = pathlib.Path(tempfile.mkdtemp(prefix="shapeout_test_únícòdè".encode("utf-8")))
Expand Down

0 comments on commit ec3dac9

Please sign in to comment.