Changeset 4685 for trunk/GSASIIimgGUI.py


Ignore:
Timestamp:
Dec 29, 2020 12:37:31 PM (10 months ago)
Author:
vondreele
Message:

Add gain map calculator

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIimgGUI.py

    r4672 r4685  
    122122            GMid = G2gd.GetGPXtreeItemId(G2frame, G2frame.root, gainMap)
    123123            if GMid:
    124                 Npix,gainfile,imagetag = G2IO.GetCheckImageFile(G2frame,GMid)
    125                 GMimage = G2IO.GetImageData(G2frame,gainfile,True,ImageTag=imagetag,FormatName=formatName)
     124                Npix,gainfile,imagetag = G2IO.GetCheckImageFile(G2frame,GMid)               
     125                Gdata = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,GMid,'Image Controls'))
     126                gformat = Gdata['formatName']
     127                GMimage = G2IO.GetImageData(G2frame,gainfile,True,ImageTag=imagetag,FormatName=gformat)
    126128                sumImg = sumImg*GMimage/1000
    127129    sumImg -= int(data.get('Flat Bkg',0))
     
    154156        dlg.Destroy()
    155157       
     158    def OnMakeGainMap(event):
     159        sumImg = GetImageZ(G2frame,data)
     160        masks = copy.deepcopy(G2frame.GPXtree.GetItemPyData(
     161            G2gd.GetGPXtreeItemId(G2frame,G2frame.Image,'Masks')))
     162        Data = copy.deepcopy(data)
     163        #force defaults for GainMap calc
     164        Data['IOtth'] = [0.1,60.0]
     165        Data['outAzimuths'] = 1
     166        Data['LRazimuth'] = [0.,360.]
     167        Data['outChannels'] = 2500
     168        Data['SampleAbs'] = [0.0,False]
     169        Data['binType'] = '2-theta'
     170        G2frame.Integrate = G2img.ImageIntegrate(sumImg,Data,masks,blkSize)           
     171        Iy,azms,Ix = G2frame.Integrate[:3]
     172        GainMap = G2img.MakeGainMap(sumImg,Ix,Iy,Data,masks,blkSize)*1000.
     173        Npix,imagefile,imagetag = G2IO.GetCheckImageFile(G2frame,G2frame.Image)
     174        pth = os.path.split(os.path.abspath(imagefile))[0]
     175        outname = 'GainMap'
     176        dlg = wx.FileDialog(G2frame, 'Choose gain map filename', pth,outname,
     177            'G2img files (*.G2img)|*.G2img',wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT)
     178        if dlg.ShowModal() == wx.ID_OK:
     179            newimagefile = dlg.GetPath()
     180            newimagefile = G2IO.FileDlgFixExt(dlg,newimagefile)
     181            Data['formatName'] = 'GSAS-II image'
     182            Data['range'] = [(800,1200),[800,1200]]
     183            G2IO.PutG2Image(newimagefile,[],data,Npix,GainMap)
     184            Id = G2frame.GPXtree.AppendItem(parent=G2frame.root,text='IMG '+os.path.split(newimagefile)[1])
     185            G2frame.GPXtree.SetItemPyData(Id,[Npix,newimagefile])
     186            G2frame.GPXtree.SetItemPyData(G2frame.GPXtree.AppendItem(Id,text='Comments'),[])
     187            G2frame.GPXtree.SetItemPyData(G2frame.GPXtree.AppendItem(Id,text='Image Controls'),Data)
     188            G2frame.GPXtree.SetItemPyData(G2frame.GPXtree.AppendItem(Id,text='Masks'),masks)
     189            G2frame.GPXtree.Expand(Id)
     190            G2frame.GPXtree.SelectItem(Id)      #to show the gain map & put it in the list
     191
    156192    G2frame.dataWindow.ClearData()
    157193    G2frame.ImageZ = GetImageZ(G2frame,data)
     
    194230    tthSizer.Add(wx.StaticText(G2frame.dataWindow,label=' Sample changer position %.2f mm '%data['samplechangerpos']),0,WACV)
    195231    mainSizer.Add(tthSizer,0)
     232    if not data['Gain map']:
     233        makeGain = wx.Button(G2frame.dataWindow,label='Make gain map from this image? NB: use only an amorphous pattern for this')
     234        makeGain.Bind(wx.EVT_BUTTON,OnMakeGainMap)
     235        mainSizer.Add(makeGain)
    196236    G2frame.dataWindow.SetDataSize()
    197237
     
    473513        '''Integrate image in response to a menu event or from the AutoIntegrate
    474514        dialog. In the latter case, event=None.
    475         TODO: think of not repeating x,y-->2th,azm calc for unchanging calibrations?
    476515        '''
    477516        CleanupMasks(masks)
     
    13111350            ResetThresholds()
    13121351            wx.CallAfter(G2plt.PlotExposedImage,G2frame,event=event)
    1313        
     1352           
    13141353        backSizer = wx.FlexGridSizer(0,6,5,5)
    13151354        oldFlat = data.get('Flat Bkg',0.)
     
    13441383        backSizer.Add((5,5),0)
    13451384        backSizer.Add(wx.StaticText(G2frame.dataWindow,-1,' Gain map'),0,WACV)
    1346         gainMap = wx.ComboBox(parent=G2frame.dataWindow,value=data['Gain map'],choices=Choices,
     1385        gainMap = wx.ComboBox(G2frame.dataWindow,value=data['Gain map'],choices=Choices,
    13471386            style=wx.CB_READONLY|wx.CB_DROPDOWN)
    13481387        gainMap.Bind(wx.EVT_COMBOBOX,OnGainMap)
Note: See TracChangeset for help on using the changeset viewer.