Skip to content

Commit

Permalink
Merge branch 'develop' into numpy2
Browse files Browse the repository at this point in the history
  • Loading branch information
andped10 committed Sep 3, 2024
2 parents 1be9208 + 641c44c commit fd7875c
Show file tree
Hide file tree
Showing 59 changed files with 1,223 additions and 1,225 deletions.
4 changes: 2 additions & 2 deletions docs/src/sample/material_library.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The construction of a :py:class:`Material` is achieved as shown below.
name='Boron'
)
The above object will have the properties of :py:attr:`sld` and :py:attr:`isld`, which will have values of :code:`6.908 1 / angstrom ** 2` and :code:`-0.278 1 / angstrom ** 2` respectively.
The above object will have the properties of :py:attr:`sld` and :py:attr:`isld`, which will have values of :code:`6.908 1/angstrom^2` and :code:`-0.278 1/angstrom^2` respectively.
As is shown in the `tutorials`_, a material can be used to construct a :py:class:`Layer` from which `slab models`_ are created.

:py:class:`MaterialDensity`
Expand Down Expand Up @@ -78,7 +78,7 @@ So to produce a :py:class:`MaterialSolvated` that is 20 % D2O in a polymer, the
name='Solvated Polymer'
)
For the :py:attr:`solvated_polymer` object, the :py:attr:`sld` will be :code:`2.872 1 / angstrom ** 2` (the weighted average of the two scattering length densities).
For the :py:attr:`solvated_polymer` object, the :py:attr:`sld` will be :code:`2.872 1/angstrom^2` (the weighted average of the two scattering length densities).
The :py:class:`MaterialSolvated` includes a constraint such that if the value of either constituent scattering length densities (both real and imaginary components) or the fraction changes, then the resulting material :py:attr:`sld` and :py:attr:`isld` will change appropriately.

