Changeset 3218


Ignore:
Timestamp:
Jan 11, 2018 9:44:24 AM (6 years ago)
Author:
toby
Message:

add new stuff to simulate tutorial

Location:
Tutorials/PythonScript
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • Tutorials/PythonScript/Scripting.htm

    r3209 r3218  
    584584<blockquote><textarea rows="4" cols="70" readonly>
    585585gpx = G2sc.G2Project(filename='PbSO4sim.gpx') # create a project
    586 # setup step 1: add a phase to the project
     586# step 1, setup: add a phase to the project
    587587phase0 = gpx.add_phase(os.path.join(datadir,"PbSO4-Wyckoff.cif"),
    588588                      phasename="PbSO4",fmthint='CIF') </textarea></blockquote>
     
    595595``[phase0]``.
    596596
    597 <blockquote><textarea rows="6" cols="70" readonly>
    598 # setup 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)
    599599hist1 = gpx.add_simulated_powder_histogram("PbSO4 simulation",
    600600                          os.path.join(datadir,"inst_d1a.prm"),
     
    602602                          phases=gpx.phases())</textarea></blockquote>
    603603
    604 Finally, to perform the simulation computation, a refinement is
     604Note that the computed pattern cannot be seen above "simulated noise"
     605unless the intensities are large enough. We can change the pattern
     606scale 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
     611hist1.SampleParameters['Scale'][0] = 1000000.
     612</textarea></blockquote>
     613
     614Next, to perform the simulation computation, a refinement is
    605615needed:
    606616
    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
    608619gpx.data['Controls']['data']['max cyc'] = 0 # refinement not needed
    609620gpx.do_refinements([{}])
     
    612623However, there is no need to actually optimize any variables,
    613624so the number of refinement cycles is set to zero. Refinement is
    614 initiated then with <I>proj</i>.<tt>do_refinements</tt>. Finally, the
     625initiated then with <I>proj</i>.<tt>do_refinements</tt>. To keep the
     626results in a .gpx file, the
    615627project is saved.
    616628
    617 </blockquote>
     629<P>
     630Finally, we want to do something with the results. The histogram could
     631be 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
     634a refinement computation is done with a dummy histogram the "observed"
     635pattern is set from the calculated intensities. Here an alternate option is
     636used, where the values are retrieved and plotted.
     637
     638<blockquote><textarea rows="6" cols="70" readonly>
     639# step 5, retrieve results & plot
     640x = gpx.histogram(0).getdata('x')
     641y = gpx.histogram(0).getdata('ycalc')
     642import matplotlib.pyplot as plt
     643plt.plot(x,y)
     644plt.savefig('PbSO4.png') # to show on screen use: plt.show()</textarea></blockquote>
     645
     646Note that in the above, <tt>gpx.histogram(0)</tt> is used to show how
     647to reference <tt>hist1</tt> when the histogram object is not
     648known. The generated two-theta values and computed intensity values
     649are retrieved and the remaining lines generate a very simple plot
     650which is saved to a file, as shown below.
     651</blockquote>
     652
     653<img src="PbSO4.png">
    618654
    619655<hr>
    620656<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 -->
    622658</body> </html>
  • Tutorials/PythonScript/data/sim.py

    r3209 r3218  
    1414gpx = G2sc.G2Project(filename='PbSO4sim.gpx') # create a project
    1515
    16 # setup step 1: add a phase to the project
     16# step 1, setup: add a phase to the project
    1717phase0 = gpx.add_phase(os.path.join(datadir,"PbSO4-Wyckoff.cif"),
    1818                      phasename="PbSO4",fmthint='CIF')
    1919
    20 # setup 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)
    2121hist1 = gpx.add_simulated_powder_histogram("PbSO4 simulation",
    2222                          os.path.join(datadir,"inst_d1a.prm"),
    2323                          5.,120.,0.01,
    2424                          phases=gpx.phases())
     25
     26# Step 3: Set the scale factor to adjust the y scale
     27hist1.SampleParameters['Scale'][0] = 1000000.
     28
     29# step 4, compute: turn off parameter optimization and calculate pattern
    2530gpx.data['Controls']['data']['max cyc'] = 0 # refinement not needed
    2631gpx.do_refinements([{}])
    2732gpx.save()
    2833
     34# step 5, retrieve results & plot
     35x = gpx.histogram(0).getdata('x')
     36y = gpx.histogram(0).getdata('ycalc')
     37import matplotlib.pyplot as plt
     38plt.plot(x,y)
     39plt.savefig('PbSO4.png') # to show on screen use: plt.show()
    2940
    3041
     42
Note: See TracChangeset for help on using the changeset viewer.