11import os
22import numpy as np
33import time
4-
4+ from pathlib import Path
55import larch
66from pyshortcuts import fix_varname
77
@@ -18,12 +18,12 @@ def fix_xrd1d_filename(xrd_file):
1818 """
1919 # first append '.npy'
2020 xrd1d_file = xrd_file + '.npy'
21- if os . path . exists (xrd1d_file ):
21+ if Path ( xrd1d_file ). exists ():
2222 return xrd1d_file
2323
2424 # second, eiger .h5 -> .npy
2525 xrd1d_file = xrd_file .replace ('.h5' , '.npy' ).replace ('_master' , '' )
26- if os . path . exists (xrd1d_file ):
26+ if Path ( xrd1d_file ). exists ():
2727 return xrd1d_file
2828
2929 return None
@@ -154,7 +154,6 @@ def roicounts(self, roiname):
154154 elo , ehi = self .det .rois [iroi ].left , self .det .rois [iroi ].right
155155 counts = self .det .counts [self .yslice , self .xslice , elo :ehi ]
156156
157-
158157class GSEXRM_MapRow :
159158 '''
160159 read one row worth of data:
@@ -218,29 +217,47 @@ def __init__(self, yvalue, xrffile, xrdfile, xpsfile, sisfile, folder,
218217 else :
219218 xrd_reader = read_xrd_netcdf
220219
221- # print( "xrd_reader ", xrd_reader, xrdtype, xrdfile, ' cal :%s: ' % xrdcal)
220+ # print( "xrd_reader ", xrd_reader, xrdtype, xrdfile, ' cal :%s: ' % xrdcal)
221+
222222 # reading can fail with IOError, generally meaning the file isn't
223223 # ready for read. Try again for up to 5 seconds
224- t0 = time .time ()
225- sis_ok , xps_ok = False , False
226224
225+ # and...
226+ # from windows, missing files may mean that the networked filesystem has
227+ # not synced with the files written to the mount by the collection procees.
228+ # toggling a small file in this folder will force a refresh of the
229+ # directory listing, which may help
230+ if os .name == 'nt' :
231+ tmpfile = Path (folder , '_wintmp_.txt' )
232+ if tmpfile .exists ():
233+ tmpfile .unlink ()
234+ else :
235+ with open (tmpfile , 'w' ) as fh :
236+ fh .write ('_tmp\n ' )
237+ time .sleep (0.1 )
238+
239+ sis_ok , xps_ok = False , False
227240 gdata , sdata = [], []
241+ t0 = time .time ()
228242 while not (sis_ok and xps_ok ):
229- try :
230- ghead , gdata = readASCII (os .path .join (folder , xpsfile ))
231- xps_ok = len (gdata ) > 1
232- except IOError :
233- if (time .time () - t0 ) > 5.0 :
234- break
235- time .sleep (0.25 )
236- try :
237- shead , sdata = readASCII (os .path .join (folder , sisfile ))
238- sdata = sdata [offslice ]
239- sis_ok = len (sdata ) > 1
240- except IOError :
241- if (time .time () - t0 ) > 5.0 :
242- break
243- time .sleep (0.25 )
243+ folder_filelist = os .listdir (folder )
244+ if xpsfile in folder_filelist and (not xps_ok ):
245+ try :
246+ ghead , gdata = readASCII (Path (folder , xpsfile ).as_posix ())
247+ xps_ok = len (gdata ) > 1
248+ except IOError :
249+ pass
250+
251+ if sisfile in folder_filelist and (not sis_ok ):
252+ try :
253+ shead , sdata = readASCII (Path (folder , sisfile ).as_posix ())
254+ sdata = sdata [offslice ]
255+ sis_ok = len (sdata ) > 1
256+ except IOError :
257+ pass
258+ if (sis_ok and xps_ok ) or (time .time () > t0 + 5.0 ):
259+ break
260+ time .sleep (1.0 )
244261
245262 if not (sis_ok and xps_ok ):
246263 print ('Failed to read ASCII data for SIS: %s (%i), XPS: %s (%i)' %
@@ -285,7 +302,7 @@ def __init__(self, yvalue, xrffile, xrdfile, xpsfile, sisfile, folder,
285302
286303 except (IOError , IndexError ):
287304 time .sleep (0.025 )
288-
305+
289306 if atime < 0 or xrf_dat is None :
290307 print ( 'Failed to read data.' )
291308 return
0 commit comments