.. _`assemblies`: ./assemblies_library.html
Expand Down
39 changes: 31 additions & 8 deletions docs/src/tutorials/fitting/repeating.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@
"\n",
"import numpy as np\n",
"import scipp as sc\n",
"import easyreflectometry\n",
"import pooch\n",
"import refl1d\n",
"\n",
"import easyreflectometry\n",
"\n",
"from easyreflectometry.data import load\n",
"from easyreflectometry.sample import Layer\n",
"from easyreflectometry.sample import Sample\n",
Expand All @@ -46,7 +49,8 @@
"from easyreflectometry.experiment import PercentageFhwm\n",
"from easyreflectometry.calculators import CalculatorFactory\n",
"from easyreflectometry.fitting import Fitter\n",
"from easyreflectometry.plot import plot"
"from easyreflectometry.plot import plot\n",
"from easyscience.fitting import AvailableMinimizers"
]
},
{
Expand Down Expand Up @@ -78,18 +82,22 @@
"## Reading in experimental data\n",
"\n",
"The data that we will investigate in this tutorial was generated with [GenX](https://aglavic.github.io/genx/) and is stored in an `.ort` [format file](https://github.com/reflectivity/file_format/blob/master/specification.md).\n",
"Use link to [download](repeating_layers.ort) the ort data."
"We use `pooch` to fetch the file from the repository."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "609174e5-1371-412d-a29f-cb05bfe36df0",
"id": "7121c7e9",
"metadata": {},
"outputs": [],
"source": [
"data = load('repeating_layers.ort')\n",
"data"
"file_path = pooch.retrieve(\n",
" # URL to one of Pooch's test files\n",
" url=\"https://raw.githubusercontent.com/EasyScience/EasyReflectometryLib/master/docs/src/tutorials/fitting/repeating_layers.ort\",\n",
" known_hash=\"a5ffca9fd24f1d362266251723aec7ce9f34f123e39a38dfc4d829c758e6bf90\",\n",
")\n",
"data = load(file_path)"
]
},
{
Expand Down Expand Up @@ -265,7 +273,8 @@
"outputs": [],
"source": [
"fitter = Fitter(model)\n",
"analysed = fitter.fit(data, method='differential_evolution')\n",
"fitter.switch_minimizer(AvailableMinimizers.LMFit_differential_evolution)\n",
"analysed = fitter.fit(data)\n",
"analysed"
]
},
Expand Down Expand Up @@ -316,8 +325,22 @@
}
],
"metadata": {
"kernelspec": {
"display_name": "erl_1_311",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python"
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
}
},
"nbformat": 4,
Expand Down
30 changes: 26 additions & 4 deletions docs/src/tutorials/fitting/simple_fitting.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@
"source": [
"%matplotlib inline\n",
"\n",
"import easyreflectometry\n",
"import pooch\n",
"import refnx\n",
"\n",
"import easyreflectometry\n",
"\n",
"from easyreflectometry.data import load\n",
"from easyreflectometry.sample import Layer\n",
"from easyreflectometry.sample import Sample\n",
Expand Down Expand Up @@ -71,7 +74,7 @@
"\n",
"`easyreflectometry` has support for the `.ort` file format, a [standard file format for reduced reflectivity data developed by the Open Reflectometry Standards Organisation](https://www.reflectometry.org/working_groups/file_formats/).\n",
"To load in a dataset, we use the `load` function.\n",
"Use link to [download](example.ort) the ort data."
"We use `pooch` to fetch the file from the repository."
]
},
{
Expand All @@ -81,7 +84,12 @@
"metadata": {},
"outputs": [],
"source": [
"data = load('example.ort')"
"file_path = pooch.retrieve(\n",
" # URL to one of Pooch's test files\n",
" url=\"https://raw.githubusercontent.com/EasyScience/EasyReflectometryLib/master/docs/src/tutorials/fitting/example.ort\",\n",
" known_hash=\"82d0c95c069092279a799a8131ad3710335f601d9f1080754b387f42e407dfab\",\n",
")\n",
"data = load(file_path)"
]
},
{
Expand Down Expand Up @@ -514,8 +522,22 @@
}
],
"metadata": {
"kernelspec": {
"display_name": "erl_1_311",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python"
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
}
},
"nbformat": 4,
Expand Down
20 changes: 10 additions & 10 deletions docs/src/tutorials/magnetism.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import scipp as sc\n",
"\n",
"import easyreflectometry\n",
"import refl1d\n",
"import refl1d.names\n",
"\n",
"import easyreflectometry\n",
"\n",
"from easyreflectometry.calculators import CalculatorFactory\n",
"from easyreflectometry.experiment import Model\n",
"from easyreflectometry.experiment import PercentageFhwm\n",
Expand Down Expand Up @@ -250,7 +250,7 @@
"model_interface.magnetism = False\n",
"model_data_no_magnetism_ref1d_easy = model.interface().fit_func(\n",
" model_coords,\n",
" model.uid,\n",
" model.unique_name,\n",
")\n",
"plt.plot(model_coords, model_data_no_magnetism_ref1d_easy, 'r-', label=f'EasyReflectometry ({model_interface.name})', linewidth=2)\n",
"\n",
Expand Down Expand Up @@ -280,7 +280,7 @@
"model_interface.include_magnetism = True\n",
"model_data_magnetism = model.interface().fit_func(\n",
" model_coords,\n",
" model.uid,\n",
" model.unique_name,\n",
")\n",
"plt.plot(model_coords, model_data_magnetism, '-k', label=f'Without magnetic layers ({model_interface.name})', linewidth=4)\n",
"\n",
Expand All @@ -293,7 +293,7 @@
"model_interface._wrapper.update_layer(list(model_interface._wrapper.storage['layer'].keys())[2], magnetism_rhoM=5, magnetism_thetaM=175)\n",
"model_data_magnetism_layer_1 = model.interface().fit_func(\n",
" model_coords,\n",
" model.uid,\n",
" model.unique_name,\n",
")\n",
"plt.plot(model_coords, model_data_magnetism_layer_1, 'r-', label=f'With magnetic layers ({model_interface.name})', linewidth=2)\n",
"\n",
Expand Down Expand Up @@ -353,7 +353,7 @@
"model_interface._wrapper.update_layer(list(model_interface._wrapper.storage['layer'].keys())[2], magnetism_rhoM=5, magnetism_thetaM=175)\n",
"model_data_magnetism_easy = model.interface().fit_func(\n",
" model_coords,\n",
" model.uid,\n",
" model.unique_name,\n",
")\n",
"plt.plot(model_coords, model_data_magnetism_easy, 'r-', label=f'EasyReflect ({model_interface.name})', linewidth=2)\n",
"\n",
Expand Down Expand Up @@ -476,7 +476,7 @@
"model_interface = model.interface()\n",
"model_data_no_magnetism_refnx = model.interface().fit_func(\n",
" model_coords,\n",
" model.uid,\n",
" model.unique_name,\n",
")\n",
"plt.plot(model_coords, model_data_no_magnetism_refnx, 'k-', label=f'EasyReflectometry ({model_interface.name})', linewidth=5)\n",
"\n",
Expand All @@ -486,7 +486,7 @@
"model_interface = model.interface()\n",
"model_data_no_magnetism_ref1d = model.interface().fit_func(\n",
" model_coords,\n",
" model.uid,\n",
" model.unique_name,\n",
")\n",
"plt.plot(model_coords, model_data_no_magnetism_ref1d, 'r-', label=f'EasyReflectometry ({model_interface.name})', linewidth=2)\n",
"\n",
Expand Down Expand Up @@ -516,7 +516,7 @@
"model_interface.magnetism = True\n",
"model_data_magnetism = model.interface().fit_func(\n",
" model_coords,\n",
" model.uid,\n",
" model.unique_name,\n",
")\n",
"plt.plot(model_coords, model_data_magnetism, '-k', label=f'With magnetism ({model_interface.name})', linewidth=4)\n",
"\n",
Expand All @@ -527,7 +527,7 @@
"model_interface.magnetism = False\n",
"model_data_no_magnetism = model.interface().fit_func(\n",
" model_coords,\n",
" model.uid,\n",
" model.unique_name,\n",
")\n",
"plt.plot(model_coords, model_data_no_magnetism, 'r-', label=f'Without magnetism ({model_interface.name})', linewidth=2)\n",
"\n",
Expand Down
Loading

0 comments on commit fd7875c

Please sign in to comment.