Changeset 4825


Ignore:
Timestamp:
Feb 23, 2021 1:57:49 PM (8 months ago)
Author:
toby
Message:

remove unused & deleted hists from seq ref; option to remove hists from all phases; bugs for seq ref with unused hists

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIdataGUI.py

    r4822 r4825  
    39853985            TextList.append(self.GPXtree.GetItemText(item))
    39863986            item, cookie = self.GPXtree.GetNextChild(sub, cookie)               
    3987         dlg = wx.MultiChoiceDialog(self, 'Which phase to delete?', 'Delete phase', TextList, wx.CHOICEDLG_STYLE)
     3987        dlg = wx.MultiChoiceDialog(self, 'Which phase(s) to delete?', 'Delete phase', TextList, wx.CHOICEDLG_STYLE)
    39883988        try:
    39893989            if dlg.ShowModal() == wx.ID_OK:
     
    48774877        return phaseData
    48784878
    4879     def GetPhaseInfofromTree(self):
     4879    def GetPhaseInfofromTree(self, Used=False):
    48804880        '''Get the phase names and their rId values,
    4881         also the histograms used in each phase.
    4882 
     4881        also the histograms referenced in each phase.
     4882
     4883        :param bool Used: if Used is True, only histograms that are
     4884            referenced in the histogram are returned
    48834885        :returns: (phaseRIdList, usedHistograms) where
    48844886
     
    48994901                data = self.GPXtree.GetItemPyData(item)
    49004902                UseList = data['Histograms']
    4901                 usedHistograms[phaseName] = list(UseList.keys())
     4903                if Used:
     4904                    usedHistograms[phaseName] = [h for h in UseList if UseList[h]['Use']]
     4905                else:
     4906                    usedHistograms[phaseName] = list(UseList.keys())
    49024907                item, cookie = self.GPXtree.GetNextChild(sub, cookie)
    49034908        return phaseRIdList,usedHistograms
     
    53275332        Controls = self.GPXtree.GetItemPyData(GetGPXtreeItemId(self,self.root, 'Controls'))
    53285333        Controls['ShowCell'] = True
     5334        for key in ('parmMinDict','parmMaxDict','parmFrozen'):
     5335            if key not in Controls: Controls[key] = {}
     5336        # check for deleted or unused histograms in refine list
     5337        phaseRIdList,histdict = self.GetPhaseInfofromTree(Used=True)
     5338        usedHistograms = []
     5339        for k in histdict:
     5340            usedHistograms += histdict[k]
     5341        usedHistograms = list(set(usedHistograms))
     5342        newseqList = [i for i in seqList if i in usedHistograms]
     5343        if len(newseqList) != len(seqList):
     5344            G2G.G2MessageBox(self,
     5345                str(len(seqList)-len(newseqList))+
     5346                ' histograms that are not used have been removed from the sequential list.',
     5347                'Histograms removed')
     5348            Controls['Seq Data'] = newseqList
     5349            seqList = newseqList
    53295350        self.OnFileSave(event)
    53305351        # check that constraints are OK here
     
    53595380        # select it
    53605381        self.PatternId = GetGPXtreeItemId(self,self.root,histNames[0])
    5361         if self.GPXtree.GetItemText(self.PatternId).startswith('PWDR '):
     5382        if self.PatternId and self.GPXtree.GetItemText(self.PatternId).startswith('PWDR '):
    53625383            refPlotUpdate = G2plt.PlotPatterns(self,refineMode=True) # prepare for plot updating
    53635384        else:
     
    65366557        def OnSelectData(event):
    65376558            choices = GetGPXtreeDataNames(G2frame,['PWDR','HKLF',])
     6559            phaseRIdList,histdict = G2frame.GetPhaseInfofromTree(Used=True)
     6560            usedHistograms = []
     6561            for k in histdict:
     6562                usedHistograms += histdict[k]
     6563            usedHistograms = list(set(usedHistograms))
     6564            choices = [i for i in choices if i in usedHistograms]
     6565            if len(choices) == 0:
     6566                G2G.G2MessageBox(self,
     6567                                'No histograms in use found for a sequential fit.',
     6568                                'No Histograms')
     6569                return
    65386570            sel = []
    65396571            try:
     
    65446576            except ValueError:  #data changed somehow - start fresh
    65456577                sel = []
    6546             dlg = G2G.G2MultiChoiceDialog(G2frame, 'Sequential refinement',
    6547                 'Select dataset to include',choices)
     6578            dlg = G2G.G2MultiChoiceDialog(G2frame, 'Select datasets to include',
     6579                        'Sequential refinement selection',choices)
    65486580            dlg.SetSelections(sel)
    65496581            names = []
     
    79928024            Albls = [pfx+'A'+str(i) for i in range(6)]
    79938025            for name in histNames:
     8026                if name not in Histograms: continue
    79948027                hId = Histograms[name]['hId']
    79958028                phfx = '%d:%d:'%(pId,hId)
     
    82828315        for row,name in enumerate(histNames):
    82838316            deltaChi = G2frame.SeqTable.GetValue(row,deltaChiCol)
    8284             if deltaChi > 10.:
    8285                 G2frame.dataDisplay.SetCellStyle(row,deltaChiCol,color=wx.Colour(255,0,0))
    8286             elif deltaChi > 1.0:
    8287                 G2frame.dataDisplay.SetCellStyle(row,deltaChiCol,color=wx.Colour(255,255,0))
     8317            try:
     8318                if deltaChi > 10.:
     8319                    G2frame.dataDisplay.SetCellStyle(row,deltaChiCol,color=wx.Colour(255,0,0))
     8320                elif deltaChi > 1.0:
     8321                    G2frame.dataDisplay.SetCellStyle(row,deltaChiCol,color=wx.Colour(255,255,0))
     8322            except:
     8323                pass
    82888324    G2frame.dataDisplay.InstallGridToolTip(GridSetToolTip,GridColLblToolTip)
    82898325    #G2frame.dataDisplay.SendSizeEvent() # resize needed on mac
  • trunk/GSASIIphsGUI.py

    r4824 r4825  
    97749774        if G2frame.dataWindow.HistsInPhase:
    97759775            DelList = []
    9776             dlg = G2G.G2MultiChoiceDialog(G2frame, 'Delete histogram',
    9777                 'Which histogram to delete from this phase?',G2frame.dataWindow.HistsInPhase)
     9776            extraOpts= {'label_0':'Remove from all phases','value_0':False}
     9777            h,pd = G2frame.GetUsedHistogramsAndPhasesfromTree()
     9778            if len(pd) > 1:
     9779                opts = extraOpts
     9780            else:
     9781                opts = {}
     9782            dlg = G2G.G2MultiChoiceDialog(G2frame,
     9783                'Select histogram(s) to remove   \nfrom this phase:',
     9784                'Remove histograms', G2frame.dataWindow.HistsInPhase,
     9785                extraOpts=opts)
    97789786            try:
    97799787                if dlg.ShowModal() == wx.ID_OK:
    97809788                    DelList = [G2frame.dataWindow.HistsInPhase[i] for i in dlg.GetSelections()]
    9781                     for i in DelList:
    9782                         del data['Histograms'][i]
    97839789            finally:
    97849790                dlg.Destroy()
    9785         wx.CallAfter(G2ddG.UpdateDData,G2frame,DData,data)
    9786        
     9791            if extraOpts['value_0']:
     9792                for p in pd:
     9793                    for i in DelList:
     9794                        if i in pd[p]['Histograms']: del pd[p]['Histograms'][i]
     9795            else:
     9796                for i in DelList:
     9797                    del data['Histograms'][i]
     9798            #wx.CallLater(100,G2ddG.UpdateDData,G2frame,DData,data) #  produces error
     9799            wx.CallAfter(UpdatePhaseData,G2frame,Item,data)
     9800           
    97879801    def OnDataApplyStrain(event):
    97889802        SGData = data['General']['SGData']       
  • trunk/GSASIIstrMain.py

    r4819 r4825  
    605605        if histogram not in Histograms:
    606606            G2fil.G2Print("Error: not found!")
    607             continue
     607            raise G2obj.G2Exception("refining with invalid histogram {}".
     608                                        format(histogram))
    608609        hId = Histograms[histogram]['hId']
    609610        redphaseVary = phaseCheck(phaseVary,Phases,histogram)
Note: See TracChangeset for help on using the changeset viewer.