Changeset 3462


Ignore:
Timestamp:
Jul 5, 2018 10:08:10 AM (3 years ago)
Author:
toby
Message:

move check of fractions/scale to OnRefine? and OnView?

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIconstrGUI.py

    r3456 r3462  
    11901190
    11911191################################################################################
     1192# check scale & phase fractions, create constraint if needed
     1193################################################################################
     1194def CheckAllScalePhaseFractions(G2frame):
     1195    '''Check if scale factor and all phase fractions are refined without a constraint
     1196    for all used histograms, if so, offer the user a chance to create a constraint
     1197    on the sum of phase fractions
     1198    '''
     1199    histograms, phases = G2frame.GetUsedHistogramsAndPhasesfromTree()
     1200    for i,hist in enumerate(histograms):
     1201        CheckScalePhaseFractions(G2frame,hist,histograms,phases)
     1202       
     1203def CheckScalePhaseFractions(G2frame,hist,histograms,phases):
     1204    '''Check if scale factor and all phase fractions are refined without a constraint
     1205    for histogram hist, if so, offer the user a chance to create a constraint
     1206    on the sum of phase fractions
     1207    '''
     1208    if G2frame.testSeqRefineMode():
     1209        histStr = '*'
     1210    else:
     1211        histStr = str(histograms[hist]['hId'])
     1212    # is scale factor varied
     1213    if not histograms[hist]['Sample Parameters']['Scale'][1]:
     1214        return
     1215    # are all phase fractions varied in all used histograms
     1216    phaseCount = 0
     1217    for p in phases:
     1218        if phases[p]['Histograms'][hist]['Use'] and not phases[p]['Histograms'][hist]['Scale'][1]:
     1219            return
     1220        else:
     1221            phaseCount += 1
     1222   
     1223    # all phase fractions and scale factor varied, now scan through constraints
     1224    sub = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,'Constraints')
     1225    Constraints = G2frame.GPXtree.GetItemPyData(sub)
     1226    fracConstr = False
     1227    for c in Constraints.get('HAP',[]):
     1228        if c[-1] != 'c': continue
     1229        if not c[-3]: continue
     1230        if len(c[:-3]) != phaseCount: continue
     1231        # got a constraint equation with right number of terms, is it on phase fractions for
     1232        # the correct histogram?
     1233        if all([(i[1].name == 'Scale' and i[1].varname().split(':')[1] == histStr) for i in c[:-3]]):
     1234            # got a constraint, this is OK
     1235            return
     1236    dlg = wx.MessageDialog(G2frame,
     1237                            'You are refining the scale factor and all phase fractions for histogram #'+
     1238                            histStr+'. This will produce an unstable refinement. '+
     1239                            'Do you want to constrain the sum of phase fractions?',
     1240                            'Create constraint?',
     1241                            wx.OK|wx.CANCEL)
     1242    if dlg.ShowModal() != wx.ID_OK:
     1243        dlg.Destroy()
     1244        return
     1245    dlg.Destroy()
     1246
     1247    constr = []
     1248    for p in phases:
     1249        if not phases[p]['Histograms'][hist]['Use']: continue
     1250        constr += [[1.0,G2obj.G2VarObj(':'.join((str(phases[p]['pId']),histStr,'Scale')))]]
     1251    constr += [1.0,None,'c']
     1252    Constraints['HAP'] += [constr]
     1253       
     1254################################################################################
    11921255#### Make nuclear/magnetic phase transition constraints - called by OnTransform in G2phsGUI
    11931256################################################################################       
  • trunk/GSASIIdataGUI.py

    r3459 r3462  
    42774277        for a sequential fit.
    42784278        '''
     4279        G2cnstG.CheckAllScalePhaseFractions(self)
    42794280        try:
    42804281            parmDict,varyList = self.MakeLSParmDict()
     
    43124313        Called from the Calculate/Refine menu.
    43134314        '''
     4315        G2cnstG.CheckAllScalePhaseFractions(self)
    43144316        if self.testSeqRefineMode():
    43154317            self.OnSeqRefine(event)
  • trunk/GSASIIphsGUI.py

    r3461 r3462  
    11031103                    atomData[i][-1] = Faces
    11041104                       
    1105 ################################################################################
    1106 ################################################################################
    1107 def CheckAllScalePhaseFractions(G2frame):
    1108     '''Check if scale factor and all phase fractions are refined without a constraint
    1109     for all used histograms, if so, offer the user a chance to create a constraint
    1110     on the sum of phase fractions
    1111     '''
    1112     histograms, phases = G2frame.GetUsedHistogramsAndPhasesfromTree()
    1113     for i,hist in enumerate(histograms):
    1114         CheckScalePhaseFractions(G2frame,hist,histograms,phases)
    1115        
    1116 def CheckScalePhaseFractions(G2frame,hist,histograms,phases):
    1117     '''Check if scale factor and all phase fractions are refined without a constraint
    1118     for histogram hist, if so, offer the user a chance to create a constraint
    1119     on the sum of phase fractions
    1120     '''
    1121     if G2frame.testSeqRefineMode():
    1122         histStr = '*'
    1123     else:
    1124         histStr = str(histograms[hist]['hId'])
    1125     # is scale factor varied
    1126     if not histograms[hist]['Sample Parameters']['Scale'][1]:
    1127         return
    1128     # are all phase fractions varied in all used histograms
    1129     phaseCount = 0
    1130     for p in phases:
    1131         if phases[p]['Histograms'][hist]['Use'] and not phases[p]['Histograms'][hist]['Scale'][1]:
    1132             return
    1133         else:
    1134             phaseCount += 1
    1135    
    1136     # all phase fractions and scale factor varied, now scan through constraints
    1137     sub = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,'Constraints')
    1138     Constraints = G2frame.GPXtree.GetItemPyData(sub)
    1139     fracConstr = False
    1140     for c in Constraints.get('HAP',[]):
    1141         if c[-1] != 'c': continue
    1142         if not c[-3]: continue
    1143         if len(c[:-3]) != phaseCount: continue
    1144         # got a constraint equation with right number of terms, is it on phase fractions for
    1145         # the correct histogram?
    1146         if all([(i[1].name == 'Scale' and i[1].varname().split(':')[1] == histStr) for i in c[:-3]]):
    1147             # got a constraint, this is OK
    1148             return
    1149     dlg = wx.MessageDialog(G2frame,
    1150                             'You are refining the scale factor and all phase fractions for histogram #'+
    1151                             histStr+'. This will produce an unstable refinement. '+
    1152                             'Do you want to constrain the sum of phase fractions?',
    1153                             'Create constraint?',
    1154                             wx.OK|wx.CANCEL)
    1155     if dlg.ShowModal() != wx.ID_OK:
    1156         dlg.Destroy()
    1157         return
    1158     dlg.Destroy()
    1159 
    1160     constr = []
    1161     for p in phases:
    1162         if not phases[p]['Histograms'][hist]['Use']: continue
    1163         constr += [[1.0,G2obj.G2VarObj(':'.join((str(phases[p]['pId']),histStr,'Scale')))]]
    1164     constr += [1.0,None,'c']
    1165     Constraints['HAP'] += [constr]
    11661105################################################################################
    11671106################################################################################
     
    92719210            return
    92729211    ChangePage(0)
    9273     CheckAllScalePhaseFractions(G2frame)
Note: See TracChangeset for help on using the changeset viewer.