diff options
Diffstat (limited to 'processing')
-rw-r--r-- | processing/chapter.tex | 79 | ||||
-rw-r--r-- | processing/fit_amplitude.png | bin | 0 -> 60004 bytes | |||
-rw-r--r-- | processing/fit_function.png | bin | 0 -> 67168 bytes | |||
-rw-r--r-- | processing/fit_function.py | 21 | ||||
-rw-r--r-- | processing/fit_tau.png | bin | 0 -> 60105 bytes |
5 files changed, 97 insertions, 3 deletions
diff --git a/processing/chapter.tex b/processing/chapter.tex index e430e1d..1ec2c37 100644 --- a/processing/chapter.tex +++ b/processing/chapter.tex @@ -1004,12 +1004,83 @@ Guess... Can be used directly...
+[USERS CAN WRITE THEIR OWN FUNCTION OBJECTS]
+
+\begin{figure}
+ \includegraphics[width=0.5\textwidth]{"processing/fit_function"}
+ \includepython{"processing/fit_function.py"}
+ \caption[CAPTION TODO]{
+ CAPTION TODO
+ }
+\end{figure}
+
\subsection{Fitter} % ----------------------------------------------------------------------------
-Loops through...
-Returns model and outs...
+The Fitter class is specially made to work seamlessly with data objects. %
+
+WrightTools is especially good at dimensionality reduction through fitting. %
+This concept is best demonstrated through an example. %
+
+Let’s load in some test data. %
+\begin{codefragment}{python}
+#import
+import WrightTools as wt
+from WrightTools import datasets
+# create
+ps = datasets.COLORS.v2p1_MoS2_TrEE_movie
+data = wt.data.from_COLORS(ps)
+# cleanup
+data.level('ai0', 'd2', -3)
+data.scale()
+data.convert('eV')
+data.name = 'MoS2'
+\end{codefragment}
+This is a three-dimensional dataset: %
+\begin{codefragment}{python}
+>>> data.axis_names
+['w2', 'w1', 'd2']
+>>> data.shape
+(41, 41, 23)
+\end{codefragment}
+We could create an animation to see every single pixel, but we can't see everything at once that
+way. %
+Instead we could imagine fitting every decay ($\tau_{21}$ trace) to an exponential. %
+Then we could plot the amplitude and time constant of that exponential decay. %
+This helps us get at subtle questions about the data. %
+Do the lineshapes narrow with time? Does the redder feature decay slower than the bluer feature? %
+Faster? %
+
+Using the \python{Fitter} class, it is easy to perform an exponential fit along each TAU21 trace at
+each OMEGA1, OMEGA2 coordinate. %
+\begin{codefragment}{python}
+# isolate only relevant data
+data = data.split('w1', 1.75)[1].split('d2', 0)[0]
+# prepare a function
+function = wt.fit.Exponential()
+function.limits['amplitude'] = [0, 1]
+function.limits['offset'] = [0, 0]
+function.limits['tau'] = [0, 2000]
+# do the fit
+fitter = wt.fit.Fitter(function, data, 'd2')
+outs = fitter.run()
+\end{codefragment}
+When we call fitter.run(), every slice of the data object will be fit according to the given
+function object. Fitter automatically creates two new data objects when this happens. outs contains
+the fit parameters, in this case amplitude, tau, and offset. Accordingly, outs is lower-dimensional
+than the original data object. model contains the fit evaluated at each coordinate of the original
+dataset—it’s really useful for inspecting the quality of your fit procedure.
+
+[ALSO GOOD FOR WORKUP OF TUNING DATA: SEE SECTION ...]
+
+\begin{figure}
+ \includegraphics[width=0.4\textwidth]{"processing/fit_amplitude"}
+ \includegraphics[width=0.4\textwidth]{"processing/fit_tau"}
+ \caption[CAPTION TODO]{
+ CAPTION TODO
+ }
+ \label{pro:fig:fitted_movie}
+\end{figure}
-\clearpage
\section{Construction, maintenance, and distribution} % ==========================================
While WrightTools has already been useful to the work done in the WrightGroup over the last 3
@@ -1098,6 +1169,8 @@ WrightTools uses semantic versioning. % Git...
+As of 2018-04-08, WrightTools has ........ commits from ..... developers
+
\subsection{Unit tests} % ------------------------------------------------------------------------
Unit testing...
diff --git a/processing/fit_amplitude.png b/processing/fit_amplitude.png Binary files differnew file mode 100644 index 0000000..85e3f02 --- /dev/null +++ b/processing/fit_amplitude.png diff --git a/processing/fit_function.png b/processing/fit_function.png Binary files differnew file mode 100644 index 0000000..ae10662 --- /dev/null +++ b/processing/fit_function.png diff --git a/processing/fit_function.py b/processing/fit_function.py new file mode 100644 index 0000000..247b476 --- /dev/null +++ b/processing/fit_function.py @@ -0,0 +1,21 @@ +# import +import os +import numpy as np +import matplotlib.pyplot as plt +import WrightTools as wt +from WrightTools import fit +# define +here = os.path.abspath(os.path.dirname(__file__)) +# noisey gaussian +xi = np.linspace(-100, 100, 25) +yi = 20*np.exp(-0.5*((xi-5)/20.)**2) +yi = np.random.poisson(yi) +plt.scatter(xi, yi) +# fitted +g = wt.fit.Gaussian() +ps = g.fit(yi, xi) +xi = np.linspace(-100, 100, 101) +model = g.evaluate(ps, xi) +# plot +plt.plot(xi, model) +wt.artists.savefig(os.path.join(here, 'fit_function.png')) diff --git a/processing/fit_tau.png b/processing/fit_tau.png Binary files differnew file mode 100644 index 0000000..b68fd76 --- /dev/null +++ b/processing/fit_tau.png |