Changeset 5274
- Timestamp:
- May 12, 2022 2:57:13 PM (17 months ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIdataGUI.py
r5272 r5274 767 767 self.Refine.append(item) 768 768 self.Bind(wx.EVT_MENU, self.OnRefine, id=item.GetId()) 769 769 # this could be disabled during sequential fits: 770 item = parent.Append(wx.ID_ANY,'Compute partials','Record the contribution from each phase') 771 self.Bind(wx.EVT_MENU, self.OnRefinePartials, id=item.GetId()) 770 772 item = parent.Append(wx.ID_ANY,'&Run Fprime','X-ray resonant scattering') 771 773 self.Bind(wx.EVT_MENU, self.OnRunFprime, id=item.GetId()) … … 5350 5352 Called from the Calculate/Refine menu. 5351 5353 ''' 5354 self._cleanPartials() # phase partials invalid after a refinement 5352 5355 if self.testSeqRefineMode(): 5353 5356 self.OnSeqRefine(event) … … 5448 5451 either single or sequentially 5449 5452 ''' 5453 self._cleanPartials() # phase partials invalid after a refinement 5450 5454 self.OnFileSave(event) 5451 5455 item = GetGPXtreeItemId(self,self.root,'Covariance') … … 5502 5506 return True 5503 5507 return False 5504 5508 5509 def _cleanPartials(self): 5510 '''Delete any partials created with :meth:`OnRefinePartials`; used 5511 in GUI-based refinements, as the partials are no longer correct after 5512 any fit. 5513 ''' 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) 5523 5524 5525 def OnRefinePartials(self,event): 5526 '''Computes and saves the intensities from each phase for each powder 5527 histogram. These inten 5528 Do a 0 cycle fit with no variables to pickle intensities for each 5529 phase into a file. 5530 Not for sequential fits. 5531 Sets Controls['PhasePartials'] to a file name to trigger save of 5532 info in :meth:`GSASIIstrMath.getPowderProfile` and then clear that. 5533 ''' 5534 if self.testSeqRefineMode(): 5535 G2G.G2MessageBox(self, 5536 'Phase partials cannot be computed for seqiential fits' 5537 'not allowed') 5538 return 5539 Controls = self.GPXtree.GetItemPyData(GetGPXtreeItemId(self,self.root, 'Controls')) 5540 savCyc,Controls['max cyc'] = Controls['max cyc'],0 5541 Controls['PhasePartials'] = os.path.abspath(os.path.splitext(self.GSASprojectfile)[0]) 5542 self.OnFileSave(event) 5543 dlg = G2G.RefinementProgress(parent=self) 5544 self.SaveTreeSetting() # save the current tree selection 5545 self.GPXtree.SaveExposedItems() # save the exposed/hidden tree items 5546 5547 import pickle 5548 5549 try: 5550 OK,Rvals = G2stMn.Refine(self.GSASprojectfile,dlg,refPlotUpdate=None,newLeBail=False) 5551 except Exception as msg: 5552 print('Refinement failed with message',msg) 5553 return True 5554 finally: 5555 dlg.Update(101.) # forces the Auto_Hide; needed after move w/Win & wx3.0 5556 # assemble the arrays by histogram 5557 5558 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], 5571 histograms[h]['Data'][2],histograms[h]['Data'][3], 5572 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) 5578 ypartial = np.zeros_like(x) 5579 ypartial[xB:xF] = pickle.load(fp) 5580 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() 5593 Controls['max cyc'] = savCyc 5594 Controls['PhasePartials'] = None 5595 self.OnFileSave(event) 5596 return False 5597 5505 5598 def reloadFromGPX(self,rtext=None): 5506 5599 '''Deletes current data tree & reloads it from GPX file (after a -
trunk/GSASIIstrMath.py
r5266 r5274 19 19 import scipy.stats as st 20 20 import multiprocessing as mp 21 import pickle 21 22 import GSASIIpath 22 23 GSASIIpath.SetVersionNumber("$Revision$") … … 3274 3275 return alp,bet 3275 3276 3277 # set up for save of phase partials if triggered in GSASIIdataGUI.OnRefinePartials 3278 phasePartials = calcControls.get('PhasePartials',None) 3279 def SavePartial(*args): pass 3280 if phasePartials: 3281 phPartialFile = phasePartials+'.partials'+str(Histogram['hId']) 3282 phPartialFP = open(phPartialFile,'wb') # create/overwrite a file 3283 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 file 3288 pickle.dump(phase,phPartialFP) 3289 pickle.dump(y,phPartialFP) 3290 phPartialFP.close() 3276 3291 hId = Histogram['hId'] 3277 3292 hfx = ':%d:'%(hId) … … 3345 3360 useMP,ncores = G2mp.InitMP() 3346 3361 if len(refDict['RefList']) < 100: useMP = False 3362 if phasePartials: 3363 useMP = False 3364 ypartial = np.zeros_like(yb) 3347 3365 if useMP: # multiprocessing: create a set of initialized Python processes 3348 3366 MPpool = mp.Pool(ncores,G2mp.InitPwdrProfGlobals,[im,shl,x]) … … 3387 3405 fp = G2pwd.getFCJVoigt3(refl[5+im],refl[6+im],refl[7+im],shl,ma.getdata(x[iBeg:iFin]))[0] 3388 3406 yc[iBeg:iFin] += refl[11+im]*refl[9+im]*fp #>90% of time spent here 3407 if phasePartials: ypartial[iBeg:iFin] += refl[11+im]*refl[9+im]*fp 3389 3408 if Ka2: 3390 3409 pos2 = refl[5+im]+lamRatio*tand(refl[5+im]/2.0) # + 360/pi * Dlam/lam * tan(th) … … 3403 3422 fp2 = G2pwd.getFCJVoigt3(pos2,refl[6+im],refl[7+im],shl,ma.getdata(x[iBeg:iFin]))[0] 3404 3423 yc[iBeg:iFin] += refl[11+im]*refl[9+im]*kRatio*fp2 #and here 3424 if phasePartials: ypartial[iBeg:iFin] += refl[11+im]*refl[9+im]*kRatio*fp2 3425 if phasePartials: SavePartial(phase,ypartial) 3405 3426 elif 'E' in calcControls[hfx+'histType']: 3406 3427 -
trunk/help/gsasII.html
r5262 r5274 5525 5525 style='font-family:Symbol;mso-fareast-font-family:Symbol;mso-bidi-font-family: 5526 5526 Symbol'><span style='mso-list:Ignore'>·<span style='font:7.0pt "Times New Roman"'> 5527 </span></span></span><![endif]><b>Compute partials - </b>This runs a 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. 5539 </P> 5540 5541 <p class=MsoListParagraphCxSpMiddle style='text-indent:-.25in;mso-list:l2 level1 lfo5'><![if !supportLists]><span 5542 style='font-family:Symbol;mso-fareast-font-family:Symbol;mso-bidi-font-family: 5543 Symbol'><span style='mso-list:Ignore'>·<span style='font:7.0pt "Times New Roman"'> 5527 5544 </span></span></span><![endif]><b>Run <span class=SpellE>Fprime</span> - </b>This 5528 5545 run the utility routine <span class=SpellE>Fprime</span> that displays real and … … 9746 9763 </span></div> 9747 9764 9748 <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 9749 modified: Wed Feb 23 16:21:54 CST 2022 <o:p></o:p></p> 9750 9751 <!-- hhmts end --></div> 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:38 CDT 2022 <!-- hhmts end --></div> 9752 9766 9753 9767 </body>
Note: See TracChangeset
for help on using the changeset viewer.