neutrons / PyRS

Reduction and visualization software for Stress Residual (HB2B)
https://neutrons-pyrs.readthedocs.io/en/latest/index.html
GNU General Public License v3.0
6 stars 7 forks source link

SummaryGeneratorStress ValueError: substring not found #700

Closed rosswhitfield closed 4 years ago

rosswhitfield commented 4 years ago

There is an assumed input filename format when writing the summary csv but in at at least one case #698 this is not what the user has done.

As a simple way to reproduce the error, first do

cp tests/data/HB2B_1331.h5 tests/data/AxialDirection_1.h5
cp tests/data/HB2B_1332.h5 tests/data/TransverseDirection.h5

Then run

from pyrs.dataobjects.fields import StrainField, StressField
from pyrs.core.summary_generator_stress import SummaryGeneratorStress

sample11 = StrainField('tests/data/AxialDirection_1.h5', peak_tag='peak0')
sample22 = StrainField('tests/data/TransverseDirection.h5', peak_tag='peak0')

stress = StressField(sample11, sample22, None, 200, 0.3, stress_type='in-plane-strain')

stress_csv = SummaryGeneratorStress('file.csv', stress)
stress_csv.write_summary_csv()

and it will fail with

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-4-b58678ce1e54> in <module>
----> 1 stress_csv.write_summary_csv()

~/src/PyRS/pyrs/core/summary_generator_stress.py in write_summary_csv(self)
    221         # function starts here
    222         with open(self._filename, 'w') as handle:
--> 223             self._write_csv_header(handle)
    224             _write_summary_csv_column_names(handle)
    225             _write_summary_csv_body(handle)

~/src/PyRS/pyrs/core/summary_generator_stress.py in _write_csv_header(self, handle)
     96                 line = '# Direction ' + str(direction) + ': '
     97                 for filename in strain.filenames:
---> 98                     run_number = filename[filename.index('HB2B_') + 5: filename.index('.h5')]
     99                     line += str(run_number) + ', '
    100 

ValueError: substring not found
williamfgc commented 4 years ago

Addressed by #710