silx
silx copied to clipboard
issues with silx.io.specfile.SpecFile
Hello,
With a few simple spec files in hand, I discover that the behavior of silx.io.specfile.SpecFile() unpredictably depends on the file content.
-
Should the file begin with a leading empty line? Experimenting with 'spec_test.dat' says yes, otherwise header lines of the last entry merge with those of the 1st entry. Experimenting with 'vasole_test0.dat' says no, because with an empty line SfErrFileRead is thrown.
-
The presence of a file header leads to a crash, with or without a leading empty line.
Please look at the files in the zip and possibly tell what could be wrong with them. Those with the trailing underline are with a leading empty line. spec_files.zip
I am interested in extracting the last entry from a large spec file. As of now, its header lines are either mixed with those of the first entry or I get a crash.
Here is my test script
from silx.io.specfile import SpecFile
def read_entry(fname, entry):
sf = SpecFile(fname)
entry = sf[entry]
print(entry.header)
return entry
if __name__ == "__main__":
# data = read_entry('spec_test.dat', 0) # ok
# data = read_entry('spec_test.dat', -1) # not ok, merges headers
# data = read_entry('spec_test_.dat', 0) # ok
# data = read_entry('spec_test_.dat', -1) # ok
# without file header, without leading empty line
# data = read_entry('vasole_test0.dat', 0) # ok
# data = read_entry('vasole_test0.dat', -1) # ok
# without file header, with leading empty line
# data = read_entry('vasole_test0_.dat', 0) # error
# with file header
# data = read_entry('vasole_test1.dat', 0) # error
# data = read_entry('vasole_test1_.dat', 0) # error
print('Done')
Thank you in advance!