Changeset 5291


Ignore:
Timestamp:
May 27, 2022 11:43:05 AM (7 months ago)
Author:
vondreele
Message:

add new menu item to Calculate: "Save partials as csv"
Simplify GUI for save partial csv.
Handle histograms with only one phase in save csv - now skipped.
Error trap for missing partials pickle file.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIdataGUI.py

    r5287 r5291  
    8484import GSASIIpwd as G2pwd
    8585import GSASIIstrMain as G2stMn
    86 import GSASIIstrMath as G2stMth
     86#import GSASIIstrMath as G2stMth
    8787import defaultIparms as dI
    8888import GSASIIfpaGUI as G2fpa
    8989import GSASIIseqGUI as G2seq
    9090import GSASIIddataGUI as G2ddG
    91 import GSASIIspc as G2spc
     91#import GSASIIspc as G2spc
    9292
    9393try:
     
    773773        item.Enable(state) # disabled during sequential fits
    774774        self.Bind(wx.EVT_MENU, self.OnRefinePartials, id=item.GetId())
     775       
     776        item = parent.Append(wx.ID_ANY,'Save partials as csv','Save the computed partials as a csv file')
     777        self.Refine.append(item)
     778        item.Enable(state) # disabled during sequential fits
     779        self.Bind(wx.EVT_MENU, self.OnSavePartials, id=item.GetId())
     780       
    775781        item = parent.Append(wx.ID_ANY,'&Run Fprime','X-ray resonant scattering')
    776782        self.Bind(wx.EVT_MENU, self.OnRunFprime, id=item.GetId())
     
    54645470       
    54655471        if GSASIIpath.GetConfigValue('G2RefinementWindow'):           
    5466             Controls = self.GPXtree.GetItemPyData(GetGPXtreeItemId(self,self.root, 'Controls'))
     5472#            Controls = self.GPXtree.GetItemPyData(GetGPXtreeItemId(self,self.root, 'Controls'))
    54675473            if (self.testSeqRefineMode()):
    54685474                l = len(self.testSeqRefineMode())
     
    55515557    def OnRefinePartials(self,event):
    55525558        '''Computes and saves the intensities from each phase for each powder
    5553         histogram. These inten
    5554         Do a 0 cycle fit with no variables to pickle intensities for each
    5555         phase into a file.
    5556         Not for sequential fits.
     5559        histogram. Do a 0 cycle fit with no variables to pickle intensities for each
     5560        phase into a file. Not for sequential fits.
    55575561        Sets Controls['PhasePartials'] to a file name to trigger save of
    55585562        info in :meth:`GSASIIstrMath.getPowderProfile` and then clear that.
     
    55845588            dlg.Update(101.) # forces the Auto_Hide; needed after move w/Win & wx3.0
    55855589        dlg.Destroy()
    5586 
     5590        Controls['deriv type'] = saveDervtype
     5591        Controls['max cyc'] = savCyc
     5592        self.OnFileSave(event)
     5593   
     5594    def OnSavePartials(self,event):
     5595        ''' Saves partials as a csv file
     5596        '''
     5597        Controls = self.GPXtree.GetItemPyData(GetGPXtreeItemId(self,self.root, 'Controls'))
     5598        phPartialFile = Controls['PhasePartials']
     5599        try:
     5600            fp = open(phPartialFile,'rb')
     5601        except:
     5602            G2G.G2MessageBox(self,
     5603                'Phase partials cannot be saved - partials file does not exist',
     5604                'No partials file')
     5605            return
     5606        # savCyc,Controls['max cyc'] = Controls['max cyc'],0
     5607        # saveDervtype,Controls['deriv type'] = Controls['deriv type'],'analytic Hessian'
    55875608        while True: # loop until we get a name or the user says no to export
    5588             dlg = wx.MessageDialog(self.GetTopLevelParent(),
    5589                 'Export the partial intensities by phase as a comma-separated-variable file?',
    5590                 caption='Export partials?',style=wx.YES_NO)
    5591             dlg.CenterOnParent()
    5592             result = wx.ID_NO
    5593             try:
    5594                 result = dlg.ShowModal()
    5595             finally:
    5596                 dlg.Destroy()
    5597             if result == wx.ID_NO:
    5598                 Controls['deriv type'] = saveDervtype
    5599                 Controls['max cyc'] = savCyc
    5600                 Controls['PhasePartials'] = None
    5601                 self.OnFileSave(event)
    5602                 return
    56035609
    56045610            filename = None
     
    56165622                        filename += '_part_N'
    56175623                    break
     5624                else:
     5625                    return False
    56185626            finally:
    56195627                dlg.Destroy()
    56205628        # write the .csv file(s)
    56215629        histograms,phases = self.GetUsedHistogramsAndPhasesfromTree()
    5622         phPartialFile = Controls['PhasePartials']
    5623         fp = open(phPartialFile,'rb')
    56245630        pickle.load(fp)   # skip over initial None
    56255631        done = False
     
    56375643                    print('Error histogram',hId,'not found. This should not happen!')
    56385644                    fp.close()
    5639                     Controls['deriv type'] = saveDervtype
    5640                     Controls['max cyc'] = savCyc
     5645                    # Controls['deriv type'] = saveDervtype
     5646                    # Controls['max cyc'] = savCyc
    56415647                    Controls['PhasePartials'] = None
    56425648                    self.OnFileSave(event)
     
    56545660                    lblList.append(phase)
    56555661                    ypartial = np.zeros_like(x)
    5656                     ypartial[xB:xF] = pickle.load(fp)
    5657                     valList.append(ypartial)
     5662                    yp = pickle.load(fp)
     5663                    if len(yp):
     5664                        ypartial[xB:xF] = yp
     5665                        valList.append(ypartial)
     5666                    else:
     5667                        valList = None
     5668                        continue
    56585669            except EOFError:
    56595670                done = True
     
    56675678                fp1.close()
    56685679                print('File',phPartialFile,'written')
    5669 
    5670         Controls['deriv type'] = saveDervtype
    5671         Controls['max cyc'] = savCyc
    5672         Controls['PhasePartials'] = None
    5673         self.OnFileSave(event)
    5674         return False
     5680        fp.close()
     5681        print('Saving partials as csv files finished')
     5682       
    56755683   
    56765684    def reloadFromGPX(self,rtext=None):
Note: See TracChangeset for help on using the changeset viewer.