Changeset 1518 for trunk/GSASIIimgGUI.py


Ignore:
Timestamp:
Oct 6, 2014 10:16:26 AM (9 years ago)
Author:
vondreele
Message:

Add metadata file processing for Image stress/strain data - reads sample load & sample phi from text file.
Correction to PWDR metadata file processing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIimgGUI.py

    r1472 r1518  
    4242##### Image Data
    4343################################################################################
     44
    4445def UpdateImageData(G2frame,data):
    4546   
     
    15001501        finally:
    15011502            dlg.Destroy()
    1502 
     1503           
     1504    def OnStrStaSample(event):
     1505        filename = ''
     1506        dlg = wx.FileDialog(G2frame, 'Choose multihistogram metadata text file', '.', '',
     1507            'metadata file (*.*)|*.*',wx.OPEN|wx.CHANGE_DIR)
     1508        try:
     1509            if dlg.ShowModal() == wx.ID_OK:
     1510                filename = dlg.GetPath()
     1511                File = open(filename,'r')
     1512                S = File.readline()
     1513                newItems = []
     1514                itemNames = []
     1515                Comments = []
     1516                while S:
     1517                    if S[0] == '#':
     1518                        Comments.append(S)
     1519                        S = File.readline()
     1520                        continue
     1521                    S = S.replace(',',' ').replace('\t',' ')
     1522                    Stuff = S[:-1].split()
     1523                    itemNames.append(Stuff[0])
     1524                    newItems.append(Stuff[1:])
     1525                    S = File.readline()               
     1526                File.close()
     1527        finally:
     1528            dlg.Destroy()
     1529        if not filename:
     1530            G2frame.ErrorDialog('Nothing to do','No file selected')
     1531            return
     1532        dataDict = dict(zip(itemNames,newItems))
     1533        ifany = False
     1534        Names = [' ','Sample phi','Sample z','Sample load']
     1535        dlg = G2gd.G2ColumnIDDialog( G2frame,' Choose multihistogram metadata columns:',
     1536            'Select columns',Comments,Names,np.array(newItems).T)
     1537        try:
     1538            if dlg.ShowModal() == wx.ID_OK:
     1539                colNames,newData = dlg.GetSelection()
     1540                dataDict = dict(zip(itemNames,newData.T))
     1541                for item in colNames:
     1542                    if item != ' ':
     1543                        ifany = True
     1544        finally:
     1545            dlg.Destroy()
     1546        if not ifany:
     1547            G2frame.ErrorDialog('Nothing to do','No columns identified')
     1548            return
     1549        histList = []
     1550        item, cookie = G2frame.PatternTree.GetFirstChild(G2frame.root)       
     1551        while item:
     1552            name = G2frame.PatternTree.GetItemText(item)
     1553            if name.startswith('IMG'):
     1554                histList.append(name)
     1555            item, cookie = G2frame.PatternTree.GetNextChild(G2frame.root, cookie)
     1556        colIds = {}
     1557        for i,name in enumerate(colNames):
     1558            if name != ' ':
     1559                colIds[name] = i
     1560        for hist in histList:
     1561            name = hist.split()[1]  #this is file name
     1562            if name in dataDict:
     1563                newItems = {}
     1564                for item in colIds:
     1565                    newItems[item] = float(dataDict[name][colIds[item]])
     1566                Id = G2gd.GetPatternTreeItemId(G2frame,G2frame.root,hist)
     1567                stsrData = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Id,'Stress/Strain'))
     1568                stsrData.update(newItems)       
     1569        UpdateStressStrain(G2frame,data)       
     1570   
    15031571    def OnFitStrSta(event):
    15041572        Controls = G2frame.PatternTree.GetItemPyData(
     
    17451813    G2frame.dataFrame.Bind(wx.EVT_MENU, OnCopyStrSta, id=G2gd.wxID_STRSTACOPY)
    17461814    G2frame.dataFrame.Bind(wx.EVT_MENU, OnLoadStrSta, id=G2gd.wxID_STRSTALOAD)
    1747     G2frame.dataFrame.Bind(wx.EVT_MENU, OnSaveStrSta, id=G2gd.wxID_STRSTASAVE)   
     1815    G2frame.dataFrame.Bind(wx.EVT_MENU, OnSaveStrSta, id=G2gd.wxID_STRSTASAVE)
     1816    G2frame.dataFrame.Bind(wx.EVT_MENU, OnStrStaSample, id=G2gd.wxID_STRSTSAMPLE)       
    17481817    if not G2frame.dataFrame.GetStatusBar():
    17491818        Status = G2frame.dataFrame.CreateStatusBar()
Note: See TracChangeset for help on using the changeset viewer.