Hi Chris, 


On Tue, Sep 10, 2019 at 6:52 AM Patridge, Christopher <patridgc@dyc.edu> wrote:
Good morning,

I have OSX Larch installed and attempting to open XAS data files.  It cannot read the file and Larch returns an error:

Error trying to read '/Users/DrPatridge/Desktop/2019-03-21/CaVO_50-40-10_vs_Zn.002':

    _tmp_file_ = read_xdi('/Users/DrPatridge/Desktop/2019-03-21/CaVO_50-40-10_vs_Zn.002')
             ^^^
   File /Users/DrPatridge/.larch/init.lar, line 1
  File "/xraylarch/share/larch/plugins/io/xdi.py", line 258, in read_xdi
    xdif = XDIFile(filename, labels=labels)
  File "/xraylarch/share/larch/plugins/io/xdi.py", line 124, in __init__
    self.read(self.filename)
  File "/xraylarch/share/larch/plugins/io/xdi.py", line 165, in read
    mvals = tostrlist(xdi.meta_values,   self.nmetadata)
  File "/xraylarch/share/larch/plugins/io/xdi.py", line 65, in Py3tostrlist
    return [str(i, 'ASCII') for i in (nitems*c_char_p).from_address(address)]
  File "/xraylarch/share/larch/plugins/io/xdi.py", line 65, in <listcomp>
    return [str(i, 'ASCII') for i in (nitems*c_char_p).from_address(address)]

UnicodeDecodeError: ('ascii', b'3.1356369 \xc3\x85', 10, 11, 'ordinal not in range(128)’)

Is this a plugin error or something else?  I attached one of the files if anyone could test?  I can open it in Athena.


Oh, yes I see that too.   Oddly enough this file (that contains UTF-8 text) can be read with `read_ascii()` but fails with `read_xdi()`.  

The XDI-reading failure there is basically because the Python wrapper (stupidly) expects ASCII code.  Even fixing that, `read_xdi()` would fail because it tries to set a numeric mono d_spacing, and we never tested against having units on the d-spacing.   That's not due to the text encoding, as even

   # Mono.d_spacing: 31.356369 Angstroms 

would currently fail with `read_xdi()`.  But It would be OK with `read_ascii()` (and I suspect that Athena isn't parsing that string for a numerical d_spacing either).  These are all easy to fix (and just now pushed to git master).
 
FWIW, we've battle-tested file-reading of many beamline data format variations in Larch and XAS_Viewer over the summer and the next release (should be soon, if building the Windows package goes smoothly) will read many more beamline data files, and support older athena files, and have this fix.
 
--Matt