-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from jmborr/40_simultaneous_fit
Simultaneous fitting of water data
- Loading branch information
Showing
17 changed files
with
2,728 additions
and
14 deletions.
There are no files selected for viewing
668 changes: 668 additions & 0 deletions
668
notebooks/.ipynb_checkpoints/water_fitting-checkpoint.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
972 changes: 972 additions & 0 deletions
972
notebooks/.ipynb_checkpoints/widget_builder_on_the_fly-checkpoint.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from IPython.core.display import HTML\n", | ||
"from IPython.core.display import display\n", | ||
"from ipywidgets import widgets\n", | ||
"\n", | ||
"import numpy as np\n", | ||
"\n", | ||
"import matplotlib.pyplot as plt\n", | ||
"%matplotlib notebook" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"application/vnd.jupyter.widget-view+json": { | ||
"model_id": "726a1be1595849c7bc5bfc91ea5449a6", | ||
"version_major": 2, | ||
"version_minor": 0 | ||
}, | ||
"text/plain": [ | ||
"A Jupyter Widget" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"user_input_ui = widgets.HBox([widgets.Label(\"Define Function:\",\n", | ||
" layout=widgets.Layout(width='10%')),\n", | ||
" widgets.Text(value='',\n", | ||
" placeholder=\"Define function here\",\n", | ||
" layout=widgets.Layout(width='60%')),\n", | ||
" widgets.Label(\"Ex: f(a,b,c)=a+b*c\",\n", | ||
" layout=widgets.Layout(width='20%'))])\n", | ||
"display(user_input_ui)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"..." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"At this point, you retrieve the name of the coefficient defined in the function, let's pretend those are \n", | ||
"\n", | ||
" * argument_1\n", | ||
" * argument_2\n", | ||
" * argument_3\n", | ||
" \n", | ||
" ```\n", | ||
" function(x, argument_1, argument_2, argument_3) = 3*argument_1*x + argument_2 * argument_3\n", | ||
"```" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"list_arguments = ['argument_1', 'argument_2', 'argument_3']" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def function(x, argument_1, argument_2, argument_3):\n", | ||
" return 3*argument_1*x*x + argument_2*x + argument_3" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def value_changed(value):\n", | ||
" # retrieve value of all widgets\n", | ||
" list_value = []\n", | ||
" for _top_widget in vertical_layout.children:\n", | ||
" _text_float = _top_widget.children[1]\n", | ||
" list_value.append(_text_float.value)\n", | ||
"\n", | ||
" x = np.linspace(0,100)\n", | ||
" plt.clf()\n", | ||
" plt.plot(x, function(x, list_value[0], list_value[1], list_value[2]))\n", | ||
" plt.title(\"argument_1: {}, argument_2: {}, argument_3: {}\".format(list_value[0], list_value[1], list_value[2]))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": { | ||
"scrolled": false | ||
}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"application/vnd.jupyter.widget-view+json": { | ||
"model_id": "2d8bd4928ce143c1b41d1ace62a16e7c", | ||
"version_major": 2, | ||
"version_minor": 0 | ||
}, | ||
"text/plain": [ | ||
"A Jupyter Widget" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
}, | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"<matplotlib.figure.Figure at 0x7fc003586390>" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"\n", | ||
"list_ui = []\n", | ||
"for _argument in list_arguments:\n", | ||
" \n", | ||
" _arg_ui = widgets.HBox([widgets.Label(_argument,\n", | ||
" \n", | ||
" layout=widgets.Layout(width='10%')),\n", | ||
" widgets.FloatText(value=0,\n", | ||
" layout=widgets.Layout(width='20%'))])\n", | ||
" _arg_ui.children[1].observe(value_changed, 'value')\n", | ||
" \n", | ||
" list_ui.append(_arg_ui)\n", | ||
" vertical_layout = widgets.VBox(list_ui)\n", | ||
" \n", | ||
"display(vertical_layout) \n", | ||
"plt.clf()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 2 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython2", | ||
"version": "2.7.12" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
h5py | ||
lmfit | ||
matplotlib | ||
numpy | ||
scipy | ||
lmfit | ||
six | ||
h5py |
This file contains 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
This file contains 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
Empty file.
Oops, something went wrong.