Changeset 5275
- Timestamp:
- May 13, 2022 5:47:57 PM (19 months ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIdataGUI.py
r5274 r5275 767 767 self.Refine.append(item) 768 768 self.Bind(wx.EVT_MENU, self.OnRefine, id=item.GetId()) 769 # this could be disabled during sequential fits:770 769 item = parent.Append(wx.ID_ANY,'Compute partials','Record the contribution from each phase') 770 self.Refine.append(item) 771 item.Enable(state) # disabled during sequential fits 771 772 self.Bind(wx.EVT_MENU, self.OnRefinePartials, id=item.GetId()) 772 773 item = parent.Append(wx.ID_ANY,'&Run Fprime','X-ray resonant scattering') … … 809 810 810 811 for item in self.Refine: 811 if 'Le Bail' in item.GetItemLabel() :812 i f seqSetting: item.Enable(False)812 if 'Le Bail' in item.GetItemLabel() or 'partials' in item.GetItemLabel() : 813 item.Enable(not seqSetting) 813 814 elif seqSetting: 814 815 item.SetItemLabel('Se&quential refine\tCtrl+R') #might fail on old wx … … 2754 2755 defnam = os.path.splitext(os.path.split(self.GSASprojectfile)[1])[0]+'.gcmd' 2755 2756 dlg = wx.FileDialog(self, 2756 'Choose a nfile to save past actions', '.', defnam,2757 'Choose a file to save past actions', '.', defnam, 2757 2758 'GSAS-II cmd output (*.gcmd)|*.gcmd', 2758 2759 wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT) … … 5512 5513 any fit. 5513 5514 ''' 5514 PhasePartials = os.path.abspath(os.path.splitext(self.GSASprojectfile)[0]) 5515 histograms,phases = self.GetUsedHistogramsAndPhasesfromTree() 5516 for h in histograms: 5517 if 'PWDR' not in h[:4]: continue 5518 hId = histograms[h]['hId'] 5519 phPartialFile = PhasePartials+'.partials'+str(hId) 5520 if os.path.exists(phPartialFile): 5521 os.remove(phPartialFile) 5522 print('file deleted:',phPartialFile) 5515 PhasePartials = os.path.abspath(os.path.splitext(self.GSASprojectfile)[0]+'.partials') 5516 if os.path.exists(PhasePartials): 5517 os.remove(PhasePartials) 5518 print('file deleted:',PhasePartials) 5523 5519 5524 5520 … … 5532 5528 info in :meth:`GSASIIstrMath.getPowderProfile` and then clear that. 5533 5529 ''' 5534 if self.testSeqRefineMode(): 5530 if self.testSeqRefineMode(): # should not happen, as should not be enabled 5535 5531 G2G.G2MessageBox(self, 5536 'Phase partials cannot be computed for seq iential fits'5537 ' not allowed')5532 'Phase partials cannot be computed for sequential fits', 5533 'Sequential not allowed') 5538 5534 return 5539 5535 Controls = self.GPXtree.GetItemPyData(GetGPXtreeItemId(self,self.root, 'Controls')) 5540 5536 savCyc,Controls['max cyc'] = Controls['max cyc'],0 5541 Controls['PhasePartials'] = os.path.abspath(os.path.splitext(self.GSASprojectfile)[0] )5537 Controls['PhasePartials'] = os.path.abspath(os.path.splitext(self.GSASprojectfile)[0]+'.partials') 5542 5538 self.OnFileSave(event) 5543 5539 dlg = G2G.RefinementProgress(parent=self) … … 5545 5541 self.GPXtree.SaveExposedItems() # save the exposed/hidden tree items 5546 5542 5547 import pickle5548 5549 5543 try: 5550 5544 OK,Rvals = G2stMn.Refine(self.GSASprojectfile,dlg,refPlotUpdate=None,newLeBail=False) 5551 5545 except Exception as msg: 5552 5546 print('Refinement failed with message',msg) 5547 Controls['max cyc'] = savCyc 5548 Controls['PhasePartials'] = None 5549 self.OnFileSave(event) 5553 5550 return True 5554 5551 finally: 5555 5552 dlg.Update(101.) # forces the Auto_Hide; needed after move w/Win & wx3.0 5556 # assemble the arrays by histogram 5553 dlg.Destroy() 5554 5555 while True: # loop until we get a name or the user says no to export 5556 dlg = wx.MessageDialog(self.GetTopLevelParent(), 5557 'Export the partial intensities by phase as a comma-separated-variable file?', 5558 caption='Export partials?',style=wx.YES_NO) 5559 dlg.CenterOnParent() 5560 result = wx.ID_NO 5561 try: 5562 result = dlg.ShowModal() 5563 finally: 5564 dlg.Destroy() 5565 if result == wx.ID_NO: 5566 Controls['max cyc'] = savCyc 5567 Controls['PhasePartials'] = None 5568 self.OnFileSave(event) 5569 return 5570 5571 filename = None 5572 defpath,defnam = os.path.split(os.path.abspath( 5573 os.path.splitext(self.GSASprojectfile)[0]+'_part_N.csv')) 5557 5574 5575 dlg = wx.FileDialog(self, 5576 'Choose a file prefix to save the partials', defpath, defnam, 5577 'spreadsheet input (*.csv)|*.csv',wx.FD_SAVE) 5578 dlg.CenterOnParent() 5579 try: 5580 if dlg.ShowModal() == wx.ID_OK: 5581 filename = os.path.splitext(dlg.GetPath())[0] # drop extension 5582 if not filename.endswith('_part_N'): 5583 filename += '_part_N' 5584 break 5585 finally: 5586 dlg.Destroy() 5587 # write the .csv file(s) 5588 import pickle 5558 5589 histograms,phases = self.GetUsedHistogramsAndPhasesfromTree() 5559 for h in histograms: 5560 if 'PWDR' not in h[:4]: continue 5561 hId = histograms[h]['hId'] 5562 hfx = ':%d:'%(hId) 5563 Limits = histograms[h]['Limits'][1] 5564 x = histograms[h]['Data'][0] 5565 xB = np.searchsorted(x,Limits[0]) 5566 xF = np.searchsorted(x,Limits[1])+1 5567 phPartialFile = Controls['PhasePartials']+'.partials'+str(hId) 5568 fp = open(phPartialFile,'rb') 5569 pickle.load(fp) # skip over x values 5570 valList = [x,histograms[h]['Data'][1], 5590 phPartialFile = Controls['PhasePartials'] 5591 fp = open(phPartialFile,'rb') 5592 pickle.load(fp) # skip over initial None 5593 done = False 5594 while not done: # looping over histograms 5595 valList = None 5596 lblList = ['x','obs','wgt','calc','background'] 5597 try: 5598 hId = pickle.load(fp) # get histogram number 5599 pickle.load(fp) # skip over x values 5600 pickle.load(fp) # skip over bkg values 5601 for h in histograms: 5602 if 'PWDR' not in h[:4]: continue 5603 if hId == histograms[h]['hId']: break 5604 else: 5605 print('Error histogram',hId,'not found. This should not happen!') 5606 fp.close() 5607 Controls['max cyc'] = savCyc 5608 Controls['PhasePartials'] = None 5609 self.OnFileSave(event) 5610 return 5611 Limits = histograms[h]['Limits'][1] 5612 x = histograms[h]['Data'][0] 5613 xB = np.searchsorted(x,Limits[0]) 5614 xF = np.searchsorted(x,Limits[1])+1 5615 valList = [x,histograms[h]['Data'][1], 5571 5616 histograms[h]['Data'][2],histograms[h]['Data'][3], 5572 5617 histograms[h]['Data'][4]] 5573 lblList = ['x','obs','wgt','calc','background'] 5574 while True: 5575 try: 5576 ph = pickle.load(fp) 5577 lblList.append(ph) 5618 while True: # read until we hit an EOF or a None 5619 phase = pickle.load(fp) # get histogram number 5620 if phase is None: break 5621 lblList.append(phase) 5578 5622 ypartial = np.zeros_like(x) 5579 5623 ypartial[xB:xF] = pickle.load(fp) 5580 5624 valList.append(ypartial) 5581 except EOFError: 5582 break 5583 fp.close() 5584 phPartialFile = Controls['PhasePartials']+'_part_'+str(histograms[h]['hId'])+'.csv' 5585 fp = open(phPartialFile,'w') 5586 fp.write(', '.join(lblList)) 5587 fp.write('\n') 5588 for l in zip(*valList): 5589 fp.write(', '.join([str(i) for i in l])+'\n') 5590 fp.close() 5591 print('File',phPartialFile,'written') 5592 dlg.Destroy() 5625 except EOFError: 5626 done = True 5627 if valList: 5628 phPartialFile = filename.replace('_part_N', 5629 '_part_'+str(hId)+'.csv') 5630 fp1 = open(phPartialFile,'w') 5631 fp1.write(', '.join(lblList)) 5632 fp1.write('\n') 5633 for l in zip(*valList): 5634 fp1.write(', '.join([str(i) for i in l])+'\n') 5635 fp1.close() 5636 print('File',phPartialFile,'written') 5637 5593 5638 Controls['max cyc'] = savCyc 5594 5639 Controls['PhasePartials'] = None -
trunk/GSASIIstrMath.py
r5274 r5275 3275 3275 return alp,bet 3276 3276 3277 # set up for save of phase partials if triggered in GSASIIdataGUI.OnRefinePartials3278 phasePartials = calcControls.get('PhasePartials',None)3279 def SavePartial(*args): pass3280 if phasePartials:3281 phPartialFile = phasePartials+'.partials'+str(Histogram['hId'])3282 phPartialFP = open(phPartialFile,'wb') # create/overwrite a file3283 pickle.dump(x,phPartialFP)3284 phPartialFP.close()3285 print('Storing intensity by phase in',phPartialFile)3286 def SavePartial(phase,y):3287 phPartialFP = open(phPartialFile,'ab') # append to file3288 pickle.dump(phase,phPartialFP)3289 pickle.dump(y,phPartialFP)3290 phPartialFP.close()3291 3277 hId = Histogram['hId'] 3292 3278 hfx = ':%d:'%(hId) … … 3297 3283 cw = np.diff(ma.getdata(x)) 3298 3284 cw = np.append(cw,cw[-1]) 3285 # set up for save of phase partials if triggered in GSASIIdataGUI.OnRefinePartials 3286 phasePartials = calcControls.get('PhasePartials',None) 3287 if phasePartials: 3288 phPartialFP = open(phasePartials,'ab') # create histogram header 3289 pickle.dump(None,phPartialFP) 3290 pickle.dump(hId,phPartialFP) 3291 pickle.dump(x,phPartialFP) 3292 pickle.dump(yb,phPartialFP) 3293 phPartialFP.close() 3294 def SavePartial(phase,y): 3295 phPartialFP = open(phasePartials,'ab') # append to file 3296 pickle.dump(phase,phPartialFP) 3297 pickle.dump(y,phPartialFP) 3298 phPartialFP.close() 3299 3299 3300 3300 if 'C' in calcControls[hfx+'histType']: … … 4262 4262 histoList = list(Histograms.keys()) 4263 4263 histoList.sort() 4264 phasePartials = calcControls.get('PhasePartials',None) 4265 if phasePartials: 4266 print('Storing intensity by phase in',phasePartials) 4267 phPartialFP = open(phasePartials,'wb') # create/clear partials file 4268 phPartialFP.close() 4264 4269 for histogram in histoList: 4265 4270 if 'PWDR' in histogram[:4]: -
trunk/help/gsasII.html
r5274 r5275 5527 5527 </span></span></span><![endif]><b>Compute partials - </b>This runs a 5528 5528 zero-cycle refinement where the contributions from each phase (phase 5529 partial intensities) are written separately to a file for each histogram in the 5530 refinement. This information is written into files named 5531 <tt><I>project</I>.partials</tt><I>N</I> where <I>N</I> is the 5532 histogram number and <tt><I>project</I></tt> is the GSAS-II project (.gpx) 5533 name. From those file(s), files named 5534 <tt><I>project</I>_part_</tt><I>N</I><tt>.csv</tt> are also created. 5535 The first set of files are intended for future use internally by 5536 GSAS-II and the latter files are for use in external software. The 5537 former set will be deleted if a refinement is run. Use this menu 5538 command to recreate them if needed. 5529 partial intensities) are written for each histogram 5530 and each phase in that histogram into a single file named 5531 <tt><I>project</I>.partials</tt> where 5532 <tt><I>project</I></tt> is the GSAS-II project (.gpx) 5533 name. This file is intended for internal use in GSAS-II and will be 5534 deleted if additional refinements are performed (making the 5535 information in them obsolete; use this menu 5536 command to recreate them if needed.) 5537 When the <tt>.partials</tt> file is created, the user can optionally choose to 5538 export the intensity information in a series of ASCII files named 5539 <tt><I>prefix</I>_part_</tt><I>N</I><tt>.csv</tt>, which can be read by 5540 spreadsheets and most scientific software. 5539 5541 </P> 5540 5542 … … 9763 9765 </span></div> 9764 9766 9765 <p class=MsoNormal style='tab-stops:45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt'><!-- hhmts start -->Last modified: Thu May 12 14:50:38CDT 2022 <!-- hhmts end --></div>9767 <p class=MsoNormal style='tab-stops:45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt'><!-- hhmts start -->Last modified: Fri May 13 16:26:04 CDT 2022 <!-- hhmts end --></div> 9766 9768 9767 9769 </body>
Note: See TracChangeset
for help on using the changeset viewer.