Changeset 1a5d5f2 in sasview for src/sas/sascalc/fit


Ignore:
Timestamp:
Dec 2, 2016 4:56:54 PM (8 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
b61bd57
Parents:
e42c8e9d
Message:

send errors back from fitting. Fixes #820

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/fit/BumpsFitting.py

    rb699768 r1a5d5f2  
    44import os 
    55from datetime import timedelta, datetime 
     6import traceback 
    67 
    78import numpy 
     
    293294            R.success = result['success'] 
    294295            if R.success: 
    295                 R.stderr = numpy.hstack((result['stderr'][fitted_index], 
    296                                          numpy.NaN*numpy.ones(len(fitness.computed_pars)))) 
     296                if result['stderr'] is None: 
     297                    R.stderr = numpy.NaN*numpy.ones(len(param_list)) 
     298                else: 
     299                    R.stderr = numpy.hstack((result['stderr'][fitted_index], 
     300                                             numpy.NaN*numpy.ones(len(fitness.computed_pars)))) 
    297301                R.pvec = numpy.hstack((result['value'][fitted_index], 
    298302                                      [p.value for p in fitness.computed_pars])) 
     
    306310                R.uncertainty_state = result['uncertainty'] 
    307311            all_results.append(R) 
     312        all_results[0].mesg = result['errors'] 
    308313 
    309314        if q is not None: 
     
    344349    try: 
    345350        best, fbest = fitdriver.fit() 
    346     except: 
    347         import traceback; traceback.print_exc() 
    348         raise 
     351        errors = [] 
     352    except Exception as exc: 
     353        best, fbest = None, numpy.NaN 
     354        errors = [str(exc), traceback.traceback.format_exc()] 
    349355    finally: 
    350356        mapper.stop_mapper(fitdriver.mapper) 
     
    356362 
    357363    success = best is not None 
     364    try: 
     365        stderr = fitdriver.stderr() if success else None 
     366    except Exception as exc: 
     367        errors.append(str(exc)) 
     368        errors.append(traceback.format_exc()) 
     369        stderr = None 
    358370    return { 
    359371        'value': best if success else None, 
    360         'stderr': fitdriver.stderr() if success else None, 
     372        'stderr': stderr, 
    361373        'success': success, 
    362374        'convergence': convergence, 
    363375        'uncertainty': getattr(fitdriver.fitter, 'state', None), 
     376        'errors': '\n'.join(errors), 
    364377        } 
    365378 
Note: See TracChangeset for help on using the changeset viewer.