From 654a7eb4d6e778be08c9d323c116c2556121d369 Mon Sep 17 00:00:00 2001 From: Daniel Kohler <11864045+ddkohler@users.noreply.github.com> Date: Sat, 13 Sep 2025 00:51:59 -0500 Subject: [PATCH 1/3] parse documentation also some refactoring --- makeitwright/core/parsers/__init__.py | 63 ++++++++++++++++----------- 1 file changed, 38 insertions(+), 25 deletions(-) diff --git a/makeitwright/core/parsers/__init__.py b/makeitwright/core/parsers/__init__.py index 1d2de02..7a29c4b 100644 --- a/makeitwright/core/parsers/__init__.py +++ b/makeitwright/core/parsers/__init__.py @@ -40,9 +40,9 @@ def typeID(*fpaths): if "LabRAM HR" in txt: if (htype := horiba_typeID(fpath)) is not None: types[fpath] = htype - if "Goniometer" in txt: + elif "Goniometer" in txt: types[fpath] = 'Bruker_XRD' - if "[m]" in txt: + elif "[m]" in txt: types[fpath] = 'Gwyddion_traces' if fpath.suffix == '.asc': @@ -56,7 +56,7 @@ def typeID(*fpaths): if fpath.suffix == '.wt5': types[fpath] = 'wt5' - print(f"{len(types)} of {len(fpaths)} files identified as valid data types") + print(f"{len(types)} of {len(fpaths)} files designated valid") return types @@ -78,30 +78,43 @@ def listfiles(fdir:str|pathlib.Path, pattern:str="*") -> list[pathlib.Path]: ] -def parse(fdir, objective, select_types=None, keywords:list|str=[], exclude=[]): +def parse(fdir, objective, select_types=None, keywords:list|str=[], exclude:list|str=[]): """ - DOCUMENTATION NEEDED + import all files in a directory matching name rules. + A file must match all provided keywords. + Any file that matches any exclude word is ignored. + + Parameters + ---------- + fdir: path-like + directory to search for files + objective: identifier + the objective used. for images, this is used to convert camera indices into spatial coordinates + select_types: list of strings (optional) + types of data to keep (e.g. "TRPL"). other data types are ignored. + keywords: list of strings + files are only parsed if their names contain all keywords + exclude: string or list of strings + files are only parsed if their names contain no exclude words + + see also + -------- + + WrightTools.collection.from_directory """ - files = listfiles(fdir) - - include = [1 for i in range(len(files))] - if keywords: - if type(keywords) is not list: - keywords = [keywords] - for kw in keywords: - for i, f in enumerate(files): - if kw not in str(f): - include[i]=0 - if exclude: - if type(exclude) is not list: - exclude = [exclude] - for x in exclude: - for i, f in enumerate(files): - if x in str(f): - include[i]=0 - - files = [file for i, file in zip(include, files) if i] - print(f'found {sum(include)} files matching keyword specifications') + if not isinstance(keywords, list): + keywords = [keywords] + if not isinstance(exclude, list): + exclude = [exclude] + + files = [ + file for file in filter( + lambda f: all([kw in str(f) for kw in keywords]) + and all(x not in str(f) for x in exclude), + listfiles(fdir) + ) + ] + print(f'found {len(files)} files matching keyword specifications') ftypes = typeID(*files) if select_types: From 170993191544368412fc3ada2035c2ae48cd1188 Mon Sep 17 00:00:00 2001 From: Daniel Kohler <11864045+ddkohler@users.noreply.github.com> Date: Sat, 13 Sep 2025 00:52:07 -0500 Subject: [PATCH 2/3] pl test --- makeitwright/core/parsers/andor.py | 2 -- tests/test_PL.py | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 tests/test_PL.py diff --git a/makeitwright/core/parsers/andor.py b/makeitwright/core/parsers/andor.py index 0f76c54..d9c8468 100644 --- a/makeitwright/core/parsers/andor.py +++ b/makeitwright/core/parsers/andor.py @@ -26,7 +26,6 @@ def fromAndorNeo(fpath, name=None, px_per_um=None): data New data object. """ - # parse filepath data:wt.Data = wt.data.from_Solis(fpath, name=name, verbose=True) data.rename_variables(xindex="x", yindex="y", wm="wl") data.rename_channels(signal="sig") @@ -47,5 +46,4 @@ def fromAndorNeo(fpath, name=None, px_per_um=None): else: data.sig.label = "counts" - return data diff --git a/tests/test_PL.py b/tests/test_PL.py new file mode 100644 index 0000000..2b1002b --- /dev/null +++ b/tests/test_PL.py @@ -0,0 +1,16 @@ +import makeitwright as mw +from makeitwright import datasets + +andor = mw.andor +roi = mw.helpers.roi +parse = mw.parsers.parse +plot = mw.spectra.plot_spectra + + +def test_import_andor(): + p = datasets.PL + filepath = p.parent + filename = p.stem + + data1 = parse(filepath, objective="10", keywords=filename + ".asc") + data2 = mw.parsers.fromAndorNeo(p) From 454e26fbe983f16d92b5614e6f519e2ed52c8b39 Mon Sep 17 00:00:00 2001 From: Daniel Kohler <11864045+ddkohler@users.noreply.github.com> Date: Sat, 13 Sep 2025 01:06:30 -0500 Subject: [PATCH 3/3] Update test_PL.py --- tests/test_PL.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/test_PL.py b/tests/test_PL.py index 2b1002b..67d9670 100644 --- a/tests/test_PL.py +++ b/tests/test_PL.py @@ -2,15 +2,19 @@ from makeitwright import datasets andor = mw.andor -roi = mw.helpers.roi parse = mw.parsers.parse -plot = mw.spectra.plot_spectra def test_import_andor(): + """smokescreen to see if importing fails""" p = datasets.PL filepath = p.parent filename = p.stem data1 = parse(filepath, objective="10", keywords=filename + ".asc") data2 = mw.parsers.fromAndorNeo(p) + assert data1.variable_names == data2.variable_names == ("wl", "y") + + +if __name__ == "__main__": + test_import_andor()