Changeset 1745 in bayesapp


Ignore:
Timestamp:
Sep 4, 2021, 9:59:59 AM (6 weeks ago)
Author:
ehb
Message:

Updates for error checking
Andreas Larsen

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • bin/bayesapp.py

    r1741 r1745  
    1111from matplotlib import gridspec
    1212import subprocess
     13import time
    1314
    1415if __name__=='__main__':
     
    106107    d = genapp(json_variables)
    107108
     109    ## check q range
     110    try:
     111        qmax = float(q_max)
     112    except:
     113        qmax = 10.0
     114    try:
     115        qmin = float(q_min)
     116    except:
     117        qmin = 0.0
     118    q_diff = qmax - qmin
     119
     120    if q_diff < 0.0:
     121        out_line = '\n\n!!!ERROR!!!\nqmin should be smaller than qmax.\n\n'
     122        d.udpmessage({"_textarea": out_line})
     123        sys.exit()
    108124    ## run bayesfit
    109     d.udpmessage({"_textarea":"run bayesapp\n"})
     125    d.udpmessage({"_textarea":"running bayesapp...\n"})
    110126
    111127    def execute(command,f):
     128        start_time = time.time()
     129        maximum_output_size = 1000000 # maximum output size in number of characters
     130        maximum_time = 900
     131        total_output_size = 0
    112132        popen = subprocess.Popen(command, stdout=subprocess.PIPE,bufsize=1)
    113133        lines_iterator = iter(popen.stdout.readline, b"")
     
    116136                nline = line.rstrip()
    117137                nline_latin = nline.decode('latin')
    118                 out_line = '%s\n' % nline_latin
    119                 d.udpmessage({"_textarea": out_line})
     138                total_output_size += len(nline_latin)
     139                total_time = time.time() - start_time
     140                if total_output_size > maximum_output_size:
     141                    popen.terminate()
     142                    out_line = '\n\n!!!ERROR!!!\nProcess stopped - could not find solution. Is data input a SAXS/SANS dataset with format (q,I,dI)?\n\n'
     143                    d.udpmessage({"_textarea": out_line})
     144                    sys.exit()
     145                elif total_time > maximum_time:
     146                    popen.terminate()
     147                    out_line = '\n\n!!!ERROR!!!\nProcess stopped - reached max time of 15 min (900 sec). Is data input a SAXS/SANS dataset with format (q,I,dI)?. If data is large (several thousand data points), consider rebinning and input the rebinned data instead.\n\n'
     148                    d.udpmessage({"_textarea": out_line})
     149                    sys.exit()
     150                else:
     151                    out_line = '%s\n' % nline_latin
     152                    d.udpmessage({"_textarea": out_line})
     153                    #Debugging below:
     154                    #out_line_2 = 'output_size = %d, max_output_size = %d\n' % (total_output_size,maximum_output_size)
     155                    #d.udpmessage({"_textarea": out_line_2})
     156                    #out_line_3 = 'time = %1.1f, max_time = %1.1f\n' % (total_time,maximum_time)
     157                    #d.udpmessage({"_textarea": out_line_3})
    120158                f.write(out_line)
    121159   
    122160    f = open('stdout.d','w')
    123     execute(['/opt/genapp/bayesapp/bin/source/iftci','<','inputfile.d'],f)
     161    #execute(['/opt/genapp/bayesapp/bin/source/iftci','<','inputfile.d'],f)
     162    execute([os.path.dirname(os.path.realpath(__file__)) + '/source/iftci','<','inputfile.d'],f)
    124163    f.close()
    125164
  • bin/source/iftci_v10.f

    r1742 r1745  
    564564      endif
    565565      if(etaest.eq.0.and.answerm.eq.'M') then
    566       cpumax=999
     566      cpumax=900
    567567      answer='E'
    568568c ratio is fitted by evidence
     
    636636      write(6,*)'Number of data points after rebin  = ',mtot
    637637      write(6,*)'Number of points added (S(q)->1)   = ',nadd
     638
     639      if(ndata.lt.5) then
     640        write(6,*)''
     641        write(6,*)'!!Problem!'
     642        write(6,*)' Number of points less than 5'
     643        write(6,*)' - try extending the q range'
     644        write(6,*)' - check file format: (q,I,sigma)'
     645        write(6,*)' - check units: nm-1 or A-1'
     646        write(6,*)''
     647        STOP
     648      endif
    638649
    639650      mtot=mtot+nadd
     
    15771588      cpu=(clock-clockold)*0.001
    15781589      write(166,955)cpu,cpumax
    1579   955 format(1x,'Cpu time used: ',f4.1,
    1580      -' seconds of maximum ',f4.1,' seconds')
     1590  955 format(1x,'CPU time used: ',f6.1,
     1591     -' seconds of maximum ',f6.1,' seconds')
    15811592      else
    15821593      write(166,*)'This logfile is calculated when p(r) is estimated'
     
    16241635      write(6,*)
    16251636      write(6,947)cpu
    1626   947 format(1x,'Cpu time used         :  ',f4.1,
     1637  947 format(1x,'CPU time used         :  ',f6.1,
    16271638     -' seconds')
    16281639      CLOSE(14)
  • modules/bayesapp.json

    r1741 r1745  
    2626            "role"       : "input"
    2727            ,"id"         : "datafile"
    28             ,"label"      : "Data file"
     28            ,"label"      : "Data file (columns: q,I,sigma)"
    2929# need to force copy over
    3030#            ,"type"       : "lrfile"
Note: See TracChangeset for help on using the changeset viewer.