Changeset 1297


Ignore:
Timestamp:
Apr 23, 2014 4:32:15 PM (8 years ago)
Author:
vondreele
Message:

setup sequential small angle refinements & display
includes copy & copy flags over Models
stop pattern plots in multiple integrations; now only when done

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASII.py

    r1296 r1297  
    31933193        finally:
    31943194            dlg.Destroy()
    3195         oldId =  self.PatternTree.GetSelection()
     3195        oldId =  self.PatternTree.GetSelection()        #retain current selection
    31963196        oldName = self.PatternTree.GetItemText(oldId)
    31973197        parentId = self.PatternTree.GetItemParent(oldId)
    31983198        parentName = ''
    31993199        if parentId:
    3200             parentName = self.PatternTree.GetItemText(parentId)
     3200            parentName = self.PatternTree.GetItemText(parentId)     #find the current data tree name
    32013201        dlg = wx.MessageDialog(self,'Load new result?','Refinement results, Rw =%.3f'%(Rw),wx.OK|wx.CANCEL)
    32023202        try:
     
    32713271                    self.G2plotNB.clear()
    32723272                G2IO.ProjFileOpen(self)
    3273                 # (BHT) what does this next section of code do?
    3274                 #item, cookie = self.PatternTree.GetFirstChild(self.root)
    3275                 #while item and not Id:
    3276                 #    name = self.PatternTree.GetItemText(item)
    3277                 #    if name[:4] in ['PWDR','HKLF']:
    3278                 #        Id = item
    3279                 #    item, cookie = self.PatternTree.GetNextChild(self.root, cookie)
    3280                 #if Id:
    3281                 #    self.PatternTree.SelectItem(Id)
    3282 
    3283                 # Open the sequential results tree entry
    32843273                Id = G2gd.GetPatternTreeItemId(self,self.root,'Sequential results')
    32853274                self.PatternTree.SelectItem(Id)
    3286                 G2gd.MovePatternTreeToGrid(self,Id)
    32873275
    32883276        finally:
  • trunk/GSASIIIO.py

    r1285 r1297  
    10151015            Id,[valuesdict,
    10161016                [np.array(X),np.array(Y),np.array(W),np.zeros(N),np.zeros(N),np.zeros(N)]])
    1017     G2frame.PatternTree.SelectItem(Id)
    1018     G2frame.PatternTree.Expand(Id)
    1019     G2frame.PatternId = Id
     1017        return Id
    10201018           
    10211019# def powderFxyeSave(G2frame,exports,powderfile):
  • trunk/GSASIIgrid.py

    r1295 r1297  
    135135
    136136[ wxID_SAVESEQSEL,wxID_SAVESEQSELCSV,wxID_PLOTSEQSEL,
    137   wxADDSEQVAR,wxDELSEQVAR,wxEDITSEQVAR,
    138 ] = [wx.NewId() for item in range(6)]
     137    wxID_SAVESASDSEQSEL,wxID_SAVESASDSEQSELCSV,wxID_PLOTSASDSEQSEL,
     138    wxADDSEQVAR,wxDELSEQVAR,wxEDITSEQVAR,
     139    wxADDSASDSEQVAR,wxDELSASDSEQVAR,wxEDITSASDSEQVAR,
     140] = [wx.NewId() for item in range(12)]
    139141
    140142[ wxID_MODELCOPY,wxID_MODELFIT,wxID_MODELADD,wxID_ELEMENTADD,wxID_ELEMENTDELETE,
    141143    wxID_ADDSUBSTANCE,wxID_LOADSUBSTANCE,wxID_DELETESUBSTANCE,wxID_COPYSUBSTANCE,
    142     wxID_MODELUNDO,wxID_MODELFITALL,
    143 ] = [wx.NewId() for item in range(11)]
     144    wxID_MODELUNDO,wxID_MODELFITALL,wxID_MODELCOPYFLAGS,
     145] = [wx.NewId() for item in range(12)]
    144146
    145147[ wxID_SELECTPHASE,wxID_PWDHKLPLOT,
     
    24762478        self.PostfillDataMenu()
    24772479           
     2480        # Sequential SASD results
     2481        self.SequentialSASDMenu = wx.MenuBar()
     2482        self.PrefillDataMenu(self.SequentialSASDMenu,helpType='Sequential',helpLbl='Sequential SASD Refinement')
     2483        self.SequentialSASDFile = wx.Menu(title='')
     2484        self.SequentialSASDMenu.Append(menu=self.SequentialSASDFile, title='Selected Cols')
     2485        self.SequentialSASDFile.Append(id=wxID_SAVESASDSEQSEL, kind=wx.ITEM_NORMAL,text='Save as text',
     2486            help='Save selected sequential SASD refinement results as a text file')
     2487        self.SequentialSASDFile.Append(id=wxID_SAVESASDSEQSELCSV, kind=wx.ITEM_NORMAL,text='Save as CSV',
     2488            help='Save selected sequential SASD refinement results as a CSV spreadsheet file')
     2489        self.SequentialSASDFile.Append(id=wxID_PLOTSASDSEQSEL, kind=wx.ITEM_NORMAL,text='Plot selected',
     2490            help='Plot selected sequential SASD refinement results')
     2491#        self.SequentialPvars = wx.Menu(title='')
     2492#        self.SequentialMenu.Append(menu=self.SequentialPvars, title='Pseudo Vars')
     2493#        self.SequentialPvars.Append(
     2494#            id=wxADDSEQVAR, kind=wx.ITEM_NORMAL,text='Add',
     2495#            help='Add a new pseudo-variable')
     2496#        self.SequentialPvars.Append(
     2497#            id=wxDELSEQVAR, kind=wx.ITEM_NORMAL,text='Delete',
     2498#            help='Delete an existing pseudo-variable')
     2499#        self.SequentialPvars.Append(
     2500#            id=wxEDITSEQVAR, kind=wx.ITEM_NORMAL,text='Edit',
     2501#            help='Edit an existing pseudo-variable')
     2502        self.PostfillDataMenu()
     2503           
    24782504        # Powder
    24792505        self.HistMenu = wx.MenuBar()
     
    26442670        self.ModelEdit.Append(id=wxID_MODELCOPY, kind=wx.ITEM_NORMAL,text='Copy',
    26452671            help='Copy model parameters to other histograms')
     2672        self.ModelEdit.Append(id=wxID_MODELCOPYFLAGS, kind=wx.ITEM_NORMAL,text='Copy flags',
     2673            help='Copy model refinement flags to other histograms')
    26462674        self.PostfillDataMenu()
    26472675       
     
    36703698        finally:
    36713699            dlg.Destroy()
     3700           
    36723701    # lookup table for unique cell parameters by symmetry
    36733702    cellGUIlist = [
     
    36833712    # cell labels
    36843713    cellUlbl = ('a','b','c',u'\u03B1',u'\u03B2',u'\u03B3') # unicode a,b,c,alpha,beta,gamma
     3714   
    36853715    def striphist(var,insChar=''):
    36863716        'strip a histogram number from a var name'
     
    36883718        sv[1] = insChar
    36893719        return ':'.join(sv)
     3720       
    36903721    def plotSpCharFix(lbl):
    36913722        'Change selected unicode characters to their matplotlib equivalent'
     
    38473878    colSigs += [None]
    38483879    colLabels += ['Rwp']
    3849     Types += [wg.GRID_VALUE_FLOAT,]
     3880    Types += [wg.GRID_VALUE_FLOAT+':10,3',]
    38503881    # add % change in Chi^2 in last cycle
    38513882    colList += [[100.*data[name]['Rvals'].get('DelChi2',-1) for name in histNames]]
     
    39854016            G2frame.dataDisplay.SetCellStyle(row,deltaChiCol,color=wx.Color(255,255,0))
    39864017        # colList += [[data[name]['Rvals']['converged'] for name in histNames]]
     4018       
     4019def UpdateSASDSeqResults(G2frame,data,prevSize=None):
     4020   
     4021    def GetColumnInfo(col):
     4022        '''returns column label, lists of values and errors (or None) for each column in the table.
     4023        label is reformatted from Unicode to MatPlotLib
     4024        '''
     4025        plotName = plotSpCharFix(G2frame.SeqTable.GetColLabelValue(col))
     4026        collist = [float(i) for i in colList[col]]
     4027        return plotName,collist,colSigs[col]
     4028           
     4029    def GetSampleParms():
     4030        '''Make a dictionary of the sample parameters are not the same over the
     4031        refinement series.
     4032        '''
     4033        sampleParmDict = {'Temperature':[],'Pressure':[],
     4034                          'FreePrm1':[],'FreePrm2':[],'FreePrm3':[],}
     4035        sampleParm = {}
     4036        for name in histNames:
     4037            Id = GetPatternTreeItemId(G2frame,G2frame.root,name)
     4038            sampleData = G2frame.PatternTree.GetItemPyData(GetPatternTreeItemId(G2frame,Id,'Sample Parameters'))
     4039            for item in sampleParmDict:
     4040                sampleParmDict[item].append(sampleData[item])
     4041        for item in sampleParmDict:
     4042            frstValue = sampleParmDict[item][0]
     4043            if np.any(np.array(sampleParmDict[item])-frstValue):
     4044                sampleParm[item] = sampleParmDict[item]           
     4045        return sampleParm
     4046
     4047    def PlotSelect(event):
     4048        'Plots a row (covariance) or column on double-click'
     4049        cols = G2frame.dataDisplay.GetSelectedCols()
     4050        rows = G2frame.dataDisplay.GetSelectedRows()
     4051        if cols:
     4052            G2plt.PlotSelectedSequence(G2frame,cols,GetColumnInfo,SelectXaxis)
     4053        elif rows:
     4054            name = histNames[rows[0]]       #only does 1st one selected
     4055            G2plt.PlotCovariance(G2frame,data[name])
     4056        else:
     4057            G2frame.ErrorDialog(
     4058                'Select row or columns',
     4059                'Nothing selected in table. Click on column or row label(s) to plot. N.B. Grid selection can be a bit funky.'
     4060                )
     4061
     4062    def SelectXaxis():
     4063        'returns a selected column number (or None) as the X-axis selection'
     4064        ncols = G2frame.SeqTable.GetNumberCols()
     4065        colNames = [G2frame.SeqTable.GetColLabelValue(r) for r in range(ncols)]
     4066        dlg = G2SingleChoiceDialog(
     4067            G2frame.dataDisplay,
     4068            'Select x-axis parameter for plot or Cancel for sequence number',
     4069            'Select X-axis',
     4070            colNames)
     4071        try:
     4072            if dlg.ShowModal() == wx.ID_OK:
     4073                col = dlg.GetSelection()
     4074            else:
     4075                col = None
     4076        finally:
     4077            dlg.Destroy()
     4078        return col
     4079   
     4080    def plotSpCharFix(lbl):
     4081        'Change selected unicode characters to their matplotlib equivalent'
     4082        for u,p in [
     4083            (u'\u03B1',r'$\alpha$'),
     4084            (u'\u03B2',r'$\beta$'),
     4085            (u'\u03B3',r'$\gamma$'),
     4086            (u'\u0394\u03C7',r'$\Delta\chi$'),
     4087            ]:
     4088            lbl = lbl.replace(u,p)
     4089        return lbl
     4090   
     4091    def OnPlotSelSeq(event):
     4092        'plot the selected columns or row from menu command'
     4093        cols = sorted(G2frame.dataDisplay.GetSelectedCols()) # ignore selection order
     4094        rows = G2frame.dataDisplay.GetSelectedRows()
     4095        if cols:
     4096            G2plt.PlotSelectedSequence(G2frame,cols,GetColumnInfo,SelectXaxis)
     4097        elif rows:
     4098            name = histNames[rows[0]]       #only does 1st one selected
     4099            G2plt.PlotCovariance(G2frame,data[name])
     4100        else:
     4101            G2frame.ErrorDialog(
     4102                'Select columns',
     4103                'No columns or rows selected in table. Click on row or column labels to select fields for plotting.'
     4104                )
     4105           
     4106    histNames = data['histNames']
     4107    if G2frame.dataDisplay:
     4108        G2frame.dataDisplay.Destroy()
     4109    if not G2frame.dataFrame.GetStatusBar():
     4110        Status = G2frame.dataFrame.CreateStatusBar()
     4111        Status.SetStatusText("Select column to export; Double click on column to plot data; on row for Covariance")
     4112
     4113    G2frame.dataFrame.SetLabel('Sequential SASD refinement results')
     4114    if not G2frame.dataFrame.GetStatusBar():
     4115        Status = G2frame.dataFrame.CreateStatusBar()
     4116        Status.SetStatusText('')
     4117#    G2frame.dataFrame.Bind(wx.EVT_MENU, OnSaveSelSeq, id=wxID_SAVESASDSEQSEL)
     4118#    G2frame.dataFrame.Bind(wx.EVT_MENU, OnSaveSelSeqCSV, id=wxID_SAVESASDSEQSELCSV)
     4119    G2frame.dataFrame.Bind(wx.EVT_MENU, OnPlotSelSeq, id=wxID_PLOTSASDSEQSEL)
     4120#    G2frame.dataFrame.Bind(wx.EVT_MENU, AddNewSeqExpression, id=wxADDSEQVAR)
     4121#    G2frame.dataFrame.Bind(wx.EVT_MENU, DelSeqExpression, id=wxDELSEQVAR)
     4122#    G2frame.dataFrame.Bind(wx.EVT_MENU, EditSeqExpression, id=wxEDITSEQVAR)
     4123#    EnableSeqExpressionMenus()
     4124    # build up the data table one column at a time
     4125    colList = []
     4126    colSigs = []
     4127    colLabels = []
     4128    Types = []
     4129    nRows = len(histNames)
     4130    # add Rwp values
     4131    colList += [[data[name]['Rvals']['Rwp'] for name in histNames]]
     4132    colSigs += [None]
     4133    colLabels += ['Rwp']
     4134    Types += [wg.GRID_VALUE_FLOAT+':10,3',]
     4135    # add sample parameters
     4136    sampleParms = GetSampleParms()
     4137    for key in sampleParms:
     4138        colList += [sampleParms[key]]
     4139        colSigs += [None]
     4140        colLabels += [key]
     4141        Types += [wg.GRID_VALUE_FLOAT+':10,3',]
     4142    # add the variables that were refined; change from rows to columns
     4143    collist = zip(*[data[name]['variables'] for name in histNames])
     4144    colText = [['%12.5g'%collist[j][i] for i in range(len(collist[0]))] for j in range(len(collist))]
     4145    colList += colText
     4146    colLabels += data[histNames[0]]['varyList']
     4147    Types += len(data[histNames[0]]['varyList'])*[wg.GRID_VALUE_STRING]
     4148    colSigs += zip(*[data[name]['sig'] for name in histNames])
     4149#    # add Pseudovars
     4150#    for exp in Controls['SeqPseudoVars']:
     4151#        obj = Controls['SeqPseudoVars'][exp]
     4152#        calcobj = G2obj.ExpressionCalcObj(obj)
     4153#        valList = []
     4154#        for row in zip(*colList):
     4155#            parmDict = dict(zip(colLabels,row))
     4156#            calcobj.SetupCalc(parmDict)
     4157#            valList.append(calcobj.EvalExpression())
     4158#        colList += [valList]
     4159#        colSigs += [None]
     4160#        colLabels += [exp]
     4161#        Types += [wg.GRID_VALUE_FLOAT,]
     4162
     4163    rowList = [c for c in zip(*colList)]     # convert from columns to rows
     4164    G2frame.SeqTable = Table(rowList,colLabels=colLabels,rowLabels=histNames,types=Types)
     4165    G2frame.dataDisplay = GSGrid(parent=G2frame.dataFrame)
     4166    G2frame.dataDisplay.SetTable(G2frame.SeqTable, True)
     4167    G2frame.dataDisplay.EnableEditing(False)
     4168    G2frame.dataDisplay.Bind(wg.EVT_GRID_LABEL_LEFT_DCLICK, PlotSelect)
     4169    G2frame.dataDisplay.SetRowLabelSize(8*len(histNames[0]))       #pretty arbitrary 8
     4170    G2frame.dataDisplay.SetMargins(0,0)
     4171    G2frame.dataDisplay.AutoSizeColumns(True)
     4172    if prevSize:
     4173        G2frame.dataDisplay.SetSize(prevSize)
     4174    else:
     4175        G2frame.dataFrame.setSizePosLeft([700,350])
    39874176   
    39884177################################################################################
     
    42164405        elif G2frame.PatternTree.GetItemText(item) == 'Sequential results':
    42174406            data = G2frame.PatternTree.GetItemPyData(item)
    4218             UpdateSeqResults(G2frame,data)           
     4407            UpdateSeqResults(G2frame,data)
     4408        elif G2frame.PatternTree.GetItemText(item) == 'Small Angle Sequential results':
     4409            data = G2frame.PatternTree.GetItemPyData(item)
     4410            UpdateSASDSeqResults(G2frame,data)
    42194411        elif G2frame.PatternTree.GetItemText(item) == 'Covariance':
    42204412            data = G2frame.PatternTree.GetItemPyData(item)
  • trunk/GSASIIimgGUI.py

    r1274 r1297  
    114114            G2frame.Integrate = G2img.ImageIntegrate(sumImg,data,masks,blkSize,dlg)
    115115    #        G2plt.PlotIntegration(G2frame,newPlot=True)
    116             G2IO.SaveIntegration(G2frame,G2frame.PickId,data)
     116            Id = G2IO.SaveIntegration(G2frame,G2frame.PickId,data)
     117            G2frame.PatternId = Id
     118            G2frame.PatternTree.SelectItem(Id)
     119            G2frame.PatternTree.Expand(Id)
    117120        finally:
    118121            dlg.Destroy()
     
    141144                        result = TextList[1:]
    142145                        for item in result: item[0] = True
     146                    G2frame.EnablePlot = False
    143147                    for item in result:
    144148                        ifintegrate,name,id = item
     
    177181                                    G2frame.Integrate = G2img.ImageIntegrate(image,Data,Masks,blkSize,dlgp)
    178182#                               G2plt.PlotIntegration(G2frame,newPlot=True,event=event)
    179                                 G2IO.SaveIntegration(G2frame,Id,Data)
     183                                pId = G2IO.SaveIntegration(G2frame,Id,Data)
    180184                            finally:
    181185                                dlgp.Destroy()
     186                    else:
     187                        G2frame.EnablePlot = True
     188                        G2frame.PatternTree.SelectItem(pId)
     189                        G2frame.PatternTree.Expand(pId)
     190                        G2frame.PatternId = pId
     191                       
    182192            finally:
    183193                dlg.Destroy()
  • trunk/GSASIIplot.py

    r1295 r1297  
    20442044    covArray = np.divide(np.divide(covMatrix,xvar),xvar.T)
    20452045    title = ' for\n'+Data['title']
    2046     newAtomDict = Data['newAtomDict']
     2046    newAtomDict = Data.get('newAtomDict',{})
    20472047   
    20482048
  • trunk/GSASIIpwdGUI.py

    r1295 r1297  
    27222722                copy.deepcopy(data))
    27232723               
     2724    def OnCopyFlags(event):
     2725        thisModel = copy.deepcopy(data)
     2726        hst = G2frame.PatternTree.GetItemText(G2frame.PatternId)
     2727        histList = GetHistsLikeSelected(G2frame)
     2728        if not histList:
     2729            G2frame.ErrorDialog('No match','No histograms match '+hst,G2frame.dataFrame)
     2730            return
     2731        dlg = G2gd.G2MultiChoiceDialog(
     2732            G2frame.dataFrame,
     2733            'Copy sample ref. flags from\n'+str(hst[5:])+' to...',
     2734            'Copy sample flags', histList)
     2735        distChoice = ['LogNormal','Gaussian','LSW','Schulz-Zimm','Bragg','Unified',
     2736            'Porod','Monodisperse',]
     2737        parmOrder = ['Volume','Radius','Mean','StdDev','G','Rg','B','P',
     2738            'Cutoff','PkInt','PkPos','PkSig','PkGam',]
     2739        try:
     2740            if dlg.ShowModal() == wx.ID_OK:
     2741                result = dlg.GetSelections()
     2742                for i in result:
     2743                    item = histList[i]
     2744                    Id = G2gd.GetPatternTreeItemId(G2frame,G2frame.root,item)
     2745                    newModel = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Id,'Models'))
     2746                    newModel['Back'][1] = copy.copy(thisModel['Back'][1])
     2747                    for ilev,level in enumerate(newModel['Particle']['Levels']):
     2748                        for form in level:
     2749                            if form in distChoice:
     2750                                thisForm = thisModel['Particle']['Levels'][ilev][form]                               
     2751                                for item in parmOrder:
     2752                                    if item in thisForm:
     2753                                       level[form][item][1] = copy.copy(thisForm[item][1])
     2754        finally:
     2755            dlg.Destroy()
     2756
     2757       
     2758               
    27242759    def OnFitModelAll(event):
    2725         choices = GetPatternTreeDataNames(G2frame,['SASD',])
     2760        choices = G2gd.GetPatternTreeDataNames(G2frame,['SASD',])
    27262761        sel = []
    2727         dlg = G2MultiChoiceDialog(G2frame.dataFrame, 'Sequential SASD refinement',
     2762        dlg = G2gd.G2MultiChoiceDialog(G2frame.dataFrame, 'Sequential SASD refinement',
    27282763             'Select dataset to include',choices)
    27292764        dlg.SetSelections(sel)
     
    27332768                names.append(choices[sel])
    27342769        dlg.Destroy()
    2735         for name in names: print name
     2770        SeqResult = {'histNames':names}
     2771        dlg = wx.ProgressDialog('SASD Sequential fit','Data set name = '+names[0],len(names),
     2772            style = wx.PD_ELAPSED_TIME|wx.PD_AUTO_HIDE|wx.PD_REMAINING_TIME|wx.PD_CAN_ABORT)
     2773        wx.BeginBusyCursor()
     2774        try:
     2775            for i,name in enumerate(names):
     2776                print ' Sequential fit for ',name
     2777                GoOn = dlg.Update(i,newmsg='Data set name = '+name)[0]
     2778                if not GoOn:
     2779                    break
     2780                Id =  G2gd.GetPatternTreeItemId(G2frame,G2frame.root,name)
     2781                IProfDict,IProfile = G2frame.PatternTree.GetItemPyData(Id)[:2]
     2782                IModel = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Id, 'Models'))
     2783                ISample = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Id, 'Sample Parameters'))
     2784                ILimits = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Id, 'Limits'))
     2785                IInst = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Id, 'Instrument Parameters'))
     2786                ISubstances = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Id, 'Substances'))
     2787                IfOK,result,varyList,sig,Rvals,covMatrix = G2sasd.ModelFit(IProfile,IProfDict,ILimits,ISubstances,ISample,IModel)
     2788                if not IfOK:
     2789                    G2frame.ErrorDialog('Failed sequential refinement for data '+name,
     2790                        'You need to rethink your selection of parameters\n'+    \
     2791                        ' Model restored to previous version for'+name)
     2792                    SeqResult['histNames'] = names[:i]
     2793                    dlg.Destroy()
     2794                    break
     2795               
     2796                G2sasd.ModelFxn(IProfile,IProfDict,ILimits,ISubstances,ISample,IModel)
     2797                SeqResult[name] = {'variables':result[0],'varyList':varyList,'sig':sig,'Rvals':Rvals,
     2798                    'covMatrix':covMatrix,'title':name}
     2799            else:
     2800                dlg.Destroy()
     2801                print ' ***** Small angle sequential refinement successful *****'
     2802        finally:
     2803            wx.EndBusyCursor()   
     2804        Id =  G2gd.GetPatternTreeItemId(G2frame,G2frame.root,'Small Angle Sequential results')
     2805        if Id:
     2806            G2frame.PatternTree.SetItemPyData(Id,SeqResult)
     2807        else:
     2808            Id = G2frame.PatternTree.AppendItem(parent=G2frame.root,text='Small Angle Sequential results')
     2809            G2frame.PatternTree.SetItemPyData(Id,SeqResult)
     2810        G2frame.PatternTree.SelectItem(Id)
    27362811       
    27372812    def OnFitModel(event):
     
    27472822        elif data['Current'] == 'Particle fit':
    27482823            SaveState()
    2749             if not G2sasd.ModelFit(Profile,ProfDict,Limits,Substances,Sample,data):
     2824            if not G2sasd.ModelFit(Profile,ProfDict,Limits,Substances,Sample,data)[0]:
    27502825                G2frame.ErrorDialog('Failed refinement',
    27512826                    'You need to rethink your selection of parameters\n'+    \
     
    31703245    G2frame.dataDisplay = wxscroll.ScrolledPanel(G2frame.dataFrame)
    31713246    G2frame.dataFrame.Bind(wx.EVT_MENU, OnCopyModel, id=G2gd.wxID_MODELCOPY)
     3247    G2frame.dataFrame.Bind(wx.EVT_MENU, OnCopyFlags, id=G2gd.wxID_MODELCOPYFLAGS)
    31723248    G2frame.dataFrame.Bind(wx.EVT_MENU, OnFitModel, id=G2gd.wxID_MODELFIT)
    31733249    G2frame.dataFrame.Bind(wx.EVT_MENU, OnFitModelAll, id=G2gd.wxID_MODELFITALL)
  • trunk/GSASIIsasd.py

    r1283 r1297  
    923923
    924924    def GetModelParms():
     925        parmOrder = ['Volume','Radius','Mean','StdDev','MinSize','G','Rg','B','P','Cutoff',
     926            'PkInt','PkPos','PkSig','PkGam',]
    925927        parmDict = {}
    926928        varyList = []
     
    953955                            values.append(controls['FFargs'][item][0])
    954956            distDict = controls['DistType']
    955             for item in level[distDict]:
    956                 parmDict[cid+item] = level[distDict][item][0]
    957                 if level[distDict][item][1]:
    958                     values.append(level[distDict][item][0])
    959                     varyList.append(cid+item)
     957            for item in parmOrder:
     958                if item in level[distDict]:
     959                    parmDict[cid+item] = level[distDict][item][0]
     960                    if level[distDict][item][1]:
     961                        values.append(level[distDict][item][0])
     962                        varyList.append(cid+item)
    960963        return levelTypes,parmDict,varyList,values
    961964       
     
    10511054    ncyc = int(result[2]['nfev']/2)
    10521055    chisq = np.sum(result[2]['fvec']**2)
    1053     Rwp = np.sqrt(chisq/np.sum(wt[Ibeg:Ifin]*Io[Ibeg:Ifin]**2))*100.      #to %
    1054     GOF = chisq/(Ifin-Ibeg-len(varyList))       #reduced chi^2
     1056    Rvals = {}
     1057    Rvals['Rwp'] = np.sqrt(chisq/np.sum(wt[Ibeg:Ifin]*Io[Ibeg:Ifin]**2))*100.      #to %
     1058    Rvals['GOF'] = chisq/(Ifin-Ibeg-len(varyList))       #reduced chi^2
    10551059    parmDict.update(zip(varyList,result[0]))
    10561060    Ic[Ibeg:Ifin] = getSASD(Q[Ibeg:Ifin],levelTypes,parmDict)
    10571061    try:
    1058         sigDict = dict(zip(varyList,np.sqrt(np.diag(result[1])*GOF)))
     1062        sig = np.sqrt(np.diag(result[1])*Rvals['GOF'])
     1063        sigDict = dict(zip(varyList,sig))
    10591064        print ' Results of small angle data modelling fit:'
    10601065        print 'Number of function calls:',result[2]['nfev'],' Number of observations: ',Ifin-Ibeg,' Number of parameters: ',len(varyList)
    1061         print 'Rwp = %7.2f%%, chi**2 = %12.6g, reduced chi**2 = %6.2f'%(Rwp,chisq,GOF)
     1066        print 'Rwp = %7.2f%%, chi**2 = %12.6g, reduced chi**2 = %6.2f'%(Rvals['Rwp'],chisq,Rvals['GOF'])
    10621067        SetModelParms()
    1063         return True
     1068        covMatrix = result[1]*Rvals['GOF']
     1069        return True,result,varyList,sig,Rvals,covMatrix
    10641070    except ValueError:
    1065         return False
    1066        
     1071        return False,0,0,0,0,0
    10671072   
    10681073def ModelFxn(Profile,ProfDict,Limits,Substances,Sample,sasdData):
  • trunk/GSASIIstrMain.py

    r1291 r1297  
    8585        print >>printFile,' Refinement time = %8.3fs, %8.3fs/cycle, for %d cycles'%(runtime,runtime/ncyc,ncyc)
    8686        print >>printFile,' wR = %7.2f%%, chi**2 = %12.6g, reduced chi**2 = %6.2f'%(Rvals['Rwp'],Rvals['chisq'],Rvals['GOF'])
     87        IfOK = True
    8788        try:
    8889            covMatrix = result[1]*Rvals['GOF']
     
    9495            break                   #refinement succeeded - finish up!
    9596        except TypeError,FloatingPointError:          #result[1] is None on singular matrix
     97            IfOK = False
    9698            print '**** Refinement failed - singular matrix ****'
    9799            if 'Hessian' in Controls['deriv type']:
     
    109111                        break
    110112    G2stMth.GetFobsSq(Histograms,Phases,parmDict,calcControls)
    111     return Rvals,result,covMatrix,sig
     113    return IfOK,Rvals,result,covMatrix,sig
    112114
    113115def Refine(GPXfile,dlg):
     
    170172    print >>printFile,'\n Refinement results:'
    171173    print >>printFile,135*'-'
    172     Rvals,result,covMatrix,sig = RefineCore(Controls,Histograms,Phases,restraintDict,
     174    IfOK,Rvals,result,covMatrix,sig = RefineCore(Controls,Histograms,Phases,restraintDict,
    173175        rigidbodyDict,parmDict,varyList,calcControls,pawleyLookup,ifPrint,printFile,dlg)
    174176    sigDict = dict(zip(varyList,sig))
     
    223225    Histograms,Phases = G2stIO.GetUsedHistogramsAndPhases(GPXfile)
    224226    if not Phases:
    225         print ' *** ERROR - you have no histograms to refine! ***'
     227        print ' *** ERROR - you have no phases to refine! ***'
    226228        print ' *** Refine aborted ***'
    227229        raise Exception
     
    349351        print >>printFile,'\n Refinement results for histogram: v'+histogram
    350352        print >>printFile,135*'-'
    351         Rvals,result,covMatrix,sig = RefineCore(Controls,Histo,Phases,restraintDict,
     353        IfOK,Rvals,result,covMatrix,sig = RefineCore(Controls,Histo,Phases,restraintDict,
    352354            rigidbodyDict,parmDict,varyList,calcControls,pawleyLookup,ifPrint,printFile,dlg)
    353355
Note: See TracChangeset for help on using the changeset viewer.