Skip to content

Commit

Permalink
Merge pull request #48 from jmborr/47_update_notebook_load_data_from_…
Browse files Browse the repository at this point in the history
…repo

Update notebook so that it will load from the repository
  • Loading branch information
jmborr authored Apr 12, 2018
2 parents ca4db49 + 35b3c40 commit dc63e77
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 244 deletions.
74 changes: 60 additions & 14 deletions notebooks/.ipynb_checkpoints/water_fitting-checkpoint.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
"- Visualize results from the simultaneous fit.\n",
"\n",
"### Useful links\n",
"- [qef documentation](http://qef.readthedocs.io/en/latest/) (<code>pip install qef</code>) Utilities for QENS fitting\n",
"- [lmfit documentation](https://lmfit.github.io/lmfit-py/index.html) Curve fitting\n",
"- [qef documentation](http://qef.readthedocs.io/en/latest/) Utilities for QENS fitting\n",
"- [matplotlib](https://matplotlib.org) Plotting with python\n",
"- [Post your questions](https://gitter.im/basisdoc/Lobby)\n",
"\n",
"<a id='Table of Contents'></a><h3>Table of Contents</h3>\n",
"- <a href='#load_data'>Load data and visualize data</a> \n",
"- <a href='#download_data'>Donwload Data</a> \n",
"- <a href='#load_data'>Load Data and Visualize</a> \n",
"- <a href='#def_fit_range'>Define the Fitting Range</a> \n",
"- <a href='#def_mod'>Define the model</a> \n",
"- <a href='#init_guess'>Obtain an initial guess</a> \n",
Expand Down Expand Up @@ -66,12 +67,14 @@
"from qef.models.tabulatedmodel import TabulatedModel\n",
"from qef.models.resolution import TabulatedResolutionModel\n",
"from qef.models.teixeira import TeixeiraWaterModel\n",
"from qef.operators.convolve import Convolve\n",
"\n",
"# Finding out test data\n",
"qef_module_file = os.path.abspath(qef.__file__)\n",
"qef_dir = os.path.join(os.path.dirname(qef_module_file), os.pardir)\n",
"data_dir = os.path.join(qef_dir, 'tests', 'data', 'io')"
"from qef.operators.convolve import Convolve"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Imports for plotting and widgets"
]
},
{
Expand All @@ -94,7 +97,33 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Imports for plotting and widgets"
"(<a href='#Table of Contents'>Top</a>)<a id='download_data'></a><h3>Donwload Data</h3>\n",
"\n",
"It's assumed <code>git</code> is installed in your system. Otherwise,\n",
"[follow instructions](http://qef.readthedocs.io/en/latest/installation.html#testing-tutorials-data)\n",
"to download and unpack your data to <code>/tmp/qef_data</code>."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%bash\n",
"qef_data_dir=\"/tmp/qef_data\"\n",
"git clone https://github.com/jmborr/qef_data ${qef_data_dir}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"qef_data_dir = '/tmp/qef_data'\n",
"data_dir = os.path.join(qef_data_dir, 'data', 'io')\n",
"print(data_dir)"
]
},
{
Expand Down Expand Up @@ -215,7 +244,19 @@
"source": [
"(<a href='#Table of Contents'>Top</a>)<a id='init_guess'></a><h3>Obtain an initial guess</h3>\n",
"\n",
"A widget that compares the evaluation of the model with one of the experimental spectra. You can tweak only the free (unconstrained) parameters."
"A widget that compares the evaluation of the model with one of the experimental spectra. You can tweak only the free (unconstrained) parameters.\n",
"\n",
"When run, you will see two empty panels, one for comparison between experiment and model, and the second panel for residuals. Start changing the values of the parameters for the panels to be populated.\n",
"\n",
"A good initial guess for the first spectrum is :\n",
"\n",
"> spectum index = 0 \n",
"> I_c = 4 \n",
"> e_center = 0 \n",
"> e_amplitude = 0.1 \n",
"> l_sigma = 0.03 \n",
"> b_intercept = 0 \n",
"> b_slope = 0 \n"
]
},
{
Expand All @@ -233,7 +274,12 @@
"y_exp = fr['y'][0] # associated experimental values for the first histogram\n",
"e_exp = fr['e'][0]\n",
"\n",
"f, (ax1, ax2) = plt.subplots(2, 1)\n",
"f = plt.figure()\n",
"gs = plt.GridSpec(nrows=2, ncols=1, height_ratios=[4, 1])\n",
"ax1 = f.add_subplot(gs[0]) # host the fit\n",
"ax2 = f.add_subplot(gs[1], sharex=ax1) # host the residuals\n",
"\n",
"#f, (ax1, ax2) = plt.subplots(2, 1)\n",
"def plot_new_spectrum(an_axis):\n",
" global y_exp\n",
" an_axis.clear()\n",
Expand Down Expand Up @@ -653,14 +699,14 @@
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.12"
"pygments_lexer": "ipython3",
"version": "3.6.4"
}
},
"nbformat": 4,
Expand Down
94 changes: 53 additions & 41 deletions notebooks/water_fitting.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"- Visualize results from the simultaneous fit.\n",
"\n",
"### Useful links\n",
"- [qef documentation](http://qef.readthedocs.io/en/latest/) (<code>pip install qef</code>) Utilities for QENS fitting\n",
"- [lmfit documentation](https://lmfit.github.io/lmfit-py/index.html) Curve fitting\n",
"- [qef documentation](http://qef.readthedocs.io/en/latest/) Utilities for QENS fitting\n",
"- [matplotlib](https://matplotlib.org) Plotting with python\n",
"- [Post your questions](https://gitter.im/basisdoc/Lobby)\n",
"\n",
Expand Down Expand Up @@ -48,18 +48,9 @@
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/sw/miniconda3/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n",
" from ._conv import register_converters as _register_converters\n"
]
}
],
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from __future__ import (absolute_import, division, print_function)\n",
"\n",
Expand All @@ -76,17 +67,19 @@
"from qef.models.tabulatedmodel import TabulatedModel\n",
"from qef.models.resolution import TabulatedResolutionModel\n",
"from qef.models.teixeira import TeixeiraWaterModel\n",
"from qef.operators.convolve import Convolve\n",
"\n",
"# Finding out test data\n",
"qef_module_file = os.path.abspath(qef.__file__)\n",
"qef_dir = os.path.join(os.path.dirname(qef_module_file), os.pardir)\n",
"data_dir = os.path.join(qef_dir, 'tests', 'data', 'io')"
"from qef.operators.convolve import Convolve"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Imports for plotting and widgets"
]
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -101,34 +94,36 @@
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"/sw/miniconda3/lib/python3.6/site-packages/qef/../tests/data/io\n"
]
}
],
"cell_type": "markdown",
"metadata": {},
"source": [
"print(data_dir)"
"(<a href='#Table of Contents'>Top</a>)<a id='download_data'></a><h3>Donwload Data</h3>\n",
"\n",
"It's assumed <code>git</code> is installed in your system. Otherwise,\n",
"[follow instructions](http://qef.readthedocs.io/en/latest/installation.html#testing-tutorials-data)\n",
"to download and unpack your data to <code>/tmp/qef_data</code>."
]
},
{
"cell_type": "markdown",
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"### Imports for plotting and widgets"
"%%bash\n",
"qef_data_dir=\"/tmp/qef_data\"\n",
"git clone https://github.com/jmborr/qef_data ${qef_data_dir}"
]
},
{
"cell_type": "markdown",
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"(<a href='#Table of Contents'>Top</a>)<a id='download_data'></a><h3>Donwload Data</h3>\n"
"qef_data_dir = '/tmp/qef_data'\n",
"data_dir = os.path.join(qef_data_dir, 'data', 'io')\n",
"print(data_dir)"
]
},
{
Expand Down Expand Up @@ -249,7 +244,19 @@
"source": [
"(<a href='#Table of Contents'>Top</a>)<a id='init_guess'></a><h3>Obtain an initial guess</h3>\n",
"\n",
"A widget that compares the evaluation of the model with one of the experimental spectra. You can tweak only the free (unconstrained) parameters."
"A widget that compares the evaluation of the model with one of the experimental spectra. You can tweak only the free (unconstrained) parameters.\n",
"\n",
"When run, you will see two empty panels, one for comparison between experiment and model, and the second panel for residuals. Start changing the values of the parameters for the panels to be populated.\n",
"\n",
"A good initial guess for the first spectrum is :\n",
"\n",
"> spectum index = 0 \n",
"> I_c = 4 \n",
"> e_center = 0 \n",
"> e_amplitude = 0.1 \n",
"> l_sigma = 0.03 \n",
"> b_intercept = 0 \n",
"> b_slope = 0 \n"
]
},
{
Expand All @@ -267,7 +274,12 @@
"y_exp = fr['y'][0] # associated experimental values for the first histogram\n",
"e_exp = fr['e'][0]\n",
"\n",
"f, (ax1, ax2) = plt.subplots(2, 1)\n",
"f = plt.figure()\n",
"gs = plt.GridSpec(nrows=2, ncols=1, height_ratios=[4, 1])\n",
"ax1 = f.add_subplot(gs[0]) # host the fit\n",
"ax2 = f.add_subplot(gs[1], sharex=ax1) # host the residuals\n",
"\n",
"#f, (ax1, ax2) = plt.subplots(2, 1)\n",
"def plot_new_spectrum(an_axis):\n",
" global y_exp\n",
" an_axis.clear()\n",
Expand Down Expand Up @@ -362,9 +374,9 @@
"source": [
"(<a href='#Table of Contents'>Top</a>)<a id='seq_fit'></a><h3>Sequential Fit</h3>\n",
"\n",
"Starting from the first spectrum, we iteratively fit spectra of higher q's.\n",
"**Special instructions:** If the fit you carried out in the previous cell was not for the first spectrum, the sequential fit will not run but raise an error. Go back to the cell for the Initial Guess and carry out a guess and a subsequent fit for the first spectrum, then come back here.\n",
"\n",
"*Special instructions:* If the previous guess was not for the first spectrum, the code will not run but raise and error. Go back to the previous cell and carry out a guess for the first spectrum, then come back here.\n",
"Starting from the first spectrum, we iteratively fit spectra of higher q's.\n",
"\n",
"We do not assume any particular Q-dependence for the width of the Lorentzian function."
]
Expand Down
Loading

0 comments on commit dc63e77

Please sign in to comment.