@@ -93,6 +93,9 @@ def _to_bool(txt):
9393 r"(?P<date>\S+)\s+(\(h:m:s\.ms\)|At Time:) (?P<time>\S+)" )
9494 closeDatetime2_pat = re .compile (r"-TimeClosed (?P<date>\S+) (?P<time>\S+)" )
9595
96+ # Precompiled filename pattern
97+ _filename_pat = re .compile (r"## File Name:* (?P<filename>.*)" )
98+
9699 # BML - example
97100 # ######## Neuralynx Data File Header
98101 # ## File Name: null
@@ -165,10 +168,6 @@ def _to_bool(txt):
165168 # -TimeCreated 2019/06/28 17:36:50
166169 # -TimeClosed 2019/06/28 17:45:48
167170
168- # regular expressions to match filename
169- filename_regex = [r"## File Name (?P<filename>\S+)" ,
170- r'-OriginalFileName "?(?P<filename>\S+)"?' ]
171-
172171 def __init__ (self , filename , props_only = False ):
173172 """
174173 Factory function to build NlxHeader for a given file.
@@ -186,11 +185,11 @@ def __init__(self, filename, props_only=False):
186185 ValueError ("Neuralynx files must start with 8 # characters." )
187186
188187 self .read_properties (filename , txt_header )
189- numChidEntries = self .convert_channel_ids_names (filename )
190188 self .setApplicationAndVersion ()
189+ numChidEntries = self .convert_channel_ids_names (filename )
191190 self .setBitToMicroVolt ()
192191 self .setInputRanges (numChidEntries )
193- # :TODO: needs to also handle filename property
192+ self . _setFilenameProp ( txt_header )
194193
195194 if not props_only :
196195 self .readTimeDate (txt_header )
@@ -215,26 +214,6 @@ def read_properties(self, filename, txt_header):
215214 value = type_ (value )
216215 self [name ] = value
217216
218- def setInputRanges (self , numChidEntries ):
219- if "InputRange" in self :
220- ir_entries = re .findall (r"\w+" , self ["InputRange" ])
221- if len (ir_entries ) == 1 :
222- self ["InputRange" ] = [int (ir_entries [0 ])] * numChidEntries
223- else :
224- self ["InputRange" ] = [int (e ) for e in ir_entries ]
225- assert len (self ["InputRange" ]) == numChidEntries , \
226- "Number of channel ids does not match input range values."
227-
228- def setBitToMicroVolt (self ):
229- # convert bit_to_microvolt
230- if "bit_to_microVolt" in self :
231- btm_entries = re .findall (r"\S+" , self ["bit_to_microVolt" ])
232- if len (btm_entries ) == 1 :
233- btm_entries = btm_entries * len (self ["channel_ids" ])
234- self ["bit_to_microVolt" ] = [float (e ) * 1e6 for e in btm_entries ]
235- assert len (self ["bit_to_microVolt" ]) == len ( self ["channel_ids" ]), \
236- "Number of channel ids does not match bit_to_microVolt conversion factors."
237-
238217 def setApplicationAndVersion (self ):
239218 """
240219 Set "ApplicationName" property and app_version attribute based on existing properties
@@ -294,6 +273,38 @@ def convert_channel_ids_names(self, filename):
294273
295274 return len (chid_entries )
296275
276+ def setBitToMicroVolt (self ):
277+ # convert bit_to_microvolt
278+ if "bit_to_microVolt" in self :
279+ btm_entries = re .findall (r"\S+" , self ["bit_to_microVolt" ])
280+ if len (btm_entries ) == 1 :
281+ btm_entries = btm_entries * len (self ["channel_ids" ])
282+ self ["bit_to_microVolt" ] = [float (e ) * 1e6 for e in btm_entries ]
283+ assert len (self ["bit_to_microVolt" ]) == len ( self ["channel_ids" ]), \
284+ "Number of channel ids does not match bit_to_microVolt conversion factors."
285+
286+ def setInputRanges (self , numChidEntries ):
287+ if "InputRange" in self :
288+ ir_entries = re .findall (r"\w+" , self ["InputRange" ])
289+ if len (ir_entries ) == 1 :
290+ self ["InputRange" ] = [int (ir_entries [0 ])] * numChidEntries
291+ else :
292+ self ["InputRange" ] = [int (e ) for e in ir_entries ]
293+ assert len (self ["InputRange" ]) == numChidEntries , \
294+ "Number of channel ids does not match input range values."
295+
296+ def _setFilenameProp (self , txt_header ):
297+ """
298+ Add an OriginalFileName property if in header.
299+ """
300+ if not 'OriginalFileName' in self .keys ():
301+ fnm = NlxHeader ._filename_pat .search (txt_header )
302+ if not fnm : return
303+ else : self ['OriginalFileName' ] = fnm .group (1 ).strip (' "\t \r \n ' )
304+ else :
305+ # some file types quote the property so strip that also
306+ self ['OriginalFileName' ] = self ['OriginalFileName' ].strip (' "\t \r \n ' )
307+
297308 def readTimeDate (self , txt_header ):
298309 """
299310 Read time and date from text of header
0 commit comments