Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions docs/docs/tutorials/component_collection.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,22 @@
"y = component_collection.evaluate(x)\n",
"plt.plot(x, y, label='Component collection')\n",
"\n",
"for component in component_collection.components:\n",
"for component in component_collection:\n",
" y = component.evaluate(x)\n",
" plt.plot(x, y, label=component.display_name)\n",
"\n",
"plt.legend()\n",
"plt.show()"
"plt.show()\n",
"\n",
"# Accessing components by name\n",
"gaussian_component = component_collection['Gaussian']\n",
"print(gaussian_component)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "easydynamics_newbase",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -81,7 +85,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.12"
"version": "3.14.4"
}
},
"nbformat": 4,
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/tutorials/components.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
},
{
"cell_type": "code",
"execution_count": null,
"id": "1",
"execution_count": 1,
"id": "df408006",
"metadata": {},
"outputs": [],
"source": [
Expand Down
10 changes: 5 additions & 5 deletions docs/docs/tutorials/data/create_fake_data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"for i in range(Q.size):\n",
" components = model.get_component_collection(i)\n",
" offset = 0.0\n",
" components.components[0].area = 3.79 - 0.2 * Q[i].value\n",
" components[0].area = 3.79 - 0.2 * Q[i].value\n",
"\n",
"energy = sc.linspace(start=-3.0, stop=3.0, num=756, unit='meV', dim='energy')\n",
"\n",
Expand Down Expand Up @@ -86,14 +86,14 @@
"energy = sc.linspace(start=-3.0, stop=3.0, num=756, unit='meV', dim='energy')\n",
"intensity_values = np.zeros((Q.size, energy.size))\n",
"rng = np.random.default_rng()\n",
"noise = rng.normal(loc=0.0, scale=0.35, size=intensity_dataarray.shape)\n",
"noise = rng.normal(loc=0.0, scale=0.35, size=intensity_values.shape)\n",
"\n",
"for i in range(Q.size):\n",
" components = model.get_component_collection(i)\n",
" offset = sc.scalar(value=rng.uniform(0.05, 0.15), unit='meV')\n",
" components.components[0].area = 3.79 - 0.2 * Q[i].value\n",
" components.components[2].center = 1.4 + Q[i].value / 10.0\n",
" components.components[2].area = 2.45 + Q[i].value / 10.0\n",
" components[0].area = 3.79 - 0.2 * Q[i].value\n",
" components[2].center = 1.4 + Q[i].value / 10.0\n",
" components[2].area = 2.45 + Q[i].value / 10.0\n",
"\n",
" intensity_values[i, :] = components.evaluate(x=energy.values - offset.value)\n",
"\n",
Expand Down
22 changes: 11 additions & 11 deletions docs/docs/tutorials/tutorial0_basics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
"\n",
"import easydynamics as edyn\n",
"import easydynamics.sample_model as sm\n",
"from easydynamics.analysis import Analysis\n",
"from easydynamics.analysis import ParameterAnalysis\n",
"from easydynamics.analysis.parameter_analysis import FitBinding\n",
"\n",
"# Make the plots interactive\n",
"%matplotlib widget"
Expand Down Expand Up @@ -125,7 +122,7 @@
" </div>\n",
"</details>\n",
"\n",
"In this data we see a single Gaussian shaped peak and a background that seems to be zero on average. We now want to fit this data, e.g. to determine how the Gaussian changes with $Q$. We define a `Gaussian` like this:"
"In this data we see a single Gaussian shaped peak and a background that seems to be zero on average. We now want to fit this data, e.g. to determine how the Gaussian changes with $Q$. We define a `Gaussian` like this. The `name` will soon be used for indexing, while the `display_name` is what is displayed in figures. By defalut, `display_name` is the same as `name`."
]
},
{
Expand All @@ -135,7 +132,7 @@
"metadata": {},
"outputs": [],
"source": [
"gaussian = sm.Gaussian(display_name='Gaussian', area=1, width=0.05)"
"gaussian = sm.Gaussian(name='Gaussian', area=1, width=0.05)"
]
},
{
Expand Down Expand Up @@ -201,7 +198,7 @@
"metadata": {},
"outputs": [],
"source": [
"analysis = Analysis(\n",
"analysis = edyn.Analysis(\n",
" experiment=experiment,\n",
" sample_model=model,\n",
")"
Expand Down Expand Up @@ -382,7 +379,8 @@
"outputs": [],
"source": [
"energy = sc.linspace('energy', -3.5, 3.5, num=1001, unit='meV')\n",
"data_and_model = analysis.data_and_model_to_datagroup(energy=energy)"
"data_and_model = analysis.data_and_model_to_datagroup(energy=energy)\n",
"print(data_and_model)"
]
},
{
Expand All @@ -400,11 +398,13 @@
"metadata": {},
"outputs": [],
"source": [
"fit_func = sm.Polynomial(coefficients=[3.7, -0.5], display_name='Straight line')\n",
"fit_func = sm.Polynomial(\n",
" coefficients=[3.7, -0.5], name='Straight line', display_name='Straight line'\n",
")\n",
"\n",
"binding = FitBinding(parameter_name='Gaussian area', model=fit_func)\n",
"binding = edyn.FitBinding(parameter_name='Gaussian area', model=fit_func)\n",
"\n",
"parameter_analysis = ParameterAnalysis(\n",
"parameter_analysis = edyn.ParameterAnalysis(\n",
" parameters=analysis,\n",
" bindings=[binding],\n",
")"
Expand Down Expand Up @@ -468,7 +468,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "in16b",
"language": "python",
"name": "python3"
},
Expand Down
18 changes: 7 additions & 11 deletions docs/docs/tutorials/tutorial0_more_advanced.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@
"metadata": {},
"outputs": [],
"source": [
"gaussian = sm.Gaussian(display_name='Gaussian', area=3, width=0.05)\n",
"lorentzian = sm.Lorentzian(display_name='Lorentzian', area=2, width=0.3)\n",
"dho = sm.DampedHarmonicOscillator(display_name='DHO', area=1.5, width=0.2, center=1.5)\n",
"gaussian = sm.Gaussian(name='Gaussian', area=3, width=0.05)\n",
"lorentzian = sm.Lorentzian(name='Lorentzian', area=2, width=0.3)\n",
"dho = sm.DampedHarmonicOscillator(name='DHO', area=1.5, width=0.2, center=1.5)\n",
"\n",
"collection = sm.ComponentCollection()\n",
"collection.append_component(gaussian)\n",
Expand Down Expand Up @@ -245,7 +245,7 @@
"id": "af4103fb",
"metadata": {},
"source": [
"The fit looks very good. We can again get a list of the parameters for this fit by accesing the corresponding `Analysis1d` object. Note ethat the Gaussian and Lorentzian centers are both zero, but that the `energy_offset` is non-zero."
"The fit looks very good. We can again get a list of the parameters for this fit by accesing the corresponding `Analysis1d` object. Note that the Gaussian and Lorentzian centers are both zero, but that the `energy_offset` is non-zero."
]
},
{
Expand Down Expand Up @@ -310,14 +310,10 @@
"metadata": {},
"outputs": [],
"source": [
"gauss_fit_func = sm.Polynomial(\n",
" coefficients=[3.7, -0.5], unit='1/angstrom', display_name='Gauss area fit'\n",
")\n",
"dho_area_fit_func = sm.Polynomial(\n",
" coefficients=[2.0, 0.12], unit='1/angstrom', display_name='DHO area fit'\n",
")\n",
"gauss_fit_func = sm.Polynomial(coefficients=[3.7, -0.5], unit='1/angstrom', name='Gauss area fit')\n",
"dho_area_fit_func = sm.Polynomial(coefficients=[2.0, 0.12], unit='1/angstrom', name='DHO area fit')\n",
"dho_center_fit_func = sm.Polynomial(\n",
" coefficients=[1.1, 0.2], unit='1/angstrom', display_name='DHO center fit'\n",
" coefficients=[1.1, 0.2], unit='1/angstrom', name='DHO center fit'\n",
")\n",
"\n",
"binding1 = edyn.FitBinding(parameter_name='Gaussian area', model=gauss_fit_func)\n",
Expand Down
78 changes: 32 additions & 46 deletions docs/docs/tutorials/tutorial1_brownian.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
"# Brownian Diffusion\n",
"We here show how to set up an Analysis object and use it to first fit an artificial vanadium measurement to obtain the resolution. Next, we use the fitted resolution to fit an artificial measurement of a model with diffusion and some elastic scattering. \n",
"\n",
"We extract and plot the relevant parameters. Finally, we show how to fit directly to the diffusion model.\n",
"\n",
"In the near future, it will be possible to fit the width and area of the Lorentzian to the diffusion model as well."
"We extract and plot the relevant parameters and fit them to a diffusion model. Finally, we show how to fit all the data simultaneously to the diffusion model."
]
},
{
Expand All @@ -23,20 +21,8 @@
"# Imports\n",
"import pooch\n",
"\n",
"from easydynamics.analysis.analysis import Analysis\n",
"from easydynamics.analysis.parameter_analysis import FitBinding\n",
"from easydynamics.analysis.parameter_analysis import ParameterAnalysis\n",
"from easydynamics.experiment import Experiment\n",
"from easydynamics.sample_model import BrownianTranslationalDiffusion\n",
"from easydynamics.sample_model import ComponentCollection\n",
"from easydynamics.sample_model import DeltaFunction\n",
"from easydynamics.sample_model import Gaussian\n",
"from easydynamics.sample_model import Lorentzian\n",
"from easydynamics.sample_model import Polynomial\n",
"from easydynamics.sample_model.background_model import BackgroundModel\n",
"from easydynamics.sample_model.instrument_model import InstrumentModel\n",
"from easydynamics.sample_model.resolution_model import ResolutionModel\n",
"from easydynamics.sample_model.sample_model import SampleModel\n",
"import easydynamics as edyn\n",
"import easydynamics.sample_model as sm\n",
"\n",
"# Make the plots interactive\n",
"%matplotlib widget"
Expand All @@ -60,7 +46,7 @@
"outputs": [],
"source": [
"# Load the vanadium data\n",
"vanadium_experiment = Experiment('Vanadium')\n",
"vanadium_experiment = edyn.Experiment('Vanadium')\n",
"\n",
"file_path = pooch.retrieve(\n",
" url='https://github.com/easyscience/dynamics-lib/raw/refs/heads/master/docs/docs/tutorials/data/vanadium_data_example.h5',\n",
Expand Down Expand Up @@ -120,8 +106,8 @@
"metadata": {},
"outputs": [],
"source": [
"delta_function = DeltaFunction(display_name='DeltaFunction', area=1)\n",
"sample_model = SampleModel(components=delta_function)"
"delta_function = sm.DeltaFunction(name='DeltaFunction', area=1)\n",
"sample_model = sm.SampleModel(components=delta_function)"
]
},
{
Expand All @@ -143,11 +129,11 @@
"metadata": {},
"outputs": [],
"source": [
"resolution_components = ComponentCollection()\n",
"res_gauss = Gaussian(width=0.1, area=1, display_name='Res. Gauss')\n",
"resolution_components = sm.ComponentCollection()\n",
"res_gauss = sm.Gaussian(width=0.1, area=1, name='Res. Gauss')\n",
"res_gauss.area.fixed = True\n",
"resolution_components.append_component(res_gauss)\n",
"resolution_model = ResolutionModel(components=resolution_components)"
"resolution_model = sm.ResolutionModel(components=resolution_components)"
]
},
{
Expand All @@ -165,7 +151,7 @@
"metadata": {},
"outputs": [],
"source": [
"background_model = BackgroundModel(components=Polynomial(coefficients=[0.001]))"
"background_model = sm.BackgroundModel(components=sm.Polynomial(coefficients=[0.001]))"
]
},
{
Expand All @@ -183,7 +169,7 @@
"metadata": {},
"outputs": [],
"source": [
"instrument_model = InstrumentModel(\n",
"instrument_model = sm.InstrumentModel(\n",
" resolution_model=resolution_model,\n",
" background_model=background_model,\n",
")"
Expand All @@ -204,7 +190,7 @@
"metadata": {},
"outputs": [],
"source": [
"vanadium_analysis = Analysis(\n",
"vanadium_analysis = edyn.Analysis(\n",
" display_name='Vanadium Full Analysis',\n",
" experiment=vanadium_experiment,\n",
" sample_model=sample_model,\n",
Expand Down Expand Up @@ -317,7 +303,7 @@
"metadata": {},
"outputs": [],
"source": [
"diffusion_experiment = Experiment('Diffusion')\n",
"diffusion_experiment = edyn.Experiment('Diffusion')\n",
"\n",
"file_path = pooch.retrieve(\n",
" url='https://github.com/easyscience/dynamics-lib/raw/refs/heads/master/docs/docs/tutorials/data/diffusion_data_example.h5',\n",
Expand Down Expand Up @@ -352,17 +338,17 @@
"metadata": {},
"outputs": [],
"source": [
"delta_function = DeltaFunction(display_name='DeltaFunction', area=0.2)\n",
"lorentzian = Lorentzian(display_name='Lorentzian', area=0.5, width=0.3)\n",
"component_collection = ComponentCollection(\n",
"delta_function = sm.DeltaFunction(name='DeltaFunction', area=0.2)\n",
"lorentzian = sm.Lorentzian(name='Lorentzian', area=0.5, width=0.3)\n",
"component_collection = sm.ComponentCollection(\n",
" components=[delta_function, lorentzian],\n",
")\n",
"\n",
"sample_model = SampleModel(\n",
"sample_model = sm.SampleModel(\n",
" components=component_collection,\n",
")\n",
"\n",
"background_model = BackgroundModel(components=Polynomial(coefficients=[0.001]))"
"background_model = sm.BackgroundModel(components=sm.Polynomial(coefficients=[0.001]))"
]
},
{
Expand All @@ -380,14 +366,14 @@
"metadata": {},
"outputs": [],
"source": [
"instrument_model = InstrumentModel(\n",
"instrument_model = sm.InstrumentModel(\n",
" background_model=background_model,\n",
" resolution_model=vanadium_analysis.instrument_model.resolution_model,\n",
")\n",
"instrument_model.resolution_model.fix_all_parameters()\n",
"instrument_model.normalize_resolution()\n",
"\n",
"diffusion_analysis = Analysis(\n",
"diffusion_analysis = edyn.Analysis(\n",
" display_name='Diffusion Analysis',\n",
" experiment=diffusion_experiment,\n",
" sample_model=sample_model,\n",
Expand Down Expand Up @@ -496,17 +482,17 @@
"metadata": {},
"outputs": [],
"source": [
"brownian_diffusion_model = BrownianTranslationalDiffusion(\n",
" display_name='Brownian Translational Diffusion', diffusion_coefficient=2.4e-9, scale=0.5\n",
"brownian_diffusion_model = sm.BrownianTranslationalDiffusion(\n",
" name='Brownian Translational Diffusion', diffusion_coefficient=2.4e-9, scale=0.5\n",
")\n",
"\n",
"binding = FitBinding(\n",
"binding = edyn.FitBinding(\n",
" parameter_name='Lorentzian',\n",
" model=brownian_diffusion_model,\n",
" modes=['area', 'width'],\n",
")\n",
"\n",
"parameter_analysis = ParameterAnalysis(\n",
"parameter_analysis = edyn.ParameterAnalysis(\n",
" parameters=diffusion_analysis,\n",
" bindings=[binding],\n",
")"
Expand Down Expand Up @@ -596,20 +582,20 @@
"metadata": {},
"outputs": [],
"source": [
"delta_function = DeltaFunction(display_name='DeltaFunction', area=0.2)\n",
"component_collection = ComponentCollection(\n",
"delta_function = sm.DeltaFunction(name='DeltaFunction', area=0.2)\n",
"component_collection = sm.ComponentCollection(\n",
" components=[delta_function],\n",
")\n",
"diffusion_model = BrownianTranslationalDiffusion(\n",
" display_name='Brownian Translational Diffusion', diffusion_coefficient=2.4e-9, scale=0.5\n",
"diffusion_model = sm.BrownianTranslationalDiffusion(\n",
" name='Brownian Translational Diffusion', diffusion_coefficient=2.4e-9, scale=0.5\n",
")\n",
"\n",
"sample_model = SampleModel(\n",
"sample_model = sm.SampleModel(\n",
" components=component_collection,\n",
" diffusion_models=diffusion_model,\n",
")\n",
"\n",
"background_model = BackgroundModel(components=Polynomial(coefficients=[0.001]))"
"background_model = sm.BackgroundModel(components=sm.Polynomial(coefficients=[0.001]))"
]
},
{
Expand All @@ -619,7 +605,7 @@
"metadata": {},
"outputs": [],
"source": [
"instrument_model = InstrumentModel(\n",
"instrument_model = sm.InstrumentModel(\n",
" background_model=background_model,\n",
" resolution_model=vanadium_analysis.instrument_model.resolution_model,\n",
")"
Expand All @@ -640,7 +626,7 @@
"metadata": {},
"outputs": [],
"source": [
"diffusion_model_analysis = Analysis(\n",
"diffusion_model_analysis = edyn.Analysis(\n",
" display_name='Diffusion Full Analysis',\n",
" experiment=diffusion_experiment,\n",
" sample_model=sample_model,\n",
Expand Down
Loading
Loading