Created
September 4, 2014 23:55
-
-
Save ZGainsforth/009af49304ba2e430180 to your computer and use it in GitHub Desktop.
Subtract a single scattering profile from a monochromated diffraction pattern and compute the RDF from it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- coding: utf-8 -*- | |
| from matplotlib import * | |
| use('Qt4Agg') | |
| from matplotlib.pyplot import * | |
| from numpy import * | |
| def PlotRFFT(x, y): | |
| ### PlotRFFT(x, y): plots the FFT of y assuming y is real. Generates one plot with two subfigures: abscissa = frequency and abscissa = period. | |
| f = fft.rfft(y)/len(y)*2 | |
| nu = fft.rfftfreq(len(y), x[1]-x[0]) | |
| p = 1/nu | |
| amp = abs(f) | |
| subplot(2,1,1) | |
| plot(nu, amp) | |
| xlabel('Frequency') | |
| ylabel('Amplitude') | |
| subplot(2,1,2) | |
| plot(p, amp) | |
| xlabel('Period') | |
| ylabel('Amplitude') | |
| show() | |
| close('all') | |
| # Load the Q integration from disk. | |
| Q = genfromtxt('Cecil Grid A6 S2 - 0053 - Q integration.dat') | |
| # Simulate a single scattering profile (atomic form factor) as being propotional to Q**-2 and then fit it. | |
| S = Q[:,0]**-2 | |
| # In this case I just fit it by hand. | |
| Q2 = Q[:,1]-(S*7800+5300) | |
| # Don't use the start or end of the vector -- it has artifacts. | |
| iStart = 5 | |
| iEnd = -20 | |
| # Plot the patterns. | |
| plot(Q[iStart:iEnd,0], Q[iStart:iEnd,1], Q[iStart:iEnd,0], S[iStart:iEnd]*7800+5300, Q[iStart:iEnd,0], Q2[iStart:iEnd]) | |
| xlabel('Q') | |
| legend(['Raw', 'Q^-2 scattering background', 'Subtracted']) | |
| # Plot the fft. | |
| figure(2) | |
| PlotRFFT(Q[iStart:iEnd,0], Q2[iStart:iEnd]) | |
| # Save the single scattering subtracted profile. | |
| savetxt('Cecil Grid A6 S2 - 0053 - Q integration - form factor subtracted.dat', vstack((Q[iStart:iEnd,0], Q2[iStart:iEnd])).T) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment