Changeset 2147


Ignore:
Timestamp:
Feb 13, 2016 9:12:07 AM (8 years ago)
Author:
vondreele
Message:

handle TOF profile type=2 iparm files (e.g. for GEM)
implement multibank instprm files - add Save all profiles to Instrument parameters MenuBinding?
Do the Load profile to handle these - modifications to OnLoad?
add common transformation matrices to MergeDialog?
add bank no. to ReadPowderInstprm? call for matching it - in progress

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASII.py

    r2141 r2147  
    952952        return lines       
    953953           
    954     def ReadPowderInstprm(self,instLines):
     954    def ReadPowderInstprm(self,instLines,bank):
    955955        '''Read lines from a GSAS-II (new) instrument parameter file
     956        similar to G2pwdGUI.OnLoad
     957        If instprm file has multiple banks each with header #Bank n: ..., this
     958        finds matching bank no. to load - rejects nonmatches.
    956959
    957960        :param list instLines: strings from GSAS-II parameter file; can be concatenated with ';'
     961        :param int  bank: bank number to check when instprm file has '#BANK n:...' strings
     962            when bank = n then use parameters; otherwise skip that set. Ignored if BANK n:
     963            not present. NB: this kind of instprm file made by a Save all profile command in Instrument Parameters
    958964
    959965        '''
     
    962968        newItems = []
    963969        newVals = []
     970        Found = False
    964971        for S in instLines:
    965972            if S[0] == '#':
     
    11481155                            s = Iparm['INS  1PRCF 2'].split()
    11491156                            data.extend([0.0,0.0,G2IO.sfloat(s[0]),G2IO.sfloat(s[1]),0.0,0.0,0.0,azm])    #beta-q, sig-0, sig-1, sig-2, sig-q, X, Y                       
     1157                    elif abs(pfType) == 2:
     1158                        data.extend([G2IO.sfloat(s[1]),0.0,1./G2IO.sfloat(s[3])]) #alpha, beta-0, beta-1
     1159                        data.extend([0.0,0.0,G2IO.sfloat(s[1]),0.0,0.0,0.0,0.0,azm])    #beta-q, sig-0, sig-1, sig-2, sig-q, X, Y                           
    11501160                else:
    11511161                    s = Iparm['INS  1PRCF1 '].split()
     
    12221232                instParmList = None
    12231233                if Lines is not None:
    1224                     instParmList = self.ReadPowderInstprm(Lines)
     1234                    instParmList = self.ReadPowderInstprm(Lines,bank)    #know Bank - see above
    12251235                if instParmList is not None:
    12261236                    rd.instfile = instfile
     
    12441254            instParmList = None
    12451255            if Lines is not None:
    1246                 instParmList = self.ReadPowderInstprm(Lines)
     1256                instParmList = self.ReadPowderInstprm(Lines,bank)    #know Bank - see above
    12471257            if instParmList is not None:
    12481258                rd.instfile = instfile
     
    12721282                    instParmList = None
    12731283                    if Lines is not None:
    1274                         instParmList = self.ReadPowderInstprm(Lines)
     1284                        instParmList = self.ReadPowderInstprm(Lines,bank)    #know Bank - see above
    12751285                    if instParmList is not None:
    12761286                        rd.instfile = instfile
     
    13061316            instParmList = None
    13071317            if Lines is not None:
    1308                 instParmList = self.ReadPowderInstprm(Lines)
     1318                instParmList = self.ReadPowderInstprm(Lines,bank)    #know Bank - see above
    13091319            if instParmList is not None:
    13101320                rd.instfile = instfile
     
    13381348            rd.instfile = ''
    13391349            rd.instmsg = 'default: '+dI.defaultIparm_lbl[res]
    1340             return self.ReadPowderInstprm(dI.defaultIparms[res])
     1350            return self.ReadPowderInstprm(dI.defaultIparms[res],bank)    #know Bank - see above
    13411351
    13421352    def OnImportPowder(self,event):
  • trunk/GSASIIgrid.py

    r2146 r2147  
    107107
    108108[ wxID_INSTPRMRESET,wxID_CHANGEWAVETYPE,wxID_INSTCOPY, wxID_INSTFLAGCOPY, wxID_INSTLOAD,
    109     wxID_INSTSAVE, wxID_INST1VAL, wxID_INSTCALIB,
    110 ] = [wx.NewId() for item in range(8)]
     109    wxID_INSTSAVE, wxID_INST1VAL, wxID_INSTCALIB,wxID_INSTSAVEALL,
     110] = [wx.NewId() for item in range(9)]
    111111
    112112[ wxID_UNDO,wxID_LSQPEAKFIT,wxID_LSQONECYCLE,wxID_RESETSIGGAM,wxID_CLEARPEAKS,wxID_AUTOSEARCH,
     
    153153VERY_LIGHT_GREY = wx.Colour(235,235,235)
    154154
    155 # Aliases for Classes/Functions moved to GSASIIctrls, all should be tracked down but leaving as a reminder
    156 #SingleFloatDialog = G2G.SingleFloatDialog
    157 #SingleStringDialog = G2G.SingleStringDialog
    158 #MultiStringDialog = G2G.MultiStringDialog
    159 #G2ColumnIDDialog = G2G.G2ColumnIDDialog
    160 #ItemSelector = G2G.ItemSelector
    161 #HorizontalLine = G2G.HorizontalLine
    162 #G2LoggedButton = G2G.G2LoggedButton
    163 #EnumSelector = G2G.EnumSelector
    164 #G2ChoiceButton = G2G.G2ChoiceButton
    165 #GSGrid = G2G.GSGrid
    166 #Table = G2G.Table
    167 #GridFractionEditor = G2G.GridFractionEditor
    168 #GSNoteBook = G2G.GSNoteBook
     155commonTrans = {'abc':np.eye(3),'a-cb':np.array([[1,0,0],[0,0,-1],[0,1,0]]),
     156    'ba-c':np.array([[0,1,0],[1,0,0],[0,0,-1]]),'-cba':np.array([[0,0,-1],[0,1,0],[1,0,0]]),
     157    'bca':np.array([[0,1,0],[0,0,1],[1,0,0]]),'cab':np.array([[0,0,1],[1,0,0],[0,1,0]]),
     158    'P->R':np.array([[1,-1,0],[0,1,-1],[1,1,1]]),'R->P':np.array([[2./3,1./3,1./3],[-1./3,1./3,1./3],[-1./3,-2./3,1./3]]),
     159    'P->A':np.array([[-1,0,0],[0,-1,1],[0,1,1]]),'R->O':np.array([[-1,0,0],[0,-1,0],[0,0,1]]),
     160    'P->B':np.array([[-1,0,1],[0,-1,0],[1,0,1]]),'B->P':np.array([[-.5,0,.5],[0,-1,0],[.5,0,.5]]),
     161    'P->C':np.array([[1,1,0],[1,-1,0],[0,0,-1]]),'C->P':np.array([[.5,.5,0],[.5,-.5,0],[0,0,-1]]),
     162    'P->F':np.array([[-1,1,1],[1,-1,1],[1,1,-1]]),'F->P':np.array([[0,.5,.5],[.5,0,.5],[.5,.5,0]]),   
     163    'P->I':np.array([[0,1,1],[1,0,1],[1,1,0]]),'I->P':np.array([[-.5,.5,.5],[.5,-.5,.5],[.5,.5,-.5]]),   
     164    'A->P':np.array([[-1,0,0],[0,-.5,.5],[0,.5,.5]]),'O->R':np.array([[-1,0,0],[0,-1,0],[0,0,1]]), }
     165commonNames = ['abc','bca','cab','a-cb','ba-c','-cba','P->A','A->P',
     166    'P->B','B->P','P->C','C->P','P->I','I->P','P->F','F->P','P->R','R->P','R->O','O->R']
    169167
    170168# Should SGMessageBox, SymOpDialog, DisAglDialog be moved?
     
    324322   
    325323    :param wx.Frame parent: reference to parent frame (or None)
    326     :param data: HKLF data
     324    :param data: HKLF data
     325   
     326    #NB: commonNames & commonTrans defined at top of this file
    327327   
    328328    '''       
     
    340340        self.Laue = '1'
    341341        self.Class = 'triclinic'
     342        self.Common = 'abc'
    342343        self.Draw()
    343344       
    344345    def Draw(self):
    345        
    346         commonTrans = {'abc':np.eye(3),'a-cb':np.array([[1,0,0],[0,0,-1],[0,1,0]]),
    347             'ba-c':np.array([[0,1,0],[1,0,0],[0,0,-1]]),'-cba':np.array([[0,0,-1],[0,1,0],[1,0,0]]),
    348             'bca':np.array([[0,1,0],[0,0,1],[1,0,0]]),'cab':np.array([[0,0,1],[1,0,0],[0,1,0]]),
    349             'P->R':np.array([[1,-1,0],[0,1,-1],[1,1,1]]),'R->P':np.array([[2./3,1./3,1./3],[-1./3,1./3,1./3],[-1./3,-2./3,1./3]]),
    350             'P->A':np.array([[-1,0,0],[0,-1,1],[0,1,1]]),'R->O':np.array([[-1,0,0],[0,-1,0],[0,0,1]]),
    351             'P->B':np.array([[-1,0,1],[0,-1,0],[1,0,1]]),'B->P':np.array([[-.5,0,.5],[0,-1,0],[.5,0,.5]]),
    352             'P->C':np.array([[1,1,0],[1,-1,0],[0,0,-1]]),'C->P':np.array([[.5,.5,0],[.5,-.5,0],[0,0,-1]]),
    353             'P->F':np.array([[-1,1,1],[1,-1,1],[1,1,-1]]),'F->P':np.array([[0,.5,.5],[.5,0,.5],[.5,.5,0]]),   
    354             'P->I':np.array([[0,1,1],[1,0,1],[1,1,0]]),'I->P':np.array([[-.5,.5,.5],[.5,-.5,.5],[.5,.5,-.5]]),   
    355             'A->P':np.array([[-1,0,0],[0,-.5,.5],[0,.5,.5]]),'O->R':np.array([[-1,0,0],[0,-1,0],[0,0,1]]), }
    356         commonNames = ['abc','bca','cab','a-cb','ba-c','-cba','P->A','A->P',
    357             'P->B','B->P','P->C','C->P','P->I','I->P','P->F','F->P','P->R','R->P','R->O','O->R']
    358346               
    359347        def OnMatValue(event):
     
    381369        def OnCommon(event):
    382370            Obj = event.GetEventObject()
    383             self.Trans = commonTrans[Obj.GetValue()]
     371            self.Common = Obj.GetValue()
     372            self.Trans = commonTrans[self.Common]
    384373            wx.CallAfter(self.Draw)
    385374       
     
    396385            commonSizer = wx.BoxSizer(wx.HORIZONTAL)
    397386            commonSizer.Add(wx.StaticText(self.panel,label=' Common transformations: '),0,WACV)
    398             common = wx.ComboBox(self.panel,value='abc',choices=commonNames,
     387            common = wx.ComboBox(self.panel,value=self.Common,choices=commonNames,
    399388                style=wx.CB_READONLY|wx.CB_DROPDOWN)
    400389            common.Bind(wx.EVT_COMBOBOX,OnCommon)
     
    10921081        self.InstEdit.Append(help='Load instrument profile parameters from file',
    10931082            id=wxID_INSTLOAD, kind=wx.ITEM_NORMAL,text='Load profile...')           
     1083        self.InstEdit.Append(help='Save all instrument profile parameters to one file',
     1084            id=wxID_INSTSAVE, kind=wx.ITEM_NORMAL,text='Save profile...')
    10941085        self.InstEdit.Append(help='Save instrument profile parameters to file',
    1095             id=wxID_INSTSAVE, kind=wx.ITEM_NORMAL,text='Save profile...')           
     1086            id=wxID_INSTSAVEALL, kind=wx.ITEM_NORMAL,text='Save all profile...')           
    10961087        self.InstEdit.Append(help='Copy instrument profile parameters to other histograms',
    10971088            id=wxID_INSTCOPY, kind=wx.ITEM_NORMAL,text='Copy')
     
    30563047            dlg.Destroy()
    30573048        Super = data[1]['Super']
    3058         refList = G2lat.transposeHKLF(Trans,Super,refList)
    3059         if not len(refList):
     3049        refList,badRefs = G2lat.transposeHKLF(Trans,Super,refList)
     3050        if len(badRefs):    #do I want to list badRefs?
    30603051            G2frame.ErrorDialog('Failed transformation','Matrix yields fractional hkl indices')
    30613052            return
  • trunk/GSASIIlattice.py

    r2146 r2147  
    525525   
    526526def transposeHKLF(transMat,Super,refList):
     527    ''' Apply transformation matrix to hkl(m)
     528    param: transmat: 3x3 or 4x4 array
     529    param: Super: 0 or 1 for extra index
     530    param: refList list of h,k,l,....
     531    return: newRefs transformed list of h',k',l',,,
     532    return: badRefs list of noninteger h',k',l'...
     533    '''
    527534    newRefs = np.copy(refList)
     535    badRefs = []
    528536    for H in newRefs:
    529537        newH = np.inner(transMat,H[:3+Super])
    530538        H[:3+Super] = np.rint(newH)
    531539        if not np.allclose(newH,H[:3+Super],atol=0.01):
    532             return []
    533     return newRefs
     540            badRefs.append(newH)
     541    return newRefs,badRefs
    534542   
    535543def sortHKLd(HKLd,ifreverse,ifdup,ifSS=False):
     
    539547    :param ifreverse: True for largest d first
    540548    :param ifdup: True if duplicate d-spacings allowed
     549    :return sorted reflection list
    541550    '''
    542551    T = []
  • trunk/GSASIIpwdGUI.py

    r2137 r2147  
    11831183    '''
    11841184#patch
    1185     if 'Bank' not in data:
    1186         data['Bank'] = [1,1,0]
     1185    if 'Bank' not in data:  #get it from name
     1186        hst = G2frame.PatternTree.GetItemText(G2frame.PatternId)
     1187        if 'Bank' in hst:
     1188            bank = int(hst.split('Bank')[1])
     1189            data['Bank'] = [bank,bank,0]
     1190        else:
     1191            data['Bank'] = [1,1,0]
    11871192#end patch   
    11881193    def keycheck(keys):
     
    12521257        '''Loads instrument parameters from a G2 .instprm file
    12531258        in response to the Instrument Parameters-Operations/Load Profile menu
     1259        If instprm file has multiple banks each with header #Bank n: ..., this
     1260        finds matching bank no. to load - rejects nonmatches.
    12541261       
    12551262        Note that similar code is found in ReadPowderInstprm (GSASII.py)
    12561263        '''
     1264        data = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,
     1265            G2frame.PatternId,'Instrument Parameters'))[0]
     1266        bank = data['Bank'][0]
    12571267        pth = G2G.GetImportPath(G2frame)
    12581268        if not pth: pth = '.'
     
    12661276                newItems = []
    12671277                newVals = []
     1278                Found = False
    12681279                while S:
    12691280                    if S[0] == '#':
    1270                         S = File.readline()
    1271                         continue
     1281                        if Found:
     1282                            break
     1283                        if 'Bank' in S:
     1284                            if bank == int(S.split(':')[0].split()[1]):
     1285                                S = File.readline()
     1286                                continue
     1287                            else:
     1288                                S = File.readline()
     1289                                while S and '#Bank' not in S:
     1290                                    S = File.readline()
     1291                                continue
     1292                        else:   #a non #Bank file
     1293                            S = File.readline()
     1294                            continue
     1295                    Found = True
    12721296                    [item,val] = S[:-1].split(':')
    12731297                    newItems.append(item)
     
    12781302                    S = File.readline()               
    12791303                File.close()
    1280                 Inst,Inst2 = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId,'Instrument Parameters'))
    1281                 if 'Bank' not in Inst:  #patch for old .instprm files - may cause faults for TOF data
    1282                     Inst['Bank'] = [1,1,0]
    1283                 data = G2IO.makeInstDict(newItems,newVals,len(newVals)*[False,])
    1284                 G2frame.PatternTree.SetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId,'Instrument Parameters'),[data,Inst2])
    1285                 RefreshInstrumentGrid(event,doAnyway=True)          #to get peaks updated
     1304                if Found:
     1305                    Inst,Inst2 = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId,'Instrument Parameters'))
     1306                    if 'Bank' not in Inst:  #patch for old .instprm files - may cause faults for TOF data
     1307                        Inst['Bank'] = [1,1,0]
     1308                    data = G2IO.makeInstDict(newItems,newVals,len(newVals)*[False,])
     1309                    G2frame.PatternTree.SetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId,'Instrument Parameters'),[data,Inst2])
     1310                    RefreshInstrumentGrid(event,doAnyway=True)          #to get peaks updated
     1311                else:
     1312                    G2frame.ErrorDialog('No match','Bank %d not in %s'%(bank,filename),G2frame.dataFrame)
    12861313                UpdateInstrumentGrid(G2frame,data)
    12871314                G2plt.PlotPeakWidths(G2frame)
     
    12921319        '''Respond to the Instrument Parameters Operations/Save Profile menu
    12931320        item: writes current parameters to a .instprm file
     1321        It does not write Bank n: on # line & thus can be used any time w/o clash of bank nos.
    12941322        '''
    12951323        pth = G2G.GetExportPath(G2frame)
     
    13051333                for item in data:
    13061334                    File.write(item+':'+str(data[item][1])+'\n')
     1335                File.close()
     1336        finally:
     1337            dlg.Destroy()
     1338           
     1339    def OnSaveAll(event):
     1340        '''Respond to the Instrument Parameters Operations/Save all Profile menu & writes
     1341        selected inst parms. across multiple banks into a single file
     1342        Each block starts with #Bank n: GSAS-II instrument... where n is bank no.
     1343        item: writes parameters from selected PWDR entries to a .instprm file
     1344        '''
     1345        hst = G2frame.PatternTree.GetItemText(G2frame.PatternId)
     1346        histList = GetHistsLikeSelected(G2frame)
     1347        histList.insert(0,hst)
     1348        saveList = []
     1349        dlg = G2G.G2MultiChoiceDialog(
     1350            G2frame.dataFrame,
     1351            'Save instrument parameters from',
     1352            'Save instrument parameters', histList)
     1353        try:
     1354            if dlg.ShowModal() == wx.ID_OK:
     1355                for i in dlg.GetSelections():
     1356                    saveList.append(histList[i])
     1357        finally:
     1358            dlg.Destroy()
     1359        pth = G2G.GetExportPath(G2frame)
     1360        dlg = wx.FileDialog(G2frame, 'Choose GSAS-II instrument parameters file', pth, '',
     1361            'instrument parameter files (*.instprm)|*.instprm',wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT)
     1362        try:
     1363            if dlg.ShowModal() == wx.ID_OK:
     1364                filename = dlg.GetPath()
     1365                # make sure extension is .instprm
     1366                filename = os.path.splitext(filename)[0]+'.instprm'
     1367                File = open(filename,'w')
     1368                for hist in saveList:
     1369                    Id = G2gd.GetPatternTreeItemId(G2frame,G2frame.root,hist)
     1370                    inst = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Id,'Instrument Parameters'))[0]
     1371                    if 'Bank' not in inst:  #patch
     1372                        bank = 1
     1373                        if 'Bank' in hist:
     1374                            bank = int(hist.split('Bank')[1])
     1375                        inst['Bank'] = [bank,bank,0]
     1376                    bank = inst['Bank'][0]               
     1377                    File.write("#Bank %d: GSAS-II instrument parameter file; do not add/delete items!\n"%(bank))
     1378                    for item in inst:
     1379                        File.write(item+':'+str(inst[item][1])+'\n')                                   
    13071380                File.close()
    13081381        finally:
     
    17271800        G2frame.Bind(wx.EVT_MENU,OnLoad,id=G2gd.wxID_INSTLOAD)
    17281801        G2frame.Bind(wx.EVT_MENU,OnSave,id=G2gd.wxID_INSTSAVE)
     1802        G2frame.Bind(wx.EVT_MENU,OnSaveAll,id=G2gd.wxID_INSTSAVEALL)
    17291803        G2frame.Bind(wx.EVT_MENU,OnReset,id=G2gd.wxID_INSTPRMRESET)
    17301804        G2frame.Bind(wx.EVT_MENU,OnInstCopy,id=G2gd.wxID_INSTCOPY)
     
    17331807        G2frame.Bind(wx.EVT_MENU,OnCopy1Val,id=G2gd.wxID_INST1VAL)
    17341808    elif 'L' in insVal['Type']:                   #SASD data menu commands
    1735         G2gd.SetDataMenuBar(G2frame,G2frame.dataFrame.InstMenu)
     1809        G2gd.SetDataMenuBar(G2frame,G2frame.dataFrame.SASDInstMenu)
    17361810        if not G2frame.dataFrame.GetStatusBar():
    17371811            Status = G2frame.dataFrame.CreateStatusBar()
Note: See TracChangeset for help on using the changeset viewer.