@@ -414,7 +414,8 @@ For this tutorial, we will go through two examples. One simple one
414
414
involving shifting a function in the ``x `` and ``y `` directions, and
415
415
another involving a Fourier transform.
416
416
417
- 1. Let's start by taking a simple ``sine `` function:
417
+ 1. Let's start by taking a simple ``sine `` function.
418
+
418
419
.. code-block :: python
419
420
420
421
import numpy as np
@@ -423,7 +424,8 @@ another involving a Fourier transform.
423
424
morph_table = np.array([morph_x, morph_y]).T
424
425
425
426
2. Then, let our target function be that same ``sine `` function shifted
426
- to the right by ``0.3 `` and up by ``0.7 ``:
427
+ to the right by ``0.3 `` and up by ``0.7 ``.
428
+
427
429
.. code-block :: python
428
430
429
431
target_x = morph_x + 0.3
@@ -434,20 +436,23 @@ another involving a Fourier transform.
434
436
this would require us to refine over two separate morph
435
437
operations. We can instead perform these morphs simultaneously
436
438
by defining a function:
439
+
437
440
.. code-block :: python
438
441
439
442
def shift (x , y , hshift , vshift ):
440
443
return x + hshift, y + vshift
441
444
442
445
4. Now, let's try finding the optimal shift parameters using the ``MorphFuncxy `` morph.
443
- We can try an initial guess of ``hshift=0.0 `` and ``vshift=0.0 ``:
446
+ We can try an initial guess of ``hshift=0.0 `` and ``vshift=0.0 ``.
447
+
444
448
.. code-block :: python
445
449
446
450
from diffpy.morph.morphpy import morph_arrays
447
451
initial_guesses = {" hshift" : 0.0 , " vshift" : 0.0 }
448
452
info, table = morph_arrays(morph_table, target_table, funcxy = (shift, initial_guesses))
449
453
450
- 5. Finally, to see the refined ``hshift `` and ``vshift `` parameters, we extract them from ``info ``:
454
+ 5. Finally, to see the refined ``hshift `` and ``vshift `` parameters, we extract them from ``info ``.
455
+
451
456
.. code-block :: python
452
457
453
458
print (f " Refined hshift: { info[" funcxy" ][" hshift" ]} " )
@@ -457,8 +462,9 @@ Now for an example involving a Fourier transform.
457
462
458
463
1. Let's say you measured a signal of the form :math: `f(x)=\exp \{\cos (\pi x)\}`.
459
464
Unfortunately, your measurement was taken against a noisy sinusoidal
460
- background of the form :math: `n(x)=A\sin (Bx)`, where ``A, B `` are unknown.
465
+ background of the form :math: `n(x)=A\sin (Bx)`, where ``A ``, `` B `` are unknown.
461
466
For our example, let's say (unknown to us) that ``A=2 `` and ``B=1.7 ``.
467
+
462
468
.. code-block :: python
463
469
464
470
import numpy as np
@@ -477,6 +483,7 @@ Now for an example involving a Fourier transform.
477
483
478
484
2. Your colleague remembers they previously computed the Fourier transform
479
485
of the function and has sent that to you.
486
+
480
487
.. code-block :: python
481
488
482
489
# We only consider the region where the grid is positive for simplicity
@@ -485,8 +492,9 @@ Now for an example involving a Fourier transform.
485
492
target_table = np.array([target_x, target_f]).T
486
493
487
494
3. We can now write a noise subtraction function that takes in our measured
488
- signal and guesses for parameters ``A, B ``, and computes the Fourier
495
+ signal and guesses for parameters ``A ``, `` B ``, and computes the Fourier
489
496
transform post-noise-subtraction.
497
+
490
498
.. code-block :: python
491
499
492
500
def noise_subtracted_ft (x , y , A , B ):
@@ -501,6 +509,7 @@ Now for an example involving a Fourier transform.
501
509
502
510
4. Finally, we can provide initial guesses of ``A=0 `` and ``B=1 `` to the
503
511
``MorphFuncxy `` morph and see what refined values we get.
512
+
504
513
.. code-block :: python
505
514
506
515
from diffpy.morph.morphpy import morph_arrays
@@ -509,6 +518,7 @@ Now for an example involving a Fourier transform.
509
518
510
519
5. Print these values to see if they match with the true values of
511
520
of ``A=2.0 `` and ``B=1.7 ``!
521
+
512
522
.. code-block :: python
513
523
514
524
print (f " Refined A: { info[" funcxy" ][" A" ]} " )
@@ -519,7 +529,7 @@ You can also use this morph to help find optimal parameters
519
529
PDFs of materials with known structures.
520
530
One does this by setting the ``MorphFuncxy `` function to a PDF
521
531
computing function such as
522
- `` ` PDFgetx3`` <https://www.diffpy.org/products/pdfgetx.html>`_.
532
+ `PDFgetx3 <https://www.diffpy.org/products/pdfgetx.html >`_.
523
533
The input (morphed) 1D function should be the 1D diffraction data
524
534
one wishes to compute the PDF of and the target 1D function
525
535
can be the PDF of a target material with similar geometry.
0 commit comments