Changeset 3218
- Timestamp:
- Jan 11, 2018 9:44:24 AM (6 years ago)
- Location:
- Tutorials/PythonScript
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
Tutorials/PythonScript/Scripting.htm
r3209 r3218 584 584 <blockquote><textarea rows="4" cols="70" readonly> 585 585 gpx = G2sc.G2Project(filename='PbSO4sim.gpx') # create a project 586 # s etup step 1: add a phase to the project586 # step 1, setup: add a phase to the project 587 587 phase0 = gpx.add_phase(os.path.join(datadir,"PbSO4-Wyckoff.cif"), 588 588 phasename="PbSO4",fmthint='CIF') </textarea></blockquote> … … 595 595 ``[phase0]``. 596 596 597 <blockquote><textarea rows="6" cols=" 70" readonly>598 # s etup step 2: add a simulated histogram and link it to the previous phase(s)597 <blockquote><textarea rows="6" cols="80" readonly> 598 # step 2, setup: add a simulated histogram and link it to the previous phase(s) 599 599 hist1 = gpx.add_simulated_powder_histogram("PbSO4 simulation", 600 600 os.path.join(datadir,"inst_d1a.prm"), … … 602 602 phases=gpx.phases())</textarea></blockquote> 603 603 604 Finally, to perform the simulation computation, a refinement is 604 Note that the computed pattern cannot be seen above "simulated noise" 605 unless the intensities are large enough. We can change the pattern 606 scale factor using the Scale factor (parameter 607 <tt>hist1.data['Sample Parameters']['Scale'][0]</tt>), as shown below. 608 609 <blockquote><textarea rows="3" cols="70" readonly> 610 # Step 3: Set the scale factor to adjust the y scale 611 hist1.SampleParameters['Scale'][0] = 1000000. 612 </textarea></blockquote> 613 614 Next, to perform the simulation computation, a refinement is 605 615 needed: 606 616 607 <blockquote><textarea rows="3" cols="70" readonly> 617 <blockquote><textarea rows="4" cols="80" readonly> 618 # step 4, compute: turn off parameter optimization and calculate pattern 608 619 gpx.data['Controls']['data']['max cyc'] = 0 # refinement not needed 609 620 gpx.do_refinements([{}]) … … 612 623 However, there is no need to actually optimize any variables, 613 624 so the number of refinement cycles is set to zero. Refinement is 614 initiated then with <I>proj</i>.<tt>do_refinements</tt>. Finally, the 625 initiated then with <I>proj</i>.<tt>do_refinements</tt>. To keep the 626 results in a .gpx file, the 615 627 project is saved. 616 628 617 </blockquote> 629 <P> 630 Finally, we want to do something with the results. The histogram could 631 be written to a file with the <A href= 632 "http://gsas-ii.readthedocs.io/en/latest/GSASIIscriptable.html#GSASIIscriptable.G2PwdrData.Export"> 633 <i>histogram.</i><tt>Export()</tt></A> command. Note that the first time 634 a refinement computation is done with a dummy histogram the "observed" 635 pattern is set from the calculated intensities. Here an alternate option is 636 used, where the values are retrieved and plotted. 637 638 <blockquote><textarea rows="6" cols="70" readonly> 639 # step 5, retrieve results & plot 640 x = gpx.histogram(0).getdata('x') 641 y = gpx.histogram(0).getdata('ycalc') 642 import matplotlib.pyplot as plt 643 plt.plot(x,y) 644 plt.savefig('PbSO4.png') # to show on screen use: plt.show()</textarea></blockquote> 645 646 Note that in the above, <tt>gpx.histogram(0)</tt> is used to show how 647 to reference <tt>hist1</tt> when the histogram object is not 648 known. The generated two-theta values and computed intensity values 649 are retrieved and the remaining lines generate a very simple plot 650 which is saved to a file, as shown below. 651 </blockquote> 652 653 <img src="PbSO4.png"> 618 654 619 655 <hr> 620 656 <address></address> 621 <!-- hhmts start -->Last modified: Thu Dec 28 12:18:27 CST 2017<!-- hhmts end -->657 <!-- hhmts start -->Last modified: Thu Jan 11 09:41:57 CST 2018 <!-- hhmts end --> 622 658 </body> </html> -
Tutorials/PythonScript/data/sim.py
r3209 r3218 14 14 gpx = G2sc.G2Project(filename='PbSO4sim.gpx') # create a project 15 15 16 # s etup step 1: add a phase to the project16 # step 1, setup: add a phase to the project 17 17 phase0 = gpx.add_phase(os.path.join(datadir,"PbSO4-Wyckoff.cif"), 18 18 phasename="PbSO4",fmthint='CIF') 19 19 20 # s etup step 2: add a simulated histogram and link it to the previous phase(s)20 # step 2, setup: add a simulated histogram and link it to the previous phase(s) 21 21 hist1 = gpx.add_simulated_powder_histogram("PbSO4 simulation", 22 22 os.path.join(datadir,"inst_d1a.prm"), 23 23 5.,120.,0.01, 24 24 phases=gpx.phases()) 25 26 # Step 3: Set the scale factor to adjust the y scale 27 hist1.SampleParameters['Scale'][0] = 1000000. 28 29 # step 4, compute: turn off parameter optimization and calculate pattern 25 30 gpx.data['Controls']['data']['max cyc'] = 0 # refinement not needed 26 31 gpx.do_refinements([{}]) 27 32 gpx.save() 28 33 34 # step 5, retrieve results & plot 35 x = gpx.histogram(0).getdata('x') 36 y = gpx.histogram(0).getdata('ycalc') 37 import matplotlib.pyplot as plt 38 plt.plot(x,y) 39 plt.savefig('PbSO4.png') # to show on screen use: plt.show() 29 40 30 41 42
Note: See TracChangeset
for help on using the changeset viewer.