@@ -40,9 +40,9 @@ def typeID(*fpaths):
4040 if "LabRAM HR" in txt :
4141 if (htype := horiba_typeID (fpath )) is not None :
4242 types [fpath ] = htype
43- if "Goniometer" in txt :
43+ elif "Goniometer" in txt :
4444 types [fpath ] = 'Bruker_XRD'
45- if "[m]" in txt :
45+ elif "[m]" in txt :
4646 types [fpath ] = 'Gwyddion_traces'
4747
4848 if fpath .suffix == '.asc' :
@@ -56,7 +56,7 @@ def typeID(*fpaths):
5656 if fpath .suffix == '.wt5' :
5757 types [fpath ] = 'wt5'
5858
59- print (f"{ len (types )} of { len (fpaths )} files identified as valid data types " )
59+ print (f"{ len (types )} of { len (fpaths )} files designated valid" )
6060 return types
6161
6262
@@ -78,30 +78,43 @@ def listfiles(fdir:str|pathlib.Path, pattern:str="*") -> list[pathlib.Path]:
7878 ]
7979
8080
81- def parse (fdir , objective , select_types = None , keywords :list | str = [], exclude = []):
81+ def parse (fdir , objective , select_types = None , keywords :list | str = [], exclude : list | str = []):
8282 """
83- DOCUMENTATION NEEDED
83+ import all files in a directory matching name rules.
84+ A file must match all provided keywords.
85+ Any file that matches any exclude word is ignored.
86+
87+ Parameters
88+ ----------
89+ fdir: path-like
90+ directory to search for files
91+ objective: identifier
92+ the objective used. for images, this is used to convert camera indices into spatial coordinates
93+ select_types: list of strings (optional)
94+ types of data to keep (e.g. "TRPL"). other data types are ignored.
95+ keywords: list of strings
96+ files are only parsed if their names contain all keywords
97+ exclude: string or list of strings
98+ files are only parsed if their names contain no exclude words
99+
100+ see also
101+ --------
102+
103+ WrightTools.collection.from_directory
84104 """
85- files = listfiles (fdir )
86-
87- include = [1 for i in range (len (files ))]
88- if keywords :
89- if type (keywords ) is not list :
90- keywords = [keywords ]
91- for kw in keywords :
92- for i , f in enumerate (files ):
93- if kw not in str (f ):
94- include [i ]= 0
95- if exclude :
96- if type (exclude ) is not list :
97- exclude = [exclude ]
98- for x in exclude :
99- for i , f in enumerate (files ):
100- if x in str (f ):
101- include [i ]= 0
102-
103- files = [file for i , file in zip (include , files ) if i ]
104- print (f'found { sum (include )} files matching keyword specifications' )
105+ if not isinstance (keywords , list ):
106+ keywords = [keywords ]
107+ if not isinstance (exclude , list ):
108+ exclude = [exclude ]
109+
110+ files = [
111+ file for file in filter (
112+ lambda f : all ([kw in str (f ) for kw in keywords ])
113+ and all (x not in str (f ) for x in exclude ),
114+ listfiles (fdir )
115+ )
116+ ]
117+ print (f'found { len (files )} files matching keyword specifications' )
105118
106119 ftypes = typeID (* files )
107120 if select_types :
0 commit comments